@m3ui-vue/m3ui-vue 1.4.0 → 1.4.2
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 +295 -11
- 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/MCountdown.vue.d.ts +80 -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 +10 -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 +5133 -3366
- 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__/MCountdown.test.ts +75 -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__/MTypewriter.test.ts +50 -0
- package/src/__tests__/calendarMonth.test.ts +104 -0
- package/src/__tests__/clearToNull.test.ts +30 -0
- package/src/__tests__/ssr.test.ts +4 -0
- package/src/components/MAutocomplete.vue +2 -2
- package/src/components/MCalendarHeatmap.vue +349 -0
- package/src/components/MCountdown.vue +200 -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/MSelect.vue +2 -2
- 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 +10 -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'
|
|
@@ -23,6 +25,11 @@ const props = defineProps<{
|
|
|
23
25
|
min?: string
|
|
24
26
|
/** Maximum selectable date (YYYY-MM-DD) */
|
|
25
27
|
max?: string
|
|
28
|
+
/**
|
|
29
|
+
* First and last year the year grid (opened from the month's title) offers, as `[from, to]`; the years min/max
|
|
30
|
+
* leave no day in are disabled. Default 1900–2100, as Compose's DatePickerDefaults.YearRange
|
|
31
|
+
*/
|
|
32
|
+
yearRange?: [number, number]
|
|
26
33
|
/** Disables the picker */
|
|
27
34
|
disabled?: boolean
|
|
28
35
|
/** Error state */
|
|
@@ -65,12 +72,25 @@ watch(() => props.modelValue, (v) => {
|
|
|
65
72
|
})
|
|
66
73
|
|
|
67
74
|
// Weekday names, the month's title and its six-week grid, shared with the other date pickers
|
|
68
|
-
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange, prevMonth, nextMonth, isToday } = useCalendarMonth(viewDate, {
|
|
75
|
+
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange, prevMonth, nextMonth, isToday, years, showYear } = useCalendarMonth(viewDate, {
|
|
69
76
|
locale: () => resolvedLocale.value,
|
|
70
77
|
min: () => props.min,
|
|
71
78
|
max: () => props.max,
|
|
79
|
+
yearRange: () => props.yearRange,
|
|
72
80
|
})
|
|
73
81
|
|
|
82
|
+
// Compose's YearPicker: the month's title is a menu button that lays a 3-column grid of years over the days; a
|
|
83
|
+
// year shows that year with the same month and goes back to the days
|
|
84
|
+
const yearPicker = ref(false)
|
|
85
|
+
const yearToggle = ref<InstanceType<typeof MMonthYearButton>>()
|
|
86
|
+
watch(open, () => { yearPicker.value = false })
|
|
87
|
+
|
|
88
|
+
function pickYear(year: number) {
|
|
89
|
+
showYear(year)
|
|
90
|
+
yearPicker.value = false
|
|
91
|
+
yearToggle.value?.focus()
|
|
92
|
+
}
|
|
93
|
+
|
|
74
94
|
function selectDay(day: typeof calendarDays.value[0]) {
|
|
75
95
|
if (day.disabled) return
|
|
76
96
|
emit('update:modelValue', day.iso)
|
|
@@ -197,42 +217,62 @@ onUnmounted(() => {
|
|
|
197
217
|
:style="dropPos"
|
|
198
218
|
>
|
|
199
219
|
<!-- Header -->
|
|
200
|
-
<div class="mb-3 flex items-center justify-between">
|
|
201
|
-
<
|
|
202
|
-
|
|
203
|
-
|
|
220
|
+
<div class="mb-3 flex h-10 items-center justify-between">
|
|
221
|
+
<MMonthYearButton
|
|
222
|
+
ref="yearToggle"
|
|
223
|
+
:label="monthLabel"
|
|
224
|
+
:expanded="yearPicker"
|
|
225
|
+
:action="yearPicker ? localeStrings.dateSwitchToDay : localeStrings.dateSwitchToYear"
|
|
226
|
+
@toggle="yearPicker = !yearPicker"
|
|
227
|
+
/>
|
|
228
|
+
<div v-if="!yearPicker" class="flex">
|
|
229
|
+
<MIconButton icon="chevron_left" :label="prevMonthLabel ?? localeStrings.previousMonth" :size="36" @click="prevMonth" />
|
|
230
|
+
<MIconButton icon="chevron_right" :label="nextMonthLabel ?? localeStrings.nextMonth" :size="36" @click="nextMonth" />
|
|
231
|
+
</div>
|
|
204
232
|
</div>
|
|
205
233
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
<
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
234
|
+
<div class="relative">
|
|
235
|
+
<!-- Weekday headers -->
|
|
236
|
+
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
237
|
+
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
|
|
238
|
+
{{ wd }}
|
|
239
|
+
</span>
|
|
240
|
+
</div>
|
|
241
|
+
|
|
242
|
+
<!-- Days grid -->
|
|
243
|
+
<div class="grid grid-cols-7 gap-0.5">
|
|
244
|
+
<button
|
|
245
|
+
v-for="(day, i) in calendarDays"
|
|
246
|
+
:key="i"
|
|
247
|
+
type="button"
|
|
248
|
+
class="flex h-10 w-full items-center justify-center rounded-full text-body-medium transition-colors duration-100"
|
|
249
|
+
:class="[
|
|
250
|
+
day.disabled
|
|
251
|
+
? 'cursor-not-allowed text-on-surface/25'
|
|
252
|
+
: day.iso === modelValue
|
|
253
|
+
? 'bg-primary text-on-primary'
|
|
254
|
+
: isToday(day.iso)
|
|
255
|
+
? 'border border-primary text-primary cursor-pointer hover:bg-primary/8'
|
|
256
|
+
: day.current
|
|
257
|
+
? 'cursor-pointer text-on-surface hover:bg-on-surface/8'
|
|
258
|
+
: 'cursor-pointer text-on-surface-variant/50 hover:bg-on-surface/4',
|
|
259
|
+
]"
|
|
260
|
+
:disabled="day.disabled"
|
|
261
|
+
@click="selectDay(day)"
|
|
262
|
+
>
|
|
263
|
+
{{ day.date }}
|
|
264
|
+
</button>
|
|
265
|
+
</div>
|
|
212
266
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
:
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
? 'cursor-not-allowed text-on-surface/25'
|
|
223
|
-
: day.iso === modelValue
|
|
224
|
-
? 'bg-primary text-on-primary'
|
|
225
|
-
: isToday(day.iso)
|
|
226
|
-
? 'border border-primary text-primary cursor-pointer hover:bg-primary/8'
|
|
227
|
-
: day.current
|
|
228
|
-
? 'cursor-pointer text-on-surface hover:bg-on-surface/8'
|
|
229
|
-
: 'cursor-pointer text-on-surface-variant/50 hover:bg-on-surface/4',
|
|
230
|
-
]"
|
|
231
|
-
:disabled="day.disabled"
|
|
232
|
-
@click="selectDay(day)"
|
|
233
|
-
>
|
|
234
|
-
{{ day.date }}
|
|
235
|
-
</button>
|
|
267
|
+
<!-- Year grid, over the days and as tall as them -->
|
|
268
|
+
<MYearGrid
|
|
269
|
+
:open="yearPicker"
|
|
270
|
+
:years="years"
|
|
271
|
+
:view-year="viewDate.getFullYear()"
|
|
272
|
+
:locale="resolvedLocale"
|
|
273
|
+
:label="localeStrings.dateSwitchToYear"
|
|
274
|
+
@pick="pickYear"
|
|
275
|
+
/>
|
|
236
276
|
</div>
|
|
237
277
|
</div>
|
|
238
278
|
</Transition>
|
|
@@ -10,7 +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
|
|
13
|
+
import MMonthYearButton from './_MMonthYearButton.vue'
|
|
14
|
+
import MYearGrid from './_MYearGrid.vue'
|
|
14
15
|
import { useLocale } from '../composables/useLocale'
|
|
15
16
|
import { isoDate as fmt, useCalendarMonth } from '../composables/_useCalendarMonth'
|
|
16
17
|
|
|
@@ -30,6 +31,11 @@ const props = withDefaults(defineProps<{
|
|
|
30
31
|
locale?: string
|
|
31
32
|
/** Dialog title */
|
|
32
33
|
title?: string
|
|
34
|
+
/**
|
|
35
|
+
* First and last year the year grid (opened from the month's title) offers, as `[from, to]`; the years min/max
|
|
36
|
+
* leave no day in are disabled. Default 1900–2100, as Compose's DatePickerDefaults.YearRange
|
|
37
|
+
*/
|
|
38
|
+
yearRange?: [number, number]
|
|
33
39
|
}>(), {
|
|
34
40
|
modelValue: null,
|
|
35
41
|
show: false,
|
|
@@ -57,18 +63,33 @@ watch(() => props.show, (open) => {
|
|
|
57
63
|
selected.value = props.modelValue ?? null
|
|
58
64
|
viewDate.value = props.modelValue ? new Date(props.modelValue + 'T00:00:00') : new Date()
|
|
59
65
|
inputMode.value = 'calendar'
|
|
66
|
+
yearPicker.value = false
|
|
60
67
|
dateInput.value = props.modelValue ? isoToDisplay(props.modelValue) : ''
|
|
61
68
|
}
|
|
62
69
|
})
|
|
63
70
|
|
|
64
71
|
// ── Calendar logic ─────────────────────────────────────────────────
|
|
65
72
|
// Weekday names, the month's title and its six-week grid, shared with the other date pickers
|
|
66
|
-
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange: isOOR, prevMonth, nextMonth } = useCalendarMonth(viewDate, {
|
|
73
|
+
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange: isOOR, prevMonth, nextMonth, years, showYear } = useCalendarMonth(viewDate, {
|
|
67
74
|
locale: () => resolvedLocale.value,
|
|
68
75
|
min: () => props.min,
|
|
69
76
|
max: () => props.max,
|
|
77
|
+
yearRange: () => props.yearRange,
|
|
70
78
|
})
|
|
71
79
|
|
|
80
|
+
// ── Year grid ──────────────────────────────────────────────────────
|
|
81
|
+
// Compose's YearPicker: the month's title is a menu button that lays a 3-column grid of years over the days; a
|
|
82
|
+
// year shows that year with the same month and goes back to the days.
|
|
83
|
+
const yearPicker = ref(false)
|
|
84
|
+
const yearToggle = ref<InstanceType<typeof MMonthYearButton>>()
|
|
85
|
+
watch(inputMode, () => { yearPicker.value = false })
|
|
86
|
+
|
|
87
|
+
function pickYear(year: number) {
|
|
88
|
+
showYear(year)
|
|
89
|
+
yearPicker.value = false
|
|
90
|
+
yearToggle.value?.focus()
|
|
91
|
+
}
|
|
92
|
+
|
|
72
93
|
const todayIso = fmt(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())
|
|
73
94
|
|
|
74
95
|
function selectDay(day: typeof calendarDays.value[0]) {
|
|
@@ -167,43 +188,64 @@ function onDialog(open: boolean) {
|
|
|
167
188
|
|
|
168
189
|
<!-- Calendar mode -->
|
|
169
190
|
<div v-if="inputMode === 'calendar'" class="px-4 pt-3 pb-2">
|
|
170
|
-
<!-- Month nav
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
<
|
|
174
|
-
|
|
191
|
+
<!-- Month nav: Compose's MonthsNavigation, the month/year menu button at the start and the arrows at the end
|
|
192
|
+
(hidden while the year grid is open) -->
|
|
193
|
+
<div class="mb-2 flex h-10 items-center justify-between">
|
|
194
|
+
<MMonthYearButton
|
|
195
|
+
ref="yearToggle"
|
|
196
|
+
:label="monthLabel"
|
|
197
|
+
:expanded="yearPicker"
|
|
198
|
+
:action="yearPicker ? locale.dateSwitchToDay : locale.dateSwitchToYear"
|
|
199
|
+
@toggle="yearPicker = !yearPicker"
|
|
200
|
+
/>
|
|
201
|
+
<div v-if="!yearPicker" class="flex">
|
|
202
|
+
<MIconButton icon="chevron_left" :label="locale.previousMonth" :size="36" @click="prevMonth" />
|
|
203
|
+
<MIconButton icon="chevron_right" :label="locale.nextMonth" :size="36" @click="nextMonth" />
|
|
204
|
+
</div>
|
|
175
205
|
</div>
|
|
176
206
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
<
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
<div class="relative">
|
|
208
|
+
<!-- Weekday headers -->
|
|
209
|
+
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
210
|
+
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
|
|
211
|
+
{{ wd }}
|
|
212
|
+
</span>
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<!-- Days grid -->
|
|
216
|
+
<div class="grid grid-cols-7 gap-0.5">
|
|
217
|
+
<button
|
|
218
|
+
v-for="(day, i) in calendarDays"
|
|
219
|
+
:key="i"
|
|
220
|
+
type="button"
|
|
221
|
+
class="flex h-10 w-full items-center justify-center rounded-full text-body-medium transition-colors duration-100"
|
|
222
|
+
:class="[
|
|
223
|
+
day.disabled
|
|
224
|
+
? 'cursor-not-allowed text-on-surface/25'
|
|
225
|
+
: day.iso === selected
|
|
226
|
+
? 'bg-primary text-on-primary'
|
|
227
|
+
: day.iso === todayIso
|
|
228
|
+
? 'border border-primary text-primary cursor-pointer hover:bg-primary/8'
|
|
229
|
+
: day.current
|
|
230
|
+
? 'cursor-pointer text-on-surface hover:bg-on-surface/8'
|
|
231
|
+
: 'cursor-pointer text-on-surface-variant/50 hover:bg-on-surface/4',
|
|
232
|
+
]"
|
|
233
|
+
:disabled="day.disabled"
|
|
234
|
+
@click="selectDay(day)"
|
|
235
|
+
>
|
|
236
|
+
{{ day.date }}
|
|
237
|
+
</button>
|
|
238
|
+
</div>
|
|
183
239
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
? 'cursor-not-allowed text-on-surface/25'
|
|
194
|
-
: day.iso === selected
|
|
195
|
-
? 'bg-primary text-on-primary'
|
|
196
|
-
: day.iso === todayIso
|
|
197
|
-
? 'border border-primary text-primary cursor-pointer hover:bg-primary/8'
|
|
198
|
-
: day.current
|
|
199
|
-
? 'cursor-pointer text-on-surface hover:bg-on-surface/8'
|
|
200
|
-
: 'cursor-pointer text-on-surface-variant/50 hover:bg-on-surface/4',
|
|
201
|
-
]"
|
|
202
|
-
:disabled="day.disabled"
|
|
203
|
-
@click="selectDay(day)"
|
|
204
|
-
>
|
|
205
|
-
{{ day.date }}
|
|
206
|
-
</button>
|
|
240
|
+
<!-- Year grid, over the days and as tall as them -->
|
|
241
|
+
<MYearGrid
|
|
242
|
+
:open="yearPicker"
|
|
243
|
+
:years="years"
|
|
244
|
+
:view-year="viewDate.getFullYear()"
|
|
245
|
+
:locale="resolvedLocale"
|
|
246
|
+
:label="locale.dateSwitchToYear"
|
|
247
|
+
@pick="pickYear"
|
|
248
|
+
/>
|
|
207
249
|
</div>
|
|
208
250
|
</div>
|
|
209
251
|
|
|
@@ -228,3 +270,4 @@ function onDialog(open: boolean) {
|
|
|
228
270
|
</div>
|
|
229
271
|
</MDialog>
|
|
230
272
|
</template>
|
|
273
|
+
|
|
@@ -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
|
|