@stacksjs/components 0.2.979 → 0.2.982
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/{DateTimePicker-d5984mm1.stx → DateTimePicker-7zk8tc4s.stx} +30 -23
- package/dist/{DialogPanel-v972ztcc.stx → DialogPanel-aav3werz.stx} +1 -1
- package/dist/{Drawer-18xpj1je.stx → Drawer-f6hwnwmg.stx} +1 -1
- package/dist/index.js +2 -2
- package/dist/ui/date-time-picker/DateTimePicker.d.ts +3 -0
- package/dist/ui/date-time-picker/date-time-picker-text.d.ts +67 -0
- package/dist/ui/dialog/index.d.ts +2 -2
- package/dist/ui/drawer/index.d.ts +2 -2
- package/package.json +3 -3
- package/src/ui/date-time-picker/DateTimePicker.stx +30 -23
- package/src/ui/date-time-picker/date-time-picker-text.ts +47 -0
- package/src/ui/dialog/DialogPanel.stx +1 -1
- package/src/ui/dialog/index.ts +2 -2
- package/src/ui/drawer/Drawer.stx +1 -1
- package/src/ui/drawer/index.ts +2 -2
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script server>
|
|
2
|
+
import { dateTimePickerText } from './date-time-picker-text'
|
|
3
|
+
|
|
2
4
|
export const value = $props.value || null
|
|
3
5
|
export const timeZone = $props.timeZone || 'UTC'
|
|
4
6
|
export const locale = $props.locale || 'en-US'
|
|
@@ -9,10 +11,11 @@ export const disabled = $bool($props.disabled)
|
|
|
9
11
|
export const clearable = $bool($props.clearable, true)
|
|
10
12
|
const step = $num($props.minuteStep, 1)
|
|
11
13
|
export const minuteStep = Number.isInteger(step) && step > 0 && 60 % step === 0 ? step : 1
|
|
12
|
-
export const placeholder = $props.placeholder || '
|
|
13
|
-
export const label = $props.label || '
|
|
14
|
-
export const
|
|
15
|
-
export const
|
|
14
|
+
export const placeholder = $props.placeholder || ''
|
|
15
|
+
export const label = $props.label || ''
|
|
16
|
+
export const initialText = dateTimePickerText(locale)
|
|
17
|
+
export const triggerLabel = label || initialText.label
|
|
18
|
+
export const triggerPlaceholder = placeholder || initialText.placeholder
|
|
16
19
|
export const instanceId = $uid
|
|
17
20
|
export const rootClasses = `relative inline-block ${$props.className || ''}`.trim()
|
|
18
21
|
export const triggerClasses = 'inline-flex items-center gap-2 rounded-control bg-field px-3 py-2 text-sm text-fg ring-1 ring-inset ring-line-strong hover:bg-field-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-not-allowed disabled:opacity-50'
|
|
@@ -21,10 +24,11 @@ export const panelClasses = 'absolute left-0 z-30 w-96 max-w-[calc(100vw-2rem)]
|
|
|
21
24
|
|
|
22
25
|
<script client>
|
|
23
26
|
import { measureTooltipPosition, trackBrowserPopup, trackNativePopup } from '../../utils/tooltip-position'
|
|
27
|
+
import { dateTimePickerText } from './date-time-picker-text'
|
|
24
28
|
import { dateTimeFields, dateTimeInstant, dateTimePreset, dateTimeToIso, formatDateTime, validTimeZone } from './date-time'
|
|
25
29
|
const emit = defineEmits()
|
|
26
30
|
const instanceId = {{ instanceId }}
|
|
27
|
-
const
|
|
31
|
+
const customLabel = useReactiveProp('label', {{ label }})
|
|
28
32
|
const rootRef = useRef('dateTimeRoot')
|
|
29
33
|
const triggerRef = useRef('dateTimeTrigger')
|
|
30
34
|
const value = useReactiveProp('value', {{ value }}, { parse: value => value })
|
|
@@ -35,7 +39,10 @@ const maximum = useReactiveProp('maxDate', {{ maxDate }}, { parse: value => valu
|
|
|
35
39
|
const suggested = useReactiveProp('suggestedTime', {{ suggestedTime }}, { parse: value => value })
|
|
36
40
|
const disabled = useReactiveProp('disabled', {{ disabled }})
|
|
37
41
|
const clearable = useReactiveProp('clearable', {{ clearable }})
|
|
38
|
-
const
|
|
42
|
+
const customPlaceholder = useReactiveProp('placeholder', {{ placeholder }})
|
|
43
|
+
const text = derived(() => dateTimePickerText(locale()))
|
|
44
|
+
const label = derived(() => customLabel() || text().label)
|
|
45
|
+
const placeholder = derived(() => customPlaceholder() || text().placeholder)
|
|
39
46
|
const minuteStep = useReactiveProp('minuteStep', {{ minuteStep }}, { parse: value => {
|
|
40
47
|
const n = Number(value)
|
|
41
48
|
return Number.isInteger(n) && n > 0 && 60 % n === 0 ? n : 1
|
|
@@ -94,20 +101,20 @@ const candidate = derived(() => {
|
|
|
94
101
|
return dateTimeToIso(date, time, zone)
|
|
95
102
|
})
|
|
96
103
|
function boundsError(iso) {
|
|
97
|
-
if (!iso) return
|
|
104
|
+
if (!iso) return text().invalidTime
|
|
98
105
|
const minValue = minimum()
|
|
99
106
|
const maxValue = maximum()
|
|
100
107
|
const min = dateTimeInstant(minValue)
|
|
101
108
|
const max = dateTimeInstant(maxValue)
|
|
102
|
-
if (minValue && !min) return
|
|
103
|
-
if (maxValue && !max) return
|
|
104
|
-
if (min && Date.parse(iso) < Date.parse(min)) return
|
|
105
|
-
if (max && Date.parse(iso) > Date.parse(max)) return
|
|
109
|
+
if (minValue && !min) return text().invalidMinimum
|
|
110
|
+
if (maxValue && !max) return text().invalidMaximum
|
|
111
|
+
if (min && Date.parse(iso) < Date.parse(min)) return text().beforeMinimum
|
|
112
|
+
if (max && Date.parse(iso) > Date.parse(max)) return text().afterMaximum
|
|
106
113
|
return ''
|
|
107
114
|
}
|
|
108
115
|
const error = derived(() => {
|
|
109
|
-
if (!validTimeZone(timeZone())) return
|
|
110
|
-
if (Number(draftTime().slice(3, 5)) % minuteStep() !== 0) return
|
|
116
|
+
if (!validTimeZone(timeZone())) return text().invalidTimezone
|
|
117
|
+
if (Number(draftTime().slice(3, 5)) % minuteStep() !== 0) return text().minuteIncrement
|
|
111
118
|
return boundsError(candidate())
|
|
112
119
|
})
|
|
113
120
|
|
|
@@ -215,21 +222,21 @@ defineExpose({ open, close })
|
|
|
215
222
|
<span :text="displayValue">{{ triggerPlaceholder }}</span>
|
|
216
223
|
</button>
|
|
217
224
|
<div :if="isOpen" class="{{ panelClasses }}" role="dialog" data-native="Modal" visible="false" hidden :hidden="!isOpen()" :id="panelId" :aria-labelledby="titleId" :aria-describedby="zoneId" data-date-time-panel>
|
|
218
|
-
<h3 class="mb-2 text-sm font-semibold text-fg" :id="titleId" x-text="label">{{
|
|
219
|
-
<p class="mb-3 text-xs text-fg-muted" :id="zoneId">
|
|
225
|
+
<h3 class="mb-2 text-sm font-semibold text-fg" :id="titleId" x-text="label">{{ triggerLabel }}</h3>
|
|
226
|
+
<p class="mb-3 text-xs text-fg-muted" :id="zoneId"><span :text="text().timezone">{{ initialText.timezone }}</span> <span x-text="timeZone"></span></p>
|
|
220
227
|
<div class="mb-3 flex flex-wrap gap-2">
|
|
221
|
-
<button type="button" class="rounded-control bg-surface px-2 py-1 text-xs text-fg hover:bg-surface-hover" data-date-time-preset="hour" :disabled="presetDisabled('hour')" @click="choosePreset('hour')">
|
|
222
|
-
<button type="button" class="rounded-control bg-surface px-2 py-1 text-xs text-fg hover:bg-surface-hover" data-date-time-preset="tomorrow" :disabled="presetDisabled('tomorrow')" @click="choosePreset('tomorrow')">
|
|
223
|
-
<button :if="suggestion" type="button" class="rounded-control bg-surface px-2 py-1 text-xs text-fg hover:bg-surface-hover" data-date-time-preset="suggested" :disabled="presetDisabled('suggested')" @click="choosePreset('suggested')">
|
|
228
|
+
<button type="button" class="rounded-control bg-surface px-2 py-1 text-xs text-fg hover:bg-surface-hover" data-date-time-preset="hour" :disabled="presetDisabled('hour')" @click="choosePreset('hour')" :text="text().hour">{{ initialText.hour }}</button>
|
|
229
|
+
<button type="button" class="rounded-control bg-surface px-2 py-1 text-xs text-fg hover:bg-surface-hover" data-date-time-preset="tomorrow" :disabled="presetDisabled('tomorrow')" @click="choosePreset('tomorrow')" :text="text().tomorrow">{{ initialText.tomorrow }}</button>
|
|
230
|
+
<button :if="suggestion" type="button" class="rounded-control bg-surface px-2 py-1 text-xs text-fg hover:bg-surface-hover" data-date-time-preset="suggested" :disabled="presetDisabled('suggested')" @click="choosePreset('suggested')" :text="text().suggested">{{ initialText.suggested }}</button>
|
|
224
231
|
</div>
|
|
225
|
-
<Calendar :value="calendarValue()" :minDate="calendarMin()" :maxDate="calendarMax()" :locale="locale" @change.stop="onCalendarChange" className="max-w-none p-0 shadow-none" />
|
|
226
|
-
<label class="mt-3 block text-xs font-medium text-fg" :for="timeId">
|
|
232
|
+
<Calendar :value="calendarValue()" :minDate="calendarMin()" :maxDate="calendarMax()" :locale="locale" previousMonthLabel="{{ initialText.previousMonth }}" nextMonthLabel="{{ initialText.nextMonth }}" :previousMonthLabel="text().previousMonth" :nextMonthLabel="text().nextMonth" @change.stop="onCalendarChange" className="max-w-none p-0 shadow-none" />
|
|
233
|
+
<label class="mt-3 block text-xs font-medium text-fg" :for="timeId" :text="text().time">{{ initialText.time }}</label>
|
|
227
234
|
<input type="time" class="mt-1 w-full rounded-control bg-field px-3 py-2 text-sm text-fg ring-1 ring-line-strong focus:ring-2 focus:ring-accent" :id="timeId" data-date-time-clock x-model="draftTime" :step="minuteStep() * 60" :aria-invalid="error() ? 'true' : null" :aria-describedby="error() ? errorId : zoneId" @keydown.enter.prevent="apply()" />
|
|
228
235
|
<p class="mt-2 text-xs text-danger-fg" :id="errorId" role="status" aria-live="polite" x-text="error"></p>
|
|
229
236
|
<div class="mt-3 flex justify-end gap-2">
|
|
230
|
-
<button :if="clearable" type="button" class="mr-auto rounded-control px-3 py-2 text-sm text-fg-muted hover:bg-surface-hover" data-date-time-clear @click="clear()">
|
|
231
|
-
<button type="button" class="rounded-control px-3 py-2 text-sm text-fg hover:bg-surface-hover" data-date-time-cancel @click="close()">
|
|
232
|
-
<button type="button" class="rounded-control bg-accent-solid px-3 py-2 text-sm text-accent-ink disabled:opacity-50" :disabled="!!error()" data-date-time-apply @click="apply()">
|
|
237
|
+
<button :if="clearable" type="button" class="mr-auto rounded-control px-3 py-2 text-sm text-fg-muted hover:bg-surface-hover" data-date-time-clear @click="clear()" :text="text().clear">{{ initialText.clear }}</button>
|
|
238
|
+
<button type="button" class="rounded-control px-3 py-2 text-sm text-fg hover:bg-surface-hover" data-date-time-cancel @click="close()" :text="text().cancel">{{ initialText.cancel }}</button>
|
|
239
|
+
<button type="button" class="rounded-control bg-accent-solid px-3 py-2 text-sm text-accent-ink disabled:opacity-50" :disabled="!!error()" data-date-time-apply @click="apply()" :text="text().apply">{{ initialText.apply }}</button>
|
|
233
240
|
</div>
|
|
234
241
|
</div>
|
|
235
242
|
</div>
|
|
@@ -51,7 +51,7 @@ export const nativeGrabberClasses = `self-center h-[5px] w-9 shrink-0 rounded-fu
|
|
|
51
51
|
</script>
|
|
52
52
|
|
|
53
53
|
<script client>
|
|
54
|
-
const systemSheet = typeof craft !== 'undefined' && craft.platform
|
|
54
|
+
const systemSheet = typeof craft !== 'undefined' && ['ios', 'android'].includes(craft.platform) && craft.capabilities.nativePlatformControls === true
|
|
55
55
|
</script>
|
|
56
56
|
|
|
57
57
|
@if($native)
|
|
@@ -130,7 +130,7 @@ export const drawerInstanceId = $uid
|
|
|
130
130
|
// A nested overlay's close belongs to that overlay, never this drawer.
|
|
131
131
|
const emit = defineEmits(['close'])
|
|
132
132
|
const drawerInstanceId = {{ drawerInstanceId }}
|
|
133
|
-
const systemSheet = typeof craft !== 'undefined' && craft.platform
|
|
133
|
+
const systemSheet = typeof craft !== 'undefined' && ['ios', 'android'].includes(craft.platform) && craft.capabilities.nativePlatformControls === true
|
|
134
134
|
// useReactiveProp lets the parent drive `open` via signals
|
|
135
135
|
// (`:open="drawerOpen()"`) instead of the prop being captured once.
|
|
136
136
|
// See stacksjs/stx#1704.
|