@m3ui-vue/m3ui-vue 0.6.4 → 0.7.1
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 +4 -0
- package/dist/{MMenuItem-C7jKU-Qh.js → MMenuItem-xQ1x6-DH.js} +38 -21
- package/dist/MMenuItem-xQ1x6-DH.js.map +1 -0
- package/dist/code-editor.js +1 -1
- package/dist/components/MCheckbox.vue.d.ts +2 -0
- package/dist/components/MFab.vue.d.ts +24 -2
- package/dist/components/MFabMenu.vue.d.ts +37 -0
- package/dist/components/MLoadingIndicator.vue.d.ts +13 -0
- package/dist/components/MPullToRefresh.vue.d.ts +30 -0
- package/dist/components/MSearchBar.vue.d.ts +57 -0
- package/dist/components/MSwitch.vue.d.ts +2 -0
- package/dist/components/MTopAppBar.vue.d.ts +4 -0
- package/dist/composables/useLocale.d.ts +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/locales/index.js +7 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +2031 -1539
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles/theme.css +1 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-BKsIWNix.js → useLocale-DbREg9Zn.js} +2 -1
- package/dist/useLocale-DbREg9Zn.js.map +1 -0
- package/package.json +1 -1
- package/src/components/MAutocomplete.vue +1 -1
- package/src/components/MBottomSheet.vue +1 -1
- package/src/components/MButton.vue +18 -2
- package/src/components/MCard.vue +10 -1
- package/src/components/MCheckbox.vue +38 -23
- package/src/components/MChip.vue +10 -1
- package/src/components/MColorPickerModal.vue +1 -1
- package/src/components/MCommandPalette.vue +1 -1
- package/src/components/MDatePickerModal.vue +1 -1
- package/src/components/MDateRangePickerModal.vue +1 -1
- package/src/components/MDialog.vue +1 -1
- package/src/components/MFab.vue +66 -11
- package/src/components/MFabMenu.vue +167 -0
- package/src/components/MIconButton.vue +16 -2
- package/src/components/MLoadingIndicator.vue +184 -0
- package/src/components/MMultiAutocomplete.vue +1 -1
- package/src/components/MMultiSelect.vue +1 -1
- package/src/components/MNavigationDrawer.vue +1 -1
- package/src/components/MOverlay.vue +1 -1
- package/src/components/MPullToRefresh.vue +180 -0
- package/src/components/MRadio.vue +38 -36
- package/src/components/MSearchBar.vue +237 -0
- package/src/components/MSelect.vue +1 -1
- package/src/components/MSideSheet.vue +1 -1
- package/src/components/MSlider.vue +42 -20
- package/src/components/MSpotlightSearch.vue +1 -1
- package/src/components/MSwitch.vue +54 -27
- package/src/components/MTabs.vue +72 -33
- package/src/components/MTimePickerModal.vue +1 -1
- package/src/components/MTopAppBar.vue +16 -8
- package/src/components/MTour.vue +1 -1
- package/src/composables/useLocale.ts +2 -0
- package/src/index.ts +5 -0
- package/src/locales/de.ts +1 -0
- package/src/locales/es.ts +1 -0
- package/src/locales/fr.ts +1 -0
- package/src/locales/ja.ts +1 -0
- package/src/locales/ko.ts +1 -0
- package/src/locales/pt.ts +1 -0
- package/src/locales/zh.ts +1 -0
- package/src/styles/theme.css +1 -0
- package/dist/MMenuItem-C7jKU-Qh.js.map +0 -1
- package/dist/useLocale-BKsIWNix.js.map +0 -1
|
@@ -31,45 +31,47 @@ const checkedColor: Record<string, string> = {
|
|
|
31
31
|
class="inline-flex items-center gap-3 select-none"
|
|
32
32
|
:class="disabled ? 'cursor-not-allowed opacity-[0.38]' : 'cursor-pointer'"
|
|
33
33
|
>
|
|
34
|
-
<span class="relative flex h-
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
<span class="relative -m-3.5 flex h-12 w-12 shrink-0 items-center justify-center">
|
|
35
|
+
<span class="relative flex h-5 w-5">
|
|
36
|
+
<input
|
|
37
|
+
:id="id"
|
|
38
|
+
type="radio"
|
|
39
|
+
class="sr-only"
|
|
40
|
+
:checked="isChecked"
|
|
41
|
+
:disabled="disabled"
|
|
42
|
+
@change="emit('update:modelValue', value)"
|
|
43
|
+
/>
|
|
43
44
|
|
|
44
|
-
<!--
|
|
45
|
-
SVG radio: vector circles sharing center (10,10) stay round + concentric
|
|
46
|
-
at any zoom. Outer ring uses r=8 (not 9) so the 2px stroke (7..9) leaves
|
|
47
|
-
~1px of clearance to the viewBox edge — prevents the border getting
|
|
48
|
-
clipped at certain zoom levels.
|
|
49
|
-
-->
|
|
50
|
-
<svg
|
|
51
|
-
viewBox="0 0 20 20"
|
|
52
|
-
class="h-full w-full transition-colors duration-150"
|
|
53
|
-
:class="isChecked ? checkedColor[color] : 'text-on-surface-variant'"
|
|
54
|
-
aria-hidden="true"
|
|
55
|
-
>
|
|
56
|
-
<circle cx="10" cy="10" r="8" fill="none" stroke="currentColor" stroke-width="2" />
|
|
57
45
|
<!--
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
the dot itself, so it grows symmetrically in place.
|
|
46
|
+
SVG radio: vector circles sharing center (10,10) stay round + concentric
|
|
47
|
+
at any zoom. Outer ring uses r=8 (not 9) so the 2px stroke (7..9) leaves
|
|
48
|
+
~1px of clearance to the viewBox edge — prevents the border getting
|
|
49
|
+
clipped at certain zoom levels.
|
|
63
50
|
-->
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
fill="currentColor"
|
|
71
|
-
|
|
72
|
-
|
|
51
|
+
<svg
|
|
52
|
+
viewBox="0 0 20 20"
|
|
53
|
+
class="h-full w-full transition-colors duration-150"
|
|
54
|
+
:class="isChecked ? checkedColor[color] : 'text-on-surface-variant'"
|
|
55
|
+
aria-hidden="true"
|
|
56
|
+
>
|
|
57
|
+
<circle cx="10" cy="10" r="8" fill="none" stroke="currentColor" stroke-width="2" />
|
|
58
|
+
<!--
|
|
59
|
+
Dot scaled via CSS, but the transform-origin is pinned to the circle's
|
|
60
|
+
own bounding box center (transform-box: fill-box). Without this, the SVG
|
|
61
|
+
element origin is (0,0) of the viewBox, so scale() grows from a corner
|
|
62
|
+
and the dot visibly slides to the center. fill-box fixes the origin to
|
|
63
|
+
the dot itself, so it grows symmetrically in place.
|
|
64
|
+
-->
|
|
65
|
+
<circle
|
|
66
|
+
class="m3-radio-dot"
|
|
67
|
+
:class="{ 'is-checked': isChecked }"
|
|
68
|
+
cx="10"
|
|
69
|
+
cy="10"
|
|
70
|
+
r="4.5"
|
|
71
|
+
fill="currentColor"
|
|
72
|
+
/>
|
|
73
|
+
</svg>
|
|
74
|
+
</span>
|
|
73
75
|
</span>
|
|
74
76
|
|
|
75
77
|
<span v-if="label" class="text-body-large text-on-surface">{{ label }}</span>
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch, onMounted, onUnmounted, nextTick, useId } from 'vue'
|
|
3
|
+
import MIcon from './MIcon.vue'
|
|
4
|
+
import MIconButton from './MIconButton.vue'
|
|
5
|
+
import MSpinner from './MSpinner.vue'
|
|
6
|
+
import { useLocale } from '../composables/useLocale'
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(
|
|
9
|
+
defineProps<{
|
|
10
|
+
modelValue?: string
|
|
11
|
+
/** Controls the expanded/collapsed state — also works uncontrolled if omitted. */
|
|
12
|
+
expanded?: boolean
|
|
13
|
+
placeholder?: string
|
|
14
|
+
/** 'docked' grows into a rounded panel anchored below the bar (default).
|
|
15
|
+
* 'fullscreen' takes over the whole viewport, matching M3's mobile
|
|
16
|
+
* search pattern — the leading icon becomes a back button either way. */
|
|
17
|
+
variant?: 'docked' | 'fullscreen'
|
|
18
|
+
leadingIcon?: string
|
|
19
|
+
/** Which side of the *collapsed* bar the leading icon sits on. The
|
|
20
|
+
* expanded panel's back button always stays at the start regardless —
|
|
21
|
+
* that's a near-universal "go back" convention. */
|
|
22
|
+
iconPosition?: 'start' | 'end'
|
|
23
|
+
/** Centers the input/placeholder text instead of the M3-standard start
|
|
24
|
+
* alignment (an iOS-style look some apps use for the collapsed bar). */
|
|
25
|
+
textAlign?: 'start' | 'center'
|
|
26
|
+
loading?: boolean
|
|
27
|
+
clearable?: boolean
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
}>(),
|
|
30
|
+
{
|
|
31
|
+
modelValue: '',
|
|
32
|
+
variant: 'docked',
|
|
33
|
+
leadingIcon: 'search',
|
|
34
|
+
iconPosition: 'start',
|
|
35
|
+
textAlign: 'start',
|
|
36
|
+
loading: false,
|
|
37
|
+
clearable: true,
|
|
38
|
+
disabled: false,
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const emit = defineEmits<{
|
|
43
|
+
'update:modelValue': [string]
|
|
44
|
+
'update:expanded': [boolean]
|
|
45
|
+
search: [string]
|
|
46
|
+
}>()
|
|
47
|
+
|
|
48
|
+
const locale = useLocale()
|
|
49
|
+
const id = useId()
|
|
50
|
+
|
|
51
|
+
const expanded = ref(props.expanded ?? false)
|
|
52
|
+
watch(
|
|
53
|
+
() => props.expanded,
|
|
54
|
+
(v) => { if (v !== undefined && v !== expanded.value) expanded.value = v },
|
|
55
|
+
)
|
|
56
|
+
watch(expanded, (v) => emit('update:expanded', v))
|
|
57
|
+
|
|
58
|
+
const barEl = ref<HTMLElement | null>(null)
|
|
59
|
+
const panelEl = ref<HTMLElement | null>(null)
|
|
60
|
+
const inputEl = ref<HTMLInputElement | null>(null)
|
|
61
|
+
const panelPos = ref({ top: '0px', left: '0px', width: '0px' })
|
|
62
|
+
|
|
63
|
+
function computePanelPos() {
|
|
64
|
+
if (!barEl.value) return
|
|
65
|
+
const rect = barEl.value.getBoundingClientRect()
|
|
66
|
+
panelPos.value = { top: `${rect.top}px`, left: `${rect.left}px`, width: `${rect.width}px` }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function open() {
|
|
70
|
+
if (props.disabled || expanded.value) return
|
|
71
|
+
if (props.variant === 'docked') computePanelPos()
|
|
72
|
+
expanded.value = true
|
|
73
|
+
nextTick(() => inputEl.value?.focus())
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function close() {
|
|
77
|
+
if (!expanded.value) return
|
|
78
|
+
expanded.value = false
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function onInput(e: Event) {
|
|
82
|
+
emit('update:modelValue', (e.target as HTMLInputElement).value)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function onClear() {
|
|
86
|
+
emit('update:modelValue', '')
|
|
87
|
+
nextTick(() => inputEl.value?.focus())
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function onKeydown(e: KeyboardEvent) {
|
|
91
|
+
if (e.key === 'Escape') {
|
|
92
|
+
close()
|
|
93
|
+
inputEl.value?.blur()
|
|
94
|
+
} else if (e.key === 'Enter') {
|
|
95
|
+
emit('search', props.modelValue)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function onOutsideClick(e: MouseEvent) {
|
|
100
|
+
if (props.variant !== 'docked' || !expanded.value) return
|
|
101
|
+
const t = e.target as Node
|
|
102
|
+
if (barEl.value?.contains(t) || panelEl.value?.contains(t)) return
|
|
103
|
+
close()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function onScroll(e: Event) {
|
|
107
|
+
if (props.variant !== 'docked' || !expanded.value) return
|
|
108
|
+
if (panelEl.value?.contains(e.target as Node)) return
|
|
109
|
+
close()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
onMounted(() => {
|
|
113
|
+
document.addEventListener('mousedown', onOutsideClick)
|
|
114
|
+
window.addEventListener('scroll', onScroll, true)
|
|
115
|
+
})
|
|
116
|
+
onUnmounted(() => {
|
|
117
|
+
document.removeEventListener('mousedown', onOutsideClick)
|
|
118
|
+
window.removeEventListener('scroll', onScroll, true)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
watch(expanded, (v) => {
|
|
122
|
+
if (v && props.variant === 'fullscreen') document.body.style.overflow = 'hidden'
|
|
123
|
+
else document.body.style.overflow = ''
|
|
124
|
+
})
|
|
125
|
+
onUnmounted(() => { document.body.style.overflow = '' })
|
|
126
|
+
</script>
|
|
127
|
+
|
|
128
|
+
<template>
|
|
129
|
+
<div ref="barEl" class="relative w-full">
|
|
130
|
+
<div
|
|
131
|
+
v-show="!expanded"
|
|
132
|
+
class="flex h-14 items-center gap-3 rounded-full bg-surface-container-high px-4 shadow-elevation-1 transition-shadow duration-150"
|
|
133
|
+
:class="disabled ? 'pointer-events-none opacity-[0.38]' : ''"
|
|
134
|
+
>
|
|
135
|
+
<span class="inline-flex shrink-0 items-center" :class="iconPosition === 'end' ? 'order-last' : ''">
|
|
136
|
+
<slot name="leading">
|
|
137
|
+
<MIcon :name="leadingIcon" :size="20" class="text-on-surface" />
|
|
138
|
+
</slot>
|
|
139
|
+
</span>
|
|
140
|
+
<input
|
|
141
|
+
:id="id"
|
|
142
|
+
type="text"
|
|
143
|
+
role="searchbox"
|
|
144
|
+
:value="modelValue"
|
|
145
|
+
:placeholder="placeholder ?? locale.search"
|
|
146
|
+
:disabled="disabled"
|
|
147
|
+
:aria-expanded="expanded"
|
|
148
|
+
class="w-full bg-transparent text-body-large text-on-surface outline-none placeholder:text-on-surface-variant"
|
|
149
|
+
:class="textAlign === 'center' ? 'text-center' : ''"
|
|
150
|
+
@focus="open"
|
|
151
|
+
@input="onInput"
|
|
152
|
+
@keydown="onKeydown"
|
|
153
|
+
/>
|
|
154
|
+
<button
|
|
155
|
+
v-if="clearable && modelValue && !disabled"
|
|
156
|
+
type="button"
|
|
157
|
+
class="flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
158
|
+
@mousedown.prevent="onClear"
|
|
159
|
+
>
|
|
160
|
+
<MIcon name="close" :size="18" />
|
|
161
|
+
</button>
|
|
162
|
+
<slot name="trailing" />
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<Teleport to="body">
|
|
167
|
+
<Transition :name="variant === 'fullscreen' ? 'm3-searchbar-full' : 'm3-searchbar-docked'">
|
|
168
|
+
<div
|
|
169
|
+
v-if="expanded"
|
|
170
|
+
ref="panelEl"
|
|
171
|
+
class="fixed z-500 flex flex-col overflow-hidden bg-surface-container-high"
|
|
172
|
+
:class="variant === 'fullscreen' ? 'inset-0' : 'max-h-[70vh] rounded-[28px] shadow-elevation-3'"
|
|
173
|
+
:style="variant === 'docked' ? panelPos : undefined"
|
|
174
|
+
>
|
|
175
|
+
<div
|
|
176
|
+
class="flex shrink-0 items-center gap-3 px-4"
|
|
177
|
+
:class="variant === 'fullscreen' ? 'h-[72px]' : 'h-14'"
|
|
178
|
+
>
|
|
179
|
+
<MIconButton
|
|
180
|
+
icon="arrow_back"
|
|
181
|
+
:label="locale.close"
|
|
182
|
+
variant="standard"
|
|
183
|
+
@click="close"
|
|
184
|
+
/>
|
|
185
|
+
<input
|
|
186
|
+
ref="inputEl"
|
|
187
|
+
type="text"
|
|
188
|
+
role="searchbox"
|
|
189
|
+
:value="modelValue"
|
|
190
|
+
:placeholder="placeholder ?? locale.search"
|
|
191
|
+
class="w-full bg-transparent text-body-large text-on-surface outline-none placeholder:text-on-surface-variant"
|
|
192
|
+
:class="textAlign === 'center' ? 'text-center' : ''"
|
|
193
|
+
@input="onInput"
|
|
194
|
+
@keydown="onKeydown"
|
|
195
|
+
/>
|
|
196
|
+
<MSpinner v-if="loading" :size="20" class="shrink-0 text-on-surface-variant" />
|
|
197
|
+
<button
|
|
198
|
+
v-else-if="clearable && modelValue"
|
|
199
|
+
type="button"
|
|
200
|
+
class="flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
201
|
+
@mousedown.prevent="onClear"
|
|
202
|
+
>
|
|
203
|
+
<MIcon name="close" :size="18" />
|
|
204
|
+
</button>
|
|
205
|
+
<slot name="trailing" />
|
|
206
|
+
</div>
|
|
207
|
+
|
|
208
|
+
<div class="h-px shrink-0 bg-outline-variant" />
|
|
209
|
+
|
|
210
|
+
<div class="flex-1 overflow-y-auto">
|
|
211
|
+
<slot />
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
</Transition>
|
|
215
|
+
</Teleport>
|
|
216
|
+
</template>
|
|
217
|
+
|
|
218
|
+
<style scoped>
|
|
219
|
+
.m3-searchbar-docked-enter-active,
|
|
220
|
+
.m3-searchbar-docked-leave-active {
|
|
221
|
+
transition: opacity 150ms ease, transform 150ms cubic-bezier(0.2, 0, 0, 1);
|
|
222
|
+
transform-origin: top center;
|
|
223
|
+
}
|
|
224
|
+
.m3-searchbar-docked-enter-from,
|
|
225
|
+
.m3-searchbar-docked-leave-to {
|
|
226
|
+
opacity: 0;
|
|
227
|
+
transform: scaleY(0.9);
|
|
228
|
+
}
|
|
229
|
+
.m3-searchbar-full-enter-active,
|
|
230
|
+
.m3-searchbar-full-leave-active {
|
|
231
|
+
transition: opacity 150ms ease;
|
|
232
|
+
}
|
|
233
|
+
.m3-searchbar-full-enter-from,
|
|
234
|
+
.m3-searchbar-full-leave-to {
|
|
235
|
+
opacity: 0;
|
|
236
|
+
}
|
|
237
|
+
</style>
|
|
@@ -302,7 +302,7 @@ const labelClasses = computed(() => {
|
|
|
302
302
|
<Transition name="m3-select-modal">
|
|
303
303
|
<div
|
|
304
304
|
v-if="modalOpen && mode === 'modal'"
|
|
305
|
-
class="fixed inset-0 z-50 flex items-center justify-center bg-
|
|
305
|
+
class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/40 p-4"
|
|
306
306
|
@click.self="closeModal"
|
|
307
307
|
>
|
|
308
308
|
<div class="select-modal-box flex max-h-[80vh] w-full max-w-sm flex-col overflow-hidden rounded-[28px] bg-surface-container-high shadow-elevation-3">
|
|
@@ -42,7 +42,7 @@ const panelStyle = computed(() => ({
|
|
|
42
42
|
<Transition name="ss" :duration="{ enter: 320, leave: 280 }">
|
|
43
43
|
<div v-if="modelValue" class="fixed inset-0 z-200 flex justify-end">
|
|
44
44
|
<!-- Scrim -->
|
|
45
|
-
<div class="ss-scrim absolute inset-0 bg-
|
|
45
|
+
<div class="ss-scrim absolute inset-0 bg-scrim/40" @click="close" />
|
|
46
46
|
|
|
47
47
|
<!-- Panel -->
|
|
48
48
|
<aside
|
|
@@ -44,6 +44,7 @@ const emit = defineEmits<{ 'update:modelValue': [number | [number, number]] }>()
|
|
|
44
44
|
|
|
45
45
|
const trackEl = ref<HTMLElement>()
|
|
46
46
|
const dragging = ref<false | 'single' | 0 | 1>(false)
|
|
47
|
+
const focused = ref(false)
|
|
47
48
|
const isVertical = computed(() => props.orientation === 'vertical')
|
|
48
49
|
const isRange = computed(() => props.variant === 'range')
|
|
49
50
|
const isCentered = computed(() => props.variant === 'centered')
|
|
@@ -81,7 +82,9 @@ const endDotHidden = computed(() => {
|
|
|
81
82
|
})
|
|
82
83
|
|
|
83
84
|
const sizeMap = {
|
|
84
|
-
|
|
85
|
+
// thumbH 44 matches SliderTokens.HandleHeight exactly — hitArea bumped from
|
|
86
|
+
// 38 to 46 to keep containing it (was sized for the old 32px handle).
|
|
87
|
+
xs: { track: 16, thumbW: 4, thumbH: 44, dot: 4, gap: 6, hitArea: 46, radius: 6, dotInset: 12, thumbInset: 5, iconSize: 14, thumbIconSize: 22 },
|
|
85
88
|
sm: { track: 28, thumbW: 4, thumbH: 40, dot: 5, gap: 7, hitArea: 46, radius: 8, dotInset: 13, thumbInset: 6, iconSize: 16, thumbIconSize: 28 },
|
|
86
89
|
md: { track: 54, thumbW: 5, thumbH: 62, dot: 5, gap: 8, hitArea: 66, radius: 12, dotInset: 15, thumbInset: 7, iconSize: 20, thumbIconSize: 42 },
|
|
87
90
|
lg: { track: 72, thumbW: 5, thumbH: 78, dot: 6, gap: 10, hitArea: 82, radius: 14, dotInset: 17, thumbInset: 8, iconSize: 24, thumbIconSize: 52 },
|
|
@@ -105,26 +108,37 @@ const gap = computed(() => {
|
|
|
105
108
|
return Math.max(s.value.gap, s.value.thumbIconSize / 2 + 4)
|
|
106
109
|
})
|
|
107
110
|
|
|
108
|
-
const
|
|
109
|
-
primary:
|
|
110
|
-
secondary:
|
|
111
|
-
tertiary:
|
|
112
|
-
error:
|
|
111
|
+
const activeColorMap: Record<string, string> = {
|
|
112
|
+
primary: 'var(--color-primary)',
|
|
113
|
+
secondary: 'var(--color-secondary)',
|
|
114
|
+
tertiary: 'var(--color-tertiary)',
|
|
115
|
+
error: 'var(--color-error)',
|
|
113
116
|
}
|
|
114
117
|
// `fillColor`/`thumbColor` accept a custom CSS color (hex, rgb(), a var, …) —
|
|
115
118
|
// not just an M3 role — that's the point of a "custom color" prop, otherwise
|
|
116
119
|
// it'd just duplicate `color`. A known role name still works as a shortcut.
|
|
117
|
-
|
|
118
|
-
// shade is derived by mixing it down against the current surface.
|
|
119
|
-
function resolvePalette(custom: string | undefined, base: 'primary' | 'secondary' | 'tertiary' | 'error') {
|
|
120
|
+
function resolveActive(custom: string | undefined, base: 'primary' | 'secondary' | 'tertiary' | 'error') {
|
|
120
121
|
const value = custom ?? base
|
|
121
|
-
|
|
122
|
-
return { active: value, inactive: `color-mix(in srgb, ${value} 30%, var(--color-surface-container-highest))` }
|
|
122
|
+
return activeColorMap[value] ?? value
|
|
123
123
|
}
|
|
124
|
+
|
|
125
|
+
// M3's SliderTokens fix the inactive track/stop-indicator color to
|
|
126
|
+
// secondary-container regardless of the active track's color (Inactive/Focus/
|
|
127
|
+
// Pressed TrackColor are all SecondaryContainer) — never derived from the
|
|
128
|
+
// active hue the way MCheckbox/MChip's containers are. Disabled state also
|
|
129
|
+
// isn't a single blanket opacity: DisabledActiveTrackOpacity/DisabledHandleOpacity
|
|
130
|
+
// = 38% on-surface, DisabledInactiveTrackOpacity = 12% on-surface.
|
|
131
|
+
const DISABLED_ACTIVE = 'color-mix(in srgb, var(--color-on-surface) 38%, transparent)'
|
|
132
|
+
const DISABLED_INACTIVE = 'color-mix(in srgb, var(--color-on-surface) 12%, transparent)'
|
|
133
|
+
|
|
124
134
|
// `ct` (fill + corner dot) and `thumbCt` (thumb bar/icon) each fall back to the
|
|
125
135
|
// base `color` prop, but can be overridden independently via `fillColor`/`thumbColor`.
|
|
126
|
-
const ct = computed(() =>
|
|
127
|
-
|
|
136
|
+
const ct = computed(() => props.disabled
|
|
137
|
+
? { active: DISABLED_ACTIVE, inactive: DISABLED_INACTIVE }
|
|
138
|
+
: { active: resolveActive(props.fillColor, props.color), inactive: 'var(--color-secondary-container)' })
|
|
139
|
+
const thumbCt = computed(() => props.disabled
|
|
140
|
+
? { active: DISABLED_ACTIVE, inactive: DISABLED_INACTIVE }
|
|
141
|
+
: { active: resolveActive(props.thumbColor, props.color), inactive: 'var(--color-secondary-container)' })
|
|
128
142
|
|
|
129
143
|
function clamp(v: number) {
|
|
130
144
|
const stepped = Math.round((v - props.min) / props.step) * props.step + props.min
|
|
@@ -330,9 +344,13 @@ function thumbPos(pct: number) {
|
|
|
330
344
|
transition: nd.value ? 'left 75ms ease, bottom 75ms ease, transform 80ms ease' : 'transform 80ms ease',
|
|
331
345
|
}
|
|
332
346
|
// Pressed state pinches the thumb thinner along the travel axis (like the
|
|
333
|
-
// official M3 slider handle) while slightly growing the cross axis.
|
|
347
|
+
// official M3 slider handle) while slightly growing the cross axis. Exact
|
|
348
|
+
// ratio matches SliderTokens.PressedHandleWidth/FocusHandleWidth = 2dp,
|
|
349
|
+
// i.e. half of the base 4dp width — applies on keyboard focus too, not
|
|
350
|
+
// just an active pointer drag (Compose's isFocused covers both).
|
|
351
|
+
const isNarrowed = isDragging || focused.value
|
|
334
352
|
const grow = isDragging ? 1.08 : 1
|
|
335
|
-
const narrow =
|
|
353
|
+
const narrow = isNarrowed ? 0.5 : 1
|
|
336
354
|
if (isVertical.value) {
|
|
337
355
|
base.left = '50%'
|
|
338
356
|
base.bottom = clampedPos(pct)
|
|
@@ -413,14 +431,16 @@ const tooltipPct = computed(() => {
|
|
|
413
431
|
:aria-valuemax="max"
|
|
414
432
|
:aria-disabled="disabled || undefined"
|
|
415
433
|
:aria-orientation="orientation"
|
|
416
|
-
class="relative touch-none cursor-pointer outline-none"
|
|
417
|
-
:class="disabled && 'cursor-not-allowed
|
|
434
|
+
class="group relative touch-none cursor-pointer outline-none"
|
|
435
|
+
:class="disabled && 'cursor-not-allowed'"
|
|
418
436
|
:style="isVertical
|
|
419
437
|
? { width: `${s.hitArea}px`, minHeight: '160px', height: '100%' }
|
|
420
438
|
: { height: `${s.hitArea}px`, width: '100%' }
|
|
421
439
|
"
|
|
422
440
|
@pointerdown="onPointerDown"
|
|
423
441
|
@keydown="onKeyDown"
|
|
442
|
+
@focus="focused = true"
|
|
443
|
+
@blur="focused = false"
|
|
424
444
|
>
|
|
425
445
|
<!-- Track container -->
|
|
426
446
|
<div
|
|
@@ -565,13 +585,15 @@ const tooltipPct = computed(() => {
|
|
|
565
585
|
</template>
|
|
566
586
|
</div>
|
|
567
587
|
|
|
568
|
-
<!-- Thumb(s)
|
|
588
|
+
<!-- Thumb(s) — only the pctLo thumb takes keyboard input (arrow keys only
|
|
589
|
+
move index 0 in range mode, see onKeyDown), so it's the only one that
|
|
590
|
+
gets the focus-visible ring. -->
|
|
569
591
|
<template v-if="thumbIcon">
|
|
570
|
-
<MIcon :name="thumbIcon" :size="s.thumbIconSize" class="pointer-events-none" :style="thumbIconPos(pctLo)" />
|
|
592
|
+
<MIcon :name="thumbIcon" :size="s.thumbIconSize" class="pointer-events-none rounded-full group-focus-visible:ring-2 group-focus-visible:ring-primary group-focus-visible:ring-offset-2 group-focus-visible:ring-offset-surface" :style="thumbIconPos(pctLo)" />
|
|
571
593
|
<MIcon v-if="isRange" :name="thumbIcon" :size="s.thumbIconSize" class="pointer-events-none" :style="thumbIconPos(pctHi)" />
|
|
572
594
|
</template>
|
|
573
595
|
<template v-else>
|
|
574
|
-
<div class="pointer-events-none" :style="thumbPos(pctLo)" />
|
|
596
|
+
<div class="pointer-events-none group-focus-visible:ring-2 group-focus-visible:ring-primary group-focus-visible:ring-offset-2 group-focus-visible:ring-offset-surface" :style="thumbPos(pctLo)" />
|
|
575
597
|
<div v-if="isRange" class="pointer-events-none" :style="thumbPos(pctHi)" />
|
|
576
598
|
</template>
|
|
577
599
|
|
|
@@ -141,7 +141,7 @@ onBeforeUnmount(() => {
|
|
|
141
141
|
<Transition name="m3-spot">
|
|
142
142
|
<div
|
|
143
143
|
v-if="modelValue"
|
|
144
|
-
class="fixed inset-0 z-50 flex items-start justify-center bg-
|
|
144
|
+
class="fixed inset-0 z-50 flex items-start justify-center bg-scrim/50 pt-[12vh]"
|
|
145
145
|
@click.self="close"
|
|
146
146
|
>
|
|
147
147
|
<div class="spot-box flex w-full max-w-xl flex-col overflow-hidden rounded-2xl bg-surface-container-high shadow-elevation-3">
|
|
@@ -3,12 +3,37 @@ import { computed } from 'vue'
|
|
|
3
3
|
import MIcon from './MIcon.vue'
|
|
4
4
|
|
|
5
5
|
const props = withDefaults(
|
|
6
|
-
defineProps<{
|
|
7
|
-
|
|
6
|
+
defineProps<{
|
|
7
|
+
modelValue: boolean
|
|
8
|
+
disabled?: boolean
|
|
9
|
+
label?: string
|
|
10
|
+
color?: 'primary' | 'secondary' | 'tertiary' | 'error'
|
|
11
|
+
}>(),
|
|
12
|
+
{ disabled: false, color: 'primary' },
|
|
8
13
|
)
|
|
9
14
|
|
|
10
15
|
const emit = defineEmits<{ 'update:modelValue': [boolean] }>()
|
|
11
16
|
|
|
17
|
+
// Same 4 named colors as MRadio/MCheckbox's color prop.
|
|
18
|
+
const trackClasses: Record<string, string> = {
|
|
19
|
+
primary: 'border-primary bg-primary',
|
|
20
|
+
secondary: 'border-secondary bg-secondary',
|
|
21
|
+
tertiary: 'border-tertiary bg-tertiary',
|
|
22
|
+
error: 'border-error bg-error',
|
|
23
|
+
}
|
|
24
|
+
const thumbClasses: Record<string, string> = {
|
|
25
|
+
primary: 'bg-on-primary',
|
|
26
|
+
secondary: 'bg-on-secondary',
|
|
27
|
+
tertiary: 'bg-on-tertiary',
|
|
28
|
+
error: 'bg-on-error',
|
|
29
|
+
}
|
|
30
|
+
const iconClasses: Record<string, string> = {
|
|
31
|
+
primary: 'text-primary',
|
|
32
|
+
secondary: 'text-secondary',
|
|
33
|
+
tertiary: 'text-tertiary',
|
|
34
|
+
error: 'text-error',
|
|
35
|
+
}
|
|
36
|
+
|
|
12
37
|
// All thumb transforms live here so each direction can use its own easing curve.
|
|
13
38
|
// translateY(-50%) vertically centres the 24px thumb in the 32px track.
|
|
14
39
|
// ON → spring cubic-bezier: overshoots ~2px then settles → satisfying "click"
|
|
@@ -28,34 +53,36 @@ const thumbStyle = computed(() => ({
|
|
|
28
53
|
class="inline-flex items-center gap-3 select-none"
|
|
29
54
|
:class="disabled ? 'cursor-not-allowed opacity-[0.38]' : 'cursor-pointer'"
|
|
30
55
|
>
|
|
31
|
-
<span
|
|
32
|
-
class="relative inline-flex h-8 w-[52px] shrink-0 items-center rounded-full border-2 transition-colors duration-200"
|
|
33
|
-
:class="modelValue ? 'border-primary bg-primary' : 'border-outline bg-surface-container-highest'"
|
|
34
|
-
>
|
|
35
|
-
<input
|
|
36
|
-
type="checkbox"
|
|
37
|
-
class="sr-only"
|
|
38
|
-
:checked="modelValue"
|
|
39
|
-
:disabled="disabled"
|
|
40
|
-
@change="emit('update:modelValue', !modelValue)"
|
|
41
|
-
/>
|
|
42
|
-
|
|
43
|
-
<!-- Thumb: position + size animated via inline style (allows per-direction easing) -->
|
|
56
|
+
<span class="relative -my-2 inline-flex h-12 shrink-0 items-center">
|
|
44
57
|
<span
|
|
45
|
-
class="
|
|
46
|
-
:class="modelValue ?
|
|
47
|
-
:style="thumbStyle"
|
|
58
|
+
class="relative inline-flex h-8 w-[52px] items-center rounded-full border-2 transition-colors duration-200"
|
|
59
|
+
:class="modelValue ? trackClasses[color] : 'border-outline bg-surface-container-highest'"
|
|
48
60
|
>
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
<input
|
|
62
|
+
type="checkbox"
|
|
63
|
+
class="sr-only"
|
|
64
|
+
:checked="modelValue"
|
|
65
|
+
:disabled="disabled"
|
|
66
|
+
@change="emit('update:modelValue', !modelValue)"
|
|
67
|
+
/>
|
|
68
|
+
|
|
69
|
+
<!-- Thumb: position + size animated via inline style (allows per-direction easing) -->
|
|
70
|
+
<span
|
|
71
|
+
class="absolute left-1 top-1/2 flex h-6 w-6 items-center justify-center rounded-full will-change-transform"
|
|
72
|
+
:class="modelValue ? [thumbClasses[color], 'shadow-sm'] : 'bg-outline'"
|
|
73
|
+
:style="thumbStyle"
|
|
56
74
|
>
|
|
57
|
-
<
|
|
58
|
-
|
|
75
|
+
<Transition
|
|
76
|
+
enter-active-class="transition-opacity duration-150 delay-[120ms]"
|
|
77
|
+
enter-from-class="opacity-0"
|
|
78
|
+
enter-to-class="opacity-100"
|
|
79
|
+
leave-active-class="transition-opacity duration-75"
|
|
80
|
+
leave-from-class="opacity-100"
|
|
81
|
+
leave-to-class="opacity-0"
|
|
82
|
+
>
|
|
83
|
+
<MIcon v-if="modelValue" name="check" :size="14" :class="iconClasses[color]" />
|
|
84
|
+
</Transition>
|
|
85
|
+
</span>
|
|
59
86
|
</span>
|
|
60
87
|
</span>
|
|
61
88
|
<span v-if="label" class="text-body-large text-on-surface">{{ label }}</span>
|