@m3ui-vue/m3ui-vue 1.1.2 → 1.1.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/dist/API.md +135 -5
- package/dist/{MIcon-DLOkQduI.js → MIcon-Bxh9j135.js} +15 -8
- package/dist/MIcon-Bxh9j135.js.map +1 -0
- package/dist/{MMenuItem-DVxKEv1W.js → MMenuItem-BckcR0nW.js} +4 -4
- package/dist/{MMenuItem-DVxKEv1W.js.map → MMenuItem-BckcR0nW.js.map} +1 -1
- package/dist/{MSlider-BXsBv0ox.js → MSlider-LyH_gy8D.js} +56 -47
- package/dist/MSlider-LyH_gy8D.js.map +1 -0
- package/dist/{MTextField-rML9jnXs.js → MTextField-FCPOTB0o.js} +65 -64
- package/dist/{MTextField-rML9jnXs.js.map → MTextField-FCPOTB0o.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MAnimatedNumber.vue.d.ts +27 -0
- package/dist/components/MIcon.vue.d.ts +2 -0
- package/dist/components/MListGroup.vue.d.ts +23 -0
- package/dist/components/MScheduler.vue.d.ts +2 -2
- package/dist/components/MScheme.vue.d.ts +60 -0
- package/dist/components/MSparkline.vue.d.ts +41 -0
- package/dist/components/MWindow.vue.d.ts +2 -2
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/composables/_useSegmentRuns.d.ts +8 -0
- package/dist/composables/dynamicColor.d.ts +11 -0
- package/dist/composables/useColorPalette.d.ts +3 -1
- package/dist/composables/useConfetti.d.ts +32 -0
- package/dist/composables/useLocale.d.ts +6 -0
- package/dist/index.d.ts +7 -1
- package/dist/locales/index.js +21 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +16187 -15377
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +45 -45
- package/dist/{material-color-utilities-Cktu8DBU.js → material-color-utilities-C_iikgRm.js} +928 -603
- package/dist/material-color-utilities-C_iikgRm.js.map +1 -0
- package/dist/rich-text-editor.js +4 -4
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-CqQrhWFl.js → useLocale-SfQHnJfp.js} +4 -1
- package/dist/useLocale-SfQHnJfp.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MAnimatedNumber.test.ts +106 -0
- package/src/__tests__/MIcon.test.ts +19 -0
- package/src/__tests__/MListItemShape.test.ts +34 -0
- package/src/__tests__/MScheme.test.ts +107 -0
- package/src/__tests__/MSparkline.test.ts +96 -0
- package/src/__tests__/iconButtonNames.test.ts +124 -0
- package/src/__tests__/ssr.test.ts +1 -0
- package/src/__tests__/useConfetti.test.ts +81 -0
- package/src/components/MAnimatedNumber.vue +301 -0
- package/src/components/MAutocomplete.vue +34 -4
- package/src/components/MBottomSheet.vue +1 -0
- package/src/components/MDataTable.vue +1 -1
- package/src/components/MIcon.vue +11 -4
- package/src/components/MList.vue +8 -30
- package/src/components/MListGroup.vue +66 -0
- package/src/components/MMaskField.vue +3 -0
- package/src/components/MMultiAutocomplete.vue +5 -1
- package/src/components/MMultiSelect.vue +19 -9
- package/src/components/MScheme.vue +162 -0
- package/src/components/MSearchBar.vue +2 -0
- package/src/components/MSelect.vue +44 -10
- package/src/components/MSideSheet.vue +3 -0
- package/src/components/MSimpleCarousel.vue +6 -0
- package/src/components/MSparkline.vue +250 -0
- package/src/components/MSplitButton.vue +3 -0
- package/src/components/MSpotlightSearch.vue +1 -0
- package/src/components/MTable.vue +1 -0
- package/src/components/MTagInput.vue +4 -0
- package/src/components/MTextField.vue +3 -0
- package/src/components/MTour.vue +1 -0
- package/src/components/MTreeTable.vue +1 -0
- package/src/components/_MTreeNode.vue +3 -0
- package/src/composables/_useSegmentRuns.ts +39 -0
- package/src/composables/dynamicColor.ts +66 -0
- package/src/composables/useColorPalette.ts +2 -2
- package/src/composables/useConfetti.ts +204 -0
- package/src/composables/useLocale.ts +9 -0
- package/src/index.ts +7 -1
- package/src/locales/de.ts +3 -0
- package/src/locales/es.ts +3 -0
- package/src/locales/fr.ts +3 -0
- package/src/locales/ja.ts +3 -0
- package/src/locales/ko.ts +3 -0
- package/src/locales/pt.ts +3 -0
- package/src/locales/zh.ts +3 -0
- package/dist/MIcon-DLOkQduI.js.map +0 -1
- package/dist/MSlider-BXsBv0ox.js.map +0 -1
- package/dist/material-color-utilities-Cktu8DBU.js.map +0 -1
- package/dist/useLocale-CqQrhWFl.js.map +0 -1
|
@@ -75,6 +75,14 @@ const modalOpen = ref(false)
|
|
|
75
75
|
const modalSearch = ref('')
|
|
76
76
|
const search = ref('')
|
|
77
77
|
const highlightIndex = ref(-1)
|
|
78
|
+
// ARIA combobox + listbox: the input points at the open list and the option the arrow keys are on
|
|
79
|
+
const listId = `${id}-list`
|
|
80
|
+
const optionId = (i: number) => `${id}-opt-${i}`
|
|
81
|
+
const activeOption = computed(() => {
|
|
82
|
+
if (!open.value && !modalOpen.value) return undefined
|
|
83
|
+
const i = filteredOptions.value.findIndex((o) => !o.disabled && getEnabledIndex(o) === highlightIndex.value)
|
|
84
|
+
return i >= 0 ? optionId(i) : undefined
|
|
85
|
+
})
|
|
78
86
|
const fieldEl = ref<HTMLElement | null>(null)
|
|
79
87
|
const inputEl = ref<HTMLInputElement | null>(null)
|
|
80
88
|
const { resolvedFieldBg } = useFieldBg(fieldEl, () => props.fieldBg)
|
|
@@ -350,7 +358,12 @@ const labelClasses = computed(() => {
|
|
|
350
358
|
:disabled="disabled"
|
|
351
359
|
autocomplete="off"
|
|
352
360
|
role="combobox"
|
|
353
|
-
|
|
361
|
+
aria-autocomplete="list"
|
|
362
|
+
:aria-expanded="open || modalOpen"
|
|
363
|
+
:aria-controls="open || modalOpen ? listId : undefined"
|
|
364
|
+
:aria-activedescendant="activeOption"
|
|
365
|
+
:aria-required="required || undefined"
|
|
366
|
+
:aria-invalid="error || undefined"
|
|
354
367
|
:aria-disabled="disabled"
|
|
355
368
|
:class="[
|
|
356
369
|
triggerClasses,
|
|
@@ -371,6 +384,7 @@ const labelClasses = computed(() => {
|
|
|
371
384
|
|
|
372
385
|
<!-- Clear button -->
|
|
373
386
|
<button
|
|
387
|
+
:aria-label="locale.clear"
|
|
374
388
|
v-if="clearable && hasValue && !disabled"
|
|
375
389
|
type="button"
|
|
376
390
|
class="absolute right-9 top-1/2 -translate-y-1/2 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
@@ -409,13 +423,20 @@ const labelClasses = computed(() => {
|
|
|
409
423
|
>
|
|
410
424
|
<div
|
|
411
425
|
v-if="open && mode === 'docked'"
|
|
426
|
+
:id="listId"
|
|
412
427
|
ref="dropdownEl"
|
|
428
|
+
role="listbox"
|
|
429
|
+
:aria-label="label || undefined"
|
|
413
430
|
class="fixed z-500 max-h-60 overflow-auto rounded-xs bg-surface-container py-1 shadow-elevation-2"
|
|
414
431
|
:style="dropPos"
|
|
415
432
|
>
|
|
416
433
|
<div
|
|
417
434
|
v-for="(opt, i) in filteredOptions"
|
|
435
|
+
:id="optionId(i)"
|
|
418
436
|
:key="i"
|
|
437
|
+
role="option"
|
|
438
|
+
:aria-selected="eq(opt.value, modelValue)"
|
|
439
|
+
:aria-disabled="opt.disabled || undefined"
|
|
419
440
|
data-option
|
|
420
441
|
class="flex cursor-pointer items-center gap-3 px-4 py-3 text-body-large"
|
|
421
442
|
:class="[
|
|
@@ -452,9 +473,14 @@ const labelClasses = computed(() => {
|
|
|
452
473
|
class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/32 p-4"
|
|
453
474
|
@click.self="closeDropdown"
|
|
454
475
|
>
|
|
455
|
-
<div
|
|
476
|
+
<div
|
|
477
|
+
class="ac-modal-box flex max-h-[80vh] w-full max-w-sm flex-col overflow-hidden rounded-[28px] bg-surface-container-high shadow-elevation-3"
|
|
478
|
+
role="dialog"
|
|
479
|
+
aria-modal="true"
|
|
480
|
+
:aria-labelledby="`${id}-dialog-title`"
|
|
481
|
+
>
|
|
456
482
|
<div class="flex items-center justify-between px-6 pt-6 pb-4">
|
|
457
|
-
<h2 class="text-headline-small text-on-surface">{{ label || placeholder }}</h2>
|
|
483
|
+
<h2 :id="`${id}-dialog-title`" class="text-headline-small text-on-surface">{{ label || placeholder }}</h2>
|
|
458
484
|
<MIconButton icon="close" :label="locale.close" @click="closeDropdown" />
|
|
459
485
|
</div>
|
|
460
486
|
|
|
@@ -473,10 +499,14 @@ const labelClasses = computed(() => {
|
|
|
473
499
|
|
|
474
500
|
<div class="h-px bg-outline-variant" />
|
|
475
501
|
|
|
476
|
-
<div class="flex-1 overflow-y-auto py-2">
|
|
502
|
+
<div :id="listId" role="listbox" :aria-labelledby="`${id}-dialog-title`" class="flex-1 overflow-y-auto py-2">
|
|
477
503
|
<div
|
|
478
504
|
v-for="(opt, i) in modalFilteredOptions"
|
|
505
|
+
:id="optionId(i)"
|
|
479
506
|
:key="i"
|
|
507
|
+
role="option"
|
|
508
|
+
:aria-selected="eq(opt.value, modelValue)"
|
|
509
|
+
:aria-disabled="opt.disabled || undefined"
|
|
480
510
|
class="flex cursor-pointer items-center gap-4 px-6 py-3.5 text-body-large transition-colors"
|
|
481
511
|
:class="[
|
|
482
512
|
opt.disabled
|
|
@@ -248,6 +248,7 @@ const squareCorners = computed(() => props.squareCornersWhenFull && isExpanded.v
|
|
|
248
248
|
<div v-if="title" class="flex shrink-0 items-center justify-between px-6 pb-4">
|
|
249
249
|
<h2 class="text-title-large text-on-surface">{{ title }}</h2>
|
|
250
250
|
<button
|
|
251
|
+
:aria-label="locale.close"
|
|
251
252
|
type="button"
|
|
252
253
|
class="flex h-9 w-9 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8"
|
|
253
254
|
@click="close"
|
|
@@ -411,7 +411,7 @@ function colStyle(col: DataTableColumn) {
|
|
|
411
411
|
<div v-if="searchable" class="flex min-w-48 flex-1 items-center gap-2 rounded-full border border-outline-variant bg-surface-container px-3 py-1.5 transition-[border-color,box-shadow] duration-150 focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30">
|
|
412
412
|
<MIcon name="search" :size="16" class="shrink-0 text-on-surface-variant" />
|
|
413
413
|
<input v-model="search" type="text" :placeholder="searchPlaceholder ?? locale.search" class="w-full bg-transparent text-body-medium text-on-surface outline-none placeholder:text-on-surface-variant" />
|
|
414
|
-
<button v-if="search" class="text-on-surface-variant transition-colors hover:text-on-surface" @click="search = ''">
|
|
414
|
+
<button type="button" :aria-label="locale.clearSearch" v-if="search" class="text-on-surface-variant transition-colors hover:text-on-surface" @click="search = ''">
|
|
415
415
|
<MIcon name="close" :size="14" />
|
|
416
416
|
</button>
|
|
417
417
|
</div>
|
package/src/components/MIcon.vue
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
3
|
* Renders a Material Symbols Outlined glyph by name. Color follows the surrounding text color (set it with a
|
|
4
|
-
* Tailwind text-* class).
|
|
4
|
+
* Tailwind text-* class). Decorative by default: hidden from assistive technology, which would otherwise read the
|
|
5
|
+
* glyph's ligature text (its name, e.g. "arrow_drop_down"). Give it a `label` when the icon says something on its own.
|
|
5
6
|
*/
|
|
6
7
|
withDefaults(defineProps<{
|
|
7
8
|
/** Material Symbol name (e.g. "settings", "favorite") */
|
|
@@ -10,11 +11,17 @@ withDefaults(defineProps<{
|
|
|
10
11
|
size?: number
|
|
11
12
|
/** Filled glyph (the Material Symbols FILL axis), as M3 draws a selected icon */
|
|
12
13
|
filled?: boolean
|
|
14
|
+
/** What the icon means, when nothing next to it says so: makes it an image with this name instead of decoration */
|
|
15
|
+
label?: string
|
|
13
16
|
}>(), { size: 24, filled: false })
|
|
14
17
|
</script>
|
|
15
18
|
|
|
16
19
|
<template>
|
|
17
|
-
<span
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
<span
|
|
21
|
+
class="material-symbols-outlined leading-none"
|
|
22
|
+
:role="label ? 'img' : undefined"
|
|
23
|
+
:aria-label="label"
|
|
24
|
+
:aria-hidden="label ? undefined : 'true'"
|
|
25
|
+
:style="{ fontSize: `${size}px`, fontVariationSettings: filled ? `'FILL' 1` : undefined }"
|
|
26
|
+
>{{ name }}</span>
|
|
20
27
|
</template>
|
package/src/components/MList.vue
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* A vertical list container (MList) with rich, flexible rows (MListItem) and optional section headers
|
|
4
4
|
* (MListSubheader) — one-line to three-line items, leading/trailing elements, selection, navigation, segmented,
|
|
5
|
-
* and expandable variants.
|
|
5
|
+
* and expandable variants. MListGroup splits a list into groups (separate rounded runs in a segmented list).
|
|
6
6
|
*
|
|
7
|
-
* @slot default MListItem / MListSubheader children
|
|
7
|
+
* @slot default MListItem / MListSubheader / MListGroup children
|
|
8
8
|
* @event update:selected Fires when a selectable item is clicked (via v-model:selected)
|
|
9
9
|
*/
|
|
10
|
-
import { computed,
|
|
10
|
+
import { computed, provide, ref } from 'vue'
|
|
11
|
+
import { useSegmentRuns } from '../composables/_useSegmentRuns'
|
|
11
12
|
|
|
12
13
|
const props = withDefaults(
|
|
13
14
|
defineProps<{
|
|
@@ -33,36 +34,13 @@ const emit = defineEmits<{
|
|
|
33
34
|
'update:selected': [value: string | number | null]
|
|
34
35
|
}>()
|
|
35
36
|
|
|
36
|
-
// Segmented items need to know whether they open or close their run of items
|
|
37
|
-
//
|
|
37
|
+
// Segmented items need to know whether they open or close their run of items. A subheader, an MListGroup
|
|
38
|
+
// or any other non-item child starts a new run.
|
|
38
39
|
const listEl = ref<HTMLElement>()
|
|
39
|
-
const
|
|
40
|
-
function measure() {
|
|
41
|
-
const map = new Map<Element, 'single' | 'first' | 'middle' | 'last'>()
|
|
42
|
-
let run: Element[] = []
|
|
43
|
-
const flush = () => {
|
|
44
|
-
run.forEach((el, i) => map.set(el, run.length === 1 ? 'single' : i === 0 ? 'first' : i === run.length - 1 ? 'last' : 'middle'))
|
|
45
|
-
run = []
|
|
46
|
-
}
|
|
47
|
-
for (const child of listEl.value?.children ?? []) {
|
|
48
|
-
if (child.getAttribute('role') === 'listitem') run.push(child)
|
|
49
|
-
else flush()
|
|
50
|
-
}
|
|
51
|
-
flush()
|
|
52
|
-
positions.value = map
|
|
53
|
-
}
|
|
54
|
-
let observer: MutationObserver | undefined
|
|
55
|
-
onMounted(() => {
|
|
56
|
-
measure()
|
|
57
|
-
if (listEl.value) {
|
|
58
|
-
observer = new MutationObserver(measure)
|
|
59
|
-
observer.observe(listEl.value, { childList: true })
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
onUnmounted(() => observer?.disconnect())
|
|
40
|
+
const segmentPosition = useSegmentRuns(listEl)
|
|
63
41
|
|
|
64
42
|
provide('m-list', {
|
|
65
|
-
segmentPosition
|
|
43
|
+
segmentPosition,
|
|
66
44
|
dense: computed(() => props.dense),
|
|
67
45
|
nav: computed(() => props.nav),
|
|
68
46
|
segmented: computed(() => props.segmented),
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A group of items inside an MList, optionally titled. In a segmented list each group is a rounded run of its
|
|
4
|
+
* own (its first and last items take the large outer corners), set apart from the items and groups around it,
|
|
5
|
+
* like the grouped cards of a settings screen. Elsewhere it only groups and titles its items. Assistive
|
|
6
|
+
* technology announces it as a nested list named by its title.
|
|
7
|
+
*
|
|
8
|
+
* @slot default MListItem children
|
|
9
|
+
* @slot title Custom title content, replacing the title prop
|
|
10
|
+
*/
|
|
11
|
+
import { computed, inject, provide, ref, useId, type ComputedRef } from 'vue'
|
|
12
|
+
import { useSegmentRuns } from '../composables/_useSegmentRuns'
|
|
13
|
+
|
|
14
|
+
withDefaults(
|
|
15
|
+
defineProps<{
|
|
16
|
+
/** Heading above the group, styled like MListSubheader */
|
|
17
|
+
title?: string
|
|
18
|
+
/** Align the title with items that have a leading icon (adds left padding) */
|
|
19
|
+
inset?: boolean
|
|
20
|
+
}>(),
|
|
21
|
+
{ inset: false },
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
// Same context as MList's, with the group's own runs: its items are measured against each other, not the list
|
|
25
|
+
const parent = inject<({ segmented: ComputedRef<boolean>; nav: ComputedRef<boolean> } & Record<string, unknown>) | null>('m-list', null)
|
|
26
|
+
const groupEl = ref<HTMLElement>()
|
|
27
|
+
const segmentPosition = useSegmentRuns(groupEl)
|
|
28
|
+
if (parent) provide('m-list', { ...parent, segmentPosition })
|
|
29
|
+
|
|
30
|
+
const segmented = computed(() => parent?.segmented.value ?? false)
|
|
31
|
+
const nav = computed(() => parent?.nav.value ?? false)
|
|
32
|
+
const titleId = `m3-list-group-${useId()}`
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<template>
|
|
36
|
+
<li role="none" class="m3-list-group flex flex-col" :class="segmented && 'm3-list-group-segmented'">
|
|
37
|
+
<div
|
|
38
|
+
v-if="title || $slots.title"
|
|
39
|
+
:id="titleId"
|
|
40
|
+
class="px-4 pb-2 text-label-medium font-medium text-on-surface-variant"
|
|
41
|
+
:class="[segmented ? 'pt-2' : 'pt-4', inset && 'pl-16']"
|
|
42
|
+
>
|
|
43
|
+
<slot name="title">{{ title }}</slot>
|
|
44
|
+
</div>
|
|
45
|
+
<ul
|
|
46
|
+
ref="groupEl"
|
|
47
|
+
role="list"
|
|
48
|
+
:aria-labelledby="title || $slots.title ? titleId : undefined"
|
|
49
|
+
class="flex flex-col"
|
|
50
|
+
:class="(segmented || nav) && 'gap-0.5'"
|
|
51
|
+
>
|
|
52
|
+
<slot />
|
|
53
|
+
</ul>
|
|
54
|
+
</li>
|
|
55
|
+
</template>
|
|
56
|
+
|
|
57
|
+
<style>
|
|
58
|
+
/* Segmented: 10px plus the list's 2dp gap sets a group apart from what comes before and after it.
|
|
59
|
+
In the components layer so a consumer's margin utility still wins. */
|
|
60
|
+
@layer components {
|
|
61
|
+
.m3-list-group-segmented:not(:first-child),
|
|
62
|
+
.m3-list-group-segmented + li[role='listitem'] {
|
|
63
|
+
margin-top: 10px;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
</style>
|
|
@@ -9,9 +9,11 @@ import { computed, ref, useId, watch } from 'vue'
|
|
|
9
9
|
import MIcon from './MIcon.vue'
|
|
10
10
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
11
11
|
import { useDebounce } from '../composables/useDebounce'
|
|
12
|
+
import { useLocale } from '../composables/useLocale'
|
|
12
13
|
|
|
13
14
|
export type MaskPreset = 'credit-card' | 'phone' | 'date' | 'time' | 'cpf' | 'cnpj' | 'zip'
|
|
14
15
|
|
|
16
|
+
const locale = useLocale()
|
|
15
17
|
const PRESETS: Record<MaskPreset, string> = {
|
|
16
18
|
'credit-card': '#### #### #### ####',
|
|
17
19
|
phone: '(###) ###-####',
|
|
@@ -219,6 +221,7 @@ const labelClasses = computed(() => {
|
|
|
219
221
|
</label>
|
|
220
222
|
|
|
221
223
|
<button
|
|
224
|
+
:aria-label="locale.clear"
|
|
222
225
|
v-if="showClear"
|
|
223
226
|
type="button"
|
|
224
227
|
class="absolute right-3 top-1/2 -translate-y-1/2 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
@@ -408,6 +408,7 @@ const labelClasses = computed(() => {
|
|
|
408
408
|
>
|
|
409
409
|
{{ chip.label }}
|
|
410
410
|
<button
|
|
411
|
+
:aria-label="`${locale.remove} ${chip.label}`"
|
|
411
412
|
v-if="!disabled"
|
|
412
413
|
type="button"
|
|
413
414
|
class="flex h-4 w-4 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
@@ -442,6 +443,8 @@ const labelClasses = computed(() => {
|
|
|
442
443
|
:disabled="disabled"
|
|
443
444
|
autocomplete="off"
|
|
444
445
|
role="combobox"
|
|
446
|
+
aria-autocomplete="list"
|
|
447
|
+
:aria-controls="open ? `${id}-list` : undefined"
|
|
445
448
|
:aria-expanded="open"
|
|
446
449
|
:aria-disabled="disabled"
|
|
447
450
|
:class="[
|
|
@@ -463,6 +466,7 @@ const labelClasses = computed(() => {
|
|
|
463
466
|
|
|
464
467
|
<!-- Clear button -->
|
|
465
468
|
<button
|
|
469
|
+
:aria-label="locale.clear"
|
|
466
470
|
v-if="clearable && hasValue && !disabled"
|
|
467
471
|
type="button"
|
|
468
472
|
class="absolute right-9 top-4 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
@@ -505,7 +509,7 @@ const labelClasses = computed(() => {
|
|
|
505
509
|
class="fixed z-500 max-h-60 overflow-auto rounded-xs bg-surface-container shadow-elevation-2"
|
|
506
510
|
:style="dropPos"
|
|
507
511
|
>
|
|
508
|
-
<div class="flex flex-col py-1">
|
|
512
|
+
<div :id="`${id}-list`" role="group" :aria-label="label || undefined" class="flex flex-col py-1">
|
|
509
513
|
<label
|
|
510
514
|
v-for="(opt, i) in filteredOptions"
|
|
511
515
|
:key="i"
|
|
@@ -86,6 +86,10 @@ const emit = defineEmits<{ 'update:modelValue': [unknown[]] }>()
|
|
|
86
86
|
const id = useId()
|
|
87
87
|
const open = ref(false)
|
|
88
88
|
const modalOpen = ref(false)
|
|
89
|
+
// Focused (from the keyboard too) looks like open: M3's focused field, 2dp primary indicator and primary label,
|
|
90
|
+
// instead of the browser's own outline
|
|
91
|
+
const focused = ref(false)
|
|
92
|
+
const highlighted = computed(() => open.value || modalOpen.value || focused.value)
|
|
89
93
|
const modalSearch = ref('')
|
|
90
94
|
const search = ref('')
|
|
91
95
|
const fieldEl = ref<HTMLElement | null>(null)
|
|
@@ -221,7 +225,7 @@ onUnmounted(() => {
|
|
|
221
225
|
|
|
222
226
|
const triggerClasses = computed(() => {
|
|
223
227
|
const base = [
|
|
224
|
-
'flex min-h-[56px] w-full items-center gap-1.5 flex-wrap',
|
|
228
|
+
'flex min-h-[56px] w-full items-center gap-1.5 flex-wrap outline-none',
|
|
225
229
|
'transition-[border-color,border-width] duration-150',
|
|
226
230
|
props.disabled ? 'cursor-not-allowed' : 'cursor-pointer',
|
|
227
231
|
props.leadingIcon ? 'pl-12 pr-10' : 'pl-4 pr-10',
|
|
@@ -230,7 +234,7 @@ const triggerClasses = computed(() => {
|
|
|
230
234
|
if (props.variant === 'outlined') {
|
|
231
235
|
const border = props.disabled
|
|
232
236
|
? 'border-on-surface/12'
|
|
233
|
-
:
|
|
237
|
+
: highlighted.value
|
|
234
238
|
? (props.error ? 'border-2 border-error' : 'border-2 border-primary')
|
|
235
239
|
: (props.error ? 'border-error' : 'border-outline hover:border-on-surface')
|
|
236
240
|
return [...base, 'rounded-xs border bg-transparent py-2', border].join(' ')
|
|
@@ -238,7 +242,7 @@ const triggerClasses = computed(() => {
|
|
|
238
242
|
|
|
239
243
|
const border = props.disabled
|
|
240
244
|
? 'border-on-surface/38'
|
|
241
|
-
:
|
|
245
|
+
: highlighted.value
|
|
242
246
|
? (props.error ? 'border-b-2 border-error' : 'border-b-2 border-primary')
|
|
243
247
|
: (props.error ? 'border-error' : 'border-on-surface-variant hover:border-on-surface')
|
|
244
248
|
const bg = props.disabled
|
|
@@ -247,7 +251,7 @@ const triggerClasses = computed(() => {
|
|
|
247
251
|
return [
|
|
248
252
|
...base,
|
|
249
253
|
'rounded-t-xs border-b pb-2',
|
|
250
|
-
hasValue.value ||
|
|
254
|
+
hasValue.value || highlighted.value ? 'pt-7' : 'pt-4',
|
|
251
255
|
bg,
|
|
252
256
|
border,
|
|
253
257
|
].join(' ')
|
|
@@ -265,7 +269,7 @@ const labelClasses = computed(() => {
|
|
|
265
269
|
const unFloated = props.variant === 'filled'
|
|
266
270
|
? 'top-[53%] -translate-y-1/2 text-body-large'
|
|
267
271
|
: 'top-1/2 -translate-y-1/2 text-body-large'
|
|
268
|
-
const active =
|
|
272
|
+
const active = highlighted.value || hasValue.value
|
|
269
273
|
|
|
270
274
|
return [
|
|
271
275
|
'pointer-events-none absolute right-10 truncate transition-all duration-200',
|
|
@@ -273,7 +277,7 @@ const labelClasses = computed(() => {
|
|
|
273
277
|
active ? floated : unFloated,
|
|
274
278
|
props.disabled
|
|
275
279
|
? 'text-on-surface/38'
|
|
276
|
-
:
|
|
280
|
+
: highlighted.value
|
|
277
281
|
? (props.error ? 'text-error' : 'text-primary')
|
|
278
282
|
: (props.error ? 'text-error' : 'text-on-surface-variant'),
|
|
279
283
|
].join(' ')
|
|
@@ -305,12 +309,16 @@ const labelClasses = computed(() => {
|
|
|
305
309
|
:class="triggerClasses"
|
|
306
310
|
role="button"
|
|
307
311
|
:tabindex="disabled ? -1 : 0"
|
|
308
|
-
:aria-expanded="open"
|
|
312
|
+
:aria-expanded="open || modalOpen"
|
|
309
313
|
:aria-haspopup="true"
|
|
314
|
+
:aria-controls="open ? `${id}-list` : undefined"
|
|
315
|
+
:aria-labelledby="label ? `${id}-label` : undefined"
|
|
310
316
|
@click="open ? close() : openDropdown()"
|
|
311
317
|
@keydown.enter.prevent="open ? close() : openDropdown()"
|
|
312
318
|
@keydown.space.prevent="open ? close() : openDropdown()"
|
|
313
319
|
@keydown.escape="close()"
|
|
320
|
+
@focus="focused = true"
|
|
321
|
+
@blur="focused = false"
|
|
314
322
|
>
|
|
315
323
|
<template v-if="hasValue">
|
|
316
324
|
<span
|
|
@@ -321,6 +329,7 @@ const labelClasses = computed(() => {
|
|
|
321
329
|
>
|
|
322
330
|
{{ chip.label }}
|
|
323
331
|
<button
|
|
332
|
+
:aria-label="`${locale.remove} ${chip.label}`"
|
|
324
333
|
v-if="!disabled"
|
|
325
334
|
type="button"
|
|
326
335
|
class="flex h-4 w-4 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
@@ -350,11 +359,12 @@ const labelClasses = computed(() => {
|
|
|
350
359
|
</span>
|
|
351
360
|
</div>
|
|
352
361
|
|
|
353
|
-
<label :class="labelClasses">
|
|
362
|
+
<label :id="`${id}-label`" :class="labelClasses">
|
|
354
363
|
{{ label }}<span v-if="required" class="text-error"> *</span>
|
|
355
364
|
</label>
|
|
356
365
|
|
|
357
366
|
<button
|
|
367
|
+
:aria-label="locale.clear"
|
|
358
368
|
v-if="clearable && hasValue && !disabled"
|
|
359
369
|
type="button"
|
|
360
370
|
class="absolute right-9 top-4 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
@@ -409,7 +419,7 @@ const labelClasses = computed(() => {
|
|
|
409
419
|
</div>
|
|
410
420
|
</div>
|
|
411
421
|
|
|
412
|
-
<div class="flex flex-col py-1">
|
|
422
|
+
<div :id="`${id}-list`" role="group" :aria-label="label || undefined" class="flex flex-col py-1">
|
|
413
423
|
<label
|
|
414
424
|
v-for="(opt, i) in filteredOptions"
|
|
415
425
|
:key="i"
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import type { GeneratedScheme } from '../composables/dynamicColor'
|
|
4
|
+
|
|
5
|
+
// Shared by every MScheme: the app's light/dark state (the `dark` class on <html>, whoever sets it), one observer
|
|
6
|
+
// for all of them, and the schemes and image seeds already built.
|
|
7
|
+
const isDark = ref(false)
|
|
8
|
+
let observer: MutationObserver | undefined
|
|
9
|
+
let users = 0
|
|
10
|
+
function watchDark() {
|
|
11
|
+
if (users++ > 0) return
|
|
12
|
+
const html = document.documentElement
|
|
13
|
+
isDark.value = html.classList.contains('dark')
|
|
14
|
+
observer = new MutationObserver(() => (isDark.value = html.classList.contains('dark')))
|
|
15
|
+
observer.observe(html, { attributes: true, attributeFilter: ['class'] })
|
|
16
|
+
}
|
|
17
|
+
function unwatchDark() {
|
|
18
|
+
if (--users > 0) return
|
|
19
|
+
observer?.disconnect()
|
|
20
|
+
observer = undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const schemes = new Map<string, Promise<GeneratedScheme>>()
|
|
24
|
+
const imageSeeds = new Map<string, Promise<string>>()
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script setup lang="ts">
|
|
28
|
+
/**
|
|
29
|
+
* Paints its content with a color scheme of its own, built from a seed color or from an image's dominant color
|
|
30
|
+
* (Material You's content color: an album, a dish or a profile photo coloring its own page), or one of the
|
|
31
|
+
* palettes (a theme picker's previews). Every `bg-*`/`text-*`
|
|
32
|
+
* M3 utility and every component inside it uses the scheme, in light or dark like the rest of the app, while the
|
|
33
|
+
* rest of the app keeps its palette. Its text color is the scheme's `on-surface`; it sets no background.
|
|
34
|
+
*
|
|
35
|
+
* @slot default The content. Receives `{ seed, ready }`: the seed in use (the image's once it's read) and whether
|
|
36
|
+
* the scheme is applied yet
|
|
37
|
+
* @event seed Emitted with the seed color read from `image`
|
|
38
|
+
*/
|
|
39
|
+
import { computed, onMounted, onUnmounted, shallowRef, watch } from 'vue'
|
|
40
|
+
import { generateScheme, seedFromImage, type SchemeVariant } from '../composables/dynamicColor'
|
|
41
|
+
import { hasPaletteCss, palettes } from '../composables/useColorPalette'
|
|
42
|
+
|
|
43
|
+
const props = withDefaults(
|
|
44
|
+
defineProps<{
|
|
45
|
+
/** Seed color (`#rrggbb`) the scheme is built from */
|
|
46
|
+
seed?: string
|
|
47
|
+
/**
|
|
48
|
+
* An image (URL) whose dominant color becomes the seed, picked as Android picks a wallpaper's. Cross-origin
|
|
49
|
+
* images need CORS headers. `seed` wins while both are set
|
|
50
|
+
*/
|
|
51
|
+
image?: string
|
|
52
|
+
/**
|
|
53
|
+
* One of the palettes (`useColorPalette().palettes`, custom ones included), applied to this element only with
|
|
54
|
+
* its own CSS, in its standard contrast. `seed` and `image` win while set
|
|
55
|
+
*/
|
|
56
|
+
palette?: string
|
|
57
|
+
/** How the seed spreads into the scheme; `content` and `fidelity` keep the seed's own color most visible */
|
|
58
|
+
variant?: SchemeVariant
|
|
59
|
+
/** Contrast level: 0 standard, 0.5 medium, 1 high (-1 reduced) */
|
|
60
|
+
contrast?: number
|
|
61
|
+
/** Element to render */
|
|
62
|
+
as?: string
|
|
63
|
+
}>(),
|
|
64
|
+
{ variant: 'tonal-spot', contrast: 0, as: 'div' },
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
const emit = defineEmits<{ seed: [color: string] }>()
|
|
68
|
+
|
|
69
|
+
const imageSeed = shallowRef<string>()
|
|
70
|
+
const scheme = shallowRef<GeneratedScheme>()
|
|
71
|
+
|
|
72
|
+
// A palette with CSS (palettes.css, or a custom one with its own) is just its attribute on this element. 'purple'
|
|
73
|
+
// lives in :root with no [data-palette] block, and a custom palette may have none: those are built from their seed.
|
|
74
|
+
const paletteSeed = shallowRef<string>()
|
|
75
|
+
watch(
|
|
76
|
+
() => props.palette,
|
|
77
|
+
(id) => {
|
|
78
|
+
paletteSeed.value = undefined
|
|
79
|
+
if (!id || typeof document === 'undefined' || (id !== 'purple' && hasPaletteCss(id))) return
|
|
80
|
+
paletteSeed.value = palettes.find((p) => p.id === id)?.seed
|
|
81
|
+
},
|
|
82
|
+
{ immediate: true },
|
|
83
|
+
)
|
|
84
|
+
const paletteAttr = computed(() => (!props.seed && !props.image && props.palette && !paletteSeed.value ? props.palette : undefined))
|
|
85
|
+
|
|
86
|
+
const activeSeed = computed(() => props.seed ?? (props.image ? imageSeed.value : paletteSeed.value))
|
|
87
|
+
|
|
88
|
+
watch(
|
|
89
|
+
() => props.image,
|
|
90
|
+
async (src) => {
|
|
91
|
+
imageSeed.value = undefined
|
|
92
|
+
if (!src || typeof window === 'undefined') return
|
|
93
|
+
let pending = imageSeeds.get(src)
|
|
94
|
+
if (!pending) {
|
|
95
|
+
pending = seedFromImage(src)
|
|
96
|
+
imageSeeds.set(src, pending)
|
|
97
|
+
pending.catch(() => imageSeeds.delete(src))
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const color = await pending
|
|
101
|
+
if (props.image !== src) return
|
|
102
|
+
imageSeed.value = color
|
|
103
|
+
emit('seed', color)
|
|
104
|
+
} catch {
|
|
105
|
+
// Unreadable image (failed to load, or cross-origin without CORS): keep the app's colors
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{ immediate: true },
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
watch(
|
|
112
|
+
() => [activeSeed.value, props.variant, props.contrast] as const,
|
|
113
|
+
async ([seed, variant, contrast]) => {
|
|
114
|
+
if (!seed) {
|
|
115
|
+
scheme.value = undefined
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
const key = `${seed}|${variant}|${contrast}`
|
|
119
|
+
let pending = schemes.get(key)
|
|
120
|
+
if (!pending) {
|
|
121
|
+
pending = generateScheme(seed, { variant, contrast })
|
|
122
|
+
schemes.set(key, pending)
|
|
123
|
+
}
|
|
124
|
+
const result = await pending
|
|
125
|
+
if (activeSeed.value === seed && props.variant === variant && props.contrast === contrast) scheme.value = result
|
|
126
|
+
},
|
|
127
|
+
{ immediate: true },
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
onMounted(watchDark)
|
|
131
|
+
onUnmounted(unwatchDark)
|
|
132
|
+
|
|
133
|
+
const style = computed(() => {
|
|
134
|
+
if (!scheme.value || paletteAttr.value) return undefined
|
|
135
|
+
const dark = isDark.value
|
|
136
|
+
const out: Record<string, string> = { colorScheme: dark ? 'dark' : 'light' }
|
|
137
|
+
for (const [role, value] of Object.entries(dark ? scheme.value.dark : scheme.value.light)) out[`--color-${role}`] = value
|
|
138
|
+
return out
|
|
139
|
+
})
|
|
140
|
+
</script>
|
|
141
|
+
|
|
142
|
+
<template>
|
|
143
|
+
<component
|
|
144
|
+
:is="as"
|
|
145
|
+
class="m3-scheme"
|
|
146
|
+
:class="paletteAttr && isDark && 'dark'"
|
|
147
|
+
:data-palette="paletteAttr"
|
|
148
|
+
:style="style"
|
|
149
|
+
>
|
|
150
|
+
<slot :seed="activeSeed" :ready="!!style || !!paletteAttr" />
|
|
151
|
+
</component>
|
|
152
|
+
</template>
|
|
153
|
+
|
|
154
|
+
<style>
|
|
155
|
+
/* Plain text inherits a color computed outside, with the app's palette: use the scheme's. In the base layer so a
|
|
156
|
+
text-* class on the component wins. */
|
|
157
|
+
@layer base {
|
|
158
|
+
.m3-scheme {
|
|
159
|
+
color: var(--color-on-surface);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
</style>
|
|
@@ -185,6 +185,7 @@ useScrollLock(() => expanded.value && fullscreen.value)
|
|
|
185
185
|
@keydown="onKeydown"
|
|
186
186
|
/>
|
|
187
187
|
<button
|
|
188
|
+
:aria-label="locale.clearSearch"
|
|
188
189
|
v-if="clearable && modelValue && !disabled"
|
|
189
190
|
type="button"
|
|
190
191
|
class="flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
@@ -234,6 +235,7 @@ useScrollLock(() => expanded.value && fullscreen.value)
|
|
|
234
235
|
/>
|
|
235
236
|
<MSpinner v-if="loading" :size="20" class="shrink-0 text-on-surface-variant" />
|
|
236
237
|
<button
|
|
238
|
+
:aria-label="locale.clearSearch"
|
|
237
239
|
v-else-if="clearable && modelValue"
|
|
238
240
|
type="button"
|
|
239
241
|
class="flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|