@m3ui-vue/m3ui-vue 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/API.md +69 -8
- package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
- package/dist/MIcon-DLOkQduI.js.map +1 -0
- package/dist/{MTextField-Ck0oWDMk.js → MTextField-DKtgPymd.js} +416 -206
- package/dist/MTextField-DKtgPymd.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.md +547 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MButton.vue.d.ts +4 -2
- package/dist/components/MButtonGroup.vue.d.ts +2 -0
- package/dist/components/MFab.vue.d.ts +4 -2
- package/dist/components/MIcon.vue.d.ts +3 -0
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MMenuItem.vue.d.ts +17 -4
- package/dist/components/MSplitButton.vue.d.ts +2 -0
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTimePickerModal.vue.d.ts +3 -0
- package/dist/components/MTimeScroll.vue.d.ts +22 -0
- package/dist/components/MToggleButton.vue.d.ts +2 -0
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
- package/dist/composables/_useSpring.d.ts +2 -0
- package/dist/composables/useLocale.d.ts +6 -0
- package/dist/directives/vRipple.d.ts +16 -0
- package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
- package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
- package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
- package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
- package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
- package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
- package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
- package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/locales/index.js +42 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +5741 -5634
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +22 -22
- package/dist/styles/theme.css +13 -0
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-CFW8cIzL.js → useLocale-Cn9MVIdw.js} +7 -1
- package/dist/useLocale-Cn9MVIdw.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/MIconButton.test.ts +60 -0
- package/src/__tests__/MMenuItem.test.ts +84 -0
- package/src/__tests__/MScrollField.test.ts +28 -0
- package/src/__tests__/MTabs.test.ts +39 -0
- package/src/__tests__/MTimePickerModal.test.ts +52 -0
- package/src/__tests__/MTimeScroll.test.ts +44 -0
- package/src/__tests__/vRipple.test.ts +92 -0
- package/src/components/MButton.vue +4 -13
- package/src/components/MButtonGroup.vue +4 -11
- package/src/components/MFab.vue +8 -15
- package/src/components/MIcon.vue +4 -2
- package/src/components/MIconButton.vue +96 -24
- package/src/components/MMenuItem.vue +115 -13
- package/src/components/MScrollField.vue +10 -2
- package/src/components/MSplitButton.vue +5 -12
- package/src/components/MTabs.vue +16 -5
- package/src/components/MTimePickerModal.vue +48 -8
- package/src/components/MTimeScroll.vue +161 -0
- package/src/components/MToggleButton.vue +5 -12
- package/src/composables/_carouselStrategy.ts +3 -0
- package/src/composables/_useSpring.ts +2 -0
- package/src/composables/useLocale.ts +12 -0
- package/src/data/emoji-names/emoji-names-de.ts +1 -0
- package/src/data/emoji-names/emoji-names-en.ts +1 -0
- package/src/data/emoji-names/emoji-names-es.ts +1 -0
- package/src/data/emoji-names/emoji-names-fr.ts +1 -0
- package/src/data/emoji-names/emoji-names-ja.ts +1 -0
- package/src/data/emoji-names/emoji-names-ko.ts +1 -0
- package/src/data/emoji-names/emoji-names-pt.ts +1 -0
- package/src/data/emoji-names/emoji-names-zh.ts +1 -0
- package/src/data/emojis.ts +1 -0
- package/src/directives/vRipple.ts +73 -0
- package/src/index.ts +5 -0
- package/src/locales/de.ts +6 -0
- package/src/locales/es.ts +6 -0
- package/src/locales/fr.ts +6 -0
- package/src/locales/ja.ts +6 -0
- package/src/locales/ko.ts +6 -0
- package/src/locales/pt.ts +6 -0
- package/src/locales/zh.ts +6 -0
- package/src/plugin.ts +2 -0
- package/src/styles/theme.css +13 -0
- package/dist/MIcon-CaEooCmZ.js.map +0 -1
- package/dist/MTextField-Ck0oWDMk.js.map +0 -1
- package/dist/useLocale-CFW8cIzL.js.map +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MTimePickerModal from '../components/MTimePickerModal.vue'
|
|
5
|
+
import MTimeScroll from '../components/MTimeScroll.vue'
|
|
6
|
+
|
|
7
|
+
let wrapper: VueWrapper | undefined
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
wrapper?.unmount()
|
|
10
|
+
wrapper = undefined
|
|
11
|
+
document.body.innerHTML = ''
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
async function open(props: Record<string, unknown>) {
|
|
15
|
+
wrapper = mount(MTimePickerModal, { props: { modelValue: null, ...props }, attachTo: document.body })
|
|
16
|
+
await wrapper.setProps({ show: true })
|
|
17
|
+
await nextTick()
|
|
18
|
+
return wrapper
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const button = (text: string) => [...document.body.querySelectorAll('button')].find((b) => b.textContent?.trim() === text)!
|
|
22
|
+
|
|
23
|
+
describe('MTimePickerModal', () => {
|
|
24
|
+
it('shows the clock dial by default', async () => {
|
|
25
|
+
const w = await open({ modelValue: '09:30' })
|
|
26
|
+
expect(w.findComponent(MTimeScroll).exists()).toBe(false)
|
|
27
|
+
expect(document.body.textContent).toContain('09')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('picks the time with scroll wheels in scroll mode and confirms it as 24-hour', async () => {
|
|
31
|
+
const w = await open({ modelValue: '21:07', mode: 'scroll' })
|
|
32
|
+
const scroll = w.findComponent(MTimeScroll)
|
|
33
|
+
expect(scroll.exists()).toBe(true)
|
|
34
|
+
// The minute wheel only shows multiples of minuteStep (5): it starts on 05
|
|
35
|
+
expect(scroll.props('modelValue')).toBe('21:05')
|
|
36
|
+
await scroll.vm.$emit('update:modelValue', '08:45')
|
|
37
|
+
button('OK').click()
|
|
38
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['08:45'])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('switches between scroll and keyboard input', async () => {
|
|
42
|
+
const w = await open({ modelValue: '14:00', mode: 'scroll', use24h: true })
|
|
43
|
+
const toggle = document.body.querySelector<HTMLButtonElement>('[aria-label="Switch to text input mode"]')!
|
|
44
|
+
toggle.click()
|
|
45
|
+
await nextTick()
|
|
46
|
+
expect(w.findComponent(MTimeScroll).exists()).toBe(false)
|
|
47
|
+
expect(document.body.querySelectorAll('input')).toHaveLength(2)
|
|
48
|
+
document.body.querySelector<HTMLButtonElement>('[aria-label="Switch to scroll mode"]')!.click()
|
|
49
|
+
await nextTick()
|
|
50
|
+
expect(w.findComponent(MTimeScroll).props('modelValue')).toBe('14:00')
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MTimeScroll from '../components/MTimeScroll.vue'
|
|
4
|
+
import MScrollField from '../components/MScrollField.vue'
|
|
5
|
+
|
|
6
|
+
describe('MTimeScroll', () => {
|
|
7
|
+
it('maps a 12-hour time onto the wheels (12 o\'clock is the last hour item)', () => {
|
|
8
|
+
const w = mount(MTimeScroll, { props: { modelValue: '00:30' } })
|
|
9
|
+
const [hours, minutes] = w.findAllComponents(MScrollField)
|
|
10
|
+
expect(hours!.props('count')).toBe(12)
|
|
11
|
+
expect(hours!.props('modelValue')).toBe(11)
|
|
12
|
+
expect(minutes!.props('modelValue')).toBe(30)
|
|
13
|
+
expect(w.find('[role="radio"][aria-checked="true"]').text()).toMatch(/AM/i)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('keeps AM/PM when the hour wheel turns', async () => {
|
|
17
|
+
const w = mount(MTimeScroll, { props: { modelValue: '15:00' } })
|
|
18
|
+
await w.findAllComponents(MScrollField)[0]!.vm.$emit('update:modelValue', 0)
|
|
19
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['13:00'])
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('switches period with the toggle', async () => {
|
|
23
|
+
const w = mount(MTimeScroll, { props: { modelValue: '09:15' } })
|
|
24
|
+
await w.findAll('[role="radio"]')[1]!.trigger('click')
|
|
25
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['21:15'])
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('uses a 24-hour wheel without the toggle', async () => {
|
|
29
|
+
const w = mount(MTimeScroll, { props: { modelValue: '18:40', use24h: true } })
|
|
30
|
+
const [hours] = w.findAllComponents(MScrollField)
|
|
31
|
+
expect(hours!.props('count')).toBe(24)
|
|
32
|
+
expect(hours!.props('modelValue')).toBe(18)
|
|
33
|
+
expect(w.find('[role="radiogroup"]').exists()).toBe(false)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('steps minutes by minuteStep', async () => {
|
|
37
|
+
const w = mount(MTimeScroll, { props: { modelValue: '10:07', minuteStep: 5 } })
|
|
38
|
+
const minutes = w.findAllComponents(MScrollField)[1]!
|
|
39
|
+
expect(minutes.props('count')).toBe(12)
|
|
40
|
+
expect(minutes.props('modelValue')).toBe(1)
|
|
41
|
+
await minutes.vm.$emit('update:modelValue', 3)
|
|
42
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['10:15'])
|
|
43
|
+
})
|
|
44
|
+
})
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, ref, withDirectives } from 'vue'
|
|
4
|
+
import { vRipple, type RippleValue } from '../directives/vRipple'
|
|
5
|
+
import MButton from '../components/MButton.vue'
|
|
6
|
+
|
|
7
|
+
function host(value: RippleValue | (() => RippleValue)) {
|
|
8
|
+
return mount(defineComponent({
|
|
9
|
+
setup() {
|
|
10
|
+
return () => withDirectives(h('div', { class: 'host' }), [[vRipple, typeof value === 'function' ? value() : value]])
|
|
11
|
+
},
|
|
12
|
+
}))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function press(el: Element, button = 0) {
|
|
16
|
+
el.dispatchEvent(new PointerEvent('pointerdown', { button, clientX: 10, clientY: 10, bubbles: true }))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('vRipple', () => {
|
|
20
|
+
it('spawns a ripple inside a clipping layer on press', () => {
|
|
21
|
+
const w = host(undefined)
|
|
22
|
+
press(w.element)
|
|
23
|
+
const layer = w.element.querySelector('.m3-ripple-layer')
|
|
24
|
+
expect(layer).not.toBeNull()
|
|
25
|
+
expect(layer!.querySelector('.m3-ripple')).not.toBeNull()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('removes the layer when the animation ends', () => {
|
|
29
|
+
const w = host(true)
|
|
30
|
+
press(w.element)
|
|
31
|
+
w.element.querySelector('.m3-ripple')!.dispatchEvent(new Event('animationend'))
|
|
32
|
+
expect(w.element.querySelector('.m3-ripple-layer')).toBeNull()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('makes a statically positioned host relative', () => {
|
|
36
|
+
const w = mount(defineComponent({
|
|
37
|
+
setup: () => () => withDirectives(h('div'), [[vRipple, true]]),
|
|
38
|
+
}), { attachTo: document.body })
|
|
39
|
+
press(w.element)
|
|
40
|
+
expect((w.element as HTMLElement).style.position).toBe('relative')
|
|
41
|
+
w.unmount()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('does nothing when false or disabled', () => {
|
|
45
|
+
for (const value of [false, { disabled: true }] as RippleValue[]) {
|
|
46
|
+
const w = host(value)
|
|
47
|
+
press(w.element)
|
|
48
|
+
expect(w.element.querySelector('.m3-ripple')).toBeNull()
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('ignores secondary buttons', () => {
|
|
53
|
+
const w = host(true)
|
|
54
|
+
press(w.element, 2)
|
|
55
|
+
expect(w.element.querySelector('.m3-ripple')).toBeNull()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('takes a color as a string or an option', () => {
|
|
59
|
+
for (const value of ['rgb(255, 0, 0)', { color: 'rgb(255, 0, 0)' }] as RippleValue[]) {
|
|
60
|
+
const w = host(value)
|
|
61
|
+
press(w.element)
|
|
62
|
+
expect((w.element.querySelector('.m3-ripple') as HTMLElement).style.background).toBe('rgb(255, 0, 0)')
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('follows binding updates', async () => {
|
|
67
|
+
const disabled = ref(true)
|
|
68
|
+
const w = mount(defineComponent({
|
|
69
|
+
setup() {
|
|
70
|
+
return () => withDirectives(h('div'), [[vRipple, { disabled: disabled.value }]])
|
|
71
|
+
},
|
|
72
|
+
}))
|
|
73
|
+
press(w.element)
|
|
74
|
+
expect(w.element.querySelector('.m3-ripple')).toBeNull()
|
|
75
|
+
disabled.value = false
|
|
76
|
+
await w.vm.$nextTick()
|
|
77
|
+
press(w.element)
|
|
78
|
+
expect(w.element.querySelector('.m3-ripple')).not.toBeNull()
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
describe('MButton ripple', () => {
|
|
83
|
+
it('uses rippleColor and skips the ripple while loading', async () => {
|
|
84
|
+
const w = mount(MButton, { props: { rippleColor: 'rgb(0, 0, 255)' }, slots: { default: 'Go' } })
|
|
85
|
+
press(w.element)
|
|
86
|
+
expect((w.element.querySelector('.m3-ripple') as HTMLElement).style.background).toBe('rgb(0, 0, 255)')
|
|
87
|
+
await w.setProps({ loading: true })
|
|
88
|
+
w.element.querySelectorAll('.m3-ripple-layer').forEach((l) => l.remove())
|
|
89
|
+
press(w.element)
|
|
90
|
+
expect(w.element.querySelector('.m3-ripple')).toBeNull()
|
|
91
|
+
})
|
|
92
|
+
})
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { computed } from 'vue'
|
|
8
8
|
import MSpinner from './MSpinner.vue'
|
|
9
9
|
import MIcon from './MIcon.vue'
|
|
10
|
+
import { vRipple } from '../directives/vRipple'
|
|
10
11
|
|
|
11
12
|
const NAMED_COLORS = ['primary', 'error'] as const
|
|
12
13
|
type NamedColor = (typeof NAMED_COLORS)[number]
|
|
@@ -46,6 +47,8 @@ const props = withDefaults(
|
|
|
46
47
|
shape?: 'rounded' | 'squared'
|
|
47
48
|
/** Vue Router destination — renders as RouterLink instead of button */
|
|
48
49
|
to?: string | Record<string, any>
|
|
50
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
51
|
+
rippleColor?: string
|
|
49
52
|
}>(),
|
|
50
53
|
{
|
|
51
54
|
variant: 'filled',
|
|
@@ -165,18 +168,6 @@ const variantClasses = computed(() => {
|
|
|
165
168
|
return ''
|
|
166
169
|
}
|
|
167
170
|
})
|
|
168
|
-
|
|
169
|
-
function createRipple(event: PointerEvent) {
|
|
170
|
-
if (props.disabled || props.loading) return
|
|
171
|
-
const button = event.currentTarget as HTMLElement
|
|
172
|
-
const rect = button.getBoundingClientRect()
|
|
173
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
174
|
-
const el = document.createElement('span')
|
|
175
|
-
el.className = 'm3-ripple'
|
|
176
|
-
el.style.cssText = `width:${d}px;height:${d}px;top:${event.clientY - rect.top - d / 2}px;left:${event.clientX - rect.left - d / 2}px`
|
|
177
|
-
button.appendChild(el)
|
|
178
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
179
|
-
}
|
|
180
171
|
</script>
|
|
181
172
|
|
|
182
173
|
<template>
|
|
@@ -187,7 +178,7 @@ function createRipple(event: PointerEvent) {
|
|
|
187
178
|
:disabled="disabled || loading"
|
|
188
179
|
:class="[base, shapeClass, sizeClasses, px, variantClasses, disabledContainerClasses]"
|
|
189
180
|
:style="customStyle"
|
|
190
|
-
|
|
181
|
+
v-ripple="{ disabled: disabled || loading, color: rippleColor }"
|
|
191
182
|
>
|
|
192
183
|
<template v-if="iconPos === 'leading'">
|
|
193
184
|
<MSpinner v-if="loading" :size="spinnerSize" />
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { computed, ref } from 'vue'
|
|
9
9
|
import MIcon from './MIcon.vue'
|
|
10
10
|
import { FAST_SPATIAL, useSpring } from '../composables/_useSpring'
|
|
11
|
+
import { vRipple } from '../directives/vRipple'
|
|
11
12
|
|
|
12
13
|
export interface ButtonGroupOption {
|
|
13
14
|
value: unknown
|
|
@@ -31,6 +32,8 @@ const props = withDefaults(defineProps<{
|
|
|
31
32
|
selectionRequired?: boolean
|
|
32
33
|
/** Selected button color */
|
|
33
34
|
color?: 'primary' | 'secondary' | 'tertiary'
|
|
35
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
36
|
+
rippleColor?: string
|
|
34
37
|
}>(), {
|
|
35
38
|
variant: 'standard',
|
|
36
39
|
size: 'sm',
|
|
@@ -99,22 +102,11 @@ const selectedColors = computed(() => {
|
|
|
99
102
|
|
|
100
103
|
const unselectedColors = 'bg-surface-container-highest text-on-surface'
|
|
101
104
|
|
|
102
|
-
function createRipple(event: PointerEvent) {
|
|
103
|
-
const button = event.currentTarget as HTMLElement
|
|
104
|
-
const rect = button.getBoundingClientRect()
|
|
105
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
106
|
-
const el = document.createElement('span')
|
|
107
|
-
el.className = 'm3-ripple'
|
|
108
|
-
el.style.cssText = `width:${d}px;height:${d}px;top:${event.clientY - rect.top - d / 2}px;left:${event.clientX - rect.left - d / 2}px`
|
|
109
|
-
button.appendChild(el)
|
|
110
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
111
|
-
}
|
|
112
105
|
|
|
113
106
|
const buttons: (HTMLElement | null)[] = []
|
|
114
107
|
const pressedIndex = ref(-1)
|
|
115
108
|
|
|
116
109
|
function onPointerDown(e: PointerEvent, i: number) {
|
|
117
|
-
createRipple(e)
|
|
118
110
|
if (e.button !== 0 || props.options[i]?.disabled) return
|
|
119
111
|
measureWidths()
|
|
120
112
|
pressedIndex.value = i
|
|
@@ -233,6 +225,7 @@ useSpring(
|
|
|
233
225
|
]"
|
|
234
226
|
:disabled="opt.disabled"
|
|
235
227
|
:aria-pressed="isSelected(opt.value)"
|
|
228
|
+
v-ripple="{ disabled: opt.disabled, color: rippleColor }"
|
|
236
229
|
@pointerdown="onPointerDown($event, i)"
|
|
237
230
|
@pointerup="onPointerUp"
|
|
238
231
|
@pointerleave="onPointerUp"
|
package/src/components/MFab.vue
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { computed, onMounted, onUnmounted, ref, useSlots } from 'vue'
|
|
11
11
|
import MIcon from './MIcon.vue'
|
|
12
|
+
import { vRipple } from '../directives/vRipple'
|
|
12
13
|
|
|
13
14
|
export interface SpeedDialItem {
|
|
14
15
|
icon: string
|
|
@@ -58,6 +59,8 @@ const props = withDefaults(
|
|
|
58
59
|
* the content's own leave animation has time to play instead of just
|
|
59
60
|
* vanishing. 'none' skips any panel-level transition entirely. */
|
|
60
61
|
contentTransition?: 'scale' | 'fade' | 'none'
|
|
62
|
+
/** Any CSS color for the press ripple; defaults to the FAB's content color */
|
|
63
|
+
rippleColor?: string
|
|
61
64
|
}>(),
|
|
62
65
|
{
|
|
63
66
|
color: 'primary',
|
|
@@ -97,7 +100,7 @@ const fabSizeClasses = computed(() => {
|
|
|
97
100
|
if (props.label) return 'h-14 min-w-20 rounded-2xl pl-4 pr-5 gap-3'
|
|
98
101
|
switch (props.size) {
|
|
99
102
|
case 'small': return 'h-10 w-10 rounded-md'
|
|
100
|
-
case 'medium': return 'h-20 w-20 rounded-
|
|
103
|
+
case 'medium': return 'h-20 w-20 rounded-lg-increased'
|
|
101
104
|
case 'large': return 'h-24 w-24 rounded-[28px]'
|
|
102
105
|
default: return 'h-14 w-14 rounded-2xl'
|
|
103
106
|
}
|
|
@@ -197,16 +200,6 @@ function onScroll() {
|
|
|
197
200
|
open.value = false
|
|
198
201
|
}
|
|
199
202
|
|
|
200
|
-
function createRipple(event: PointerEvent | MouseEvent, target?: HTMLElement) {
|
|
201
|
-
const button = (target ?? event.currentTarget) as HTMLElement
|
|
202
|
-
const rect = button.getBoundingClientRect()
|
|
203
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
204
|
-
const el = document.createElement('span')
|
|
205
|
-
el.className = 'm3-ripple'
|
|
206
|
-
el.style.cssText = `width:${d}px;height:${d}px;top:${event.clientY - rect.top - d / 2}px;left:${event.clientX - rect.left - d / 2}px`
|
|
207
|
-
button.appendChild(el)
|
|
208
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
209
|
-
}
|
|
210
203
|
|
|
211
204
|
const contentStyle = ref<Record<string, string>>({})
|
|
212
205
|
|
|
@@ -260,8 +253,7 @@ function handleFabClick(e: PointerEvent) {
|
|
|
260
253
|
}
|
|
261
254
|
}
|
|
262
255
|
|
|
263
|
-
function handleItemClick(
|
|
264
|
-
createRipple(e, buttonEl)
|
|
256
|
+
function handleItemClick(item: SpeedDialItem) {
|
|
265
257
|
if (!props.persistent) open.value = false
|
|
266
258
|
item.onClick?.()
|
|
267
259
|
}
|
|
@@ -302,7 +294,7 @@ onUnmounted(() => {
|
|
|
302
294
|
class="relative inline-flex cursor-pointer items-center justify-center overflow-hidden shadow-elevation-3 transition-shadow duration-150 hover:shadow-elevation-4 active:shadow-elevation-3 disabled:cursor-not-allowed disabled:opacity-[0.38] before:content-[''] before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 hover:before:opacity-[0.08] active:before:opacity-[0.12]"
|
|
303
295
|
:class="[colorMap[color], fabSizeClasses]"
|
|
304
296
|
:disabled="disabled"
|
|
305
|
-
|
|
297
|
+
v-ripple="{ disabled, color: rippleColor }"
|
|
306
298
|
@click="handleFabClick"
|
|
307
299
|
>
|
|
308
300
|
<MIcon
|
|
@@ -338,7 +330,8 @@ onUnmounted(() => {
|
|
|
338
330
|
class="relative flex cursor-pointer items-center justify-center overflow-hidden rounded-lg shadow-elevation-3 transition-shadow duration-150 hover:shadow-elevation-4 active:shadow-elevation-3 before:content-[''] before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 hover:before:opacity-[0.08] active:before:opacity-[0.12]"
|
|
339
331
|
:class="colorMap[color]"
|
|
340
332
|
:style="{ width: `${ITEM_PX}px`, height: `${ITEM_PX}px` }"
|
|
341
|
-
|
|
333
|
+
v-ripple="rippleColor"
|
|
334
|
+
@pointerdown="handleItemClick(item)"
|
|
342
335
|
>
|
|
343
336
|
<MIcon :name="item.icon" :size="20" />
|
|
344
337
|
</component>
|
package/src/components/MIcon.vue
CHANGED
|
@@ -8,11 +8,13 @@ withDefaults(defineProps<{
|
|
|
8
8
|
name: string
|
|
9
9
|
/** Icon size in px */
|
|
10
10
|
size?: number
|
|
11
|
-
|
|
11
|
+
/** Filled glyph (the Material Symbols FILL axis), as M3 draws a selected icon */
|
|
12
|
+
filled?: boolean
|
|
13
|
+
}>(), { size: 24, filled: false })
|
|
12
14
|
</script>
|
|
13
15
|
|
|
14
16
|
<template>
|
|
15
|
-
<span class="material-symbols-outlined leading-none" :style="{ fontSize: `${size}px` }">{{
|
|
17
|
+
<span class="material-symbols-outlined leading-none" :style="{ fontSize: `${size}px`, fontVariationSettings: filled ? `'FILL' 1` : undefined }">{{
|
|
16
18
|
name
|
|
17
19
|
}}</span>
|
|
18
20
|
</template>
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
|
-
* A button that shows only an icon — four visual styles, the same 5-tier expressive sizing as MButton.
|
|
3
|
+
* A button that shows only an icon — four visual styles, the same 5-tier expressive sizing as MButton. Give it
|
|
4
|
+
* `checked` (v-model:checked) and it becomes M3's icon toggle button.
|
|
5
|
+
*
|
|
6
|
+
* @event update:checked Emitted on click when `checked` is set — powers v-model:checked
|
|
4
7
|
*/
|
|
5
|
-
import { computed } from 'vue'
|
|
8
|
+
import { computed, ref } from 'vue'
|
|
6
9
|
import MIcon from './MIcon.vue'
|
|
10
|
+
import { vRipple } from '../directives/vRipple'
|
|
11
|
+
import { DEFAULT_EFFECTS, useSpring } from '../composables/_useSpring'
|
|
7
12
|
|
|
8
13
|
const props = withDefaults(
|
|
9
14
|
defineProps<{
|
|
@@ -24,16 +29,29 @@ const props = withDefaults(
|
|
|
24
29
|
disabled?: boolean
|
|
25
30
|
/** Vue Router destination — renders as RouterLink instead of button */
|
|
26
31
|
to?: string | Record<string, any>
|
|
32
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
33
|
+
rippleColor?: string
|
|
34
|
+
/**
|
|
35
|
+
* Makes it a toggle button (v-model:checked): selected colors, a filled icon, and a shape that morphs when
|
|
36
|
+
* pressed and when checked. Leave it unset for a plain icon button
|
|
37
|
+
*/
|
|
38
|
+
checked?: boolean
|
|
39
|
+
/** Icon shown while checked, when it differs from `icon` (e.g. 'pause' for 'play_arrow') */
|
|
40
|
+
checkedIcon?: string
|
|
27
41
|
}>(),
|
|
28
42
|
{
|
|
29
43
|
variant: 'standard',
|
|
30
44
|
shape: 'rounded',
|
|
31
45
|
size: 'sm',
|
|
32
46
|
disabled: false,
|
|
47
|
+
checked: undefined,
|
|
33
48
|
},
|
|
34
49
|
)
|
|
35
50
|
|
|
36
|
-
const
|
|
51
|
+
const emit = defineEmits<{ 'update:checked': [boolean] }>()
|
|
52
|
+
|
|
53
|
+
const isToggle = computed(() => props.checked !== undefined)
|
|
54
|
+
const tag = computed(() => props.to && !isToggle.value ? 'RouterLink' : 'button')
|
|
37
55
|
|
|
38
56
|
// Container height/width (icon buttons are always square by default — real
|
|
39
57
|
// `IconButtonDefaults.<tier>ContainerSize()` also has Narrow/Wide width options not
|
|
@@ -41,19 +59,58 @@ const tag = computed(() => props.to ? 'RouterLink' : 'button')
|
|
|
41
59
|
// per M3's 5-tier `{XSmall,Small,Medium,Large,XLarge}IconButtonTokens.kt`. `squareRadius`
|
|
42
60
|
// matches each tier's own `ContainerShapeSquare` (12px xs/sm, 16px md, 28px lg/xl) — same
|
|
43
61
|
// pattern as MButton's size tiers.
|
|
62
|
+
// Toggle radii (px) from the same token files: `square` is ContainerShapeSquare, `pressed`
|
|
63
|
+
// PressedContainerShape, `checkedRound` SelectedContainerShapeRound (a round button squares off when
|
|
64
|
+
// checked); SelectedContainerShapeSquare is CornerFull (a square one turns round), i.e. px / 2.
|
|
44
65
|
const sizeMap = {
|
|
45
|
-
xs: { px: 32, icon: 20, squareRadius: 'rounded-md' },
|
|
46
|
-
sm: { px: 40, icon: 24, squareRadius: 'rounded-md' },
|
|
47
|
-
md: { px: 56, icon: 24, squareRadius: 'rounded-lg' },
|
|
48
|
-
lg: { px: 96, icon: 32, squareRadius: 'rounded-xl' },
|
|
49
|
-
xl: { px: 136, icon: 40, squareRadius: 'rounded-xl' },
|
|
66
|
+
xs: { px: 32, icon: 20, squareRadius: 'rounded-md', square: 12, pressed: 8, checkedRound: 12 },
|
|
67
|
+
sm: { px: 40, icon: 24, squareRadius: 'rounded-md', square: 12, pressed: 8, checkedRound: 12 },
|
|
68
|
+
md: { px: 56, icon: 24, squareRadius: 'rounded-lg', square: 16, pressed: 12, checkedRound: 16 },
|
|
69
|
+
lg: { px: 96, icon: 32, squareRadius: 'rounded-xl', square: 28, pressed: 16, checkedRound: 28 },
|
|
70
|
+
xl: { px: 136, icon: 40, squareRadius: 'rounded-xl', square: 28, pressed: 16, checkedRound: 28 },
|
|
50
71
|
}
|
|
51
72
|
|
|
52
73
|
const resolved = computed(() => {
|
|
53
|
-
if (typeof props.size === 'number')
|
|
74
|
+
if (typeof props.size === 'number') {
|
|
75
|
+
return { px: props.size, icon: Math.round(props.size * 0.55), squareRadius: 'rounded-md', square: 12, pressed: 8, checkedRound: 12 }
|
|
76
|
+
}
|
|
54
77
|
return sizeMap[props.size] ?? sizeMap.sm
|
|
55
78
|
})
|
|
56
79
|
|
|
80
|
+
// Icon toggle shape morph (IconButton.kt's shapeByInteraction: pressed, else checked, else the resting
|
|
81
|
+
// shape), on the DefaultEffects spring the source picks so it doesn't bounce. Plain icon buttons keep
|
|
82
|
+
// a static shape, like Compose's non-`shapes` overloads.
|
|
83
|
+
const rootEl = ref<unknown>(null)
|
|
84
|
+
const pressed = ref(false)
|
|
85
|
+
|
|
86
|
+
function targetRadius() {
|
|
87
|
+
const r = resolved.value
|
|
88
|
+
const full = r.px / 2
|
|
89
|
+
if (pressed.value) return r.pressed
|
|
90
|
+
if (props.checked) return props.shape === 'squared' ? full : r.checkedRound
|
|
91
|
+
return props.shape === 'squared' ? r.square : full
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
useSpring(
|
|
95
|
+
() => (isToggle.value ? [targetRadius()] : []),
|
|
96
|
+
(v) => {
|
|
97
|
+
// A RouterLink root (plain button with `to`) is a component instance, not an element
|
|
98
|
+
if (rootEl.value instanceof HTMLElement) rootEl.value.style.borderRadius = v.length ? `${v[0]}px` : ''
|
|
99
|
+
},
|
|
100
|
+
DEFAULT_EFFECTS,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
function onPointerDown() {
|
|
104
|
+
if (isToggle.value && !props.disabled) pressed.value = true
|
|
105
|
+
}
|
|
106
|
+
function onPointerUp() {
|
|
107
|
+
pressed.value = false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function onClick() {
|
|
111
|
+
if (isToggle.value && !props.disabled) emit('update:checked', !props.checked)
|
|
112
|
+
}
|
|
113
|
+
|
|
57
114
|
/*
|
|
58
115
|
* State layer via a `before:` overlay (same technique MButton uses) rather than a direct
|
|
59
116
|
* `hover:bg-*`/`active:bg-*` utility: a solid `bg-primary`/`bg-secondary-container`
|
|
@@ -76,6 +133,7 @@ const base =
|
|
|
76
133
|
// `disabled:text-on-surface/38` in `base` above, exactly like the real `outlinedIconButtonBorder`
|
|
77
134
|
// (which literally reuses `LocalContentColor` at the same disabled opacity as the icon).
|
|
78
135
|
const disabledContainerClasses = computed(() => {
|
|
136
|
+
if (props.variant === 'outlined' && props.checked) return 'disabled:bg-on-surface/10'
|
|
79
137
|
switch (props.variant) {
|
|
80
138
|
case 'filled':
|
|
81
139
|
case 'tonal':
|
|
@@ -87,19 +145,26 @@ const disabledContainerClasses = computed(() => {
|
|
|
87
145
|
|
|
88
146
|
const shapeClass = computed(() => props.shape === 'squared' ? resolved.value.squareRadius : 'rounded-full')
|
|
89
147
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
148
|
+
|
|
149
|
+
// Toggle colors: the Selected*/Unselected* tokens of each variant's *IconButtonTokens. Unchecked
|
|
150
|
+
// filled/tonal differ from the plain button's colors, so the checked state stands out.
|
|
151
|
+
const toggleClasses = computed(() => {
|
|
152
|
+
const on = props.checked
|
|
153
|
+
switch (props.variant) {
|
|
154
|
+
case 'filled':
|
|
155
|
+
return on ? 'bg-primary text-on-primary' : 'bg-surface-container text-on-surface-variant'
|
|
156
|
+
case 'tonal':
|
|
157
|
+
return on ? 'bg-secondary text-on-secondary' : 'bg-secondary-container text-on-secondary-container'
|
|
158
|
+
case 'outlined':
|
|
159
|
+
// outlinedIconToggleButtonBorder: no border once checked
|
|
160
|
+
return on ? 'bg-inverse-surface text-inverse-on-surface' : 'border border-current text-on-surface-variant'
|
|
161
|
+
default:
|
|
162
|
+
return on ? 'text-primary' : 'text-on-surface-variant'
|
|
163
|
+
}
|
|
164
|
+
})
|
|
101
165
|
|
|
102
166
|
const variantClasses = computed(() => {
|
|
167
|
+
if (isToggle.value) return toggleClasses.value
|
|
103
168
|
switch (props.variant) {
|
|
104
169
|
case 'filled':
|
|
105
170
|
// Real IconButton.kt has no elevation tokens at all for any variant — flat, unlike Button
|
|
@@ -119,14 +184,21 @@ const variantClasses = computed(() => {
|
|
|
119
184
|
<template>
|
|
120
185
|
<component
|
|
121
186
|
:is="tag"
|
|
122
|
-
|
|
123
|
-
:
|
|
187
|
+
ref="rootEl"
|
|
188
|
+
:to="tag === 'RouterLink' ? to : undefined"
|
|
189
|
+
:type="tag === 'RouterLink' ? undefined : 'button'"
|
|
124
190
|
:aria-label="label || undefined"
|
|
191
|
+
:aria-pressed="isToggle ? checked : undefined"
|
|
125
192
|
:disabled="disabled"
|
|
126
193
|
:class="[base, shapeClass, variantClasses, disabledContainerClasses]"
|
|
127
194
|
:style="{ width: `${resolved.px}px`, height: `${resolved.px}px` }"
|
|
128
|
-
|
|
195
|
+
v-ripple="{ disabled, color: rippleColor }"
|
|
196
|
+
@pointerdown="onPointerDown"
|
|
197
|
+
@pointerup="onPointerUp"
|
|
198
|
+
@pointerleave="onPointerUp"
|
|
199
|
+
@pointercancel="onPointerUp"
|
|
200
|
+
@click="onClick"
|
|
129
201
|
>
|
|
130
|
-
<MIcon :name="icon" :size="resolved.icon" />
|
|
202
|
+
<MIcon :name="checked && checkedIcon ? checkedIcon : icon" :size="resolved.icon" :filled="!!checked" />
|
|
131
203
|
</component>
|
|
132
204
|
</template>
|