@m3ui-vue/m3ui-vue 1.1.4 → 1.2.0
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/dist/API.md +511 -34
- package/dist/MMenuItem-DI351kIf.js +929 -0
- package/dist/MMenuItem-DI351kIf.js.map +1 -0
- package/dist/{MSlider-JflHJ70q.js → MSlider-BnEy5ieZ.js} +295 -320
- package/dist/MSlider-BnEy5ieZ.js.map +1 -0
- package/dist/MTextField-BBmkaIbO.js +633 -0
- package/dist/MTextField-BBmkaIbO.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +83 -49
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MButton.vue.d.ts +7 -1
- package/dist/components/MButtonGroup.vue.d.ts +40 -31
- package/dist/components/MCarousel.vue.d.ts +2 -0
- package/dist/components/MChart.vue.d.ts +6 -0
- package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
- package/dist/components/MContextMenu.vue.d.ts +2 -2
- package/dist/components/MCopyButton.vue.d.ts +1 -1
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +13 -1
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MMap.vue.d.ts +20 -2
- package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
- package/dist/components/MMapFilter.vue.d.ts +3 -0
- package/dist/components/MMapLayers.vue.d.ts +3 -0
- package/dist/components/MMenu.vue.d.ts +2 -2
- package/dist/components/MMenuItem.vue.d.ts +7 -3
- package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
- package/dist/components/MOverlay.vue.d.ts +12 -1
- package/dist/components/MProgressBar.vue.d.ts +5 -3
- package/dist/components/MPullToRefresh.vue.d.ts +7 -2
- package/dist/components/MRichTextEditor.vue.d.ts +7 -1
- package/dist/components/MSearchField.vue.d.ts +58 -0
- package/dist/components/MSegmentedButton.vue.d.ts +31 -23
- package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
- package/dist/components/MSkeleton.vue.d.ts +6 -3
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTextField.vue.d.ts +5 -1
- package/dist/components/MTimeline.vue.d.ts +85 -22
- package/dist/components/MTooltip.vue.d.ts +1 -1
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/composables/_mapStyle.d.ts +13 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_tooltipTrigger.d.ts +22 -0
- package/dist/composables/_useMenuNav.d.ts +28 -0
- package/dist/composables/useAutoGrow.d.ts +21 -0
- package/dist/composables/useColorPalette.d.ts +1 -1
- package/dist/composables/useLocale.d.ts +3 -0
- package/dist/composables/useMap.d.ts +19 -3
- package/dist/composables/useMapFilter.d.ts +4 -1
- package/dist/composables/useMapLayers.d.ts +5 -2
- package/dist/composables/useScrollReveal.d.ts +44 -0
- package/dist/composables/useThemeTokens.d.ts +21 -0
- package/dist/composables/viewportHints.d.ts +27 -0
- package/dist/directives/vClickOutside.d.ts +25 -0
- package/dist/directives/vFocusRing.d.ts +22 -0
- package/dist/directives/vLongPress.d.ts +27 -0
- package/dist/directives/vReveal.d.ts +10 -0
- package/dist/directives/vScrollElevation.d.ts +31 -0
- package/dist/directives/vSkeleton.d.ts +19 -0
- package/dist/directives/vStateLayer.d.ts +20 -0
- package/dist/directives/vSwipe.d.ts +45 -0
- package/dist/directives/vTooltip.d.ts +23 -0
- package/dist/index.d.ts +28 -1
- package/dist/locales/index.js +21 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7131 -6216
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +1 -1
- package/dist/map.js +821 -791
- package/dist/map.js.map +1 -1
- package/dist/motion-DZiXG09o.js +150 -0
- package/dist/motion-DZiXG09o.js.map +1 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/rich-text-editor.js +13 -9
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles/theme.css +63 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CXibICQA.js → useLocale-JYxDDeXC.js} +4 -2
- package/dist/useLocale-JYxDDeXC.js.map +1 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MButton.test.ts +22 -0
- package/src/__tests__/MCarousel.test.ts +9 -0
- package/src/__tests__/MChart.test.ts +77 -5
- package/src/__tests__/MIconButton.test.ts +33 -0
- package/src/__tests__/MMap.test.ts +53 -1
- package/src/__tests__/MMapLayers.test.ts +46 -2
- package/src/__tests__/MMenu.test.ts +104 -1
- package/src/__tests__/MMenuItem.test.ts +18 -0
- package/src/__tests__/MNavigationDrawer.test.ts +80 -0
- package/src/__tests__/MOverlay.test.ts +49 -0
- package/src/__tests__/MProgressBar.test.ts +41 -0
- package/src/__tests__/MPullToRefresh.test.ts +33 -0
- package/src/__tests__/MRichTextEditor.test.ts +22 -0
- package/src/__tests__/MSearchField.test.ts +71 -0
- package/src/__tests__/MSkeleton.test.ts +38 -0
- package/src/__tests__/MTimeline.test.ts +238 -0
- package/src/__tests__/_fakeMaplibre.ts +3 -1
- package/src/__tests__/attrsFallthrough.test.ts +3 -0
- package/src/__tests__/escapeStack.test.ts +93 -0
- package/src/__tests__/ssr.test.ts +21 -2
- package/src/__tests__/useAutoGrow.test.ts +103 -0
- package/src/__tests__/useScrollReveal.test.ts +102 -0
- package/src/__tests__/useThemeTokens.test.ts +114 -0
- package/src/__tests__/vClickOutside.test.ts +82 -0
- package/src/__tests__/vFocusRing.test.ts +36 -0
- package/src/__tests__/vLongPress.test.ts +81 -0
- package/src/__tests__/vScrollElevation.test.ts +89 -0
- package/src/__tests__/vSkeleton.test.ts +48 -0
- package/src/__tests__/vStateLayer.test.ts +53 -0
- package/src/__tests__/vSwipe.test.ts +93 -0
- package/src/__tests__/vTooltip.test.ts +95 -0
- package/src/__tests__/viewportHints.test.ts +41 -0
- package/src/components/MAutocomplete.vue +5 -0
- package/src/components/MBottomSheet.vue +4 -1
- package/src/components/MButton.vue +15 -1
- package/src/components/MButtonGroup.vue +22 -17
- package/src/components/MCarousel.vue +7 -1
- package/src/components/MChart.vue +74 -34
- package/src/components/MCircleProgressBar.vue +14 -9
- package/src/components/MCommandPalette.vue +3 -2
- package/src/components/MContextMenu.vue +19 -60
- package/src/components/MDragDropList.vue +2 -0
- package/src/components/MIconButton.vue +40 -1
- package/src/components/MKanban.vue +2 -0
- package/src/components/MLightbox.vue +7 -2
- package/src/components/MMap.vue +38 -5
- package/src/components/MMapBaseLayers.vue +7 -3
- package/src/components/MMapFilter.vue +7 -4
- package/src/components/MMapGeoJson.vue +1 -1
- package/src/components/MMapLayers.vue +6 -2
- package/src/components/MMapMeasure.vue +5 -2
- package/src/components/MMenu.vue +18 -59
- package/src/components/MMenuItem.vue +11 -2
- package/src/components/MMultiAutocomplete.vue +5 -0
- package/src/components/MNavigationDrawer.vue +96 -11
- package/src/components/MNavigationRail.vue +4 -15
- package/src/components/MOverlay.vue +32 -13
- package/src/components/MProgressBar.vue +25 -27
- package/src/components/MPullToRefresh.vue +20 -1
- package/src/components/MRichTextEditor.vue +19 -5
- package/src/components/MSearchBar.vue +5 -0
- package/src/components/MSearchField.vue +142 -0
- package/src/components/MSegmentedButton.vue +19 -17
- package/src/components/MSelect.vue +10 -1
- package/src/components/MSideSheet.vue +5 -2
- package/src/components/MSimpleCarousel.vue +10 -1
- package/src/components/MSkeleton.vue +30 -8
- package/src/components/MSpotlightSearch.vue +3 -2
- package/src/components/MTextField.vue +15 -2
- package/src/components/MTimeline.vue +370 -81
- package/src/components/MTooltip.vue +20 -152
- package/src/components/_MDrawerItemList.vue +25 -6
- package/src/composables/_mapStyle.ts +45 -0
- package/src/composables/_themeTransition.ts +2 -0
- package/src/composables/_tooltipTrigger.ts +184 -0
- package/src/composables/_useMenuNav.ts +209 -0
- package/src/composables/useAutoGrow.ts +78 -0
- package/src/composables/useLocale.ts +5 -0
- package/src/composables/useMap.ts +43 -5
- package/src/composables/useMapFilter.ts +6 -5
- package/src/composables/useMapLayers.ts +7 -6
- package/src/composables/useScrollReveal.ts +151 -0
- package/src/composables/useThemeTokens.ts +116 -0
- package/src/composables/viewportHints.ts +80 -0
- package/src/directives/vClickOutside.ts +90 -0
- package/src/directives/vFocusRing.ts +60 -0
- package/src/directives/vLongPress.ts +134 -0
- package/src/directives/vReveal.ts +57 -0
- package/src/directives/vScrollElevation.ts +116 -0
- package/src/directives/vSkeleton.ts +87 -0
- package/src/directives/vStateLayer.ts +83 -0
- package/src/directives/vSwipe.ts +197 -0
- package/src/directives/vTooltip.ts +128 -0
- package/src/index.ts +28 -1
- package/src/locales/de.ts +2 -0
- package/src/locales/es.ts +2 -0
- package/src/locales/fr.ts +2 -0
- package/src/locales/ja.ts +2 -0
- package/src/locales/ko.ts +2 -0
- package/src/locales/pt.ts +2 -0
- package/src/locales/zh.ts +2 -0
- package/src/map.ts +1 -1
- package/src/plugin.ts +34 -0
- package/src/styles/theme.css +63 -0
- package/dist/MMenuItem-BfjqwcYP.js +0 -830
- package/dist/MMenuItem-BfjqwcYP.js.map +0 -1
- package/dist/MSlider-JflHJ70q.js.map +0 -1
- package/dist/MTextField-NaIB6RbM.js +0 -673
- package/dist/MTextField-NaIB6RbM.js.map +0 -1
- package/dist/composables/_useThemeTokens.d.ts +0 -7
- package/dist/useLocale-CXibICQA.js.map +0 -1
- package/src/composables/_useThemeTokens.ts +0 -42
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { defineComponent, h, nextTick, ref, withDirectives } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import { vTooltip, type TooltipValue } from '../directives/vTooltip'
|
|
5
|
+
|
|
6
|
+
// A closing tooltip fades out before it's removed: the open one is the one the element points to
|
|
7
|
+
const shown = (el: Element) => {
|
|
8
|
+
const id = el.getAttribute('aria-describedby')
|
|
9
|
+
return id ? document.getElementById(id) : null
|
|
10
|
+
}
|
|
11
|
+
const pointer = (type: string, pointerType: string, x = 10) =>
|
|
12
|
+
new PointerEvent(type, { pointerType, pointerId: 1, clientX: x, clientY: 10, bubbles: true })
|
|
13
|
+
|
|
14
|
+
describe('vTooltip', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
document.body.innerHTML = ''
|
|
17
|
+
vi.useFakeTimers()
|
|
18
|
+
})
|
|
19
|
+
afterEach(() => vi.useRealTimers())
|
|
20
|
+
|
|
21
|
+
function host(value: () => TooltipValue, onClick = vi.fn()) {
|
|
22
|
+
const w = mount(defineComponent({
|
|
23
|
+
setup: () => () => withDirectives(h('button', { class: 'btn', onClick }, 'Save'), [[vTooltip, value()]]),
|
|
24
|
+
}), { attachTo: document.body })
|
|
25
|
+
return { w, el: w.element as HTMLElement, onClick }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
it('shows the text on hover after the delay, described by it, and hides on leave', () => {
|
|
29
|
+
const { el } = host(() => 'Save changes')
|
|
30
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
31
|
+
vi.advanceTimersByTime(599)
|
|
32
|
+
expect(shown(el)).toBeNull()
|
|
33
|
+
vi.advanceTimersByTime(1)
|
|
34
|
+
const tip = shown(el)!
|
|
35
|
+
expect(tip.getAttribute('role')).toBe('tooltip')
|
|
36
|
+
expect(tip.textContent).toBe('Save changes')
|
|
37
|
+
el.dispatchEvent(pointer('pointerleave', 'mouse'))
|
|
38
|
+
expect(el.hasAttribute('aria-describedby')).toBe(false)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('takes options, and shows nothing when disabled or empty', () => {
|
|
42
|
+
const { el } = host(() => ({ text: 'Later', delay: 100, placement: 'bottom' }))
|
|
43
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
44
|
+
vi.advanceTimersByTime(100)
|
|
45
|
+
expect(shown(el)?.textContent).toBe('Later')
|
|
46
|
+
|
|
47
|
+
const off = host(() => ({ text: 'Nope', disabled: true }))
|
|
48
|
+
off.el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
49
|
+
vi.advanceTimersByTime(600)
|
|
50
|
+
expect(shown(off.el)).toBeNull()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('a long press shows it and swallows its click; a tap clicks', async () => {
|
|
54
|
+
const { el, onClick } = host(() => 'Save')
|
|
55
|
+
el.dispatchEvent(pointer('pointerdown', 'touch'))
|
|
56
|
+
window.dispatchEvent(pointer('pointerup', 'touch'))
|
|
57
|
+
el.click()
|
|
58
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
59
|
+
expect(shown(el)).toBeNull()
|
|
60
|
+
|
|
61
|
+
el.dispatchEvent(pointer('pointerdown', 'touch'))
|
|
62
|
+
vi.advanceTimersByTime(500)
|
|
63
|
+
expect(shown(el)?.textContent).toBe('Save')
|
|
64
|
+
window.dispatchEvent(pointer('pointerup', 'touch'))
|
|
65
|
+
el.click()
|
|
66
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
67
|
+
vi.advanceTimersByTime(1500)
|
|
68
|
+
expect(shown(el)).toBeNull()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('follows a new text while shown, hides when it empties, and cleans up on unmount', async () => {
|
|
72
|
+
const text = ref('One')
|
|
73
|
+
const { w, el } = host(() => text.value)
|
|
74
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
75
|
+
vi.advanceTimersByTime(600)
|
|
76
|
+
text.value = 'Two'
|
|
77
|
+
await nextTick()
|
|
78
|
+
expect(shown(el)?.textContent).toBe('Two')
|
|
79
|
+
text.value = ''
|
|
80
|
+
await nextTick()
|
|
81
|
+
expect(shown(el)).toBeNull()
|
|
82
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
83
|
+
vi.advanceTimersByTime(600)
|
|
84
|
+
w.unmount()
|
|
85
|
+
expect(document.querySelector('[role="tooltip"]')).toBeNull()
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('Escape hides it', () => {
|
|
89
|
+
const { el } = host(() => 'Save')
|
|
90
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
91
|
+
vi.advanceTimersByTime(600)
|
|
92
|
+
el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
|
|
93
|
+
expect(shown(el)).toBeNull()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, it, expect } from 'vitest'
|
|
3
|
+
import { viewportFromHeaders, VIEWPORT_HINTS } from '../composables/viewportHints'
|
|
4
|
+
|
|
5
|
+
const IPHONE = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1'
|
|
6
|
+
const ANDROID_PHONE = 'Mozilla/5.0 (Linux; Android 15; Pixel 9) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Mobile Safari/537.36'
|
|
7
|
+
const ANDROID_TABLET = 'Mozilla/5.0 (Linux; Android 15; SM-X910) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Safari/537.36'
|
|
8
|
+
const FIREFOX_DESKTOP = 'Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0'
|
|
9
|
+
|
|
10
|
+
describe('viewportFromHeaders', () => {
|
|
11
|
+
it('prefers the cookie, then the viewport hints', () => {
|
|
12
|
+
expect(viewportFromHeaders({ cookie: 'a=1; m3-viewport=1440x900', 'sec-ch-viewport-width': '390', 'user-agent': IPHONE }))
|
|
13
|
+
.toEqual({ width: 1440, height: 900 })
|
|
14
|
+
expect(viewportFromHeaders({ 'sec-ch-viewport-width': '390', 'sec-ch-viewport-height': '844', 'user-agent': FIREFOX_DESKTOP }))
|
|
15
|
+
.toEqual({ width: 390, height: 844 })
|
|
16
|
+
// Only the width (older Chromium): a height in proportion
|
|
17
|
+
expect(viewportFromHeaders({ 'Sec-CH-Viewport-Width': '1600' })).toEqual({ width: 1600, height: 1000 })
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('guesses the kind of device on a first visit', () => {
|
|
21
|
+
expect(viewportFromHeaders({ 'user-agent': IPHONE })!.width).toBeLessThan(600)
|
|
22
|
+
expect(viewportFromHeaders({ 'user-agent': ANDROID_PHONE })!.width).toBeLessThan(600)
|
|
23
|
+
const tablet = viewportFromHeaders({ 'user-agent': ANDROID_TABLET })!.width
|
|
24
|
+
expect(tablet).toBeGreaterThanOrEqual(600)
|
|
25
|
+
expect(tablet).toBeLessThan(840)
|
|
26
|
+
expect(viewportFromHeaders({ 'user-agent': FIREFOX_DESKTOP })!.width).toBeGreaterThanOrEqual(1200)
|
|
27
|
+
// Chromium's mobile hint, with a user agent that doesn't say
|
|
28
|
+
expect(viewportFromHeaders({ 'sec-ch-ua-mobile': '?1', 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K)' })!.width).toBeLessThan(600)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('takes a Headers object, ignores bad values, and can skip the guess', () => {
|
|
32
|
+
expect(viewportFromHeaders(new Headers({ cookie: 'm3-viewport=800x600' }))).toEqual({ width: 800, height: 600 })
|
|
33
|
+
expect(viewportFromHeaders({ cookie: 'm3-viewport=wide', 'user-agent': FIREFOX_DESKTOP })!.width).toBe(1280)
|
|
34
|
+
expect(viewportFromHeaders({ 'user-agent': IPHONE }, { guess: false })).toBeUndefined()
|
|
35
|
+
expect(viewportFromHeaders({})).toBeUndefined()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('names the hints for Accept-CH', () => {
|
|
39
|
+
expect(VIEWPORT_HINTS).toBe('Sec-CH-Viewport-Width, Sec-CH-Viewport-Height')
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -13,6 +13,7 @@ import { useLocale } from '../composables/useLocale'
|
|
|
13
13
|
import { useDebounce } from '../composables/useDebounce'
|
|
14
14
|
import type { SelectOption } from './MSelect.vue'
|
|
15
15
|
import { useScrollLock } from '../composables/_useScrollLock'
|
|
16
|
+
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
16
17
|
|
|
17
18
|
// Root is a fragment (field div + a sibling Teleport for the dropdown panel), so Vue can't
|
|
18
19
|
// auto-apply a consumer's class/attrs to either one — forward them onto the field div below.
|
|
@@ -174,6 +175,7 @@ function select(opt: SelectOption) {
|
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
useScrollLock(modalOpen)
|
|
178
|
+
useEscapeStack(modalOpen, closeDropdown)
|
|
177
179
|
|
|
178
180
|
function onInputFocus() {
|
|
179
181
|
search.value = ''
|
|
@@ -208,6 +210,9 @@ function onScroll(e: Event) {
|
|
|
208
210
|
|
|
209
211
|
function onKeydown(e: KeyboardEvent) {
|
|
210
212
|
if (e.key === 'Escape') {
|
|
213
|
+
// Closing the list uses the key: keep it from also closing a dialog around the field. With nothing open it
|
|
214
|
+
// only leaves the field and passes on
|
|
215
|
+
if (open.value || modalOpen.value) e.stopPropagation()
|
|
211
216
|
closeDropdown()
|
|
212
217
|
inputEl.value?.blur()
|
|
213
218
|
return
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @slot default Sheet body content (scrollable)
|
|
9
9
|
* @slot actions Footer action buttons, shown in a bordered strip below the content
|
|
10
|
-
* @event update:modelValue Emitted when the sheet closes (scrim click, drag-to-dismiss, or the close button) —
|
|
10
|
+
* @event update:modelValue Emitted when the sheet closes (scrim click, drag-to-dismiss, Escape, or the close button) —
|
|
11
11
|
* powers v-model
|
|
12
12
|
* @event update:expanded Emitted when the sheet moves between partially and fully expanded (or closes) —
|
|
13
13
|
* powers v-model:expanded
|
|
@@ -16,6 +16,7 @@ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
|
16
16
|
import MIcon from './MIcon.vue'
|
|
17
17
|
import { useLocale } from '../composables/useLocale'
|
|
18
18
|
import { useSheetMotion } from '../composables/_useSheetMotion'
|
|
19
|
+
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
19
20
|
|
|
20
21
|
const props = withDefaults(defineProps<{
|
|
21
22
|
/** Open/closed state (v-model) */
|
|
@@ -42,6 +43,8 @@ const props = withDefaults(defineProps<{
|
|
|
42
43
|
|
|
43
44
|
const emit = defineEmits<{ 'update:modelValue': [boolean]; 'update:expanded': [boolean] }>()
|
|
44
45
|
const close = () => emit('update:modelValue', false)
|
|
46
|
+
// Modal: Escape closes it, through the library's stack (a dialog or menu over it takes it first)
|
|
47
|
+
useEscapeStack(() => props.modelValue, close)
|
|
45
48
|
const locale = useLocale()
|
|
46
49
|
|
|
47
50
|
// Only the safe area is kept clear at the top, like the status bar inset in Compose
|
|
@@ -51,6 +51,12 @@ const props = withDefaults(
|
|
|
51
51
|
to?: string | Record<string, any>
|
|
52
52
|
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
53
53
|
rippleColor?: string
|
|
54
|
+
/**
|
|
55
|
+
* Label and icon color, over what the variant and `color` give: an M3 role (`on-surface` for a neutral text
|
|
56
|
+
* button, `on-primary-container`…) or any CSS color (`#000` on a white filled button). Disabled buttons keep
|
|
57
|
+
* their own
|
|
58
|
+
*/
|
|
59
|
+
contentColor?: string
|
|
54
60
|
}>(),
|
|
55
61
|
{
|
|
56
62
|
variant: 'filled',
|
|
@@ -82,6 +88,14 @@ const customStyle = computed(() => {
|
|
|
82
88
|
|
|
83
89
|
const isError = computed(() => props.color === 'error')
|
|
84
90
|
|
|
91
|
+
// Color-role names (`on-surface`, `secondary-container`…) read the theme's token; anything else is a CSS color
|
|
92
|
+
const ROLE = /^(on-)?(primary|secondary|tertiary|error|surface|surface-variant|inverse-surface|inverse-primary)(-container|-variant)?$/
|
|
93
|
+
const style = computed(() => {
|
|
94
|
+
const c = props.contentColor
|
|
95
|
+
if (!c || props.disabled || props.loading) return customStyle.value
|
|
96
|
+
return { ...customStyle.value, color: ROLE.test(c) ? `var(--color-${c})` : c }
|
|
97
|
+
})
|
|
98
|
+
|
|
85
99
|
const base =
|
|
86
100
|
'relative inline-flex items-center justify-center font-medium ' +
|
|
87
101
|
'whitespace-nowrap overflow-hidden transition-[box-shadow,background-color,color] duration-150 select-none cursor-pointer ' +
|
|
@@ -179,7 +193,7 @@ const variantClasses = computed(() => {
|
|
|
179
193
|
:type="to ? undefined : type"
|
|
180
194
|
:disabled="disabled || loading"
|
|
181
195
|
:class="[base, shapeClass, sizeClasses, px, variantClasses, disabledContainerClasses]"
|
|
182
|
-
:style="
|
|
196
|
+
:style="style"
|
|
183
197
|
v-ripple="{ disabled: disabled || loading, color: rippleColor }"
|
|
184
198
|
>
|
|
185
199
|
<template v-if="iconPos === 'leading'">
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
<script
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export interface ButtonGroupOption<T = unknown> {
|
|
3
|
+
value: T
|
|
4
|
+
label?: string
|
|
5
|
+
icon?: string
|
|
6
|
+
disabled?: boolean
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script setup lang="ts" generic="T, M extends T | T[] | null = T | null">
|
|
2
11
|
/**
|
|
3
12
|
* A set of buttons that share selection state — standard (separated) or connected (joined into one pill),
|
|
4
13
|
* single or multi select, any value type.
|
|
@@ -10,18 +19,14 @@ import MIcon from './MIcon.vue'
|
|
|
10
19
|
import { FAST_SPATIAL, useSpring } from '../composables/_useSpring'
|
|
11
20
|
import { vRipple } from '../directives/vRipple'
|
|
12
21
|
|
|
13
|
-
export interface ButtonGroupOption {
|
|
14
|
-
value: unknown
|
|
15
|
-
label?: string
|
|
16
|
-
icon?: string
|
|
17
|
-
disabled?: boolean
|
|
18
|
-
}
|
|
19
|
-
|
|
20
22
|
const props = withDefaults(defineProps<{
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Selected value (null when none), or values with `multiSelect` (v-model) — any type, typed after the options'
|
|
25
|
+
* values
|
|
26
|
+
*/
|
|
27
|
+
modelValue: M
|
|
23
28
|
/** The options to choose from; see `ButtonGroupOption`. */
|
|
24
|
-
options: ButtonGroupOption[]
|
|
29
|
+
options: ButtonGroupOption<T>[]
|
|
25
30
|
/** Standard (separated) or connected (joined) */
|
|
26
31
|
variant?: 'standard' | 'connected'
|
|
27
32
|
/** Button size */
|
|
@@ -42,7 +47,7 @@ const props = withDefaults(defineProps<{
|
|
|
42
47
|
color: 'primary',
|
|
43
48
|
})
|
|
44
49
|
|
|
45
|
-
const emit = defineEmits<{ 'update:modelValue': [
|
|
50
|
+
const emit = defineEmits<{ 'update:modelValue': [M] }>()
|
|
46
51
|
|
|
47
52
|
function eq(a: unknown, b: unknown): boolean {
|
|
48
53
|
if (a === b) return true
|
|
@@ -56,10 +61,10 @@ function isSelected(value: unknown) {
|
|
|
56
61
|
return eq(props.modelValue, value)
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
function toggle(opt: ButtonGroupOption) {
|
|
64
|
+
function toggle(opt: ButtonGroupOption<T>) {
|
|
60
65
|
if (opt.disabled) return
|
|
61
66
|
if (props.multiSelect) {
|
|
62
|
-
const arr = Array.isArray(props.modelValue) ? [...props.modelValue] : props.modelValue != null ? [props.modelValue] : []
|
|
67
|
+
const arr: T[] = Array.isArray(props.modelValue) ? [...props.modelValue] : props.modelValue != null ? [props.modelValue as T] : []
|
|
63
68
|
const idx = arr.findIndex(v => eq(v, opt.value))
|
|
64
69
|
if (idx >= 0) {
|
|
65
70
|
if (props.selectionRequired && arr.length <= 1) return
|
|
@@ -67,12 +72,12 @@ function toggle(opt: ButtonGroupOption) {
|
|
|
67
72
|
} else {
|
|
68
73
|
arr.push(opt.value)
|
|
69
74
|
}
|
|
70
|
-
emit('update:modelValue', arr)
|
|
75
|
+
emit('update:modelValue', arr as M)
|
|
71
76
|
} else {
|
|
72
77
|
if (isSelected(opt.value) && !props.selectionRequired) {
|
|
73
|
-
emit('update:modelValue', null)
|
|
78
|
+
emit('update:modelValue', null as M)
|
|
74
79
|
} else {
|
|
75
|
-
emit('update:modelValue', opt.value)
|
|
80
|
+
emit('update:modelValue', opt.value as M)
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
}
|
|
@@ -567,7 +567,13 @@ onBeforeUnmount(() => {
|
|
|
567
567
|
rootEl.value?.removeEventListener('wheel', onWheel)
|
|
568
568
|
})
|
|
569
569
|
|
|
570
|
-
defineExpose({
|
|
570
|
+
defineExpose({
|
|
571
|
+
scrollToItem,
|
|
572
|
+
next,
|
|
573
|
+
prev,
|
|
574
|
+
/** Moves keyboard focus to the carousel, so the arrow keys scroll it */
|
|
575
|
+
focus: (options?: FocusOptions) => rootEl.value?.focus(options),
|
|
576
|
+
})
|
|
571
577
|
</script>
|
|
572
578
|
|
|
573
579
|
<template>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
3
|
* A thin Chart.js wrapper — line, bar, pie, doughnut, and radar types, with legend/tooltip/axis colors that
|
|
4
|
-
* automatically track the active M3 theme (light/dark,
|
|
5
|
-
* point.
|
|
4
|
+
* automatically track the active M3 theme (light/dark, palette, contrast). Datasets without colors of their own get
|
|
5
|
+
* the theme's too, one per series (one per slice in a pie or doughnut). Available from the `/chart` entry point.
|
|
6
6
|
*/
|
|
7
|
-
import { computed, ref, watch, onMounted,
|
|
7
|
+
import { computed, ref, watch, onMounted, shallowRef, type Component } from 'vue'
|
|
8
|
+
import { useThemeTokens } from '../composables/useThemeTokens'
|
|
8
9
|
|
|
9
10
|
type ChartType = 'line' | 'bar' | 'pie' | 'doughnut' | 'radar'
|
|
10
11
|
|
|
@@ -21,42 +22,83 @@ const props = withDefaults(
|
|
|
21
22
|
options?: Record<string, any>
|
|
22
23
|
/** Chart height */
|
|
23
24
|
height?: string
|
|
25
|
+
/**
|
|
26
|
+
* Colors for datasets that don't set their own, in order (one per series; per slice in a pie or doughnut): M3
|
|
27
|
+
* role names (`primary`, `tertiary-container`…) or any CSS colors. Default primary, tertiary, secondary, success,
|
|
28
|
+
* error, outline
|
|
29
|
+
*/
|
|
30
|
+
colors?: string[]
|
|
24
31
|
}>(),
|
|
25
32
|
{ height: '300px' },
|
|
26
33
|
)
|
|
27
34
|
|
|
35
|
+
const SERIES = ['primary', 'tertiary', 'secondary', 'success', 'error', 'outline']
|
|
36
|
+
|
|
28
37
|
const ready = ref(false)
|
|
29
38
|
const chartComponent = shallowRef<Component | null>(null)
|
|
30
39
|
const componentMap = shallowRef<Record<string, Component>>({})
|
|
31
40
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
// Every role a color list may name, read as plain strings (a canvas can't resolve CSS variables) and kept current
|
|
42
|
+
// across theme, palette, contrast and generated-palette changes, settled after the switch's color transition
|
|
43
|
+
const ROLES = [
|
|
44
|
+
'primary', 'secondary', 'tertiary', 'error', 'success', 'outline', 'outline-variant', 'inverse-primary',
|
|
45
|
+
'primary-container', 'secondary-container', 'tertiary-container', 'error-container', 'success-container',
|
|
46
|
+
'on-surface', 'on-surface-variant', 'surface', 'surface-container',
|
|
47
|
+
] as const
|
|
48
|
+
const tokens = useThemeTokens(ROLES)
|
|
49
|
+
const isRole = (c: string): c is (typeof ROLES)[number] => (ROLES as readonly string[]).includes(c)
|
|
50
|
+
const resolve = (c: string) => (isRole(c) ? tokens.value[c] : c)
|
|
51
|
+
|
|
52
|
+
// Canvas can't resolve CSS vars either for fonts: pass Chart.js the resolved stack, read again once web fonts load
|
|
53
|
+
// (text drawn before keeps the fallback)
|
|
54
|
+
const readFont = () =>
|
|
55
|
+
(typeof document === 'undefined' ? '' : getComputedStyle(document.documentElement).getPropertyValue('--font-sans').trim())
|
|
56
|
+
|| "'Roboto', system-ui, sans-serif"
|
|
57
|
+
const fontFamily = ref(readFont())
|
|
58
|
+
|
|
59
|
+
const m3Colors = computed(() => ({
|
|
60
|
+
onSurface: tokens.value['on-surface'],
|
|
61
|
+
onSurfaceVariant: tokens.value['on-surface-variant'],
|
|
62
|
+
outlineVariant: tokens.value['outline-variant'],
|
|
63
|
+
surface: tokens.value.surface,
|
|
64
|
+
surfaceContainer: tokens.value['surface-container'],
|
|
65
|
+
fontFamily: fontFamily.value,
|
|
66
|
+
}))
|
|
67
|
+
|
|
68
|
+
/** A color at some opacity, for fills under a line or inside a radar. */
|
|
69
|
+
function withAlpha(color: string, a: number) {
|
|
70
|
+
const m = color.match(/^#([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i)
|
|
71
|
+
if (m) return `rgba(${parseInt(m[1]!, 16)}, ${parseInt(m[2]!, 16)}, ${parseInt(m[3]!, 16)}, ${a})`
|
|
72
|
+
return `color-mix(in srgb, ${color} ${Math.round(a * 100)}%, transparent)`
|
|
46
73
|
}
|
|
47
74
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
75
|
+
// Datasets without colors get the theme's: only the keys they leave unset, so a consumer's own colors always win
|
|
76
|
+
const themedData = computed(() => {
|
|
77
|
+
const data = props.data
|
|
78
|
+
if (!Array.isArray(data?.datasets)) return data
|
|
79
|
+
const palette = (props.colors?.length ? props.colors : SERIES).map(resolve)
|
|
80
|
+
const at = (i: number) => palette[i % palette.length]!
|
|
81
|
+
const slices = props.type === 'pie' || props.type === 'doughnut'
|
|
82
|
+
const datasets = data.datasets.map((ds: Record<string, any>, i: number) => {
|
|
83
|
+
const fill: Record<string, any> = {}
|
|
84
|
+
if (slices) {
|
|
85
|
+
if (ds.backgroundColor === undefined) fill.backgroundColor = (ds.data ?? []).map((_: unknown, j: number) => at(j))
|
|
86
|
+
// Slices separated by the card's own color
|
|
87
|
+
if (ds.borderColor === undefined) fill.borderColor = m3Colors.value.surface
|
|
88
|
+
} else {
|
|
89
|
+
const c = at(i)
|
|
90
|
+
if (ds.borderColor === undefined) fill.borderColor = c
|
|
91
|
+
if (ds.backgroundColor === undefined) fill.backgroundColor = props.type === 'bar' ? c : withAlpha(c, props.type === 'radar' ? 0.2 : 0.15)
|
|
92
|
+
if (props.type !== 'bar' && ds.pointBackgroundColor === undefined) fill.pointBackgroundColor = c
|
|
93
|
+
}
|
|
94
|
+
return { ...fill, ...ds }
|
|
95
|
+
})
|
|
96
|
+
return { ...data, datasets }
|
|
97
|
+
})
|
|
51
98
|
|
|
52
99
|
onMounted(async () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
themeObserver = new MutationObserver(() => { m3Colors.value = getM3Colors() })
|
|
56
|
-
// `class` flips light/dark, `data-palette` switches the palette (useColorPalette / createM3UI).
|
|
57
|
-
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style', 'data-palette'] })
|
|
58
|
-
// Canvas text drawn before a web font finishes loading keeps the fallback, so redraw once it has
|
|
59
|
-
document.fonts?.ready.then(() => { m3Colors.value = getM3Colors() })
|
|
100
|
+
fontFamily.value = readFont()
|
|
101
|
+
document.fonts?.ready.then(() => { fontFamily.value = readFont() })
|
|
60
102
|
|
|
61
103
|
const [chartjs, vueChartjs] = await Promise.all([
|
|
62
104
|
import('chart.js'),
|
|
@@ -88,8 +130,6 @@ onMounted(async () => {
|
|
|
88
130
|
ready.value = true
|
|
89
131
|
})
|
|
90
132
|
|
|
91
|
-
onBeforeUnmount(() => { themeObserver?.disconnect() })
|
|
92
|
-
|
|
93
133
|
watch(() => props.type, () => {
|
|
94
134
|
if (ready.value) chartComponent.value = componentMap.value[props.type] ?? null
|
|
95
135
|
}, { immediate: true })
|
|
@@ -132,12 +172,12 @@ const mergedOptions = computed<Record<string, any>>(() => {
|
|
|
132
172
|
if (props.type !== 'pie' && props.type !== 'doughnut') {
|
|
133
173
|
base.scales = {
|
|
134
174
|
x: {
|
|
135
|
-
grid: { color: c.outlineVariant
|
|
175
|
+
grid: { color: withAlpha(c.outlineVariant, 0.25), drawTicks: false },
|
|
136
176
|
ticks: { color: c.onSurfaceVariant, font: { family: c.fontFamily, size: 11 }, padding: 8 },
|
|
137
177
|
border: { color: c.outlineVariant },
|
|
138
178
|
},
|
|
139
179
|
y: {
|
|
140
|
-
grid: { color: c.outlineVariant
|
|
180
|
+
grid: { color: withAlpha(c.outlineVariant, 0.25), drawTicks: false },
|
|
141
181
|
ticks: { color: c.onSurfaceVariant, font: { family: c.fontFamily, size: 11 }, padding: 8 },
|
|
142
182
|
border: { color: c.outlineVariant },
|
|
143
183
|
},
|
|
@@ -147,8 +187,8 @@ const mergedOptions = computed<Record<string, any>>(() => {
|
|
|
147
187
|
if (props.type === 'radar') {
|
|
148
188
|
base.scales = {
|
|
149
189
|
r: {
|
|
150
|
-
grid: { color: c.outlineVariant
|
|
151
|
-
angleLines: { color: c.outlineVariant
|
|
190
|
+
grid: { color: withAlpha(c.outlineVariant, 0.25) },
|
|
191
|
+
angleLines: { color: withAlpha(c.outlineVariant, 0.25) },
|
|
152
192
|
pointLabels: { color: c.onSurfaceVariant, font: { family: c.fontFamily, size: 11 } },
|
|
153
193
|
ticks: { color: c.onSurfaceVariant, backdropColor: 'transparent', font: { family: c.fontFamily } },
|
|
154
194
|
},
|
|
@@ -176,7 +216,7 @@ function deepMerge(target: any, source: any): any {
|
|
|
176
216
|
<component
|
|
177
217
|
v-if="ready && chartComponent"
|
|
178
218
|
:is="chartComponent"
|
|
179
|
-
:data="
|
|
219
|
+
:data="themedData"
|
|
180
220
|
:options="mergedOptions"
|
|
181
221
|
/>
|
|
182
222
|
</div>
|
|
@@ -13,8 +13,10 @@ const props = withDefaults(
|
|
|
13
13
|
value?: number;
|
|
14
14
|
/** Spinning arc — no value needed. Identical for both variants. */
|
|
15
15
|
indeterminate?: boolean;
|
|
16
|
-
/** Ring color */
|
|
17
|
-
color?: "primary" | "secondary" | "tertiary" | "error";
|
|
16
|
+
/** Ring color: an M3 role or any CSS color */
|
|
17
|
+
color?: "primary" | "secondary" | "tertiary" | "error" | (string & {});
|
|
18
|
+
/** Track color: an M3 role or any CSS color. Default the role's container, or the ring color at 24% for a CSS color */
|
|
19
|
+
trackColor?: string;
|
|
18
20
|
/** wavy: animated bumpy ring that fades to circle near 0% and 100%; circle: smooth arc */
|
|
19
21
|
variant?: "circle" | "wavy";
|
|
20
22
|
/** Label text below the circle */
|
|
@@ -37,13 +39,16 @@ const clampedValue = computed(() => Math.min(100, Math.max(0, props.value ?? 0))
|
|
|
37
39
|
// variant's default is intentionally larger to fit the wave amplitude without clipping.
|
|
38
40
|
const effectiveSize = computed(() => props.size ?? (props.variant === "wavy" ? 48 : 40));
|
|
39
41
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const ROLES = ["primary", "secondary", "tertiary", "error"];
|
|
43
|
+
const roleOr = (c: string) => (ROLES.includes(c) || c.endsWith("-container") ? `var(--color-${c})` : c);
|
|
44
|
+
const svgColor = computed(() => ({
|
|
45
|
+
fill: roleOr(props.color),
|
|
46
|
+
track: props.trackColor
|
|
47
|
+
? roleOr(props.trackColor)
|
|
48
|
+
: ROLES.includes(props.color)
|
|
49
|
+
? `var(--color-${props.color}-container)`
|
|
50
|
+
: `color-mix(in srgb, ${props.color} 24%, transparent)`,
|
|
51
|
+
}));
|
|
47
52
|
|
|
48
53
|
// ── Geometry ─────────────────────────────────────────────────────────────
|
|
49
54
|
const R = 40;
|
|
@@ -11,6 +11,7 @@ import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue'
|
|
|
11
11
|
import MIcon from './MIcon.vue'
|
|
12
12
|
import { useLocale } from '../composables/useLocale'
|
|
13
13
|
import { useScrollLock } from '../composables/_useScrollLock'
|
|
14
|
+
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
14
15
|
|
|
15
16
|
const locale = useLocale()
|
|
16
17
|
|
|
@@ -103,8 +104,6 @@ function onKeydown(e: KeyboardEvent) {
|
|
|
103
104
|
} else if (e.key === 'Enter' && filtered.value.length) {
|
|
104
105
|
e.preventDefault()
|
|
105
106
|
selectItem(filtered.value[activeIndex.value]!)
|
|
106
|
-
} else if (e.key === 'Escape') {
|
|
107
|
-
close()
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
|
|
@@ -135,6 +134,8 @@ watch(
|
|
|
135
134
|
)
|
|
136
135
|
|
|
137
136
|
useScrollLock(() => props.modelValue)
|
|
137
|
+
// Escape through the library's stack: opened over a dialog, it closes alone
|
|
138
|
+
useEscapeStack(() => props.modelValue, close)
|
|
138
139
|
|
|
139
140
|
watch(query, () => { activeIndex.value = 0 })
|
|
140
141
|
|