@zonsh/ui 0.2.0 → 0.5.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/LICENSE +22 -0
- package/README.md +19 -13
- package/dist/components/accordion.js +1 -1
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/ascii-field.d.ts +1 -1
- package/dist/components/ascii-field.js +2 -1
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +9 -0
- package/dist/components/breadcrumb.js +6 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +2 -2
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.d.ts +1 -1
- package/dist/components/calendar.js +18 -3
- package/dist/components/carousel.d.ts +22 -3
- package/dist/components/carousel.js +25 -7
- package/dist/components/chart.d.ts +20 -0
- package/dist/components/chart.js +52 -3
- package/dist/components/code-block.d.ts +20 -10
- package/dist/components/code-block.js +54 -12
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +30 -8
- package/dist/components/color-picker.js +48 -27
- package/dist/components/combobox.d.ts +21 -3
- package/dist/components/combobox.js +79 -7
- package/dist/components/command.d.ts +23 -3
- package/dist/components/command.js +63 -18
- package/dist/components/conversation.d.ts +10 -1
- package/dist/components/conversation.js +24 -7
- package/dist/components/copy-button.d.ts +15 -6
- package/dist/components/copy-button.js +27 -10
- package/dist/components/data-table.d.ts +66 -6
- package/dist/components/data-table.js +376 -23
- package/dist/components/date-picker.d.ts +73 -4
- package/dist/components/date-picker.js +138 -7
- package/dist/components/dialog.d.ts +10 -1
- package/dist/components/dialog.js +6 -3
- package/dist/components/drawer.d.ts +10 -1
- package/dist/components/drawer.js +6 -3
- package/dist/components/feature-list.js +2 -2
- package/dist/components/field.d.ts +27 -8
- package/dist/components/field.js +49 -4
- package/dist/components/file-drop.d.ts +26 -4
- package/dist/components/file-drop.js +125 -64
- package/dist/components/filter-bar.d.ts +50 -3
- package/dist/components/filter-bar.js +71 -33
- package/dist/components/form.d.ts +4 -2
- package/dist/components/form.js +24 -2
- package/dist/components/graph.d.ts +41 -0
- package/dist/components/graph.js +106 -50
- package/dist/components/illustration.js +51 -4
- package/dist/components/input-group.d.ts +18 -7
- package/dist/components/input-group.js +41 -19
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/kbd.d.ts +17 -0
- package/dist/components/kbd.js +8 -1
- package/dist/components/layout.d.ts +2 -1
- package/dist/components/layout.js +55 -11
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +457 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.js +1 -1
- package/dist/components/menu.js +3 -1
- package/dist/components/menubar.js +60 -13
- package/dist/components/message.d.ts +3 -3
- package/dist/components/message.js +12 -8
- package/dist/components/meter.js +3 -1
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/navigation-menu.js +4 -2
- package/dist/components/number-field.d.ts +21 -2
- package/dist/components/number-field.js +53 -28
- package/dist/components/otp-field.d.ts +14 -1
- package/dist/components/otp-field.js +10 -2
- package/dist/components/pagination.d.ts +13 -7
- package/dist/components/pagination.js +18 -7
- package/dist/components/pdf-viewer.d.ts +67 -2
- package/dist/components/pdf-viewer.js +88 -21
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.js +1 -1
- package/dist/components/progress.js +3 -1
- package/dist/components/prompt-input.d.ts +34 -9
- package/dist/components/prompt-input.js +37 -17
- package/dist/components/radio-group.js +7 -2
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +16 -1
- package/dist/components/reasoning.js +10 -7
- package/dist/components/resizable.d.ts +10 -1
- package/dist/components/resizable.js +4 -1
- package/dist/components/response.d.ts +17 -5
- package/dist/components/response.js +58 -18
- package/dist/components/scroll-area.d.ts +1 -1
- package/dist/components/select.js +14 -3
- package/dist/components/separator.js +1 -1
- package/dist/components/sidebar.d.ts +20 -4
- package/dist/components/sidebar.js +70 -35
- package/dist/components/site-header.d.ts +46 -12
- package/dist/components/site-header.js +78 -19
- package/dist/components/skeleton.d.ts +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/slider.js +3 -1
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1282 -0
- package/dist/components/sources.d.ts +17 -2
- package/dist/components/sources.js +11 -4
- package/dist/components/spinner.d.ts +13 -1
- package/dist/components/spinner.js +5 -2
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +13 -3
- package/dist/components/table.js +231 -41
- package/dist/components/tabs.js +8 -4
- package/dist/components/tags-input.d.ts +18 -2
- package/dist/components/tags-input.js +66 -34
- package/dist/components/theme.d.ts +16 -2
- package/dist/components/theme.js +34 -8
- package/dist/components/time-field.d.ts +24 -4
- package/dist/components/time-field.js +32 -9
- package/dist/components/timeline.d.ts +18 -2
- package/dist/components/timeline.js +13 -4
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +18 -2
- package/dist/components/toast.js +12 -3
- package/dist/components/toggle-group.js +1 -0
- package/dist/components/tool-call.d.ts +19 -8
- package/dist/components/tool-call.js +23 -7
- package/dist/components/toolbar.d.ts +1 -1
- package/dist/components/toolbar.js +10 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +10 -4
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +673 -0
- package/dist/components/tree.js +45 -9
- package/dist/components/video-player.d.ts +10 -2
- package/dist/components/video-player.js +134 -38
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- package/dist/lib/code-highlight.d.ts +3 -16
- package/dist/lib/code-highlight.js +160 -10
- package/dist/lib/code-theme.js +3 -3
- package/dist/lib/digit-roll.js +8 -8
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/glide.d.ts +5 -4
- package/dist/lib/glide.js +5 -4
- package/dist/lib/graph-layout.js +11 -2
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +8 -3
- package/dist/lib/platform.js +13 -6
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +3 -2
- package/dist/lib/table-fit.js +52 -23
- package/dist/lib/theme-script.d.ts +15 -2
- package/dist/lib/theme-script.js +23 -3
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +60 -26
- package/dist/styles/index.css +11 -2
- package/dist/styles/material.css +47 -23
- package/dist/styles/parts/ai.css +4 -2
- package/dist/styles/parts/controls.css +85 -32
- package/dist/styles/parts/data.css +33 -5
- package/dist/styles/parts/feedback.css +110 -13
- package/dist/styles/parts/foundations.css +1 -1
- package/dist/styles/parts/navigation.css +230 -5
- package/dist/styles/parts/overlays.css +98 -11
- package/dist/styles/parts/pdf.css +13 -7
- package/dist/styles/tokens.css +28 -4
- package/dist/vite.d.ts +0 -50
- package/dist/vite.js +0 -100
- package/package.json +28 -33
- package/dist/components/code-highlight.d.ts +0 -13
- package/dist/components/code-highlight.js +0 -107
- package/dist/components/whiteboard.d.ts +0 -80
- package/dist/components/whiteboard.js +0 -389
- package/dist/styles/parts/whiteboard.css +0 -855
|
@@ -2,6 +2,17 @@ import * as React from "react";
|
|
|
2
2
|
import type { DateRange, DayPickerLocale, PropsBase } from "react-day-picker";
|
|
3
3
|
import { type CalendarProps } from "./calendar.js";
|
|
4
4
|
import { type PopoverContentProps } from "./popover.js";
|
|
5
|
+
export interface DatePickerMessages {
|
|
6
|
+
/** DatePicker's trigger while no date is picked. */
|
|
7
|
+
placeholder: string;
|
|
8
|
+
/** DateRangePicker's trigger while no range is picked. */
|
|
9
|
+
rangePlaceholder: string;
|
|
10
|
+
}
|
|
11
|
+
declare module "./locale" {
|
|
12
|
+
interface Messages {
|
|
13
|
+
datePicker: DatePickerMessages;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
5
16
|
declare const triggerSizes: {
|
|
6
17
|
readonly sm: "min-h-(--control-h-sm) gap-2 px-2.5 text-[13px] [&_svg]:size-3.5";
|
|
7
18
|
readonly default: "min-h-(--control-h) gap-3 pe-3 ps-3.5 text-[15px] [&_svg]:size-4";
|
|
@@ -9,9 +20,12 @@ declare const triggerSizes: {
|
|
|
9
20
|
/** Calendar props a picker passes through: `disabled` days, `captionLayout` + `dropdown`, `startMonth`, `weekStartsOn` … */
|
|
10
21
|
export type DatePickerCalendarProps = Pick<CalendarProps, "dropdown"> & Omit<PropsBase, "mode" | "required" | "locale" | "month" | "defaultMonth" | "onMonthChange">;
|
|
11
22
|
interface PickerBaseProps {
|
|
12
|
-
/** Shown while no date is picked. */
|
|
23
|
+
/** Shown while no date is picked. Default `messages.datePicker.placeholder` (`rangePlaceholder`). */
|
|
13
24
|
placeholder?: string;
|
|
14
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* A date-fns locale (or one from `react-day-picker/locale`, which also translates labels). A
|
|
27
|
+
* LocaleProvider does not set it: pass the date-fns locale for the provider's language.
|
|
28
|
+
*/
|
|
15
29
|
locale?: DayPickerLocale;
|
|
16
30
|
/** A date-fns format string for the trigger. Default `"PP"`: "Oct 5, 2026", "05.10.2026". */
|
|
17
31
|
format?: string;
|
|
@@ -39,6 +53,10 @@ interface PickerBaseProps {
|
|
|
39
53
|
"aria-label"?: string;
|
|
40
54
|
"aria-labelledby"?: string;
|
|
41
55
|
"aria-describedby"?: string;
|
|
56
|
+
/** The trigger: what a form library focuses to show an error (React Hook Form's `field.ref`). */
|
|
57
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
58
|
+
/** Called when focus leaves the picker — its trigger and calendar — as a form library's `onBlur`. */
|
|
59
|
+
onBlur?: () => void;
|
|
42
60
|
}
|
|
43
61
|
export interface DatePickerPreset {
|
|
44
62
|
label: string;
|
|
@@ -62,7 +80,7 @@ export interface DatePickerProps extends PickerBaseProps {
|
|
|
62
80
|
* The rule people break: a picker for dates people know by heart (a birthday, a passport's
|
|
63
81
|
* date of issue). Those are faster typed into an `Input`.
|
|
64
82
|
*/
|
|
65
|
-
export declare function DatePicker({ value: valueProp, defaultValue, onValueChange, presets, closeOnSelect, placeholder, locale, format, name, open: openProp, defaultOpen, onOpenChange, calendar, popover, ...trigger }: DatePickerProps): React.JSX.Element;
|
|
83
|
+
export declare function DatePicker({ value: valueProp, defaultValue, onValueChange, presets, closeOnSelect, placeholder, locale, format, name, open: openProp, defaultOpen, onOpenChange, calendar, popover, ref, ...trigger }: DatePickerProps): React.JSX.Element;
|
|
66
84
|
export interface DateRangePickerPreset {
|
|
67
85
|
label: string;
|
|
68
86
|
value: DateRange;
|
|
@@ -87,5 +105,56 @@ export interface DateRangePickerProps extends PickerBaseProps {
|
|
|
87
105
|
* outside click. With `name`, submits an ISO 8601 interval (`2026-10-05/2026-10-12`) once both
|
|
88
106
|
* ends are picked.
|
|
89
107
|
*/
|
|
90
|
-
export declare function DateRangePicker({ value: valueProp, defaultValue, onValueChange, presets, numberOfMonths, placeholder, locale, format, name, open: openProp, defaultOpen, onOpenChange, calendar, popover, ...trigger }: DateRangePickerProps): React.JSX.Element;
|
|
108
|
+
export declare function DateRangePicker({ value: valueProp, defaultValue, onValueChange, presets, numberOfMonths, placeholder, locale, format, name, open: openProp, defaultOpen, onOpenChange, calendar, popover, ref, ...trigger }: DateRangePickerProps): React.JSX.Element;
|
|
109
|
+
export interface DateTimePickerMessages {
|
|
110
|
+
/** The trigger's text while no date is picked. */
|
|
111
|
+
placeholder: string;
|
|
112
|
+
/** The label of the time field under the calendar. */
|
|
113
|
+
time: string;
|
|
114
|
+
}
|
|
115
|
+
declare module "./locale" {
|
|
116
|
+
interface Messages {
|
|
117
|
+
dateTimePicker: DateTimePickerMessages;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export interface DateTimePickerProps extends Omit<PickerBaseProps, "format" | "placeholder"> {
|
|
121
|
+
/** The picked moment. `null` is empty; leave `undefined` for an uncontrolled picker. */
|
|
122
|
+
value?: Date | null;
|
|
123
|
+
defaultValue?: Date | null;
|
|
124
|
+
/**
|
|
125
|
+
* Called with the date at the picked time once both are there, and with `null` when either is
|
|
126
|
+
* cleared — as a native `datetime-local` input has no value until it is whole.
|
|
127
|
+
*/
|
|
128
|
+
onValueChange?: (value: Date | null) => void;
|
|
129
|
+
/** The earliest moment. Days before it can't be picked, and on its day the time can't go earlier. */
|
|
130
|
+
min?: Date;
|
|
131
|
+
/** The latest moment. */
|
|
132
|
+
max?: Date;
|
|
133
|
+
/** `12` or `24` hours, in the field and on the trigger. Default: the locale's own clock. */
|
|
134
|
+
hourCycle?: 12 | 24;
|
|
135
|
+
/** Minutes moved by one arrow press in the time field: `15` for quarter hours. */
|
|
136
|
+
step?: number;
|
|
137
|
+
/**
|
|
138
|
+
* The time a picked day takes while none is set yet, `"HH:mm"` — `"09:00"` for a meeting. Without
|
|
139
|
+
* one, the time field waits to be filled and the picker has no value until it is.
|
|
140
|
+
*/
|
|
141
|
+
defaultTime?: string;
|
|
142
|
+
/** `Intl.DateTimeFormat` options for the trigger. Default `{ dateStyle: "medium", timeStyle: "short" }`. */
|
|
143
|
+
format?: Intl.DateTimeFormatOptions;
|
|
144
|
+
/** Shown while no date is picked. Default from the locale messages: "Pick a date and time". */
|
|
145
|
+
placeholder?: string;
|
|
146
|
+
/** Interface text; a LocaleProvider sets it for every DateTimePicker. */
|
|
147
|
+
labels?: Partial<DateTimePickerMessages>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* DateTimePicker — a date and a time of day in one field: the DatePicker's trigger showing the
|
|
151
|
+
* moment formatted for the locale ("Oct 5, 2026, 2:30 PM", "05.10.2026, 14:30"), opening a
|
|
152
|
+
* `Calendar` with a `TimeField` under it. Picking a day keeps the time, and moves on to the time
|
|
153
|
+
* while it is empty; Enter in the time field closes the popover.
|
|
154
|
+
*
|
|
155
|
+
* The value is a `Date`, in local time; a form gets it as `2026-10-05T14:30`. The rule people
|
|
156
|
+
* break: a date and time for something that lasts all day (a deadline, a holiday). That is a
|
|
157
|
+
* `DatePicker`.
|
|
158
|
+
*/
|
|
159
|
+
export declare function DateTimePicker({ value: valueProp, defaultValue, onValueChange, min, max, hourCycle, step, defaultTime, format, placeholder, locale, name, open: openProp, defaultOpen, onOpenChange, calendar, popover, labels, ref, ...trigger }: DateTimePickerProps): React.JSX.Element;
|
|
91
160
|
export {};
|
|
@@ -8,7 +8,13 @@ import { cn, sx } from "../lib/cn.js";
|
|
|
8
8
|
import { mergeRefs } from "../lib/merge-refs.js";
|
|
9
9
|
import { roomOf } from "../lib/room.js";
|
|
10
10
|
import { Calendar } from "./calendar.js";
|
|
11
|
+
import { useLocale, useMessages } from "./locale.js";
|
|
11
12
|
import { Popover, PopoverContent, PopoverTrigger } from "./popover.js";
|
|
13
|
+
import { TimeField } from "./time-field.js";
|
|
14
|
+
const defaultMessages = {
|
|
15
|
+
placeholder: "Pick a date",
|
|
16
|
+
rangePlaceholder: "Pick a date range",
|
|
17
|
+
};
|
|
12
18
|
/* ── Shared pieces ─────────────────────────────────────────────────────────── */
|
|
13
19
|
const triggerSizes = {
|
|
14
20
|
sm: "min-h-(--control-h-sm) gap-2 px-2.5 text-[13px] [&_svg]:size-3.5",
|
|
@@ -25,7 +31,7 @@ function useControllable(value, defaultValue) {
|
|
|
25
31
|
return [current, set];
|
|
26
32
|
}
|
|
27
33
|
/** The popup of a picker: focus moving into it hasn't left the field. */
|
|
28
|
-
const PICKER_POPUP = '[data-slot="date-picker-content"], [data-slot="date-range-picker-content"]';
|
|
34
|
+
const PICKER_POPUP = '[data-slot="date-picker-content"], [data-slot="date-range-picker-content"], [data-slot="date-time-picker-content"]';
|
|
29
35
|
/**
|
|
30
36
|
* The trigger looks like a Select trigger with a calendar for its indicator. It is what the Field's
|
|
31
37
|
* label names and `Field invalid` marks; its name is the label and the value, so the date is read
|
|
@@ -36,7 +42,7 @@ const PICKER_POPUP = '[data-slot="date-picker-content"], [data-slot="date-range-
|
|
|
36
42
|
* `onFormSubmit`, and its `required` blocks a submit while it is empty. A submit that finds it so
|
|
37
43
|
* focuses it, and it hands focus on to the trigger.
|
|
38
44
|
*/
|
|
39
|
-
function PickerTrigger({ slot, size = "default", empty, value, name, required, className, children, ref, leaveRef, ...props }) {
|
|
45
|
+
function PickerTrigger({ slot, size = "default", empty, value, name, required, className, children, ref, leaveRef, onBlur, ...props }) {
|
|
40
46
|
const valueId = React.useId();
|
|
41
47
|
const trigger = React.useRef(null);
|
|
42
48
|
const refs = React.useMemo(() => mergeRefs(trigger, ref), [ref]);
|
|
@@ -48,6 +54,7 @@ function PickerTrigger({ slot, size = "default", empty, value, name, required, c
|
|
|
48
54
|
leaveRef.current = () => {
|
|
49
55
|
if (fieldInput.current)
|
|
50
56
|
fieldBlur?.({ currentTarget: fieldInput.current });
|
|
57
|
+
onBlur?.();
|
|
51
58
|
};
|
|
52
59
|
return (_jsxs(_Fragment, { children: [_jsx(PopoverTrigger, { ...button, ref: refs, "aria-labelledby": labelledBy ? `${labelledBy} ${valueId}` : undefined, onBlur: (event) => {
|
|
53
60
|
if (!event.relatedTarget?.closest(PICKER_POPUP))
|
|
@@ -121,9 +128,11 @@ function usePickerLeave(trigger, onBlur) {
|
|
|
121
128
|
* The rule people break: a picker for dates people know by heart (a birthday, a passport's
|
|
122
129
|
* date of issue). Those are faster typed into an `Input`.
|
|
123
130
|
*/
|
|
124
|
-
export function DatePicker({ value: valueProp, defaultValue = null, onValueChange, presets, closeOnSelect = true, placeholder
|
|
131
|
+
export function DatePicker({ value: valueProp, defaultValue = null, onValueChange, presets, closeOnSelect = true, placeholder, locale, format = "PP", name, open: openProp, defaultOpen = false, onOpenChange, calendar, popover, ref, ...trigger }) {
|
|
132
|
+
const text = useMessages("datePicker", defaultMessages);
|
|
125
133
|
const [value, setValue] = useControllable(valueProp, defaultValue);
|
|
126
134
|
const triggerRef = React.useRef(null);
|
|
135
|
+
const triggerRefs = React.useMemo(() => mergeRefs(triggerRef, ref), [ref]);
|
|
127
136
|
const narrow = useRoom(triggerRef);
|
|
128
137
|
const [open, setOpen] = useControllable(openProp, defaultOpen);
|
|
129
138
|
const [month, setMonth] = React.useState(() => value ?? new Date());
|
|
@@ -139,7 +148,7 @@ export function DatePicker({ value: valueProp, defaultValue = null, onValueChang
|
|
|
139
148
|
setOpen(next);
|
|
140
149
|
onOpenChange?.(next);
|
|
141
150
|
};
|
|
142
|
-
return (_jsxs(Popover, { open: open, onOpenChange: (next) => changeOpen(next), children: [_jsx(PickerTrigger, { slot: "date-picker-trigger", empty: !value, value: value ? isoDate(value) : "", name: name, ...trigger, ref:
|
|
151
|
+
return (_jsxs(Popover, { open: open, onOpenChange: (next) => changeOpen(next), children: [_jsx(PickerTrigger, { slot: "date-picker-trigger", empty: !value, value: value ? isoDate(value) : "", name: name, ...trigger, ref: triggerRefs, leaveRef: leave.leaveRef, children: value ? formatDate(value, format, { locale }) : (placeholder ?? text.placeholder) }), _jsx(PopoverContent, { align: "start", ...popover, "data-slot": "date-picker-content", className: sx(panelClassName, popover?.className), onBlur: leave.popupBlur, children: _jsxs("div", { className: cn("flex", narrow ? "flex-col" : "flex-row"), children: [presets && presets.length > 0 && (_jsx(PresetList, { slot: "date-picker-presets", narrow: narrow, items: presets.map((preset) => ({
|
|
143
152
|
label: preset.label,
|
|
144
153
|
current: !!value && isSameDay(value, preset.value),
|
|
145
154
|
onSelect: () => {
|
|
@@ -161,11 +170,13 @@ export function DatePicker({ value: valueProp, defaultValue = null, onValueChang
|
|
|
161
170
|
* outside click. With `name`, submits an ISO 8601 interval (`2026-10-05/2026-10-12`) once both
|
|
162
171
|
* ends are picked.
|
|
163
172
|
*/
|
|
164
|
-
export function DateRangePicker({ value: valueProp, defaultValue = null, onValueChange, presets, numberOfMonths = 2, placeholder
|
|
173
|
+
export function DateRangePicker({ value: valueProp, defaultValue = null, onValueChange, presets, numberOfMonths = 2, placeholder, locale, format = "PP", name, open: openProp, defaultOpen = false, onOpenChange, calendar, popover, ref, ...trigger }) {
|
|
174
|
+
const text = useMessages("datePicker", defaultMessages);
|
|
165
175
|
const [value, setValue] = useControllable(valueProp, defaultValue);
|
|
166
176
|
const [open, setOpen] = useControllable(openProp, defaultOpen);
|
|
167
177
|
const [month, setMonth] = React.useState(() => value?.from ?? new Date());
|
|
168
178
|
const triggerRef = React.useRef(null);
|
|
179
|
+
const triggerRefs = React.useMemo(() => mergeRefs(triggerRef, ref), [ref]);
|
|
169
180
|
const narrow = useRoom(triggerRef);
|
|
170
181
|
const months = narrow ? 1 : numberOfMonths;
|
|
171
182
|
useFormReset(triggerRef, () => setValue(defaultValue));
|
|
@@ -184,10 +195,10 @@ export function DateRangePicker({ value: valueProp, defaultValue = null, onValue
|
|
|
184
195
|
const to = value?.to;
|
|
185
196
|
const label = from
|
|
186
197
|
? `${formatDate(from, format, { locale })} – ${to ? formatDate(to, format, { locale }) : ""}`.trim()
|
|
187
|
-
: placeholder;
|
|
198
|
+
: (placeholder ?? text.rangePlaceholder);
|
|
188
199
|
return (_jsxs(Popover, { open: open, onOpenChange: (next) => changeOpen(next), children: [_jsx(PickerTrigger, { slot: "date-range-picker-trigger", empty: !from,
|
|
189
200
|
// A range is a value once both its ends are picked: until then a form gets nothing.
|
|
190
|
-
value: from && to ? `${isoDate(from)}/${isoDate(to)}` : "", name: name, ...trigger, ref:
|
|
201
|
+
value: from && to ? `${isoDate(from)}/${isoDate(to)}` : "", name: name, ...trigger, ref: triggerRefs, leaveRef: leave.leaveRef, children: label }), _jsx(PopoverContent, { align: "start", ...popover, "data-slot": "date-range-picker-content", className: sx(panelClassName, popover?.className), onBlur: leave.popupBlur, children: _jsxs("div", { className: cn("flex", narrow ? "flex-col" : "flex-row"), children: [presets && presets.length > 0 && (_jsx(PresetList, { slot: "date-range-picker-presets", narrow: narrow, items: presets.map((preset) => ({
|
|
191
202
|
label: preset.label,
|
|
192
203
|
current: !!from &&
|
|
193
204
|
!!to &&
|
|
@@ -205,3 +216,123 @@ export function DateRangePicker({ value: valueProp, defaultValue = null, onValue
|
|
|
205
216
|
// Side by side, outside days would show the same dates twice.
|
|
206
217
|
showOutsideDays: months === 1, ...calendar, mode: "range", locale: locale, numberOfMonths: months, selected: value ?? undefined, onSelect: (next) => commit(next ?? null), month: month, onMonthChange: setMonth })] }) })] }));
|
|
207
218
|
}
|
|
219
|
+
const defaultDateTimeMessages = {
|
|
220
|
+
placeholder: "Pick a date and time",
|
|
221
|
+
time: "Time",
|
|
222
|
+
};
|
|
223
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
224
|
+
/** A date's time of day as the TimeField's `"HH:mm"`. */
|
|
225
|
+
const timeOf = (date) => `${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
|
|
226
|
+
/** The day of `day` at `time` ("HH:mm"), local time. */
|
|
227
|
+
const atTime = (day, time) => {
|
|
228
|
+
const [h = 0, m = 0] = time.split(":").map(Number);
|
|
229
|
+
const next = new Date(day);
|
|
230
|
+
next.setHours(h, m, 0, 0);
|
|
231
|
+
return next;
|
|
232
|
+
};
|
|
233
|
+
const startOfDayOf = (date) => {
|
|
234
|
+
const next = new Date(date);
|
|
235
|
+
next.setHours(0, 0, 0, 0);
|
|
236
|
+
return next;
|
|
237
|
+
};
|
|
238
|
+
/** A local date-time as a form gets it from a native `datetime-local` input: `2026-10-05T14:30`. */
|
|
239
|
+
const isoLocal = (date) => `${isoDate(date)}T${timeOf(date)}`;
|
|
240
|
+
const timeValue = (date) => date?.getTime() ?? null;
|
|
241
|
+
const noSubscribe = () => () => { };
|
|
242
|
+
/**
|
|
243
|
+
* DateTimePicker — a date and a time of day in one field: the DatePicker's trigger showing the
|
|
244
|
+
* moment formatted for the locale ("Oct 5, 2026, 2:30 PM", "05.10.2026, 14:30"), opening a
|
|
245
|
+
* `Calendar` with a `TimeField` under it. Picking a day keeps the time, and moves on to the time
|
|
246
|
+
* while it is empty; Enter in the time field closes the popover.
|
|
247
|
+
*
|
|
248
|
+
* The value is a `Date`, in local time; a form gets it as `2026-10-05T14:30`. The rule people
|
|
249
|
+
* break: a date and time for something that lasts all day (a deadline, a holiday). That is a
|
|
250
|
+
* `DatePicker`.
|
|
251
|
+
*/
|
|
252
|
+
export function DateTimePicker({ value: valueProp, defaultValue = null, onValueChange, min, max, hourCycle, step, defaultTime, format, placeholder, locale, name, open: openProp, defaultOpen = false, onOpenChange, calendar, popover, labels, ref, ...trigger }) {
|
|
253
|
+
const text = useMessages("dateTimePicker", defaultDateTimeMessages, labels);
|
|
254
|
+
const [value, setValue] = useControllable(valueProp, defaultValue);
|
|
255
|
+
const [open, setOpen] = useControllable(openProp, defaultOpen);
|
|
256
|
+
const triggerRef = React.useRef(null);
|
|
257
|
+
const triggerRefs = React.useMemo(() => mergeRefs(triggerRef, ref), [ref]);
|
|
258
|
+
const timeRef = React.useRef(null);
|
|
259
|
+
const leave = usePickerLeave(triggerRef, popover?.onBlur);
|
|
260
|
+
// Formatted for the date-fns locale passed in, or the LocaleProvider's; without either, the
|
|
261
|
+
// browser's — which a server can't know, so the server and the hydrating render use en-US.
|
|
262
|
+
const providerLocale = useLocale();
|
|
263
|
+
const hydrated = React.useSyncExternalStore(noSubscribe, () => true, () => false);
|
|
264
|
+
const tag = locale?.code ?? providerLocale ?? (hydrated ? undefined : "en-US");
|
|
265
|
+
// A day picked before its time (or a time before its day) is kept here until the other comes.
|
|
266
|
+
const [draft, setDraft] = React.useState(() => ({
|
|
267
|
+
day: value,
|
|
268
|
+
time: value ? timeOf(value) : null,
|
|
269
|
+
}));
|
|
270
|
+
// A controlled value that changes from outside resets the draft; one we emitted does not.
|
|
271
|
+
const [synced, setSynced] = React.useState(timeValue(value));
|
|
272
|
+
if (timeValue(value) !== synced) {
|
|
273
|
+
setSynced(timeValue(value));
|
|
274
|
+
const whole = draft.day && draft.time ? atTime(draft.day, draft.time).getTime() : null;
|
|
275
|
+
if (timeValue(value) !== whole)
|
|
276
|
+
setDraft({ day: value, time: value ? timeOf(value) : null });
|
|
277
|
+
}
|
|
278
|
+
const [month, setMonth] = React.useState(() => value ?? new Date());
|
|
279
|
+
useFormReset(triggerRef, () => {
|
|
280
|
+
setValue(defaultValue);
|
|
281
|
+
setDraft({ day: defaultValue, time: defaultValue ? timeOf(defaultValue) : null });
|
|
282
|
+
});
|
|
283
|
+
const clamp = (date) => min && date < min ? new Date(min) : max && date > max ? new Date(max) : date;
|
|
284
|
+
const emit = (day, time) => {
|
|
285
|
+
const next = day && time ? clamp(atTime(day, time)) : null;
|
|
286
|
+
setDraft({ day: next ?? day, time: next ? timeOf(next) : time });
|
|
287
|
+
if (timeValue(next) === timeValue(value))
|
|
288
|
+
return;
|
|
289
|
+
setSynced(timeValue(next));
|
|
290
|
+
setValue(next);
|
|
291
|
+
onValueChange?.(next);
|
|
292
|
+
};
|
|
293
|
+
const changeOpen = (next) => {
|
|
294
|
+
if (next)
|
|
295
|
+
setMonth(draft.day ?? value ?? min ?? new Date());
|
|
296
|
+
setOpen(next);
|
|
297
|
+
onOpenChange?.(next);
|
|
298
|
+
};
|
|
299
|
+
const fmt = React.useMemo(() => {
|
|
300
|
+
const options = {
|
|
301
|
+
...(format ?? { dateStyle: "medium", timeStyle: "short" }),
|
|
302
|
+
...(hourCycle ? { hourCycle: hourCycle === 12 ? "h12" : "h23" } : {}),
|
|
303
|
+
};
|
|
304
|
+
const make = (o) => {
|
|
305
|
+
try {
|
|
306
|
+
return new Intl.DateTimeFormat(tag, o);
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
return new Intl.DateTimeFormat("en-US", o);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
return { full: make(options), day: make({ dateStyle: "medium" }) };
|
|
313
|
+
}, [tag, format, hourCycle]);
|
|
314
|
+
const onDayOf = (bound) => bound && draft.day && isSameDay(bound, draft.day) ? timeOf(bound) : undefined;
|
|
315
|
+
const ownDisabled = calendar?.disabled;
|
|
316
|
+
const disabledDays = [
|
|
317
|
+
...(min ? [{ before: startOfDayOf(min) }] : []),
|
|
318
|
+
...(max ? [{ after: startOfDayOf(max) }] : []),
|
|
319
|
+
...(Array.isArray(ownDisabled) ? ownDisabled : ownDisabled ? [ownDisabled] : []),
|
|
320
|
+
];
|
|
321
|
+
let label = placeholder ?? text.placeholder;
|
|
322
|
+
if (value)
|
|
323
|
+
label = fmt.full.format(value);
|
|
324
|
+
else if (draft.day)
|
|
325
|
+
label = `${fmt.day.format(draft.day)}, ––:––`;
|
|
326
|
+
return (_jsxs(Popover, { open: open, onOpenChange: (next) => changeOpen(next), children: [_jsx(PickerTrigger, { slot: "date-time-picker-trigger", empty: !value, value: value ? isoLocal(value) : "", name: name, ...trigger, ref: triggerRefs, leaveRef: leave.leaveRef, children: label }), _jsxs(PopoverContent, { align: "start", ...popover, "data-slot": "date-time-picker-content", className: sx(panelClassName, popover?.className), onBlur: leave.popupBlur, children: [_jsx(Calendar, { autoFocus: true, ...calendar, disabled: disabledDays.length ? disabledDays : undefined, mode: "single", required: true, locale: locale, selected: draft.day ?? undefined, onSelect: (day) => {
|
|
327
|
+
const time = draft.time ?? defaultTime ?? null;
|
|
328
|
+
emit(day ?? null, time);
|
|
329
|
+
// The day is there; the time comes next while it is empty.
|
|
330
|
+
if (!time)
|
|
331
|
+
requestAnimationFrame(() => timeRef.current?.querySelector("[data-slot=time-field-segment]")?.focus());
|
|
332
|
+
}, month: month, onMonthChange: setMonth }), _jsxs(BaseField.Root, { ref: timeRef, disabled: trigger.disabled, "data-slot": "date-time-picker-time", className: "flex items-center gap-3 border-t border-border/60 p-3", onKeyDown: (event) => {
|
|
333
|
+
if (event.key === "Enter") {
|
|
334
|
+
event.preventDefault();
|
|
335
|
+
changeOpen(false);
|
|
336
|
+
}
|
|
337
|
+
}, children: [_jsx(BaseField.Label, { className: "shrink-0 text-sm font-medium text-foreground select-none", children: text.time }), _jsx(TimeField, { value: draft.time, onValueChange: (time) => emit(draft.day, time), hourCycle: hourCycle, locale: tag, step: step, min: onDayOf(min), max: onDayOf(max) })] })] })] }));
|
|
338
|
+
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Dialog as BaseDialog } from "@base-ui/react/dialog";
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
export interface DialogMessages {
|
|
4
|
+
/** The close button's name. */
|
|
5
|
+
close: string;
|
|
6
|
+
}
|
|
7
|
+
declare module "./locale" {
|
|
8
|
+
interface Messages {
|
|
9
|
+
dialog: DialogMessages;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* Dialog — a focused task on top of the page: a short form, a decision, a detail view.
|
|
5
14
|
* A dialog is an *object*, so its popup takes the card geometry (20px, the card material).
|
|
@@ -23,7 +32,7 @@ export interface DialogContentProps extends BaseDialog.Popup.Props {
|
|
|
23
32
|
size?: DialogSize;
|
|
24
33
|
/** Render the circular close button in the top-right corner. */
|
|
25
34
|
showCloseButton?: boolean;
|
|
26
|
-
/** Accessible name of the close button. */
|
|
35
|
+
/** Accessible name of the close button. Default "Close", or `messages.dialog.close` from a LocaleProvider. */
|
|
27
36
|
closeLabel?: string;
|
|
28
37
|
/** Props for the portal (e.g. `container`, `keepMounted`). */
|
|
29
38
|
portal?: Omit<BaseDialog.Portal.Props, "children">;
|
|
@@ -6,6 +6,8 @@ import * as React from "react";
|
|
|
6
6
|
import { cn, sx, triggerSlot } from "../lib/cn.js";
|
|
7
7
|
import { mergeRefs } from "../lib/merge-refs.js";
|
|
8
8
|
import { overlayBackdrop, overlayCard, overlayCloseButton, overlayDescription, overlayFooter, overlayHeader, overlayTitle, usePopupDir, } from "./_overlay.js";
|
|
9
|
+
import { useMessages } from "./locale.js";
|
|
10
|
+
const defaultMessages = { close: "Close" };
|
|
9
11
|
/**
|
|
10
12
|
* Dialog — a focused task on top of the page: a short form, a decision, a detail view.
|
|
11
13
|
* A dialog is an *object*, so its popup takes the card geometry (20px, the card material).
|
|
@@ -29,14 +31,15 @@ const dialogSizes = {
|
|
|
29
31
|
* The dialog itself: Portal + Backdrop + Viewport + Popup. Enters and exits with opacity and a
|
|
30
32
|
* 0.97 scale; the viewport keeps a 16px gutter on every side so it never touches the screen edge.
|
|
31
33
|
*/
|
|
32
|
-
export function DialogContent({ size = "default", showCloseButton = true, closeLabel
|
|
34
|
+
export function DialogContent({ size = "default", showCloseButton = true, closeLabel, portal, className, children, dir, ...props }) {
|
|
33
35
|
const popupDir = usePopupDir(dir);
|
|
36
|
+
const text = useMessages("dialog", defaultMessages);
|
|
34
37
|
return (_jsxs(BaseDialog.Portal, { ...portal, children: [_jsx(BaseDialog.Backdrop, { "data-slot": "dialog-backdrop", className: overlayBackdrop }), _jsx(BaseDialog.Viewport, { "data-slot": "dialog-viewport", className: "fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-6", children: _jsxs(BaseDialog.Popup, { "data-slot": "dialog-content", "data-size": size, dir: popupDir, className: sx([
|
|
35
38
|
"relative flex max-h-full w-full min-w-0 flex-col gap-6 overflow-hidden rounded-card p-6 font-body outline-none sm:p-8",
|
|
36
39
|
overlayCard,
|
|
37
40
|
"popup-motion",
|
|
38
41
|
dialogSizes[size],
|
|
39
|
-
], className), ...props, children: [children, showCloseButton && (_jsx(BaseDialog.Close, { "data-slot": "dialog-close-button", "aria-label": closeLabel, className: overlayCloseButton, children: _jsx(XIcon, { "aria-hidden": true }) }))] }) })] }));
|
|
42
|
+
], className), ...props, children: [children, showCloseButton && (_jsx(BaseDialog.Close, { "data-slot": "dialog-close-button", "aria-label": closeLabel ?? text.close, className: overlayCloseButton, children: _jsx(XIcon, { "aria-hidden": true }) }))] }) })] }));
|
|
40
43
|
}
|
|
41
44
|
/** Title + description block. Leaves room at the end for the close button. */
|
|
42
45
|
export function DialogHeader({ className, ...props }) {
|
|
@@ -88,5 +91,5 @@ export function DialogFooter({ className, ...props }) {
|
|
|
88
91
|
}
|
|
89
92
|
/** Closes the dialog. Compose with a button: `render={<Button variant="secondary" />}`. */
|
|
90
93
|
export function DialogClose(props) {
|
|
91
|
-
return _jsx(BaseDialog.Close, { "
|
|
94
|
+
return _jsx(BaseDialog.Close, { ...triggerSlot("dialog-close", props.render), ...props });
|
|
92
95
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Drawer as BaseDrawer } from "@base-ui/react/drawer";
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
export interface DrawerMessages {
|
|
4
|
+
/** The close button's name. */
|
|
5
|
+
close: string;
|
|
6
|
+
}
|
|
7
|
+
declare module "./locale" {
|
|
8
|
+
interface Messages {
|
|
9
|
+
drawer: DrawerMessages;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
export type DrawerSide = "bottom" | "right" | "left";
|
|
4
13
|
export interface DrawerProps extends BaseDrawer.Root.Props {
|
|
5
14
|
/**
|
|
@@ -35,7 +44,7 @@ export interface DrawerContentProps extends BaseDrawer.Popup.Props {
|
|
|
35
44
|
fullHeight?: boolean;
|
|
36
45
|
/** Render the circular close button in the top-right corner. */
|
|
37
46
|
showCloseButton?: boolean;
|
|
38
|
-
/** Accessible name of the close button. */
|
|
47
|
+
/** Accessible name of the close button. Default "Close", or `messages.drawer.close` from a LocaleProvider. */
|
|
39
48
|
closeLabel?: string;
|
|
40
49
|
/** Show the grab handle. Defaults to `true` on bottom sheets. */
|
|
41
50
|
showHandle?: boolean;
|
|
@@ -5,6 +5,8 @@ import { XIcon } from "lucide-react";
|
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import { cn, sx, triggerSlot } from "../lib/cn.js";
|
|
7
7
|
import { overlayCard, overlayCloseButton, overlayDescription, overlayFooter, overlayHeader, overlayTitle, usePopupDir, } from "./_overlay.js";
|
|
8
|
+
import { useMessages } from "./locale.js";
|
|
9
|
+
const defaultMessages = { close: "Close" };
|
|
8
10
|
const swipeDirection = { bottom: "down", right: "right", left: "left" };
|
|
9
11
|
const DrawerSideContext = React.createContext("bottom");
|
|
10
12
|
/**
|
|
@@ -41,8 +43,9 @@ const popupBySide = {
|
|
|
41
43
|
* the whole sheet drags; with a mouse, everything except controls and a scrolling body does, so
|
|
42
44
|
* text there stays selectable. Motion lives in `styles/parts/overlays.css`.
|
|
43
45
|
*/
|
|
44
|
-
export function DrawerContent({ size = "default", fullHeight = false, showCloseButton = true, closeLabel
|
|
46
|
+
export function DrawerContent({ size = "default", fullHeight = false, showCloseButton = true, closeLabel, showHandle, portal, className, children, dir, ...props }) {
|
|
45
47
|
const side = React.useContext(DrawerSideContext);
|
|
48
|
+
const text = useMessages("drawer", defaultMessages);
|
|
46
49
|
const popupDir = usePopupDir(dir);
|
|
47
50
|
const handle = showHandle ?? side === "bottom";
|
|
48
51
|
return (_jsxs(BaseDrawer.Portal, { ...portal, children: [_jsx(BaseDrawer.Backdrop, { "data-slot": "drawer-backdrop", className: "fixed inset-0 z-50 min-h-dvh bg-black/40 supports-[-webkit-touch-callout:none]:absolute dark:bg-black/60" }), _jsx(BaseDrawer.Viewport, { "data-slot": "drawer-viewport", className: cn("fixed inset-0 z-50 flex", viewportBySide[side]), children: _jsxs(BaseDrawer.Popup, { "data-slot": "drawer-content", "data-side": side, "data-size": side === "bottom" ? size : undefined, "data-full-height": side === "bottom" && fullHeight ? "" : undefined, dir: popupDir, className: sx([
|
|
@@ -54,7 +57,7 @@ export function DrawerContent({ size = "default", fullHeight = false, showCloseB
|
|
|
54
57
|
], className), ...props, children: [handle && (_jsx("div", { "data-slot": "drawer-handle-area", className: "flex h-7 shrink-0 cursor-grab justify-center pt-3 in-data-swiping:cursor-grabbing", children: _jsx("div", { "data-slot": "drawer-handle", "aria-hidden": true, className: "h-1 w-10 rounded-full bg-field-edge" }) })), _jsx("div", { "data-slot": "drawer-body", className: cn(
|
|
55
58
|
// Its children keep their height and the body scrolls: shrunk to fit, a table or a
|
|
56
59
|
// code block (anything that scrolls itself) would fold down to nothing.
|
|
57
|
-
"flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto overscroll-contain p-6 break-words *:shrink-0 sm:p-8", side === "bottom" && "pb-[calc(1.5rem+env(safe-area-inset-bottom,0px))]", handle && "pt-2 sm:pt-3"), children: children }), showCloseButton && (_jsx(BaseDrawer.Close, { "data-slot": "drawer-close-button", "aria-label": closeLabel, className: overlayCloseButton, children: _jsx(XIcon, { "aria-hidden": true }) }))] }) })] }));
|
|
60
|
+
"flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto overscroll-contain p-6 break-words *:shrink-0 sm:p-8", side === "bottom" && "pb-[calc(1.5rem+env(safe-area-inset-bottom,0px))]", handle && "pt-2 sm:pt-3"), children: children }), showCloseButton && (_jsx(BaseDrawer.Close, { "data-slot": "drawer-close-button", "aria-label": closeLabel ?? text.close, className: overlayCloseButton, children: _jsx(XIcon, { "aria-hidden": true }) }))] }) })] }));
|
|
58
61
|
}
|
|
59
62
|
/** Title + description block. Leaves room at the end for the close button. */
|
|
60
63
|
export function DrawerHeader({ className, ...props }) {
|
|
@@ -72,5 +75,5 @@ export function DrawerFooter({ className, ...props }) {
|
|
|
72
75
|
}
|
|
73
76
|
/** Closes the drawer. Compose with a button: `render={<Button variant="secondary" />}`. */
|
|
74
77
|
export function DrawerClose(props) {
|
|
75
|
-
return _jsx(BaseDrawer.Close, { "
|
|
78
|
+
return _jsx(BaseDrawer.Close, { ...triggerSlot("drawer-close", props.render), ...props });
|
|
76
79
|
}
|
|
@@ -23,7 +23,7 @@ export function FeatureList({ columns = 3, className, ...props }) {
|
|
|
23
23
|
* title and body.
|
|
24
24
|
*/
|
|
25
25
|
export function FeatureItem({ index, icon, title, titleFont = "body", titleAs: Title = "h3", className, children, ...props }) {
|
|
26
|
-
return (_jsxs("li", { "data-slot": "feature-item", className: cn("flex flex-col border-t border-border pt-6 pb-10 sm:pt-7 sm:pb-12", className), ...props, children: [index != null || icon != null ? (_jsxs("div", { className: "mb-8 flex items-center justify-between gap-4 sm:mb-10", children: [_jsx("span", { "data-slot": "feature-item-index", className: "font-mono text-xs leading-none tracking-[0.08em] text-muted-foreground tabular-nums", children: index }), icon != null ? (_jsx("span", { "data-slot": "feature-item-icon", "aria-hidden": true, className: "text-foreground-soft [&_svg]:size-5 [&_svg]:shrink-0", children: icon })) : null] })) : null, _jsx(Title, { "data-slot": "feature-item-title", className: cn("m-0 text-foreground", titleFont === "heading"
|
|
26
|
+
return (_jsxs("li", { "data-slot": "feature-item", className: cn("flex flex-col border-t border-border pt-6 pb-10 sm:pt-7 sm:pb-12", className), ...props, children: [index != null || icon != null ? (_jsxs("div", { "data-slot": "feature-item-header", className: "mb-8 flex items-center justify-between gap-4 sm:mb-10", children: [_jsx("span", { "data-slot": "feature-item-index", className: "font-mono text-xs leading-none tracking-[0.08em] text-muted-foreground tabular-nums", children: index }), icon != null ? (_jsx("span", { "data-slot": "feature-item-icon", "aria-hidden": true, className: "text-foreground-soft [&_svg]:size-5 [&_svg]:shrink-0", children: icon })) : null] })) : null, _jsx(Title, { "data-slot": "feature-item-title", className: cn("m-0 text-foreground", titleFont === "heading"
|
|
27
27
|
? "font-heading text-[24px] leading-[1.15] font-light tracking-[-0.02em] sm:text-[26px]"
|
|
28
28
|
: "font-body text-[17px] leading-snug font-medium tracking-normal sm:text-[18px]"), children: title }), children != null ? (_jsx("div", { "data-slot": "feature-item-body", className: "mt-3 flex flex-col gap-4 text-[16px] leading-relaxed text-foreground-soft [&>p]:m-0", children: children })) : null] }));
|
|
29
29
|
}
|
|
@@ -39,5 +39,5 @@ export function FeatureCalloutList({ className, ...props }) {
|
|
|
39
39
|
* "Fast search — Find any note by a word inside it, as you type."
|
|
40
40
|
*/
|
|
41
41
|
export function FeatureCallout({ icon, label, className, children, ...props }) {
|
|
42
|
-
return (_jsxs("li", { "data-slot": "feature-callout", className: cn("flex items-start gap-3 text-[15px] leading-relaxed text-foreground-soft", className), ...props, children: [icon != null ? (_jsx("span", { "aria-hidden": true, className: "mt-[0.3em] text-foreground [&_svg]:size-4 [&_svg]:shrink-0", children: icon })) : null, _jsxs("span", { className: "min-w-0", children: [_jsx("strong", { className: "font-mono text-[13px] font-semibold tracking-[0.02em] text-foreground", children: label }), children != null ? _jsxs(_Fragment, { children: [" \u2014 ", children] }) : null] })] }));
|
|
42
|
+
return (_jsxs("li", { "data-slot": "feature-callout", className: cn("flex items-start gap-3 text-[15px] leading-relaxed text-foreground-soft", className), ...props, children: [icon != null ? (_jsx("span", { "data-slot": "feature-callout-icon", "aria-hidden": true, className: "mt-[0.3em] text-foreground [&_svg]:size-4 [&_svg]:shrink-0", children: icon })) : null, _jsxs("span", { className: "min-w-0", children: [_jsx("strong", { "data-slot": "feature-callout-label", className: "font-mono text-[13px] font-semibold tracking-[0.02em] text-foreground", children: label }), children != null ? _jsxs(_Fragment, { children: [" \u2014 ", children] }) : null] })] }));
|
|
43
43
|
}
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
import { Field as BaseField } from "@base-ui/react/field";
|
|
2
2
|
import { Fieldset as BaseFieldset } from "@base-ui/react/fieldset";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { type FieldErrorLike } from "../lib/field-errors.js";
|
|
5
|
+
export interface FieldProps extends BaseField.Root.Props {
|
|
6
|
+
/**
|
|
7
|
+
* The field's error from a form library or your own state: a message, an object with a
|
|
8
|
+
* `message` (React Hook Form's `fieldState.error`) or a list of them (TanStack Form's
|
|
9
|
+
* `field.state.meta.errors`). Any message marks the field invalid, and a bare `<FieldError />`
|
|
10
|
+
* shows it. Inside a `Form`, a submit then goes to `onSubmit` for the library to check again.
|
|
11
|
+
*/
|
|
12
|
+
error?: FieldErrorLike | readonly FieldErrorLike[];
|
|
13
|
+
}
|
|
3
14
|
/**
|
|
4
15
|
* Field — groups a label, a control, a description and validation.
|
|
5
16
|
* Every control needs a visible label. Errors use destructive ink *plus* a message.
|
|
17
|
+
*
|
|
18
|
+
* With a form library, pass its error to `error` and end the field with a bare `<FieldError />`.
|
|
6
19
|
*/
|
|
7
|
-
export declare function Field({ className, ...props }:
|
|
8
|
-
export declare function FieldLabel({ className, ...props }: BaseField.Label.Props):
|
|
9
|
-
export declare function FieldDescription({ className, ...props }: BaseField.Description.Props):
|
|
10
|
-
|
|
20
|
+
export declare function Field({ className, error, invalid, ...props }: FieldProps): React.JSX.Element;
|
|
21
|
+
export declare function FieldLabel({ className, ...props }: BaseField.Label.Props): React.JSX.Element;
|
|
22
|
+
export declare function FieldDescription({ className, ...props }: BaseField.Description.Props): React.JSX.Element;
|
|
23
|
+
/**
|
|
24
|
+
* FieldError — the field's error message, linked to its control. With `match` (`"valueMissing"`,
|
|
25
|
+
* `"typeMismatch"` …) it shows its own words for that one problem. Bare, it shows the `error` passed
|
|
26
|
+
* to its `Field`, an error the `Form` got from the server, or the browser's message for a problem
|
|
27
|
+
* no `match` beside it covers — so a bare one after the `match` ones adds the server's errors.
|
|
28
|
+
*/
|
|
29
|
+
export declare function FieldError({ className, match, children, ...props }: BaseField.Error.Props): React.JSX.Element;
|
|
11
30
|
/** A labelled group of fields (radio groups, checkbox groups, address blocks). */
|
|
12
|
-
export declare function Fieldset({ className, ...props }: BaseFieldset.Root.Props):
|
|
13
|
-
export declare function FieldsetLegend({ className, ...props }: BaseFieldset.Legend.Props):
|
|
14
|
-
export declare const FieldItem:
|
|
15
|
-
export declare const FieldValidity:
|
|
31
|
+
export declare function Fieldset({ className, ...props }: BaseFieldset.Root.Props): React.JSX.Element;
|
|
32
|
+
export declare function FieldsetLegend({ className, ...props }: BaseFieldset.Legend.Props): React.JSX.Element;
|
|
33
|
+
export declare const FieldItem: React.ForwardRefExoticComponent<Omit<import("@base-ui/react").FieldItemProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
34
|
+
export declare const FieldValidity: React.FC<import("@base-ui/react").FieldValidityProps>;
|
package/dist/components/field.js
CHANGED
|
@@ -2,13 +2,38 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Field as BaseField } from "@base-ui/react/field";
|
|
4
4
|
import { Fieldset as BaseFieldset } from "@base-ui/react/fieldset";
|
|
5
|
+
import * as React from "react";
|
|
5
6
|
import { sx } from "../lib/cn.js";
|
|
7
|
+
import { errorMessages, FieldErrorsContext, LibraryErrorsContext, } from "../lib/field-errors.js";
|
|
6
8
|
/**
|
|
7
9
|
* Field — groups a label, a control, a description and validation.
|
|
8
10
|
* Every control needs a visible label. Errors use destructive ink *plus* a message.
|
|
11
|
+
*
|
|
12
|
+
* With a form library, pass its error to `error` and end the field with a bare `<FieldError />`.
|
|
9
13
|
*/
|
|
10
|
-
export function Field({ className, ...props }) {
|
|
11
|
-
|
|
14
|
+
export function Field({ className, error, invalid, ...props }) {
|
|
15
|
+
// `errorMessages` returns a new list each time: keep it while the messages are the same.
|
|
16
|
+
const latest = errorMessages(error);
|
|
17
|
+
const [messages, setMessages] = React.useState(latest);
|
|
18
|
+
if (latest.join("\n") !== messages.join("\n"))
|
|
19
|
+
setMessages(latest);
|
|
20
|
+
const failing = messages.length > 0;
|
|
21
|
+
const libraryErrors = React.useContext(LibraryErrorsContext);
|
|
22
|
+
const id = React.useId();
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
if (!libraryErrors || !failing)
|
|
25
|
+
return;
|
|
26
|
+
libraryErrors.add(id);
|
|
27
|
+
return () => void libraryErrors.delete(id);
|
|
28
|
+
}, [libraryErrors, failing, id]);
|
|
29
|
+
// The problems a `FieldError match="…"` has its own words for, so a bare one doesn't repeat them.
|
|
30
|
+
const [covered, setCovered] = React.useState([]);
|
|
31
|
+
const cover = React.useCallback((problem) => {
|
|
32
|
+
setCovered((list) => [...list, problem]);
|
|
33
|
+
return () => setCovered((list) => list.filter((_, i) => i !== list.indexOf(problem)));
|
|
34
|
+
}, []);
|
|
35
|
+
const context = React.useMemo(() => ({ messages, covered, cover }), [messages, covered, cover]);
|
|
36
|
+
return (_jsx(FieldErrorsContext.Provider, { value: context, children: _jsx(BaseField.Root, { "data-slot": "field", className: sx("flex flex-col gap-2", className), invalid: invalid ?? (failing || undefined), ...props }) }));
|
|
12
37
|
}
|
|
13
38
|
export function FieldLabel({ className, ...props }) {
|
|
14
39
|
return (_jsx(BaseField.Label, { "data-slot": "field-label", className: sx([
|
|
@@ -22,8 +47,28 @@ export function FieldLabel({ className, ...props }) {
|
|
|
22
47
|
export function FieldDescription({ className, ...props }) {
|
|
23
48
|
return (_jsx(BaseField.Description, { "data-slot": "field-description", className: sx("text-[13px] leading-normal text-muted-foreground", className), ...props }));
|
|
24
49
|
}
|
|
25
|
-
|
|
26
|
-
|
|
50
|
+
/**
|
|
51
|
+
* FieldError — the field's error message, linked to its control. With `match` (`"valueMissing"`,
|
|
52
|
+
* `"typeMismatch"` …) it shows its own words for that one problem. Bare, it shows the `error` passed
|
|
53
|
+
* to its `Field`, an error the `Form` got from the server, or the browser's message for a problem
|
|
54
|
+
* no `match` beside it covers — so a bare one after the `match` ones adds the server's errors.
|
|
55
|
+
*/
|
|
56
|
+
export function FieldError({ className, match, children, ...props }) {
|
|
57
|
+
const { messages, covered, cover } = React.useContext(FieldErrorsContext);
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
if (typeof match === "string" && match !== "valid")
|
|
60
|
+
return cover(match);
|
|
61
|
+
}, [match, cover]);
|
|
62
|
+
// The Field's `error`, unless this message is for one native problem (`match`).
|
|
63
|
+
const library = match === undefined && messages.length > 0;
|
|
64
|
+
const text = library
|
|
65
|
+
? (children ??
|
|
66
|
+
(messages.length > 1 ? (_jsx("ul", { children: messages.map((message) => (_jsx("li", { children: message }, message))) })) : (messages[0])))
|
|
67
|
+
: children;
|
|
68
|
+
const error = (_jsx(BaseField.Error, { "data-slot": "field-error", className: sx("text-[13px] leading-normal text-destructive", className), match: library || match, ...(text === undefined ? {} : { children: text }), ...props }));
|
|
69
|
+
if (match !== undefined)
|
|
70
|
+
return error;
|
|
71
|
+
return (_jsx(BaseField.Validity, { children: ({ validity }) => !library && covered.some((problem) => validity[problem]) ? null : error }));
|
|
27
72
|
}
|
|
28
73
|
/** A labelled group of fields (radio groups, checkbox groups, address blocks). */
|
|
29
74
|
export function Fieldset({ className, ...props }) {
|