@m3ui-vue/m3ui-vue 0.7.1 → 0.8.1
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 +14 -6
- package/dist/{MMenuItem-xQ1x6-DH.js → MMenuItem-CDWfeU4F.js} +331 -252
- package/dist/MMenuItem-CDWfeU4F.js.map +1 -0
- package/dist/code-editor.d.ts +1 -0
- package/dist/code-editor.js +22 -7
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MButton.vue.d.ts +7 -0
- package/dist/components/MCalendar.vue.d.ts +0 -1
- package/dist/components/MCard.vue.d.ts +2 -0
- package/dist/components/MCarousel.vue.d.ts +12 -14
- package/dist/components/MChatBubble.vue.d.ts +0 -1
- package/dist/components/MCircleProgressBar.vue.d.ts +0 -1
- package/dist/components/MCodeEditor.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +3 -0
- package/dist/components/MDatePicker.vue.d.ts +1 -3
- package/dist/components/MDatePickerModal.vue.d.ts +0 -1
- package/dist/components/MDateRangePicker.vue.d.ts +1 -3
- package/dist/components/MDateRangePickerModal.vue.d.ts +0 -1
- package/dist/components/MDialog.vue.d.ts +23 -7
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MKanban.vue.d.ts +1 -0
- package/dist/components/MListItem.vue.d.ts +11 -6
- package/dist/components/MNavigationRail.vue.d.ts +17 -1
- package/dist/components/MScheduler.vue.d.ts +0 -1
- package/dist/components/MSelect.vue.d.ts +1 -0
- package/dist/components/MShape.vue.d.ts +51 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +34 -0
- package/dist/components/MSimpleCarousel.vue.d.ts +45 -0
- package/dist/components/MSwitch.vue.d.ts +8 -0
- package/dist/components/MTabs.vue.d.ts +3 -0
- package/dist/components/MToggleButton.vue.d.ts +29 -0
- package/dist/components/MTree.vue.d.ts +0 -1
- package/dist/components/MTreeTable.vue.d.ts +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4387 -2525
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +1 -1
- package/dist/styles/palettes.css +659 -0
- package/dist/styles/theme.css +1 -0
- package/dist/styles.css +1 -1
- package/package.json +16 -1
- package/src/__tests__/MCarousel.test.ts +33 -0
- package/src/__tests__/MShape.test.ts +36 -0
- package/src/__tests__/MToggleButton.test.ts +27 -0
- package/src/__tests__/useColorPalette.test.ts +2 -2
- package/src/code-editor.ts +1 -0
- package/src/components/MAutocomplete.vue +40 -27
- package/src/components/MBadge.vue +1 -1
- package/src/components/MBottomSheet.vue +4 -4
- package/src/components/MButton.vue +51 -21
- package/src/components/MButtonGroup.vue +2 -2
- package/src/components/MCalendar.vue +9 -5
- package/src/components/MCard.vue +76 -11
- package/src/components/MCarousel.vue +123 -173
- package/src/components/MChatBubble.vue +0 -1
- package/src/components/MCheckbox.vue +58 -13
- package/src/components/MChip.vue +26 -6
- package/src/components/MCircleProgressBar.vue +7 -4
- package/src/components/MCodeEditor.vue +60 -9
- package/src/components/MColorPicker.vue +9 -8
- package/src/components/MColorPickerModal.vue +2 -2
- package/src/components/MCommandPalette.vue +1 -1
- package/src/components/MConfirmDialog.vue +4 -0
- package/src/components/MContextMenu.vue +27 -6
- package/src/components/MDatePicker.vue +23 -20
- package/src/components/MDatePickerModal.vue +14 -9
- package/src/components/MDateRangePicker.vue +24 -21
- package/src/components/MDateRangePickerModal.vue +12 -7
- package/src/components/MDialog.vue +103 -12
- package/src/components/MFab.vue +10 -7
- package/src/components/MFabMenu.vue +1 -1
- package/src/components/MIconButton.vue +41 -19
- package/src/components/MKanban.vue +5 -1
- package/src/components/MListItem.vue +35 -17
- package/src/components/MLoadingIndicator.vue +14 -7
- package/src/components/MMaskField.vue +14 -6
- package/src/components/MMenu.vue +32 -7
- package/src/components/MMenuItem.vue +2 -2
- package/src/components/MMultiAutocomplete.vue +46 -27
- package/src/components/MMultiSelect.vue +45 -23
- package/src/components/MNavigationBar.vue +5 -10
- package/src/components/MNavigationDrawer.vue +10 -9
- package/src/components/MNavigationRail.vue +335 -22
- package/src/components/MNumberField.vue +14 -6
- package/src/components/MOverlay.vue +1 -1
- package/src/components/MPinInput.vue +7 -4
- package/src/components/MProgressBar.vue +16 -10
- package/src/components/MRadio.vue +54 -12
- package/src/components/MScheduler.vue +10 -6
- package/src/components/MSearchBar.vue +8 -3
- package/src/components/MSegmentedButton.vue +14 -9
- package/src/components/MSelect.vue +49 -33
- package/src/components/MShape.vue +107 -0
- package/src/components/MShortNavigationBar.vue +113 -0
- package/src/components/MSideSheet.vue +1 -1
- package/src/components/MSimpleCarousel.vue +325 -0
- package/src/components/MSnackbar.vue +4 -4
- package/src/components/MSplitButton.vue +32 -17
- package/src/components/MSpotlightSearch.vue +1 -1
- package/src/components/MSwitch.vue +96 -18
- package/src/components/MTabs.vue +16 -12
- package/src/components/MTagInput.vue +33 -22
- package/src/components/MTextField.vue +14 -6
- package/src/components/MTimePicker.vue +9 -9
- package/src/components/MTimePickerModal.vue +16 -16
- package/src/components/MToggleButton.vue +188 -0
- package/src/components/MToolbar.vue +5 -3
- package/src/components/MTooltip.vue +4 -4
- package/src/components/MTopAppBar.vue +19 -7
- package/src/components/MTour.vue +1 -1
- package/src/components/MTree.vue +4 -2
- package/src/components/MTreeTable.vue +5 -1
- package/src/composables/useColorPalette.ts +10 -0
- package/src/index.ts +9 -1
- package/src/styles/palettes.css +659 -0
- package/src/styles/theme.css +1 -0
- package/dist/MMenuItem-xQ1x6-DH.js.map +0 -1
|
@@ -19,6 +19,12 @@ const props = withDefaults(
|
|
|
19
19
|
disabled?: boolean
|
|
20
20
|
loading?: boolean
|
|
21
21
|
icon?: string
|
|
22
|
+
/**
|
|
23
|
+
* Which side of the label `icon` renders on. Real M3 buttons support both via
|
|
24
|
+
* `ButtonDefaults.contentPaddingFor(hasStartIcon/hasEndIcon)` — padding ends up identical
|
|
25
|
+
* either way at every tier, so this only changes render order, not spacing.
|
|
26
|
+
*/
|
|
27
|
+
iconPos?: 'leading' | 'trailing'
|
|
22
28
|
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
23
29
|
shape?: 'rounded' | 'squared'
|
|
24
30
|
to?: string | Record<string, any>
|
|
@@ -29,6 +35,7 @@ const props = withDefaults(
|
|
|
29
35
|
type: 'button',
|
|
30
36
|
disabled: false,
|
|
31
37
|
loading: false,
|
|
38
|
+
iconPos: 'leading',
|
|
32
39
|
size: 'sm',
|
|
33
40
|
shape: 'rounded',
|
|
34
41
|
},
|
|
@@ -53,48 +60,64 @@ const customStyle = computed(() => {
|
|
|
53
60
|
const isError = computed(() => props.color === 'error')
|
|
54
61
|
|
|
55
62
|
const base =
|
|
56
|
-
'relative inline-flex items-center justify-center
|
|
63
|
+
'relative inline-flex items-center justify-center font-medium ' +
|
|
57
64
|
'whitespace-nowrap overflow-hidden transition-[box-shadow,background-color,color] duration-150 select-none cursor-pointer ' +
|
|
58
65
|
'disabled:cursor-not-allowed disabled:shadow-none disabled:text-on-surface/38 ' +
|
|
59
66
|
"before:content-[''] before:pointer-events-none before:absolute before:inset-0 " +
|
|
60
67
|
'before:bg-current before:opacity-0 before:transition-opacity before:duration-150 ' +
|
|
61
68
|
'enabled:hover:before:opacity-[0.08] enabled:active:before:opacity-[0.12]'
|
|
62
69
|
|
|
63
|
-
// M3 disabled tokens: container at
|
|
64
|
-
//
|
|
65
|
-
// above, applies to every variant including text/elevated which have no container).
|
|
70
|
+
// M3 disabled tokens: container at 10% on-surface opacity (DisabledContainerOpacity, same
|
|
71
|
+
// across Filled/Tonal/Elevated), content/label always at 38% on-surface (handled in `base`
|
|
72
|
+
// above, applies to every variant including text/elevated which have no container). The
|
|
73
|
+
// outlined border uses the SAME color role as its enabled border (OutlineVariant, not
|
|
74
|
+
// on-surface) just dimmed to that 10% too — see `variantClasses`' outlined case below for
|
|
75
|
+
// why the enabled color is also outline-variant, not outline.
|
|
66
76
|
const disabledContainerClasses = computed(() => {
|
|
67
77
|
switch (props.variant) {
|
|
68
78
|
case 'filled':
|
|
69
79
|
case 'tonal':
|
|
70
80
|
case 'elevated':
|
|
71
|
-
return 'disabled:bg-on-surface/
|
|
81
|
+
return 'disabled:bg-on-surface/10'
|
|
72
82
|
case 'outlined':
|
|
73
|
-
return 'disabled:border-
|
|
83
|
+
return isError.value ? 'disabled:border-error/10' : 'disabled:border-outline-variant/10'
|
|
74
84
|
default:
|
|
75
85
|
return ''
|
|
76
86
|
}
|
|
77
87
|
})
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
/*
|
|
90
|
+
* M3's newer 5-tier "expressive" button sizing (Button{XSmall,Small,Medium,Large,
|
|
91
|
+
* XLarge}Tokens.kt + Button.kt's size-variant overloads — @ExperimentalMaterial3ExpressiveApi
|
|
92
|
+
* in Compose, but this `size` prop is deliberately implementing exactly that system, same
|
|
93
|
+
* as MFabMenu/MLoadingIndicator already do for other Expressive-only components). Content
|
|
94
|
+
* padding is IDENTICAL whether or not an icon is present at every tier in the default
|
|
95
|
+
* (non "precision pointer") mode — e.g. `IconMediumLeadingPadding = MediumLeadingPadding`
|
|
96
|
+
* verbatim in the real source — so there's deliberately no separate icon-vs-no-icon padding
|
|
97
|
+
* split here, unlike the old version of this file which had one (and got the values wrong
|
|
98
|
+
* in both directions). `gap` between icon and label also varies by tier (IconLabelSpace),
|
|
99
|
+
* not a flat value for every size.
|
|
100
|
+
*/
|
|
81
101
|
const sizeMap = {
|
|
82
|
-
xs: { h: 'h-8', text: 'text-label-
|
|
83
|
-
sm: { h: 'h-10', text: 'text-label-large', icon: 20, spinner: 16,
|
|
84
|
-
md: { h: 'h-14', text: 'text-title-medium', icon:
|
|
85
|
-
lg: { h: 'h-
|
|
86
|
-
xl: { h: 'h-
|
|
102
|
+
xs: { h: 'h-8', text: 'text-label-large', icon: 20, spinner: 16, gap: 'gap-1', px: 'px-3', pxText: 'px-2', squareRadius: 'rounded-md' },
|
|
103
|
+
sm: { h: 'h-10', text: 'text-label-large', icon: 20, spinner: 16, gap: 'gap-2', px: 'px-4', pxText: 'px-3', squareRadius: 'rounded-md' },
|
|
104
|
+
md: { h: 'h-14', text: 'text-title-medium', icon: 24, spinner: 18, gap: 'gap-2', px: 'px-6', pxText: 'px-3', squareRadius: 'rounded-lg' },
|
|
105
|
+
lg: { h: 'h-24', text: 'text-headline-small', icon: 32, spinner: 26, gap: 'gap-3', px: 'px-12', pxText: 'px-4', squareRadius: 'rounded-xl' },
|
|
106
|
+
xl: { h: 'h-[136px]', text: 'text-headline-large', icon: 40, spinner: 34, gap: 'gap-4', px: 'px-16', pxText: 'px-4', squareRadius: 'rounded-xl' },
|
|
87
107
|
}
|
|
88
108
|
|
|
89
109
|
const s = computed(() => sizeMap[props.size] ?? sizeMap.sm)
|
|
90
|
-
const sizeClasses = computed(() => `${s.value.h} ${s.value.text}`)
|
|
110
|
+
const sizeClasses = computed(() => `${s.value.h} ${s.value.text} ${s.value.gap}`)
|
|
91
111
|
const iconSize = computed(() => s.value.icon)
|
|
92
112
|
const spinnerSize = computed(() => s.value.spinner)
|
|
93
113
|
|
|
94
|
-
const px = computed(() =>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
114
|
+
const px = computed(() => props.variant === 'text' ? s.value.pxText : s.value.px)
|
|
115
|
+
|
|
116
|
+
// Squared shape radius scales with size, matching each tier's own ContainerShapeSquare
|
|
117
|
+
// token (ButtonXSmallTokens/ButtonSmallTokens use CornerMedium=12px, ButtonMediumTokens
|
|
118
|
+
// CornerLarge=16px, ButtonLargeTokens/ButtonXLargeTokens CornerExtraLarge=28px) — the
|
|
119
|
+
// pill (ContainerShapeRound) is CornerFull at every tier, so that half doesn't vary.
|
|
120
|
+
const shapeClass = computed(() => props.shape === 'squared' ? s.value.squareRadius : 'rounded-full')
|
|
98
121
|
|
|
99
122
|
const variantClasses = computed(() => {
|
|
100
123
|
const err = isError.value
|
|
@@ -112,9 +135,10 @@ const variantClasses = computed(() => {
|
|
|
112
135
|
? 'bg-surface-container-low text-error shadow-elevation-1 enabled:hover:shadow-elevation-2'
|
|
113
136
|
: 'bg-surface-container-low text-primary shadow-elevation-1 enabled:hover:shadow-elevation-2'
|
|
114
137
|
case 'outlined':
|
|
138
|
+
// OutlinedButtonTokens.OutlineColor = ColorSchemeKeyTokens.OutlineVariant, not Outline
|
|
115
139
|
return err
|
|
116
140
|
? 'border border-error text-error'
|
|
117
|
-
: 'border border-outline text-primary'
|
|
141
|
+
: 'border border-outline-variant text-primary'
|
|
118
142
|
case 'text':
|
|
119
143
|
return err
|
|
120
144
|
? 'text-error'
|
|
@@ -147,8 +171,14 @@ function createRipple(event: PointerEvent) {
|
|
|
147
171
|
:style="customStyle"
|
|
148
172
|
@pointerdown="createRipple"
|
|
149
173
|
>
|
|
150
|
-
<
|
|
151
|
-
|
|
174
|
+
<template v-if="iconPos === 'leading'">
|
|
175
|
+
<MSpinner v-if="loading" :size="spinnerSize" />
|
|
176
|
+
<MIcon v-else-if="icon" :name="icon" :size="iconSize" />
|
|
177
|
+
</template>
|
|
152
178
|
<slot />
|
|
179
|
+
<template v-if="iconPos === 'trailing'">
|
|
180
|
+
<MSpinner v-if="loading" :size="spinnerSize" />
|
|
181
|
+
<MIcon v-else-if="icon" :name="icon" :size="iconSize" />
|
|
182
|
+
</template>
|
|
153
183
|
</component>
|
|
154
184
|
</template>
|
|
@@ -105,7 +105,7 @@ function createRipple(event: PointerEvent) {
|
|
|
105
105
|
function btnStyle(i: number, selected: boolean) {
|
|
106
106
|
const count = props.options.length
|
|
107
107
|
const full = fullRadius.value
|
|
108
|
-
const inner = '
|
|
108
|
+
const inner = '8px'
|
|
109
109
|
let tl: string, tr: string, br: string, bl: string
|
|
110
110
|
if (props.variant === 'standard' || selected) {
|
|
111
111
|
tl = tr = br = bl = full
|
|
@@ -126,7 +126,7 @@ function btnStyle(i: number, selected: boolean) {
|
|
|
126
126
|
<template>
|
|
127
127
|
<div
|
|
128
128
|
class="inline-flex"
|
|
129
|
-
:class="variant === 'standard' ? 'gap-
|
|
129
|
+
:class="variant === 'standard' ? 'gap-3' : 'gap-0.5'"
|
|
130
130
|
role="group"
|
|
131
131
|
>
|
|
132
132
|
<button
|
|
@@ -20,11 +20,15 @@ const props = withDefaults(defineProps<{
|
|
|
20
20
|
nextMonthLabel?: string
|
|
21
21
|
}>(), {
|
|
22
22
|
events: () => [],
|
|
23
|
-
locale: 'es-ES',
|
|
24
23
|
})
|
|
25
24
|
|
|
26
25
|
const localeStrings = useLocale()
|
|
27
26
|
|
|
27
|
+
// Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
|
|
28
|
+
// fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
|
|
29
|
+
// to a hardcoded 'es-ES' regardless of what locale the app actually provided.
|
|
30
|
+
const resolvedLocale = computed(() => props.locale ?? localeStrings.lang)
|
|
31
|
+
|
|
28
32
|
const emit = defineEmits<{
|
|
29
33
|
dateClick: [string]
|
|
30
34
|
eventClick: [CalendarEvent]
|
|
@@ -32,13 +36,13 @@ const emit = defineEmits<{
|
|
|
32
36
|
|
|
33
37
|
const viewDate = ref(new Date())
|
|
34
38
|
|
|
35
|
-
const WEEKDAYS = (() => {
|
|
36
|
-
const f = new Intl.DateTimeFormat(
|
|
39
|
+
const WEEKDAYS = computed(() => {
|
|
40
|
+
const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'short' })
|
|
37
41
|
return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, i + 1)))
|
|
38
|
-
})
|
|
42
|
+
})
|
|
39
43
|
|
|
40
44
|
const monthLabel = computed(() =>
|
|
41
|
-
new Intl.DateTimeFormat(
|
|
45
|
+
new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value)
|
|
42
46
|
)
|
|
43
47
|
|
|
44
48
|
function fmt(y: number, m: number, d: number) {
|
package/src/components/MCard.vue
CHANGED
|
@@ -6,6 +6,7 @@ const props = withDefaults(
|
|
|
6
6
|
variant?: 'elevated' | 'filled' | 'outlined'
|
|
7
7
|
clickable?: boolean
|
|
8
8
|
elevated?: boolean
|
|
9
|
+
disabled?: boolean
|
|
9
10
|
/** src URL for a full-bleed header image */
|
|
10
11
|
image?: string
|
|
11
12
|
imageAlt?: string
|
|
@@ -13,17 +14,11 @@ const props = withDefaults(
|
|
|
13
14
|
title?: string
|
|
14
15
|
subtitle?: string
|
|
15
16
|
}>(),
|
|
16
|
-
{ variant: 'elevated', clickable: false, elevated: false },
|
|
17
|
+
{ variant: 'elevated', clickable: false, elevated: false, disabled: false },
|
|
17
18
|
)
|
|
18
19
|
|
|
19
20
|
const resolvedVariant = computed(() => (props.elevated ? 'elevated' : props.variant))
|
|
20
21
|
|
|
21
|
-
const variantClasses: Record<string, string> = {
|
|
22
|
-
elevated: 'bg-surface-container-low shadow-elevation-1',
|
|
23
|
-
filled: 'bg-surface-container-highest',
|
|
24
|
-
outlined: 'bg-surface border border-outline-variant',
|
|
25
|
-
}
|
|
26
|
-
|
|
27
22
|
// Expose the card's background as --field-bg so outlined text-field labels
|
|
28
23
|
// inside the card automatically match without needing the fieldBg prop.
|
|
29
24
|
const fieldBgByVariant: Record<string, string> = {
|
|
@@ -32,24 +27,94 @@ const fieldBgByVariant: Record<string, string> = {
|
|
|
32
27
|
outlined: 'var(--color-surface)',
|
|
33
28
|
}
|
|
34
29
|
|
|
30
|
+
/*
|
|
31
|
+
* M3 Card{Filled,Elevated,Outlined}Tokens: all three variants share ContainerShape =
|
|
32
|
+
* CornerMedium (12px), so a flat `rounded-md` on the wrapper (below) is correct for all of
|
|
33
|
+
* them already — no per-variant shape difference. Container color/border IS mutually
|
|
34
|
+
* exclusive between the disabled and enabled cases on purpose (a single computed picking
|
|
35
|
+
* ONE class set, never both at once): two competing `bg-*`/`border-*` utilities for the
|
|
36
|
+
* same CSS property risk losing to each other based on Tailwind's compiled-CSS source
|
|
37
|
+
* order rather than which one appears later in this class list — bit us for real on
|
|
38
|
+
* MIconButton's `relative`/`absolute` and would bite here too with `bg-surface-variant`
|
|
39
|
+
* vs `bg-surface-container-highest` fighting over `background-color`.
|
|
40
|
+
*
|
|
41
|
+
* Disabled colors are real per-variant token overrides (elevated swaps to plain `surface`,
|
|
42
|
+
* filled to `surface-variant`), not just a dimmed version of the resting color, all at 38%
|
|
43
|
+
* container opacity EXCEPT outlined, which keeps its background as-is and only dims the
|
|
44
|
+
* border — to a *different* color too (`outline` at 12%, not the resting `outline-variant`).
|
|
45
|
+
* The opacity is applied via Tailwind's `/38` color-opacity modifier on the background
|
|
46
|
+
* color itself (`bg-surface/38`), not a `opacity-*` utility on the whole element — the
|
|
47
|
+
* real Compose Card only dims the container color, not its content/text, and a plain
|
|
48
|
+
* `opacity-*` class would incorrectly wash out the card's text/icons along with it.
|
|
49
|
+
*/
|
|
50
|
+
const containerClasses = computed(() => {
|
|
51
|
+
const map = props.disabled
|
|
52
|
+
? {
|
|
53
|
+
elevated: 'bg-surface/38 shadow-none',
|
|
54
|
+
filled: 'bg-surface-variant/38',
|
|
55
|
+
outlined: 'bg-surface border border-outline/12',
|
|
56
|
+
}
|
|
57
|
+
: {
|
|
58
|
+
elevated: 'bg-surface-container-low shadow-elevation-1',
|
|
59
|
+
filled: 'bg-surface-container-highest',
|
|
60
|
+
outlined: 'bg-surface border border-outline-variant',
|
|
61
|
+
}
|
|
62
|
+
return map[resolvedVariant.value]
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
* Hover/pressed elevation differ per variant — only `elevated` goes up to Level2 on hover
|
|
67
|
+
* and stays at Level1 while pressed; `filled`/`outlined` only reach Level1 on hover and
|
|
68
|
+
* drop back to flat (Level0/`shadow-none`) while pressed, they never match elevated's
|
|
69
|
+
* pressed-but-still-elevated Level1. Focus indicator also differs: elevated/filled get a
|
|
70
|
+
* `secondary` ring (FocusIndicatorColor) since they have no border to repurpose; outlined
|
|
71
|
+
* instead darkens its own border to `on-surface` (FocusOutlineColor) rather than adding a
|
|
72
|
+
* separate ring on top of the border it already has.
|
|
73
|
+
*/
|
|
74
|
+
const clickableClasses: Record<string, string> = {
|
|
75
|
+
elevated: 'hover:shadow-elevation-2 active:shadow-elevation-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-secondary',
|
|
76
|
+
filled: 'hover:shadow-elevation-1 active:shadow-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-secondary',
|
|
77
|
+
outlined: 'hover:shadow-elevation-1 active:shadow-none focus-visible:outline-none focus-visible:border-on-surface',
|
|
78
|
+
}
|
|
79
|
+
|
|
35
80
|
// State layer (8% hover / 12% active), same before:-pseudo pattern as MButton/MFab.
|
|
36
81
|
// Needed because the card has a real background to preserve underneath — unlike
|
|
37
82
|
// MListItem, a plain hover:bg-on-surface/8 here would replace the card's own tone.
|
|
38
|
-
const
|
|
39
|
-
'relative
|
|
83
|
+
const stateLayerClasses =
|
|
84
|
+
'relative ' +
|
|
40
85
|
"before:content-[''] before:pointer-events-none before:absolute before:inset-0 " +
|
|
41
86
|
'before:bg-on-surface before:opacity-0 before:transition-opacity before:duration-150 ' +
|
|
42
87
|
'hover:before:opacity-[0.08] active:before:opacity-[0.12]'
|
|
88
|
+
|
|
89
|
+
const isInteractive = computed(() => props.clickable && !props.disabled)
|
|
90
|
+
|
|
91
|
+
// A plain div has no native :disabled/keyboard behavior — role="button" + tabindex make it
|
|
92
|
+
// reachable and identifiable, and Enter/Space here replicate a real button's activation
|
|
93
|
+
// keys by just triggering a native click on the root, so whatever @click listener the
|
|
94
|
+
// consumer attached (via plain attribute fallthrough, since MCard doesn't declare an emit
|
|
95
|
+
// for this) fires exactly as it would for a mouse click, with no separate code path needed.
|
|
96
|
+
function onKeydown(event: KeyboardEvent) {
|
|
97
|
+
if (!isInteractive.value) return
|
|
98
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
99
|
+
event.preventDefault()
|
|
100
|
+
;(event.currentTarget as HTMLElement).click()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
43
103
|
</script>
|
|
44
104
|
|
|
45
105
|
<template>
|
|
46
106
|
<div
|
|
47
107
|
class="overflow-hidden rounded-md transition-shadow duration-150"
|
|
48
108
|
:class="[
|
|
49
|
-
|
|
50
|
-
|
|
109
|
+
containerClasses,
|
|
110
|
+
isInteractive ? ['cursor-pointer', clickableClasses[resolvedVariant], stateLayerClasses] : '',
|
|
111
|
+
disabled ? 'cursor-not-allowed pointer-events-none' : '',
|
|
51
112
|
]"
|
|
52
113
|
:style="{ '--field-bg': fieldBgByVariant[resolvedVariant] }"
|
|
114
|
+
:role="clickable ? 'button' : undefined"
|
|
115
|
+
:tabindex="isInteractive ? 0 : undefined"
|
|
116
|
+
:aria-disabled="clickable && disabled ? 'true' : undefined"
|
|
117
|
+
@keydown="onKeydown"
|
|
53
118
|
>
|
|
54
119
|
<!-- Optional header image -->
|
|
55
120
|
<div v-if="image || $slots.media" :class="['w-full overflow-hidden', imageHeight ?? 'h-48']">
|