|
7 | 7 | :script="script" |
8 | 8 | > |
9 | 9 | <div class="d-flex flex-column justify-center align-center ga-3"> |
10 | | - <v-btn :color="color" icon @click="next"> |
| 10 | + <v-btn :color="color" size="x-large" icon @click="next"> |
11 | 11 | <v-morphing-icon :icon="icon" v-bind="props"></v-morphing-icon> |
12 | 12 | </v-btn> |
13 | | - <span class="text-caption">Click to change icon</span> |
| 13 | + <span>☝️</span> |
| 14 | + <span class="text-body-medium">Click to change icon</span> |
14 | 15 | </div> |
15 | 16 |
|
16 | 17 | <template v-slot:configuration> |
17 | 18 | <v-select |
18 | 19 | v-model="color" |
19 | 20 | :items="colors" |
| 21 | + item-title="title" |
| 22 | + item-value="hex" |
20 | 23 | label="Color" |
21 | 24 | clearable |
22 | 25 | ></v-select> |
|
29 | 32 | const name = 'v-morphing-icon' |
30 | 33 | const model = shallowRef('default') |
31 | 34 | const options = [] |
32 | | - import { getForeground, parseColor } from 'vuetify/lib/util/colorUtils' |
33 | | - import { useTheme } from 'vuetify' |
34 | | -
|
35 | | - const theme = useTheme() |
36 | | - const colors = ['primary', 'secondary', 'success', 'error', 'warning', 'info', 'surface-variant'] |
| 35 | + const colors = [ |
| 36 | + { title: 'Red', hex: '#f44336', isDark: true }, |
| 37 | + { title: 'Purple', hex: '#9c27b0', isDark: true }, |
| 38 | + { title: 'Blue', hex: '#2196f3', isDark: true }, |
| 39 | + { title: 'Lime', hex: '#cddc39', isDark: false }, |
| 40 | + { title: 'Orange', hex: '#ff9800', isDark: false }, |
| 41 | + ] |
37 | 42 | const color = shallowRef() |
38 | 43 | const dark = shallowRef(false) |
39 | 44 |
|
40 | 45 | watch(color, val => { |
41 | | - if (!val) return |
42 | | - const hex = theme.current.value.colors[color.value] |
43 | | - if (!hex) return |
44 | | - dark.value = getForeground(parseColor(hex)) === '#fff' |
| 46 | + if (!val) { |
| 47 | + dark.value = false |
| 48 | + return |
| 49 | + } |
| 50 | + dark.value = colors.find(c => c.hex === val)?.isDark ?? false |
45 | 51 | }) |
46 | 52 |
|
47 | 53 | const icons = [ |
|
55 | 61 |
|
56 | 62 | const props = computed(() => { |
57 | 63 | return { |
58 | | - dark: dark.value || undefined, |
| 64 | + dark: dark.value || (color.value ? false : undefined), |
59 | 65 | } |
60 | 66 | }) |
61 | 67 |
|
|
84 | 90 |
|
85 | 91 | const code = computed(() => { |
86 | 92 | const btnProps = color.value ? ` color="${color.value}"` : '' |
87 | | - return `<v-btn${btnProps} icon @click="next"> |
| 93 | + return `<v-btn${btnProps} size="x-large" icon @click="next"> |
88 | 94 | <${name} :icon="icon"${propsToString(props.value)}></${name}> |
89 | 95 | </v-btn>` |
90 | 96 | }) |
|
0 commit comments