@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
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { nextTick, type Component } from 'vue'
|
|
4
|
+
import MSelect from '../components/MSelect.vue'
|
|
5
|
+
import MAutocomplete from '../components/MAutocomplete.vue'
|
|
6
|
+
import MMultiSelect from '../components/MMultiSelect.vue'
|
|
7
|
+
import MMultiAutocomplete from '../components/MMultiAutocomplete.vue'
|
|
8
|
+
import MTagInput from '../components/MTagInput.vue'
|
|
9
|
+
import MTextField from '../components/MTextField.vue'
|
|
10
|
+
import MMaskField from '../components/MMaskField.vue'
|
|
11
|
+
import MSearchBar from '../components/MSearchBar.vue'
|
|
12
|
+
import MSimpleCarousel from '../components/MSimpleCarousel.vue'
|
|
13
|
+
import MSplitButton from '../components/MSplitButton.vue'
|
|
14
|
+
import MTree from '../components/MTree.vue'
|
|
15
|
+
import MTreeTable from '../components/MTreeTable.vue'
|
|
16
|
+
|
|
17
|
+
// A button's accessible name, roughly as a browser computes it: aria-label, else its text without what's hidden from
|
|
18
|
+
// assistive technology (MIcon's ligature text), else its title
|
|
19
|
+
function accessibleName(el: Element): string {
|
|
20
|
+
const label = el.getAttribute('aria-label')
|
|
21
|
+
if (label) return label
|
|
22
|
+
const clone = el.cloneNode(true) as Element
|
|
23
|
+
clone.querySelectorAll('[aria-hidden="true"]').forEach((n) => n.remove())
|
|
24
|
+
return clone.textContent?.trim() || el.getAttribute('title') || ''
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const options = [{ label: 'Lo-fi', value: 'lofi' }, { label: 'Jazz', value: 'jazz' }]
|
|
28
|
+
|
|
29
|
+
const cases: [string, Component, Record<string, unknown>][] = [
|
|
30
|
+
['MSelect', MSelect, { modelValue: 'lofi', options, label: 'Genre', clearable: true }],
|
|
31
|
+
['MAutocomplete', MAutocomplete, { modelValue: 'lofi', options, label: 'Genre', clearable: true }],
|
|
32
|
+
['MMultiSelect', MMultiSelect, { modelValue: ['lofi', 'jazz'], options, label: 'Genres', clearable: true }],
|
|
33
|
+
['MMultiAutocomplete', MMultiAutocomplete, { modelValue: ['lofi'], options, label: 'Genres', clearable: true }],
|
|
34
|
+
['MTagInput', MTagInput, { modelValue: ['vue', 'm3'], label: 'Tags', clearable: true }],
|
|
35
|
+
['MTextField', MTextField, { modelValue: 'hello', label: 'Name', clearable: true }],
|
|
36
|
+
['MMaskField', MMaskField, { modelValue: '123', label: 'Phone', clearable: true, mask: '###' }],
|
|
37
|
+
['MSearchBar', MSearchBar, { modelValue: 'tea', clearable: true }],
|
|
38
|
+
['MSimpleCarousel', MSimpleCarousel, { items: [{ src: 'a.jpg' }, { src: 'b.jpg' }] }],
|
|
39
|
+
['MSplitButton', MSplitButton, { label: 'Save', items: [{ label: 'Save as', value: 'as' }] }],
|
|
40
|
+
['MTree', MTree, { nodes: [{ id: 1, label: 'src', children: [{ id: 2, label: 'App.vue' }] }] }],
|
|
41
|
+
['MTreeTable', MTreeTable, { columns: [{ key: 'name', label: 'Name' }], rows: [{ id: 1, name: 'src', children: [{ id: 2, name: 'App.vue' }] }] }],
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
describe('icon-only buttons have an accessible name', () => {
|
|
45
|
+
let wrapper: VueWrapper | undefined
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
wrapper?.unmount()
|
|
48
|
+
wrapper = undefined
|
|
49
|
+
document.body.innerHTML = ''
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
for (const [name, component, props] of cases) {
|
|
53
|
+
it(name, async () => {
|
|
54
|
+
wrapper = mount(component, { props, attachTo: document.body })
|
|
55
|
+
await nextTick()
|
|
56
|
+
const buttons = [...document.body.querySelectorAll('button')]
|
|
57
|
+
expect(buttons.length).toBeGreaterThan(0)
|
|
58
|
+
const unnamed = buttons.filter((b) => !accessibleName(b)).map((b) => b.outerHTML.slice(0, 120))
|
|
59
|
+
expect(unnamed).toEqual([])
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
describe('MSelect listbox semantics', () => {
|
|
65
|
+
it('names the combobox by its label and exposes the open list and its options', async () => {
|
|
66
|
+
const wrapper = mount(MSelect, { props: { modelValue: 'jazz', options, label: 'Genre' }, attachTo: document.body })
|
|
67
|
+
const combo = wrapper.find('[role="combobox"]')
|
|
68
|
+
expect(document.getElementById(combo.attributes('aria-labelledby')!)?.textContent?.trim()).toBe('Genre')
|
|
69
|
+
expect(combo.attributes('aria-expanded')).toBe('false')
|
|
70
|
+
await combo.trigger('click')
|
|
71
|
+
const list = document.getElementById(combo.attributes('aria-controls')!)!
|
|
72
|
+
expect(list.getAttribute('role')).toBe('listbox')
|
|
73
|
+
const opts = [...list.querySelectorAll('[role="option"]')]
|
|
74
|
+
expect(opts.map((o) => accessibleName(o))).toEqual(['Lo-fi', 'Jazz'])
|
|
75
|
+
expect(opts.map((o) => o.getAttribute('aria-selected'))).toEqual(['false', 'true'])
|
|
76
|
+
expect(combo.attributes('aria-activedescendant')).toBe(opts[1]!.id)
|
|
77
|
+
wrapper.unmount()
|
|
78
|
+
document.body.innerHTML = ''
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
describe('MAutocomplete listbox semantics', () => {
|
|
83
|
+
it('points the input at the open list and the option the arrow keys are on', async () => {
|
|
84
|
+
const wrapper = mount(MAutocomplete, { props: { modelValue: null, options, label: 'Genre' }, attachTo: document.body })
|
|
85
|
+
const input = wrapper.find('input[role="combobox"]')
|
|
86
|
+
await input.trigger('focus')
|
|
87
|
+
await input.trigger('keydown', { key: 'ArrowDown' })
|
|
88
|
+
await nextTick()
|
|
89
|
+
const list = document.getElementById(input.attributes('aria-controls')!)!
|
|
90
|
+
expect(list.getAttribute('role')).toBe('listbox')
|
|
91
|
+
const opts = [...list.querySelectorAll('[role="option"]')]
|
|
92
|
+
expect(opts).toHaveLength(2)
|
|
93
|
+
expect(input.attributes('aria-activedescendant')).toBe(opts[0]!.id)
|
|
94
|
+
wrapper.unmount()
|
|
95
|
+
document.body.innerHTML = ''
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('MMultiSelect trigger', () => {
|
|
100
|
+
it('is named by its label', () => {
|
|
101
|
+
const wrapper = mount(MMultiSelect, { props: { modelValue: [], options, label: 'Genres' }, attachTo: document.body })
|
|
102
|
+
const trigger = wrapper.find('[role="button"]')
|
|
103
|
+
expect(document.getElementById(trigger.attributes('aria-labelledby')!)?.textContent?.trim()).toBe('Genres')
|
|
104
|
+
wrapper.unmount()
|
|
105
|
+
document.body.innerHTML = ''
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe('MSelect keyboard focus', () => {
|
|
110
|
+
// The trigger had no focus style of its own, so the browser drew its outline (white in dark, black in light)
|
|
111
|
+
it('shows M3\'s focused field instead of the browser outline', async () => {
|
|
112
|
+
const wrapper = mount(MSelect, { props: { modelValue: null, options, label: 'Genre', variant: 'outlined' }, attachTo: document.body })
|
|
113
|
+
const combo = wrapper.find('[role="combobox"]')
|
|
114
|
+
expect(combo.classes()).toContain('outline-none')
|
|
115
|
+
expect(combo.classes()).not.toContain('border-primary')
|
|
116
|
+
await combo.trigger('focus')
|
|
117
|
+
expect(combo.classes()).toEqual(expect.arrayContaining(['border-2', 'border-primary']))
|
|
118
|
+
expect(wrapper.find('label').classes()).toContain('text-primary')
|
|
119
|
+
await combo.trigger('blur')
|
|
120
|
+
expect(combo.classes()).not.toContain('border-primary')
|
|
121
|
+
wrapper.unmount()
|
|
122
|
+
document.body.innerHTML = ''
|
|
123
|
+
})
|
|
124
|
+
})
|
|
@@ -29,6 +29,7 @@ const props: Record<string, Record<string, unknown>> = {
|
|
|
29
29
|
MRelativeTime: { value: new Date(0) },
|
|
30
30
|
MResult: { status: 'success', title: 't' },
|
|
31
31
|
MShape: { shape: 'Circle' },
|
|
32
|
+
MSparkline: { data: [3, 1, 4, 1, 5] },
|
|
32
33
|
MTour: { steps: [{ target: '#x', title: 't' }] },
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach, beforeEach, vi } from 'vitest'
|
|
2
|
+
import { __resetConfetti, fireConfetti, useConfetti } from '../composables/useConfetti'
|
|
3
|
+
|
|
4
|
+
// happy-dom has no 2D canvas: a fake one that records what's drawn
|
|
5
|
+
let fills: string[] = []
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
fills = []
|
|
8
|
+
vi.stubGlobal('Path2D', class { constructor(public d: string) {} })
|
|
9
|
+
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockImplementation(function () {
|
|
10
|
+
const ctx = {
|
|
11
|
+
fillStyle: '',
|
|
12
|
+
globalAlpha: 1,
|
|
13
|
+
setTransform: () => {},
|
|
14
|
+
translate: () => {},
|
|
15
|
+
clearRect: () => {},
|
|
16
|
+
fill: () => fills.push(ctx.fillStyle),
|
|
17
|
+
}
|
|
18
|
+
return ctx as unknown as CanvasRenderingContext2D
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
__resetConfetti()
|
|
23
|
+
vi.restoreAllMocks()
|
|
24
|
+
vi.unstubAllGlobals()
|
|
25
|
+
document.querySelectorAll('canvas').forEach((c) => c.remove())
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const canvas = () => document.querySelector('canvas')
|
|
29
|
+
const frames = (ms: number) => new Promise((r) => setTimeout(r, ms))
|
|
30
|
+
|
|
31
|
+
describe('useConfetti', () => {
|
|
32
|
+
it('draws the pieces on one canvas over the page that ignores the pointer and assistive technology', async () => {
|
|
33
|
+
fireConfetti({ x: 100, y: 100 }, { count: 30 })
|
|
34
|
+
const c = canvas()!
|
|
35
|
+
expect(c.getAttribute('aria-hidden')).toBe('true')
|
|
36
|
+
expect(c.style.pointerEvents).toBe('none')
|
|
37
|
+
expect(c.style.position).toBe('fixed')
|
|
38
|
+
await frames(60)
|
|
39
|
+
expect(fills.length).toBeGreaterThanOrEqual(30)
|
|
40
|
+
// A second burst shares the canvas
|
|
41
|
+
fireConfetti({ x: 100, y: 100 }, { count: 5 })
|
|
42
|
+
expect(document.querySelectorAll('canvas')).toHaveLength(1)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('takes its colors from the origin\'s theme tokens', async () => {
|
|
46
|
+
const el = document.createElement('div')
|
|
47
|
+
el.style.setProperty('--color-primary', '#c83228')
|
|
48
|
+
el.style.setProperty('--color-tertiary', '#e5b92c')
|
|
49
|
+
document.body.appendChild(el)
|
|
50
|
+
fireConfetti(el, { count: 40 })
|
|
51
|
+
await frames(60)
|
|
52
|
+
expect(new Set(fills)).toEqual(new Set(['#c83228', '#e5b92c']))
|
|
53
|
+
el.remove()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('uses the given colors, and removes the canvas once the last piece has fallen', async () => {
|
|
57
|
+
fireConfetti({ x: 10, y: 10 }, { count: 10, colors: ['red'] })
|
|
58
|
+
await frames(60)
|
|
59
|
+
expect(new Set(fills)).toEqual(new Set(['red']))
|
|
60
|
+
await frames(4000)
|
|
61
|
+
expect(canvas()).toBeNull()
|
|
62
|
+
}, 8000)
|
|
63
|
+
|
|
64
|
+
it('does nothing under reduced motion', () => {
|
|
65
|
+
vi.stubGlobal('matchMedia', (q: string) => ({ matches: q.includes('reduce') }))
|
|
66
|
+
fireConfetti({ x: 10, y: 10 })
|
|
67
|
+
expect(canvas()).toBeNull()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('fire() takes an event, an element, a point or just options', async () => {
|
|
71
|
+
const { fire } = useConfetti()
|
|
72
|
+
const button = document.createElement('button')
|
|
73
|
+
document.body.appendChild(button)
|
|
74
|
+
button.addEventListener('click', (e) => fire(e, { count: 3, colors: ['blue'] }))
|
|
75
|
+
button.click()
|
|
76
|
+
fire({ from: 'top', count: 3, colors: ['green'] })
|
|
77
|
+
await frames(60)
|
|
78
|
+
expect(new Set(fills)).toEqual(new Set(['blue', 'green']))
|
|
79
|
+
button.remove()
|
|
80
|
+
})
|
|
81
|
+
})
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A number, time or duration whose digits roll to their new value on a spring when it changes, like an odometer:
|
|
4
|
+
* each digit rolls on its own (up when the value grows, down when it shrinks) and digits that appear or go away open
|
|
5
|
+
* and close. Numbers are formatted with `Intl.NumberFormat` (currency, percent, units, compact), times with
|
|
6
|
+
* `Intl.DateTimeFormat`, both in the app's language; durations as `h:mm:ss`. Tabular figures. Assistive technology
|
|
7
|
+
* reads the formatted value, not the rolling digits. Not an M3 spec component.
|
|
8
|
+
*/
|
|
9
|
+
import { computed, onMounted, onUnmounted, onUpdated, watch } from 'vue'
|
|
10
|
+
import { useLocale } from '../composables/useLocale'
|
|
11
|
+
import { motionSprings, type SpringSpec } from '../composables/motion'
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(
|
|
14
|
+
defineProps<{
|
|
15
|
+
/** The value: a number, a `Date` for times, or seconds for a duration */
|
|
16
|
+
value: number | Date
|
|
17
|
+
/**
|
|
18
|
+
* `number` (Intl.NumberFormat), `datetime` (Intl.DateTimeFormat; a `Date` or a timestamp) or `duration`
|
|
19
|
+
* (seconds as `h:mm:ss`, hours only when there are some). Defaults to `datetime` for a `Date`, `number` otherwise
|
|
20
|
+
*/
|
|
21
|
+
type?: 'number' | 'datetime' | 'duration'
|
|
22
|
+
/**
|
|
23
|
+
* Intl options for the type: `{ style: 'currency', currency: 'EUR' }`, `{ style: 'percent' }`,
|
|
24
|
+
* `{ style: 'unit', unit: 'kilometer-per-hour' }`, `{ notation: 'compact' }` for numbers; `{ timeStyle: 'medium' }`
|
|
25
|
+
* (the default), `{ hour: '2-digit', minute: '2-digit' }`, `{ dateStyle: 'short' }` for times. Unused for durations.
|
|
26
|
+
* Dollar-sign currencies show their country (`AR$`, `MX$`, `US$`) in any language; set `currencyDisplay` for
|
|
27
|
+
* Intl's own output (`'symbol'` gives the local peso as a plain `$`)
|
|
28
|
+
*/
|
|
29
|
+
format?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions
|
|
30
|
+
/** BCP-47 language for the format (`es-AR` for Argentine pesos and separators); defaults to the app's locale */
|
|
31
|
+
locale?: string
|
|
32
|
+
/** The rolling spring; Standard SlowSpatial by default (an unhurried landing, no visible bounce) */
|
|
33
|
+
spring?: SpringSpec
|
|
34
|
+
/** Roll to new values; false (or the system's reduced motion) jumps to them */
|
|
35
|
+
animate?: boolean
|
|
36
|
+
}>(),
|
|
37
|
+
{ animate: true },
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const t = useLocale()
|
|
41
|
+
const lang = computed(() => props.locale ?? t.lang)
|
|
42
|
+
const kind = computed(() => props.type ?? (props.value instanceof Date ? 'datetime' : 'number'))
|
|
43
|
+
const numeric = computed(() => (props.value instanceof Date ? props.value.getTime() : props.value))
|
|
44
|
+
|
|
45
|
+
type Part = { type: string; value: string }
|
|
46
|
+
|
|
47
|
+
function durationParts(total: number): Part[] {
|
|
48
|
+
const sign = total < 0 ? '-' : ''
|
|
49
|
+
const s = Math.floor(Math.abs(total))
|
|
50
|
+
const h = Math.floor(s / 3600)
|
|
51
|
+
const m = Math.floor((s % 3600) / 60)
|
|
52
|
+
const parts: Part[] = []
|
|
53
|
+
if (sign) parts.push({ type: 'minusSign', value: sign })
|
|
54
|
+
if (h) parts.push({ type: 'hour', value: String(h) }, { type: 'literal', value: ':' })
|
|
55
|
+
parts.push(
|
|
56
|
+
{ type: 'minute', value: h ? String(m).padStart(2, '0') : String(m) },
|
|
57
|
+
{ type: 'literal', value: ':' },
|
|
58
|
+
{ type: 'second', value: String(s % 60).padStart(2, '0') },
|
|
59
|
+
)
|
|
60
|
+
return parts
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const parts = computed<Part[]>(() => {
|
|
64
|
+
if (kind.value === 'duration') return durationParts(numeric.value)
|
|
65
|
+
if (kind.value === 'datetime') {
|
|
66
|
+
const options = (props.format as Intl.DateTimeFormatOptions | undefined) ?? { timeStyle: 'medium' }
|
|
67
|
+
return new Intl.DateTimeFormat(lang.value, options).formatToParts(numeric.value)
|
|
68
|
+
}
|
|
69
|
+
const format = props.format as Intl.NumberFormatOptions | undefined
|
|
70
|
+
const out = new Intl.NumberFormat(lang.value, format).formatToParts(numeric.value)
|
|
71
|
+
if (format?.style !== 'currency' || format.currencyDisplay || !format.currency) return out
|
|
72
|
+
// Intl writes a plain "$" (the local peso, US dollars in the US) or a code (MXN in Argentina) for many currencies:
|
|
73
|
+
// give the dollar-sign ones their country instead (AR$, MX$, US$), with the language's spacing for a symbol.
|
|
74
|
+
// Symbols that already say which currency they are (US$, MX$, €, R$, ¥) stay as Intl writes them.
|
|
75
|
+
const code = format.currency.toUpperCase()
|
|
76
|
+
const symbol = out.find((p) => p.type === 'currency')?.value
|
|
77
|
+
if (symbol !== '$' && symbol !== code) return out
|
|
78
|
+
const narrow = new Intl.NumberFormat(lang.value, { ...format, currencyDisplay: 'narrowSymbol' }).formatToParts(numeric.value)
|
|
79
|
+
for (const p of narrow) if (p.type === 'currency' && p.value === '$') p.value = code === 'TWD' ? 'NT$' : `${code.slice(0, 2)}$`
|
|
80
|
+
return narrow
|
|
81
|
+
})
|
|
82
|
+
const text = computed(() => parts.value.map((p) => p.value).join(''))
|
|
83
|
+
|
|
84
|
+
interface Cell {
|
|
85
|
+
key: string
|
|
86
|
+
char: string
|
|
87
|
+
digit?: number
|
|
88
|
+
/** Digits a column cycles through: 10, or 6 for the tens of minutes and seconds */
|
|
89
|
+
base: number
|
|
90
|
+
/** Roll the short way (hours: 12 → 1 is one step back, not nine forward) */
|
|
91
|
+
shortest: boolean
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const DATE_DIGITS = new Set(['hour', 'minute', 'second', 'day', 'month', 'year', 'fractionalSecond', 'relatedYear'])
|
|
95
|
+
|
|
96
|
+
// Number digits are keyed by their place (ones, tens, tenths...), time digits by their field and place within it, so
|
|
97
|
+
// each keeps its column, and its spring, as the value changes; everything else by its type and where it sits.
|
|
98
|
+
const cells = computed<Cell[]>(() => {
|
|
99
|
+
const out: Cell[] = []
|
|
100
|
+
const push = (key: string, ch: string, base = 10, shortest = false) => {
|
|
101
|
+
const digit = Number(ch)
|
|
102
|
+
out.push(ch.trim() && !Number.isNaN(digit) ? { key, char: ch, digit, base, shortest } : { key: `${key}-${ch}`, char: ch, base, shortest })
|
|
103
|
+
}
|
|
104
|
+
if (kind.value === 'number') {
|
|
105
|
+
let place = parts.value.filter((p) => p.type === 'integer').reduce((n, p) => n + p.value.length, 0)
|
|
106
|
+
let fraction = 0
|
|
107
|
+
for (const part of parts.value) {
|
|
108
|
+
if (part.type === 'integer' || part.type === 'fraction') {
|
|
109
|
+
for (const ch of part.value) push(part.type === 'integer' ? `i${--place}` : `f${++fraction}`, ch)
|
|
110
|
+
} else {
|
|
111
|
+
const at = part.type === 'group' ? place : part.type === 'decimal' ? 'd' : out.length
|
|
112
|
+
out.push({ key: `${part.type}-${at}`, char: part.value, base: 10, shortest: false })
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return out
|
|
116
|
+
}
|
|
117
|
+
parts.value.forEach((part, index) => {
|
|
118
|
+
if (!DATE_DIGITS.has(part.type)) {
|
|
119
|
+
out.push({ key: `${part.type}-${index}`, char: part.value, base: 10, shortest: false })
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
const chars = [...part.value]
|
|
123
|
+
chars.forEach((ch, i) => {
|
|
124
|
+
const fromRight = chars.length - 1 - i
|
|
125
|
+
const sixty = (part.type === 'minute' || part.type === 'second') && fromRight === 1
|
|
126
|
+
push(`${part.type}-${fromRight}`, ch, sixty ? 6 : 10, part.type === 'hour')
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
return out
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
// ── Rolling: one spring per digit column, stepped in a rAF loop and written to its strip's transform ─────────
|
|
133
|
+
interface Column { pos: number; vel: number; target: number; base: number; el?: HTMLElement; rolling?: boolean }
|
|
134
|
+
const columns = new Map<string, Column>()
|
|
135
|
+
let mounted = false
|
|
136
|
+
let raf = 0
|
|
137
|
+
let last = 0
|
|
138
|
+
let direction = 1
|
|
139
|
+
const reduceMotion = () => typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
140
|
+
|
|
141
|
+
const mod = (n: number, base: number) => ((n % base) + base) % base
|
|
142
|
+
const write = (c: Column) => {
|
|
143
|
+
if (!c.el) return
|
|
144
|
+
c.el.style.transform = `translateY(${-mod(c.pos, c.base)}lh)`
|
|
145
|
+
// Unmasked a little before landing, so the mask eases out with the last of the roll. Only touched when it changes:
|
|
146
|
+
// an attribute write every frame restyles the column every frame
|
|
147
|
+
const rolling = Math.abs(c.pos - c.target) > 0.15
|
|
148
|
+
if (rolling !== c.rolling) {
|
|
149
|
+
c.rolling = rolling
|
|
150
|
+
c.el.parentElement?.toggleAttribute('data-rolling', rolling)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// The strip's starting transform, set once per column, so the server renders the right digits. Vue may write it
|
|
155
|
+
// again when it patches the list (a digit added before it), so onUpdated puts every column back where it is.
|
|
156
|
+
const initialStyles = new Map<string, Record<string, string>>()
|
|
157
|
+
function initialStyle(cell: Cell) {
|
|
158
|
+
let style = initialStyles.get(cell.key)
|
|
159
|
+
if (!style) {
|
|
160
|
+
// A column that appears after mount rolls in from 0; the first render shows the digits as they are
|
|
161
|
+
const start = mounted && props.animate ? 0 : cell.digit!
|
|
162
|
+
columns.set(cell.key, { pos: start, vel: 0, target: cell.digit!, base: cell.base })
|
|
163
|
+
style = { transform: `translateY(${-start}lh)` }
|
|
164
|
+
initialStyles.set(cell.key, style)
|
|
165
|
+
}
|
|
166
|
+
return style
|
|
167
|
+
}
|
|
168
|
+
const setStrip = (key: string) => (el: unknown) => {
|
|
169
|
+
const c = columns.get(key)
|
|
170
|
+
if (!c) return
|
|
171
|
+
const next = (el as HTMLElement | null) ?? undefined
|
|
172
|
+
// A new element doesn't carry the old one's data-rolling
|
|
173
|
+
if (next !== c.el) c.rolling = undefined
|
|
174
|
+
c.el = next
|
|
175
|
+
}
|
|
176
|
+
// Two runs of the column's digits, so a digit rolling past the last shows the first coming in below it seamlessly
|
|
177
|
+
const strip = (base: number) => Array.from({ length: base * 2 }, (_, i) => i % base)
|
|
178
|
+
|
|
179
|
+
function frame(now: number) {
|
|
180
|
+
let dt = Math.min((now - last) / 1000, 1 / 30)
|
|
181
|
+
last = now
|
|
182
|
+
const { stiffness: k, dampingRatio } = props.spring ?? motionSprings.standard.slowSpatial
|
|
183
|
+
const c = 2 * dampingRatio * Math.sqrt(k)
|
|
184
|
+
let moving = false
|
|
185
|
+
while (dt > 0) {
|
|
186
|
+
const h = Math.min(dt, 0.004)
|
|
187
|
+
dt -= h
|
|
188
|
+
for (const col of columns.values()) {
|
|
189
|
+
col.vel += (-k * (col.pos - col.target) - c * col.vel) * h
|
|
190
|
+
col.pos += col.vel * h
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
for (const col of columns.values()) {
|
|
194
|
+
if (Math.abs(col.pos - col.target) < 0.002 && Math.abs(col.vel) < 0.01) {
|
|
195
|
+
col.pos = col.target
|
|
196
|
+
col.vel = 0
|
|
197
|
+
} else moving = true
|
|
198
|
+
write(col)
|
|
199
|
+
}
|
|
200
|
+
raf = moving ? requestAnimationFrame(frame) : 0
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
watch(numeric, (next, prev) => (direction = next >= (prev ?? next) ? 1 : -1))
|
|
204
|
+
|
|
205
|
+
watch(cells, (next) => {
|
|
206
|
+
const keys = new Set(next.map((c) => c.key))
|
|
207
|
+
for (const key of [...columns.keys()]) {
|
|
208
|
+
if (!keys.has(key)) {
|
|
209
|
+
columns.delete(key)
|
|
210
|
+
initialStyles.delete(key)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const instant = !props.animate || reduceMotion()
|
|
214
|
+
for (const cell of next) {
|
|
215
|
+
const col = cell.digit === undefined ? undefined : columns.get(cell.key)
|
|
216
|
+
if (!col) continue
|
|
217
|
+
const base = col.base
|
|
218
|
+
const from = mod(Math.round(col.target), base)
|
|
219
|
+
const forward = mod(cell.digit! - from, base)
|
|
220
|
+
const backward = mod(from - cell.digit!, base)
|
|
221
|
+
// Forward through the last digit → 0 when the value grows, backward when it shrinks; hours the short way
|
|
222
|
+
col.target += cell.shortest ? (forward <= backward ? forward : -backward) : direction > 0 ? forward : -backward
|
|
223
|
+
if (instant) {
|
|
224
|
+
col.pos = col.target
|
|
225
|
+
col.vel = 0
|
|
226
|
+
write(col)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (!instant && !raf && mounted) {
|
|
230
|
+
last = performance.now()
|
|
231
|
+
raf = requestAnimationFrame(frame)
|
|
232
|
+
}
|
|
233
|
+
}, { flush: 'post' })
|
|
234
|
+
|
|
235
|
+
onMounted(() => {
|
|
236
|
+
mounted = true
|
|
237
|
+
for (const col of columns.values()) write(col)
|
|
238
|
+
})
|
|
239
|
+
onUpdated(() => {
|
|
240
|
+
for (const col of columns.values()) write(col)
|
|
241
|
+
})
|
|
242
|
+
onUnmounted(() => cancelAnimationFrame(raf))
|
|
243
|
+
</script>
|
|
244
|
+
|
|
245
|
+
<template>
|
|
246
|
+
<span class="m3-animated-number">
|
|
247
|
+
<span class="m3-anum-sr">{{ text }}</span>
|
|
248
|
+
<TransitionGroup name="m3-anum" tag="span" class="m3-anum-cells" aria-hidden="true">
|
|
249
|
+
<span v-for="cell in cells" :key="cell.key" class="m3-anum-cell" :class="cell.digit !== undefined && 'm3-anum-digit'">
|
|
250
|
+
<span v-if="cell.digit !== undefined" :ref="setStrip(cell.key)" class="m3-anum-strip" :style="initialStyle(cell)">
|
|
251
|
+
<span v-for="(d, i) in strip(cell.base)" :key="i">{{ d }}</span>
|
|
252
|
+
</span>
|
|
253
|
+
<template v-else>{{ cell.char }}</template>
|
|
254
|
+
</span>
|
|
255
|
+
</TransitionGroup>
|
|
256
|
+
</span>
|
|
257
|
+
</template>
|
|
258
|
+
|
|
259
|
+
<style>
|
|
260
|
+
/* Defaults in the base layer so the consumer's classes on the root win (see MShape). */
|
|
261
|
+
@layer base {
|
|
262
|
+
.m3-animated-number {
|
|
263
|
+
display: inline-flex;
|
|
264
|
+
position: relative;
|
|
265
|
+
font-variant-numeric: tabular-nums;
|
|
266
|
+
white-space: nowrap;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
.m3-anum-sr {
|
|
270
|
+
position: absolute;
|
|
271
|
+
width: 1px;
|
|
272
|
+
height: 1px;
|
|
273
|
+
overflow: hidden;
|
|
274
|
+
clip-path: inset(50%);
|
|
275
|
+
white-space: nowrap;
|
|
276
|
+
}
|
|
277
|
+
.m3-anum-cells {
|
|
278
|
+
display: inline-flex;
|
|
279
|
+
}
|
|
280
|
+
.m3-anum-cell {
|
|
281
|
+
display: inline-block;
|
|
282
|
+
white-space: pre;
|
|
283
|
+
}
|
|
284
|
+
.m3-anum-digit {
|
|
285
|
+
height: 1lh;
|
|
286
|
+
width: 1ch;
|
|
287
|
+
overflow: hidden;
|
|
288
|
+
/* Rolling digits fade at the column's edges. At rest the mask is stretched so its fades fall outside the
|
|
289
|
+
column; it eases in and out instead of switching, which read as an abrupt stop. */
|
|
290
|
+
mask-image: linear-gradient(transparent, #000 20%, #000 80%, transparent);
|
|
291
|
+
mask-size: 100% 180%;
|
|
292
|
+
mask-position: center;
|
|
293
|
+
mask-repeat: no-repeat;
|
|
294
|
+
transition: mask-size 350ms cubic-bezier(0.2, 0, 0, 1);
|
|
295
|
+
}
|
|
296
|
+
.m3-anum-digit[data-rolling] {
|
|
297
|
+
mask-size: 100% 100%;
|
|
298
|
+
transition-duration: 120ms;
|
|
299
|
+
}
|
|
300
|
+
/* Its own layer while it rolls, so moving it doesn't repaint the column */
|
|
301
|
+
.m3-anum-digit[data-rolling] > .m3-anum-strip {
|
|
302
|
+
will-change: transform;
|
|
303
|
+
}
|
|
304
|
+
.m3-anum-strip {
|
|
305
|
+
display: flex;
|
|
306
|
+
flex-direction: column;
|
|
307
|
+
align-items: center;
|
|
308
|
+
}
|
|
309
|
+
.m3-anum-strip > span {
|
|
310
|
+
height: 1lh;
|
|
311
|
+
}
|
|
312
|
+
.m3-anum-enter-active,
|
|
313
|
+
.m3-anum-leave-active {
|
|
314
|
+
transition: width 300ms cubic-bezier(0.2, 0, 0, 1), opacity 200ms ease;
|
|
315
|
+
}
|
|
316
|
+
.m3-anum-enter-from,
|
|
317
|
+
.m3-anum-leave-to {
|
|
318
|
+
width: 0;
|
|
319
|
+
opacity: 0;
|
|
320
|
+
}
|
|
321
|
+
@media (prefers-reduced-motion: reduce) {
|
|
322
|
+
.m3-anum-enter-active,
|
|
323
|
+
.m3-anum-leave-active {
|
|
324
|
+
transition: none;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
</style>
|
|
@@ -75,6 +75,14 @@ const modalOpen = ref(false)
|
|
|
75
75
|
const modalSearch = ref('')
|
|
76
76
|
const search = ref('')
|
|
77
77
|
const highlightIndex = ref(-1)
|
|
78
|
+
// ARIA combobox + listbox: the input points at the open list and the option the arrow keys are on
|
|
79
|
+
const listId = `${id}-list`
|
|
80
|
+
const optionId = (i: number) => `${id}-opt-${i}`
|
|
81
|
+
const activeOption = computed(() => {
|
|
82
|
+
if (!open.value && !modalOpen.value) return undefined
|
|
83
|
+
const i = filteredOptions.value.findIndex((o) => !o.disabled && getEnabledIndex(o) === highlightIndex.value)
|
|
84
|
+
return i >= 0 ? optionId(i) : undefined
|
|
85
|
+
})
|
|
78
86
|
const fieldEl = ref<HTMLElement | null>(null)
|
|
79
87
|
const inputEl = ref<HTMLInputElement | null>(null)
|
|
80
88
|
const { resolvedFieldBg } = useFieldBg(fieldEl, () => props.fieldBg)
|
|
@@ -350,7 +358,12 @@ const labelClasses = computed(() => {
|
|
|
350
358
|
:disabled="disabled"
|
|
351
359
|
autocomplete="off"
|
|
352
360
|
role="combobox"
|
|
353
|
-
|
|
361
|
+
aria-autocomplete="list"
|
|
362
|
+
:aria-expanded="open || modalOpen"
|
|
363
|
+
:aria-controls="open || modalOpen ? listId : undefined"
|
|
364
|
+
:aria-activedescendant="activeOption"
|
|
365
|
+
:aria-required="required || undefined"
|
|
366
|
+
:aria-invalid="error || undefined"
|
|
354
367
|
:aria-disabled="disabled"
|
|
355
368
|
:class="[
|
|
356
369
|
triggerClasses,
|
|
@@ -371,6 +384,7 @@ const labelClasses = computed(() => {
|
|
|
371
384
|
|
|
372
385
|
<!-- Clear button -->
|
|
373
386
|
<button
|
|
387
|
+
:aria-label="locale.clear"
|
|
374
388
|
v-if="clearable && hasValue && !disabled"
|
|
375
389
|
type="button"
|
|
376
390
|
class="absolute right-9 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"
|
|
@@ -409,13 +423,20 @@ const labelClasses = computed(() => {
|
|
|
409
423
|
>
|
|
410
424
|
<div
|
|
411
425
|
v-if="open && mode === 'docked'"
|
|
426
|
+
:id="listId"
|
|
412
427
|
ref="dropdownEl"
|
|
428
|
+
role="listbox"
|
|
429
|
+
:aria-label="label || undefined"
|
|
413
430
|
class="fixed z-500 max-h-60 overflow-auto rounded-xs bg-surface-container py-1 shadow-elevation-2"
|
|
414
431
|
:style="dropPos"
|
|
415
432
|
>
|
|
416
433
|
<div
|
|
417
434
|
v-for="(opt, i) in filteredOptions"
|
|
435
|
+
:id="optionId(i)"
|
|
418
436
|
:key="i"
|
|
437
|
+
role="option"
|
|
438
|
+
:aria-selected="eq(opt.value, modelValue)"
|
|
439
|
+
:aria-disabled="opt.disabled || undefined"
|
|
419
440
|
data-option
|
|
420
441
|
class="flex cursor-pointer items-center gap-3 px-4 py-3 text-body-large"
|
|
421
442
|
:class="[
|
|
@@ -452,9 +473,14 @@ const labelClasses = computed(() => {
|
|
|
452
473
|
class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/32 p-4"
|
|
453
474
|
@click.self="closeDropdown"
|
|
454
475
|
>
|
|
455
|
-
<div
|
|
476
|
+
<div
|
|
477
|
+
class="ac-modal-box flex max-h-[80vh] w-full max-w-sm flex-col overflow-hidden rounded-[28px] bg-surface-container-high shadow-elevation-3"
|
|
478
|
+
role="dialog"
|
|
479
|
+
aria-modal="true"
|
|
480
|
+
:aria-labelledby="`${id}-dialog-title`"
|
|
481
|
+
>
|
|
456
482
|
<div class="flex items-center justify-between px-6 pt-6 pb-4">
|
|
457
|
-
<h2 class="text-headline-small text-on-surface">{{ label || placeholder }}</h2>
|
|
483
|
+
<h2 :id="`${id}-dialog-title`" class="text-headline-small text-on-surface">{{ label || placeholder }}</h2>
|
|
458
484
|
<MIconButton icon="close" :label="locale.close" @click="closeDropdown" />
|
|
459
485
|
</div>
|
|
460
486
|
|
|
@@ -473,10 +499,14 @@ const labelClasses = computed(() => {
|
|
|
473
499
|
|
|
474
500
|
<div class="h-px bg-outline-variant" />
|
|
475
501
|
|
|
476
|
-
<div class="flex-1 overflow-y-auto py-2">
|
|
502
|
+
<div :id="listId" role="listbox" :aria-labelledby="`${id}-dialog-title`" class="flex-1 overflow-y-auto py-2">
|
|
477
503
|
<div
|
|
478
504
|
v-for="(opt, i) in modalFilteredOptions"
|
|
505
|
+
:id="optionId(i)"
|
|
479
506
|
:key="i"
|
|
507
|
+
role="option"
|
|
508
|
+
:aria-selected="eq(opt.value, modelValue)"
|
|
509
|
+
:aria-disabled="opt.disabled || undefined"
|
|
480
510
|
class="flex cursor-pointer items-center gap-4 px-6 py-3.5 text-body-large transition-colors"
|
|
481
511
|
:class="[
|
|
482
512
|
opt.disabled
|
|
@@ -248,6 +248,7 @@ const squareCorners = computed(() => props.squareCornersWhenFull && isExpanded.v
|
|
|
248
248
|
<div v-if="title" class="flex shrink-0 items-center justify-between px-6 pb-4">
|
|
249
249
|
<h2 class="text-title-large text-on-surface">{{ title }}</h2>
|
|
250
250
|
<button
|
|
251
|
+
:aria-label="locale.close"
|
|
251
252
|
type="button"
|
|
252
253
|
class="flex h-9 w-9 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8"
|
|
253
254
|
@click="close"
|
|
@@ -30,6 +30,8 @@ const props = withDefaults(
|
|
|
30
30
|
loading?: boolean
|
|
31
31
|
/** Material Symbol icon name shown next to the label */
|
|
32
32
|
icon?: string
|
|
33
|
+
/** Draw the icon filled (Material Symbols' FILL axis), e.g. a starred star or a play icon */
|
|
34
|
+
iconFilled?: boolean
|
|
33
35
|
/** Which side of the label the icon renders on */
|
|
34
36
|
// Which side of the label `icon` renders on. Real M3 buttons support both via
|
|
35
37
|
// `ButtonDefaults.contentPaddingFor(hasStartIcon/hasEndIcon)` — padding ends up identical
|
|
@@ -182,12 +184,12 @@ const variantClasses = computed(() => {
|
|
|
182
184
|
>
|
|
183
185
|
<template v-if="iconPos === 'leading'">
|
|
184
186
|
<MSpinner v-if="loading" :size="spinnerSize" />
|
|
185
|
-
<MIcon v-else-if="icon" :name="icon" :size="iconSize" />
|
|
187
|
+
<MIcon v-else-if="icon" :name="icon" :size="iconSize" :filled="iconFilled" />
|
|
186
188
|
</template>
|
|
187
189
|
<slot />
|
|
188
190
|
<template v-if="iconPos === 'trailing'">
|
|
189
191
|
<MSpinner v-if="loading" :size="spinnerSize" />
|
|
190
|
-
<MIcon v-else-if="icon" :name="icon" :size="iconSize" />
|
|
192
|
+
<MIcon v-else-if="icon" :name="icon" :size="iconSize" :filled="iconFilled" />
|
|
191
193
|
</template>
|
|
192
194
|
</component>
|
|
193
195
|
</template>
|