@m3ui-vue/m3ui-vue 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +43 -0
  2. package/dist/API.md +266 -60
  3. package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
  4. package/dist/MIcon-DLOkQduI.js.map +1 -0
  5. package/dist/{MTextField-pJU1vFaR.js → MTextField-DKtgPymd.js} +422 -206
  6. package/dist/MTextField-DKtgPymd.js.map +1 -0
  7. package/dist/THIRD_PARTY_LICENSES.md +547 -0
  8. package/dist/api.json +1 -1
  9. package/dist/code-editor.js +2 -2
  10. package/dist/components/MBox.vue.d.ts +3 -3
  11. package/dist/components/MButton.vue.d.ts +4 -2
  12. package/dist/components/MButtonGroup.vue.d.ts +2 -0
  13. package/dist/components/MColorPicker.vue.d.ts +13 -1
  14. package/dist/components/MColorPickerModal.vue.d.ts +14 -2
  15. package/dist/components/MDragHandle.vue.d.ts +12 -0
  16. package/dist/components/MEmojiSelector.vue.d.ts +1 -1
  17. package/dist/components/MFab.vue.d.ts +5 -3
  18. package/dist/components/MFabMenu.vue.d.ts +1 -1
  19. package/dist/components/MIcon.vue.d.ts +3 -0
  20. package/dist/components/MIconButton.vue.d.ts +15 -1
  21. package/dist/components/MListItem.vue.d.ts +5 -5
  22. package/dist/components/MMenuItem.vue.d.ts +17 -4
  23. package/dist/components/MOverlay.vue.d.ts +1 -1
  24. package/dist/components/MScrollField.vue.d.ts +40 -0
  25. package/dist/components/MScrollable.vue.d.ts +9 -0
  26. package/dist/components/MSplitButton.vue.d.ts +2 -0
  27. package/dist/components/MSplitter.vue.d.ts +2 -2
  28. package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
  29. package/dist/components/MTabs.vue.d.ts +6 -0
  30. package/dist/components/MTimePickerModal.vue.d.ts +3 -0
  31. package/dist/components/MTimeScroll.vue.d.ts +22 -0
  32. package/dist/components/MToggleButton.vue.d.ts +2 -0
  33. package/dist/components/MTransition.vue.d.ts +34 -0
  34. package/dist/components/MTree.vue.d.ts +2 -2
  35. package/dist/components/MWindow.vue.d.ts +1 -1
  36. package/dist/components/_MColorPanel.vue.d.ts +18 -0
  37. package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
  38. package/dist/composables/_colorUtils.d.ts +34 -0
  39. package/dist/composables/_themeColor.d.ts +1 -0
  40. package/dist/composables/_useSpring.d.ts +17 -0
  41. package/dist/composables/dynamicColor.d.ts +18 -0
  42. package/dist/composables/useColorPalette.d.ts +27 -0
  43. package/dist/composables/useLocale.d.ts +16 -0
  44. package/dist/directives/vRipple.d.ts +16 -0
  45. package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
  46. package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
  47. package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
  48. package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
  49. package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
  50. package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
  51. package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
  52. package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
  53. package/dist/index.d.ts +12 -1
  54. package/dist/locales/index.js +112 -0
  55. package/dist/locales/index.js.map +1 -1
  56. package/dist/m3ui-vue.css +1 -1
  57. package/dist/m3ui.js +7443 -6150
  58. package/dist/m3ui.js.map +1 -1
  59. package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
  60. package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
  61. package/dist/plugin.d.ts +18 -0
  62. package/dist/rich-text-editor.js +22 -22
  63. package/dist/styles/palettes.css +546 -0
  64. package/dist/styles/theme.css +90 -0
  65. package/dist/styles.css +1 -1
  66. package/dist/terminal.js +1 -1
  67. package/dist/{useLocale-Drihe5G2.js → useLocale-Cn9MVIdw.js} +17 -1
  68. package/dist/useLocale-Cn9MVIdw.js.map +1 -0
  69. package/package.json +3 -2
  70. package/src/__tests__/MButtonGroup.test.ts +51 -0
  71. package/src/__tests__/MColorPicker.test.ts +141 -0
  72. package/src/__tests__/MDragHandle.test.ts +57 -0
  73. package/src/__tests__/MIconButton.test.ts +60 -0
  74. package/src/__tests__/MListItemShape.test.ts +76 -0
  75. package/src/__tests__/MMenuItem.test.ts +84 -0
  76. package/src/__tests__/MScrollField.test.ts +69 -0
  77. package/src/__tests__/MScrollable.test.ts +42 -0
  78. package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
  79. package/src/__tests__/MTabs.test.ts +39 -0
  80. package/src/__tests__/MTimePickerModal.test.ts +52 -0
  81. package/src/__tests__/MTimeScroll.test.ts +44 -0
  82. package/src/__tests__/MTransition.test.ts +27 -0
  83. package/src/__tests__/dynamicColor.test.ts +191 -0
  84. package/src/__tests__/vRipple.test.ts +92 -0
  85. package/src/components/MBox.vue +4 -2
  86. package/src/components/MButton.vue +4 -13
  87. package/src/components/MButtonGroup.vue +118 -44
  88. package/src/components/MColorPicker.vue +114 -210
  89. package/src/components/MColorPickerModal.vue +50 -251
  90. package/src/components/MDragHandle.vue +54 -0
  91. package/src/components/MFab.vue +8 -15
  92. package/src/components/MIcon.vue +4 -2
  93. package/src/components/MIconButton.vue +96 -24
  94. package/src/components/MList.vue +33 -3
  95. package/src/components/MListItem.vue +75 -5
  96. package/src/components/MMenuItem.vue +115 -13
  97. package/src/components/MScrollField.vue +310 -0
  98. package/src/components/MScrollable.vue +160 -5
  99. package/src/components/MSplitButton.vue +5 -12
  100. package/src/components/MSplitter.vue +33 -10
  101. package/src/components/MSwipeToDismiss.vue +247 -0
  102. package/src/components/MTabs.vue +16 -5
  103. package/src/components/MTimePickerModal.vue +48 -8
  104. package/src/components/MTimeScroll.vue +161 -0
  105. package/src/components/MToggleButton.vue +5 -12
  106. package/src/components/MTransition.vue +149 -0
  107. package/src/components/_MColorPanel.vue +478 -0
  108. package/src/composables/_carouselStrategy.ts +3 -0
  109. package/src/composables/_colorUtils.ts +107 -0
  110. package/src/composables/_themeColor.ts +33 -0
  111. package/src/composables/_useSpring.ts +91 -0
  112. package/src/composables/dynamicColor.ts +85 -0
  113. package/src/composables/useColorPalette.ts +171 -25
  114. package/src/composables/useFieldBg.ts +6 -0
  115. package/src/composables/useLocale.ts +34 -0
  116. package/src/data/emoji-names/emoji-names-de.ts +1 -0
  117. package/src/data/emoji-names/emoji-names-en.ts +1 -0
  118. package/src/data/emoji-names/emoji-names-es.ts +1 -0
  119. package/src/data/emoji-names/emoji-names-fr.ts +1 -0
  120. package/src/data/emoji-names/emoji-names-ja.ts +1 -0
  121. package/src/data/emoji-names/emoji-names-ko.ts +1 -0
  122. package/src/data/emoji-names/emoji-names-pt.ts +1 -0
  123. package/src/data/emoji-names/emoji-names-zh.ts +1 -0
  124. package/src/data/emojis.ts +1 -0
  125. package/src/directives/vRipple.ts +73 -0
  126. package/src/index.ts +14 -1
  127. package/src/locales/de.ts +16 -0
  128. package/src/locales/es.ts +16 -0
  129. package/src/locales/fr.ts +16 -0
  130. package/src/locales/ja.ts +16 -0
  131. package/src/locales/ko.ts +16 -0
  132. package/src/locales/pt.ts +16 -0
  133. package/src/locales/zh.ts +16 -0
  134. package/src/plugin.ts +30 -7
  135. package/src/styles/palettes.css +546 -0
  136. package/src/styles/theme.css +90 -0
  137. package/dist/MIcon-CaEooCmZ.js.map +0 -1
  138. package/dist/MTextField-pJU1vFaR.js.map +0 -1
  139. package/dist/useLocale-Drihe5G2.js.map +0 -1
