@xerios/design-system 0.1.1 → 0.1.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/CHANGELOG.md +133 -0
- package/README.md +12 -8
- package/dist/components/Button.svelte +0 -7
- package/dist/components/Button.svelte.d.ts +1 -13
- package/dist/components/CollapsibleAdvanced.svelte +1 -1
- package/dist/components/Dialogs.svelte +12 -0
- package/dist/components/WorkingBorder.svelte +10 -8
- package/dist/components/empty/EmptyError.svelte +61 -12
- package/dist/components/empty/EmptyError.svelte.d.ts +2 -1
- package/dist/components/filters/FilterChip.svelte +2 -2
- package/dist/components/filters/OptionList.svelte +29 -13
- package/dist/components/filters/Panel.svelte +1 -1
- package/dist/components/icons.d.ts +3 -0
- package/dist/components/icons.js +3 -0
- package/dist/components/inputs/ButtonGroup.svelte +4 -1
- package/dist/components/inputs/Calendar.svelte +232 -172
- package/dist/components/inputs/Calendar.svelte.d.ts +2 -0
- package/dist/components/inputs/DateField.svelte +209 -92
- package/dist/components/inputs/DateField.svelte.d.ts +16 -10
- package/dist/components/inputs/DateInput.svelte +22 -9
- package/dist/components/inputs/DateInput.svelte.d.ts +3 -0
- package/dist/components/inputs/DatePicker.svelte +63 -38
- package/dist/components/inputs/DatePicker.svelte.d.ts +5 -2
- package/dist/components/inputs/DateRangePicker.svelte +69 -39
- package/dist/components/inputs/DateRangePicker.svelte.d.ts +5 -2
- package/dist/components/inputs/DateRangeSelect.svelte +26 -25
- package/dist/components/inputs/RadioGroup.svelte +3 -1
- package/dist/components/inputs/Segmented.svelte +4 -1
- package/dist/components/inputs/Select.svelte +18 -8
- package/dist/components/inputs/TextArea.svelte +1 -1
- package/dist/components/scroll/ScrollButton.svelte +260 -0
- package/dist/components/scroll/ScrollButton.svelte.d.ts +61 -0
- package/dist/components/scroll/ScrollMore.svelte +57 -0
- package/dist/components/scroll/ScrollMore.svelte.d.ts +28 -0
- package/dist/components/scroll/ScrollToTop.svelte +57 -0
- package/dist/components/scroll/ScrollToTop.svelte.d.ts +22 -0
- package/dist/css/atoms.css +13 -9
- package/dist/css/base.css +1 -2
- package/dist/css/effects.css +259 -16
- package/dist/css/tokens.css +99 -72
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/lib/dates.d.ts +38 -5
- package/dist/lib/dates.js +88 -19
- package/dist/lib/edge-glow.d.ts +11 -0
- package/dist/lib/edge-glow.js +251 -0
- package/package.json +5 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
/**
|
|
3
3
|
* One month of days to pick from: the grid inside DatePicker and DateRangePicker (use those; this is their part).
|
|
4
|
-
* Days are ISO strings ('2026-11-18'), see lib/dates.js.
|
|
4
|
+
* Days are ISO strings ('2026-11-18'), see lib/dates.js.
|
|
5
5
|
*
|
|
6
6
|
* <Calendar bind:month bind:focus selected={[value]} onpick={(day) => (value = day)} label="Start date" />
|
|
7
7
|
*
|
|
@@ -14,19 +14,25 @@
|
|
|
14
14
|
* min, max: the first and last day that can be picked; others show but can't be picked.
|
|
15
15
|
* allowed: the only days that can be picked (within min and max), or null for every day.
|
|
16
16
|
* onpick(day). onpoint(day): the day under the pointer or focus, for a range picker's preview.
|
|
17
|
+
* A hairline runs down the grid where the workdays meet the weekend (the user's locale's, Saturday and Sunday by
|
|
18
|
+
* default).
|
|
19
|
+
* weekStart: the day weeks start on, 1 Monday (the default) … 7 Sunday, or 'locale' for the user's locale's first day.
|
|
17
20
|
* autofocus: take the focus (on `focus`) when it appears. label: names the grid with the month.
|
|
18
|
-
* The previous / next arrows stop at the first and last page holding a day that can be picked.
|
|
21
|
+
* The previous / next arrows stop at the first and last page holding a day that can be picked. The mouse wheel or a
|
|
22
|
+
* trackpad turns the pages too (down: next, up: previous), with the same stops.
|
|
19
23
|
* Keyboard, as the ARIA date picker grid: arrows move a day or a week, Home / End to the week's ends, PageUp /
|
|
20
24
|
* PageDown a month (with Shift a year), Enter or Space picks. Moving past the month turns the page.
|
|
21
|
-
* The month and the year in the head are
|
|
22
|
-
* years
|
|
23
|
-
*
|
|
25
|
+
* The month and the year in the head are dropdowns (Select, ghost): the months that hold a day that can be picked,
|
|
26
|
+
* and the years from min to max (without them, 3 years back to 1 ahead, and the year shown when it is further), with
|
|
27
|
+
* a search field when there are more than 8. Picking a year whose
|
|
28
|
+
* month has nothing to pick moves to its nearest month that does. Keyboard in them: as Select's.
|
|
24
29
|
*/
|
|
25
|
-
import { tick } from 'svelte'
|
|
30
|
+
import { tick, untrack } from 'svelte'
|
|
26
31
|
import Button from '../Button.svelte'
|
|
27
32
|
import DashOutline from '../DashOutline.svelte'
|
|
28
|
-
import
|
|
29
|
-
import {
|
|
33
|
+
import Select from './Select.svelte'
|
|
34
|
+
import { durations, motion } from '../../lib/motion.js'
|
|
35
|
+
import { addDays, addMonths, firstDayOfWeek, weekday, weekendDays, monthGrid, monthOf, formatMonth, parse, speakDay, weekdayNames, within, today, compare } from '../../lib/dates.js'
|
|
30
36
|
|
|
31
37
|
/**
|
|
32
38
|
* @typedef {object} Props
|
|
@@ -40,6 +46,7 @@
|
|
|
40
46
|
* @property {string[] | null} [allowed]
|
|
41
47
|
* @property {(day: string) => void} onpick
|
|
42
48
|
* @property {(day: string) => void} [onpoint]
|
|
49
|
+
* @property {number | 'locale'} [weekStart]
|
|
43
50
|
* @property {boolean} [autofocus]
|
|
44
51
|
* @property {string} [label]
|
|
45
52
|
*/
|
|
@@ -55,14 +62,20 @@
|
|
|
55
62
|
allowed = null,
|
|
56
63
|
onpick,
|
|
57
64
|
onpoint,
|
|
65
|
+
weekStart = 1,
|
|
58
66
|
autofocus = false,
|
|
59
67
|
label = '',
|
|
60
68
|
} = $props()
|
|
61
69
|
|
|
62
70
|
const uid = $props.id()
|
|
63
71
|
const now = today()
|
|
64
|
-
const weeks = $derived(monthGrid(month))
|
|
72
|
+
const weeks = $derived(monthGrid(month, weekStart === 'locale' ? firstDayOfWeek() : weekStart))
|
|
65
73
|
const names = $derived(weekdayNames(weeks[0]))
|
|
74
|
+
const weekend = new Set(weekendDays())
|
|
75
|
+
/** Per column: whether it is a weekend day (as Intl numbers them, Sunday 7). */
|
|
76
|
+
const weekendCols = $derived(weeks[0].map((day) => weekend.has(weekday(day) || 7)))
|
|
77
|
+
/** Whether a hairline runs down a column's start: where the workdays and the weekend meet. @param {number} col */
|
|
78
|
+
const split = (col) => col > 0 && weekendCols[col] !== weekendCols[col - 1]
|
|
66
79
|
const span = $derived(range ? range.toSorted(compare) : null)
|
|
67
80
|
/** Days since the epoch, for counting the days in a range. @param {string} day */
|
|
68
81
|
const dayNumber = (day) => Date.parse(day) / 864e5
|
|
@@ -113,11 +126,120 @@
|
|
|
113
126
|
/** @type {HTMLDivElement | undefined} */
|
|
114
127
|
let root = $state()
|
|
115
128
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
/*
|
|
130
|
+
* Turning the page scrolls the grid, as one strip of weeks. Two months next to each other share a week or two: those
|
|
131
|
+
* glide from where they were to where they are now, the weeks leaving fade out under the day names and the new ones
|
|
132
|
+
* slide in. A jump with no week in common (another month or year picked) slides by the whole grid, the way the months
|
|
133
|
+
* run: a later month comes up from below, an earlier one down from above.
|
|
134
|
+
* The strip is two copies of the grid (the old one, copied before the update, and the new one) in a clipped layer
|
|
135
|
+
* over the real grid, which stays in place, unseen (opacity, so its focus stays), for keys and the pointer. Another
|
|
136
|
+
* turn mid-way cuts it short and starts again from the real grid. Nothing under reduced motion.
|
|
137
|
+
*/
|
|
138
|
+
/** The page shown ('2026-11-01'). */
|
|
139
|
+
const pageKey = () => monthOf(month)
|
|
140
|
+
/** The grid the page is drawn in (the days' tbody). */
|
|
141
|
+
const grid = () => /** @type {HTMLElement | null | undefined} */ (root?.querySelector('[data-page]'))
|
|
142
|
+
/** Where each cell of a grid sits, by its data-key. @param {HTMLElement} page */
|
|
143
|
+
const cellTops = (page) => new Map([...page.querySelectorAll('[data-key]')].map((cell) => [cell.getAttribute('data-key'), cell.getBoundingClientRect().top]))
|
|
144
|
+
/** A copy of a grid to lay in the layer: a tbody inside a copy of its table (no rows), anything else on its own.
|
|
145
|
+
* @param {HTMLElement} page */
|
|
146
|
+
function copyOf(page) {
|
|
147
|
+
const copy = /** @type {HTMLElement} */ (page.cloneNode(true))
|
|
148
|
+
copy.style.opacity = ''
|
|
149
|
+
if (page.tagName !== 'TBODY') return copy
|
|
150
|
+
const shell = /** @type {HTMLElement} */ (/** @type {HTMLElement} */ (page.parentElement).cloneNode(false))
|
|
151
|
+
shell.append(copy)
|
|
152
|
+
return shell
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** The page before it turned: its key, a copy of its grid, and where its cells sat. */
|
|
156
|
+
/** @type {{ key: string, copy: HTMLElement, tops: Map<string | null, number> } | null} */
|
|
157
|
+
let before = null
|
|
158
|
+
/** The turn playing now, to cut short. @type {{ layer: HTMLElement, page: HTMLElement } | null} */
|
|
159
|
+
let turning = null
|
|
160
|
+
/** The page the grid shows, as of the last update (by the time the pre-effect runs, the state is already the next). */
|
|
161
|
+
/** @type {string | null} */
|
|
162
|
+
let shown = null
|
|
163
|
+
|
|
164
|
+
function settle() {
|
|
165
|
+
if (!turning) return
|
|
166
|
+
turning.layer.remove()
|
|
167
|
+
turning.page.style.opacity = ''
|
|
168
|
+
turning = null
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Before the DOM updates for a new page: copy the grid as it still is.
|
|
172
|
+
$effect.pre(() => {
|
|
173
|
+
pageKey()
|
|
174
|
+
untrack(() => {
|
|
175
|
+
settle()
|
|
176
|
+
const page = grid()
|
|
177
|
+
before = shown && page ? { key: shown, copy: copyOf(page), tops: cellTops(page) } : null
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
$effect(() => {
|
|
181
|
+
const key = pageKey()
|
|
182
|
+
untrack(() => {
|
|
183
|
+
scrollPage(key)
|
|
184
|
+
shown = key
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
/** @param {string} key the page now shown */
|
|
189
|
+
function scrollPage(key) {
|
|
190
|
+
const from = before
|
|
191
|
+
before = null
|
|
192
|
+
const page = grid()
|
|
193
|
+
const duration = motion(durations.medium1)
|
|
194
|
+
if (!from || from.key === key || !page || !root || !duration) return
|
|
195
|
+
// How far the strip moved: by a cell both pages show (the new page's first, or the old page's first), else by the
|
|
196
|
+
// whole grid and the gap between its rows, in the direction the pages run.
|
|
197
|
+
const tops = cellTops(page)
|
|
198
|
+
const [first] = tops.keys()
|
|
199
|
+
const [oldFirst] = from.tops.keys()
|
|
200
|
+
const gap = parseFloat(getComputedStyle(page).rowGap) || 0
|
|
201
|
+
const forward = from.key < key
|
|
202
|
+
const shift = from.tops.has(first)
|
|
203
|
+
? /** @type {number} */ (from.tops.get(first)) - /** @type {number} */ (tops.get(first))
|
|
204
|
+
: tops.has(oldFirst)
|
|
205
|
+
? /** @type {number} */ (from.tops.get(oldFirst)) - /** @type {number} */ (tops.get(oldFirst))
|
|
206
|
+
: (forward ? 1 : -1) * (page.offsetHeight + gap)
|
|
207
|
+
if (!shift) return
|
|
208
|
+
|
|
209
|
+
const box = root.getBoundingClientRect()
|
|
210
|
+
const area = page.getBoundingClientRect()
|
|
211
|
+
const layer = document.createElement('div')
|
|
212
|
+
layer.setAttribute('aria-hidden', 'true')
|
|
213
|
+
layer.inert = true
|
|
214
|
+
Object.assign(layer.style, {
|
|
215
|
+
position: 'absolute',
|
|
216
|
+
left: `${area.left - box.left}px`,
|
|
217
|
+
top: `${area.top - box.top}px`,
|
|
218
|
+
width: `${area.width}px`,
|
|
219
|
+
height: `${area.height}px`,
|
|
220
|
+
overflow: 'clip',
|
|
221
|
+
pointerEvents: 'none',
|
|
222
|
+
})
|
|
223
|
+
/** Lays a copy at the top of the layer. @param {HTMLElement} copy */
|
|
224
|
+
const strip = (copy) => {
|
|
225
|
+
Object.assign(copy.style, { position: 'absolute', top: '0', left: '0', width: '100%', margin: '0' })
|
|
226
|
+
layer.append(copy)
|
|
227
|
+
return copy
|
|
228
|
+
}
|
|
229
|
+
const old = strip(from.copy)
|
|
230
|
+
const now = strip(copyOf(page))
|
|
231
|
+
root.append(layer)
|
|
232
|
+
page.style.opacity = '0'
|
|
233
|
+
const run = { layer, page }
|
|
234
|
+
turning = run
|
|
235
|
+
// M3's standard curve (easings.standard.standard): the pages begin and end on screen.
|
|
236
|
+
const timing = { duration, easing: 'cubic-bezier(0.2, 0, 0, 1)' }
|
|
237
|
+
old.animate([{ translate: '0 0', opacity: 1 }, { translate: `0 ${-shift}px`, opacity: 0 }], timing)
|
|
238
|
+
now.animate([{ translate: `0 ${shift}px` }, { translate: '0 0' }], timing).finished.then(
|
|
239
|
+
() => turning === run && settle(),
|
|
240
|
+
() => {},
|
|
241
|
+
)
|
|
242
|
+
}
|
|
121
243
|
|
|
122
244
|
/** @param {string} day */
|
|
123
245
|
const yearOf = (day) => Number(day.slice(0, 4))
|
|
@@ -134,8 +256,6 @@
|
|
|
134
256
|
.formatToParts(parse(month) ?? undefined)
|
|
135
257
|
.filter((part) => part.type === 'month' || part.type === 'year'),
|
|
136
258
|
)
|
|
137
|
-
const years = $derived(Array.from({ length: 12 }, (_y, i) => yearsFrom + i))
|
|
138
|
-
|
|
139
259
|
/** The focus day moved into month m (0–11) of year y, keeping its day where that month has it. @param {number} y @param {number} m */
|
|
140
260
|
const dayIn = (y, m) => addMonths(focus, (y - yearOf(focus)) * 12 + m - monthIndex(focus))
|
|
141
261
|
/** Whether any day of month m (0–11) of year y can be picked. @param {number} y @param {number} m */
|
|
@@ -147,56 +267,33 @@
|
|
|
147
267
|
/** @param {number} y */
|
|
148
268
|
const yearOpen = (y) => (open ? open.some((day) => day.startsWith(`${y}-`)) : true) && !(max && `${y}-01-01` > max) && !(min && `${y}-12-31` < min)
|
|
149
269
|
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
270
|
+
/** The months of the shown year that hold a day to pick (and the shown one), for the month dropdown. */
|
|
271
|
+
const monthOptions = $derived(
|
|
272
|
+
monthNames.map((name, m) => ({ value: m, label: name.long })).filter(({ value: m }) => m === monthIndex(month) || monthOpen(yearOf(month), m)),
|
|
273
|
+
)
|
|
274
|
+
/** The years from min to max (without them, 3 back and 1 ahead, stretched to the year shown) that hold a day to pick,
|
|
275
|
+
* for the year dropdown. */
|
|
276
|
+
const yearOptions = $derived.by(() => {
|
|
277
|
+
const shown = yearOf(month)
|
|
278
|
+
const first = min ? yearOf(min) : Math.min(yearOf(now) - 3, shown)
|
|
279
|
+
const last = max ? yearOf(max) : Math.max(yearOf(now) + 1, shown)
|
|
280
|
+
return Array.from({ length: Math.max(0, last - first + 1) }, (_y, i) => first + i)
|
|
281
|
+
.filter((y) => y === shown || yearOpen(y))
|
|
282
|
+
.map((y) => ({ value: y, label: String(y) }))
|
|
283
|
+
})
|
|
162
284
|
|
|
163
285
|
/** @param {number} m */
|
|
164
286
|
function pickMonth(m) {
|
|
165
|
-
if (!monthOpen(yearOf(month), m)) return
|
|
166
287
|
focus = dayIn(yearOf(month), m)
|
|
167
288
|
month = monthOf(focus)
|
|
168
|
-
void showView('days')
|
|
169
289
|
}
|
|
170
|
-
/** @param {number} y */
|
|
290
|
+
/** Moves to year y, in the same month, or the nearest one that holds a day to pick. @param {number} y */
|
|
171
291
|
function pickYear(y) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** Moves the focus in the months or years grid (n months), paging the years along. @param {number} n */
|
|
179
|
-
async function moveCell(n) {
|
|
180
|
-
focus = addMonths(focus, n)
|
|
292
|
+
const want = monthIndex(month)
|
|
293
|
+
const months = [...Array(12).keys()].filter((m) => monthOpen(y, m))
|
|
294
|
+
const m = months.length ? months.reduce((best, m) => (Math.abs(m - want) < Math.abs(best - want) ? m : best)) : want
|
|
295
|
+
focus = dayIn(y, m)
|
|
181
296
|
month = monthOf(focus)
|
|
182
|
-
const y = yearOf(focus)
|
|
183
|
-
if (view === 'years' && (y < yearsFrom || y >= yearsFrom + 12)) yearsFrom += Math.floor((y - yearsFrom) / 12) * 12
|
|
184
|
-
await tick()
|
|
185
|
-
root?.querySelector('[tabindex="0"]')?.focus()
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** @param {KeyboardEvent} e */
|
|
189
|
-
function onCellKey(e) {
|
|
190
|
-
if (e.key === 'Escape') {
|
|
191
|
-
e.preventDefault()
|
|
192
|
-
e.stopPropagation()
|
|
193
|
-
void showView('days')
|
|
194
|
-
return
|
|
195
|
-
}
|
|
196
|
-
const step = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -3, ArrowDown: 3, PageUp: -12, PageDown: 12 }[e.key]
|
|
197
|
-
if (!step) return
|
|
198
|
-
e.preventDefault()
|
|
199
|
-
void moveCell(view === 'years' ? step * 12 : step)
|
|
200
297
|
}
|
|
201
298
|
|
|
202
299
|
/** Moves the focus to a day, turning the page when it lies in another month. @param {string} day */
|
|
@@ -208,28 +305,25 @@
|
|
|
208
305
|
table?.querySelector(`[data-day="${day}"]`)?.focus()
|
|
209
306
|
}
|
|
210
307
|
|
|
211
|
-
/** The arrow buttons turn the page
|
|
308
|
+
/** The arrow buttons turn the page a month and keep the focus; the focus day moves with them. */
|
|
212
309
|
/** @param {number} n */
|
|
213
310
|
async function turn(n) {
|
|
214
311
|
if (!canTurn(n)) return
|
|
215
|
-
const
|
|
216
|
-
|
|
312
|
+
const arrow = root?.querySelector(`[data-turn="${n}"]`)
|
|
313
|
+
const pressed = !!arrow && arrow === document.activeElement
|
|
314
|
+
focus = addMonths(focus, n)
|
|
217
315
|
month = monthOf(focus)
|
|
218
|
-
if (view === 'years') yearsFrom += n * 12
|
|
219
316
|
// Reaching the limit disables the pressed arrow, which drops the focus; hand it to the other one.
|
|
220
|
-
if (!canTurn(n)) {
|
|
317
|
+
if (pressed && !canTurn(n)) {
|
|
221
318
|
await tick()
|
|
222
319
|
root?.querySelector(`[data-turn="${-n}"]`)?.focus()
|
|
223
320
|
}
|
|
224
321
|
}
|
|
225
322
|
/** Whether the page before (-1) or after (1) holds a day that can be picked. @param {number} n */
|
|
226
323
|
function canTurn(n) {
|
|
227
|
-
if (view === 'years') return yearOpen(n < 0 ? yearsFrom - 1 : yearsFrom + 12)
|
|
228
|
-
if (view === 'months') return yearOpen(yearOf(month) + n)
|
|
229
324
|
const next = addMonths(monthOf(month), n)
|
|
230
325
|
return monthOpen(yearOf(next), monthIndex(next))
|
|
231
326
|
}
|
|
232
|
-
const turnLabel = $derived({ days: 'month', months: 'year', years: 'years' }[view])
|
|
233
327
|
|
|
234
328
|
/** @param {KeyboardEvent} e */
|
|
235
329
|
function onkeydown(e) {
|
|
@@ -260,73 +354,62 @@
|
|
|
260
354
|
onpick(day)
|
|
261
355
|
}
|
|
262
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Attachment: the wheel turns the page, down to the next month (as the arrows do) and up to the previous, stopping where they do. The wheel's travel adds up to a notch before a page turns, and a turn
|
|
359
|
+
* waits for the last one's scroll to play out (about four a second), so a trackpad's glide doesn't race through the
|
|
360
|
+
* months. Not passive: the page behind
|
|
361
|
+
* doesn't scroll while the pointer is over the calendar. A pinch (ctrlKey) is left to zoom.
|
|
362
|
+
* @param {HTMLElement} node
|
|
363
|
+
*/
|
|
364
|
+
function wheelTurns(node) {
|
|
365
|
+
let travel = 0
|
|
366
|
+
let last = 0
|
|
367
|
+
/** @param {WheelEvent} e */
|
|
368
|
+
const onwheel = (e) => {
|
|
369
|
+
if (e.ctrlKey || Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return
|
|
370
|
+
e.preventDefault()
|
|
371
|
+
travel += e.deltaMode === WheelEvent.DOM_DELTA_LINE ? e.deltaY * 16 : e.deltaMode === WheelEvent.DOM_DELTA_PAGE ? e.deltaY * 400 : e.deltaY
|
|
372
|
+
// One turn at a time: as long as a turn's scroll plays.
|
|
373
|
+
if (Math.abs(travel) < 50 || e.timeStamp - last < durations.medium1) return
|
|
374
|
+
last = e.timeStamp
|
|
375
|
+
const n = Math.sign(travel)
|
|
376
|
+
travel = 0
|
|
377
|
+
void turn(n)
|
|
378
|
+
}
|
|
379
|
+
node.addEventListener('wheel', onwheel, { passive: false })
|
|
380
|
+
return () => node.removeEventListener('wheel', onwheel)
|
|
381
|
+
}
|
|
382
|
+
|
|
263
383
|
/** Attachment: takes the focus when the calendar appears, if asked to. @param {HTMLTableElement} node */
|
|
264
384
|
function takeFocus(node) {
|
|
265
385
|
if (autofocus) void tick().then(() => node.querySelector('[tabindex="0"]')?.focus())
|
|
266
386
|
}
|
|
267
387
|
</script>
|
|
268
388
|
|
|
269
|
-
<div bind:this={root} class="calendar">
|
|
389
|
+
<div bind:this={root} class="calendar" {@attach wheelTurns}>
|
|
270
390
|
<span id="{uid}-label" class="sr-only">{label}</span>
|
|
271
|
-
<span id="{uid}-month" class="sr-only" aria-live="polite">{
|
|
391
|
+
<span id="{uid}-month" class="sr-only" aria-live="polite">{formatMonth(month)}</span>
|
|
272
392
|
<div class="head">
|
|
273
|
-
<Button iconOnly icon="caretLeft" label="Previous
|
|
393
|
+
<Button iconOnly icon="caretLeft" label="Previous month" data-turn="-1" disabled={!canTurn(-1)} onclick={() => turn(-1)} />
|
|
394
|
+
<!-- The month and the year, in the locale's order. -->
|
|
274
395
|
<span class="title">
|
|
275
|
-
{#
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
{
|
|
279
|
-
{
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
<button type="button" class="pick" {@attach tooltip('Choose year')} onclick={() => showView('years')}>{part.value}</button>
|
|
283
|
-
{/if}
|
|
284
|
-
{/each}
|
|
285
|
-
{/if}
|
|
396
|
+
{#each headParts as part (part.type)}
|
|
397
|
+
{#if part.type === 'month'}
|
|
398
|
+
<Select class="head-pick" ghost hideLabel search={false} id="{uid}-month-pick" label="Month" options={monthOptions} bind:value={() => monthIndex(month), pickMonth} />
|
|
399
|
+
{:else}
|
|
400
|
+
<Select class="head-pick data" ghost hideLabel id="{uid}-year-pick" label="Year" options={yearOptions} bind:value={() => yearOf(month), pickYear} />
|
|
401
|
+
{/if}
|
|
402
|
+
{/each}
|
|
286
403
|
</span>
|
|
287
|
-
<Button iconOnly icon="caretRight" label="Next
|
|
404
|
+
<Button iconOnly icon="caretRight" label="Next month" data-turn="1" disabled={!canTurn(1)} onclick={() => turn(1)} />
|
|
288
405
|
</div>
|
|
289
|
-
{#if view === 'months'}
|
|
290
|
-
<!-- The keys are its buttons' (arrows move between them, Esc goes back to the days). -->
|
|
291
|
-
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
292
|
-
<div class="cells" role="group" aria-labelledby="{uid}-label {uid}-month" onkeydown={onCellKey}>
|
|
293
|
-
{#each monthNames as name, m (m)}
|
|
294
|
-
<button
|
|
295
|
-
type="button"
|
|
296
|
-
class="cell"
|
|
297
|
-
class:chosen={m === monthIndex(month)}
|
|
298
|
-
tabindex={m === monthIndex(focus) ? 0 : -1}
|
|
299
|
-
aria-label="{name.long} {yearOf(month)}"
|
|
300
|
-
aria-current={m === monthIndex(month) ? 'true' : undefined}
|
|
301
|
-
aria-disabled={monthOpen(yearOf(month), m) ? undefined : 'true'}
|
|
302
|
-
onclick={() => pickMonth(m)}>{name.short}</button
|
|
303
|
-
>
|
|
304
|
-
{/each}
|
|
305
|
-
</div>
|
|
306
|
-
{:else if view === 'years'}
|
|
307
|
-
<!-- The keys are its buttons' (arrows move between them, Esc goes back to the days). -->
|
|
308
|
-
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
309
|
-
<div class="cells" role="group" aria-labelledby="{uid}-label {uid}-month" onkeydown={onCellKey}>
|
|
310
|
-
{#each years as y (y)}
|
|
311
|
-
<button
|
|
312
|
-
type="button"
|
|
313
|
-
class="cell data"
|
|
314
|
-
class:chosen={y === yearOf(month)}
|
|
315
|
-
tabindex={y === yearOf(focus) ? 0 : -1}
|
|
316
|
-
aria-current={y === yearOf(month) ? 'true' : undefined}
|
|
317
|
-
aria-disabled={yearOpen(y) ? undefined : 'true'}
|
|
318
|
-
onclick={() => pickYear(y)}>{y}</button
|
|
319
|
-
>
|
|
320
|
-
{/each}
|
|
321
|
-
</div>
|
|
322
|
-
{:else}
|
|
323
406
|
<table bind:this={table} role="grid" aria-labelledby="{uid}-label {uid}-month" {onkeydown} {@attach takeFocus}>
|
|
324
407
|
<thead>
|
|
325
408
|
<tr>
|
|
326
|
-
{#each names as name, i (i)}<th scope="col" abbr={name.long}>{name.short}</th>{/each}
|
|
409
|
+
{#each names as name, i (i)}<th scope="col" abbr={name.long} class:split={split(i)}>{name.short}</th>{/each}
|
|
327
410
|
</tr>
|
|
328
411
|
</thead>
|
|
329
|
-
<tbody>
|
|
412
|
+
<tbody data-page>
|
|
330
413
|
{#each weeks as week (week[0])}
|
|
331
414
|
<tr>
|
|
332
415
|
{#each week as day, col (day)}
|
|
@@ -335,10 +418,11 @@
|
|
|
335
418
|
{@const inRange = !!span && day >= span[0] && day <= span[1]}
|
|
336
419
|
{@const edge = isEnd(day)}
|
|
337
420
|
{@const between = inRange && !edge}
|
|
338
|
-
<td role="gridcell" aria-selected={chosen || inRange}>
|
|
421
|
+
<td role="gridcell" aria-selected={chosen || inRange} class:split={split(col)}>
|
|
339
422
|
<button
|
|
340
423
|
type="button"
|
|
341
424
|
data-day={day}
|
|
425
|
+
data-key={day}
|
|
342
426
|
class="day"
|
|
343
427
|
class:outside={!inMonth}
|
|
344
428
|
class:chosen={chosen || edge}
|
|
@@ -361,7 +445,6 @@
|
|
|
361
445
|
{/each}
|
|
362
446
|
</tbody>
|
|
363
447
|
</table>
|
|
364
|
-
{/if}
|
|
365
448
|
</div>
|
|
366
449
|
|
|
367
450
|
<style>
|
|
@@ -371,87 +454,64 @@
|
|
|
371
454
|
-webkit-user-select: none;
|
|
372
455
|
/* A day's width: the cells sit edge to edge, so a range's outline slices (slice()) line up by it. */
|
|
373
456
|
--day: 32px;
|
|
457
|
+
/* Holds the layer the weeks scroll in as the page turns. */
|
|
458
|
+
position: relative;
|
|
374
459
|
display: grid;
|
|
375
460
|
gap: var(--space-2);
|
|
376
|
-
|
|
461
|
+
/* As wide as the days, whatever the month: the panel keeps its size as the pages turn. */
|
|
462
|
+
width: calc(var(--day) * 7);
|
|
377
463
|
}
|
|
378
464
|
.head {
|
|
379
465
|
display: flex;
|
|
380
466
|
align-items: center;
|
|
381
|
-
|
|
382
|
-
gap: var(--space-2);
|
|
467
|
+
gap: 2px;
|
|
383
468
|
}
|
|
384
469
|
.title {
|
|
470
|
+
flex: 1 1 auto;
|
|
385
471
|
display: flex;
|
|
386
472
|
align-items: center;
|
|
387
473
|
gap: 2px;
|
|
474
|
+
min-width: 0;
|
|
475
|
+
}
|
|
476
|
+
/* The month's dropdown takes the room the year's leaves, so a long month name doesn't widen the head. */
|
|
477
|
+
.title > :global(.field:has(.head-pick:not(.data))) {
|
|
478
|
+
flex: 1 1 0;
|
|
479
|
+
}
|
|
480
|
+
/* The month and year dropdowns: ghost Selects, as tight as the head needs (a Select's button is 120px at least). */
|
|
481
|
+
.title :global(.trigger.head-pick) {
|
|
482
|
+
gap: 6px;
|
|
483
|
+
min-width: 0;
|
|
484
|
+
min-height: 28px;
|
|
485
|
+
padding: 0 4px 0 8px;
|
|
388
486
|
font-weight: var(--w-semibold);
|
|
389
|
-
color: var(--fg);
|
|
390
|
-
}
|
|
391
|
-
.range {
|
|
392
|
-
font-family: var(--font-data);
|
|
393
|
-
font-variant-numeric: tabular-nums;
|
|
394
|
-
}
|
|
395
|
-
.pick {
|
|
396
|
-
min-height: 24px;
|
|
397
|
-
padding: 0 var(--space-1);
|
|
398
|
-
border: 0;
|
|
399
|
-
border-radius: var(--r);
|
|
400
|
-
background: none;
|
|
401
|
-
color: inherit;
|
|
402
|
-
font: inherit;
|
|
403
|
-
transition: background-color var(--dur-fast) var(--ease-out);
|
|
404
|
-
}
|
|
405
|
-
.pick:hover {
|
|
406
|
-
background: var(--control-3);
|
|
407
|
-
}
|
|
408
|
-
.pick:focus-visible,
|
|
409
|
-
.cell:focus-visible {
|
|
410
|
-
outline: 2px solid var(--accent);
|
|
411
|
-
outline-offset: -2px;
|
|
412
|
-
}
|
|
413
|
-
/* Twelve months or years, in the width of the day grid (7 × 32px). */
|
|
414
|
-
.cells {
|
|
415
|
-
display: grid;
|
|
416
|
-
grid-template-columns: repeat(3, 1fr);
|
|
417
|
-
gap: 2px;
|
|
418
|
-
width: 224px;
|
|
419
|
-
}
|
|
420
|
-
.cell {
|
|
421
|
-
min-height: 40px;
|
|
422
|
-
padding: 0;
|
|
423
|
-
border: 0;
|
|
424
|
-
border-radius: var(--r);
|
|
425
|
-
background: none;
|
|
426
|
-
color: var(--fg);
|
|
427
|
-
font: var(--w-medium) 12px var(--font-body);
|
|
428
|
-
transition: background-color var(--dur-fast) var(--ease-out);
|
|
429
487
|
}
|
|
430
|
-
.
|
|
488
|
+
.title :global(.trigger.head-pick.data) {
|
|
431
489
|
font-family: var(--font-data);
|
|
432
490
|
font-variant-numeric: tabular-nums;
|
|
433
491
|
}
|
|
434
|
-
.cell:hover:not([aria-disabled='true']) {
|
|
435
|
-
background: var(--control-3);
|
|
436
|
-
}
|
|
437
|
-
.cell[aria-disabled='true'] {
|
|
438
|
-
color: var(--faint);
|
|
439
|
-
text-decoration: line-through;
|
|
440
|
-
cursor: default;
|
|
441
|
-
}
|
|
442
492
|
table {
|
|
443
493
|
border-collapse: collapse;
|
|
444
494
|
}
|
|
495
|
+
/* A hairline under the day names, across the grid. */
|
|
445
496
|
th {
|
|
446
497
|
width: 32px;
|
|
447
498
|
height: 24px;
|
|
499
|
+
border-bottom: 1px solid var(--line);
|
|
448
500
|
font-size: 11px;
|
|
449
501
|
font-weight: var(--w-medium);
|
|
450
|
-
color: var(--
|
|
502
|
+
color: var(--faint);
|
|
451
503
|
}
|
|
452
504
|
td {
|
|
453
505
|
padding: 1px 0;
|
|
454
506
|
}
|
|
507
|
+
tbody tr:first-child td {
|
|
508
|
+
padding-top: 4px;
|
|
509
|
+
}
|
|
510
|
+
/* A hairline down the grid where the workdays meet the weekend, drawn inside the cell's edge so it takes no width
|
|
511
|
+
(a range's bar and its outline slices stay a day wide); a day's fill (hover, chosen, a range) covers it. */
|
|
512
|
+
.split {
|
|
513
|
+
box-shadow: inset 1px 0 var(--line);
|
|
514
|
+
}
|
|
455
515
|
.day {
|
|
456
516
|
display: grid;
|
|
457
517
|
place-items: center;
|
|
@@ -20,6 +20,7 @@ declare const Calendar: import("svelte").Component<{
|
|
|
20
20
|
allowed?: string[] | null | undefined;
|
|
21
21
|
onpick: (day: string) => void;
|
|
22
22
|
onpoint?: ((day: string) => void) | undefined;
|
|
23
|
+
weekStart?: number | "locale" | undefined;
|
|
23
24
|
autofocus?: boolean | undefined;
|
|
24
25
|
label?: string | undefined;
|
|
25
26
|
}, {}, "focus" | "month">;
|
|
@@ -40,6 +41,7 @@ type Props = {
|
|
|
40
41
|
allowed?: string[] | null | undefined;
|
|
41
42
|
onpick: (day: string) => void;
|
|
42
43
|
onpoint?: ((day: string) => void) | undefined;
|
|
44
|
+
weekStart?: number | "locale" | undefined;
|
|
43
45
|
autofocus?: boolean | undefined;
|
|
44
46
|
label?: string | undefined;
|
|
45
47
|
};
|