@nervure/datetime 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/model.js ADDED
@@ -0,0 +1,280 @@
1
+ // The pick as data: reading a value, writing it back as ISO text, its two instants and its text. No DOM here.
2
+ import { addDays, addMonths, compare, dateText, dayNumber, daysInMonth, fromIsoWeek, isoWeek, monthText, parseDate, parseTime, quarterOf, quarterText, startOfWeek, timeText, weekText, } from "./calendar.js";
3
+ import { instant, offsetText, wallClock } from "./zone.js";
4
+ export const MIDNIGHT = { h: 0, mi: 0, s: 0 };
5
+ export const emptyPick = () => ({ dates: [], times: [MIDNIGHT, MIDNIGHT] });
6
+ /** True when the pick is whole: a range has its two days. */
7
+ export const complete = (pick, mode) => mode === 'range' ? pick.dates.length === 2 : pick.dates.length > 0;
8
+ // ── Reading a value ────────────────────────────────────────────────────────────────────────────────────────────
9
+ /** One date, with its time when the text has one. A text with an offset or `Z` is an instant, read in the zone. */
10
+ function readMoment(value, zone) {
11
+ if (value instanceof Date) {
12
+ if (Number.isNaN(value.getTime()))
13
+ return null;
14
+ const w = wallClock(value.getTime(), zone);
15
+ return { date: { y: w.y, m: w.m, d: w.d }, time: { h: w.h, mi: w.mi, s: w.s } };
16
+ }
17
+ const text = value.trim();
18
+ const date = parseDate(text);
19
+ if (!date)
20
+ return null;
21
+ const rest = text.slice(10);
22
+ if (!rest)
23
+ return { date, time: null };
24
+ if (/(Z|[+-]\d{2}:?\d{2})$/i.test(rest)) {
25
+ const epoch = Date.parse(text);
26
+ return Number.isNaN(epoch) ? null : readMoment(new Date(epoch), zone);
27
+ }
28
+ const time = parseTime(rest.replace(/^[T ]/, '').replace(/\.\d+$/, ''));
29
+ return time ? { date, time } : null;
30
+ }
31
+ /** Reads a value for a mode. An unreadable value gives an empty pick. */
32
+ export function readValue(value, shape) {
33
+ const pick = emptyPick();
34
+ if (value === null || value === undefined || value === '')
35
+ return pick;
36
+ const { mode, zone } = shape;
37
+ if (mode === 'multiple') {
38
+ const list = Array.isArray(value) ? value : [value];
39
+ for (const v of list) {
40
+ const m = typeof v === 'string' || v instanceof Date ? readMoment(v, zone) : null;
41
+ if (m && !pick.dates.some((d) => compare(d, m.date) === 0))
42
+ pick.dates.push(m.date);
43
+ }
44
+ pick.dates.sort(compare);
45
+ return pick;
46
+ }
47
+ if (mode === 'range') {
48
+ const pair = Array.isArray(value)
49
+ ? value
50
+ : typeof value === 'object' && !(value instanceof Date)
51
+ ? [value.start, value.end]
52
+ : [];
53
+ const a = pair[0] ? readMoment(pair[0], zone) : null;
54
+ const b = pair[1] ? readMoment(pair[1], zone) : null;
55
+ if (a && b) {
56
+ const [first, last] = compare(a.date, b.date) <= 0 ? [a, b] : [b, a];
57
+ pick.dates = [first.date, last.date];
58
+ pick.times = [first.time ?? MIDNIGHT, last.time ?? MIDNIGHT];
59
+ }
60
+ return pick;
61
+ }
62
+ if (value instanceof Date || typeof value !== 'string') {
63
+ const m = value instanceof Date ? readMoment(value, zone) : null;
64
+ if (m) {
65
+ pick.dates = [m.date];
66
+ pick.times = [m.time ?? MIDNIGHT, MIDNIGHT];
67
+ }
68
+ return pick;
69
+ }
70
+ const text = value.trim();
71
+ let m;
72
+ if (mode === 'time') {
73
+ const t = parseTime(text);
74
+ if (t) {
75
+ pick.dates = [{ y: 1970, m: 1, d: 1 }];
76
+ pick.times = [t, MIDNIGHT];
77
+ }
78
+ }
79
+ else if (mode === 'week' && (m = /^(\d{4})-W(\d{1,2})$/i.exec(text)))
80
+ pick.dates = [fromIsoWeek(+m[1], +m[2])];
81
+ else if (mode === 'month' && (m = /^(\d{4})-(\d{2})$/.exec(text)) && +m[2] >= 1 && +m[2] <= 12)
82
+ pick.dates = [{ y: +m[1], m: +m[2], d: 1 }];
83
+ else if (mode === 'quarter' && (m = /^(\d{4})-Q([1-4])$/i.exec(text)))
84
+ pick.dates = [{ y: +m[1], m: (+m[2] - 1) * 3 + 1, d: 1 }];
85
+ else if (mode === 'year' && (m = /^(\d{4})$/.exec(text)))
86
+ pick.dates = [{ y: +m[1], m: 1, d: 1 }];
87
+ else {
88
+ const moment = readMoment(text, zone);
89
+ if (moment) {
90
+ pick.dates = [moment.date];
91
+ pick.times = [moment.time ?? MIDNIGHT, MIDNIGHT];
92
+ }
93
+ }
94
+ return pick;
95
+ }
96
+ // ── Writing the value ──────────────────────────────────────────────────────────────────────────────────────────
97
+ function momentText(date, time, shape) {
98
+ if (!shape.time)
99
+ return dateText(date);
100
+ return `${dateText(date)}T${timeText(time, shape.seconds)}${offsetText(instant(date, time, shape.zone), shape.zone)}`;
101
+ }
102
+ /** The pick as ISO text, in the form of its mode. */
103
+ export function writeValue(pick, shape) {
104
+ const [first, last] = pick.dates;
105
+ if (shape.mode === 'multiple')
106
+ return pick.dates.map(dateText);
107
+ if (!first)
108
+ return null;
109
+ switch (shape.mode) {
110
+ case 'range':
111
+ return last
112
+ ? { start: momentText(first, pick.times[0], shape), end: momentText(last, pick.times[1], shape) }
113
+ : null;
114
+ case 'week':
115
+ return weekText(first);
116
+ case 'month':
117
+ return monthText(first);
118
+ case 'quarter':
119
+ return quarterText(first);
120
+ case 'year':
121
+ return String(first.y).padStart(4, '0');
122
+ case 'time':
123
+ return timeText(pick.times[0], shape.seconds);
124
+ default:
125
+ return momentText(first, pick.times[0], shape);
126
+ }
127
+ }
128
+ /** First instant of the pick and the instant just after it. */
129
+ export function bounds(pick, shape) {
130
+ const [first, last] = pick.dates;
131
+ const { mode, zone } = shape;
132
+ if (!first || mode === 'time' || mode === 'multiple' || (mode === 'range' && !last))
133
+ return [null, null];
134
+ const at = (d, t = MIDNIGHT) => new Date(instant(d, t, zone));
135
+ switch (mode) {
136
+ case 'range':
137
+ return shape.time ? [at(first, pick.times[0]), at(last, pick.times[1])] : [at(first), at(addDays(last, 1))];
138
+ case 'week': {
139
+ const monday = startOfWeek(first, 0);
140
+ return [at(monday), at(addDays(monday, 7))];
141
+ }
142
+ case 'month':
143
+ return [at({ ...first, d: 1 }), at(addMonths({ ...first, d: 1 }, 1))];
144
+ case 'quarter': {
145
+ const start = { y: first.y, m: (quarterOf(first.m) - 1) * 3 + 1, d: 1 };
146
+ return [at(start), at(addMonths(start, 3))];
147
+ }
148
+ case 'year':
149
+ return [at({ y: first.y, m: 1, d: 1 }), at({ y: first.y + 1, m: 1, d: 1 })];
150
+ default:
151
+ return shape.time ? [at(first, pick.times[0]), at(first, pick.times[0])] : [at(first), at(addDays(first, 1))];
152
+ }
153
+ }
154
+ // ── Text for the reader ────────────────────────────────────────────────────────────────────────────────────────
155
+ const noon = (d) => new Date(Date.UTC(d.y, d.m - 1, d.d, 12));
156
+ function momentLabel(date, time, shape, custom) {
157
+ if (!shape.time)
158
+ return new Intl.DateTimeFormat(shape.locale, { ...(custom ?? { dateStyle: 'medium' }), timeZone: 'UTC' }).format(noon(date));
159
+ const options = custom ?? {
160
+ dateStyle: 'medium',
161
+ timeStyle: shape.seconds ? 'medium' : 'short',
162
+ };
163
+ return new Intl.DateTimeFormat(shape.locale, { ...options, hour12: shape.hour12, timeZone: shape.zone }).format(instant(date, time, shape.zone));
164
+ }
165
+ /** The pick as the field writes it. */
166
+ export function textOf(pick, shape, labels, custom) {
167
+ const [first, last] = pick.dates;
168
+ if (!first)
169
+ return '';
170
+ const { locale } = shape;
171
+ switch (shape.mode) {
172
+ case 'multiple':
173
+ return pick.dates.map((d) => momentLabel(d, MIDNIGHT, { ...shape, time: false }, custom)).join(', ');
174
+ case 'range':
175
+ return last
176
+ ? `${momentLabel(first, pick.times[0], shape, custom)} – ${momentLabel(last, pick.times[1], shape, custom)}`
177
+ : '';
178
+ case 'week': {
179
+ const w = isoWeek(first);
180
+ return `${labels.week}${w.week} ${w.year}`;
181
+ }
182
+ case 'month':
183
+ return new Intl.DateTimeFormat(locale, {
184
+ ...(custom ?? { month: 'long', year: 'numeric' }),
185
+ timeZone: 'UTC',
186
+ }).format(noon(first));
187
+ case 'quarter':
188
+ return `${labels.quarter}${quarterOf(first.m)} ${first.y}`;
189
+ case 'year':
190
+ return String(first.y);
191
+ case 'time': {
192
+ const t = pick.times[0];
193
+ return new Intl.DateTimeFormat(locale, {
194
+ ...(custom ?? { timeStyle: shape.seconds ? 'medium' : 'short' }),
195
+ hour12: shape.hour12,
196
+ timeZone: 'UTC',
197
+ }).format(Date.UTC(1970, 0, 1, t.h, t.mi, t.s));
198
+ }
199
+ default:
200
+ return momentLabel(first, pick.times[0], shape, custom);
201
+ }
202
+ }
203
+ /** The whole selection: value, instants, zone and text. */
204
+ export function selectionOf(pick, shape, labels, format) {
205
+ const [start, end] = bounds(pick, shape);
206
+ const base = {
207
+ mode: shape.mode,
208
+ value: writeValue(pick, shape),
209
+ start,
210
+ end,
211
+ zone: shape.zone,
212
+ text: textOf(pick, shape, labels, typeof format === 'object' ? format : undefined),
213
+ };
214
+ return typeof format === 'function' && complete(pick, shape.mode) ? { ...base, text: format(base) } : base;
215
+ }
216
+ /** Last day of a month, for the grids. */
217
+ export const lastOfMonth = (y, m) => ({ y, m, d: daysInMonth(y, m) });
218
+ // ── The period mode: tabs that always give a first and a last day ──────────────────────────────────────────────
219
+ const INNER = {
220
+ day: 'date',
221
+ week: 'week',
222
+ month: 'month',
223
+ quarter: 'quarter',
224
+ year: 'year',
225
+ custom: 'range',
226
+ };
227
+ /** The mode a tab of the period block picks with. */
228
+ export const innerMode = (granularity) => INNER[granularity];
229
+ /** First and last day (both included) of a pick, whatever its mode. Null while the pick is not whole. */
230
+ export function spanOf(pick, mode) {
231
+ const [first, last] = pick.dates;
232
+ if (!first || (mode === 'range' && !last))
233
+ return null;
234
+ switch (mode) {
235
+ case 'range':
236
+ return [first, last];
237
+ case 'week': {
238
+ const monday = startOfWeek(first, 0);
239
+ return [monday, addDays(monday, 6)];
240
+ }
241
+ case 'month':
242
+ return [{ ...first, d: 1 }, lastOfMonth(first.y, first.m)];
243
+ case 'quarter': {
244
+ const m = (quarterOf(first.m) - 1) * 3 + 1;
245
+ return [{ y: first.y, m, d: 1 }, lastOfMonth(first.y, m + 2)];
246
+ }
247
+ case 'year':
248
+ return [
249
+ { y: first.y, m: 1, d: 1 },
250
+ { y: first.y, m: 12, d: 31 },
251
+ ];
252
+ default:
253
+ return [first, first];
254
+ }
255
+ }
256
+ /** The tab that fits a first and a last day: a whole year, quarter, month or ISO week, one day, else a free range. */
257
+ export function granularityOf(first, last) {
258
+ if (compare(first, last) === 0)
259
+ return 'day';
260
+ const whole = (months) => first.d === 1 && compare(last, addDays(addMonths({ ...first, d: 1 }, months), -1)) === 0;
261
+ if (first.m === 1 && whole(12))
262
+ return 'year';
263
+ if ((first.m - 1) % 3 === 0 && whole(3))
264
+ return 'quarter';
265
+ if (whole(1))
266
+ return 'month';
267
+ if (compare(first, startOfWeek(first, 0)) === 0 && dayNumber(last) - dayNumber(first) === 6)
268
+ return 'week';
269
+ return 'custom';
270
+ }
271
+ /** The period to compare with: the same days one year before, or as many days just before. */
272
+ export function comparedSpan(first, last, kind) {
273
+ if (kind === 'previousYear')
274
+ return [addMonths(first, -12), addMonths(last, -12)];
275
+ if (kind === 'previousPeriod') {
276
+ const days = dayNumber(last) - dayNumber(first) + 1;
277
+ return [addDays(first, -days), addDays(first, -1)];
278
+ }
279
+ return null;
280
+ }
@@ -0,0 +1,19 @@
1
+ import { type CSSProperties, type ReactElement } from 'react';
2
+ import type { Picker, PickerOptions } from './types.ts';
3
+ export type { Comparison, Granularity, Mode, Picker, PickerOptions, PickerValue, Selection } from './types.ts';
4
+ export interface DateTimePickerProps extends Omit<PickerOptions, 'class'> {
5
+ /** Classes of the text field, or of the box of an inline calendar. */
6
+ className?: string;
7
+ /** Classes of the panel. */
8
+ panelClassName?: string;
9
+ style?: CSSProperties;
10
+ /** Name of the form value (ISO text). */
11
+ name?: string;
12
+ id?: string;
13
+ disabled?: boolean;
14
+ 'aria-label'?: string;
15
+ /** Receives the picker: `open()`, `close()`, `getSelection()`. */
16
+ pickerRef?: (picker: Picker | null) => void;
17
+ }
18
+ /** `<DateTimePicker mode="range" presets value={value} onChange={(s) => setValue(s.value)} />`. */
19
+ export declare function DateTimePicker(props: DateTimePickerProps): ReactElement;
package/dist/react.js ADDED
@@ -0,0 +1,45 @@
1
+ import { createElement, useEffect, useRef } from 'react';
2
+ import { createDatePicker } from "./core.js";
3
+ const same = (a, b) => a === b || JSON.stringify(a) === JSON.stringify(b);
4
+ /** `<DateTimePicker mode="range" presets value={value} onChange={(s) => setValue(s.value)} />`. */
5
+ export function DateTimePicker(props) {
6
+ const { className, panelClassName, style, name, id, disabled, pickerRef, 'aria-label': label, ...options } = props;
7
+ const host = useRef(null);
8
+ const picker = useRef(null);
9
+ const latest = useRef(options);
10
+ latest.current = options;
11
+ const inline = !!options.inline;
12
+ useEffect(() => {
13
+ const p = createDatePicker(host.current, {
14
+ ...latest.current,
15
+ class: panelClassName,
16
+ onChange: (s) => latest.current.onChange?.(s),
17
+ onOpen: () => latest.current.onOpen?.(),
18
+ onClose: () => latest.current.onClose?.(),
19
+ });
20
+ picker.current = p;
21
+ pickerRef?.(p);
22
+ return () => {
23
+ p.destroy();
24
+ picker.current = null;
25
+ pickerRef?.(null);
26
+ };
27
+ // The picker is made once for a field or a box; the other options go through update()
28
+ }, [inline, name]);
29
+ const { value, onChange: _c, onOpen: _o, onClose: _x, ...rest } = options;
30
+ const settings = JSON.stringify(rest, (_, v) => (typeof v === 'function' ? String(v) : v));
31
+ useEffect(() => {
32
+ picker.current?.update({ ...rest, class: panelClassName });
33
+ }, [settings, panelClassName]);
34
+ useEffect(() => {
35
+ const p = picker.current;
36
+ if (p && value !== undefined && !same(p.getValue(), value instanceof Date ? null : value))
37
+ p.setValue(value);
38
+ }, [value instanceof Date ? value.getTime() : JSON.stringify(value)]);
39
+ const ref = (node) => {
40
+ host.current = node;
41
+ };
42
+ return inline
43
+ ? createElement('div', { ref, id, className, style })
44
+ : createElement('input', { ref, id, name, className, style, disabled, type: 'text', 'aria-label': label });
45
+ }
package/dist/style.css ADDED
@@ -0,0 +1,71 @@
1
+ .nv-dt{--nv-dt-accent:#e04f39;--nv-dt-accent-ink:#fff;--nv-dt-bg:#fff;--nv-dt-ink:#1b1f24;--nv-dt-muted:#6b7480;--nv-dt-line:#e3e6ea;--nv-dt-hover:#f1f3f5;--nv-dt-range:color-mix(in srgb,var(--nv-dt-accent) 14%,transparent);--nv-dt-radius:10px;--nv-dt-cell:36px;--nv-dt-font:inherit;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.14);box-sizing:border-box;display:inline-flex;max-width:100%;font-family:var(--nv-dt-font);font-size:14px;line-height:1.3;color:var(--nv-dt-ink);background:var(--nv-dt-bg);border:1px solid var(--nv-dt-line);border-radius:var(--nv-dt-radius);user-select:none;-webkit-user-select:none}
2
+ .nv-dt *,.nv-dt *::before{box-sizing:border-box}
3
+ .nv-dt[data-theme=dark]{--nv-dt-bg:#1c2026;--nv-dt-ink:#eef0f3;--nv-dt-muted:#9aa3ad;--nv-dt-line:#333a43;--nv-dt-hover:#2a3038;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.5)}
4
+ @media (prefers-color-scheme:dark){.nv-dt[data-theme=auto]{--nv-dt-bg:#1c2026;--nv-dt-ink:#eef0f3;--nv-dt-muted:#9aa3ad;--nv-dt-line:#333a43;--nv-dt-hover:#2a3038;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.5)}}
5
+ :root.dark .nv-dt[data-theme=auto],:root[data-theme=dark] .nv-dt[data-theme=auto]{--nv-dt-bg:#1c2026;--nv-dt-ink:#eef0f3;--nv-dt-muted:#9aa3ad;--nv-dt-line:#333a43;--nv-dt-hover:#2a3038;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.5)}
6
+ :root:not(.dark)[data-theme=light] .nv-dt[data-theme=auto]{--nv-dt-bg:#fff;--nv-dt-ink:#1b1f24;--nv-dt-muted:#6b7480;--nv-dt-line:#e3e6ea;--nv-dt-hover:#f1f3f5;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.14)}
7
+ .nv-dt-pop{position:absolute;z-index:1000;box-shadow:var(--nv-dt-shadow)}
8
+ .nv-dt[hidden]{display:none}
9
+ .nv-dt button{font:inherit;color:inherit;background:none;border:0;padding:0;margin:0;cursor:pointer;border-radius:calc(var(--nv-dt-radius) - 4px)}
10
+ .nv-dt button:focus-visible,.nv-dt input:focus-visible,.nv-dt select:focus-visible{outline:2px solid var(--nv-dt-accent);outline-offset:1px}
11
+ .nv-dt button:disabled{cursor:default;opacity:.35}
12
+ .nv-dt-presets{display:flex;flex-direction:column;gap:2px;padding:10px 8px;border-inline-end:1px solid var(--nv-dt-line);min-width:150px}
13
+ .nv-dt-presets button{text-align:start;padding:7px 10px;white-space:nowrap}
14
+ .nv-dt-presets button:hover{background:var(--nv-dt-hover)}
15
+ .nv-dt-presets button[aria-pressed=true]{background:var(--nv-dt-range);color:var(--nv-dt-accent);font-weight:600}
16
+ .nv-dt-vertical{flex-direction:column}
17
+ .nv-dt-vertical .nv-dt-presets{flex-direction:row;flex-wrap:wrap;border-inline-end:0;border-bottom:1px solid var(--nv-dt-line);min-width:0}
18
+ .nv-dt-vertical .nv-dt-months{flex-direction:column}
19
+ .nv-dt-tabs{display:flex;flex-wrap:wrap;gap:2px;padding:3px;background:var(--nv-dt-hover);border-radius:var(--nv-dt-radius)}
20
+ .nv-dt-tabs button{flex:1;padding:6px 10px;white-space:nowrap;text-transform:capitalize;color:var(--nv-dt-muted)}
21
+ .nv-dt-tabs button:hover{color:var(--nv-dt-ink)}
22
+ .nv-dt-tabs button[aria-selected=true]{background:var(--nv-dt-bg);color:var(--nv-dt-ink);font-weight:600;box-shadow:0 1px 3px rgba(0,0,0,.14)}
23
+ .nv-dt-main{display:flex;flex-direction:column;gap:10px;padding:12px;min-width:0}
24
+ .nv-dt-months{display:flex;gap:18px;flex-wrap:wrap}
25
+ .nv-dt-month{display:flex;flex-direction:column;gap:6px}
26
+ .nv-dt-head{display:flex;align-items:center;gap:4px;min-height:32px}
27
+ .nv-dt-title{flex:1;display:flex;justify-content:center;gap:2px;font-weight:600}
28
+ .nv-dt-title button{padding:5px 8px;text-transform:capitalize}
29
+ .nv-dt-title button:hover,.nv-dt-nav:hover{background:var(--nv-dt-hover)}
30
+ .nv-dt-nav{width:32px;height:32px;display:grid;place-items:center;flex:none}
31
+ .nv-dt-nav svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
32
+ .nv-dt[dir=rtl] .nv-dt-nav svg{transform:scaleX(-1)}
33
+ .nv-dt-nav[data-hide]{visibility:hidden}
34
+ .nv-dt-grid{display:grid;grid-template-columns:repeat(7,var(--nv-dt-cell));row-gap:2px}
35
+ .nv-dt-grid[data-weeks]{grid-template-columns:28px repeat(7,var(--nv-dt-cell))}
36
+ .nv-dt-dow,.nv-dt-wk{display:grid;place-items:center;height:28px;font-size:12px;color:var(--nv-dt-muted);text-transform:capitalize}
37
+ .nv-dt-wk{height:var(--nv-dt-cell);font-variant-numeric:tabular-nums}
38
+ .nv-dt-day{height:var(--nv-dt-cell);font-variant-numeric:tabular-nums;position:relative}
39
+ .nv-dt-day:hover:not(:disabled){background:var(--nv-dt-hover)}
40
+ .nv-dt-day.is-out{color:var(--nv-dt-muted);opacity:.55}
41
+ .nv-dt-day.is-today::after{content:"";position:absolute;inset-inline:0;bottom:5px;margin:auto;width:4px;height:4px;border-radius:50%;background:var(--nv-dt-accent)}
42
+ .nv-dt-day.is-in{background:var(--nv-dt-range);border-radius:0}
43
+ .nv-dt-day.is-start,.nv-dt-day.is-end,.nv-dt-day.is-on{background:var(--nv-dt-accent);color:var(--nv-dt-accent-ink);opacity:1}
44
+ .nv-dt-day.is-start:hover,.nv-dt-day.is-end:hover,.nv-dt-day.is-on:hover{background:var(--nv-dt-accent)}
45
+ .nv-dt-day.is-start.is-in{border-start-end-radius:0;border-end-end-radius:0}
46
+ .nv-dt-day.is-end.is-in{border-start-start-radius:0;border-end-start-radius:0}
47
+ .nv-dt-day.is-on.is-today::after,.nv-dt-day.is-start.is-today::after,.nv-dt-day.is-end.is-today::after{background:var(--nv-dt-accent-ink)}
48
+ .nv-dt-day:disabled{text-decoration:line-through}
49
+ .nv-dt-cells{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;min-width:calc(var(--nv-dt-cell) * 7)}
50
+ .nv-dt-cells[data-view=quarters]{grid-template-columns:repeat(2,1fr)}
51
+ .nv-dt-cell{padding:14px 6px;text-transform:capitalize;font-variant-numeric:tabular-nums}
52
+ .nv-dt-cell small{display:block;font-size:11px;color:var(--nv-dt-muted);margin-top:2px;text-transform:none}
53
+ .nv-dt-cell:hover:not(:disabled){background:var(--nv-dt-hover)}
54
+ .nv-dt-cell.is-on{background:var(--nv-dt-accent);color:var(--nv-dt-accent-ink)}
55
+ .nv-dt-cell.is-on small{color:inherit;opacity:.85}
56
+ .nv-dt-cell.is-now{box-shadow:inset 0 0 0 1px var(--nv-dt-accent)}
57
+ .nv-dt-times{display:flex;flex-wrap:wrap;gap:8px 18px;padding-top:10px;border-top:1px solid var(--nv-dt-line)}
58
+ .nv-dt-time{display:flex;align-items:center;gap:4px}
59
+ .nv-dt-time>span:first-child{color:var(--nv-dt-muted);font-size:12px;margin-inline-end:4px}
60
+ .nv-dt-time input{width:46px;height:32px;text-align:center;font:inherit;font-variant-numeric:tabular-nums;color:inherit;background:var(--nv-dt-bg);border:1px solid var(--nv-dt-line);border-radius:calc(var(--nv-dt-radius) - 4px);padding:0;user-select:text;-webkit-user-select:text}
61
+ .nv-dt-time button{height:32px;padding:0 8px;border:1px solid var(--nv-dt-line)}
62
+ .nv-dt-zone{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--nv-dt-muted)}
63
+ .nv-dt-zone select{flex:1;min-width:0;height:30px;font:inherit;color:var(--nv-dt-ink);background:var(--nv-dt-bg);border:1px solid var(--nv-dt-line);border-radius:calc(var(--nv-dt-radius) - 4px);padding:0 6px}
64
+ .nv-dt-foot{display:flex;gap:6px;justify-content:space-between;padding-top:10px;border-top:1px solid var(--nv-dt-line)}
65
+ .nv-dt-foot div{display:flex;gap:6px}
66
+ .nv-dt-foot button{padding:6px 10px}
67
+ .nv-dt-foot button:hover{background:var(--nv-dt-hover)}
68
+ .nv-dt-foot .nv-dt-apply{background:var(--nv-dt-accent);color:var(--nv-dt-accent-ink)}
69
+ .nv-dt-foot .nv-dt-apply:hover{background:var(--nv-dt-accent);filter:brightness(1.08)}
70
+ @media (max-width:520px){.nv-dt{flex-direction:column}.nv-dt-presets{flex-direction:row;flex-wrap:wrap;border-inline-end:0;border-bottom:1px solid var(--nv-dt-line);min-width:0}.nv-dt{--nv-dt-cell:clamp(30px,calc((100vw - 60px)/7),36px)}}
71
+ @media (prefers-reduced-motion:no-preference){.nv-dt-day,.nv-dt-cell,.nv-dt button{transition:background-color .12s,color .12s}}
@@ -0,0 +1 @@
1
+ export declare const pickerCss = "\n.nv-dt{--nv-dt-accent:#e04f39;--nv-dt-accent-ink:#fff;--nv-dt-bg:#fff;--nv-dt-ink:#1b1f24;--nv-dt-muted:#6b7480;--nv-dt-line:#e3e6ea;--nv-dt-hover:#f1f3f5;--nv-dt-range:color-mix(in srgb,var(--nv-dt-accent) 14%,transparent);--nv-dt-radius:10px;--nv-dt-cell:36px;--nv-dt-font:inherit;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.14);box-sizing:border-box;display:inline-flex;max-width:100%;font-family:var(--nv-dt-font);font-size:14px;line-height:1.3;color:var(--nv-dt-ink);background:var(--nv-dt-bg);border:1px solid var(--nv-dt-line);border-radius:var(--nv-dt-radius);user-select:none;-webkit-user-select:none}\n.nv-dt *,.nv-dt *::before{box-sizing:border-box}\n.nv-dt[data-theme=dark]{--nv-dt-bg:#1c2026;--nv-dt-ink:#eef0f3;--nv-dt-muted:#9aa3ad;--nv-dt-line:#333a43;--nv-dt-hover:#2a3038;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.5)}\n@media (prefers-color-scheme:dark){.nv-dt[data-theme=auto]{--nv-dt-bg:#1c2026;--nv-dt-ink:#eef0f3;--nv-dt-muted:#9aa3ad;--nv-dt-line:#333a43;--nv-dt-hover:#2a3038;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.5)}}\n:root.dark .nv-dt[data-theme=auto],:root[data-theme=dark] .nv-dt[data-theme=auto]{--nv-dt-bg:#1c2026;--nv-dt-ink:#eef0f3;--nv-dt-muted:#9aa3ad;--nv-dt-line:#333a43;--nv-dt-hover:#2a3038;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.5)}\n:root:not(.dark)[data-theme=light] .nv-dt[data-theme=auto]{--nv-dt-bg:#fff;--nv-dt-ink:#1b1f24;--nv-dt-muted:#6b7480;--nv-dt-line:#e3e6ea;--nv-dt-hover:#f1f3f5;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.14)}\n.nv-dt-pop{position:absolute;z-index:1000;box-shadow:var(--nv-dt-shadow)}\n.nv-dt[hidden]{display:none}\n.nv-dt button{font:inherit;color:inherit;background:none;border:0;padding:0;margin:0;cursor:pointer;border-radius:calc(var(--nv-dt-radius) - 4px)}\n.nv-dt button:focus-visible,.nv-dt input:focus-visible,.nv-dt select:focus-visible{outline:2px solid var(--nv-dt-accent);outline-offset:1px}\n.nv-dt button:disabled{cursor:default;opacity:.35}\n.nv-dt-presets{display:flex;flex-direction:column;gap:2px;padding:10px 8px;border-inline-end:1px solid var(--nv-dt-line);min-width:150px}\n.nv-dt-presets button{text-align:start;padding:7px 10px;white-space:nowrap}\n.nv-dt-presets button:hover{background:var(--nv-dt-hover)}\n.nv-dt-presets button[aria-pressed=true]{background:var(--nv-dt-range);color:var(--nv-dt-accent);font-weight:600}\n.nv-dt-vertical{flex-direction:column}\n.nv-dt-vertical .nv-dt-presets{flex-direction:row;flex-wrap:wrap;border-inline-end:0;border-bottom:1px solid var(--nv-dt-line);min-width:0}\n.nv-dt-vertical .nv-dt-months{flex-direction:column}\n.nv-dt-tabs{display:flex;flex-wrap:wrap;gap:2px;padding:3px;background:var(--nv-dt-hover);border-radius:var(--nv-dt-radius)}\n.nv-dt-tabs button{flex:1;padding:6px 10px;white-space:nowrap;text-transform:capitalize;color:var(--nv-dt-muted)}\n.nv-dt-tabs button:hover{color:var(--nv-dt-ink)}\n.nv-dt-tabs button[aria-selected=true]{background:var(--nv-dt-bg);color:var(--nv-dt-ink);font-weight:600;box-shadow:0 1px 3px rgba(0,0,0,.14)}\n.nv-dt-main{display:flex;flex-direction:column;gap:10px;padding:12px;min-width:0}\n.nv-dt-months{display:flex;gap:18px;flex-wrap:wrap}\n.nv-dt-month{display:flex;flex-direction:column;gap:6px}\n.nv-dt-head{display:flex;align-items:center;gap:4px;min-height:32px}\n.nv-dt-title{flex:1;display:flex;justify-content:center;gap:2px;font-weight:600}\n.nv-dt-title button{padding:5px 8px;text-transform:capitalize}\n.nv-dt-title button:hover,.nv-dt-nav:hover{background:var(--nv-dt-hover)}\n.nv-dt-nav{width:32px;height:32px;display:grid;place-items:center;flex:none}\n.nv-dt-nav svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}\n.nv-dt[dir=rtl] .nv-dt-nav svg{transform:scaleX(-1)}\n.nv-dt-nav[data-hide]{visibility:hidden}\n.nv-dt-grid{display:grid;grid-template-columns:repeat(7,var(--nv-dt-cell));row-gap:2px}\n.nv-dt-grid[data-weeks]{grid-template-columns:28px repeat(7,var(--nv-dt-cell))}\n.nv-dt-dow,.nv-dt-wk{display:grid;place-items:center;height:28px;font-size:12px;color:var(--nv-dt-muted);text-transform:capitalize}\n.nv-dt-wk{height:var(--nv-dt-cell);font-variant-numeric:tabular-nums}\n.nv-dt-day{height:var(--nv-dt-cell);font-variant-numeric:tabular-nums;position:relative}\n.nv-dt-day:hover:not(:disabled){background:var(--nv-dt-hover)}\n.nv-dt-day.is-out{color:var(--nv-dt-muted);opacity:.55}\n.nv-dt-day.is-today::after{content:\"\";position:absolute;inset-inline:0;bottom:5px;margin:auto;width:4px;height:4px;border-radius:50%;background:var(--nv-dt-accent)}\n.nv-dt-day.is-in{background:var(--nv-dt-range);border-radius:0}\n.nv-dt-day.is-start,.nv-dt-day.is-end,.nv-dt-day.is-on{background:var(--nv-dt-accent);color:var(--nv-dt-accent-ink);opacity:1}\n.nv-dt-day.is-start:hover,.nv-dt-day.is-end:hover,.nv-dt-day.is-on:hover{background:var(--nv-dt-accent)}\n.nv-dt-day.is-start.is-in{border-start-end-radius:0;border-end-end-radius:0}\n.nv-dt-day.is-end.is-in{border-start-start-radius:0;border-end-start-radius:0}\n.nv-dt-day.is-on.is-today::after,.nv-dt-day.is-start.is-today::after,.nv-dt-day.is-end.is-today::after{background:var(--nv-dt-accent-ink)}\n.nv-dt-day:disabled{text-decoration:line-through}\n.nv-dt-cells{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;min-width:calc(var(--nv-dt-cell) * 7)}\n.nv-dt-cells[data-view=quarters]{grid-template-columns:repeat(2,1fr)}\n.nv-dt-cell{padding:14px 6px;text-transform:capitalize;font-variant-numeric:tabular-nums}\n.nv-dt-cell small{display:block;font-size:11px;color:var(--nv-dt-muted);margin-top:2px;text-transform:none}\n.nv-dt-cell:hover:not(:disabled){background:var(--nv-dt-hover)}\n.nv-dt-cell.is-on{background:var(--nv-dt-accent);color:var(--nv-dt-accent-ink)}\n.nv-dt-cell.is-on small{color:inherit;opacity:.85}\n.nv-dt-cell.is-now{box-shadow:inset 0 0 0 1px var(--nv-dt-accent)}\n.nv-dt-times{display:flex;flex-wrap:wrap;gap:8px 18px;padding-top:10px;border-top:1px solid var(--nv-dt-line)}\n.nv-dt-time{display:flex;align-items:center;gap:4px}\n.nv-dt-time>span:first-child{color:var(--nv-dt-muted);font-size:12px;margin-inline-end:4px}\n.nv-dt-time input{width:46px;height:32px;text-align:center;font:inherit;font-variant-numeric:tabular-nums;color:inherit;background:var(--nv-dt-bg);border:1px solid var(--nv-dt-line);border-radius:calc(var(--nv-dt-radius) - 4px);padding:0;user-select:text;-webkit-user-select:text}\n.nv-dt-time button{height:32px;padding:0 8px;border:1px solid var(--nv-dt-line)}\n.nv-dt-zone{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--nv-dt-muted)}\n.nv-dt-zone select{flex:1;min-width:0;height:30px;font:inherit;color:var(--nv-dt-ink);background:var(--nv-dt-bg);border:1px solid var(--nv-dt-line);border-radius:calc(var(--nv-dt-radius) - 4px);padding:0 6px}\n.nv-dt-foot{display:flex;gap:6px;justify-content:space-between;padding-top:10px;border-top:1px solid var(--nv-dt-line)}\n.nv-dt-foot div{display:flex;gap:6px}\n.nv-dt-foot button{padding:6px 10px}\n.nv-dt-foot button:hover{background:var(--nv-dt-hover)}\n.nv-dt-foot .nv-dt-apply{background:var(--nv-dt-accent);color:var(--nv-dt-accent-ink)}\n.nv-dt-foot .nv-dt-apply:hover{background:var(--nv-dt-accent);filter:brightness(1.08)}\n@media (max-width:520px){.nv-dt{flex-direction:column}.nv-dt-presets{flex-direction:row;flex-wrap:wrap;border-inline-end:0;border-bottom:1px solid var(--nv-dt-line);min-width:0}.nv-dt{--nv-dt-cell:clamp(30px,calc((100vw - 60px)/7),36px)}}\n@media (prefers-reduced-motion:no-preference){.nv-dt-day,.nv-dt-cell,.nv-dt button{transition:background-color .12s,color .12s}}\n";
package/dist/styles.js ADDED
@@ -0,0 +1,74 @@
1
+ // The stylesheet of the picker. Everything a designer changes is a CSS variable on `.nv-dt`.
2
+ export const pickerCss = `
3
+ .nv-dt{--nv-dt-accent:#e04f39;--nv-dt-accent-ink:#fff;--nv-dt-bg:#fff;--nv-dt-ink:#1b1f24;--nv-dt-muted:#6b7480;--nv-dt-line:#e3e6ea;--nv-dt-hover:#f1f3f5;--nv-dt-range:color-mix(in srgb,var(--nv-dt-accent) 14%,transparent);--nv-dt-radius:10px;--nv-dt-cell:36px;--nv-dt-font:inherit;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.14);box-sizing:border-box;display:inline-flex;max-width:100%;font-family:var(--nv-dt-font);font-size:14px;line-height:1.3;color:var(--nv-dt-ink);background:var(--nv-dt-bg);border:1px solid var(--nv-dt-line);border-radius:var(--nv-dt-radius);user-select:none;-webkit-user-select:none}
4
+ .nv-dt *,.nv-dt *::before{box-sizing:border-box}
5
+ .nv-dt[data-theme=dark]{--nv-dt-bg:#1c2026;--nv-dt-ink:#eef0f3;--nv-dt-muted:#9aa3ad;--nv-dt-line:#333a43;--nv-dt-hover:#2a3038;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.5)}
6
+ @media (prefers-color-scheme:dark){.nv-dt[data-theme=auto]{--nv-dt-bg:#1c2026;--nv-dt-ink:#eef0f3;--nv-dt-muted:#9aa3ad;--nv-dt-line:#333a43;--nv-dt-hover:#2a3038;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.5)}}
7
+ :root.dark .nv-dt[data-theme=auto],:root[data-theme=dark] .nv-dt[data-theme=auto]{--nv-dt-bg:#1c2026;--nv-dt-ink:#eef0f3;--nv-dt-muted:#9aa3ad;--nv-dt-line:#333a43;--nv-dt-hover:#2a3038;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.5)}
8
+ :root:not(.dark)[data-theme=light] .nv-dt[data-theme=auto]{--nv-dt-bg:#fff;--nv-dt-ink:#1b1f24;--nv-dt-muted:#6b7480;--nv-dt-line:#e3e6ea;--nv-dt-hover:#f1f3f5;--nv-dt-shadow:0 10px 30px rgba(0,0,0,.14)}
9
+ .nv-dt-pop{position:absolute;z-index:1000;box-shadow:var(--nv-dt-shadow)}
10
+ .nv-dt[hidden]{display:none}
11
+ .nv-dt button{font:inherit;color:inherit;background:none;border:0;padding:0;margin:0;cursor:pointer;border-radius:calc(var(--nv-dt-radius) - 4px)}
12
+ .nv-dt button:focus-visible,.nv-dt input:focus-visible,.nv-dt select:focus-visible{outline:2px solid var(--nv-dt-accent);outline-offset:1px}
13
+ .nv-dt button:disabled{cursor:default;opacity:.35}
14
+ .nv-dt-presets{display:flex;flex-direction:column;gap:2px;padding:10px 8px;border-inline-end:1px solid var(--nv-dt-line);min-width:150px}
15
+ .nv-dt-presets button{text-align:start;padding:7px 10px;white-space:nowrap}
16
+ .nv-dt-presets button:hover{background:var(--nv-dt-hover)}
17
+ .nv-dt-presets button[aria-pressed=true]{background:var(--nv-dt-range);color:var(--nv-dt-accent);font-weight:600}
18
+ .nv-dt-vertical{flex-direction:column}
19
+ .nv-dt-vertical .nv-dt-presets{flex-direction:row;flex-wrap:wrap;border-inline-end:0;border-bottom:1px solid var(--nv-dt-line);min-width:0}
20
+ .nv-dt-vertical .nv-dt-months{flex-direction:column}
21
+ .nv-dt-tabs{display:flex;flex-wrap:wrap;gap:2px;padding:3px;background:var(--nv-dt-hover);border-radius:var(--nv-dt-radius)}
22
+ .nv-dt-tabs button{flex:1;padding:6px 10px;white-space:nowrap;text-transform:capitalize;color:var(--nv-dt-muted)}
23
+ .nv-dt-tabs button:hover{color:var(--nv-dt-ink)}
24
+ .nv-dt-tabs button[aria-selected=true]{background:var(--nv-dt-bg);color:var(--nv-dt-ink);font-weight:600;box-shadow:0 1px 3px rgba(0,0,0,.14)}
25
+ .nv-dt-main{display:flex;flex-direction:column;gap:10px;padding:12px;min-width:0}
26
+ .nv-dt-months{display:flex;gap:18px;flex-wrap:wrap}
27
+ .nv-dt-month{display:flex;flex-direction:column;gap:6px}
28
+ .nv-dt-head{display:flex;align-items:center;gap:4px;min-height:32px}
29
+ .nv-dt-title{flex:1;display:flex;justify-content:center;gap:2px;font-weight:600}
30
+ .nv-dt-title button{padding:5px 8px;text-transform:capitalize}
31
+ .nv-dt-title button:hover,.nv-dt-nav:hover{background:var(--nv-dt-hover)}
32
+ .nv-dt-nav{width:32px;height:32px;display:grid;place-items:center;flex:none}
33
+ .nv-dt-nav svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
34
+ .nv-dt[dir=rtl] .nv-dt-nav svg{transform:scaleX(-1)}
35
+ .nv-dt-nav[data-hide]{visibility:hidden}
36
+ .nv-dt-grid{display:grid;grid-template-columns:repeat(7,var(--nv-dt-cell));row-gap:2px}
37
+ .nv-dt-grid[data-weeks]{grid-template-columns:28px repeat(7,var(--nv-dt-cell))}
38
+ .nv-dt-dow,.nv-dt-wk{display:grid;place-items:center;height:28px;font-size:12px;color:var(--nv-dt-muted);text-transform:capitalize}
39
+ .nv-dt-wk{height:var(--nv-dt-cell);font-variant-numeric:tabular-nums}
40
+ .nv-dt-day{height:var(--nv-dt-cell);font-variant-numeric:tabular-nums;position:relative}
41
+ .nv-dt-day:hover:not(:disabled){background:var(--nv-dt-hover)}
42
+ .nv-dt-day.is-out{color:var(--nv-dt-muted);opacity:.55}
43
+ .nv-dt-day.is-today::after{content:"";position:absolute;inset-inline:0;bottom:5px;margin:auto;width:4px;height:4px;border-radius:50%;background:var(--nv-dt-accent)}
44
+ .nv-dt-day.is-in{background:var(--nv-dt-range);border-radius:0}
45
+ .nv-dt-day.is-start,.nv-dt-day.is-end,.nv-dt-day.is-on{background:var(--nv-dt-accent);color:var(--nv-dt-accent-ink);opacity:1}
46
+ .nv-dt-day.is-start:hover,.nv-dt-day.is-end:hover,.nv-dt-day.is-on:hover{background:var(--nv-dt-accent)}
47
+ .nv-dt-day.is-start.is-in{border-start-end-radius:0;border-end-end-radius:0}
48
+ .nv-dt-day.is-end.is-in{border-start-start-radius:0;border-end-start-radius:0}
49
+ .nv-dt-day.is-on.is-today::after,.nv-dt-day.is-start.is-today::after,.nv-dt-day.is-end.is-today::after{background:var(--nv-dt-accent-ink)}
50
+ .nv-dt-day:disabled{text-decoration:line-through}
51
+ .nv-dt-cells{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;min-width:calc(var(--nv-dt-cell) * 7)}
52
+ .nv-dt-cells[data-view=quarters]{grid-template-columns:repeat(2,1fr)}
53
+ .nv-dt-cell{padding:14px 6px;text-transform:capitalize;font-variant-numeric:tabular-nums}
54
+ .nv-dt-cell small{display:block;font-size:11px;color:var(--nv-dt-muted);margin-top:2px;text-transform:none}
55
+ .nv-dt-cell:hover:not(:disabled){background:var(--nv-dt-hover)}
56
+ .nv-dt-cell.is-on{background:var(--nv-dt-accent);color:var(--nv-dt-accent-ink)}
57
+ .nv-dt-cell.is-on small{color:inherit;opacity:.85}
58
+ .nv-dt-cell.is-now{box-shadow:inset 0 0 0 1px var(--nv-dt-accent)}
59
+ .nv-dt-times{display:flex;flex-wrap:wrap;gap:8px 18px;padding-top:10px;border-top:1px solid var(--nv-dt-line)}
60
+ .nv-dt-time{display:flex;align-items:center;gap:4px}
61
+ .nv-dt-time>span:first-child{color:var(--nv-dt-muted);font-size:12px;margin-inline-end:4px}
62
+ .nv-dt-time input{width:46px;height:32px;text-align:center;font:inherit;font-variant-numeric:tabular-nums;color:inherit;background:var(--nv-dt-bg);border:1px solid var(--nv-dt-line);border-radius:calc(var(--nv-dt-radius) - 4px);padding:0;user-select:text;-webkit-user-select:text}
63
+ .nv-dt-time button{height:32px;padding:0 8px;border:1px solid var(--nv-dt-line)}
64
+ .nv-dt-zone{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--nv-dt-muted)}
65
+ .nv-dt-zone select{flex:1;min-width:0;height:30px;font:inherit;color:var(--nv-dt-ink);background:var(--nv-dt-bg);border:1px solid var(--nv-dt-line);border-radius:calc(var(--nv-dt-radius) - 4px);padding:0 6px}
66
+ .nv-dt-foot{display:flex;gap:6px;justify-content:space-between;padding-top:10px;border-top:1px solid var(--nv-dt-line)}
67
+ .nv-dt-foot div{display:flex;gap:6px}
68
+ .nv-dt-foot button{padding:6px 10px}
69
+ .nv-dt-foot button:hover{background:var(--nv-dt-hover)}
70
+ .nv-dt-foot .nv-dt-apply{background:var(--nv-dt-accent);color:var(--nv-dt-accent-ink)}
71
+ .nv-dt-foot .nv-dt-apply:hover{background:var(--nv-dt-accent);filter:brightness(1.08)}
72
+ @media (max-width:520px){.nv-dt{flex-direction:column}.nv-dt-presets{flex-direction:row;flex-wrap:wrap;border-inline-end:0;border-bottom:1px solid var(--nv-dt-line);min-width:0}.nv-dt{--nv-dt-cell:clamp(30px,calc((100vw - 60px)/7),36px)}}
73
+ @media (prefers-reduced-motion:no-preference){.nv-dt-day,.nv-dt-cell,.nv-dt button{transition:background-color .12s,color .12s}}
74
+ `;
@@ -0,0 +1,128 @@
1
+ import type { PeriodName } from './calendar.ts';
2
+ import type { Labels } from './i18n.ts';
3
+ /**
4
+ * What the reader picks.
5
+ * `date`: one day. `range`: a first and a last day. `multiple`: several days. `week`, `month`, `quarter`, `year`:
6
+ * one whole period. `time`: a time of day. Add `time: true` to `date` or `range` to pick the hour too.
7
+ * `period`: a block with tabs (day, week, month, quarter, year, free range) that always gives a first and a last day.
8
+ */
9
+ export type Mode = 'date' | 'range' | 'multiple' | 'week' | 'month' | 'quarter' | 'year' | 'time' | 'period';
10
+ /** The tabs of the `period` mode: what kind of period the reader picks. `custom` is a free range. */
11
+ export type Granularity = 'day' | 'week' | 'month' | 'quarter' | 'year' | 'custom';
12
+ /** What a period is compared with. */
13
+ export type Comparison = 'none' | 'previousPeriod' | 'previousYear';
14
+ /**
15
+ * A value, as ISO 8601 text.
16
+ * `date`: `2026-12-04`, or `2026-12-04T14:30+01:00` with `time: true`. `range`: `{ start, end }`, both included.
17
+ * `multiple`: a list of dates. `week`: `2026-W49`. `month`: `2026-12`. `quarter`: `2026-Q4`. `year`: `2026`. `time`: `14:30`.
18
+ */
19
+ export type PickerValue = string | readonly string[] | {
20
+ readonly start: string;
21
+ readonly end: string;
22
+ } | null;
23
+ /** The pick, ready to use: its ISO value, its two instants and its text for the reader. */
24
+ export interface Selection {
25
+ readonly mode: Mode;
26
+ readonly value: PickerValue;
27
+ /** First instant of the pick, in the zone. Null when nothing is picked, and for `time` and `multiple`. */
28
+ readonly start: Date | null;
29
+ /** The instant just after the pick (exclusive): filter with `start <= t && t < end`. With `time: true`, the picked instant itself. */
30
+ readonly end: Date | null;
31
+ /** IANA name of the zone the pick is read in. */
32
+ readonly zone: string;
33
+ /** The pick as the field shows it. */
34
+ readonly text: string;
35
+ /** `period` mode: the tab the pick was made in. */
36
+ readonly granularity?: Granularity;
37
+ /** `period` mode with `compare`: the period to compare with, its two instants and its first and last day. */
38
+ readonly compare?: {
39
+ readonly with: Comparison;
40
+ readonly start: Date;
41
+ readonly end: Date;
42
+ readonly value: {
43
+ readonly start: string;
44
+ readonly end: string;
45
+ };
46
+ } | null;
47
+ }
48
+ /** A ready-made period of your own. `range` gives the first and last day, from today's date in the zone. */
49
+ export interface CustomPeriod {
50
+ readonly label: string;
51
+ readonly range: (today: string) => readonly [start: string, end: string];
52
+ }
53
+ export interface PickerOptions {
54
+ /** Default `date`. */
55
+ mode?: Mode;
56
+ /** Pick the hour too (`date` and `range`). Default false. */
57
+ time?: boolean;
58
+ /** Show seconds. Default false. */
59
+ seconds?: boolean;
60
+ /** Step of the minutes field. Default 1. */
61
+ minuteStep?: number;
62
+ /** 12-hour clock with AM and PM. Default: what the locale uses. */
63
+ hour12?: boolean;
64
+ value?: PickerValue | Date;
65
+ /** `local` (default), `UTC`, or an IANA name such as `Europe/Paris`. */
66
+ zone?: string;
67
+ /** Zones the reader can switch between; shows a list in the panel. */
68
+ zones?: readonly string[];
69
+ /** BCP 47 tag: `fr`, `de-CH`, `ar-TN`. Default: the language of the page, then of the browser. */
70
+ locale?: string;
71
+ /** Replace words of the picker. */
72
+ labels?: Partial<Omit<Labels, 'periods'>> & {
73
+ periods?: Partial<Labels['periods']>;
74
+ };
75
+ /** First day of the week, 0 Monday to 6 Sunday. Default: what the locale uses. */
76
+ firstDay?: number;
77
+ /** First day that can be picked, `2026-01-01`. */
78
+ min?: string;
79
+ /** Last day that can be picked. */
80
+ max?: string;
81
+ /** Days that cannot be picked: a list of dates, or a function of the date and its weekday (0 Monday to 6 Sunday). */
82
+ disable?: readonly string[] | ((date: string, weekday: number) => boolean);
83
+ /** Months shown side by side, 1 to 3. Default 1, and 2 for `range`. */
84
+ months?: number;
85
+ /** Show ISO week numbers. Default false, true for `week`. */
86
+ weekNumbers?: boolean;
87
+ /** Ready-made periods beside the calendar (`range`): true for the usual ones, or your list. */
88
+ presets?: boolean | readonly (PeriodName | CustomPeriod)[];
89
+ /** `period` mode: the tabs to show, in order. Default: all six. */
90
+ granularities?: readonly Granularity[];
91
+ /** `period` mode: the tab to start on. Default: the one that fits the value, else `month`. */
92
+ granularity?: Granularity;
93
+ /** `period` mode: compare with the previous period or the same period last year. `true` lets the reader choose. */
94
+ compare?: boolean | Comparison;
95
+ /** `horizontal` (default): periods beside the calendar, months side by side. `vertical`: periods above, months stacked. */
96
+ orientation?: 'horizontal' | 'vertical';
97
+ /** Always open, in the page, instead of a panel under the field. Default: true when the target is not a field. */
98
+ inline?: boolean;
99
+ /** Close the panel when the pick is complete. Default true, false with `time`. */
100
+ autoClose?: boolean;
101
+ placeholder?: string;
102
+ /** Accent colour (CSS). Sets `--nv-dt-accent` on the panel. */
103
+ accent?: string;
104
+ /** `auto` (default) follows the page or the system. */
105
+ theme?: 'light' | 'dark' | 'auto';
106
+ /** How the field writes the pick: Intl options, or your function. */
107
+ format?: Intl.DateTimeFormatOptions | ((selection: Selection) => string);
108
+ /** Extra classes on the panel. */
109
+ class?: string;
110
+ onChange?: (selection: Selection) => void;
111
+ onOpen?: () => void;
112
+ onClose?: () => void;
113
+ }
114
+ export interface Picker {
115
+ /** The panel. */
116
+ readonly element: HTMLElement;
117
+ getValue(): PickerValue;
118
+ getSelection(): Selection;
119
+ /** Sets the pick without calling `onChange`. */
120
+ setValue(value: PickerValue | Date): void;
121
+ /** Changes options and draws again: language, zone, mode, limits, colours. */
122
+ update(options: PickerOptions): void;
123
+ open(): void;
124
+ close(): void;
125
+ toggle(): void;
126
+ /** Removes the panel and its listeners. */
127
+ destroy(): void;
128
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};