@m3ui-vue/m3ui-vue 1.4.1 → 1.4.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 +251 -9
- package/dist/{MButton-DQMTIlaV.js → MButton-D7M324r9.js} +2 -2
- package/dist/{MButton-DQMTIlaV.js.map → MButton-D7M324r9.js.map} +1 -1
- package/dist/{MDialog-cdgapGfZ.js → MDialog-DuOnNF9s.js} +2 -2
- package/dist/{MDialog-cdgapGfZ.js.map → MDialog-DuOnNF9s.js.map} +1 -1
- package/dist/{MListItem-ZkSGIIrb.js → MListItem-Bb84X6ex.js} +144 -120
- package/dist/{MListItem-ZkSGIIrb.js.map → MListItem-Bb84X6ex.js.map} +1 -1
- package/dist/{MLoadingIndicator-U6_oGx8z.js → MLoadingIndicator-BUGRo2Tu.js} +2 -2
- package/dist/{MLoadingIndicator-U6_oGx8z.js.map → MLoadingIndicator-BUGRo2Tu.js.map} +1 -1
- package/dist/{MSeekBar-DTZVizZg.js → MSeekBar-BQUvUqb9.js} +2 -2
- package/dist/{MSeekBar-DTZVizZg.js.map → MSeekBar-BQUvUqb9.js.map} +1 -1
- package/dist/{MSlider-CqJkEYRZ.js → MSlider-SFdjE1Hy.js} +2 -2
- package/dist/{MSlider-CqJkEYRZ.js.map → MSlider-SFdjE1Hy.js.map} +1 -1
- package/dist/{MSpinner-Btgc-0nb.js → MSpinner-DKGNN64_.js} +2 -2
- package/dist/{MSpinner-Btgc-0nb.js.map → MSpinner-DKGNN64_.js.map} +1 -1
- package/dist/{MTextField-B6M0gJEO.js → MTextField-Utsef6Kk.js} +2 -2
- package/dist/{MTextField-B6M0gJEO.js.map → MTextField-Utsef6Kk.js.map} +1 -1
- package/dist/{MTooltip-Dspji4XG.js → MTooltip-BhTFQ9Z2.js} +4 -4
- package/dist/{MTooltip-Dspji4XG.js.map → MTooltip-BhTFQ9Z2.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAvailabilityCalendar.vue.d.ts +1 -1
- package/dist/components/MCalendarHeatmap.vue.d.ts +120 -0
- package/dist/components/MDatePicker.vue.d.ts +5 -0
- package/dist/components/MDatePickerModal.vue.d.ts +5 -0
- package/dist/components/MDateRangePicker.vue.d.ts +5 -0
- package/dist/components/MDateRangePickerModal.vue.d.ts +5 -0
- package/dist/components/MLightbox.vue.d.ts +1 -1
- package/dist/components/MListItem.vue.d.ts +10 -6
- package/dist/components/MMeterGroup.vue.d.ts +98 -0
- package/dist/components/MPhoneInput.vue.d.ts +72 -0
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MTreeTable.vue.d.ts +1 -1
- package/dist/components/MTypewriter.vue.d.ts +57 -0
- package/dist/components/MVideoPlayer.vue.d.ts +1 -1
- package/dist/components/_MMonthYearButton.vue.d.ts +16 -0
- package/dist/components/_MYearGrid.vue.d.ts +19 -0
- package/dist/composables/_useCalendarMonth.d.ts +7 -0
- package/dist/composables/phoneNumber.d.ts +39 -0
- package/dist/composables/useLocale.d.ts +18 -0
- package/dist/data/phone-countries.d.ts +2 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/locales/index.js +63 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +3662 -2028
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +5 -5
- package/dist/media.js +4 -4
- package/dist/pdf.js +4 -4
- package/dist/rich-text-editor.js +4 -4
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DLKJIRFi.js → useLocale-B8YKWg-H.js} +10 -1
- package/dist/useLocale-B8YKWg-H.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MCalendarHeatmap.test.ts +79 -0
- package/src/__tests__/MListItemNestedControl.test.ts +88 -0
- package/src/__tests__/MMeterGroup.test.ts +43 -0
- package/src/__tests__/MPhoneInput.test.ts +97 -0
- package/src/__tests__/MTabs.test.ts +100 -2
- package/src/__tests__/MTypewriter.test.ts +50 -0
- package/src/__tests__/calendarMonth.test.ts +104 -0
- package/src/__tests__/ssr.test.ts +4 -0
- package/src/components/MCalendarHeatmap.vue +349 -0
- package/src/components/MDatePicker.vue +74 -34
- package/src/components/MDatePickerModal.vue +79 -36
- package/src/components/MDateRangePicker.vue +73 -33
- package/src/components/MDateRangePickerModal.vue +75 -35
- package/src/components/MListItem.vue +54 -8
- package/src/components/MMeterGroup.vue +196 -0
- package/src/components/MPhoneInput.vue +480 -0
- package/src/components/MTabs.vue +33 -6
- package/src/components/MTypewriter.vue +195 -0
- package/src/components/_MMonthYearButton.vue +36 -0
- package/src/components/_MYearGrid.vue +106 -0
- package/src/composables/_useCalendarMonth.ts +32 -2
- package/src/composables/phoneNumber.ts +137 -0
- package/src/composables/useLocale.ts +27 -0
- package/src/data/phone-countries.ts +62 -0
- package/src/index.ts +8 -0
- package/src/locales/de.ts +9 -0
- package/src/locales/es.ts +9 -0
- package/src/locales/fr.ts +9 -0
- package/src/locales/ja.ts +9 -0
- package/src/locales/ko.ts +9 -0
- package/src/locales/pt.ts +9 -0
- package/src/locales/zh.ts +9 -0
- package/dist/useLocale-DLKJIRFi.js.map +0 -1
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
8
8
|
import MIcon from './MIcon.vue'
|
|
9
9
|
import MIconButton from './MIconButton.vue'
|
|
10
|
+
import MMonthYearButton from './_MMonthYearButton.vue'
|
|
11
|
+
import MYearGrid from './_MYearGrid.vue'
|
|
10
12
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
11
13
|
import { useLocale } from '../composables/useLocale'
|
|
12
14
|
import { POPUP_MARGIN, dropdownX, fitPopup } from '../composables/_popupPosition'
|
|
@@ -28,6 +30,11 @@ const props = defineProps<{
|
|
|
28
30
|
min?: string
|
|
29
31
|
/** Maximum date (YYYY-MM-DD) */
|
|
30
32
|
max?: string
|
|
33
|
+
/**
|
|
34
|
+
* First and last year the year grid (opened from the month's title) offers, as `[from, to]`; the years min/max
|
|
35
|
+
* leave no day in are disabled. Default 1900–2100, as Compose's DatePickerDefaults.YearRange
|
|
36
|
+
*/
|
|
37
|
+
yearRange?: [number, number]
|
|
31
38
|
/** Disables the picker */
|
|
32
39
|
disabled?: boolean
|
|
33
40
|
/** Error state */
|
|
@@ -78,12 +85,25 @@ watch(() => props.modelValue.start, (v) => {
|
|
|
78
85
|
})
|
|
79
86
|
|
|
80
87
|
// Weekday names, the month's title and its six-week grid, shared with the other date pickers
|
|
81
|
-
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange: isOOR, prevMonth, nextMonth } = useCalendarMonth(viewDate, {
|
|
88
|
+
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange: isOOR, prevMonth, nextMonth, years, showYear } = useCalendarMonth(viewDate, {
|
|
82
89
|
locale: () => resolvedLocale.value,
|
|
83
90
|
min: () => props.min,
|
|
84
91
|
max: () => props.max,
|
|
92
|
+
yearRange: () => props.yearRange,
|
|
85
93
|
})
|
|
86
94
|
|
|
95
|
+
// Compose's YearPicker: the month's title is a menu button that lays a 3-column grid of years over the days; a
|
|
96
|
+
// year shows that year with the same month and goes back to the days
|
|
97
|
+
const yearPicker = ref(false)
|
|
98
|
+
const yearToggle = ref<InstanceType<typeof MMonthYearButton>>()
|
|
99
|
+
watch(open, () => { yearPicker.value = false })
|
|
100
|
+
|
|
101
|
+
function pickYear(year: number) {
|
|
102
|
+
showYear(year)
|
|
103
|
+
yearPicker.value = false
|
|
104
|
+
yearToggle.value?.focus()
|
|
105
|
+
}
|
|
106
|
+
|
|
87
107
|
const todayIso = fmt(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())
|
|
88
108
|
|
|
89
109
|
function selectDay(day: typeof calendarDays.value[0]) {
|
|
@@ -234,41 +254,61 @@ onUnmounted(() => {
|
|
|
234
254
|
{{ picking === 'start' ? (pickStartText ?? localeStrings.pickStart) : (pickEndText ?? localeStrings.pickEnd) }}
|
|
235
255
|
</p>
|
|
236
256
|
|
|
237
|
-
<div class="mb-3 flex items-center justify-between">
|
|
238
|
-
<
|
|
239
|
-
|
|
240
|
-
|
|
257
|
+
<div class="mb-3 flex h-10 items-center justify-between">
|
|
258
|
+
<MMonthYearButton
|
|
259
|
+
ref="yearToggle"
|
|
260
|
+
:label="monthLabel"
|
|
261
|
+
:expanded="yearPicker"
|
|
262
|
+
:action="yearPicker ? localeStrings.dateSwitchToDay : localeStrings.dateSwitchToYear"
|
|
263
|
+
@toggle="yearPicker = !yearPicker"
|
|
264
|
+
/>
|
|
265
|
+
<div v-if="!yearPicker" class="flex">
|
|
266
|
+
<MIconButton icon="chevron_left" :label="prevMonthLabel ?? localeStrings.previousMonth" :size="36" @click="prevMonth" />
|
|
267
|
+
<MIconButton icon="chevron_right" :label="nextMonthLabel ?? localeStrings.nextMonth" :size="36" @click="nextMonth" />
|
|
268
|
+
</div>
|
|
241
269
|
</div>
|
|
242
270
|
|
|
243
|
-
<div class="
|
|
244
|
-
<
|
|
245
|
-
|
|
271
|
+
<div class="relative">
|
|
272
|
+
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
273
|
+
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">{{ wd }}</span>
|
|
274
|
+
</div>
|
|
275
|
+
|
|
276
|
+
<div class="grid grid-cols-7 gap-0.5">
|
|
277
|
+
<button
|
|
278
|
+
v-for="(day, i) in calendarDays"
|
|
279
|
+
:key="i"
|
|
280
|
+
type="button"
|
|
281
|
+
class="flex h-10 w-full items-center justify-center text-body-medium transition-colors duration-100"
|
|
282
|
+
:class="[
|
|
283
|
+
day.disabled
|
|
284
|
+
? 'cursor-not-allowed text-on-surface/25 rounded-full'
|
|
285
|
+
: day.iso === modelValue.start || day.iso === modelValue.end
|
|
286
|
+
? 'bg-primary text-on-primary rounded-full'
|
|
287
|
+
: isInRange(day.iso)
|
|
288
|
+
? 'bg-primary/12 text-on-surface cursor-pointer'
|
|
289
|
+
: day.iso === todayIso
|
|
290
|
+
? 'border border-primary text-primary rounded-full cursor-pointer hover:bg-primary/8'
|
|
291
|
+
: day.current
|
|
292
|
+
? 'cursor-pointer text-on-surface rounded-full hover:bg-on-surface/8'
|
|
293
|
+
: 'cursor-pointer text-on-surface-variant/50 rounded-full hover:bg-on-surface/4',
|
|
294
|
+
]"
|
|
295
|
+
:disabled="day.disabled"
|
|
296
|
+
@mouseenter="picking === 'end' && (hovered = day.iso)"
|
|
297
|
+
@click="selectDay(day)"
|
|
298
|
+
>
|
|
299
|
+
{{ day.date }}
|
|
300
|
+
</button>
|
|
301
|
+
</div>
|
|
246
302
|
|
|
247
|
-
|
|
248
|
-
<
|
|
249
|
-
|
|
250
|
-
:
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
:
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
: day.iso === modelValue.start || day.iso === modelValue.end
|
|
257
|
-
? 'bg-primary text-on-primary rounded-full'
|
|
258
|
-
: isInRange(day.iso)
|
|
259
|
-
? 'bg-primary/12 text-on-surface cursor-pointer'
|
|
260
|
-
: day.iso === todayIso
|
|
261
|
-
? 'border border-primary text-primary rounded-full cursor-pointer hover:bg-primary/8'
|
|
262
|
-
: day.current
|
|
263
|
-
? 'cursor-pointer text-on-surface rounded-full hover:bg-on-surface/8'
|
|
264
|
-
: 'cursor-pointer text-on-surface-variant/50 rounded-full hover:bg-on-surface/4',
|
|
265
|
-
]"
|
|
266
|
-
:disabled="day.disabled"
|
|
267
|
-
@mouseenter="picking === 'end' && (hovered = day.iso)"
|
|
268
|
-
@click="selectDay(day)"
|
|
269
|
-
>
|
|
270
|
-
{{ day.date }}
|
|
271
|
-
</button>
|
|
303
|
+
<!-- Year grid, over the days and as tall as them -->
|
|
304
|
+
<MYearGrid
|
|
305
|
+
:open="yearPicker"
|
|
306
|
+
:years="years"
|
|
307
|
+
:view-year="viewDate.getFullYear()"
|
|
308
|
+
:locale="resolvedLocale"
|
|
309
|
+
:label="localeStrings.dateSwitchToYear"
|
|
310
|
+
@pick="pickYear"
|
|
311
|
+
/>
|
|
272
312
|
</div>
|
|
273
313
|
</div>
|
|
274
314
|
</Transition>
|
|
@@ -10,6 +10,8 @@ import { computed, ref, watch } from 'vue'
|
|
|
10
10
|
import MButton from './MButton.vue'
|
|
11
11
|
import MDialog from './MDialog.vue'
|
|
12
12
|
import MIconButton from './MIconButton.vue'
|
|
13
|
+
import MMonthYearButton from './_MMonthYearButton.vue'
|
|
14
|
+
import MYearGrid from './_MYearGrid.vue'
|
|
13
15
|
import { useLocale } from '../composables/useLocale'
|
|
14
16
|
import { isoDate as fmt, useCalendarMonth } from '../composables/_useCalendarMonth'
|
|
15
17
|
|
|
@@ -27,6 +29,11 @@ const props = withDefaults(defineProps<{
|
|
|
27
29
|
min?: string
|
|
28
30
|
/** Maximum selectable date (YYYY-MM-DD) */
|
|
29
31
|
max?: string
|
|
32
|
+
/**
|
|
33
|
+
* First and last year the year grid (opened from the month's title) offers, as `[from, to]`; the years min/max
|
|
34
|
+
* leave no day in are disabled. Default 1900–2100, as Compose's DatePickerDefaults.YearRange
|
|
35
|
+
*/
|
|
36
|
+
yearRange?: [number, number]
|
|
30
37
|
/**
|
|
31
38
|
* Locale for month/day names. Falls back to the app's configured locale (createM3UI({ locale })) — same
|
|
32
39
|
* pattern as MRelativeTime
|
|
@@ -61,6 +68,7 @@ watch(() => props.show, (open) => {
|
|
|
61
68
|
start.value = props.modelValue?.start ?? null
|
|
62
69
|
end.value = props.modelValue?.end ?? null
|
|
63
70
|
picking.value = start.value && !end.value ? 'end' : 'start'
|
|
71
|
+
yearPicker.value = false
|
|
64
72
|
viewDate.value = props.modelValue?.start
|
|
65
73
|
? new Date(props.modelValue.start + 'T00:00:00')
|
|
66
74
|
: new Date()
|
|
@@ -69,12 +77,24 @@ watch(() => props.show, (open) => {
|
|
|
69
77
|
|
|
70
78
|
// ── Calendar logic ─────────────────────────────────────────────────
|
|
71
79
|
// 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, {
|
|
80
|
+
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange: isOOR, prevMonth, nextMonth, years, showYear } = useCalendarMonth(viewDate, {
|
|
73
81
|
locale: () => resolvedLocale.value,
|
|
74
82
|
min: () => props.min,
|
|
75
83
|
max: () => props.max,
|
|
84
|
+
yearRange: () => props.yearRange,
|
|
76
85
|
})
|
|
77
86
|
|
|
87
|
+
// Compose's YearPicker: the month's title is a menu button that lays a 3-column grid of years over the days; a
|
|
88
|
+
// year shows that year with the same month and goes back to the days
|
|
89
|
+
const yearPicker = ref(false)
|
|
90
|
+
const yearToggle = ref<InstanceType<typeof MMonthYearButton>>()
|
|
91
|
+
|
|
92
|
+
function pickYear(year: number) {
|
|
93
|
+
showYear(year)
|
|
94
|
+
yearPicker.value = false
|
|
95
|
+
yearToggle.value?.focus()
|
|
96
|
+
}
|
|
97
|
+
|
|
78
98
|
const todayIso = fmt(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())
|
|
79
99
|
|
|
80
100
|
function selectDay(day: typeof calendarDays.value[0]) {
|
|
@@ -158,43 +178,63 @@ function onDialog(open: boolean) {
|
|
|
158
178
|
|
|
159
179
|
<!-- Calendar -->
|
|
160
180
|
<div class="px-4 pt-3 pb-2">
|
|
161
|
-
<div class="mb-2 flex items-center justify-between">
|
|
162
|
-
<
|
|
163
|
-
|
|
164
|
-
|
|
181
|
+
<div class="mb-2 flex h-10 items-center justify-between">
|
|
182
|
+
<MMonthYearButton
|
|
183
|
+
ref="yearToggle"
|
|
184
|
+
:label="monthLabel"
|
|
185
|
+
:expanded="yearPicker"
|
|
186
|
+
:action="yearPicker ? locale.dateSwitchToDay : locale.dateSwitchToYear"
|
|
187
|
+
@toggle="yearPicker = !yearPicker"
|
|
188
|
+
/>
|
|
189
|
+
<div v-if="!yearPicker" class="flex">
|
|
190
|
+
<MIconButton icon="chevron_left" :label="locale.previousMonth" :size="36" @click="prevMonth" />
|
|
191
|
+
<MIconButton icon="chevron_right" :label="locale.nextMonth" :size="36" @click="nextMonth" />
|
|
192
|
+
</div>
|
|
165
193
|
</div>
|
|
166
194
|
|
|
167
|
-
<div class="
|
|
168
|
-
<
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
195
|
+
<div class="relative">
|
|
196
|
+
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
197
|
+
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
|
|
198
|
+
{{ wd }}
|
|
199
|
+
</span>
|
|
200
|
+
</div>
|
|
172
201
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
202
|
+
<div class="grid grid-cols-7 gap-0.5">
|
|
203
|
+
<button
|
|
204
|
+
v-for="(day, i) in calendarDays"
|
|
205
|
+
:key="i"
|
|
206
|
+
type="button"
|
|
207
|
+
class="flex h-10 w-full items-center justify-center text-body-medium transition-colors duration-100"
|
|
208
|
+
:class="[
|
|
209
|
+
day.disabled
|
|
210
|
+
? 'cursor-not-allowed text-on-surface/25 rounded-full'
|
|
211
|
+
: day.iso === start || day.iso === end
|
|
212
|
+
? 'bg-primary text-on-primary rounded-full'
|
|
213
|
+
: isInRange(day.iso)
|
|
214
|
+
? 'bg-primary/12 text-on-surface cursor-pointer'
|
|
215
|
+
: day.iso === todayIso
|
|
216
|
+
? 'border border-primary text-primary rounded-full cursor-pointer hover:bg-primary/8'
|
|
217
|
+
: day.current
|
|
218
|
+
? 'cursor-pointer text-on-surface rounded-full hover:bg-on-surface/8'
|
|
219
|
+
: 'cursor-pointer text-on-surface-variant/50 rounded-full hover:bg-on-surface/4',
|
|
220
|
+
]"
|
|
221
|
+
:disabled="day.disabled"
|
|
222
|
+
@mouseenter="picking === 'end' && (hovered = day.iso)"
|
|
223
|
+
@click="selectDay(day)"
|
|
224
|
+
>
|
|
225
|
+
{{ day.date }}
|
|
226
|
+
</button>
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
<!-- Year grid, over the days and as tall as them -->
|
|
230
|
+
<MYearGrid
|
|
231
|
+
:open="yearPicker"
|
|
232
|
+
:years="years"
|
|
233
|
+
:view-year="viewDate.getFullYear()"
|
|
234
|
+
:locale="resolvedLocale"
|
|
235
|
+
:label="locale.dateSwitchToYear"
|
|
236
|
+
@pick="pickYear"
|
|
237
|
+
/>
|
|
198
238
|
</div>
|
|
199
239
|
</div>
|
|
200
240
|
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* @slot overline Custom overline content, replacing the overline prop
|
|
8
8
|
* @slot default Custom content replacing the title/subtitle/description text block
|
|
9
9
|
* @slot children Nested content revealed when expandable is set and the item is expanded
|
|
10
|
-
* @slot trailing Custom trailing element, replacing the icon/text/switch/checkbox
|
|
10
|
+
* @slot trailing Custom trailing element, replacing the icon/text/switch/checkbox. On an expandable item it sits
|
|
11
|
+
* before the expand icon, and its controls (a switch, a button) don't open or close the item
|
|
11
12
|
* @event click Fires on any click, including on an expandable item (right before it toggles)
|
|
12
13
|
* @event update:trailingValue Fires when a trailing switch/checkbox is toggled (trailing='switch' | 'checkbox')
|
|
13
14
|
* @event update:expanded Fires when an expandable item is toggled open/closed
|
|
@@ -72,6 +73,8 @@ const props = withDefaults(
|
|
|
72
73
|
expandable?: boolean
|
|
73
74
|
/** Control the expanded state (v-model:expanded) — otherwise managed internally */
|
|
74
75
|
expanded?: boolean
|
|
76
|
+
/** Indent of the expanded #children: px, or any CSS length. Narrow it on small screens */
|
|
77
|
+
indent?: number | string
|
|
75
78
|
}>(),
|
|
76
79
|
{ active: false, disabled: false, expandable: false },
|
|
77
80
|
)
|
|
@@ -190,7 +193,7 @@ const containerClasses = computed(() => [
|
|
|
190
193
|
? 'py-1'
|
|
191
194
|
: resolvedLines.value === 3 ? 'py-3' : 'py-2',
|
|
192
195
|
minHeightClass.value,
|
|
193
|
-
isClickable.value && !props.disabled && 'cursor-pointer
|
|
196
|
+
isClickable.value && !props.disabled && 'cursor-pointer',
|
|
194
197
|
// ListTokens: ItemSelectedContainerColor = SecondaryContainer, applies to any selected list
|
|
195
198
|
// item, not just nav/segmented contexts.
|
|
196
199
|
isActive.value && 'bg-secondary-container text-on-secondary-container',
|
|
@@ -247,10 +250,30 @@ const { snap } = useSpring(() => expressiveRadii.value, (v) => {
|
|
|
247
250
|
// A change of place in the list (or of list style) isn't an interaction: jump there
|
|
248
251
|
watch([segmentPosition, isNav], () => snap())
|
|
249
252
|
|
|
250
|
-
|
|
253
|
+
// A control inside the row (a button or switch in #trailing, a checkbox in #leading) has its own interaction
|
|
254
|
+
// surface, as in M3: hovering or pressing it leaves the row alone. The row's own built-in leading checkbox is
|
|
255
|
+
// part of the row (data-mli-part), so it still presses it.
|
|
256
|
+
const NESTED_CONTROL = 'button, a, input, select, textarea, label, [role="button"], [role="switch"], [role="checkbox"], [role="radio"], [role="link"], [tabindex]'
|
|
257
|
+
function onNestedControl(e: Event) {
|
|
258
|
+
const row = e.currentTarget as Element
|
|
259
|
+
const control = (e.target as Element | null)?.closest?.(NESTED_CONTROL)
|
|
260
|
+
return !!control && control !== row && row.contains(control) && !control.closest('[data-mli-part]')
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function onPointerMove(e: PointerEvent) { if (e.pointerType !== 'touch') hovered.value = !onNestedControl(e) }
|
|
251
264
|
function onPointerLeave() { hovered.value = false; pressed.value = false }
|
|
252
|
-
function onPointerDown(e: PointerEvent) { if (e.button === 0) pressed.value = true }
|
|
265
|
+
function onPointerDown(e: PointerEvent) { if (e.button === 0 && !onNestedControl(e)) pressed.value = true }
|
|
253
266
|
function onPointerUp() { pressed.value = false }
|
|
267
|
+
|
|
268
|
+
// The state layer (ListTokens: hover 8%, pressed 12% of the content color), drawn by JS so that pressing a nested
|
|
269
|
+
// control doesn't light up the row through CSS :active, which every ancestor of the pressed element matches
|
|
270
|
+
const stateLayerOpacity = computed(() => {
|
|
271
|
+
if (!isClickable.value || props.disabled) return 0
|
|
272
|
+
return pressed.value ? 0.12 : hovered.value ? 0.08 : 0
|
|
273
|
+
})
|
|
274
|
+
const indentStyle = computed(() =>
|
|
275
|
+
props.indent === undefined ? undefined : { paddingLeft: typeof props.indent === 'number' ? `${props.indent}px` : props.indent },
|
|
276
|
+
)
|
|
254
277
|
function onFocus(e: FocusEvent) { focused.value = (e.currentTarget as Element).matches(':focus-visible') }
|
|
255
278
|
function onBlur() { focused.value = false }
|
|
256
279
|
|
|
@@ -287,6 +310,8 @@ function toggleExpand(e: MouseEvent) {
|
|
|
287
310
|
function handleClick(e: MouseEvent) {
|
|
288
311
|
if (props.disabled) return
|
|
289
312
|
if (props.expandable) {
|
|
313
|
+
// A switch or button in the header's #trailing works on its own
|
|
314
|
+
if (onNestedControl(e)) return
|
|
290
315
|
toggleExpand(e)
|
|
291
316
|
return
|
|
292
317
|
}
|
|
@@ -316,12 +341,20 @@ function handleTrailingToggle() {
|
|
|
316
341
|
@keydown="onHeaderKeyDown"
|
|
317
342
|
@focus="onFocus"
|
|
318
343
|
@blur="onBlur"
|
|
319
|
-
@pointerenter="
|
|
344
|
+
@pointerenter="onPointerMove"
|
|
345
|
+
@pointermove="onPointerMove"
|
|
320
346
|
@pointerleave="onPointerLeave"
|
|
321
347
|
@pointerdown="onPointerDown"
|
|
322
348
|
@pointerup="onPointerUp"
|
|
323
349
|
@pointercancel="onPointerUp"
|
|
324
350
|
>
|
|
351
|
+
<span
|
|
352
|
+
class="mli-state-layer pointer-events-none absolute inset-0 rounded-[inherit]"
|
|
353
|
+
:class="isActive ? 'bg-on-secondary-container' : 'bg-on-surface'"
|
|
354
|
+
:style="{ opacity: stateLayerOpacity }"
|
|
355
|
+
aria-hidden="true"
|
|
356
|
+
/>
|
|
357
|
+
|
|
325
358
|
<!-- Leading -->
|
|
326
359
|
<slot name="leading">
|
|
327
360
|
<MIcon v-if="resolvedLeading === 'icon'" :name="icon!" :size="24" class="shrink-0" :class="activeIconClass" />
|
|
@@ -340,6 +373,8 @@ function handleTrailingToggle() {
|
|
|
340
373
|
</slot>
|
|
341
374
|
</div>
|
|
342
375
|
|
|
376
|
+
<slot name="trailing" />
|
|
377
|
+
|
|
343
378
|
<!-- Expand icon -->
|
|
344
379
|
<MIcon
|
|
345
380
|
:name="isExpanded ? 'expand_less' : 'expand_more'"
|
|
@@ -352,7 +387,7 @@ function handleTrailingToggle() {
|
|
|
352
387
|
<!-- Children with collapse animation -->
|
|
353
388
|
<Transition name="mli-expand">
|
|
354
389
|
<div v-if="isExpanded" :id="childrenId" class="mli-expand-grid">
|
|
355
|
-
<div class="mli-expand-body">
|
|
390
|
+
<div class="mli-expand-body" :style="indentStyle">
|
|
356
391
|
<slot name="children" />
|
|
357
392
|
</div>
|
|
358
393
|
</div>
|
|
@@ -371,7 +406,8 @@ function handleTrailingToggle() {
|
|
|
371
406
|
:aria-disabled="(isOption || isButton) && disabled ? 'true' : undefined"
|
|
372
407
|
@click="handleClick"
|
|
373
408
|
@keydown="onRowKeyDown"
|
|
374
|
-
@pointerenter="
|
|
409
|
+
@pointerenter="onPointerMove"
|
|
410
|
+
@pointermove="onPointerMove"
|
|
375
411
|
@pointerleave="onPointerLeave"
|
|
376
412
|
@pointerdown="onPointerDown"
|
|
377
413
|
@pointerup="onPointerUp"
|
|
@@ -379,6 +415,13 @@ function handleTrailingToggle() {
|
|
|
379
415
|
@focus="onFocus"
|
|
380
416
|
@blur="onBlur"
|
|
381
417
|
>
|
|
418
|
+
<span
|
|
419
|
+
class="mli-state-layer pointer-events-none absolute inset-0 rounded-[inherit]"
|
|
420
|
+
:class="isActive ? 'bg-on-secondary-container' : 'bg-on-surface'"
|
|
421
|
+
:style="{ opacity: stateLayerOpacity }"
|
|
422
|
+
aria-hidden="true"
|
|
423
|
+
/>
|
|
424
|
+
|
|
382
425
|
<!-- Divider -->
|
|
383
426
|
<div
|
|
384
427
|
v-if="hasDivider"
|
|
@@ -406,7 +449,7 @@ function handleTrailingToggle() {
|
|
|
406
449
|
<img :src="image" alt="" class="h-14 w-14 shrink-0 rounded-md object-cover">
|
|
407
450
|
</template>
|
|
408
451
|
<template v-else-if="resolvedLeading === 'checkbox'">
|
|
409
|
-
<MCheckbox :model-value="isActive" class="shrink-0" />
|
|
452
|
+
<MCheckbox :model-value="isActive" class="shrink-0" data-mli-part />
|
|
410
453
|
</template>
|
|
411
454
|
</slot>
|
|
412
455
|
|
|
@@ -446,6 +489,9 @@ function handleTrailingToggle() {
|
|
|
446
489
|
</template>
|
|
447
490
|
|
|
448
491
|
<style>
|
|
492
|
+
.mli-state-layer {
|
|
493
|
+
transition: opacity 150ms;
|
|
494
|
+
}
|
|
449
495
|
.mli-expand-grid {
|
|
450
496
|
display: grid;
|
|
451
497
|
grid-template-rows: 1fr;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** One part of the meter */
|
|
3
|
+
export interface MeterItem {
|
|
4
|
+
label: string
|
|
5
|
+
value: number
|
|
6
|
+
/** An M3 color role (`primary`, `tertiary`...) or any CSS color; defaults to the next of a set of roles */
|
|
7
|
+
color?: string
|
|
8
|
+
/** Material Symbol shown in the legend instead of the color dot */
|
|
9
|
+
icon?: string
|
|
10
|
+
}
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
/**
|
|
15
|
+
* MMeterGroup — several values sharing one bar, like a phone's storage screen: photos, apps, system and what's left
|
|
16
|
+
* of the total. Each part is a segment with its own color, separated by a gap (M3's linear progress track gap),
|
|
17
|
+
* growing in on mount and sliding when values change; the legend lists each part with its value and share, and
|
|
18
|
+
* hovering a part highlights it in both places. Values over `max` are scaled to fit.
|
|
19
|
+
*
|
|
20
|
+
* @slot label Replaces the header's text on the left (defaults to `label`)
|
|
21
|
+
* @slot summary Replaces the header's text on the right (defaults to "used of max")
|
|
22
|
+
* @slot legend-item Replaces a legend entry; receives `item`, `percent`, `formatted` and `color`
|
|
23
|
+
* @event select Emitted with the item (and its index) when a segment or legend entry is clicked
|
|
24
|
+
*/
|
|
25
|
+
import { computed, onMounted, ref } from 'vue'
|
|
26
|
+
import MIcon from './MIcon.vue'
|
|
27
|
+
import { useLocale } from '../composables/useLocale'
|
|
28
|
+
|
|
29
|
+
const props = withDefaults(
|
|
30
|
+
defineProps<{
|
|
31
|
+
items: MeterItem[]
|
|
32
|
+
/** The whole bar; defaults to the sum of the values (no remaining part) */
|
|
33
|
+
max?: number
|
|
34
|
+
/** Title above the bar */
|
|
35
|
+
label?: string
|
|
36
|
+
/** Unit appended to formatted values ("GB") */
|
|
37
|
+
unit?: string
|
|
38
|
+
/** Intl.NumberFormat options for values */
|
|
39
|
+
numberFormat?: Intl.NumberFormatOptions
|
|
40
|
+
/** Formats a value; overrides `unit` and `numberFormat` */
|
|
41
|
+
format?: (value: number) => string
|
|
42
|
+
/** Bar thickness */
|
|
43
|
+
size?: 'sm' | 'md' | 'lg'
|
|
44
|
+
/** Legend below the bar */
|
|
45
|
+
legend?: boolean
|
|
46
|
+
/** Show each part's share (%) in the legend */
|
|
47
|
+
percent?: boolean
|
|
48
|
+
/** With `max`, list what's left as a last legend entry (outlined dot) */
|
|
49
|
+
showRemaining?: boolean
|
|
50
|
+
/** The remaining entry's label; defaults to the locale's */
|
|
51
|
+
remainingLabel?: string
|
|
52
|
+
/** Show "used of max" on the right of the header */
|
|
53
|
+
summary?: boolean
|
|
54
|
+
/** Grow the segments in on mount (off with reduced motion) */
|
|
55
|
+
animate?: boolean
|
|
56
|
+
/** BCP-47 language for numbers; defaults to the app's locale */
|
|
57
|
+
locale?: string
|
|
58
|
+
}>(),
|
|
59
|
+
{ size: 'md', legend: true, percent: false, showRemaining: true, summary: true, animate: true },
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const emit = defineEmits<{ select: [item: MeterItem, index: number] }>()
|
|
63
|
+
|
|
64
|
+
const t = useLocale()
|
|
65
|
+
const lang = computed(() => props.locale ?? t.lang)
|
|
66
|
+
|
|
67
|
+
const ROLES = new Set(['primary', 'secondary', 'tertiary', 'error', 'success', 'on-surface', 'on-surface-variant', 'outline', 'inverse-primary', 'primary-container', 'secondary-container', 'tertiary-container'])
|
|
68
|
+
const CYCLE = ['primary', 'tertiary', 'secondary', 'error', 'success']
|
|
69
|
+
const colorOf = (item: MeterItem, i: number) => {
|
|
70
|
+
const c = item.color ?? CYCLE[i % CYCLE.length]!
|
|
71
|
+
return ROLES.has(c) ? `var(--color-${c})` : c
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const used = computed(() => props.items.reduce((s, it) => s + Math.max(0, it.value), 0))
|
|
75
|
+
// The bar's whole: max, unless the values overflow it (then they're scaled to fit)
|
|
76
|
+
const whole = computed(() => Math.max(props.max ?? used.value, used.value) || 1)
|
|
77
|
+
const remaining = computed(() => (props.max != null ? Math.max(0, props.max - used.value) : 0))
|
|
78
|
+
|
|
79
|
+
const nf = computed(() => new Intl.NumberFormat(lang.value, props.numberFormat))
|
|
80
|
+
const pf = computed(() => new Intl.NumberFormat(lang.value, { style: 'percent', maximumFractionDigits: 1 }))
|
|
81
|
+
function fmt(v: number) {
|
|
82
|
+
if (props.format) return props.format(v)
|
|
83
|
+
return props.unit ? `${nf.value.format(v)} ${props.unit}` : nf.value.format(v)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const segments = computed(() =>
|
|
87
|
+
props.items
|
|
88
|
+
.map((item, index) => ({ item, index, share: Math.max(0, item.value) / whole.value, color: colorOf(item, index) }))
|
|
89
|
+
.filter((s) => s.share > 0),
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
const thickness = computed(() => ({ sm: 4, md: 12, lg: 20 })[props.size])
|
|
93
|
+
const gapPx = computed(() => (props.size === 'sm' ? 2 : 4))
|
|
94
|
+
// The track for what's left only shows when something is left; the gaps come off the segments' widths, so the
|
|
95
|
+
// shares stay exact and a full bar isn't clipped
|
|
96
|
+
const hasTrack = computed(() => used.value < whole.value)
|
|
97
|
+
const totalGap = computed(() => Math.max(0, segments.value.length + (hasTrack.value ? 1 : 0) - 1) * gapPx.value)
|
|
98
|
+
const widthOf = (share: number) => `calc((100% - ${totalGap.value}px) * ${share})`
|
|
99
|
+
|
|
100
|
+
// Grows in from zero on mount: the segments render at 0 and get their width one frame later
|
|
101
|
+
const reduced = typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
|
102
|
+
const shown = ref(!props.animate || reduced)
|
|
103
|
+
onMounted(() => {
|
|
104
|
+
if (!shown.value) requestAnimationFrame(() => requestAnimationFrame(() => { shown.value = true }))
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const hovered = ref<number | null>(null)
|
|
108
|
+
|
|
109
|
+
const summaryText = computed(() =>
|
|
110
|
+
props.max != null ? t.meterUsedOf.replace('{used}', fmt(used.value)).replace('{max}', fmt(props.max)) : fmt(used.value),
|
|
111
|
+
)
|
|
112
|
+
const ariaText = computed(() =>
|
|
113
|
+
[props.label, ...props.items.map((it) => `${it.label}: ${fmt(it.value)}`), props.max != null ? `${props.remainingLabel ?? t.meterRemaining}: ${fmt(remaining.value)}` : '']
|
|
114
|
+
.filter(Boolean)
|
|
115
|
+
.join(', '),
|
|
116
|
+
)
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<template>
|
|
120
|
+
<div class="m3-meter-group flex flex-col gap-3" role="group" :aria-label="label">
|
|
121
|
+
<!-- Header -->
|
|
122
|
+
<div v-if="label || $slots.label || summary || $slots.summary" class="flex items-baseline justify-between gap-4">
|
|
123
|
+
<span class="text-title-small font-medium text-on-surface"><slot name="label">{{ label }}</slot></span>
|
|
124
|
+
<span v-if="summary || $slots.summary" class="text-body-medium text-on-surface-variant tabular-nums">
|
|
125
|
+
<slot name="summary" :used="used" :max="max">{{ summaryText }}</slot>
|
|
126
|
+
</span>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<!-- Bar: the segments, then the track for what's left, 4dp gaps between them (M3 linear progress) -->
|
|
130
|
+
<div
|
|
131
|
+
class="flex w-full rounded-full"
|
|
132
|
+
:class="size !== 'sm' && 'overflow-hidden'"
|
|
133
|
+
:style="{ height: `${thickness}px`, gap: `${gapPx}px` }"
|
|
134
|
+
role="img"
|
|
135
|
+
:aria-label="ariaText"
|
|
136
|
+
>
|
|
137
|
+
<div
|
|
138
|
+
v-for="s in segments"
|
|
139
|
+
:key="s.index"
|
|
140
|
+
class="m3-meter-segment h-full shrink-0 cursor-pointer"
|
|
141
|
+
:class="[hovered !== null && hovered !== s.index && 'opacity-40', size === 'sm' && 'm3-meter-hit rounded-full']"
|
|
142
|
+
:style="{ width: shown ? widthOf(s.share) : '0px', backgroundColor: s.color }"
|
|
143
|
+
@mouseenter="hovered = s.index"
|
|
144
|
+
@mouseleave="hovered = null"
|
|
145
|
+
@click="emit('select', s.item, s.index)"
|
|
146
|
+
/>
|
|
147
|
+
<div v-if="hasTrack || !shown" class="h-full min-w-0 flex-1 bg-secondary-container" :class="size === 'sm' && 'rounded-full'" />
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
<!-- Legend -->
|
|
151
|
+
<ul v-if="legend" class="flex flex-wrap gap-x-5 gap-y-2" aria-hidden="true">
|
|
152
|
+
<li
|
|
153
|
+
v-for="(item, i) in items"
|
|
154
|
+
:key="i"
|
|
155
|
+
class="flex cursor-pointer items-center gap-2 text-body-medium transition-opacity"
|
|
156
|
+
:class="hovered !== null && hovered !== i && 'opacity-40'"
|
|
157
|
+
@mouseenter="hovered = i"
|
|
158
|
+
@mouseleave="hovered = null"
|
|
159
|
+
@click="emit('select', item, i)"
|
|
160
|
+
>
|
|
161
|
+
<slot name="legend-item" :item="item" :percent="item.value / whole" :formatted="fmt(item.value)" :color="colorOf(item, i)">
|
|
162
|
+
<MIcon v-if="item.icon" :name="item.icon" :size="18" :style="{ color: colorOf(item, i) }" />
|
|
163
|
+
<span v-else class="size-2.5 shrink-0 rounded-full" :style="{ backgroundColor: colorOf(item, i) }" />
|
|
164
|
+
<span class="text-on-surface">{{ item.label }}</span>
|
|
165
|
+
<span class="text-on-surface-variant tabular-nums">
|
|
166
|
+
{{ fmt(item.value) }}<template v-if="percent"> · {{ pf.format(item.value / whole) }}</template>
|
|
167
|
+
</span>
|
|
168
|
+
</slot>
|
|
169
|
+
</li>
|
|
170
|
+
<li v-if="max != null && showRemaining" class="flex items-center gap-2 text-body-medium">
|
|
171
|
+
<span class="size-2.5 shrink-0 rounded-full border-2 border-secondary-container" />
|
|
172
|
+
<span class="text-on-surface">{{ remainingLabel ?? t.meterRemaining }}</span>
|
|
173
|
+
<span class="text-on-surface-variant tabular-nums">
|
|
174
|
+
{{ fmt(remaining) }}<template v-if="percent"> · {{ pf.format(remaining / whole) }}</template>
|
|
175
|
+
</span>
|
|
176
|
+
</li>
|
|
177
|
+
</ul>
|
|
178
|
+
</div>
|
|
179
|
+
</template>
|
|
180
|
+
|
|
181
|
+
<style>
|
|
182
|
+
/* sm is 4px tall: a taller invisible hit area, so the pointer finds a segment without aiming at a hairline */
|
|
183
|
+
.m3-meter-hit {
|
|
184
|
+
position: relative;
|
|
185
|
+
}
|
|
186
|
+
.m3-meter-hit::after {
|
|
187
|
+
content: '';
|
|
188
|
+
position: absolute;
|
|
189
|
+
inset: -8px 0;
|
|
190
|
+
}
|
|
191
|
+
.m3-meter-segment {
|
|
192
|
+
transition:
|
|
193
|
+
width 700ms cubic-bezier(0.2, 0, 0, 1),
|
|
194
|
+
opacity 150ms;
|
|
195
|
+
}
|
|
196
|
+
</style>
|