@finstack-com-public/design 0.8.0 → 0.9.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/CHANGELOG.md +26 -1
- package/dist/css/calendar.css +102 -8
- package/dist/css/calendar.md +134 -2
- package/dist/css-text/calendar.js +1 -1
- package/dist/css-text/kit.js +102 -8
- package/dist/dom/calendar.d.ts +48 -3
- package/dist/dom/calendar.js +262 -46
- package/dist/dom/index.d.ts +1 -1
- package/dist/kit.css +102 -8
- package/dist/react/inputs.d.ts +27 -9
- package/dist/react/inputs.js +85 -11
- package/package.json +1 -1
package/dist/react/inputs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ButtonHTMLAttributes, type HTMLAttributes, type InputHTMLAttributes, type OutputHTMLAttributes, type ReactNode, type RefObject, type SelectHTMLAttributes, type TextareaHTMLAttributes } from 'react';
|
|
2
|
-
import { type CalendarOptions } from '../dom/calendar.ts';
|
|
2
|
+
import { type CalendarOptions, type CalendarRange, type CalendarRangeChangeDetail, type CalendarRangeLabels } from '../dom/calendar.ts';
|
|
3
3
|
type Tone = 'neutral' | 'caution' | 'warning' | 'danger';
|
|
4
4
|
/** What Field hands its control: spread it onto the input. */
|
|
5
5
|
export interface FieldControlProps {
|
|
@@ -77,14 +77,9 @@ export declare const ReadonlyValue: import("react").ForwardRefExoticComponent<HT
|
|
|
77
77
|
export declare const ComputedValue: import("react").ForwardRefExoticComponent<OutputHTMLAttributes<HTMLOutputElement> & import("react").RefAttributes<HTMLOutputElement>>;
|
|
78
78
|
/** A figure that is a button: every explainable value is keyboard-reachable (GZ §6.3). */
|
|
79
79
|
export declare const ExplainableValue: import("react").ForwardRefExoticComponent<ButtonHTMLAttributes<HTMLButtonElement> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
80
|
-
export type { CalendarDay, CalendarLabels, CalendarPage, CalendarView } from '../dom/calendar.ts';
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
value?: string | null;
|
|
84
|
-
/** Uncontrolled: the first value. */
|
|
85
|
-
defaultValue?: string | null;
|
|
86
|
-
/** A lowest-view cell was picked: on every pick, the current value too. */
|
|
87
|
-
onChange?: (value: string) => void;
|
|
80
|
+
export type { CalendarDay, CalendarLabels, CalendarPage, CalendarRange, CalendarRangeChangeDetail, CalendarRangeLabels, CalendarView, } from '../dom/calendar.ts';
|
|
81
|
+
/** The props both calendars take: the options but the value, plus the host's announcer and autoFocus. */
|
|
82
|
+
type CalendarCommonProps = Pick<CalendarOptions, 'min' | 'max' | 'today' | 'granularity' | 'weekStart' | 'months' | 'monthNames' | 'weekdayNames' | 'heading' | 'cellLabel' | 'labels'> & {
|
|
88
83
|
/** The host's one live region (CE §7); without it the calendar keeps its own. */
|
|
89
84
|
announcer?: RefObject<HTMLElement | null>;
|
|
90
85
|
/**
|
|
@@ -92,9 +87,32 @@ export interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onC
|
|
|
92
87
|
* calendar on each open (a new `key`) to start there.
|
|
93
88
|
*/
|
|
94
89
|
autoFocus?: boolean;
|
|
90
|
+
};
|
|
91
|
+
export interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue' | 'children'>, CalendarCommonProps {
|
|
92
|
+
/** Controlled: the picked day (`YYYY-MM-DD`) or month (`YYYY-MM`), or null. */
|
|
93
|
+
value?: string | null;
|
|
94
|
+
/** Uncontrolled: the first value. */
|
|
95
|
+
defaultValue?: string | null;
|
|
96
|
+
/** A lowest-view cell was picked: on every pick, the current value too. */
|
|
97
|
+
onChange?: (value: string) => void;
|
|
95
98
|
}
|
|
96
99
|
/**
|
|
97
100
|
* The calendar (D42): renders the empty `.fs-calendar` root and runs `createCalendar` on mount, which
|
|
98
101
|
* renders the header and the grid. On the server it is the empty root. Every name is a required prop.
|
|
99
102
|
*/
|
|
100
103
|
export declare const Calendar: import("react").ForwardRefExoticComponent<CalendarProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
104
|
+
export interface DateRangeCalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue' | 'children'>, Omit<CalendarCommonProps, 'labels'> {
|
|
105
|
+
/** As `Calendar`'s, plus the words said after a range's first and last cell (required). */
|
|
106
|
+
labels: CalendarRangeLabels;
|
|
107
|
+
/** Controlled: the range (`YYYY-MM-DD` or `YYYY-MM` ends), or null. */
|
|
108
|
+
value?: CalendarRange | null;
|
|
109
|
+
/** Uncontrolled: the first range. */
|
|
110
|
+
defaultValue?: CalendarRange | null;
|
|
111
|
+
/** The second pick set the end: both ends, in order. The first pick (the start) reports nothing. */
|
|
112
|
+
onChange?: (range: CalendarRangeChangeDetail) => void;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The range calendar (T85): `createCalendar` in `mode: 'range'` (D42: one helper), on the same empty
|
|
116
|
+
* root. A pending start lives in the helper: a parent re-rendering the same range keeps it.
|
|
117
|
+
*/
|
|
118
|
+
export declare const DateRangeCalendar: import("react").ForwardRefExoticComponent<DateRangeCalendarProps & import("react").RefAttributes<HTMLDivElement>>;
|
package/dist/react/inputs.js
CHANGED
|
@@ -68,22 +68,20 @@ export const ExplainableValue = forwardRef(function ExplainableValue({ className
|
|
|
68
68
|
return _jsx("button", { ref: ref, type: type, className: cx('fs-value', 'fs-value--explainable', className), ...rest });
|
|
69
69
|
});
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
71
|
+
* Runs `createCalendar` on mount (D42) and `destroy` on unmount; new bounds, names, granularity or
|
|
72
|
+
* months re-render in place, keeping the page and the focus. `heading` and `cellLabel` are called
|
|
73
|
+
* through the latest props, so inline functions cost one grid re-render, not a reset.
|
|
73
74
|
*/
|
|
74
|
-
|
|
75
|
-
const own = useRef(null);
|
|
75
|
+
function useCalendarHelper(own, { min, max, today, granularity, weekStart, months, monthNames, weekdayNames, heading, cellLabel, labels, announcer, autoFocus, }, create) {
|
|
76
76
|
const ctl = useRef(null);
|
|
77
|
-
// The helper calls these through the latest props, so new functions on each render cost nothing.
|
|
78
77
|
const names = useLatest({ heading, cellLabel });
|
|
79
|
-
const latestValue = useLatest(value);
|
|
80
78
|
const set = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
|
|
81
79
|
const options = () => ({
|
|
82
|
-
// Undefined clears a bound or today; granularity and
|
|
80
|
+
// Undefined clears a bound or today; granularity, weekStart and months keep their defaults.
|
|
83
81
|
min,
|
|
84
82
|
max,
|
|
85
83
|
today,
|
|
86
|
-
...set({ granularity, weekStart }),
|
|
84
|
+
...set({ granularity, weekStart, months }),
|
|
87
85
|
monthNames,
|
|
88
86
|
weekdayNames,
|
|
89
87
|
labels,
|
|
@@ -92,7 +90,7 @@ export const Calendar = forwardRef(function Calendar({ value, defaultValue, onCh
|
|
|
92
90
|
announcer: announcer?.current ?? undefined,
|
|
93
91
|
});
|
|
94
92
|
useIsoLayoutEffect(() => {
|
|
95
|
-
ctl.current =
|
|
93
|
+
ctl.current = create(own.current, options());
|
|
96
94
|
if (autoFocus)
|
|
97
95
|
ctl.current.focus();
|
|
98
96
|
return () => {
|
|
@@ -100,10 +98,46 @@ export const Calendar = forwardRef(function Calendar({ value, defaultValue, onCh
|
|
|
100
98
|
ctl.current = null;
|
|
101
99
|
};
|
|
102
100
|
}, []);
|
|
103
|
-
// New bounds, names or granularity: re-render in place, keeping the page and the focus.
|
|
104
101
|
useIsoLayoutEffect(() => {
|
|
102
|
+
// A range calendar's labels are the props' own, so they carry its start and end words.
|
|
105
103
|
ctl.current?.update(options());
|
|
106
|
-
}, [
|
|
104
|
+
}, [
|
|
105
|
+
min,
|
|
106
|
+
max,
|
|
107
|
+
today,
|
|
108
|
+
granularity,
|
|
109
|
+
weekStart,
|
|
110
|
+
months,
|
|
111
|
+
monthNames,
|
|
112
|
+
weekdayNames,
|
|
113
|
+
labels,
|
|
114
|
+
heading,
|
|
115
|
+
cellLabel,
|
|
116
|
+
announcer,
|
|
117
|
+
]);
|
|
118
|
+
return ctl;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The calendar (D42): renders the empty `.fs-calendar` root and runs `createCalendar` on mount, which
|
|
122
|
+
* renders the header and the grid. On the server it is the empty root. Every name is a required prop.
|
|
123
|
+
*/
|
|
124
|
+
export const Calendar = forwardRef(function Calendar({ value, defaultValue, onChange, min, max, today, granularity, weekStart, months, monthNames, weekdayNames, heading, cellLabel, labels, announcer, autoFocus, className, ...rest }, ref) {
|
|
125
|
+
const own = useRef(null);
|
|
126
|
+
const latestValue = useLatest(value);
|
|
127
|
+
const common = {
|
|
128
|
+
min,
|
|
129
|
+
max,
|
|
130
|
+
today,
|
|
131
|
+
granularity,
|
|
132
|
+
weekStart,
|
|
133
|
+
months,
|
|
134
|
+
monthNames,
|
|
135
|
+
weekdayNames,
|
|
136
|
+
heading,
|
|
137
|
+
cellLabel,
|
|
138
|
+
labels,
|
|
139
|
+
};
|
|
140
|
+
const ctl = useCalendarHelper(own, { ...common, announcer, autoFocus }, (root, options) => createCalendar(root, { ...options, value: value === undefined ? defaultValue : value }));
|
|
107
141
|
useIsoLayoutEffect(() => {
|
|
108
142
|
if (value !== undefined && ctl.current && ctl.current.value !== value)
|
|
109
143
|
ctl.current.setValue(value);
|
|
@@ -119,3 +153,43 @@ export const Calendar = forwardRef(function Calendar({ value, defaultValue, onCh
|
|
|
119
153
|
});
|
|
120
154
|
return _jsx("div", { ref: useMergedRef(own, ref), className: cx('fs-calendar', className), ...rest });
|
|
121
155
|
});
|
|
156
|
+
const sameRange = (a, b) => (a?.start ?? null) === (b?.start ?? null) && (a?.end ?? null) === (b?.end ?? null);
|
|
157
|
+
/**
|
|
158
|
+
* The range calendar (T85): `createCalendar` in `mode: 'range'` (D42: one helper), on the same empty
|
|
159
|
+
* root. A pending start lives in the helper: a parent re-rendering the same range keeps it.
|
|
160
|
+
*/
|
|
161
|
+
export const DateRangeCalendar = forwardRef(function DateRangeCalendar({ value, defaultValue, onChange, min, max, today, granularity, weekStart, months, monthNames, weekdayNames, heading, cellLabel, labels, announcer, autoFocus, className, ...rest }, ref) {
|
|
162
|
+
const own = useRef(null);
|
|
163
|
+
const latestValue = useLatest(value);
|
|
164
|
+
const common = {
|
|
165
|
+
min,
|
|
166
|
+
max,
|
|
167
|
+
today,
|
|
168
|
+
granularity,
|
|
169
|
+
weekStart,
|
|
170
|
+
months,
|
|
171
|
+
monthNames,
|
|
172
|
+
weekdayNames,
|
|
173
|
+
heading,
|
|
174
|
+
cellLabel,
|
|
175
|
+
labels,
|
|
176
|
+
};
|
|
177
|
+
const ctl = useCalendarHelper(own, { ...common, announcer, autoFocus }, (root, options) => createCalendar(root, { ...options, labels, mode: 'range', value: value === undefined ? defaultValue : value }));
|
|
178
|
+
// Only a new range in the prop resets the helper: an equal one keeps a pending start.
|
|
179
|
+
const start = value === undefined ? undefined : (value?.start ?? null);
|
|
180
|
+
const end = value === undefined ? undefined : (value?.end ?? null);
|
|
181
|
+
useIsoLayoutEffect(() => {
|
|
182
|
+
if (value !== undefined && ctl.current && !sameRange(ctl.current.value, value))
|
|
183
|
+
ctl.current.setValue(value);
|
|
184
|
+
}, [start, end]);
|
|
185
|
+
useFsEvent(own, 'fs-change', (picked) => {
|
|
186
|
+
onChange?.({ start: picked.start, end: picked.end });
|
|
187
|
+
// A controlled range the parent didn't take is put back.
|
|
188
|
+
queueMicrotask(() => {
|
|
189
|
+
const held = latestValue.current;
|
|
190
|
+
if (held !== undefined && ctl.current && !sameRange(ctl.current.value, held))
|
|
191
|
+
ctl.current.setValue(held);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
return _jsx("div", { ref: useMergedRef(own, ref), className: cx('fs-calendar', className), ...rest });
|
|
195
|
+
});
|
package/package.json
CHANGED