@cahyo-dimas/freeday 3.8.0 → 3.9.1
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 +126 -0
- package/COMPONENTS.md +112 -29
- package/README.id.md +4 -4
- package/README.md +4 -3
- package/adapters/blazor/FdyDatepicker.razor.cs +15 -1
- package/adapters/blazor/FdyMonthpicker.razor +29 -0
- package/adapters/blazor/FdyMonthpicker.razor.cs +102 -0
- package/adapters/blazor/FdyTable.razor +6 -1
- package/adapters/blazor/FdyTable.razor.cs +33 -0
- package/adapters/core/month-grid.d.ts +116 -0
- package/adapters/core/month-grid.js +234 -0
- package/adapters/react/components/FdyDatepicker.tsx +78 -160
- package/adapters/react/components/FdyMonthpicker.tsx +400 -0
- package/adapters/react/components/FdyTable.tsx +38 -2
- package/adapters/react/components/FdyTableFilter.tsx +13 -1
- package/adapters/react/index.d.ts +5 -1
- package/adapters/react/index.js +1 -0
- package/adapters/react/usePopover.ts +54 -9
- package/adapters/vue/components/FdyDatepicker.vue +72 -159
- package/adapters/vue/components/FdyMonthpicker.vue +387 -0
- package/adapters/vue/components/FdyTable.vue +33 -1
- package/adapters/vue/components/FdyTableFilter.vue +13 -1
- package/adapters/vue/index.d.ts +16 -0
- package/adapters/vue/index.js +1 -0
- package/adapters/vue/usePopover.ts +53 -10
- package/dist/freeday-table.js +64 -5
- package/dist/freeday.bundle.css +31 -6
- package/dist/freeday.css +31 -6
- package/dist/freeday.js +64 -5
- package/docs/agent-onboarding.md +3 -3
- package/docs/getting-started.md +6 -6
- package/docs/integrations.md +22 -4
- package/package.json +2 -2
- package/src/components/app-shell.css +12 -4
- package/src/components/table.css +19 -2
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import type { JSX } from 'react';
|
|
2
|
+
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { usePopover } from '../usePopover';
|
|
4
|
+
import {
|
|
5
|
+
YEARS_PER_PAGE,
|
|
6
|
+
addMonths,
|
|
7
|
+
monthCells as buildMonthCells,
|
|
8
|
+
monthFormatters,
|
|
9
|
+
monthKeyIntent,
|
|
10
|
+
pageLocale,
|
|
11
|
+
parseISOMonth,
|
|
12
|
+
startOfMonth,
|
|
13
|
+
toISOMonth,
|
|
14
|
+
yearCells as buildYearCells,
|
|
15
|
+
yearKeyIntent,
|
|
16
|
+
yearPageStart,
|
|
17
|
+
yearRangeLabel,
|
|
18
|
+
type FdyMonthCell,
|
|
19
|
+
type FdyMonthFormatters,
|
|
20
|
+
type FdyYearCell,
|
|
21
|
+
} from '../../core/month-grid.js';
|
|
22
|
+
|
|
23
|
+
// React port of adapters/vue/components/FdyMonthpicker.vue over freeday's `.fdy-datepicker` /
|
|
24
|
+
// `.fdy-cal__*` classes (see src/components/datepicker.css). Controlled (`value` + `onChange` in
|
|
25
|
+
// place of Vue's `v-model`). The month and year grids come from adapters/core/month-grid.js, the
|
|
26
|
+
// same module FdyDatepicker reads, so the rule has one home.
|
|
27
|
+
//
|
|
28
|
+
// It exists for its SIGNATURE. 3.8.0 answered "we need a month" with `mode="month"` on
|
|
29
|
+
// FdyDatepicker, which left `value: string | null` carrying `YYYY-MM-DD` or `YYYY-MM` depending on
|
|
30
|
+
// a different prop. Here the value has one format, there is no mode to read, and the day grid is
|
|
31
|
+
// absent rather than merely unvisited.
|
|
32
|
+
|
|
33
|
+
/** The one format this component speaks, re-exported so the name has a single home. */
|
|
34
|
+
export type { FdyMonth } from '../../core/month-grid';
|
|
35
|
+
|
|
36
|
+
/** Which grid is on screen. There is no level below months here: that is the component. */
|
|
37
|
+
type CalendarLevel = 'months' | 'years';
|
|
38
|
+
|
|
39
|
+
export interface FdyMonthpickerProps {
|
|
40
|
+
/** The chosen month, ISO `YYYY-MM` (`'2026-10'`). `''`/`null` for empty. One format, always. */
|
|
41
|
+
value: string | null;
|
|
42
|
+
onChange: (value: string) => void;
|
|
43
|
+
/** Earliest selectable month, `YYYY-MM` (a full `YYYY-MM-DD` is read too, as its own month). */
|
|
44
|
+
min?: string;
|
|
45
|
+
/** Latest selectable month. A bound that falls inside a month leaves that month pickable. */
|
|
46
|
+
max?: string;
|
|
47
|
+
/** BCP-47 tag for the month names. Defaults to the page's `<html lang>`, then `en`. */
|
|
48
|
+
locale?: string;
|
|
49
|
+
placeholder?: string;
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
/** Locked/view mode: stays focusable and shows its month, but can't be opened, cleared, or changed. Unlike `disabled`, it keeps tab order and isn't greyed. */
|
|
52
|
+
readonly?: boolean;
|
|
53
|
+
invalid?: boolean;
|
|
54
|
+
describedby?: string;
|
|
55
|
+
id?: string;
|
|
56
|
+
ariaLabelledby?: string;
|
|
57
|
+
/** Show a clear (×) button in the trigger when a month is set, so an optional month can be unset. Calls onChange('') to reset. Off by default. */
|
|
58
|
+
clearable?: boolean;
|
|
59
|
+
/** aria-label for the clear button (when `clearable`). Default 'Clear month'. */
|
|
60
|
+
clearLabel?: string;
|
|
61
|
+
/** aria-labels for the year arrows shown in the month grid. Defaults 'Previous year' / 'Next year'. */
|
|
62
|
+
prevYearLabel?: string;
|
|
63
|
+
nextYearLabel?: string;
|
|
64
|
+
/** aria-label for the title button that drills from the month grid to the year grid. Default 'Choose year'. */
|
|
65
|
+
chooseYearLabel?: string;
|
|
66
|
+
/** aria-labels for the page arrows shown in the year grid. Defaults 'Previous years' / 'Next years'. */
|
|
67
|
+
prevYearsLabel?: string;
|
|
68
|
+
nextYearsLabel?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function FdyMonthpicker(props: FdyMonthpickerProps): JSX.Element {
|
|
72
|
+
const baseId: string = useId();
|
|
73
|
+
const triggerId: string = props.id ?? `${baseId}-trigger`;
|
|
74
|
+
const titleId: string = `${baseId}-title`;
|
|
75
|
+
|
|
76
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
77
|
+
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
78
|
+
const panelRef = useRef<HTMLDivElement>(null);
|
|
79
|
+
const monthRefs = useRef<Record<number, HTMLButtonElement | null>>({});
|
|
80
|
+
const yearRefs = useRef<Record<number, HTMLButtonElement | null>>({});
|
|
81
|
+
// Set by the move/open handlers, consumed by the focus-sync effects below (React's analogue of
|
|
82
|
+
// Vue's `nextTick(focusCell)`).
|
|
83
|
+
const pendingMonthFocusRef = useRef<number | null>(null);
|
|
84
|
+
const pendingYearFocusRef = useRef<number | null>(null);
|
|
85
|
+
|
|
86
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
87
|
+
const [level, setLevel] = useState<CalendarLevel>('months');
|
|
88
|
+
const [focusMonth, setFocusMonth] = useState<number>(0);
|
|
89
|
+
const [focusYear, setFocusYear] = useState<number>(0);
|
|
90
|
+
/** The year the month grid shows, held as its January so the shared helpers can take a Date. */
|
|
91
|
+
const [viewMonth, setViewMonth] = useState<Date>((): Date => startOfMonth(parseISOMonth(props.value) ?? new Date()));
|
|
92
|
+
|
|
93
|
+
// Render the panel in the top layer (popover) so it never gets clipped by a card or scroll
|
|
94
|
+
// container; positions against the trigger.
|
|
95
|
+
usePopover(panelRef, triggerRef, open);
|
|
96
|
+
|
|
97
|
+
// Popover attr for React 18 (JSX may not type it): set once on mount.
|
|
98
|
+
useEffect((): void => {
|
|
99
|
+
panelRef.current?.setAttribute('popover', 'manual');
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
/** Resolved once so every formatter below reads the same tag. */
|
|
103
|
+
const activeLocale: string = props.locale ?? pageLocale();
|
|
104
|
+
const formatters: FdyMonthFormatters = useMemo(
|
|
105
|
+
(): FdyMonthFormatters => monthFormatters(activeLocale),
|
|
106
|
+
[activeLocale],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const selectedDate: Date | null = useMemo((): Date | null => parseISOMonth(props.value), [props.value]);
|
|
110
|
+
const minDate: Date | null = useMemo((): Date | null => parseISOMonth(props.min), [props.min]);
|
|
111
|
+
const maxDate: Date | null = useMemo((): Date | null => parseISOMonth(props.max), [props.max]);
|
|
112
|
+
const isDisabled: boolean = props.disabled === true;
|
|
113
|
+
const isReadonly: boolean = props.readonly === true;
|
|
114
|
+
const isInvalid: boolean = props.invalid === true;
|
|
115
|
+
const displayPlaceholder: string = props.placeholder ?? 'Select month';
|
|
116
|
+
const showClear: boolean = props.clearable === true && selectedDate !== null && !isDisabled && !isReadonly;
|
|
117
|
+
const clearLabelText: string = props.clearLabel ?? 'Clear month';
|
|
118
|
+
const chooseYearLabelText: string = props.chooseYearLabel ?? 'Choose year';
|
|
119
|
+
const prevYearLabelText: string = props.prevYearLabel ?? 'Previous year';
|
|
120
|
+
const nextYearLabelText: string = props.nextYearLabel ?? 'Next year';
|
|
121
|
+
const prevYearsLabelText: string = props.prevYearsLabel ?? 'Previous years';
|
|
122
|
+
const nextYearsLabelText: string = props.nextYearsLabel ?? 'Next years';
|
|
123
|
+
|
|
124
|
+
/* The month named in the page's language, through the same formatter the cells use. This is the
|
|
125
|
+
capability `<input type="month">` cannot be pushed into: it reads the browser. */
|
|
126
|
+
const displayValue: string = selectedDate === null ? displayPlaceholder : formatters.name.format(selectedDate);
|
|
127
|
+
|
|
128
|
+
const monthCells: FdyMonthCell[] = useMemo((): FdyMonthCell[] => buildMonthCells({
|
|
129
|
+
year: viewMonth.getFullYear(),
|
|
130
|
+
selected: selectedDate,
|
|
131
|
+
min: minDate,
|
|
132
|
+
max: maxDate,
|
|
133
|
+
focusMonth,
|
|
134
|
+
formatters,
|
|
135
|
+
}), [viewMonth, selectedDate, minDate, maxDate, focusMonth, formatters]);
|
|
136
|
+
|
|
137
|
+
const yearPage: number = yearPageStart(focusYear);
|
|
138
|
+
|
|
139
|
+
const yearCells: FdyYearCell[] = useMemo((): FdyYearCell[] => buildYearCells({
|
|
140
|
+
pageStart: yearPage,
|
|
141
|
+
selected: selectedDate,
|
|
142
|
+
min: minDate,
|
|
143
|
+
max: maxDate,
|
|
144
|
+
focusYear,
|
|
145
|
+
}), [yearPage, selectedDate, minDate, maxDate, focusYear]);
|
|
146
|
+
|
|
147
|
+
useEffect((): void => {
|
|
148
|
+
if (pendingMonthFocusRef.current === null) return;
|
|
149
|
+
const index: number = pendingMonthFocusRef.current;
|
|
150
|
+
pendingMonthFocusRef.current = null;
|
|
151
|
+
monthRefs.current[index]?.focus();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
useEffect((): void => {
|
|
155
|
+
if (pendingYearFocusRef.current === null) return;
|
|
156
|
+
const year: number = pendingYearFocusRef.current;
|
|
157
|
+
pendingYearFocusRef.current = null;
|
|
158
|
+
yearRefs.current[year]?.focus();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
/** `index` is already 0-11: the wrap lives in `monthKeyIntent`, so it is applied in one place. */
|
|
162
|
+
function moveMonthFocus(index: number, yearDelta: number): void {
|
|
163
|
+
if (yearDelta !== 0) setViewMonth(addMonths(viewMonth, yearDelta * 12));
|
|
164
|
+
setFocusMonth(index);
|
|
165
|
+
pendingMonthFocusRef.current = index;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* A month is the ANSWER here. In FdyDatepicker the same click walks down into the month's days,
|
|
169
|
+
which is the one thing the two components do differently with the shared grid. */
|
|
170
|
+
function pickMonth(index: number): void {
|
|
171
|
+
if (monthCells[index].disabled) return;
|
|
172
|
+
const first: Date = new Date(viewMonth.getFullYear(), index, 1);
|
|
173
|
+
setFocusMonth(index);
|
|
174
|
+
setViewMonth(first);
|
|
175
|
+
props.onChange(toISOMonth(first));
|
|
176
|
+
closePanel(true);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function openYearGrid(): void {
|
|
180
|
+
setFocusYear(viewMonth.getFullYear());
|
|
181
|
+
setLevel('years');
|
|
182
|
+
pendingYearFocusRef.current = viewMonth.getFullYear();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function openMonthGridAt(year: number, month: number): void {
|
|
186
|
+
setViewMonth(new Date(year, month, 1));
|
|
187
|
+
setFocusMonth(month);
|
|
188
|
+
setLevel('months');
|
|
189
|
+
pendingMonthFocusRef.current = month;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/* Picking a year is NAVIGATION and commits nothing: it drops to that year's months, where the
|
|
193
|
+
answer is given. Without this level, reaching a month four years back is four arrow presses per
|
|
194
|
+
year and no pointer route at all. */
|
|
195
|
+
function openYear(year: number): void {
|
|
196
|
+
openMonthGridAt(year, viewMonth.getMonth());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function moveYearFocus(year: number): void {
|
|
200
|
+
setFocusYear(year);
|
|
201
|
+
setViewMonth(new Date(year, viewMonth.getMonth(), 1));
|
|
202
|
+
pendingYearFocusRef.current = year;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function onMonthKeydown(e: React.KeyboardEvent): void {
|
|
206
|
+
const intent = monthKeyIntent(e.key, focusMonth);
|
|
207
|
+
if (intent.action === 'none') return;
|
|
208
|
+
e.preventDefault();
|
|
209
|
+
if (intent.action === 'focus') moveMonthFocus(intent.index, intent.yearDelta);
|
|
210
|
+
else if (intent.action === 'choose') pickMonth(intent.index);
|
|
211
|
+
else closePanel(true);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function onYearKeydown(e: React.KeyboardEvent): void {
|
|
215
|
+
const intent = yearKeyIntent(e.key, focusYear);
|
|
216
|
+
if (intent.action === 'none') return;
|
|
217
|
+
/* stopPropagation as well, matching FdyDatepicker's year grid: the panel is in the top layer
|
|
218
|
+
and a bubbling Escape would otherwise be read a second time by whatever is behind it. */
|
|
219
|
+
e.preventDefault();
|
|
220
|
+
e.stopPropagation();
|
|
221
|
+
if (intent.action === 'focus') moveYearFocus(intent.year);
|
|
222
|
+
else if (intent.action === 'choose') openYear(intent.year);
|
|
223
|
+
else closePanel(true);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Clear (reset to empty). Calls onChange(''), parseISOMonth('') is null, so the placeholder shows.
|
|
227
|
+
function clearValue(): void {
|
|
228
|
+
props.onChange('');
|
|
229
|
+
setOpen(false);
|
|
230
|
+
triggerRef.current?.focus();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function openPanel(): void {
|
|
234
|
+
if (isDisabled || isReadonly || open) return;
|
|
235
|
+
const next: Date = startOfMonth(selectedDate ?? viewMonth);
|
|
236
|
+
setViewMonth(next);
|
|
237
|
+
/* Reopening starts on months. Without this a picker that drilled to the year grid and was
|
|
238
|
+
dismissed would open on years next time, and a keyboard user would land on a grid that
|
|
239
|
+
cannot answer. */
|
|
240
|
+
setLevel('months');
|
|
241
|
+
setFocusMonth(next.getMonth());
|
|
242
|
+
setOpen(true);
|
|
243
|
+
pendingMonthFocusRef.current = next.getMonth();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function closePanel(returnFocus: boolean): void {
|
|
247
|
+
if (!open) return;
|
|
248
|
+
setOpen(false);
|
|
249
|
+
if (returnFocus) triggerRef.current?.focus();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function toggle(): void {
|
|
253
|
+
if (open) closePanel(false);
|
|
254
|
+
else openPanel();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/* A null relatedTarget means focus fell to <body>, which is what happens when the element the
|
|
258
|
+
user just pressed is REMOVED by the click it triggered (drilling into the year grid replaces
|
|
259
|
+
the grid, and with it the cell that had focus). That is not focus leaving the control, and
|
|
260
|
+
closing on it made the panel vanish mid-navigation. A pointer that really lands outside is
|
|
261
|
+
handled by the mousedown listener, which is the reliable path for that case. */
|
|
262
|
+
const onFocusout = (e: React.FocusEvent<HTMLDivElement>): void => {
|
|
263
|
+
const next: EventTarget | null = e.relatedTarget;
|
|
264
|
+
if (next === null) return;
|
|
265
|
+
if (rootRef.current !== null && !(next instanceof Node && rootRef.current.contains(next))) closePanel(false);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// Close when a pointer lands outside the whole control.
|
|
269
|
+
useEffect((): void | (() => void) => {
|
|
270
|
+
if (!open) return;
|
|
271
|
+
const onDocPointerDown = (e: MouseEvent): void => {
|
|
272
|
+
const t: EventTarget | null = e.target;
|
|
273
|
+
if (rootRef.current !== null && t instanceof Node && !rootRef.current.contains(t)) closePanel(false);
|
|
274
|
+
};
|
|
275
|
+
document.addEventListener('mousedown', onDocPointerDown);
|
|
276
|
+
return (): void => document.removeEventListener('mousedown', onDocPointerDown);
|
|
277
|
+
}, [open]);
|
|
278
|
+
|
|
279
|
+
return (
|
|
280
|
+
<div ref={rootRef} className={isInvalid ? 'fdy-datepicker fdy-datepicker--error' : 'fdy-datepicker'} onBlur={onFocusout}>
|
|
281
|
+
<button
|
|
282
|
+
id={triggerId}
|
|
283
|
+
ref={triggerRef}
|
|
284
|
+
type="button"
|
|
285
|
+
className={open ? 'fdy-datepicker__trigger is-open' : 'fdy-datepicker__trigger'}
|
|
286
|
+
aria-haspopup="dialog"
|
|
287
|
+
aria-expanded={open}
|
|
288
|
+
aria-labelledby={props.ariaLabelledby}
|
|
289
|
+
aria-invalid={isInvalid ? 'true' : undefined}
|
|
290
|
+
aria-readonly={isReadonly ? 'true' : undefined}
|
|
291
|
+
aria-describedby={props.describedby}
|
|
292
|
+
disabled={isDisabled}
|
|
293
|
+
onClick={toggle}
|
|
294
|
+
>
|
|
295
|
+
<span className={selectedDate === null ? 'fdy-datepicker__value fdy-datepicker__value--placeholder' : 'fdy-datepicker__value'}>
|
|
296
|
+
{displayValue}
|
|
297
|
+
</span>
|
|
298
|
+
<span className={showClear ? 'fdy-datepicker__icon is-hidden' : 'fdy-datepicker__icon'} aria-hidden="true">
|
|
299
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
|
|
300
|
+
<rect x="3" y="4" width="18" height="18" rx="2"></rect>
|
|
301
|
+
<path d="M16 2v4M8 2v4M3 10h18"></path>
|
|
302
|
+
</svg>
|
|
303
|
+
</span>
|
|
304
|
+
</button>
|
|
305
|
+
{showClear ? (
|
|
306
|
+
<button
|
|
307
|
+
type="button"
|
|
308
|
+
className="fdy-datepicker__clear"
|
|
309
|
+
aria-label={clearLabelText}
|
|
310
|
+
onMouseDown={(e: React.MouseEvent): void => e.preventDefault()}
|
|
311
|
+
onClick={clearValue}
|
|
312
|
+
>
|
|
313
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
|
|
314
|
+
<path d="M18 6 6 18M6 6l12 12"></path>
|
|
315
|
+
</svg>
|
|
316
|
+
</button>
|
|
317
|
+
) : null}
|
|
318
|
+
|
|
319
|
+
<div ref={panelRef} className="fdy-datepicker__panel" role="dialog" aria-modal="false" aria-labelledby={titleId} hidden={!open}>
|
|
320
|
+
{/* ONE head for both levels on purpose: swapping it destroys the very button the user just
|
|
321
|
+
pressed, focus falls to <body>, and the panel's own focusout handler closes it. */}
|
|
322
|
+
<div className="fdy-cal__head">
|
|
323
|
+
<button
|
|
324
|
+
type="button"
|
|
325
|
+
className="fdy-cal__nav"
|
|
326
|
+
aria-label={level === 'years' ? prevYearsLabelText : prevYearLabelText}
|
|
327
|
+
onClick={(): void => {
|
|
328
|
+
if (level === 'years') moveYearFocus(focusYear - YEARS_PER_PAGE);
|
|
329
|
+
else moveMonthFocus(focusMonth, -1);
|
|
330
|
+
}}
|
|
331
|
+
>
|
|
332
|
+
‹
|
|
333
|
+
</button>
|
|
334
|
+
<button
|
|
335
|
+
id={titleId}
|
|
336
|
+
type="button"
|
|
337
|
+
className="fdy-cal__title"
|
|
338
|
+
aria-label={level === 'years' ? undefined : chooseYearLabelText}
|
|
339
|
+
onClick={(): void => {
|
|
340
|
+
if (level === 'years') openMonthGridAt(viewMonth.getFullYear(), viewMonth.getMonth());
|
|
341
|
+
else openYearGrid();
|
|
342
|
+
}}
|
|
343
|
+
>
|
|
344
|
+
{level === 'years' ? yearRangeLabel(yearPage) : String(viewMonth.getFullYear())}
|
|
345
|
+
</button>
|
|
346
|
+
<button
|
|
347
|
+
type="button"
|
|
348
|
+
className="fdy-cal__nav"
|
|
349
|
+
aria-label={level === 'years' ? nextYearsLabelText : nextYearLabelText}
|
|
350
|
+
onClick={(): void => {
|
|
351
|
+
if (level === 'years') moveYearFocus(focusYear + YEARS_PER_PAGE);
|
|
352
|
+
else moveMonthFocus(focusMonth, 1);
|
|
353
|
+
}}
|
|
354
|
+
>
|
|
355
|
+
›
|
|
356
|
+
</button>
|
|
357
|
+
</div>
|
|
358
|
+
{level === 'years' ? (
|
|
359
|
+
<div className="fdy-cal__grid fdy-cal__grid--years" role="grid" aria-labelledby={titleId} onKeyDown={onYearKeydown}>
|
|
360
|
+
{yearCells.map((cell: FdyYearCell): JSX.Element => (
|
|
361
|
+
<button
|
|
362
|
+
key={cell.year}
|
|
363
|
+
ref={(el: HTMLButtonElement | null): void => { yearRefs.current[cell.year] = el; }}
|
|
364
|
+
type="button"
|
|
365
|
+
className={['fdy-cal__year', cell.today ? 'is-today' : '', cell.selected ? 'is-selected' : ''].filter(Boolean).join(' ')}
|
|
366
|
+
role="gridcell"
|
|
367
|
+
aria-label={String(cell.year)}
|
|
368
|
+
aria-selected={cell.selected ? true : undefined}
|
|
369
|
+
disabled={cell.disabled}
|
|
370
|
+
tabIndex={cell.focusable ? 0 : -1}
|
|
371
|
+
onClick={(): void => openYear(cell.year)}
|
|
372
|
+
>
|
|
373
|
+
{cell.year}
|
|
374
|
+
</button>
|
|
375
|
+
))}
|
|
376
|
+
</div>
|
|
377
|
+
) : (
|
|
378
|
+
<div className="fdy-cal__grid fdy-cal__grid--months" role="grid" aria-labelledby={titleId} onKeyDown={onMonthKeydown}>
|
|
379
|
+
{monthCells.map((cell: FdyMonthCell): JSX.Element => (
|
|
380
|
+
<button
|
|
381
|
+
key={cell.index}
|
|
382
|
+
ref={(el: HTMLButtonElement | null): void => { monthRefs.current[cell.index] = el; }}
|
|
383
|
+
type="button"
|
|
384
|
+
className={['fdy-cal__month', cell.today ? 'is-today' : '', cell.selected ? 'is-selected' : ''].filter(Boolean).join(' ')}
|
|
385
|
+
role="gridcell"
|
|
386
|
+
aria-label={cell.ariaLabel}
|
|
387
|
+
aria-selected={cell.selected ? true : undefined}
|
|
388
|
+
disabled={cell.disabled}
|
|
389
|
+
tabIndex={cell.focusable ? 0 : -1}
|
|
390
|
+
onClick={(): void => pickMonth(cell.index)}
|
|
391
|
+
>
|
|
392
|
+
{cell.label}
|
|
393
|
+
</button>
|
|
394
|
+
))}
|
|
395
|
+
</div>
|
|
396
|
+
)}
|
|
397
|
+
</div>
|
|
398
|
+
</div>
|
|
399
|
+
);
|
|
400
|
+
}
|
|
@@ -83,6 +83,13 @@ export interface FdyTableProps<Row extends object> {
|
|
|
83
83
|
* reset to 0 after sort/filter, or a clamp when filtering shrank the set). */
|
|
84
84
|
onPageIndexChange?: (index: number) => void;
|
|
85
85
|
loading?: boolean;
|
|
86
|
+
/** The loading row's text, rendered by this table rather than by the footer. Default `Loading…`.
|
|
87
|
+
* Blazor has carried `LoadingText` all along while the two script adapters wrote the word into
|
|
88
|
+
* the template, so a table in any other language could translate its empty row and not the row
|
|
89
|
+
* right beside it. Defaulted here, like `emptyText` and the four selection strings, and
|
|
90
|
+
* unlike the six footer strings further down, which the footer defaults because the footer is
|
|
91
|
+
* what renders them. */
|
|
92
|
+
loadingText?: string;
|
|
86
93
|
emptyText?: string;
|
|
87
94
|
ariaLabel?: string;
|
|
88
95
|
/** Custom cell renderer; return undefined for a column to use the default text. */
|
|
@@ -128,6 +135,23 @@ export interface FdyTableProps<Row extends object> {
|
|
|
128
135
|
bulkLabel?: string;
|
|
129
136
|
/** Bulk-bar actions (React equivalent of Vue's `bulk-actions` slot). */
|
|
130
137
|
bulkActions?: ReactNode;
|
|
138
|
+
/* The footer's six strings, forwarded to the `FdyTableFooter` this table draws itself. 3.8.0 gave
|
|
139
|
+
* the footer those props and this table passed none of them on, so the hatch reached every footer
|
|
140
|
+
* except the one almost every screen uses, and the documented way out was to switch the footer off
|
|
141
|
+
* and render it yourself: a door that opens only if you stop using the table. Flat props, with the
|
|
142
|
+
* footer's own names, so moving between the two routes moves a prop rather than reshaping it. */
|
|
143
|
+
/** Footer range line, `{from}` `{to}` `{total}` substituted. Default `Showing {from}–{to} of {total}`. */
|
|
144
|
+
infoText?: string;
|
|
145
|
+
/** Footer: the visible word beside the rows-per-page control, which also names it. Default `Rows`. */
|
|
146
|
+
pageSizeLabel?: string;
|
|
147
|
+
/** Footer: accessible name of the pager landmark. Default `Pagination`. */
|
|
148
|
+
paginationLabel?: string;
|
|
149
|
+
/** Footer: accessible name of the previous-page arrow. Default `Previous page`. */
|
|
150
|
+
prevLabel?: string;
|
|
151
|
+
/** Footer: accessible name of the next-page arrow. Default `Next page`. */
|
|
152
|
+
nextLabel?: string;
|
|
153
|
+
/** Footer: accessible name of a numbered page button. `{n}` substituted. Default `Go to page {n}`. */
|
|
154
|
+
pageLabel?: string;
|
|
131
155
|
}
|
|
132
156
|
|
|
133
157
|
export function FdyTable<Row extends object>(props: FdyTableProps<Row>): JSX.Element {
|
|
@@ -419,7 +443,7 @@ export function FdyTable<Row extends object>(props: FdyTableProps<Row>): JSX.Ele
|
|
|
419
443
|
<tbody>
|
|
420
444
|
{props.loading ? (
|
|
421
445
|
<tr>
|
|
422
|
-
<td colSpan={colCount} className="fdy-table__state" role="status">Loading
|
|
446
|
+
<td colSpan={colCount} className="fdy-table__state" role="status">{props.loadingText ?? 'Loading…'}</td>
|
|
423
447
|
</tr>
|
|
424
448
|
) : displayRows.length === 0 ? (
|
|
425
449
|
<tr>
|
|
@@ -469,8 +493,20 @@ export function FdyTable<Row extends object>(props: FdyTableProps<Row>): JSX.Ele
|
|
|
469
493
|
</table>
|
|
470
494
|
</div>
|
|
471
495
|
|
|
496
|
+
{/* The six strings are passed as given, `undefined` included: every default lives in the
|
|
497
|
+
footer, so an omitted prop here is the footer's English and not a second copy of it. */}
|
|
472
498
|
{props.pager !== false && (
|
|
473
|
-
<FdyTableFooter
|
|
499
|
+
<FdyTableFooter
|
|
500
|
+
page={footerPage}
|
|
501
|
+
pageSizes={props.pageSizes}
|
|
502
|
+
infoText={props.infoText}
|
|
503
|
+
pageSizeLabel={props.pageSizeLabel}
|
|
504
|
+
paginationLabel={props.paginationLabel}
|
|
505
|
+
prevLabel={props.prevLabel}
|
|
506
|
+
nextLabel={props.nextLabel}
|
|
507
|
+
pageLabel={props.pageLabel}
|
|
508
|
+
onPageChange={onFooterPage}
|
|
509
|
+
/>
|
|
474
510
|
)}
|
|
475
511
|
</div>
|
|
476
512
|
);
|
|
@@ -26,7 +26,19 @@ export function FdyTableFilter(props: FdyTableFilterProps): JSX.Element {
|
|
|
26
26
|
const panelRef = useRef<HTMLDivElement>(null);
|
|
27
27
|
const [open, setOpen] = useState<boolean>(false);
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
/* Always end-aligned, and not an option the parent can set: the funnel is a 24px button in a
|
|
30
|
+
column header while the panel runs past 200px, so lining up their LEFT edges aligns the panel
|
|
31
|
+
with nothing anybody can see. In the rightmost column, the one this was reported from, the
|
|
32
|
+
panel ran past the page and the viewport clamp parked it 4px off the screen edge. A prop no
|
|
33
|
+
caller would ever set to 'start' is a prop that should not exist. The clamp still catches the
|
|
34
|
+
leftmost column, where an end-aligned panel would hang off the other edge.
|
|
35
|
+
`matchWidth:false` for the other half of the same thought. Every other typed dropdown wants a
|
|
36
|
+
panel at least as wide as the control it hangs off; this one hangs off a 24px icon, and that
|
|
37
|
+
floor is written inline, where it outranks the `min-width:14rem` `.fdy-filter` asks for: the
|
|
38
|
+
panel measured 224px on the raw path and 206 here, and an enum column with short labels would
|
|
39
|
+
have gone narrower still. The choice sits in this component rather than in the hook, because a
|
|
40
|
+
hook that guessed it from the trigger's size would be guessing for the other nine callers too. */
|
|
41
|
+
usePopover(panelRef, triggerRef, open, 'end', false);
|
|
30
42
|
// Popover attr for React 18/19 JSX typing: set once on mount (same as the other components).
|
|
31
43
|
useEffect((): void => {
|
|
32
44
|
panelRef.current?.setAttribute('popover', 'manual');
|
|
@@ -27,9 +27,13 @@ export interface FdyCflSelectDetail { row?: unknown; rows?: unknown[] }
|
|
|
27
27
|
export interface FdyTableChangeDetail { page: number; sort: string | null; query: string }
|
|
28
28
|
|
|
29
29
|
// Re-exports of React components and hooks
|
|
30
|
-
export { usePopover } from './usePopover';
|
|
30
|
+
export { usePopover, type FdyPopoverAlign } from './usePopover';
|
|
31
31
|
export { FdyCombo, type FdyComboProps, type FdyComboOption } from './components/FdyCombo';
|
|
32
32
|
export { FdyDatepicker, type FdyDatepickerProps, type FdyDatepickerMode } from './components/FdyDatepicker';
|
|
33
|
+
/** A picker that answers with a whole month, `YYYY-MM`. Replaces `FdyDatepicker`'s deprecated
|
|
34
|
+
* `mode="month"`, where one prop carried two formats and another prop chose between them. */
|
|
35
|
+
export { FdyMonthpicker, type FdyMonthpickerProps } from './components/FdyMonthpicker';
|
|
36
|
+
export type { FdyMonth } from '../core/month-grid';
|
|
33
37
|
export { FdyDateRange, type FdyDateRangeProps, type DateRangeValue } from './components/FdyDateRange';
|
|
34
38
|
export { FdyAutocomplete, type FdyAutocompleteProps } from './components/FdyAutocomplete';
|
|
35
39
|
export { FdyCascade, type FdyCascadeProps, type CascadeNode } from './components/FdyCascade';
|
package/adapters/react/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { useFreeday } from './useFreeday.js';
|
|
|
2
2
|
export { usePopover } from './usePopover.ts';
|
|
3
3
|
export { FdyCombo } from './components/FdyCombo.tsx';
|
|
4
4
|
export { FdyDatepicker } from './components/FdyDatepicker.tsx';
|
|
5
|
+
export { FdyMonthpicker } from './components/FdyMonthpicker.tsx';
|
|
5
6
|
export { FdyDateRange } from './components/FdyDateRange.tsx';
|
|
6
7
|
export { FdyAutocomplete } from './components/FdyAutocomplete.tsx';
|
|
7
8
|
export { FdyCascade } from './components/FdyCascade.tsx';
|
|
@@ -3,24 +3,56 @@ import { useEffect, type RefObject } from 'react';
|
|
|
3
3
|
// React port of adapters/vue/usePopover.ts. Lifts a dropdown panel into the top layer via the
|
|
4
4
|
// native Popover API so it escapes any ancestor overflow clip (a .fdy-card, a scroll container),
|
|
5
5
|
// then positions it `fixed` against its trigger (flip above when there's no room below; match the
|
|
6
|
-
// trigger width). Degrades to the panel's own
|
|
6
|
+
// trigger width; line either edge up with the trigger's). Degrades to the panel's own
|
|
7
|
+
// [hidden]/absolute CSS where Popover is unavailable.
|
|
7
8
|
|
|
8
9
|
interface PopoverElement extends HTMLElement {
|
|
9
10
|
showPopover(): void;
|
|
10
11
|
hidePopover(): void;
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Which of the panel's edges lines up with the trigger's. `'start'` (the default everywhere it is
|
|
16
|
+
* omitted) puts the panel's LEFT edge on the trigger's left edge, right for an input-shaped
|
|
17
|
+
* dropdown. `'end'` puts its RIGHT edge on the trigger's right edge, which is what a panel much
|
|
18
|
+
* wider than its trigger needs when the trigger sits in a right-hand gutter or a table header.
|
|
19
|
+
* Same two names as the raw path's `place()`, so one concept does not grow a second vocabulary.
|
|
20
|
+
*/
|
|
21
|
+
export type FdyPopoverAlign = 'start' | 'end';
|
|
22
|
+
|
|
13
23
|
const GAP = 4; // ~ --space-1
|
|
14
24
|
const supported: boolean =
|
|
15
25
|
typeof HTMLElement !== 'undefined'
|
|
16
26
|
&& typeof (HTMLElement.prototype as Partial<PopoverElement>).showPopover === 'function';
|
|
17
27
|
|
|
18
|
-
function place(
|
|
19
|
-
|
|
28
|
+
function place(
|
|
29
|
+
panel: HTMLElement,
|
|
30
|
+
trigger: HTMLElement,
|
|
31
|
+
align: FdyPopoverAlign | undefined,
|
|
32
|
+
matchWidth: boolean | undefined,
|
|
33
|
+
): void {
|
|
34
|
+
/* Take the panel out of the flow BEFORE measuring anything. Until this runs the panel is still
|
|
35
|
+
* `position:absolute` with `top:calc(100% + …)` from its component's stylesheet, an author rule
|
|
36
|
+
* outranks the popover UA style, and in the top layer that `100%` resolves against the viewport.
|
|
37
|
+
* So a panel that has just been shown sits one viewport height down the page and drags the
|
|
38
|
+
* document's scrollable overflow with it. Where scrollbars take layout space (every Windows and
|
|
39
|
+
* Linux browser; macOS overlay scrollbars hide it) the document gains a classic scrollbar for the
|
|
40
|
+
* duration, documentElement.clientWidth drops by its width, and the page relays out that much
|
|
41
|
+
* narrower. A trigger rect read in that instant belongs to a layout the next three lines undo:
|
|
42
|
+
* measured 741 instead of 756 for a combo in a 24px gutter, a scrollbar's width to the left. */
|
|
20
43
|
panel.style.position = 'fixed';
|
|
21
44
|
panel.style.margin = '0';
|
|
22
45
|
panel.style.inset = 'auto';
|
|
23
|
-
|
|
46
|
+
const r: DOMRect = trigger.getBoundingClientRect();
|
|
47
|
+
/* The trigger's width as a FLOOR, and `matchWidth !== false` rather than a truthiness test, the
|
|
48
|
+
same spelling the raw `place()` uses. It is what keeps the four input-shaped panels looking
|
|
49
|
+
like one control with its list hanging off it, and it is not cosmetic: `.fdy-combo__listbox`,
|
|
50
|
+
`.fdy-autocomplete__listbox` and `.fdy-cascade__panel` are `min-width:100%`, and once the panel
|
|
51
|
+
is `fixed` in the top layer that 100% is the VIEWPORT, so without this line a 220px combo opens
|
|
52
|
+
a 1000px listbox. A panel whose stylesheet asks for a width of its own opts out instead:
|
|
53
|
+
`.fdy-filter` wants `min-width:14rem` and hangs off a 24px funnel, and an inline floor of 24px
|
|
54
|
+
outranks the rule, which left the typed filter panel 206px wide against the 224 it asked for. */
|
|
55
|
+
if (matchWidth !== false) panel.style.minWidth = `${r.width}px`;
|
|
24
56
|
const ph: number = panel.offsetHeight;
|
|
25
57
|
const pw: number = panel.offsetWidth;
|
|
26
58
|
const vw: number = document.documentElement.clientWidth;
|
|
@@ -28,16 +60,29 @@ function place(panel: HTMLElement, trigger: HTMLElement): void {
|
|
|
28
60
|
const below: number = vh - r.bottom - GAP;
|
|
29
61
|
const above: number = r.top - GAP;
|
|
30
62
|
const top: number = ph <= below || below >= above ? r.bottom + GAP : Math.max(GAP, r.top - GAP - ph);
|
|
31
|
-
let left: number = r.left;
|
|
32
|
-
|
|
63
|
+
let left: number = align === 'end' ? r.right - pw : r.left;
|
|
64
|
+
/* Clamped on BOTH sides, and that is not belt-and-braces: the first line keeps a start-aligned
|
|
65
|
+
panel on screen, the second keeps an end-aligned one on screen when the panel is wider than the
|
|
66
|
+
room to the left of its trigger. Keeping only one of them trades an overflow on one edge for an
|
|
67
|
+
overflow on the other. */
|
|
68
|
+
if (left + pw > vw - GAP) left = vw - GAP - pw;
|
|
69
|
+
if (left < GAP) left = GAP;
|
|
33
70
|
panel.style.top = `${Math.round(top)}px`;
|
|
34
71
|
panel.style.left = `${Math.round(left)}px`;
|
|
35
72
|
}
|
|
36
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Anchor a dropdown `panelRef` to `triggerRef` in the top layer while `open` is true. The panel
|
|
76
|
+
* element must carry `popover="manual"`. `align` and `matchWidth` are plain values, not an options
|
|
77
|
+
* object, so the effect below can list them in its dependencies without a caller having to
|
|
78
|
+
* memoise anything. Omitting them means `'start'` and `true`.
|
|
79
|
+
*/
|
|
37
80
|
export function usePopover(
|
|
38
81
|
panelRef: RefObject<HTMLElement | null>,
|
|
39
82
|
triggerRef: RefObject<HTMLElement | null>,
|
|
40
83
|
open: boolean,
|
|
84
|
+
align?: FdyPopoverAlign,
|
|
85
|
+
matchWidth?: boolean,
|
|
41
86
|
): void {
|
|
42
87
|
useEffect((): void | (() => void) => {
|
|
43
88
|
const panel: PopoverElement | null = panelRef.current as PopoverElement | null;
|
|
@@ -45,12 +90,12 @@ export function usePopover(
|
|
|
45
90
|
if (!supported || panel === null || trigger === null) return;
|
|
46
91
|
|
|
47
92
|
function reposition(): void {
|
|
48
|
-
if (panel !== null && trigger !== null && panel.matches(':popover-open')) place(panel, trigger);
|
|
93
|
+
if (panel !== null && trigger !== null && panel.matches(':popover-open')) place(panel, trigger, align, matchWidth);
|
|
49
94
|
}
|
|
50
95
|
|
|
51
96
|
if (open) {
|
|
52
97
|
if (!panel.matches(':popover-open')) panel.showPopover();
|
|
53
|
-
place(panel, trigger);
|
|
98
|
+
place(panel, trigger, align, matchWidth);
|
|
54
99
|
window.addEventListener('scroll', reposition, true);
|
|
55
100
|
window.addEventListener('resize', reposition);
|
|
56
101
|
return (): void => {
|
|
@@ -60,5 +105,5 @@ export function usePopover(
|
|
|
60
105
|
};
|
|
61
106
|
}
|
|
62
107
|
return;
|
|
63
|
-
}, [open, panelRef, triggerRef]);
|
|
108
|
+
}, [open, panelRef, triggerRef, align, matchWidth]);
|
|
64
109
|
}
|