@m3ui-vue/m3ui-vue 1.1.2 → 1.1.4
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 +1 -1
- package/dist/API.md +202 -10
- package/dist/{MIcon-DLOkQduI.js → MIcon-Bxh9j135.js} +15 -8
- package/dist/MIcon-Bxh9j135.js.map +1 -0
- package/dist/{MMenuItem-DVxKEv1W.js → MMenuItem-BfjqwcYP.js} +85 -64
- package/dist/MMenuItem-BfjqwcYP.js.map +1 -0
- package/dist/MSlider-JflHJ70q.js +1525 -0
- package/dist/MSlider-JflHJ70q.js.map +1 -0
- package/dist/{MTextField-rML9jnXs.js → MTextField-NaIB6RbM.js} +68 -66
- package/dist/MTextField-NaIB6RbM.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MAnimatedNumber.vue.d.ts +29 -0
- package/dist/components/MButton.vue.d.ts +2 -0
- package/dist/components/MContainerTransform.vue.d.ts +59 -0
- package/dist/components/MDialog.vue.d.ts +8 -5
- package/dist/components/MFlex.vue.d.ts +1 -1
- package/dist/components/MIcon.vue.d.ts +2 -0
- package/dist/components/MIconButton.vue.d.ts +2 -0
- package/dist/components/MListGroup.vue.d.ts +23 -0
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MNavigationRail.vue.d.ts +1 -1
- package/dist/components/MScheduler.vue.d.ts +2 -2
- package/dist/components/MScheme.vue.d.ts +60 -0
- package/dist/components/MSparkline.vue.d.ts +41 -0
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MToolbar.vue.d.ts +32 -5
- package/dist/components/MWindow.vue.d.ts +2 -2
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/components/_MToolbarFab.vue.d.ts +16 -0
- package/dist/composables/_containerTransform.d.ts +48 -0
- package/dist/composables/_useSegmentRuns.d.ts +8 -0
- package/dist/composables/dynamicColor.d.ts +11 -0
- package/dist/composables/useColorPalette.d.ts +3 -1
- package/dist/composables/useConfetti.d.ts +32 -0
- package/dist/composables/useContainerTransform.d.ts +30 -0
- package/dist/composables/useLocale.d.ts +9 -0
- package/dist/index.d.ts +10 -1
- package/dist/locales/index.js +35 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +16844 -15530
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +55 -55
- package/dist/{material-color-utilities-Cktu8DBU.js → material-color-utilities-C_iikgRm.js} +928 -603
- package/dist/material-color-utilities-C_iikgRm.js.map +1 -0
- package/dist/rich-text-editor.js +11 -11
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-CqQrhWFl.js → useLocale-CXibICQA.js} +6 -1
- package/dist/useLocale-CXibICQA.js.map +1 -0
- package/package.json +2 -1
- package/src/__tests__/MAnimatedNumber.test.ts +128 -0
- package/src/__tests__/MContainerTransform.test.ts +279 -0
- package/src/__tests__/MDialog.test.ts +27 -0
- package/src/__tests__/MIcon.test.ts +19 -0
- package/src/__tests__/MListItemExpandable.test.ts +48 -0
- package/src/__tests__/MListItemShape.test.ts +42 -5
- package/src/__tests__/MListKeyboard.test.ts +90 -0
- package/src/__tests__/MMapTools.test.ts +2 -1
- package/src/__tests__/MNavigationRail.test.ts +33 -0
- package/src/__tests__/MScheme.test.ts +107 -0
- package/src/__tests__/MSlider.test.ts +161 -0
- package/src/__tests__/MSparkline.test.ts +96 -0
- package/src/__tests__/MToolbar.test.ts +157 -0
- package/src/__tests__/attrsFallthrough.test.ts +6 -0
- package/src/__tests__/hydration.test.ts +25 -0
- package/src/__tests__/iconButtonNames.test.ts +124 -0
- package/src/__tests__/ssr.test.ts +1 -0
- package/src/__tests__/useConfetti.test.ts +81 -0
- package/src/components/MAnimatedNumber.vue +327 -0
- package/src/components/MAutocomplete.vue +34 -4
- package/src/components/MBottomSheet.vue +1 -0
- package/src/components/MButton.vue +4 -2
- package/src/components/MContainerTransform.vue +321 -0
- package/src/components/MDataTable.vue +1 -1
- package/src/components/MDialog.vue +31 -6
- package/src/components/MFab.vue +10 -5
- package/src/components/MIcon.vue +11 -4
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MList.vue +33 -31
- package/src/components/MListGroup.vue +66 -0
- package/src/components/MListItem.vue +138 -84
- package/src/components/MMaskField.vue +3 -0
- package/src/components/MMultiAutocomplete.vue +5 -1
- package/src/components/MMultiSelect.vue +19 -9
- package/src/components/MNavigationRail.vue +40 -10
- package/src/components/MScheme.vue +162 -0
- package/src/components/MSearchBar.vue +2 -0
- package/src/components/MSelect.vue +44 -10
- package/src/components/MSideSheet.vue +3 -0
- package/src/components/MSimpleCarousel.vue +6 -0
- package/src/components/MSlider.vue +161 -42
- package/src/components/MSparkline.vue +250 -0
- package/src/components/MSplitButton.vue +3 -0
- package/src/components/MSpotlightSearch.vue +1 -0
- package/src/components/MTable.vue +1 -0
- package/src/components/MTagInput.vue +4 -0
- package/src/components/MTextField.vue +3 -0
- package/src/components/MToolbar.vue +256 -15
- package/src/components/MTour.vue +1 -0
- package/src/components/MTreeTable.vue +1 -0
- package/src/components/_MToolbarFab.vue +14 -0
- package/src/components/_MTreeNode.vue +3 -0
- package/src/composables/_containerTransform.ts +179 -0
- package/src/composables/_useEscapeStack.ts +2 -0
- package/src/composables/_useSegmentRuns.ts +39 -0
- package/src/composables/dynamicColor.ts +66 -0
- package/src/composables/useColorPalette.ts +2 -2
- package/src/composables/useConfetti.ts +204 -0
- package/src/composables/useContainerTransform.ts +59 -0
- package/src/composables/useLocale.ts +14 -0
- package/src/index.ts +10 -1
- package/src/locales/de.ts +5 -0
- package/src/locales/es.ts +5 -0
- package/src/locales/fr.ts +5 -0
- package/src/locales/ja.ts +5 -0
- package/src/locales/ko.ts +5 -0
- package/src/locales/pt.ts +5 -0
- package/src/locales/zh.ts +5 -0
- package/dist/MIcon-DLOkQduI.js.map +0 -1
- package/dist/MMenuItem-DVxKEv1W.js.map +0 -1
- package/dist/MSlider-BXsBv0ox.js +0 -1402
- package/dist/MSlider-BXsBv0ox.js.map +0 -1
- package/dist/MTextField-rML9jnXs.js.map +0 -1
- package/dist/material-color-utilities-Cktu8DBU.js.map +0 -1
- package/dist/useLocale-CqQrhWFl.js.map +0 -1
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @event update:trailingValue Fires when a trailing switch/checkbox is toggled (trailing='switch' | 'checkbox')
|
|
13
13
|
* @event update:expanded Fires when an expandable item is toggled open/closed
|
|
14
14
|
*/
|
|
15
|
-
import { computed, inject, ref,
|
|
15
|
+
import { computed, getCurrentInstance, h, inject, ref, useId, watch, type FunctionalComponent } from 'vue'
|
|
16
16
|
import type { ComponentPublicInstance } from 'vue'
|
|
17
17
|
import type { ComputedRef } from 'vue'
|
|
18
18
|
import MIcon from './MIcon.vue'
|
|
@@ -82,7 +82,11 @@ const emit = defineEmits<{
|
|
|
82
82
|
'update:expanded': [value: boolean]
|
|
83
83
|
}>()
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
// Root attrs go on the row (the element that looks like the item), which is wrapped in an <li> for links and buttons
|
|
86
|
+
defineOptions({ inheritAttrs: false })
|
|
87
|
+
// `click` is a declared emit, so a listener for it never shows up in attrs: read it off the vnode
|
|
88
|
+
const instance = getCurrentInstance()
|
|
89
|
+
const hasClickListener = () => !!instance?.vnode.props?.onClick
|
|
86
90
|
|
|
87
91
|
const internalExpanded = ref(props.expanded ?? false)
|
|
88
92
|
watch(() => props.expanded, (v) => { if (v !== undefined) internalExpanded.value = v })
|
|
@@ -109,9 +113,29 @@ const resolvedLines = computed(() => {
|
|
|
109
113
|
})
|
|
110
114
|
|
|
111
115
|
const isClickable = computed(() =>
|
|
112
|
-
props.clickable || props.href || props.to ||
|
|
116
|
+
props.clickable || props.href || props.to || hasClickListener() || list?.selectable.value || props.expandable,
|
|
113
117
|
)
|
|
114
118
|
|
|
119
|
+
// What the row is for assistive technology and the keyboard. In a selectable list, an option of its listbox
|
|
120
|
+
// (MList moves focus between them with the arrows); a link stays a link and a clickable row is a button, each
|
|
121
|
+
// inside an <li> since a list can only hold list items; anything else is a plain list item.
|
|
122
|
+
const isOption = computed(() => !!list?.selectable.value && props.value != null && !props.href && !props.to && !props.expandable)
|
|
123
|
+
const isLink = computed(() => !!(props.href || props.to))
|
|
124
|
+
const isButton = computed(() => !isOption.value && !isLink.value && !props.expandable && (props.clickable || hasClickListener()))
|
|
125
|
+
const wrapped = computed(() => isLink.value || isButton.value)
|
|
126
|
+
const rowRole = computed(() => (isOption.value ? 'option' : isButton.value ? 'button' : isLink.value ? undefined : 'listitem'))
|
|
127
|
+
const rowTabindex = computed(() => {
|
|
128
|
+
if (isOption.value) return isActive.value && !props.disabled ? 0 : -1
|
|
129
|
+
if (isButton.value) return props.disabled ? -1 : 0
|
|
130
|
+
return undefined
|
|
131
|
+
})
|
|
132
|
+
function onRowKeyDown(e: KeyboardEvent) {
|
|
133
|
+
if (!isOption.value && !isButton.value) return
|
|
134
|
+
if ((e.key !== 'Enter' && e.key !== ' ') || e.target !== e.currentTarget) return
|
|
135
|
+
e.preventDefault()
|
|
136
|
+
handleClick(e as unknown as MouseEvent)
|
|
137
|
+
}
|
|
138
|
+
|
|
115
139
|
const isActive = computed(() => {
|
|
116
140
|
if (props.active) return true
|
|
117
141
|
if (list?.selectable.value && props.value != null) return list.selected.value === props.value
|
|
@@ -182,6 +206,12 @@ const containerClasses = computed(() => [
|
|
|
182
206
|
// item of a run; the interaction shapes stay the same. Animated with MotionSchemeKeyTokens.FastSpatial.
|
|
183
207
|
// Nav lists keep their pill (that's NavigationDrawerItem's shape, which doesn't morph).
|
|
184
208
|
const rootEl = ref<Element | ComponentPublicInstance | null>(null)
|
|
209
|
+
// The <li> around a link or button row (the list's child, for segment runs); other rows are the <li> themselves
|
|
210
|
+
const wrapperEl = ref<Element | null>(null)
|
|
211
|
+
const RowWrapper: FunctionalComponent = (_, { slots }) =>
|
|
212
|
+
wrapped.value
|
|
213
|
+
? h('li', { role: 'listitem', ref: (e) => { wrapperEl.value = e as Element | null } }, slots.default?.())
|
|
214
|
+
: slots.default?.()
|
|
185
215
|
const shapeEl = ref<HTMLElement | null>(null)
|
|
186
216
|
const el = (r: Element | ComponentPublicInstance | null) => (r && '$el' in r ? (r.$el as Element) : r)
|
|
187
217
|
const hovered = ref(false)
|
|
@@ -192,7 +222,7 @@ const REST = 4
|
|
|
192
222
|
const HOVERED = 8
|
|
193
223
|
const LARGE = 16
|
|
194
224
|
|
|
195
|
-
const segmentPosition = computed(() => (isSegmented.value ? list?.segmentPosition(el(rootEl.value)) : undefined))
|
|
225
|
+
const segmentPosition = computed(() => (isSegmented.value ? list?.segmentPosition(wrapped.value ? wrapperEl.value : el(rootEl.value)) : undefined))
|
|
196
226
|
|
|
197
227
|
const expressiveRadii = computed<number[]>(() => {
|
|
198
228
|
if (isNav.value) return []
|
|
@@ -227,7 +257,7 @@ function onBlur() { focused.value = false }
|
|
|
227
257
|
const tag = computed(() => {
|
|
228
258
|
if (props.href) return 'a'
|
|
229
259
|
if (props.to) return 'router-link'
|
|
230
|
-
if (
|
|
260
|
+
if (isButton.value) return 'div'
|
|
231
261
|
return 'li'
|
|
232
262
|
})
|
|
233
263
|
|
|
@@ -237,6 +267,16 @@ const linkProps = computed(() => {
|
|
|
237
267
|
return {}
|
|
238
268
|
})
|
|
239
269
|
|
|
270
|
+
// An expandable item's header is a button (the row stays the list item): reachable and operable from the
|
|
271
|
+
// keyboard, telling assistive technology whether its children are shown
|
|
272
|
+
const childrenId = useId()
|
|
273
|
+
function onHeaderKeyDown(e: KeyboardEvent) {
|
|
274
|
+
if (e.key !== 'Enter' && e.key !== ' ') return
|
|
275
|
+
if (e.target !== e.currentTarget) return
|
|
276
|
+
e.preventDefault()
|
|
277
|
+
handleClick(e as unknown as MouseEvent)
|
|
278
|
+
}
|
|
279
|
+
|
|
240
280
|
function toggleExpand(e: MouseEvent) {
|
|
241
281
|
if (props.disabled) return
|
|
242
282
|
internalExpanded.value = !internalExpanded.value
|
|
@@ -262,11 +302,20 @@ function handleTrailingToggle() {
|
|
|
262
302
|
</script>
|
|
263
303
|
|
|
264
304
|
<template>
|
|
265
|
-
<li v-if="expandable" ref="rootEl" role="listitem">
|
|
305
|
+
<li v-if="expandable" ref="rootEl" v-bind="$attrs" role="listitem">
|
|
266
306
|
<div
|
|
267
307
|
ref="shapeEl"
|
|
308
|
+
role="button"
|
|
309
|
+
:tabindex="disabled ? -1 : 0"
|
|
310
|
+
:aria-expanded="isExpanded"
|
|
311
|
+
:aria-controls="childrenId"
|
|
312
|
+
:aria-disabled="disabled || undefined"
|
|
313
|
+
class="focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary"
|
|
268
314
|
:class="containerClasses"
|
|
269
315
|
@click="handleClick"
|
|
316
|
+
@keydown="onHeaderKeyDown"
|
|
317
|
+
@focus="onFocus"
|
|
318
|
+
@blur="onBlur"
|
|
270
319
|
@pointerenter="onPointerEnter"
|
|
271
320
|
@pointerleave="onPointerLeave"
|
|
272
321
|
@pointerdown="onPointerDown"
|
|
@@ -302,7 +351,7 @@ function handleTrailingToggle() {
|
|
|
302
351
|
|
|
303
352
|
<!-- Children with collapse animation -->
|
|
304
353
|
<Transition name="mli-expand">
|
|
305
|
-
<div v-if="isExpanded" class="mli-expand-grid">
|
|
354
|
+
<div v-if="isExpanded" :id="childrenId" class="mli-expand-grid">
|
|
306
355
|
<div class="mli-expand-body">
|
|
307
356
|
<slot name="children" />
|
|
308
357
|
</div>
|
|
@@ -310,85 +359,90 @@ function handleTrailingToggle() {
|
|
|
310
359
|
</Transition>
|
|
311
360
|
</li>
|
|
312
361
|
|
|
313
|
-
<
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
<
|
|
342
|
-
<
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
>
|
|
346
|
-
<
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
<
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
<
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
<slot name="overline">
|
|
363
|
-
<p v-if="overline" class="truncate text-label-small" :class="activeIconClass">{{ overline }}</p>
|
|
364
|
-
</slot>
|
|
365
|
-
<slot>
|
|
366
|
-
<p class="truncate text-body-large" :class="activeTextClass">{{ title }}</p>
|
|
367
|
-
<p v-if="subtitle && resolvedLines >= 2" class="text-body-medium" :class="[activeIconClass, resolvedLines === 2 && 'truncate']">
|
|
368
|
-
{{ subtitle }}
|
|
369
|
-
</p>
|
|
370
|
-
<p v-if="description && resolvedLines >= 3" class="line-clamp-2 text-body-small" :class="activeIconClass">
|
|
371
|
-
{{ description }}
|
|
372
|
-
</p>
|
|
362
|
+
<RowWrapper v-else>
|
|
363
|
+
<component
|
|
364
|
+
:is="tag"
|
|
365
|
+
:class="containerClasses"
|
|
366
|
+
ref="rootEl"
|
|
367
|
+
v-bind="{ ...linkProps, ...$attrs }"
|
|
368
|
+
:role="rowRole"
|
|
369
|
+
:tabindex="rowTabindex"
|
|
370
|
+
:aria-selected="isOption ? isActive : undefined"
|
|
371
|
+
:aria-disabled="(isOption || isButton) && disabled ? 'true' : undefined"
|
|
372
|
+
@click="handleClick"
|
|
373
|
+
@keydown="onRowKeyDown"
|
|
374
|
+
@pointerenter="onPointerEnter"
|
|
375
|
+
@pointerleave="onPointerLeave"
|
|
376
|
+
@pointerdown="onPointerDown"
|
|
377
|
+
@pointerup="onPointerUp"
|
|
378
|
+
@pointercancel="onPointerUp"
|
|
379
|
+
@focus="onFocus"
|
|
380
|
+
@blur="onBlur"
|
|
381
|
+
>
|
|
382
|
+
<!-- Divider -->
|
|
383
|
+
<div
|
|
384
|
+
v-if="hasDivider"
|
|
385
|
+
class="absolute top-0 right-0 h-px bg-outline-variant"
|
|
386
|
+
:class="hasDivider === 'inset' ? 'left-16' : 'left-0'"
|
|
387
|
+
/>
|
|
388
|
+
|
|
389
|
+
<!-- Leading -->
|
|
390
|
+
<slot name="leading">
|
|
391
|
+
<template v-if="resolvedLeading === 'icon'">
|
|
392
|
+
<MIcon :name="icon!" :size="24" class="shrink-0" :class="activeIconClass" />
|
|
393
|
+
</template>
|
|
394
|
+
<template v-else-if="resolvedLeading === 'icon-container'">
|
|
395
|
+
<div
|
|
396
|
+
class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full"
|
|
397
|
+
:class="iconContainerClasses[iconContainerColor || 'primary']"
|
|
398
|
+
>
|
|
399
|
+
<MIcon :name="icon!" :size="24" />
|
|
400
|
+
</div>
|
|
401
|
+
</template>
|
|
402
|
+
<template v-else-if="resolvedLeading === 'avatar'">
|
|
403
|
+
<MAvatar :name="avatarName!" :size="40" class="shrink-0" />
|
|
404
|
+
</template>
|
|
405
|
+
<template v-else-if="resolvedLeading === 'image'">
|
|
406
|
+
<img :src="image" alt="" class="h-14 w-14 shrink-0 rounded-md object-cover">
|
|
407
|
+
</template>
|
|
408
|
+
<template v-else-if="resolvedLeading === 'checkbox'">
|
|
409
|
+
<MCheckbox :model-value="isActive" class="shrink-0" />
|
|
410
|
+
</template>
|
|
373
411
|
</slot>
|
|
374
|
-
</div>
|
|
375
412
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
413
|
+
<!-- Content -->
|
|
414
|
+
<div class="min-w-0 flex-1">
|
|
415
|
+
<slot name="overline">
|
|
416
|
+
<p v-if="overline" class="truncate text-label-small" :class="activeIconClass">{{ overline }}</p>
|
|
417
|
+
</slot>
|
|
418
|
+
<slot>
|
|
419
|
+
<p class="truncate text-body-large" :class="activeTextClass">{{ title }}</p>
|
|
420
|
+
<p v-if="subtitle && resolvedLines >= 2" class="text-body-medium" :class="[activeIconClass, resolvedLines === 2 && 'truncate']">
|
|
421
|
+
{{ subtitle }}
|
|
422
|
+
</p>
|
|
423
|
+
<p v-if="description && resolvedLines >= 3" class="line-clamp-2 text-body-small" :class="activeIconClass">
|
|
424
|
+
{{ description }}
|
|
425
|
+
</p>
|
|
426
|
+
</slot>
|
|
427
|
+
</div>
|
|
428
|
+
|
|
429
|
+
<!-- Trailing -->
|
|
430
|
+
<slot name="trailing">
|
|
431
|
+
<template v-if="resolvedTrailing === 'icon'">
|
|
432
|
+
<MIcon :name="trailingIcon!" :size="24" class="shrink-0" :class="activeIconClass" />
|
|
433
|
+
</template>
|
|
434
|
+
<template v-else-if="resolvedTrailing === 'text'">
|
|
435
|
+
<span class="shrink-0 text-label-small" :class="activeIconClass">{{ trailingText }}</span>
|
|
436
|
+
</template>
|
|
437
|
+
<template v-else-if="resolvedTrailing === 'switch'">
|
|
438
|
+
<MSwitch :model-value="!!trailingValue" @update:model-value="handleTrailingToggle" />
|
|
439
|
+
</template>
|
|
440
|
+
<template v-else-if="resolvedTrailing === 'checkbox'">
|
|
441
|
+
<MCheckbox :model-value="!!trailingValue" @update:model-value="handleTrailingToggle" />
|
|
442
|
+
</template>
|
|
443
|
+
</slot>
|
|
444
|
+
</component>
|
|
445
|
+
</RowWrapper>
|
|
392
446
|
</template>
|
|
393
447
|
|
|
394
448
|
<style>
|
|
@@ -9,9 +9,11 @@ import { computed, ref, useId, watch } from 'vue'
|
|
|
9
9
|
import MIcon from './MIcon.vue'
|
|
10
10
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
11
11
|
import { useDebounce } from '../composables/useDebounce'
|
|
12
|
+
import { useLocale } from '../composables/useLocale'
|
|
12
13
|
|
|
13
14
|
export type MaskPreset = 'credit-card' | 'phone' | 'date' | 'time' | 'cpf' | 'cnpj' | 'zip'
|
|
14
15
|
|
|
16
|
+
const locale = useLocale()
|
|
15
17
|
const PRESETS: Record<MaskPreset, string> = {
|
|
16
18
|
'credit-card': '#### #### #### ####',
|
|
17
19
|
phone: '(###) ###-####',
|
|
@@ -219,6 +221,7 @@ const labelClasses = computed(() => {
|
|
|
219
221
|
</label>
|
|
220
222
|
|
|
221
223
|
<button
|
|
224
|
+
:aria-label="locale.clear"
|
|
222
225
|
v-if="showClear"
|
|
223
226
|
type="button"
|
|
224
227
|
class="absolute right-3 top-1/2 -translate-y-1/2 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
@@ -408,6 +408,7 @@ const labelClasses = computed(() => {
|
|
|
408
408
|
>
|
|
409
409
|
{{ chip.label }}
|
|
410
410
|
<button
|
|
411
|
+
:aria-label="`${locale.remove} ${chip.label}`"
|
|
411
412
|
v-if="!disabled"
|
|
412
413
|
type="button"
|
|
413
414
|
class="flex h-4 w-4 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
@@ -442,6 +443,8 @@ const labelClasses = computed(() => {
|
|
|
442
443
|
:disabled="disabled"
|
|
443
444
|
autocomplete="off"
|
|
444
445
|
role="combobox"
|
|
446
|
+
aria-autocomplete="list"
|
|
447
|
+
:aria-controls="open ? `${id}-list` : undefined"
|
|
445
448
|
:aria-expanded="open"
|
|
446
449
|
:aria-disabled="disabled"
|
|
447
450
|
:class="[
|
|
@@ -463,6 +466,7 @@ const labelClasses = computed(() => {
|
|
|
463
466
|
|
|
464
467
|
<!-- Clear button -->
|
|
465
468
|
<button
|
|
469
|
+
:aria-label="locale.clear"
|
|
466
470
|
v-if="clearable && hasValue && !disabled"
|
|
467
471
|
type="button"
|
|
468
472
|
class="absolute right-9 top-4 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
@@ -505,7 +509,7 @@ const labelClasses = computed(() => {
|
|
|
505
509
|
class="fixed z-500 max-h-60 overflow-auto rounded-xs bg-surface-container shadow-elevation-2"
|
|
506
510
|
:style="dropPos"
|
|
507
511
|
>
|
|
508
|
-
<div class="flex flex-col py-1">
|
|
512
|
+
<div :id="`${id}-list`" role="group" :aria-label="label || undefined" class="flex flex-col py-1">
|
|
509
513
|
<label
|
|
510
514
|
v-for="(opt, i) in filteredOptions"
|
|
511
515
|
:key="i"
|
|
@@ -86,6 +86,10 @@ const emit = defineEmits<{ 'update:modelValue': [unknown[]] }>()
|
|
|
86
86
|
const id = useId()
|
|
87
87
|
const open = ref(false)
|
|
88
88
|
const modalOpen = ref(false)
|
|
89
|
+
// Focused (from the keyboard too) looks like open: M3's focused field, 2dp primary indicator and primary label,
|
|
90
|
+
// instead of the browser's own outline
|
|
91
|
+
const focused = ref(false)
|
|
92
|
+
const highlighted = computed(() => open.value || modalOpen.value || focused.value)
|
|
89
93
|
const modalSearch = ref('')
|
|
90
94
|
const search = ref('')
|
|
91
95
|
const fieldEl = ref<HTMLElement | null>(null)
|
|
@@ -221,7 +225,7 @@ onUnmounted(() => {
|
|
|
221
225
|
|
|
222
226
|
const triggerClasses = computed(() => {
|
|
223
227
|
const base = [
|
|
224
|
-
'flex min-h-[56px] w-full items-center gap-1.5 flex-wrap',
|
|
228
|
+
'flex min-h-[56px] w-full items-center gap-1.5 flex-wrap outline-none',
|
|
225
229
|
'transition-[border-color,border-width] duration-150',
|
|
226
230
|
props.disabled ? 'cursor-not-allowed' : 'cursor-pointer',
|
|
227
231
|
props.leadingIcon ? 'pl-12 pr-10' : 'pl-4 pr-10',
|
|
@@ -230,7 +234,7 @@ const triggerClasses = computed(() => {
|
|
|
230
234
|
if (props.variant === 'outlined') {
|
|
231
235
|
const border = props.disabled
|
|
232
236
|
? 'border-on-surface/12'
|
|
233
|
-
:
|
|
237
|
+
: highlighted.value
|
|
234
238
|
? (props.error ? 'border-2 border-error' : 'border-2 border-primary')
|
|
235
239
|
: (props.error ? 'border-error' : 'border-outline hover:border-on-surface')
|
|
236
240
|
return [...base, 'rounded-xs border bg-transparent py-2', border].join(' ')
|
|
@@ -238,7 +242,7 @@ const triggerClasses = computed(() => {
|
|
|
238
242
|
|
|
239
243
|
const border = props.disabled
|
|
240
244
|
? 'border-on-surface/38'
|
|
241
|
-
:
|
|
245
|
+
: highlighted.value
|
|
242
246
|
? (props.error ? 'border-b-2 border-error' : 'border-b-2 border-primary')
|
|
243
247
|
: (props.error ? 'border-error' : 'border-on-surface-variant hover:border-on-surface')
|
|
244
248
|
const bg = props.disabled
|
|
@@ -247,7 +251,7 @@ const triggerClasses = computed(() => {
|
|
|
247
251
|
return [
|
|
248
252
|
...base,
|
|
249
253
|
'rounded-t-xs border-b pb-2',
|
|
250
|
-
hasValue.value ||
|
|
254
|
+
hasValue.value || highlighted.value ? 'pt-7' : 'pt-4',
|
|
251
255
|
bg,
|
|
252
256
|
border,
|
|
253
257
|
].join(' ')
|
|
@@ -265,7 +269,7 @@ const labelClasses = computed(() => {
|
|
|
265
269
|
const unFloated = props.variant === 'filled'
|
|
266
270
|
? 'top-[53%] -translate-y-1/2 text-body-large'
|
|
267
271
|
: 'top-1/2 -translate-y-1/2 text-body-large'
|
|
268
|
-
const active =
|
|
272
|
+
const active = highlighted.value || hasValue.value
|
|
269
273
|
|
|
270
274
|
return [
|
|
271
275
|
'pointer-events-none absolute right-10 truncate transition-all duration-200',
|
|
@@ -273,7 +277,7 @@ const labelClasses = computed(() => {
|
|
|
273
277
|
active ? floated : unFloated,
|
|
274
278
|
props.disabled
|
|
275
279
|
? 'text-on-surface/38'
|
|
276
|
-
:
|
|
280
|
+
: highlighted.value
|
|
277
281
|
? (props.error ? 'text-error' : 'text-primary')
|
|
278
282
|
: (props.error ? 'text-error' : 'text-on-surface-variant'),
|
|
279
283
|
].join(' ')
|
|
@@ -305,12 +309,16 @@ const labelClasses = computed(() => {
|
|
|
305
309
|
:class="triggerClasses"
|
|
306
310
|
role="button"
|
|
307
311
|
:tabindex="disabled ? -1 : 0"
|
|
308
|
-
:aria-expanded="open"
|
|
312
|
+
:aria-expanded="open || modalOpen"
|
|
309
313
|
:aria-haspopup="true"
|
|
314
|
+
:aria-controls="open ? `${id}-list` : undefined"
|
|
315
|
+
:aria-labelledby="label ? `${id}-label` : undefined"
|
|
310
316
|
@click="open ? close() : openDropdown()"
|
|
311
317
|
@keydown.enter.prevent="open ? close() : openDropdown()"
|
|
312
318
|
@keydown.space.prevent="open ? close() : openDropdown()"
|
|
313
319
|
@keydown.escape="close()"
|
|
320
|
+
@focus="focused = true"
|
|
321
|
+
@blur="focused = false"
|
|
314
322
|
>
|
|
315
323
|
<template v-if="hasValue">
|
|
316
324
|
<span
|
|
@@ -321,6 +329,7 @@ const labelClasses = computed(() => {
|
|
|
321
329
|
>
|
|
322
330
|
{{ chip.label }}
|
|
323
331
|
<button
|
|
332
|
+
:aria-label="`${locale.remove} ${chip.label}`"
|
|
324
333
|
v-if="!disabled"
|
|
325
334
|
type="button"
|
|
326
335
|
class="flex h-4 w-4 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
@@ -350,11 +359,12 @@ const labelClasses = computed(() => {
|
|
|
350
359
|
</span>
|
|
351
360
|
</div>
|
|
352
361
|
|
|
353
|
-
<label :class="labelClasses">
|
|
362
|
+
<label :id="`${id}-label`" :class="labelClasses">
|
|
354
363
|
{{ label }}<span v-if="required" class="text-error"> *</span>
|
|
355
364
|
</label>
|
|
356
365
|
|
|
357
366
|
<button
|
|
367
|
+
:aria-label="locale.clear"
|
|
358
368
|
v-if="clearable && hasValue && !disabled"
|
|
359
369
|
type="button"
|
|
360
370
|
class="absolute right-9 top-4 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
@@ -409,7 +419,7 @@ const labelClasses = computed(() => {
|
|
|
409
419
|
</div>
|
|
410
420
|
</div>
|
|
411
421
|
|
|
412
|
-
<div class="flex flex-col py-1">
|
|
422
|
+
<div :id="`${id}-list`" role="group" :aria-label="label || undefined" class="flex flex-col py-1">
|
|
413
423
|
<label
|
|
414
424
|
v-for="(opt, i) in filteredOptions"
|
|
415
425
|
:key="i"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @event update:expanded Emitted when the modal panel closes (modal mode only) — pair with :expanded for
|
|
9
9
|
* v-model:expanded. With `hideOnCollapse`, swiping the panel away closes it too
|
|
10
10
|
*/
|
|
11
|
-
import { computed, ref, watch, onUnmounted } from 'vue'
|
|
11
|
+
import { computed, nextTick, onMounted, ref, watch, onUnmounted } from 'vue'
|
|
12
12
|
import MIcon from './MIcon.vue'
|
|
13
13
|
import MBadge from './MBadge.vue'
|
|
14
14
|
import { useItemLink, type ItemLink } from '../composables/_useItemLink'
|
|
@@ -36,7 +36,7 @@ const props = withDefaults(defineProps<{
|
|
|
36
36
|
/** Vertical alignment of items within the rail */
|
|
37
37
|
alignment?: 'top' | 'center' | 'bottom'
|
|
38
38
|
/**
|
|
39
|
-
* Widens the rail (
|
|
39
|
+
* Widens the rail (to fit the longest label, 220 to 360px) and shows each item's icon beside its label in a full-width pill, instead of the icon
|
|
40
40
|
* over the label. Toggle it from your own menu button.
|
|
41
41
|
*/
|
|
42
42
|
// M3 `WideNavigationRail`'s expanded state: items become icon+label side by side in a full-width pill instead of icon-over-label in a narrow centered one.
|
|
@@ -105,7 +105,28 @@ function onKeydown(e: KeyboardEvent) {
|
|
|
105
105
|
* out at full (expanded) size and is simply clipped by the panel's own `overflow-hidden`
|
|
106
106
|
* width, rather than each item's pill separately animating like the non-modal rail's does.
|
|
107
107
|
*/
|
|
108
|
-
|
|
108
|
+
// The expanded rail fits its longest label, between WideNavigationRail's ExpandedRailMinWidth and MaxWidth
|
|
109
|
+
// (220 and 360dp). Around a label: the items' 12px inset, the pill's 16px paddings, the 24px icon and its 8px gap.
|
|
110
|
+
// Labels still too long end in an ellipsis.
|
|
111
|
+
const RAIL_MIN = 220
|
|
112
|
+
const RAIL_MAX = 360
|
|
113
|
+
const ITEM_CHROME = 12 + 16 + 24 + 8 + 16 + 12
|
|
114
|
+
const LABEL_MAX = RAIL_MAX - ITEM_CHROME
|
|
115
|
+
const longestLabel = ref(0)
|
|
116
|
+
const expandedWidth = computed(() => Math.min(RAIL_MAX, Math.max(RAIL_MIN, longestLabel.value + ITEM_CHROME)))
|
|
117
|
+
// A label's natural width (scrollWidth: its overflow box clips it while collapsed), measured in the rail or panel
|
|
118
|
+
function measureLabels(root: Element | null | undefined) {
|
|
119
|
+
if (!root) return
|
|
120
|
+
const widths = [...root.querySelectorAll<HTMLElement>('[data-rail-label]')].map((el) => el.scrollWidth)
|
|
121
|
+
if (widths.length) longestLabel.value = Math.max(...widths)
|
|
122
|
+
}
|
|
123
|
+
const railEl = ref<HTMLElement>()
|
|
124
|
+
onMounted(() => {
|
|
125
|
+
measureLabels(railEl.value)
|
|
126
|
+
// Web fonts change the labels' widths once they load
|
|
127
|
+
document.fonts?.ready.then(() => measureLabels(railEl.value)).catch(() => {})
|
|
128
|
+
})
|
|
129
|
+
watch(() => props.items.map((i) => i.label).join('\n'), () => nextTick(() => measureLabels(railEl.value)))
|
|
109
130
|
const SPRING_DAMPING = 0.9
|
|
110
131
|
const SPRING_STIFFNESS = 1400
|
|
111
132
|
// The dismissible (hideOnCollapse) panel slides instead: ModalWideNavigationRailState's DefaultSpatial
|
|
@@ -251,7 +272,7 @@ function onPanelPointerMove(e: PointerEvent) {
|
|
|
251
272
|
// Stop a running slide; the finger owns the panel from where it is
|
|
252
273
|
stopSlide()
|
|
253
274
|
drag.startX = panelX
|
|
254
|
-
drag.width = (e.currentTarget as HTMLElement).offsetWidth ||
|
|
275
|
+
drag.width = (e.currentTarget as HTMLElement).offsetWidth || expandedWidth.value
|
|
255
276
|
}
|
|
256
277
|
const panel = e.currentTarget as HTMLElement
|
|
257
278
|
const scrim = panel.parentElement?.querySelector<HTMLElement>('.wnr-scrim') ?? null
|
|
@@ -292,6 +313,8 @@ function onPanelClickCapture(e: MouseEvent) {
|
|
|
292
313
|
}
|
|
293
314
|
|
|
294
315
|
function onPanelEnter(el: Element, done: () => void) {
|
|
316
|
+
// The panel's own labels (the inline rail isn't there with hideOnCollapse)
|
|
317
|
+
measureLabels(el)
|
|
295
318
|
if (props.hideOnCollapse) {
|
|
296
319
|
// Standalone modal: the items are expanded from the start, the panel slides in from off-screen
|
|
297
320
|
panelExpanded.value = true
|
|
@@ -318,7 +341,7 @@ function onPanelEnter(el: Element, done: () => void) {
|
|
|
318
341
|
} else {
|
|
319
342
|
panelExpanded.value = true
|
|
320
343
|
}
|
|
321
|
-
if (panel) springWidth(panel, 0,
|
|
344
|
+
if (panel) springWidth(panel, 0, expandedWidth.value, done)
|
|
322
345
|
else done()
|
|
323
346
|
}
|
|
324
347
|
function onPanelLeave(el: Element, done: () => void) {
|
|
@@ -330,7 +353,7 @@ function onPanelLeave(el: Element, done: () => void) {
|
|
|
330
353
|
const scrim = (el as HTMLElement).querySelector<HTMLElement>('.wnr-scrim')
|
|
331
354
|
panelExpanded.value = false
|
|
332
355
|
if (scrim) scrim.style.opacity = '0'
|
|
333
|
-
if (panel) springWidth(panel,
|
|
356
|
+
if (panel) springWidth(panel, expandedWidth.value, 0, done)
|
|
334
357
|
else done()
|
|
335
358
|
}
|
|
336
359
|
|
|
@@ -363,9 +386,11 @@ useScrollLock(() => props.modal && props.expanded)
|
|
|
363
386
|
-->
|
|
364
387
|
<nav
|
|
365
388
|
v-if="!(modal && hideOnCollapse)"
|
|
389
|
+
ref="railEl"
|
|
366
390
|
v-bind="$attrs"
|
|
367
391
|
class="flex h-full flex-col border-r border-outline-variant bg-surface transition-[width] duration-200"
|
|
368
|
-
:class="railExpanded ? '
|
|
392
|
+
:class="railExpanded ? '' : 'w-20'"
|
|
393
|
+
:style="railExpanded ? { width: `${expandedWidth}px` } : undefined"
|
|
369
394
|
>
|
|
370
395
|
<!--
|
|
371
396
|
Header slot: menu-toggle button and/or FAB. Left-anchored (not `items-center`) inside
|
|
@@ -470,7 +495,9 @@ useScrollLock(() => props.modal && props.expanded)
|
|
|
470
495
|
:class="railExpanded ? 'ml-2 grid-cols-[1fr] opacity-100' : 'ml-0 grid-cols-[0fr] opacity-0'"
|
|
471
496
|
>
|
|
472
497
|
<span
|
|
473
|
-
|
|
498
|
+
data-rail-label
|
|
499
|
+
class="min-w-0 overflow-hidden text-ellipsis whitespace-nowrap text-left text-label-large font-medium"
|
|
500
|
+
:style="{ maxWidth: `${LABEL_MAX}px` }"
|
|
474
501
|
:class="item.value === modelValue ? 'text-secondary' : 'text-on-surface-variant'"
|
|
475
502
|
>
|
|
476
503
|
{{ item.label }}
|
|
@@ -511,7 +538,8 @@ useScrollLock(() => props.modal && props.expanded)
|
|
|
511
538
|
|
|
512
539
|
<nav
|
|
513
540
|
class="wnr-panel fixed inset-y-0 left-0 z-10 flex flex-col overflow-hidden rounded-r-lg bg-surface-container shadow-elevation-2"
|
|
514
|
-
:class="hideOnCollapse ? '
|
|
541
|
+
:class="hideOnCollapse ? 'touch-pan-y' : ''"
|
|
542
|
+
:style="hideOnCollapse ? { width: `${expandedWidth}px` } : undefined"
|
|
515
543
|
@pointerdown="onPanelPointerDown"
|
|
516
544
|
@pointermove="onPanelPointerMove"
|
|
517
545
|
@pointerup="onPanelPointerUp"
|
|
@@ -574,7 +602,9 @@ useScrollLock(() => props.modal && props.expanded)
|
|
|
574
602
|
:class="panelExpanded ? 'ml-2 grid-cols-[1fr] opacity-100' : 'ml-0 grid-cols-[0fr] opacity-0'"
|
|
575
603
|
>
|
|
576
604
|
<span
|
|
577
|
-
|
|
605
|
+
data-rail-label
|
|
606
|
+
class="min-w-0 overflow-hidden text-ellipsis whitespace-nowrap text-left text-label-large font-medium"
|
|
607
|
+
:style="{ maxWidth: `${LABEL_MAX}px` }"
|
|
578
608
|
:class="item.value === modelValue ? 'text-secondary' : 'text-on-surface-variant'"
|
|
579
609
|
>
|
|
580
610
|
{{ item.label }}
|