@@ -1,20 +1,33 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
- * An inline, dropdown-anchored color picker — hue slider, saturation/brightness area, and preset swatches.
3
+ * An outlined field that opens a color picker in a dropdown: saturation/brightness area, hue (and optional
4
+ * opacity) slider, eyedropper, HEX/RGB/HSL fields, recent colors and preset swatches. Updates the value live
5
+ * while picking.
4
6
  *
5
- * @event update:modelValue Emitted with the picked color.
7
+ * @event update:modelValue Emitted with the picked color, live while dragging or typing.
6
8
  */
7
- import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
9
+ import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
8
10
  import MIcon from './MIcon.vue'
11
+ import MColorPanel from './_MColorPanel.vue'
9
12
  import { useFieldBg } from '../composables/useFieldBg'
13
+ import { useLocale } from '../composables/useLocale'
14
+ import { defaultColorPresets, normalizeHex, pushRecentColor } from '../composables/_colorUtils'
10
15
 
11
16
  const props = withDefaults(defineProps<{
12
- /** Selected color in hex format (v-model) */
17
+ /** Selected color in hex format (v-model). `#rrggbb`, or `#rrggbbaa` when `alpha` is on and the color isn't opaque. */
13
18
  modelValue: string
14
19
  /** Field label */
15
20
  label?: string
16
21
  /** Preset color swatches shown in the panel */
17
22
  presets?: string[]
23
+ /** Adds an opacity slider and an alpha channel to the value */
24
+ alpha?: boolean
25
+ /** Remember picked colors and show them above the presets (stored in localStorage, shared by every picker). */
26
+ recent?: boolean
27
+ /** How many recent colors to keep. */
28
+ recentLimit?: number
29
+ /** Show a button to pick a color from the screen, where the browser supports it (Chrome, Edge). */
30
+ eyedropper?: boolean
18
31
  /** Disables the picker */
19
32
  disabled?: boolean
20
33
  /** Error state */
@@ -26,150 +39,88 @@ const props = withDefaults(defineProps<{
26
39
  /** Overrides the auto-detected background color used to cut the floating label out of the border */
27
40
  fieldBg?: string
28
41
  }>(), {
29
- presets: () => [
30
- '#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3',
31
- '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39',
32
- '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#607d8b',
33
- ],
42
+ presets: () => defaultColorPresets,
43
+ alpha: false,
44
+ recent: true,
45
+ recentLimit: 7,
46
+ eyedropper: true,
34
47
  })
35
48
 
36
49
  const emit = defineEmits<{ 'update:modelValue': [string] }>()
50
+ const t = useLocale()
37
51
 
38
52
  const open = ref(false)
39
53
  const triggerEl = ref<HTMLElement | null>(null)
54
+ const buttonEl = ref<HTMLButtonElement | null>(null)
40
55
  const panelEl = ref<HTMLElement | null>(null)
56
+ const colorPanel = ref<InstanceType<typeof MColorPanel> | null>(null)
41
57
  const dropPos = ref({ top: '0px', left: '0px' })
42
58
  const { resolvedFieldBg } = useFieldBg(triggerEl, () => props.fieldBg)
43
59
 
44
- const satBrightEl = ref<HTMLElement>()
45
- const draggingSB = ref(false)
60
+ // The value when the panel opened: shown as the "before" half of the preview, and compared on close to
61
+ // decide whether the color goes into the recents
62
+ const original = ref('')
46
63
 
47
- // HSV state
48
- const hue = ref(0)
49
- const sat = ref(100)
50
- const bright = ref(100)
51
-
52
- function hexToHsv(hex: string) {
53
- let c = hex.replace('#', '')
54
- if (c.length === 3) c = c[0]!+c[0]!+c[1]!+c[1]!+c[2]!+c[2]!
55
- const r = parseInt(c.substring(0, 2), 16) / 255
56
- const g = parseInt(c.substring(2, 4), 16) / 255
57
- const b = parseInt(c.substring(4, 6), 16) / 255
58
- const max = Math.max(r, g, b), min = Math.min(r, g, b)
59
- const d = max - min
60
- let h = 0
61
- if (d !== 0) {
62
- if (max === r) h = ((g - b) / d + 6) % 6
63
- else if (max === g) h = (b - r) / d + 2
64
- else h = (r - g) / d + 4
65
- h *= 60
66
- }
67
- const s = max === 0 ? 0 : (d / max) * 100
68
- const v = max * 100
69
- return { h, s, v }
70
- }
71
-
72
- function hsvToHex(h: number, s: number, v: number) {
73
- s /= 100; v /= 100
74
- const c = v * s
75
- const x = c * (1 - Math.abs((h / 60) % 2 - 1))
76
- const m = v - c
77
- let r = 0, g = 0, b = 0
78
- if (h < 60) { r = c; g = x }
79
- else if (h < 120) { r = x; g = c }
80
- else if (h < 180) { g = c; b = x }
81
- else if (h < 240) { g = x; b = c }
82
- else if (h < 300) { r = x; b = c }
83
- else { r = c; b = x }
84
- const toHex = (n: number) => Math.round((n + m) * 255).toString(16).padStart(2, '0')
85
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`
86
- }
87
-
88
- function syncFromProp() {
89
- const hsv = hexToHsv(props.modelValue)
90
- hue.value = hsv.h
91
- sat.value = hsv.s
92
- bright.value = hsv.v
93
- }
94
- syncFromProp()
95
-
96
- watch(() => props.modelValue, syncFromProp)
97
-
98
- function emitColor() {
99
- emit('update:modelValue', hsvToHex(hue.value, sat.value, bright.value))
100
- }
101
-
102
- const currentHex = computed(() => hsvToHex(hue.value, sat.value, bright.value))
103
- const hueColor = computed(() => `hsl(${hue.value}, 100%, 50%)`)
104
-
105
- function onSBPointerDown(e: PointerEvent) {
106
- e.preventDefault()
107
- draggingSB.value = true
108
- updateSB(e)
109
- ;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
110
- }
111
- function onSBPointerMove(e: PointerEvent) {
112
- if (!draggingSB.value) return
113
- updateSB(e)
114
- }
115
- function onSBPointerUp() {
116
- draggingSB.value = false
117
- emitColor()
118
- }
119
- function updateSB(e: PointerEvent) {
120
- if (!satBrightEl.value) return
121
- const rect = satBrightEl.value.getBoundingClientRect()
122
- sat.value = Math.max(0, Math.min(100, ((e.clientX - rect.left) / rect.width) * 100))
123
- bright.value = Math.max(0, Math.min(100, (1 - (e.clientY - rect.top) / rect.height) * 100))
124
- }
125
-
126
- function onHueInput(e: Event) {
127
- hue.value = Number((e.target as HTMLInputElement).value)
128
- emitColor()
129
- }
130
-
131
- function selectPreset(color: string) {
132
- emit('update:modelValue', color)
133
- }
134
-
135
- function onHexInput(e: Event) {
136
- const v = (e.target as HTMLInputElement).value
137
- if (/^#[0-9a-fA-F]{6}$/.test(v)) {
138
- emit('update:modelValue', v)
139
- }
140
- }
64
+ const GAP = 4
65
+ const MARGIN = 8
141
66
 
142
67
  function computeDropPos() {
143
68
  if (!triggerEl.value) return
144
69
  const rect = triggerEl.value.getBoundingClientRect()
145
- const panelH = 380
146
- const spaceBelow = window.innerHeight - rect.bottom - 8
147
- const above = spaceBelow < panelH && rect.top > panelH
148
- dropPos.value = {
149
- top: above ? `${rect.top - 4 - panelH}px` : `${rect.bottom + 4}px`,
150
- left: `${rect.left}px`,
151
- }
70
+ const w = panelEl.value?.offsetWidth ?? 312
71
+ const ph = panelEl.value?.offsetHeight ?? 480
72
+ const below = window.innerHeight - rect.bottom - GAP - MARGIN
73
+ const top = below >= ph || rect.top - GAP - MARGIN < ph
74
+ ? Math.max(MARGIN, Math.min(rect.bottom + GAP, window.innerHeight - ph - MARGIN))
75
+ : rect.top - GAP - ph
76
+ const left = Math.max(MARGIN, Math.min(rect.left, window.innerWidth - w - MARGIN))
77
+ dropPos.value = { top: `${top}px`, left: `${left}px` }
152
78
  }
153
79
 
154
- function onOut(e: MouseEvent) {
155
- const t = e.target as Node
156
- if (triggerEl.value?.contains(t)) return
157
- if (panelEl.value?.contains(t)) return
80
+ function close(refocus = false) {
81
+ if (!open.value) return
158
82
  open.value = false
83
+ if (refocus) buttonEl.value?.focus()
84
+ }
85
+
86
+ function onOut(e: MouseEvent) {
87
+ const target = e.target as Node
88
+ if (triggerEl.value?.contains(target) || panelEl.value?.contains(target)) return
89
+ close()
159
90
  }
160
91
 
161
92
  function onScroll(e: Event) {
162
93
  if (!open.value) return
163
94
  if (panelEl.value?.contains(e.target as Node)) return
164
- open.value = false
95
+ close()
165
96
  }
166
97
 
167
- watch(open, (v) => {
98
+ function onPanelKeydown(e: KeyboardEvent) {
99
+ if (e.key === 'Escape') {
100
+ e.stopPropagation()
101
+ close(true)
102
+ }
103
+ }
104
+
105
+ // The panel is teleported to <body>, so tabbing out of it lands outside the field: close when focus leaves
106
+ function onPanelFocusOut(e: FocusEvent) {
107
+ const to = e.relatedTarget as Node | null
108
+ if (!to || panelEl.value?.contains(to) || triggerEl.value?.contains(to)) return
109
+ close()
110
+ }
111
+
112
+ watch(open, async (v) => {
168
113
  if (v) {
114
+ original.value = normalizeHex(props.modelValue)
169
115
  computeDropPos()
116
+ await nextTick()
117
+ computeDropPos()
118
+ colorPanel.value?.focus()
170
119
  setTimeout(() => document.addEventListener('mousedown', onOut), 0)
171
120
  } else {
172
121
  document.removeEventListener('mousedown', onOut)
122
+ const picked = normalizeHex(props.modelValue)
123
+ if (props.recent && picked && picked !== original.value) pushRecentColor(picked, props.recentLimit)
173
124
  }
174
125
  })
175
126
 
@@ -184,23 +135,34 @@ onUnmounted(() => {
184
135
  <div class="flex flex-col gap-1">
185
136
  <div ref="triggerEl" class="relative mt-2" :style="{ '--field-bg': resolvedFieldBg }">
186
137
  <button
138
+ ref="buttonEl"
187
139
  type="button"
188
- class="flex h-14 w-full items-center gap-3 rounded-xs border bg-transparent px-4 text-left text-body-large transition-[border-color,border-width] duration-150"
140
+ aria-haspopup="dialog"
141
+ :aria-expanded="open"
142
+ :disabled="disabled"
143
+ class="flex h-14 w-full items-center gap-3 rounded-xs border bg-transparent px-4 text-left text-body-large outline-none transition-[border-color,border-width] duration-150"
189
144
  :class="[
190
- disabled ? 'pointer-events-none cursor-not-allowed border-on-surface/12' : 'cursor-pointer',
145
+ disabled ? 'cursor-not-allowed border-on-surface/12' : 'cursor-pointer',
191
146
  !disabled && (open
192
147
  ? error ? 'border-2 border-error' : 'border-2 border-primary'
193
- : error ? 'border-error' : 'border-outline hover:border-on-surface'),
148
+ : error
149
+ ? 'border-error focus-visible:border-2'
150
+ : 'border-outline hover:border-on-surface focus-visible:border-2 focus-visible:border-primary'),
194
151
  ]"
195
- @click="!disabled && (open = !open)"
152
+ @click="open = !open"
196
153
  >
197
154
  <span
198
- class="h-6 w-6 shrink-0 rounded-full border border-outline-variant"
155
+ class="m3-cp-swatch h-6 w-6 shrink-0 rounded-full"
199
156
  :class="disabled ? 'opacity-38' : ''"
200
- :style="{ backgroundColor: modelValue }"
157
+ :style="{ background: `linear-gradient(${modelValue}, ${modelValue}), repeating-conic-gradient(#d4d4d4 0 25%, #fff 0 50%) 0 0 / 8px 8px` }"
201
158
  />
202
159
  <span class="flex-1 font-mono" :class="disabled ? 'text-on-surface/38' : 'text-on-surface'">{{ modelValue }}</span>
203
- <MIcon name="palette" :size="24" class="shrink-0" :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'" />
160
+ <MIcon
161
+ name="palette"
162
+ :size="24"
163
+ class="shrink-0 transition-colors"
164
+ :class="disabled ? 'text-on-surface/38' : open ? (error ? 'text-error' : 'text-primary') : 'text-on-surface-variant'"
165
+ />
204
166
  </button>
205
167
  <label
206
168
  v-if="label"
@@ -215,78 +177,27 @@ onUnmounted(() => {
215
177
  <p v-else-if="hint" class="px-4 text-body-small text-on-surface-variant">{{ hint }}</p>
216
178
 
217
179
  <Teleport to="body">
218
- <Transition
219
- enter-active-class="transition-[opacity,transform] duration-150"
220
- enter-from-class="opacity-0 -translate-y-1 scale-[0.98]"
221
- leave-active-class="transition-[opacity,transform] duration-100"
222
- leave-to-class="opacity-0 -translate-y-1 scale-[0.98]"
223
- >
180
+ <Transition name="m3-cp-drop">
224
181
  <div
225
182
  v-if="open"
226
183
  ref="panelEl"
227
- class="fixed z-500 w-[280px] rounded-lg bg-surface-container p-4 shadow-elevation-3"
184
+ role="dialog"
185
+ :aria-label="label || t.selectColor"
186
+ class="fixed z-500 w-[312px] max-w-[calc(100vw-16px)] rounded-lg bg-surface-container p-4 shadow-elevation-2"
228
187
  :style="dropPos"
188
+ @keydown="onPanelKeydown"
189
+ @focusout="onPanelFocusOut"
229
190
  >
230
- <!-- Saturation / Brightness area -->
231
- <div
232
- ref="satBrightEl"
233
- class="relative mb-3 h-40 w-full cursor-crosshair overflow-hidden rounded-lg"
234
- :style="{ background: `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, ${hueColor})`, touchAction: 'none' }"
235
- @pointerdown="onSBPointerDown"
236
- @pointermove="onSBPointerMove"
237
- @pointerup="onSBPointerUp"
238
- >
239
- <div
240
- class="pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-elevation-1"
241
- :style="{
242
- left: `${sat}%`,
243
- top: `${100 - bright}%`,
244
- backgroundColor: currentHex,
245
- }"
246
- />
247
- </div>
248
-
249
- <!-- Hue slider -->
250
- <div class="mb-3">
251
- <input
252
- type="range"
253
- min="0"
254
- max="360"
255
- :value="hue"
256
- class="hue-slider h-3 w-full cursor-pointer appearance-none rounded-full outline-none"
257
- @input="onHueInput"
258
- />
259
- </div>
260
-
261
- <!-- Preview + hex input -->
262
- <div class="mb-3 flex items-center gap-3">
263
- <span
264
- class="h-9 w-9 shrink-0 rounded-full border border-outline-variant"
265
- :style="{ backgroundColor: currentHex }"
266
- />
267
- <input
268
- type="text"
269
- :value="modelValue"
270
- maxlength="7"
271
- class="flex-1 rounded-xs border border-outline bg-transparent px-3 py-2 font-mono text-body-medium text-on-surface outline-none caret-primary transition-colors focus:border-primary"
272
- @input="onHexInput"
273
- />
274
- </div>
275
-
276
- <!-- Presets -->
277
- <div class="flex flex-wrap gap-1.5">
278
- <button
279
- v-for="color in presets"
280
- :key="color"
281
- type="button"
282
- class="flex h-7 w-7 cursor-pointer items-center justify-center rounded-full border transition-transform duration-100 hover:scale-110"
283
- :class="color === modelValue ? 'border-on-surface' : 'border-transparent'"
284
- :style="{ backgroundColor: color }"
285
- @click="selectPreset(color)"
286
- >
287
- <MIcon v-if="color === modelValue" name="check" :size="14" class="text-white drop-shadow-[0_1px_1px_rgba(0,0,0,0.5)]" />
288
- </button>
289
- </div>
191
+ <MColorPanel
192
+ ref="colorPanel"
193
+ :model-value="modelValue"
194
+ :presets="presets"
195
+ :alpha="alpha"
196
+ :recent="recent"
197
+ :eyedropper="eyedropper"
198
+ :original="original"
199
+ @update:model-value="emit('update:modelValue', $event)"
200
+ />
290
201
  </div>
291
202
  </Transition>
292
203
  </Teleport>
@@ -294,25 +205,18 @@ onUnmounted(() => {
294
205
  </template>
295
206
 
296
207
  <style scoped>
297
- .hue-slider {
298
- background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
208
+ .m3-cp-swatch {
209
+ box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-on-surface) 12%, transparent);
210
+ }
211
+ .m3-cp-drop-enter-active {
212
+ transition: opacity 150ms cubic-bezier(0.2, 0, 0, 1), transform 250ms cubic-bezier(0.2, 0, 0, 1);
299
213
  }
300
- .hue-slider::-webkit-slider-thumb {
301
- -webkit-appearance: none;
302
- width: 16px;
303
- height: 16px;
304
- border-radius: 50%;
305
- background: white;
306
- box-shadow: 0 1px 3px rgba(0,0,0,0.4);
307
- cursor: pointer;
214
+ .m3-cp-drop-leave-active {
215
+ transition: opacity 100ms ease, transform 100ms ease;
308
216
  }
309
- .hue-slider::-moz-range-thumb {
310
- width: 16px;
311
- height: 16px;
312
- border-radius: 50%;
313
- background: white;
314
- box-shadow: 0 1px 3px rgba(0,0,0,0.4);
315
- border: none;
316
- cursor: pointer;
217
+ .m3-cp-drop-enter-from,
218
+ .m3-cp-drop-leave-to {
219
+ opacity: 0;
220
+ transform: translateY(-4px) scale(0.98);
317
221
  }
318
222
  </style>