@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.
- package/README.md +43 -0
- package/dist/API.md +266 -60
- package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
- package/dist/MIcon-DLOkQduI.js.map +1 -0
- package/dist/{MTextField-pJU1vFaR.js → MTextField-DKtgPymd.js} +422 -206
- package/dist/MTextField-DKtgPymd.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.md +547 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MBox.vue.d.ts +3 -3
- package/dist/components/MButton.vue.d.ts +4 -2
- package/dist/components/MButtonGroup.vue.d.ts +2 -0
- package/dist/components/MColorPicker.vue.d.ts +13 -1
- package/dist/components/MColorPickerModal.vue.d.ts +14 -2
- package/dist/components/MDragHandle.vue.d.ts +12 -0
- package/dist/components/MEmojiSelector.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +5 -3
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MIcon.vue.d.ts +3 -0
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MMenuItem.vue.d.ts +17 -4
- package/dist/components/MOverlay.vue.d.ts +1 -1
- package/dist/components/MScrollField.vue.d.ts +40 -0
- package/dist/components/MScrollable.vue.d.ts +9 -0
- package/dist/components/MSplitButton.vue.d.ts +2 -0
- package/dist/components/MSplitter.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTimePickerModal.vue.d.ts +3 -0
- package/dist/components/MTimeScroll.vue.d.ts +22 -0
- package/dist/components/MToggleButton.vue.d.ts +2 -0
- package/dist/components/MTransition.vue.d.ts +34 -0
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MWindow.vue.d.ts +1 -1
- package/dist/components/_MColorPanel.vue.d.ts +18 -0
- package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
- package/dist/composables/_colorUtils.d.ts +34 -0
- package/dist/composables/_themeColor.d.ts +1 -0
- package/dist/composables/_useSpring.d.ts +17 -0
- package/dist/composables/dynamicColor.d.ts +18 -0
- package/dist/composables/useColorPalette.d.ts +27 -0
- package/dist/composables/useLocale.d.ts +16 -0
- package/dist/directives/vRipple.d.ts +16 -0
- package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
- package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
- package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
- package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
- package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
- package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
- package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
- package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/locales/index.js +112 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7443 -6150
- package/dist/m3ui.js.map +1 -1
- package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
- package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
- package/dist/plugin.d.ts +18 -0
- package/dist/rich-text-editor.js +22 -22
- package/dist/styles/palettes.css +546 -0
- package/dist/styles/theme.css +90 -0
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-Drihe5G2.js → useLocale-Cn9MVIdw.js} +17 -1
- package/dist/useLocale-Cn9MVIdw.js.map +1 -0
- package/package.json +3 -2
- package/src/__tests__/MButtonGroup.test.ts +51 -0
- package/src/__tests__/MColorPicker.test.ts +141 -0
- package/src/__tests__/MDragHandle.test.ts +57 -0
- package/src/__tests__/MIconButton.test.ts +60 -0
- package/src/__tests__/MListItemShape.test.ts +76 -0
- package/src/__tests__/MMenuItem.test.ts +84 -0
- package/src/__tests__/MScrollField.test.ts +69 -0
- package/src/__tests__/MScrollable.test.ts +42 -0
- package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
- package/src/__tests__/MTabs.test.ts +39 -0
- package/src/__tests__/MTimePickerModal.test.ts +52 -0
- package/src/__tests__/MTimeScroll.test.ts +44 -0
- package/src/__tests__/MTransition.test.ts +27 -0
- package/src/__tests__/dynamicColor.test.ts +191 -0
- package/src/__tests__/vRipple.test.ts +92 -0
- package/src/components/MBox.vue +4 -2
- package/src/components/MButton.vue +4 -13
- package/src/components/MButtonGroup.vue +118 -44
- package/src/components/MColorPicker.vue +114 -210
- package/src/components/MColorPickerModal.vue +50 -251
- package/src/components/MDragHandle.vue +54 -0
- package/src/components/MFab.vue +8 -15
- package/src/components/MIcon.vue +4 -2
- package/src/components/MIconButton.vue +96 -24
- package/src/components/MList.vue +33 -3
- package/src/components/MListItem.vue +75 -5
- package/src/components/MMenuItem.vue +115 -13
- package/src/components/MScrollField.vue +310 -0
- package/src/components/MScrollable.vue +160 -5
- package/src/components/MSplitButton.vue +5 -12
- package/src/components/MSplitter.vue +33 -10
- package/src/components/MSwipeToDismiss.vue +247 -0
- package/src/components/MTabs.vue +16 -5
- package/src/components/MTimePickerModal.vue +48 -8
- package/src/components/MTimeScroll.vue +161 -0
- package/src/components/MToggleButton.vue +5 -12
- package/src/components/MTransition.vue +149 -0
- package/src/components/_MColorPanel.vue +478 -0
- package/src/composables/_carouselStrategy.ts +3 -0
- package/src/composables/_colorUtils.ts +107 -0
- package/src/composables/_themeColor.ts +33 -0
- package/src/composables/_useSpring.ts +91 -0
- package/src/composables/dynamicColor.ts +85 -0
- package/src/composables/useColorPalette.ts +171 -25
- package/src/composables/useFieldBg.ts +6 -0
- package/src/composables/useLocale.ts +34 -0
- package/src/data/emoji-names/emoji-names-de.ts +1 -0
- package/src/data/emoji-names/emoji-names-en.ts +1 -0
- package/src/data/emoji-names/emoji-names-es.ts +1 -0
- package/src/data/emoji-names/emoji-names-fr.ts +1 -0
- package/src/data/emoji-names/emoji-names-ja.ts +1 -0
- package/src/data/emoji-names/emoji-names-ko.ts +1 -0
- package/src/data/emoji-names/emoji-names-pt.ts +1 -0
- package/src/data/emoji-names/emoji-names-zh.ts +1 -0
- package/src/data/emojis.ts +1 -0
- package/src/directives/vRipple.ts +73 -0
- package/src/index.ts +14 -1
- package/src/locales/de.ts +16 -0
- package/src/locales/es.ts +16 -0
- package/src/locales/fr.ts +16 -0
- package/src/locales/ja.ts +16 -0
- package/src/locales/ko.ts +16 -0
- package/src/locales/pt.ts +16 -0
- package/src/locales/zh.ts +16 -0
- package/src/plugin.ts +30 -7
- package/src/styles/palettes.css +546 -0
- package/src/styles/theme.css +90 -0
- package/dist/MIcon-CaEooCmZ.js.map +0 -1
- package/dist/MTextField-pJU1vFaR.js.map +0 -1
- package/dist/useLocale-Drihe5G2.js.map +0 -1
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
|
-
* An
|
|
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 {
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
const
|
|
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
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
155
|
-
|
|
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
|
-
|
|
95
|
+
close()
|
|
165
96
|
}
|
|
166
97
|
|
|
167
|
-
|
|
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
|
-
|
|
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 ? '
|
|
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
|
|
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="
|
|
152
|
+
@click="open = !open"
|
|
196
153
|
>
|
|
197
154
|
<span
|
|
198
|
-
class="h-6 w-6 shrink-0 rounded-full
|
|
155
|
+
class="m3-cp-swatch h-6 w-6 shrink-0 rounded-full"
|
|
199
156
|
:class="disabled ? 'opacity-38' : ''"
|
|
200
|
-
:style="{
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
:
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
.
|
|
298
|
-
|
|
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
|
-
.
|
|
301
|
-
|
|
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
|
-
.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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>
|