@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,289 +1,88 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
|
-
* A
|
|
4
|
-
*
|
|
3
|
+
* A color picker in a dialog: saturation/brightness area, hue (and optional opacity) slider, eyedropper,
|
|
4
|
+
* HEX/RGB/HSL fields, recent colors and preset swatches. Built on MDialog; the color is only applied on confirm,
|
|
5
|
+
* and the preview shows it next to the original.
|
|
5
6
|
*
|
|
6
7
|
* @event update:modelValue Emitted when a color is confirmed — powers v-model. Only fires on confirm, not while
|
|
7
8
|
* dragging
|
|
8
9
|
* @event update:show Emitted when the dialog opens or closes — powers v-model:show
|
|
9
10
|
*/
|
|
10
|
-
import {
|
|
11
|
+
import { ref, watch } from 'vue'
|
|
11
12
|
import MButton from './MButton.vue'
|
|
12
|
-
import
|
|
13
|
+
import MDialog from './MDialog.vue'
|
|
14
|
+
import MColorPanel from './_MColorPanel.vue'
|
|
13
15
|
import { useLocale } from '../composables/useLocale'
|
|
16
|
+
import { defaultColorPresets, normalizeHex, pushRecentColor } from '../composables/_colorUtils'
|
|
14
17
|
|
|
15
18
|
const props = withDefaults(defineProps<{
|
|
16
|
-
/** Selected color in hex format (v-model) */
|
|
19
|
+
/** Selected color in hex format (v-model). `#rrggbb`, or `#rrggbbaa` when `alpha` is on and the color isn't opaque. */
|
|
17
20
|
modelValue: string
|
|
18
21
|
/** Controls dialog visibility (v-model:show) */
|
|
19
22
|
show?: boolean
|
|
20
23
|
/** Preset color swatches shown in the dialog */
|
|
21
24
|
presets?: string[]
|
|
22
|
-
/** Dialog title */
|
|
25
|
+
/** Dialog title; defaults to the locale's `selectColor` */
|
|
23
26
|
title?: string
|
|
27
|
+
/** Adds an opacity slider and an alpha channel to the value */
|
|
28
|
+
alpha?: boolean
|
|
29
|
+
/** Remember confirmed colors and show them above the presets (stored in localStorage, shared by every picker). */
|
|
30
|
+
recent?: boolean
|
|
31
|
+
/** How many recent colors to keep. */
|
|
32
|
+
recentLimit?: number
|
|
33
|
+
/** Show a button to pick a color from the screen, where the browser supports it (Chrome, Edge). */
|
|
34
|
+
eyedropper?: boolean
|
|
24
35
|
}>(), {
|
|
25
36
|
show: false,
|
|
26
|
-
presets: () =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
presets: () => defaultColorPresets,
|
|
38
|
+
alpha: false,
|
|
39
|
+
recent: true,
|
|
40
|
+
recentLimit: 7,
|
|
41
|
+
eyedropper: true,
|
|
31
42
|
})
|
|
32
43
|
|
|
33
|
-
const
|
|
44
|
+
const t = useLocale()
|
|
34
45
|
const emit = defineEmits<{
|
|
35
46
|
'update:modelValue': [string]
|
|
36
47
|
'update:show': [boolean]
|
|
37
48
|
}>()
|
|
38
49
|
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const hue = ref(0)
|
|
42
|
-
const sat = ref(100)
|
|
43
|
-
const bright = ref(100)
|
|
44
|
-
const hexInput = ref('')
|
|
45
|
-
|
|
46
|
-
function hexToHsv(hex: string) {
|
|
47
|
-
let c = hex.replace('#', '')
|
|
48
|
-
if (c.length === 3) c = c[0]! + c[0]! + c[1]! + c[1]! + c[2]! + c[2]!
|
|
49
|
-
const r = parseInt(c.substring(0, 2), 16) / 255
|
|
50
|
-
const g = parseInt(c.substring(2, 4), 16) / 255
|
|
51
|
-
const b = parseInt(c.substring(4, 6), 16) / 255
|
|
52
|
-
const max = Math.max(r, g, b), min = Math.min(r, g, b)
|
|
53
|
-
const d = max - min
|
|
54
|
-
let h = 0
|
|
55
|
-
if (d !== 0) {
|
|
56
|
-
if (max === r) h = ((g - b) / d + 6) % 6
|
|
57
|
-
else if (max === g) h = (b - r) / d + 2
|
|
58
|
-
else h = (r - g) / d + 4
|
|
59
|
-
h *= 60
|
|
60
|
-
}
|
|
61
|
-
return { h, s: max === 0 ? 0 : (d / max) * 100, v: max * 100 }
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function hsvToHex(h: number, s: number, v: number) {
|
|
65
|
-
s /= 100; v /= 100
|
|
66
|
-
const c = v * s
|
|
67
|
-
const x = c * (1 - Math.abs((h / 60) % 2 - 1))
|
|
68
|
-
const m = v - c
|
|
69
|
-
let r = 0, g = 0, b = 0
|
|
70
|
-
if (h < 60) { r = c; g = x }
|
|
71
|
-
else if (h < 120) { r = x; g = c }
|
|
72
|
-
else if (h < 180) { g = c; b = x }
|
|
73
|
-
else if (h < 240) { g = x; b = c }
|
|
74
|
-
else if (h < 300) { r = x; b = c }
|
|
75
|
-
else { r = c; b = x }
|
|
76
|
-
const toHex = (n: number) => Math.round((n + m) * 255).toString(16).padStart(2, '0')
|
|
77
|
-
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const currentHex = computed(() => hsvToHex(hue.value, sat.value, bright.value))
|
|
81
|
-
const hueColor = computed(() => `hsl(${hue.value}, 100%, 50%)`)
|
|
50
|
+
// The color being picked; becomes the value only on confirm
|
|
51
|
+
const draft = ref(props.modelValue)
|
|
82
52
|
|
|
83
53
|
watch(() => props.show, (open) => {
|
|
84
|
-
if (open)
|
|
85
|
-
|
|
86
|
-
hue.value = hsv.h
|
|
87
|
-
sat.value = hsv.s
|
|
88
|
-
bright.value = hsv.v
|
|
89
|
-
hexInput.value = props.modelValue
|
|
90
|
-
document.addEventListener('keydown', onKeydown)
|
|
91
|
-
document.body.style.overflow = 'hidden'
|
|
92
|
-
} else {
|
|
93
|
-
document.removeEventListener('keydown', onKeydown)
|
|
94
|
-
document.body.style.overflow = ''
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
function syncHex() {
|
|
99
|
-
hexInput.value = currentHex.value
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// ── Saturation / Brightness ────────────────────────────────────────
|
|
103
|
-
function onSBPointerDown(e: PointerEvent) {
|
|
104
|
-
e.preventDefault()
|
|
105
|
-
draggingSB.value = true
|
|
106
|
-
updateSB(e)
|
|
107
|
-
;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
|
|
108
|
-
}
|
|
109
|
-
function onSBPointerMove(e: PointerEvent) {
|
|
110
|
-
if (!draggingSB.value) return
|
|
111
|
-
updateSB(e)
|
|
112
|
-
}
|
|
113
|
-
function onSBPointerUp() {
|
|
114
|
-
draggingSB.value = false
|
|
115
|
-
syncHex()
|
|
116
|
-
}
|
|
117
|
-
function updateSB(e: PointerEvent) {
|
|
118
|
-
if (!satBrightEl.value) return
|
|
119
|
-
const rect = satBrightEl.value.getBoundingClientRect()
|
|
120
|
-
sat.value = Math.max(0, Math.min(100, ((e.clientX - rect.left) / rect.width) * 100))
|
|
121
|
-
bright.value = Math.max(0, Math.min(100, (1 - (e.clientY - rect.top) / rect.height) * 100))
|
|
122
|
-
syncHex()
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function onHueInput(e: Event) {
|
|
126
|
-
hue.value = Number((e.target as HTMLInputElement).value)
|
|
127
|
-
syncHex()
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function selectPreset(color: string) {
|
|
131
|
-
const hsv = hexToHsv(color)
|
|
132
|
-
hue.value = hsv.h
|
|
133
|
-
sat.value = hsv.s
|
|
134
|
-
bright.value = hsv.v
|
|
135
|
-
hexInput.value = color
|
|
136
|
-
}
|
|
54
|
+
if (open) draft.value = props.modelValue
|
|
55
|
+
}, { immediate: true })
|
|
137
56
|
|
|
138
|
-
function onHexFieldInput(e: Event) {
|
|
139
|
-
const v = (e.target as HTMLInputElement).value
|
|
140
|
-
hexInput.value = v
|
|
141
|
-
if (/^#[0-9a-fA-F]{6}$/.test(v)) {
|
|
142
|
-
const hsv = hexToHsv(v)
|
|
143
|
-
hue.value = hsv.h
|
|
144
|
-
sat.value = hsv.s
|
|
145
|
-
bright.value = hsv.v
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// ── Actions ────────────────────────────────────────────────────────
|
|
150
57
|
function cancel() { emit('update:show', false) }
|
|
151
58
|
|
|
152
59
|
function confirm() {
|
|
153
|
-
|
|
60
|
+
const picked = normalizeHex(draft.value) || draft.value
|
|
61
|
+
if (props.recent) pushRecentColor(picked, props.recentLimit)
|
|
62
|
+
emit('update:modelValue', picked)
|
|
154
63
|
emit('update:show', false)
|
|
155
64
|
}
|
|
156
|
-
|
|
157
|
-
function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
158
65
|
</script>
|
|
159
66
|
|
|
160
67
|
<template>
|
|
161
|
-
<
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
</div>
|
|
182
|
-
|
|
183
|
-
<!-- Saturation / Brightness area -->
|
|
184
|
-
<div
|
|
185
|
-
ref="satBrightEl"
|
|
186
|
-
class="relative mb-3 h-44 w-full cursor-crosshair overflow-hidden rounded-lg"
|
|
187
|
-
:style="{ background: `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, ${hueColor})`, touchAction: 'none' }"
|
|
188
|
-
@pointerdown="onSBPointerDown"
|
|
189
|
-
@pointermove="onSBPointerMove"
|
|
190
|
-
@pointerup="onSBPointerUp"
|
|
191
|
-
>
|
|
192
|
-
<div
|
|
193
|
-
class="pointer-events-none absolute h-5 w-5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-elevation-1"
|
|
194
|
-
:style="{
|
|
195
|
-
left: `${sat}%`,
|
|
196
|
-
top: `${100 - bright}%`,
|
|
197
|
-
backgroundColor: currentHex,
|
|
198
|
-
}"
|
|
199
|
-
/>
|
|
200
|
-
</div>
|
|
201
|
-
|
|
202
|
-
<!-- Hue slider -->
|
|
203
|
-
<div class="mb-3">
|
|
204
|
-
<input
|
|
205
|
-
type="range"
|
|
206
|
-
min="0"
|
|
207
|
-
max="360"
|
|
208
|
-
:value="hue"
|
|
209
|
-
class="hue-slider h-3 w-full cursor-pointer appearance-none rounded-full outline-none"
|
|
210
|
-
@input="onHueInput"
|
|
211
|
-
/>
|
|
212
|
-
</div>
|
|
213
|
-
|
|
214
|
-
<!-- Hex input -->
|
|
215
|
-
<div class="mb-3">
|
|
216
|
-
<input
|
|
217
|
-
type="text"
|
|
218
|
-
:value="hexInput"
|
|
219
|
-
maxlength="7"
|
|
220
|
-
class="w-full rounded-xs border border-outline bg-transparent px-3 py-2 font-mono text-body-medium text-on-surface caret-primary outline-none transition-colors focus:border-primary"
|
|
221
|
-
@input="onHexFieldInput"
|
|
222
|
-
/>
|
|
223
|
-
</div>
|
|
224
|
-
|
|
225
|
-
<!-- Presets -->
|
|
226
|
-
<div class="mb-4 flex flex-wrap gap-1.5">
|
|
227
|
-
<button
|
|
228
|
-
v-for="color in presets"
|
|
229
|
-
:key="color"
|
|
230
|
-
type="button"
|
|
231
|
-
class="flex h-7 w-7 cursor-pointer items-center justify-center rounded-full border transition-transform duration-100 hover:scale-110"
|
|
232
|
-
:class="color === currentHex ? 'border-on-surface' : 'border-transparent'"
|
|
233
|
-
:style="{ backgroundColor: color }"
|
|
234
|
-
@click="selectPreset(color)"
|
|
235
|
-
>
|
|
236
|
-
<MIcon v-if="color === currentHex" name="check" :size="14" class="text-white drop-shadow-[0_1px_1px_rgba(0,0,0,0.5)]" />
|
|
237
|
-
</button>
|
|
238
|
-
</div>
|
|
239
|
-
|
|
240
|
-
<!-- Footer -->
|
|
241
|
-
<div class="flex justify-end gap-2">
|
|
242
|
-
<MButton variant="text" @click="cancel">{{ locale.cancel }}</MButton>
|
|
243
|
-
<MButton variant="text" @click="confirm">OK</MButton>
|
|
244
|
-
</div>
|
|
245
|
-
</div>
|
|
246
|
-
</div>
|
|
247
|
-
</Transition>
|
|
248
|
-
</Teleport>
|
|
68
|
+
<MDialog
|
|
69
|
+
:model-value="show"
|
|
70
|
+
:title="title || t.selectColor"
|
|
71
|
+
max-width="328px"
|
|
72
|
+
:closable="false"
|
|
73
|
+
@update:model-value="!$event && cancel()"
|
|
74
|
+
>
|
|
75
|
+
<MColorPanel
|
|
76
|
+
v-model="draft"
|
|
77
|
+
:presets="presets"
|
|
78
|
+
:alpha="alpha"
|
|
79
|
+
:recent="recent"
|
|
80
|
+
:eyedropper="eyedropper"
|
|
81
|
+
:original="modelValue"
|
|
82
|
+
/>
|
|
83
|
+
<template #actions>
|
|
84
|
+
<MButton variant="text" @click="cancel">{{ t.cancel }}</MButton>
|
|
85
|
+
<MButton variant="text" @click="confirm">{{ t.confirm }}</MButton>
|
|
86
|
+
</template>
|
|
87
|
+
</MDialog>
|
|
249
88
|
</template>
|
|
250
|
-
|
|
251
|
-
<style scoped>
|
|
252
|
-
.hue-slider {
|
|
253
|
-
background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
|
|
254
|
-
}
|
|
255
|
-
.hue-slider::-webkit-slider-thumb {
|
|
256
|
-
-webkit-appearance: none;
|
|
257
|
-
width: 16px;
|
|
258
|
-
height: 16px;
|
|
259
|
-
border-radius: 50%;
|
|
260
|
-
background: white;
|
|
261
|
-
box-shadow: 0 1px 3px rgba(0,0,0,0.4);
|
|
262
|
-
cursor: pointer;
|
|
263
|
-
}
|
|
264
|
-
.hue-slider::-moz-range-thumb {
|
|
265
|
-
width: 16px;
|
|
266
|
-
height: 16px;
|
|
267
|
-
border-radius: 50%;
|
|
268
|
-
background: white;
|
|
269
|
-
box-shadow: 0 1px 3px rgba(0,0,0,0.4);
|
|
270
|
-
border: none;
|
|
271
|
-
cursor: pointer;
|
|
272
|
-
}
|
|
273
|
-
.m3-cp-modal-enter-active,
|
|
274
|
-
.m3-cp-modal-leave-active {
|
|
275
|
-
transition: opacity 0.15s ease;
|
|
276
|
-
}
|
|
277
|
-
.m3-cp-modal-enter-from,
|
|
278
|
-
.m3-cp-modal-leave-to {
|
|
279
|
-
opacity: 0;
|
|
280
|
-
}
|
|
281
|
-
.m3-cp-modal-enter-active .cp-box,
|
|
282
|
-
.m3-cp-modal-leave-active .cp-box {
|
|
283
|
-
transition: transform 0.15s ease;
|
|
284
|
-
}
|
|
285
|
-
.m3-cp-modal-enter-from .cp-box,
|
|
286
|
-
.m3-cp-modal-leave-to .cp-box {
|
|
287
|
-
transform: scale(0.95);
|
|
288
|
-
}
|
|
289
|
-
</style>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* M3's drag handle: the capsule users drag to resize or move something, e.g. the divider between two panes.
|
|
4
|
+
* Port of Compose's `VerticalDragHandle`; it only draws the handle and its pressed/dragged look, the dragging
|
|
5
|
+
* itself is up to the parent (MSplitter uses it).
|
|
6
|
+
*/
|
|
7
|
+
import { computed, ref, watch } from 'vue'
|
|
8
|
+
import { FAST_SPATIAL, useSpring } from '../composables/_useSpring'
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
|
+
/** `vertical` is a tall capsule for horizontal drags (between side-by-side panes); `horizontal` is a wide one for vertical drags. */
|
|
12
|
+
orientation?: 'vertical' | 'horizontal'
|
|
13
|
+
/** Show the dragged look (the parent is dragging) */
|
|
14
|
+
dragging?: boolean
|
|
15
|
+
}>(), { orientation: 'vertical', dragging: false })
|
|
16
|
+
|
|
17
|
+
const pressed = ref(false)
|
|
18
|
+
|
|
19
|
+
// DragHandleTokens: 4×48dp CornerFull in Outline at rest; 12×52dp CornerMedium in OnSurface pressed or
|
|
20
|
+
// dragged (CornerMedium is 12dp, which on a 12dp-wide bar is still a pill). ContainerWidth (24dp) is the
|
|
21
|
+
// touch area. VerticalDragHandle switches sizes instantly; this springs between them (Standard FastSpatial,
|
|
22
|
+
// like the library's other shape changes) and fades the color, a deliberate departure.
|
|
23
|
+
const active = computed(() => props.dragging || pressed.value)
|
|
24
|
+
const barEl = ref<HTMLElement | null>(null)
|
|
25
|
+
const { snap } = useSpring(
|
|
26
|
+
() => (active.value ? [12, 52] : [4, 48]),
|
|
27
|
+
([thick, long]) => {
|
|
28
|
+
if (!barEl.value) return
|
|
29
|
+
const vertical = props.orientation === 'vertical'
|
|
30
|
+
barEl.value.style.width = `${vertical ? thick : long}px`
|
|
31
|
+
barEl.value.style.height = `${vertical ? long : thick}px`
|
|
32
|
+
},
|
|
33
|
+
FAST_SPATIAL,
|
|
34
|
+
)
|
|
35
|
+
// Same sizes, other axis: redraw
|
|
36
|
+
watch(() => props.orientation, () => snap())
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<span
|
|
41
|
+
class="inline-flex shrink-0 items-center justify-center"
|
|
42
|
+
:class="orientation === 'vertical' ? 'h-13 w-6' : 'h-6 w-13'"
|
|
43
|
+
@pointerdown="pressed = true"
|
|
44
|
+
@pointerup="pressed = false"
|
|
45
|
+
@pointerleave="pressed = false"
|
|
46
|
+
@pointercancel="pressed = false"
|
|
47
|
+
>
|
|
48
|
+
<span
|
|
49
|
+
ref="barEl"
|
|
50
|
+
class="block rounded-full transition-colors duration-150"
|
|
51
|
+
:class="active ? 'bg-on-surface' : 'bg-outline'"
|
|
52
|
+
/>
|
|
53
|
+
</span>
|
|
54
|
+
</template>
|
package/src/components/MFab.vue
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { computed, onMounted, onUnmounted, ref, useSlots } from 'vue'
|
|
11
11
|
import MIcon from './MIcon.vue'
|
|
12
|
+
import { vRipple } from '../directives/vRipple'
|
|
12
13
|
|
|
13
14
|
export interface SpeedDialItem {
|
|
14
15
|
icon: string
|
|
@@ -58,6 +59,8 @@ const props = withDefaults(
|
|
|
58
59
|
* the content's own leave animation has time to play instead of just
|
|
59
60
|
* vanishing. 'none' skips any panel-level transition entirely. */
|
|
60
61
|
contentTransition?: 'scale' | 'fade' | 'none'
|
|
62
|
+
/** Any CSS color for the press ripple; defaults to the FAB's content color */
|
|
63
|
+
rippleColor?: string
|
|
61
64
|
}>(),
|
|
62
65
|
{
|
|
63
66
|
color: 'primary',
|
|
@@ -97,7 +100,7 @@ const fabSizeClasses = computed(() => {
|
|
|
97
100
|
if (props.label) return 'h-14 min-w-20 rounded-2xl pl-4 pr-5 gap-3'
|
|
98
101
|
switch (props.size) {
|
|
99
102
|
case 'small': return 'h-10 w-10 rounded-md'
|
|
100
|
-
case 'medium': return 'h-20 w-20 rounded-
|
|
103
|
+
case 'medium': return 'h-20 w-20 rounded-lg-increased'
|
|
101
104
|
case 'large': return 'h-24 w-24 rounded-[28px]'
|
|
102
105
|
default: return 'h-14 w-14 rounded-2xl'
|
|
103
106
|
}
|
|
@@ -197,16 +200,6 @@ function onScroll() {
|
|
|
197
200
|
open.value = false
|
|
198
201
|
}
|
|
199
202
|
|
|
200
|
-
function createRipple(event: PointerEvent | MouseEvent, target?: HTMLElement) {
|
|
201
|
-
const button = (target ?? event.currentTarget) as HTMLElement
|
|
202
|
-
const rect = button.getBoundingClientRect()
|
|
203
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
204
|
-
const el = document.createElement('span')
|
|
205
|
-
el.className = 'm3-ripple'
|
|
206
|
-
el.style.cssText = `width:${d}px;height:${d}px;top:${event.clientY - rect.top - d / 2}px;left:${event.clientX - rect.left - d / 2}px`
|
|
207
|
-
button.appendChild(el)
|
|
208
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
209
|
-
}
|
|
210
203
|
|
|
211
204
|
const contentStyle = ref<Record<string, string>>({})
|
|
212
205
|
|
|
@@ -260,8 +253,7 @@ function handleFabClick(e: PointerEvent) {
|
|
|
260
253
|
}
|
|
261
254
|
}
|
|
262
255
|
|
|
263
|
-
function handleItemClick(
|
|
264
|
-
createRipple(e, buttonEl)
|
|
256
|
+
function handleItemClick(item: SpeedDialItem) {
|
|
265
257
|
if (!props.persistent) open.value = false
|
|
266
258
|
item.onClick?.()
|
|
267
259
|
}
|
|
@@ -302,7 +294,7 @@ onUnmounted(() => {
|
|
|
302
294
|
class="relative inline-flex cursor-pointer items-center justify-center overflow-hidden shadow-elevation-3 transition-shadow duration-150 hover:shadow-elevation-4 active:shadow-elevation-3 disabled:cursor-not-allowed disabled:opacity-[0.38] before:content-[''] before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 hover:before:opacity-[0.08] active:before:opacity-[0.12]"
|
|
303
295
|
:class="[colorMap[color], fabSizeClasses]"
|
|
304
296
|
:disabled="disabled"
|
|
305
|
-
|
|
297
|
+
v-ripple="{ disabled, color: rippleColor }"
|
|
306
298
|
@click="handleFabClick"
|
|
307
299
|
>
|
|
308
300
|
<MIcon
|
|
@@ -338,7 +330,8 @@ onUnmounted(() => {
|
|
|
338
330
|
class="relative flex cursor-pointer items-center justify-center overflow-hidden rounded-lg shadow-elevation-3 transition-shadow duration-150 hover:shadow-elevation-4 active:shadow-elevation-3 before:content-[''] before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 hover:before:opacity-[0.08] active:before:opacity-[0.12]"
|
|
339
331
|
:class="colorMap[color]"
|
|
340
332
|
:style="{ width: `${ITEM_PX}px`, height: `${ITEM_PX}px` }"
|
|
341
|
-
|
|
333
|
+
v-ripple="rippleColor"
|
|
334
|
+
@pointerdown="handleItemClick(item)"
|
|
342
335
|
>
|
|
343
336
|
<MIcon :name="item.icon" :size="20" />
|
|
344
337
|
</component>
|
package/src/components/MIcon.vue
CHANGED
|
@@ -8,11 +8,13 @@ withDefaults(defineProps<{
|
|
|
8
8
|
name: string
|
|
9
9
|
/** Icon size in px */
|
|
10
10
|
size?: number
|
|
11
|
-
|
|
11
|
+
/** Filled glyph (the Material Symbols FILL axis), as M3 draws a selected icon */
|
|
12
|
+
filled?: boolean
|
|
13
|
+
}>(), { size: 24, filled: false })
|
|
12
14
|
</script>
|
|
13
15
|
|
|
14
16
|
<template>
|
|
15
|
-
<span class="material-symbols-outlined leading-none" :style="{ fontSize: `${size}px` }">{{
|
|
17
|
+
<span class="material-symbols-outlined leading-none" :style="{ fontSize: `${size}px`, fontVariationSettings: filled ? `'FILL' 1` : undefined }">{{
|
|
16
18
|
name
|
|
17
19
|
}}</span>
|
|
18
20
|
</template>
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
|
-
* A button that shows only an icon — four visual styles, the same 5-tier expressive sizing as MButton.
|
|
3
|
+
* A button that shows only an icon — four visual styles, the same 5-tier expressive sizing as MButton. Give it
|
|
4
|
+
* `checked` (v-model:checked) and it becomes M3's icon toggle button.
|
|
5
|
+
*
|
|
6
|
+
* @event update:checked Emitted on click when `checked` is set — powers v-model:checked
|
|
4
7
|
*/
|
|
5
|
-
import { computed } from 'vue'
|
|
8
|
+
import { computed, ref } from 'vue'
|
|
6
9
|
import MIcon from './MIcon.vue'
|
|
10
|
+
import { vRipple } from '../directives/vRipple'
|
|
11
|
+
import { DEFAULT_EFFECTS, useSpring } from '../composables/_useSpring'
|
|
7
12
|
|
|
8
13
|
const props = withDefaults(
|
|
9
14
|
defineProps<{
|
|
@@ -24,16 +29,29 @@ const props = withDefaults(
|
|
|
24
29
|
disabled?: boolean
|
|
25
30
|
/** Vue Router destination — renders as RouterLink instead of button */
|
|
26
31
|
to?: string | Record<string, any>
|
|
32
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
33
|
+
rippleColor?: string
|
|
34
|
+
/**
|
|
35
|
+
* Makes it a toggle button (v-model:checked): selected colors, a filled icon, and a shape that morphs when
|
|
36
|
+
* pressed and when checked. Leave it unset for a plain icon button
|
|
37
|
+
*/
|
|
38
|
+
checked?: boolean
|
|
39
|
+
/** Icon shown while checked, when it differs from `icon` (e.g. 'pause' for 'play_arrow') */
|
|
40
|
+
checkedIcon?: string
|
|
27
41
|
}>(),
|
|
28
42
|
{
|
|
29
43
|
variant: 'standard',
|
|
30
44
|
shape: 'rounded',
|
|
31
45
|
size: 'sm',
|
|
32
46
|
disabled: false,
|
|
47
|
+
checked: undefined,
|
|
33
48
|
},
|
|
34
49
|
)
|
|
35
50
|
|
|
36
|
-
const
|
|
51
|
+
const emit = defineEmits<{ 'update:checked': [boolean] }>()
|
|
52
|
+
|
|
53
|
+
const isToggle = computed(() => props.checked !== undefined)
|
|
54
|
+
const tag = computed(() => props.to && !isToggle.value ? 'RouterLink' : 'button')
|
|
37
55
|
|
|
38
56
|
// Container height/width (icon buttons are always square by default — real
|
|
39
57
|
// `IconButtonDefaults.<tier>ContainerSize()` also has Narrow/Wide width options not
|
|
@@ -41,19 +59,58 @@ const tag = computed(() => props.to ? 'RouterLink' : 'button')
|
|
|
41
59
|
// per M3's 5-tier `{XSmall,Small,Medium,Large,XLarge}IconButtonTokens.kt`. `squareRadius`
|
|
42
60
|
// matches each tier's own `ContainerShapeSquare` (12px xs/sm, 16px md, 28px lg/xl) — same
|
|
43
61
|
// pattern as MButton's size tiers.
|
|
62
|
+
// Toggle radii (px) from the same token files: `square` is ContainerShapeSquare, `pressed`
|
|
63
|
+
// PressedContainerShape, `checkedRound` SelectedContainerShapeRound (a round button squares off when
|
|
64
|
+
// checked); SelectedContainerShapeSquare is CornerFull (a square one turns round), i.e. px / 2.
|
|
44
65
|
const sizeMap = {
|
|
45
|
-
xs: { px: 32, icon: 20, squareRadius: 'rounded-md' },
|
|
46
|
-
sm: { px: 40, icon: 24, squareRadius: 'rounded-md' },
|
|
47
|
-
md: { px: 56, icon: 24, squareRadius: 'rounded-lg' },
|
|
48
|
-
lg: { px: 96, icon: 32, squareRadius: 'rounded-xl' },
|
|
49
|
-
xl: { px: 136, icon: 40, squareRadius: 'rounded-xl' },
|
|
66
|
+
xs: { px: 32, icon: 20, squareRadius: 'rounded-md', square: 12, pressed: 8, checkedRound: 12 },
|
|
67
|
+
sm: { px: 40, icon: 24, squareRadius: 'rounded-md', square: 12, pressed: 8, checkedRound: 12 },
|
|
68
|
+
md: { px: 56, icon: 24, squareRadius: 'rounded-lg', square: 16, pressed: 12, checkedRound: 16 },
|
|
69
|
+
lg: { px: 96, icon: 32, squareRadius: 'rounded-xl', square: 28, pressed: 16, checkedRound: 28 },
|
|
70
|
+
xl: { px: 136, icon: 40, squareRadius: 'rounded-xl', square: 28, pressed: 16, checkedRound: 28 },
|
|
50
71
|
}
|
|
51
72
|
|
|
52
73
|
const resolved = computed(() => {
|
|
53
|
-
if (typeof props.size === 'number')
|
|
74
|
+
if (typeof props.size === 'number') {
|
|
75
|
+
return { px: props.size, icon: Math.round(props.size * 0.55), squareRadius: 'rounded-md', square: 12, pressed: 8, checkedRound: 12 }
|
|
76
|
+
}
|
|
54
77
|
return sizeMap[props.size] ?? sizeMap.sm
|
|
55
78
|
})
|
|
56
79
|
|
|
80
|
+
// Icon toggle shape morph (IconButton.kt's shapeByInteraction: pressed, else checked, else the resting
|
|
81
|
+
// shape), on the DefaultEffects spring the source picks so it doesn't bounce. Plain icon buttons keep
|
|
82
|
+
// a static shape, like Compose's non-`shapes` overloads.
|
|
83
|
+
const rootEl = ref<unknown>(null)
|
|
84
|
+
const pressed = ref(false)
|
|
85
|
+
|
|
86
|
+
function targetRadius() {
|
|
87
|
+
const r = resolved.value
|
|
88
|
+
const full = r.px / 2
|
|
89
|
+
if (pressed.value) return r.pressed
|
|
90
|
+
if (props.checked) return props.shape === 'squared' ? full : r.checkedRound
|
|
91
|
+
return props.shape === 'squared' ? r.square : full
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
useSpring(
|
|
95
|
+
() => (isToggle.value ? [targetRadius()] : []),
|
|
96
|
+
(v) => {
|
|
97
|
+
// A RouterLink root (plain button with `to`) is a component instance, not an element
|
|
98
|
+
if (rootEl.value instanceof HTMLElement) rootEl.value.style.borderRadius = v.length ? `${v[0]}px` : ''
|
|
99
|
+
},
|
|
100
|
+
DEFAULT_EFFECTS,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
function onPointerDown() {
|
|
104
|
+
if (isToggle.value && !props.disabled) pressed.value = true
|
|
105
|
+
}
|
|
106
|
+
function onPointerUp() {
|
|
107
|
+
pressed.value = false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function onClick() {
|
|
111
|
+
if (isToggle.value && !props.disabled) emit('update:checked', !props.checked)
|
|
112
|
+
}
|
|
113
|
+
|
|
57
114
|
/*
|
|
58
115
|
* State layer via a `before:` overlay (same technique MButton uses) rather than a direct
|
|
59
116
|
* `hover:bg-*`/`active:bg-*` utility: a solid `bg-primary`/`bg-secondary-container`
|
|
@@ -76,6 +133,7 @@ const base =
|
|
|
76
133
|
// `disabled:text-on-surface/38` in `base` above, exactly like the real `outlinedIconButtonBorder`
|
|
77
134
|
// (which literally reuses `LocalContentColor` at the same disabled opacity as the icon).
|
|
78
135
|
const disabledContainerClasses = computed(() => {
|
|
136
|
+
if (props.variant === 'outlined' && props.checked) return 'disabled:bg-on-surface/10'
|
|
79
137
|
switch (props.variant) {
|
|
80
138
|
case 'filled':
|
|
81
139
|
case 'tonal':
|
|
@@ -87,19 +145,26 @@ const disabledContainerClasses = computed(() => {
|
|
|
87
145
|
|
|
88
146
|
const shapeClass = computed(() => props.shape === 'squared' ? resolved.value.squareRadius : 'rounded-full')
|
|
89
147
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
148
|
+
|
|
149
|
+
// Toggle colors: the Selected*/Unselected* tokens of each variant's *IconButtonTokens. Unchecked
|
|
150
|
+
// filled/tonal differ from the plain button's colors, so the checked state stands out.
|
|
151
|
+
const toggleClasses = computed(() => {
|
|
152
|
+
const on = props.checked
|
|
153
|
+
switch (props.variant) {
|
|
154
|
+
case 'filled':
|
|
155
|
+
return on ? 'bg-primary text-on-primary' : 'bg-surface-container text-on-surface-variant'
|
|
156
|
+
case 'tonal':
|
|
157
|
+
return on ? 'bg-secondary text-on-secondary' : 'bg-secondary-container text-on-secondary-container'
|
|
158
|
+
case 'outlined':
|
|
159
|
+
// outlinedIconToggleButtonBorder: no border once checked
|
|
160
|
+
return on ? 'bg-inverse-surface text-inverse-on-surface' : 'border border-current text-on-surface-variant'
|
|
161
|
+
default:
|
|
162
|
+
return on ? 'text-primary' : 'text-on-surface-variant'
|
|
163
|
+
}
|
|
164
|
+
})
|
|
101
165
|
|
|
102
166
|
const variantClasses = computed(() => {
|
|
167
|
+
if (isToggle.value) return toggleClasses.value
|
|
103
168
|
switch (props.variant) {
|
|
104
169
|
case 'filled':
|
|
105
170
|
// Real IconButton.kt has no elevation tokens at all for any variant — flat, unlike Button
|
|
@@ -119,14 +184,21 @@ const variantClasses = computed(() => {
|
|
|
119
184
|
<template>
|
|
120
185
|
<component
|
|
121
186
|
:is="tag"
|
|
122
|
-
|
|
123
|
-
:
|
|
187
|
+
ref="rootEl"
|
|
188
|
+
:to="tag === 'RouterLink' ? to : undefined"
|
|
189
|
+
:type="tag === 'RouterLink' ? undefined : 'button'"
|
|
124
190
|
:aria-label="label || undefined"
|
|
191
|
+
:aria-pressed="isToggle ? checked : undefined"
|
|
125
192
|
:disabled="disabled"
|
|
126
193
|
:class="[base, shapeClass, variantClasses, disabledContainerClasses]"
|
|
127
194
|
:style="{ width: `${resolved.px}px`, height: `${resolved.px}px` }"
|
|
128
|
-
|
|
195
|
+
v-ripple="{ disabled, color: rippleColor }"
|
|
196
|
+
@pointerdown="onPointerDown"
|
|
197
|
+
@pointerup="onPointerUp"
|
|
198
|
+
@pointerleave="onPointerUp"
|
|
199
|
+
@pointercancel="onPointerUp"
|
|
200
|
+
@click="onClick"
|
|
129
201
|
>
|
|
130
|
-
<MIcon :name="icon" :size="resolved.icon" />
|
|
202
|
+
<MIcon :name="checked && checkedIcon ? checkedIcon : icon" :size="resolved.icon" :filled="!!checked" />
|
|
131
203
|
</component>
|
|
132
204
|
</template>
|