Skip to content

Commit

Permalink
chore(vue3): Migrate NcColorPicker
Browse files Browse the repository at this point in the history
Signed-off-by: Raimund Schlüßler <[email protected]>
  • Loading branch information
raimund-schluessler committed Sep 24, 2023
1 parent 9bd69c1 commit 6cd7968
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 40 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

const ignorePatterns = [
'@ckpack/vue-color',
'ansi-regex',
'bail',
'char-regex',
Expand Down
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"dist"
],
"dependencies": {
"@ckpack/vue-color": "^1.5.0",
"@floating-ui/dom": "^1.1.0",
"@nextcloud/auth": "^2.0.0",
"@nextcloud/axios": "^2.0.0",
Expand Down
72 changes: 35 additions & 37 deletions src/components/NcColorPicker/NcColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ export default {
</style>
```

* Using v-bind for both color and open state and emitting an event that updates the color
* Using v-model for both color and open state and emitting an event that updates the color

```vue
<template>
<div class="container1">
<NcButton @click="open = !open"> Click Me </NcButton>
<NcColorPicker :value="color" @input="updateColor" :shown.sync="open">
<NcColorPicker v-model="color" v-model:shown="open">
<div :style="{'background-color': color}" class="color1" />
</NcColorPicker>
</div>
Expand All @@ -100,11 +100,6 @@ export default {
color: '#0082c9',
open: false
}
},
methods: {
updateColor(e) {
this.color = e
}
}
}
</script>
Expand Down Expand Up @@ -159,32 +154,34 @@ export default {
</docs>

<template>
<NcPopover v-bind="$attrs" v-on="$listeners" @apply-hide="handleClose">
<NcPopover @apply-hide="handleClose">
<template #trigger>
<slot />
</template>
<div class="color-picker"
:class="{ 'color-picker--advanced-fields': advanced && advancedFields }">
<transition name="slide" mode="out-in">
<div v-if="!advanced" class="color-picker__simple">
<button v-for="(color, index) in palette"
:key="index"
:style="{'background-color': color }"
class="color-picker__simple-color-circle"
:class="{ 'color-picker__simple-color-circle--active' : color === currentColor }"
type="button"
@click="pickColor(color)">
<Check v-if="color === currentColor"
:size="20" />
</button>
<Transition name="slide" mode="out-in">
<div>
<div v-if="!advanced" class="color-picker__simple">
<button v-for="(color, index) in palette"
:key="index"
:style="{'background-color': color }"
class="color-picker__simple-color-circle"
:class="{ 'color-picker__simple-color-circle--active' : color === currentColor }"
type="button"
@click="pickColor(color)">
<Check v-if="color === currentColor"
:size="20" />
</button>
</div>
<Chrome v-if="advanced"
v-model="currentColor"
class="color-picker__advanced"
:disable-alpha="true"
:disable-fields="!advancedFields"
@input="pickColor" />
</div>
<Chrome v-if="advanced"
v-model="currentColor"
class="color-picker__advanced"
:disable-alpha="true"
:disable-fields="!advancedFields"
@input="pickColor" />
</transition>
</Transition>
<div class="color-picker__navigation">
<NcButton v-if="advanced"
type="tertiary"
Expand Down Expand Up @@ -222,14 +219,15 @@ import ArrowLeft from 'vue-material-design-icons/ArrowLeft.vue'
import Check from 'vue-material-design-icons/Check.vue'
import DotsHorizontal from 'vue-material-design-icons/DotsHorizontal.vue'
import { Chrome } from 'vue-color'
import { Chrome } from '@ckpack/vue-color'
import { defineComponent } from 'vue'
const rgbToHex = function(color) {
const hex = color.toString(16)
return hex.length === 1 ? '0' + hex : hex
}
export default {
export default defineComponent({
name: 'NcColorPicker',
components: {
Expand All @@ -245,7 +243,7 @@ export default {
/**
* A HEX color that represents the initial value of the picker
*/
value: {
modelValue: {
type: String,
required: true,
},
Expand Down Expand Up @@ -276,21 +274,21 @@ export default {
'submit',
'close',
'update:open',
'update:value',
'update:modelValue',
'input',
],
data() {
return {
currentColor: this.value,
currentColor: this.modelValue,
advanced: false,
ariaBack: t('Back'),
ariaMore: t('More options'),
}
},
watch: {
value(color) {
modelValue(color) {
this.currentColor = color
},
},
Expand Down Expand Up @@ -342,7 +340,7 @@ export default {
/**
* Emits a hexadecimal string e.g. '#ffffff'
*/
this.$emit('update:value', color)
this.$emit('update:modelValue', color)
/**
* Emits a hexadecimal string e.g. '#ffffff'
Expand All @@ -351,7 +349,7 @@ export default {
},
},
}
})
</script>

Expand Down Expand Up @@ -456,15 +454,15 @@ export default {
}
.slide {
&-enter {
&-enter-from {
transform: translateX(-50%);
opacity: 0;
}
&-enter-to {
transform: translateX(0);
opacity: 1;
}
&-leave {
&-leave-from {
transform: translateX(0);
opacity: 1;
}
Expand Down
4 changes: 1 addition & 3 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@
// export { default as NcBreadcrumb } from './NcBreadcrumb/index.js'
// export { default as NcBreadcrumbs } from './NcBreadcrumbs/index.js'
export { default as NcButton } from './NcButton/index.js'

// Not yet adjusted for vue3
export { default as NcCheckboxRadioSwitch } from './NcCheckboxRadioSwitch/index.js'
// export { default as NcColorPicker } from './NcColorPicker/index.js'
export { default as NcColorPicker } from './NcColorPicker/index.js'
// export { default as NcContent } from './NcContent/index.js'
export { default as NcCounterBubble } from './NcCounterBubble/index.js'
// export { default as NcDashboardWidget } from './NcDashboardWidget/index.js'
Expand Down
1 change: 1 addition & 0 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ module.exports = async () => {
name: 'NcPickers',
components: [
//'src/components/Nc*Picker*/*.vue',
'src/components/NcColorPicker/*.vue',
'src/components/NcDatetimePickerNative*/*.vue',
],
},
Expand Down

0 comments on commit 6cd7968

Please sign in to comment.