@m3ui-vue/m3ui-vue 1.0.2 → 1.1.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 +666 -12
- package/dist/MMenuItem-BOkcVtEe.js +809 -0
- package/dist/MMenuItem-BOkcVtEe.js.map +1 -0
- package/dist/MSlider-BXsBv0ox.js +1402 -0
- package/dist/MSlider-BXsBv0ox.js.map +1 -0
- package/dist/MTextField-rML9jnXs.js +671 -0
- package/dist/MTextField-rML9jnXs.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBottomSheet.vue.d.ts +20 -1
- package/dist/components/MDialog.vue.d.ts +17 -8
- package/dist/components/MDragDropList.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +1 -1
- package/dist/components/MMap.vue.d.ts +74 -0
- package/dist/components/MMapBaseLayers.vue.d.ts +15 -0
- package/dist/components/MMapControl.vue.d.ts +40 -0
- package/dist/components/MMapFeatureInfo.vue.d.ts +25 -0
- package/dist/components/MMapFilter.vue.d.ts +19 -0
- package/dist/components/MMapGeoJson.vue.d.ts +34 -0
- package/dist/components/MMapHover.vue.d.ts +17 -0
- package/dist/components/MMapIdentify.vue.d.ts +37 -0
- package/dist/components/MMapLayers.vue.d.ts +31 -0
- package/dist/components/MMapMarker.vue.d.ts +45 -0
- package/dist/components/MMapMeasure.vue.d.ts +43 -0
- package/dist/components/MMapPopup.vue.d.ts +45 -0
- package/dist/components/MMapSearch.vue.d.ts +28 -0
- package/dist/components/MMenuItem.vue.d.ts +2 -2
- package/dist/components/MSeekBar.vue.d.ts +122 -0
- package/dist/components/MSplitButton.vue.d.ts +2 -2
- package/dist/components/_MMapAttribution.vue.d.ts +7 -0
- package/dist/components/_MMapLayerItem.vue.d.ts +25 -0
- package/dist/composables/_mapGeometry.d.ts +13 -0
- package/dist/composables/_mapPin.d.ts +5 -0
- package/dist/composables/_popupPosition.d.ts +12 -0
- package/dist/composables/_ssrState.d.ts +30 -0
- package/dist/composables/_storageKeys.d.ts +3 -0
- package/dist/composables/_useCalendarMonth.d.ts +24 -0
- package/dist/composables/_useEscapeStack.d.ts +3 -0
- package/dist/composables/_useScrollLock.d.ts +8 -0
- package/dist/composables/_useSheetMotion.d.ts +16 -1
- package/dist/composables/_useThemeTokens.d.ts +7 -0
- package/dist/composables/mapAdapters.d.ts +111 -0
- package/dist/composables/mapSearch.d.ts +31 -0
- package/dist/composables/themeInitScript.d.ts +4 -3
- package/dist/composables/useColorPalette.d.ts +173 -7
- package/dist/composables/useLocale.d.ts +38 -0
- package/dist/composables/useMap.d.ts +47 -0
- package/dist/composables/useMapFilter.d.ts +10 -0
- package/dist/composables/useMapLayers.d.ts +30 -0
- package/dist/composables/useTheme.d.ts +2 -1
- package/dist/index.d.ts +4 -1
- package/dist/locales/index.js +273 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7913 -8625
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +24 -0
- package/dist/map.js +2067 -0
- package/dist/map.js.map +1 -0
- package/dist/plugin.d.ts +18 -2
- package/dist/rich-text-editor.js +26 -25
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CuvWRZ1h.js → useLocale-CqQrhWFl.js} +40 -2
- package/dist/useLocale-CqQrhWFl.js.map +1 -0
- package/package.json +11 -2
- package/src/__tests__/MDialog.test.ts +30 -0
- package/src/__tests__/MFab.test.ts +52 -6
- package/src/__tests__/MMap.test.ts +422 -0
- package/src/__tests__/MMapLayers.test.ts +257 -0
- package/src/__tests__/MMapTools.test.ts +233 -0
- package/src/__tests__/MSeekBar.test.ts +170 -0
- package/src/__tests__/MTooltip.test.ts +110 -0
- package/src/__tests__/_fakeMaplibre.ts +161 -0
- package/src/__tests__/calendarMonth.test.ts +59 -0
- package/src/__tests__/hydration.test.ts +33 -0
- package/src/__tests__/pickerModals.test.ts +128 -0
- package/src/__tests__/popupPosition.test.ts +224 -0
- package/src/__tests__/scrollLock.test.ts +110 -0
- package/src/__tests__/sheets.test.ts +158 -0
- package/src/__tests__/ssr.test.ts +63 -1
- package/src/__tests__/ssrState.test.ts +155 -0
- package/src/__tests__/themeInitScript.test.ts +18 -0
- package/src/components/MAutocomplete.vue +2 -4
- package/src/components/MBottomSheet.vue +211 -13
- package/src/components/MCommandPalette.vue +4 -6
- package/src/components/MContextMenu.vue +19 -5
- package/src/components/MDatePicker.vue +29 -70
- package/src/components/MDatePickerModal.vue +116 -172
- package/src/components/MDateRangePicker.vue +29 -51
- package/src/components/MDateRangePickerModal.vue +84 -162
- package/src/components/MDialog.vue +87 -63
- package/src/components/MFab.vue +29 -7
- package/src/components/MIconButton.vue +1 -1
- package/src/components/MLightbox.vue +12 -5
- package/src/components/MMap.vue +568 -0
- package/src/components/MMapBaseLayers.vue +67 -0
- package/src/components/MMapControl.vue +175 -0
- package/src/components/MMapFeatureInfo.vue +41 -0
- package/src/components/MMapFilter.vue +80 -0
- package/src/components/MMapGeoJson.vue +136 -0
- package/src/components/MMapHover.vue +131 -0
- package/src/components/MMapIdentify.vue +104 -0
- package/src/components/MMapLayers.vue +111 -0
- package/src/components/MMapMarker.vue +109 -0
- package/src/components/MMapMeasure.vue +452 -0
- package/src/components/MMapPopup.vue +103 -0
- package/src/components/MMapSearch.vue +162 -0
- package/src/components/MMenu.vue +31 -12
- package/src/components/MMenuItem.vue +21 -4
- package/src/components/MMultiAutocomplete.vue +2 -4
- package/src/components/MMultiSelect.vue +2 -4
- package/src/components/MNavigationDrawer.vue +2 -8
- package/src/components/MNavigationRail.vue +2 -3
- package/src/components/MSearchBar.vue +2 -5
- package/src/components/MSeekBar.vue +593 -0
- package/src/components/MSelect.vue +2 -8
- package/src/components/MSplitButton.vue +23 -7
- package/src/components/MSpotlightSearch.vue +4 -6
- package/src/components/MTimePicker.vue +23 -6
- package/src/components/MTimePickerModal.vue +213 -226
- package/src/components/MTooltip.vue +99 -3
- package/src/components/_MMapAttribution.vue +81 -0
- package/src/components/_MMapLayerItem.vue +77 -0
- package/src/composables/_mapGeometry.ts +75 -0
- package/src/composables/_mapPin.ts +25 -0
- package/src/composables/_popupPosition.ts +39 -0
- package/src/composables/_ssrState.ts +80 -0
- package/src/composables/_storageKeys.ts +6 -0
- package/src/composables/_useCalendarMonth.ts +74 -0
- package/src/composables/_useEscapeStack.ts +33 -0
- package/src/composables/_useScrollLock.ts +41 -0
- package/src/composables/_useSheetMotion.ts +82 -20
- package/src/composables/_useThemeTokens.ts +42 -0
- package/src/composables/mapAdapters.ts +208 -0
- package/src/composables/mapSearch.ts +56 -0
- package/src/composables/themeInitScript.ts +6 -4
- package/src/composables/useColorPalette.ts +23 -9
- package/src/composables/useLocale.ts +78 -0
- package/src/composables/useMap.ts +98 -0
- package/src/composables/useMapFilter.ts +45 -0
- package/src/composables/useMapLayers.ts +124 -0
- package/src/composables/useTheme.ts +8 -3
- package/src/composables/useWindowSizeClass.ts +14 -5
- package/src/index.ts +4 -1
- package/src/locales/de.ts +39 -1
- package/src/locales/es.ts +39 -1
- package/src/locales/fr.ts +39 -1
- package/src/locales/ja.ts +39 -1
- package/src/locales/ko.ts +39 -1
- package/src/locales/pt.ts +39 -1
- package/src/locales/zh.ts +39 -1
- package/src/map.ts +32 -0
- package/src/plugin.ts +54 -3
- package/dist/MTextField-BPbFeI9M.js +0 -1368
- package/dist/MTextField-BPbFeI9M.js.map +0 -1
- package/dist/useLocale-CuvWRZ1h.js.map +0 -1
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { computed, ref, watch } from 'vue'
|
|
10
10
|
import MButton from './MButton.vue'
|
|
11
|
+
import MDialog from './MDialog.vue'
|
|
11
12
|
import MIconButton from './MIconButton.vue'
|
|
12
13
|
import { useLocale } from '../composables/useLocale'
|
|
14
|
+
import { isoDate as fmt, useCalendarMonth } from '../composables/_useCalendarMonth'
|
|
13
15
|
|
|
14
16
|
export interface DateRange {
|
|
15
17
|
start: string | null
|
|
@@ -62,74 +64,19 @@ watch(() => props.show, (open) => {
|
|
|
62
64
|
viewDate.value = props.modelValue?.start
|
|
63
65
|
? new Date(props.modelValue.start + 'T00:00:00')
|
|
64
66
|
: new Date()
|
|
65
|
-
document.addEventListener('keydown', onKeydown)
|
|
66
|
-
document.body.style.overflow = 'hidden'
|
|
67
|
-
} else {
|
|
68
|
-
document.removeEventListener('keydown', onKeydown)
|
|
69
|
-
document.body.style.overflow = ''
|
|
70
67
|
}
|
|
71
68
|
})
|
|
72
69
|
|
|
73
70
|
// ── Calendar logic ─────────────────────────────────────────────────
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const monthLabel = computed(() =>
|
|
80
|
-
new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value),
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
const calendarDays = computed(() => {
|
|
84
|
-
const y = viewDate.value.getFullYear()
|
|
85
|
-
const m = viewDate.value.getMonth()
|
|
86
|
-
const first = new Date(y, m, 1)
|
|
87
|
-
const startDay = (first.getDay() + 6) % 7
|
|
88
|
-
const daysInMonth = new Date(y, m + 1, 0).getDate()
|
|
89
|
-
const days: { date: number; current: boolean; iso: string; disabled: boolean }[] = []
|
|
90
|
-
|
|
91
|
-
const prevDays = new Date(y, m, 0).getDate()
|
|
92
|
-
for (let i = startDay - 1; i >= 0; i--) {
|
|
93
|
-
const d = prevDays - i
|
|
94
|
-
const iso = fmt(y, m - 1, d)
|
|
95
|
-
days.push({ date: d, current: false, iso, disabled: isOOR(iso) })
|
|
96
|
-
}
|
|
97
|
-
for (let d = 1; d <= daysInMonth; d++) {
|
|
98
|
-
const iso = fmt(y, m, d)
|
|
99
|
-
days.push({ date: d, current: true, iso, disabled: isOOR(iso) })
|
|
100
|
-
}
|
|
101
|
-
const remaining = 42 - days.length
|
|
102
|
-
for (let d = 1; d <= remaining; d++) {
|
|
103
|
-
const iso = fmt(y, m + 1, d)
|
|
104
|
-
days.push({ date: d, current: false, iso, disabled: isOOR(iso) })
|
|
105
|
-
}
|
|
106
|
-
return days
|
|
71
|
+
// Weekday names, the month's title and its six-week grid, shared with the other date pickers
|
|
72
|
+
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange: isOOR, prevMonth, nextMonth } = useCalendarMonth(viewDate, {
|
|
73
|
+
locale: () => resolvedLocale.value,
|
|
74
|
+
min: () => props.min,
|
|
75
|
+
max: () => props.max,
|
|
107
76
|
})
|
|
108
77
|
|
|
109
|
-
function fmt(y: number, m: number, d: number) {
|
|
110
|
-
const dt = new Date(y, m, d)
|
|
111
|
-
return `${dt.getFullYear()}-${String(dt.getMonth() + 1).padStart(2, '0')}-${String(dt.getDate()).padStart(2, '0')}`
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function isOOR(iso: string) {
|
|
115
|
-
if (props.min && iso < props.min) return true
|
|
116
|
-
if (props.max && iso > props.max) return true
|
|
117
|
-
return false
|
|
118
|
-
}
|
|
119
|
-
|
|
120
78
|
const todayIso = fmt(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())
|
|
121
79
|
|
|
122
|
-
function prevMonth() {
|
|
123
|
-
const d = new Date(viewDate.value)
|
|
124
|
-
d.setMonth(d.getMonth() - 1)
|
|
125
|
-
viewDate.value = d
|
|
126
|
-
}
|
|
127
|
-
function nextMonth() {
|
|
128
|
-
const d = new Date(viewDate.value)
|
|
129
|
-
d.setMonth(d.getMonth() + 1)
|
|
130
|
-
viewDate.value = d
|
|
131
|
-
}
|
|
132
|
-
|
|
133
80
|
function selectDay(day: typeof calendarDays.value[0]) {
|
|
134
81
|
if (day.disabled) return
|
|
135
82
|
if (picking.value === 'start') {
|
|
@@ -172,114 +119,89 @@ function confirm() {
|
|
|
172
119
|
}
|
|
173
120
|
}
|
|
174
121
|
|
|
175
|
-
|
|
122
|
+
// Escape or the scrim (MDialog) cancel, like the Cancel button
|
|
123
|
+
function onDialog(open: boolean) {
|
|
124
|
+
if (!open) cancel()
|
|
125
|
+
}
|
|
176
126
|
</script>
|
|
177
127
|
|
|
178
128
|
<template>
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
>
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
>
|
|
207
|
-
<p class="text-label-small text-on-surface-variant">{{ locale.pickEnd }}</p>
|
|
208
|
-
<p class="text-title-medium font-medium capitalize">{{ fmtDisplay(end) }}</p>
|
|
209
|
-
</div>
|
|
210
|
-
</div>
|
|
211
|
-
</div>
|
|
212
|
-
|
|
213
|
-
<div class="h-px bg-outline-variant" />
|
|
129
|
+
<!-- MDialog's bare box: scrim, Escape, scroll lock, the open/close animation and dialog semantics -->
|
|
130
|
+
<MDialog :model-value="show" bare max-width="360px" :title="title || locale.selectRange" @update:model-value="onDialog">
|
|
131
|
+
<!-- Header -->
|
|
132
|
+
<div class="px-6 pt-6 pb-4">
|
|
133
|
+
<p class="mb-3 text-label-large text-on-surface-variant">
|
|
134
|
+
{{ title || locale.selectRange }}
|
|
135
|
+
</p>
|
|
136
|
+
<div class="flex items-center gap-3">
|
|
137
|
+
<div
|
|
138
|
+
class="flex-1 rounded-lg px-3 py-2 text-center transition-colors"
|
|
139
|
+
:class="picking === 'start' ? 'bg-primary-container text-on-primary-container' : 'bg-surface-container-highest text-on-surface'"
|
|
140
|
+
@click="picking = 'start'"
|
|
141
|
+
>
|
|
142
|
+
<p class="text-label-small text-on-surface-variant">{{ locale.pickStart }}</p>
|
|
143
|
+
<p class="text-title-medium font-medium capitalize">{{ fmtDisplay(start) }}</p>
|
|
144
|
+
</div>
|
|
145
|
+
<span class="text-on-surface-variant">→</span>
|
|
146
|
+
<div
|
|
147
|
+
class="flex-1 rounded-lg px-3 py-2 text-center transition-colors"
|
|
148
|
+
:class="picking === 'end' ? 'bg-primary-container text-on-primary-container' : 'bg-surface-container-highest text-on-surface'"
|
|
149
|
+
@click="start && (picking = 'end')"
|
|
150
|
+
>
|
|
151
|
+
<p class="text-label-small text-on-surface-variant">{{ locale.pickEnd }}</p>
|
|
152
|
+
<p class="text-title-medium font-medium capitalize">{{ fmtDisplay(end) }}</p>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
214
156
|
|
|
215
|
-
|
|
216
|
-
<div class="px-4 pt-3 pb-2">
|
|
217
|
-
<div class="mb-2 flex items-center justify-between">
|
|
218
|
-
<MIconButton icon="chevron_left" :label="locale.previousMonth" :size="36" @click="prevMonth" />
|
|
219
|
-
<span class="text-title-small font-medium capitalize text-on-surface">{{ monthLabel }}</span>
|
|
220
|
-
<MIconButton icon="chevron_right" :label="locale.nextMonth" :size="36" @click="nextMonth" />
|
|
221
|
-
</div>
|
|
157
|
+
<div class="h-px bg-outline-variant" />
|
|
222
158
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
159
|
+
<!-- Calendar -->
|
|
160
|
+
<div class="px-4 pt-3 pb-2">
|
|
161
|
+
<div class="mb-2 flex items-center justify-between">
|
|
162
|
+
<MIconButton icon="chevron_left" :label="locale.previousMonth" :size="36" @click="prevMonth" />
|
|
163
|
+
<span class="text-title-small font-medium capitalize text-on-surface">{{ monthLabel }}</span>
|
|
164
|
+
<MIconButton icon="chevron_right" :label="locale.nextMonth" :size="36" @click="nextMonth" />
|
|
165
|
+
</div>
|
|
228
166
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
class="flex h-10 w-full items-center justify-center text-body-medium transition-colors duration-100"
|
|
235
|
-
:class="[
|
|
236
|
-
day.disabled
|
|
237
|
-
? 'cursor-not-allowed text-on-surface/25 rounded-full'
|
|
238
|
-
: day.iso === start || day.iso === end
|
|
239
|
-
? 'bg-primary text-on-primary rounded-full'
|
|
240
|
-
: isInRange(day.iso)
|
|
241
|
-
? 'bg-primary/12 text-on-surface cursor-pointer'
|
|
242
|
-
: day.iso === todayIso
|
|
243
|
-
? 'border border-primary text-primary rounded-full cursor-pointer hover:bg-primary/8'
|
|
244
|
-
: day.current
|
|
245
|
-
? 'cursor-pointer text-on-surface rounded-full hover:bg-on-surface/8'
|
|
246
|
-
: 'cursor-pointer text-on-surface-variant/50 rounded-full hover:bg-on-surface/4',
|
|
247
|
-
]"
|
|
248
|
-
:disabled="day.disabled"
|
|
249
|
-
@mouseenter="picking === 'end' && (hovered = day.iso)"
|
|
250
|
-
@click="selectDay(day)"
|
|
251
|
-
>
|
|
252
|
-
{{ day.date }}
|
|
253
|
-
</button>
|
|
254
|
-
</div>
|
|
255
|
-
</div>
|
|
167
|
+
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
168
|
+
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
|
|
169
|
+
{{ wd }}
|
|
170
|
+
</span>
|
|
171
|
+
</div>
|
|
256
172
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
173
|
+
<div class="grid grid-cols-7 gap-0.5">
|
|
174
|
+
<button
|
|
175
|
+
v-for="(day, i) in calendarDays"
|
|
176
|
+
:key="i"
|
|
177
|
+
type="button"
|
|
178
|
+
class="flex h-10 w-full items-center justify-center text-body-medium transition-colors duration-100"
|
|
179
|
+
:class="[
|
|
180
|
+
day.disabled
|
|
181
|
+
? 'cursor-not-allowed text-on-surface/25 rounded-full'
|
|
182
|
+
: day.iso === start || day.iso === end
|
|
183
|
+
? 'bg-primary text-on-primary rounded-full'
|
|
184
|
+
: isInRange(day.iso)
|
|
185
|
+
? 'bg-primary/12 text-on-surface cursor-pointer'
|
|
186
|
+
: day.iso === todayIso
|
|
187
|
+
? 'border border-primary text-primary rounded-full cursor-pointer hover:bg-primary/8'
|
|
188
|
+
: day.current
|
|
189
|
+
? 'cursor-pointer text-on-surface rounded-full hover:bg-on-surface/8'
|
|
190
|
+
: 'cursor-pointer text-on-surface-variant/50 rounded-full hover:bg-on-surface/4',
|
|
191
|
+
]"
|
|
192
|
+
:disabled="day.disabled"
|
|
193
|
+
@mouseenter="picking === 'end' && (hovered = day.iso)"
|
|
194
|
+
@click="selectDay(day)"
|
|
195
|
+
>
|
|
196
|
+
{{ day.date }}
|
|
197
|
+
</button>
|
|
263
198
|
</div>
|
|
264
|
-
</
|
|
265
|
-
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<!-- Footer -->
|
|
202
|
+
<div class="flex justify-end gap-2 px-6 py-4">
|
|
203
|
+
<MButton variant="text" @click="cancel">{{ locale.cancel }}</MButton>
|
|
204
|
+
<MButton variant="text" :disabled="!start || !end" @click="confirm">{{ locale.ok }}</MButton>
|
|
205
|
+
</div>
|
|
206
|
+
</MDialog>
|
|
266
207
|
</template>
|
|
267
|
-
|
|
268
|
-
<style scoped>
|
|
269
|
-
.m3-drp-modal-enter-active,
|
|
270
|
-
.m3-drp-modal-leave-active {
|
|
271
|
-
transition: opacity 0.15s ease;
|
|
272
|
-
}
|
|
273
|
-
.m3-drp-modal-enter-from,
|
|
274
|
-
.m3-drp-modal-leave-to {
|
|
275
|
-
opacity: 0;
|
|
276
|
-
}
|
|
277
|
-
.m3-drp-modal-enter-active .drp-box,
|
|
278
|
-
.m3-drp-modal-leave-active .drp-box {
|
|
279
|
-
transition: transform 0.15s ease;
|
|
280
|
-
}
|
|
281
|
-
.m3-drp-modal-enter-from .drp-box,
|
|
282
|
-
.m3-drp-modal-leave-to .drp-box {
|
|
283
|
-
transform: scale(0.95);
|
|
284
|
-
}
|
|
285
|
-
</style>
|
|
@@ -6,13 +6,16 @@
|
|
|
6
6
|
* @slot icon M3 AlertDialog's optional icon (Secondary color, 24dp expected). Its presence also centers the
|
|
7
7
|
* title, per spec.
|
|
8
8
|
* @slot title Overrides the title prop with custom markup
|
|
9
|
-
* @slot default Dialog body content — scrolls independently when taller than maxHeight
|
|
9
|
+
* @slot default Dialog body content — scrolls independently when taller than maxHeight. With `bare`, the whole
|
|
10
|
+
* dialog: it fills the box (no title, padding, close button or actions row)
|
|
10
11
|
* @slot actions Row of action buttons — wraps to a new line instead of overflowing when labels are long
|
|
11
12
|
* @event update:modelValue Emitted when the dialog should open/close — powers v-model
|
|
12
13
|
*/
|
|
13
|
-
import { computed, nextTick, onUnmounted, ref, watch } from 'vue'
|
|
14
|
+
import { computed, nextTick, onUnmounted, ref, useId, watch } from 'vue'
|
|
14
15
|
import MIconButton from './MIconButton.vue'
|
|
15
16
|
import { useLocale } from '../composables/useLocale'
|
|
17
|
+
import { useScrollLock } from '../composables/_useScrollLock'
|
|
18
|
+
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
16
19
|
|
|
17
20
|
const props = withDefaults(
|
|
18
21
|
defineProps<{
|
|
@@ -45,6 +48,12 @@ const props = withDefaults(
|
|
|
45
48
|
// deliberate library extension on top of the spec, kept opt-out (default `true`, matching
|
|
46
49
|
// this component's existing behavior) rather than added unconditionally.
|
|
47
50
|
closable?: boolean
|
|
51
|
+
/**
|
|
52
|
+
* Just the dialog's box (surface, shape, elevation), scrim, Escape, scroll lock and animation, with the default
|
|
53
|
+
* slot filling it: no title row, padding, close button or actions. For dialogs that draw everything themselves
|
|
54
|
+
* (the date and time pickers). `title` then only names it for assistive technology
|
|
55
|
+
*/
|
|
56
|
+
bare?: boolean
|
|
48
57
|
}>(),
|
|
49
58
|
{
|
|
50
59
|
// AlertDialogDefaults.DialogMaxWidth = 560dp
|
|
@@ -53,6 +62,7 @@ const props = withDefaults(
|
|
|
53
62
|
persistent: false,
|
|
54
63
|
fullscreen: false,
|
|
55
64
|
closable: true,
|
|
65
|
+
bare: false,
|
|
56
66
|
},
|
|
57
67
|
)
|
|
58
68
|
|
|
@@ -74,9 +84,6 @@ function close() {
|
|
|
74
84
|
emit('update:modelValue', false)
|
|
75
85
|
}
|
|
76
86
|
|
|
77
|
-
function onKeydown(event: KeyboardEvent) {
|
|
78
|
-
if (event.key === 'Escape') close()
|
|
79
|
-
}
|
|
80
87
|
|
|
81
88
|
// M3's dialog anatomy lists an optional divider between the (scrollable) content and the
|
|
82
89
|
// actions row — Compose's own AlertDialog.kt has no built-in implementation of it at all, so
|
|
@@ -92,12 +99,16 @@ function updateDividerVisibility() {
|
|
|
92
99
|
showDivider.value = el.scrollHeight - el.scrollTop - el.clientHeight > 1
|
|
93
100
|
}
|
|
94
101
|
|
|
102
|
+
useScrollLock(() => props.modelValue)
|
|
103
|
+
// Escape closes the dialog on top only, when several are stacked
|
|
104
|
+
useEscapeStack(() => props.modelValue, close)
|
|
105
|
+
|
|
106
|
+
const titleId = `m3-dialog-${useId()}`
|
|
107
|
+
|
|
95
108
|
watch(
|
|
96
109
|
() => props.modelValue,
|
|
97
110
|
async (open) => {
|
|
98
111
|
if (open) {
|
|
99
|
-
document.addEventListener('keydown', onKeydown)
|
|
100
|
-
document.body.style.overflow = 'hidden'
|
|
101
112
|
await nextTick()
|
|
102
113
|
updateDividerVisibility()
|
|
103
114
|
// Observing contentEl alone only catches viewport-driven resizes (e.g. window resize
|
|
@@ -109,16 +120,14 @@ watch(
|
|
|
109
120
|
if (contentEl.value) resizeObserver.observe(contentEl.value)
|
|
110
121
|
if (contentInnerEl.value) resizeObserver.observe(contentInnerEl.value)
|
|
111
122
|
} else {
|
|
112
|
-
document.removeEventListener('keydown', onKeydown)
|
|
113
|
-
document.body.style.overflow = ''
|
|
114
123
|
resizeObserver?.disconnect()
|
|
115
124
|
resizeObserver = undefined
|
|
116
125
|
}
|
|
117
126
|
},
|
|
127
|
+
{ immediate: true },
|
|
118
128
|
)
|
|
119
129
|
|
|
120
130
|
onUnmounted(() => {
|
|
121
|
-
document.removeEventListener('keydown', onKeydown)
|
|
122
131
|
resizeObserver?.disconnect()
|
|
123
132
|
})
|
|
124
133
|
</script>
|
|
@@ -137,64 +146,76 @@ onUnmounted(() => {
|
|
|
137
146
|
class="dialog-box flex min-w-[280px] w-full flex-col rounded-xl bg-surface-container-high shadow-elevation-3"
|
|
138
147
|
:class="sizeClasses"
|
|
139
148
|
:style="sizeStyle"
|
|
149
|
+
role="dialog"
|
|
150
|
+
aria-modal="true"
|
|
151
|
+
:aria-labelledby="!bare && ($slots.title || title) ? titleId : undefined"
|
|
152
|
+
:aria-label="bare ? title : undefined"
|
|
140
153
|
>
|
|
141
|
-
<!--
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
the right dp value: title-to-body is 16dp (8px here + 8px there), body-to-actions
|
|
148
|
-
is 24dp (8px here + 16px there), and the outermost edges (top of title, bottom of
|
|
149
|
-
whichever section is last) are the full 24dp on their own.
|
|
150
|
-
-->
|
|
151
|
-
<div class="relative px-6 pt-6 pb-2">
|
|
152
|
-
<!--
|
|
153
|
-
Wrapped in a plain div rather than passing `absolute right-4 top-4` straight to
|
|
154
|
-
MIconButton: its root already carries its own `relative` (for the ripple span),
|
|
155
|
-
and Tailwind resolves conflicting position utilities by source order in the
|
|
156
|
-
compiled CSS, not by order in the class attribute — so an external `absolute`
|
|
157
|
-
can silently lose to that internal `relative` instead of overriding it.
|
|
158
|
-
-->
|
|
159
|
-
<div v-if="closable && !persistent" class="absolute right-4 top-4">
|
|
160
|
-
<MIconButton icon="close" :label="closeLabel ?? locale.close" @click="close" />
|
|
161
|
-
</div>
|
|
154
|
+
<!-- Bare: the content is the whole dialog (scrolling if taller than maxHeight), clipped to the box's
|
|
155
|
+
corners (rounded-[inherit]) so content reaching its edges, like a full-bleed image, keeps them -->
|
|
156
|
+
<div v-if="bare" class="min-h-0 overflow-y-auto rounded-[inherit]">
|
|
157
|
+
<slot />
|
|
158
|
+
</div>
|
|
159
|
+
<template v-else>
|
|
162
160
|
<!--
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
AlertDialogDefaults.dialogPadding is 24dp on all four sides of the whole content
|
|
162
|
+
column, with per-element bottom paddings (IconPadding/TitlePadding/textPadding)
|
|
163
|
+
providing the gaps BETWEEN elements — not a single wrapping padding, since this
|
|
164
|
+
template uses separate divs per section instead of one padded Column. Each
|
|
165
|
+
section's own top/bottom classes are chosen so the combined gaps still land on
|
|
166
|
+
the right dp value: title-to-body is 16dp (8px here + 8px there), body-to-actions
|
|
167
|
+
is 24dp (8px here + 16px there), and the outermost edges (top of title, bottom of
|
|
168
|
+
whichever section is last) are the full 24dp on their own.
|
|
168
169
|
-->
|
|
169
|
-
<div
|
|
170
|
-
|
|
170
|
+
<div class="relative px-6 pt-6 pb-2">
|
|
171
|
+
<!--
|
|
172
|
+
Wrapped in a plain div rather than passing `absolute right-4 top-4` straight to
|
|
173
|
+
MIconButton: its root already carries its own `relative` (for the ripple span),
|
|
174
|
+
and Tailwind resolves conflicting position utilities by source order in the
|
|
175
|
+
compiled CSS, not by order in the class attribute — so an external `absolute`
|
|
176
|
+
can silently lose to that internal `relative` instead of overriding it.
|
|
177
|
+
-->
|
|
178
|
+
<div v-if="closable && !persistent" class="absolute right-4 top-4">
|
|
179
|
+
<MIconButton icon="close" :label="closeLabel ?? locale.close" @click="close" />
|
|
180
|
+
</div>
|
|
181
|
+
<!--
|
|
182
|
+
Icon slot: M3 AlertDialog's optional `icon` param (IconColor=Secondary,
|
|
183
|
+
IconSize=24dp expected from the slot content, IconPadding bottom=16dp below it),
|
|
184
|
+
which per spec also centers the title ("Align the title to the center when an
|
|
185
|
+
icon is present") — reserving `pr-10` on the title only when the close button is
|
|
186
|
+
also showing, so a centered title doesn't collide with it.
|
|
187
|
+
-->
|
|
188
|
+
<div v-if="$slots.icon" class="mb-4 flex justify-center text-secondary">
|
|
189
|
+
<slot name="icon" />
|
|
190
|
+
</div>
|
|
191
|
+
<h2
|
|
192
|
+
:id="titleId"
|
|
193
|
+
class="text-headline-small text-on-surface"
|
|
194
|
+
:class="[
|
|
195
|
+
$slots.icon ? 'text-center' : 'text-left',
|
|
196
|
+
closable && !persistent ? ($slots.icon ? 'px-10' : 'pr-10') : '',
|
|
197
|
+
]"
|
|
198
|
+
>
|
|
199
|
+
<slot name="title">{{ title }}</slot>
|
|
200
|
+
</h2>
|
|
171
201
|
</div>
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
]"
|
|
202
|
+
<div
|
|
203
|
+
ref="contentEl"
|
|
204
|
+
class="overflow-y-auto px-6 pt-2 text-body-medium text-on-surface-variant"
|
|
205
|
+
:class="$slots.actions ? 'pb-2' : 'pb-6'"
|
|
206
|
+
@scroll="updateDividerVisibility"
|
|
178
207
|
>
|
|
179
|
-
<
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
<div
|
|
183
|
-
ref="contentEl"
|
|
184
|
-
class="overflow-y-auto px-6 pt-2 text-body-medium text-on-surface-variant"
|
|
185
|
-
:class="$slots.actions ? 'pb-2' : 'pb-6'"
|
|
186
|
-
@scroll="updateDividerVisibility"
|
|
187
|
-
>
|
|
188
|
-
<div ref="contentInnerEl">
|
|
189
|
-
<slot />
|
|
208
|
+
<div ref="contentInnerEl">
|
|
209
|
+
<slot />
|
|
210
|
+
</div>
|
|
190
211
|
</div>
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
</
|
|
212
|
+
<!-- Divider: M3 dialog anatomy's optional divider, shown only while the content has more to scroll to -->
|
|
213
|
+
<div v-if="showDivider && $slots.actions" class="shrink-0 border-t border-outline-variant" />
|
|
214
|
+
<!-- flex-wrap approximates AlertDialogFlowRow: buttons wrap to a new line instead of overflowing when labels are too long to fit on one -->
|
|
215
|
+
<div v-if="$slots.actions" class="flex flex-wrap justify-end gap-2 px-6 pt-4 pb-6">
|
|
216
|
+
<slot name="actions" />
|
|
217
|
+
</div>
|
|
218
|
+
</template>
|
|
198
219
|
</div>
|
|
199
220
|
</div>
|
|
200
221
|
</Transition>
|
|
@@ -204,10 +225,13 @@ onUnmounted(() => {
|
|
|
204
225
|
<div
|
|
205
226
|
v-if="modelValue"
|
|
206
227
|
class="dialog-fs fixed inset-0 z-50 flex flex-col bg-surface"
|
|
228
|
+
role="dialog"
|
|
229
|
+
aria-modal="true"
|
|
230
|
+
:aria-labelledby="$slots.title || title ? titleId : undefined"
|
|
207
231
|
>
|
|
208
232
|
<div class="flex h-14 shrink-0 items-center gap-2 px-2">
|
|
209
233
|
<MIconButton v-if="!persistent" icon="close" :label="closeLabel ?? locale.close" @click="close" />
|
|
210
|
-
<h2 class="flex-1 text-title-large font-medium text-on-surface">
|
|
234
|
+
<h2 :id="titleId" class="flex-1 text-title-large font-medium text-on-surface">
|
|
211
235
|
<slot name="title">{{ title }}</slot>
|
|
212
236
|
</h2>
|
|
213
237
|
<div v-if="$slots.actions" class="flex items-center gap-2">
|
package/src/components/MFab.vue
CHANGED
|
@@ -113,10 +113,11 @@ const colorMap: Record<string, string> = {
|
|
|
113
113
|
// minimum width = height, MediumExtendedFabIconPadding/LargeExtendedFabIconPadding (12/16dp, the tokens'
|
|
114
114
|
// IconLabelSpace is marked incorrect there).
|
|
115
115
|
const EXTENDED = {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
// lead: the box's start padding (its pl-/px- class)
|
|
117
|
+
regular: { px: 56, icon: 24, lead: 16, gap: 'pl-3', box: 'h-14 min-w-20 rounded-2xl pl-4 pr-5', text: 'text-label-large font-medium' },
|
|
118
|
+
small: { px: 56, icon: 24, lead: 16, gap: 'pl-2', box: 'h-14 min-w-14 rounded-2xl px-4', text: 'text-title-medium font-medium' },
|
|
119
|
+
medium: { px: 80, icon: 28, lead: 26, gap: 'pl-3', box: 'h-20 min-w-20 rounded-lg-increased px-[26px]', text: 'text-title-large' },
|
|
120
|
+
large: { px: 96, icon: 32, lead: 28, gap: 'pl-4', box: 'h-24 min-w-24 rounded-xl px-7', text: 'text-headline-small' },
|
|
120
121
|
} as const
|
|
121
122
|
const extended = computed(() => (props.label ? EXTENDED[props.size] : null))
|
|
122
123
|
|
|
@@ -152,7 +153,23 @@ const fabPx = computed(() => {
|
|
|
152
153
|
|
|
153
154
|
// Collapsing an extended FAB: the width lerps from the square (the minimum width) to the full width on
|
|
154
155
|
// FastSpatial, the label fades on FastEffects, and it leaves the layout once fully collapsed.
|
|
156
|
+
// Collapsed, the icon sits centered like a plain FAB's. Compose keeps the start padding instead, which only centers it
|
|
157
|
+
// where padding + icon + padding fills the square: the large size's 28 + 32 + 28 leaves it 4dp off center (a
|
|
158
|
+
// deliberate departure), so the start padding lerps to the centered one with the width.
|
|
159
|
+
const collapsedLead = (e: (typeof EXTENDED)[keyof typeof EXTENDED]) => (e.px - e.icon) / 2
|
|
155
160
|
const fabButton = ref<HTMLElement | { $el: HTMLElement }>()
|
|
161
|
+
// An extended FAB that starts collapsed renders collapsed (server-side rendering: before the springs below run).
|
|
162
|
+
// Constant objects: Vue applies a binding again only when its value changes, so these never undo the springs'
|
|
163
|
+
// writes on a later render
|
|
164
|
+
const startCollapsed = !!extended.value && !props.expanded
|
|
165
|
+
const initialButtonStyle = startCollapsed
|
|
166
|
+
? {
|
|
167
|
+
width: `${extended.value!.px}px`,
|
|
168
|
+
minWidth: '0',
|
|
169
|
+
...(collapsedLead(extended.value!) !== extended.value!.lead && { paddingLeft: `${collapsedLead(extended.value!)}px` }),
|
|
170
|
+
}
|
|
171
|
+
: undefined
|
|
172
|
+
const initialLabelStyle = startCollapsed ? { display: 'none', opacity: '0' } : undefined
|
|
156
173
|
const labelEl = ref<HTMLElement>()
|
|
157
174
|
const buttonEl = () => (fabButton.value instanceof HTMLElement ? fabButton.value : fabButton.value?.$el)
|
|
158
175
|
|
|
@@ -164,11 +181,15 @@ useSpring(
|
|
|
164
181
|
if (labelEl.value) labelEl.value.style.display = p <= 0 && !props.expanded ? 'none' : ''
|
|
165
182
|
el.style.width = ''
|
|
166
183
|
el.style.minWidth = ''
|
|
184
|
+
el.style.paddingLeft = ''
|
|
167
185
|
if (p >= 1 && props.expanded) return
|
|
168
186
|
const full = el.offsetWidth
|
|
169
|
-
const min = extended.value
|
|
187
|
+
const { px: min, lead } = extended.value
|
|
188
|
+
const t = Math.min(1, Math.max(0, p))
|
|
170
189
|
el.style.minWidth = '0'
|
|
171
190
|
el.style.width = `${min + (full - min) * Math.max(0, p)}px`
|
|
191
|
+
const centered = collapsedLead(extended.value)
|
|
192
|
+
if (centered !== lead) el.style.paddingLeft = `${centered + (lead - centered) * t}px`
|
|
172
193
|
},
|
|
173
194
|
FAST_SPATIAL,
|
|
174
195
|
)
|
|
@@ -348,6 +369,7 @@ onUnmounted(() => {
|
|
|
348
369
|
:class="[colorMap[color], fabSizeClasses, extended ? 'justify-start' : 'justify-center', inBottomAppBar ? '' : 'shadow-elevation-3 hover:shadow-elevation-4 active:shadow-elevation-3']"
|
|
349
370
|
:disabled="disabled"
|
|
350
371
|
:aria-label="label && !expanded ? label : undefined"
|
|
372
|
+
:style="initialButtonStyle"
|
|
351
373
|
v-ripple="{ disabled, color: rippleColor }"
|
|
352
374
|
@click="handleFabClick"
|
|
353
375
|
>
|
|
@@ -362,8 +384,8 @@ onUnmounted(() => {
|
|
|
362
384
|
v-if="extended"
|
|
363
385
|
ref="labelEl"
|
|
364
386
|
class="shrink-0 whitespace-nowrap"
|
|
365
|
-
:class="extended.text"
|
|
366
|
-
:style="
|
|
387
|
+
:class="[extended.text, extended.gap]"
|
|
388
|
+
:style="initialLabelStyle"
|
|
367
389
|
>{{ label }}</span>
|
|
368
390
|
</component>
|
|
369
391
|
</div>
|
|
@@ -14,7 +14,7 @@ const props = withDefaults(
|
|
|
14
14
|
defineProps<{
|
|
15
15
|
/** Material Symbol icon name */
|
|
16
16
|
icon: string
|
|
17
|
-
/** Accessible label (aria-label
|
|
17
|
+
/** Accessible label (its aria-label; no visible tooltip: wrap it in MTooltip for one) */
|
|
18
18
|
label?: string
|
|
19
19
|
/** Visual style */
|
|
20
20
|
variant?: 'standard' | 'filled' | 'tonal' | 'outlined'
|