@m3ui-vue/m3ui-vue 1.1.3 → 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/README.md +1 -1
- package/dist/API.md +579 -40
- package/dist/MMenuItem-DI351kIf.js +929 -0
- package/dist/MMenuItem-DI351kIf.js.map +1 -0
- package/dist/MSlider-BnEy5ieZ.js +1500 -0
- 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/MAnimatedNumber.vue.d.ts +3 -1
- package/dist/components/MButton.vue.d.ts +9 -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/MContainerTransform.vue.d.ts +59 -0
- package/dist/components/MContextMenu.vue.d.ts +2 -2
- package/dist/components/MCopyButton.vue.d.ts +1 -1
- package/dist/components/MDialog.vue.d.ts +8 -5
- 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/MFlex.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MListItem.vue.d.ts +5 -5
- 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/MNavigationRail.vue.d.ts +1 -1
- 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/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- 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/MToolbar.vue.d.ts +32 -5
- package/dist/components/MTooltip.vue.d.ts +1 -1
- 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/_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/useContainerTransform.d.ts +30 -0
- package/dist/composables/useLocale.d.ts +6 -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 +31 -1
- package/dist/locales/index.js +35 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7692 -6273
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +1 -1
- package/dist/map.js +823 -793
- 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 +20 -16
- 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-SfQHnJfp.js → useLocale-JYxDDeXC.js} +6 -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 +2 -1
- package/src/__tests__/MAnimatedNumber.test.ts +24 -2
- 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__/MContainerTransform.test.ts +279 -0
- package/src/__tests__/MDialog.test.ts +27 -0
- package/src/__tests__/MIconButton.test.ts +33 -0
- package/src/__tests__/MListItemExpandable.test.ts +48 -0
- package/src/__tests__/MListItemShape.test.ts +9 -6
- package/src/__tests__/MListKeyboard.test.ts +90 -0
- package/src/__tests__/MMap.test.ts +53 -1
- package/src/__tests__/MMapLayers.test.ts +46 -2
- package/src/__tests__/MMapTools.test.ts +2 -1
- 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__/MNavigationRail.test.ts +33 -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__/MSlider.test.ts +161 -0
- package/src/__tests__/MTimeline.test.ts +238 -0
- package/src/__tests__/MToolbar.test.ts +157 -0
- package/src/__tests__/_fakeMaplibre.ts +3 -1
- package/src/__tests__/attrsFallthrough.test.ts +9 -0
- package/src/__tests__/escapeStack.test.ts +93 -0
- package/src/__tests__/hydration.test.ts +25 -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/MAnimatedNumber.vue +32 -6
- package/src/components/MAutocomplete.vue +5 -0
- package/src/components/MBottomSheet.vue +4 -1
- package/src/components/MButton.vue +19 -3
- 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/MContainerTransform.vue +321 -0
- package/src/components/MContextMenu.vue +19 -60
- package/src/components/MDialog.vue +31 -6
- package/src/components/MDragDropList.vue +2 -0
- package/src/components/MFab.vue +10 -5
- package/src/components/MIconButton.vue +43 -2
- package/src/components/MKanban.vue +2 -0
- package/src/components/MLightbox.vue +7 -2
- package/src/components/MList.vue +26 -2
- package/src/components/MListItem.vue +138 -84
- 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 +44 -25
- 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/MSlider.vue +161 -42
- package/src/components/MSpotlightSearch.vue +3 -2
- package/src/components/MTextField.vue +15 -2
- package/src/components/MTimeline.vue +370 -81
- package/src/components/MToolbar.vue +256 -15
- package/src/components/MTooltip.vue +20 -152
- package/src/components/_MDrawerItemList.vue +25 -6
- package/src/components/_MToolbarFab.vue +14 -0
- package/src/composables/_containerTransform.ts +179 -0
- package/src/composables/_mapStyle.ts +45 -0
- package/src/composables/_themeTransition.ts +2 -0
- package/src/composables/_tooltipTrigger.ts +184 -0
- package/src/composables/_useEscapeStack.ts +2 -0
- package/src/composables/_useMenuNav.ts +209 -0
- package/src/composables/useAutoGrow.ts +78 -0
- package/src/composables/useContainerTransform.ts +59 -0
- package/src/composables/useLocale.ts +10 -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 +31 -1
- package/src/locales/de.ts +4 -0
- package/src/locales/es.ts +4 -0
- package/src/locales/fr.ts +4 -0
- package/src/locales/ja.ts +4 -0
- package/src/locales/ko.ts +4 -0
- package/src/locales/pt.ts +4 -0
- package/src/locales/zh.ts +4 -0
- package/src/map.ts +1 -1
- package/src/plugin.ts +34 -0
- package/src/styles/theme.css +63 -0
- package/dist/MMenuItem-BckcR0nW.js +0 -809
- package/dist/MMenuItem-BckcR0nW.js.map +0 -1
- package/dist/MSlider-LyH_gy8D.js +0 -1411
- package/dist/MSlider-LyH_gy8D.js.map +0 -1
- package/dist/MTextField-FCPOTB0o.js +0 -672
- package/dist/MTextField-FCPOTB0o.js.map +0 -1
- package/dist/composables/_useThemeTokens.d.ts +0 -7
- package/dist/useLocale-SfQHnJfp.js.map +0 -1
- package/src/composables/_useThemeTokens.ts +0 -42
|
@@ -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
|
|
@@ -49,6 +51,12 @@ const props = withDefaults(
|
|
|
49
51
|
to?: string | Record<string, any>
|
|
50
52
|
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
51
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
|
|
52
60
|
}>(),
|
|
53
61
|
{
|
|
54
62
|
variant: 'filled',
|
|
@@ -80,6 +88,14 @@ const customStyle = computed(() => {
|
|
|
80
88
|
|
|
81
89
|
const isError = computed(() => props.color === 'error')
|
|
82
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
|
+
|
|
83
99
|
const base =
|
|
84
100
|
'relative inline-flex items-center justify-center font-medium ' +
|
|
85
101
|
'whitespace-nowrap overflow-hidden transition-[box-shadow,background-color,color] duration-150 select-none cursor-pointer ' +
|
|
@@ -177,17 +193,17 @@ const variantClasses = computed(() => {
|
|
|
177
193
|
:type="to ? undefined : type"
|
|
178
194
|
:disabled="disabled || loading"
|
|
179
195
|
:class="[base, shapeClass, sizeClasses, px, variantClasses, disabledContainerClasses]"
|
|
180
|
-
:style="
|
|
196
|
+
:style="style"
|
|
181
197
|
v-ripple="{ disabled: disabled || loading, color: rippleColor }"
|
|
182
198
|
>
|
|
183
199
|
<template v-if="iconPos === 'leading'">
|
|
184
200
|
<MSpinner v-if="loading" :size="spinnerSize" />
|
|
185
|
-
<MIcon v-else-if="icon" :name="icon" :size="iconSize" />
|
|
201
|
+
<MIcon v-else-if="icon" :name="icon" :size="iconSize" :filled="iconFilled" />
|
|
186
202
|
</template>
|
|
187
203
|
<slot />
|
|
188
204
|
<template v-if="iconPos === 'trailing'">
|
|
189
205
|
<MSpinner v-if="loading" :size="spinnerSize" />
|
|
190
|
-
<MIcon v-else-if="icon" :name="icon" :size="iconSize" />
|
|
206
|
+
<MIcon v-else-if="icon" :name="icon" :size="iconSize" :filled="iconFilled" />
|
|
191
207
|
</template>
|
|
192
208
|
</component>
|
|
193
209
|
</template>
|
|
@@ -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
|
|