@slashsuite/ui-react 0.12.1 → 0.13.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/MIGRATING.md +386 -8
- package/README.md +89 -44
- package/agent-docs/components/app-shell.md +9 -6
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/badge.md +2 -1
- package/agent-docs/components/body-text.md +26 -15
- package/agent-docs/components/bottom-sheet.md +27 -17
- package/agent-docs/components/breadcrumbs.md +10 -6
- package/agent-docs/components/button.md +2 -2
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +4 -3
- package/agent-docs/components/card-grid.md +15 -7
- package/agent-docs/components/card.md +33 -18
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/chat-composer.md +4 -3
- package/agent-docs/components/checkbox.md +11 -5
- package/agent-docs/components/cluster.md +10 -8
- package/agent-docs/components/code-example.md +2 -2
- package/agent-docs/components/code.md +7 -5
- package/agent-docs/components/colour-scheme-toggle.md +12 -6
- package/agent-docs/components/colour-swatch.md +41 -0
- package/agent-docs/components/combobox.md +88 -0
- package/agent-docs/components/confirm-dialog.md +98 -0
- package/agent-docs/components/container.md +2 -1
- package/agent-docs/components/copy-button.md +7 -5
- package/agent-docs/components/copy-line.md +6 -5
- package/agent-docs/components/date-field.md +14 -11
- package/agent-docs/components/date-range-picker.md +16 -9
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/dialog.md +22 -68
- package/agent-docs/components/disclosure.md +4 -0
- package/agent-docs/components/docs-layout.md +10 -6
- package/agent-docs/components/drawer.md +13 -4
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +4 -1
- package/agent-docs/components/field-dialog.md +6 -5
- package/agent-docs/components/field.md +10 -7
- package/agent-docs/components/fieldset.md +4 -4
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +4 -1
- package/agent-docs/components/form-row.md +7 -7
- package/agent-docs/components/full-bleed-layout.md +0 -2
- package/agent-docs/components/headings.md +13 -7
- package/agent-docs/components/hero.md +11 -2
- package/agent-docs/components/icon-button.md +1 -3
- package/agent-docs/components/icon.md +6 -13
- package/agent-docs/components/image.md +24 -14
- package/agent-docs/components/input.md +8 -7
- package/agent-docs/components/key-value-list.md +4 -1
- package/agent-docs/components/lightbox.md +1 -1
- package/agent-docs/components/list-layout.md +5 -7
- package/agent-docs/components/list-row.md +37 -34
- package/agent-docs/components/loading.md +2 -2
- package/agent-docs/components/markdown.md +13 -13
- package/agent-docs/components/media-tile.md +8 -4
- package/agent-docs/components/menu.md +19 -12
- package/agent-docs/components/meta-list.md +2 -2
- package/agent-docs/components/morph.md +11 -5
- package/agent-docs/components/navigation-progress.md +2 -2
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +19 -8
- package/agent-docs/components/page-fade.md +2 -1
- package/agent-docs/components/pill.md +7 -6
- package/agent-docs/components/popover.md +63 -0
- package/agent-docs/components/price.md +49 -0
- package/agent-docs/components/product-tile.md +78 -0
- package/agent-docs/components/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +1 -1
- package/agent-docs/components/radio-group.md +9 -6
- package/agent-docs/components/scroll-strip.md +3 -3
- package/agent-docs/components/segmented-control.md +4 -2
- package/agent-docs/components/select.md +8 -3
- package/agent-docs/components/show.md +2 -2
- package/agent-docs/components/side-column.md +13 -9
- package/agent-docs/components/sidebar-layout.md +1 -1
- package/agent-docs/components/site-footer.md +4 -4
- package/agent-docs/components/site-search.md +21 -9
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +15 -10
- package/agent-docs/components/stack.md +3 -3
- package/agent-docs/components/stacked-bar.md +7 -4
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +13 -6
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/switch.md +4 -4
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +35 -24
- package/agent-docs/components/tabs.md +24 -26
- package/agent-docs/components/text-link.md +12 -7
- package/agent-docs/components/textarea.md +4 -2
- package/agent-docs/components/toast.md +19 -14
- package/agent-docs/components/video.md +7 -2
- package/agent-docs/llms.txt +22 -3
- package/dist/AppShell.d.ts +25 -9
- package/dist/AppShell.js +67 -33
- package/dist/AppShellMenu.d.ts +31 -18
- package/dist/AppShellMenu.js +72 -45
- package/dist/ArticleLayout.d.ts +36 -0
- package/dist/ArticleLayout.js +27 -0
- package/dist/Audio.d.ts +16 -0
- package/dist/Audio.js +11 -0
- package/dist/Badge.d.ts +2 -1
- package/dist/Badge.js +3 -2
- package/dist/BottomSheet.d.ts +17 -6
- package/dist/BottomSheet.js +62 -11
- package/dist/Breadcrumbs.d.ts +8 -6
- package/dist/Breadcrumbs.js +17 -7
- package/dist/Button.d.ts +4 -2
- package/dist/Button.js +9 -87
- package/dist/CallToAction.d.ts +25 -0
- package/dist/CallToAction.js +17 -0
- package/dist/Callout.d.ts +2 -2
- package/dist/Callout.js +2 -2
- package/dist/Card.d.ts +88 -31
- package/dist/Card.js +55 -92
- package/dist/CardBody.d.ts +2 -0
- package/dist/CardBody.js +33 -3
- package/dist/CardGrid.d.ts +32 -4
- package/dist/CardGrid.js +42 -8
- package/dist/CardParts.d.ts +7 -1
- package/dist/CardParts.js +7 -2
- package/dist/CartButton.d.ts +33 -0
- package/dist/CartButton.js +18 -0
- package/dist/ChatComposer.d.ts +10 -4
- package/dist/ChatComposer.js +35 -13
- package/dist/Checkbox.d.ts +21 -3
- package/dist/Checkbox.js +66 -20
- package/dist/Chevron.js +1 -1
- package/dist/Cluster.d.ts +28 -15
- package/dist/Cluster.js +21 -4
- package/dist/Code.d.ts +15 -3
- package/dist/Code.js +23 -3
- package/dist/CodeBlock.d.ts +4 -4
- package/dist/CodeBlock.js +2 -2
- package/dist/CodeBody.d.ts +1 -1
- package/dist/CodeBody.js +4 -10
- package/dist/CodeExample.d.ts +1 -1
- package/dist/CodeExample.js +3 -2
- package/dist/ColourSchemeToggle.d.ts +21 -5
- package/dist/ColourSchemeToggle.js +15 -9
- package/dist/ColourSwatch.d.ts +15 -0
- package/dist/ColourSwatch.js +14 -0
- package/dist/Combobox.d.ts +42 -0
- package/dist/Combobox.js +43 -0
- package/dist/ConfirmDialog.d.ts +40 -0
- package/dist/ConfirmDialog.js +36 -0
- package/dist/Container.d.ts +3 -3
- package/dist/Container.js +1 -1
- package/dist/CopyButton.d.ts +8 -2
- package/dist/CopyButton.js +38 -28
- package/dist/CopyLine.d.ts +4 -2
- package/dist/CopyLine.js +4 -4
- package/dist/DateCalendar.d.ts +2 -0
- package/dist/DateCalendar.js +11 -9
- package/dist/DateField.d.ts +52 -21
- package/dist/DateField.js +73 -37
- package/dist/DateFieldCalendar.d.ts +12 -8
- package/dist/DateFieldCalendar.js +37 -18
- package/dist/DateRangePicker.d.ts +23 -3
- package/dist/DateRangePicker.js +10 -8
- package/dist/DateTimeField.d.ts +31 -0
- package/dist/DateTimeField.js +19 -0
- package/dist/Dialog.d.ts +42 -6
- package/dist/Dialog.js +50 -12
- package/dist/Disclosure.js +9 -1
- package/dist/DocsLayout.d.ts +13 -5
- package/dist/DocsLayout.js +11 -9
- package/dist/Drawer.d.ts +22 -7
- package/dist/Drawer.js +89 -8
- package/dist/EmbedFrame.d.ts +36 -0
- package/dist/EmbedFrame.js +18 -0
- package/dist/Field.d.ts +41 -4
- package/dist/Field.js +61 -25
- package/dist/FieldDialog.d.ts +8 -3
- package/dist/FieldDialog.js +19 -9
- package/dist/Fieldset.d.ts +3 -3
- package/dist/Fieldset.js +7 -9
- package/dist/FileDrop.js +2 -1
- package/dist/FlowDiagram.d.ts +92 -0
- package/dist/FlowDiagram.js +100 -0
- package/dist/FormRow.d.ts +6 -4
- package/dist/FormRow.js +11 -9
- package/dist/Hero.d.ts +30 -7
- package/dist/Hero.js +23 -9
- package/dist/Icon.d.ts +1 -1
- package/dist/Icon.js +1 -1
- package/dist/IconButton.js +1 -1
- package/dist/Image.d.ts +33 -9
- package/dist/Image.js +61 -16
- package/dist/Input.d.ts +1 -1
- package/dist/Input.js +4 -4
- package/dist/InputShell.d.ts +7 -0
- package/dist/InputShell.js +18 -3
- package/dist/KeyValueList.d.ts +2 -2
- package/dist/Lightbox.js +5 -3
- package/dist/ListRow.d.ts +4 -5
- package/dist/ListRow.js +36 -26
- package/dist/Mark.d.ts +10 -0
- package/dist/Mark.js +9 -0
- package/dist/Markdown.d.ts +18 -4
- package/dist/Markdown.js +176 -37
- package/dist/MediaTile.d.ts +9 -3
- package/dist/MediaTile.js +8 -4
- package/dist/Menu.d.ts +19 -8
- package/dist/Menu.js +13 -11
- package/dist/MetaList.d.ts +4 -3
- package/dist/MetaList.js +12 -4
- package/dist/Morph.d.ts +15 -1
- package/dist/Morph.js +70 -22
- package/dist/NavigationProgress.d.ts +2 -2
- package/dist/NavigationProgress.js +7 -5
- package/dist/NumberField.d.ts +66 -0
- package/dist/NumberField.js +68 -0
- package/dist/OutlineRegion.d.ts +41 -10
- package/dist/OutlineRegion.js +31 -6
- package/dist/PageFade.d.ts +9 -5
- package/dist/PageFade.js +39 -8
- package/dist/PageLayouts.d.ts +15 -5
- package/dist/PageLayouts.js +3 -3
- package/dist/Pill.d.ts +9 -4
- package/dist/Pill.js +15 -6
- package/dist/Popover.d.ts +31 -0
- package/dist/Popover.js +43 -0
- package/dist/Price.d.ts +21 -0
- package/dist/Price.js +34 -0
- package/dist/ProductTile.d.ts +36 -0
- package/dist/ProductTile.js +31 -0
- package/dist/ProgressBar.js +4 -2
- package/dist/PromoBanner.d.ts +25 -0
- package/dist/PromoBanner.js +16 -0
- package/dist/RadioGroup.d.ts +18 -8
- package/dist/RadioGroup.js +42 -18
- package/dist/ScrollStrip.d.ts +1 -1
- package/dist/ScrollStrip.js +1 -1
- package/dist/SearchInput.d.ts +17 -2
- package/dist/SearchInput.js +72 -13
- package/dist/SegmentedField.d.ts +15 -0
- package/dist/SegmentedField.js +15 -0
- package/dist/Select.js +5 -4
- package/dist/Show.d.ts +1 -1
- package/dist/Show.js +1 -1
- package/dist/SideColumn.d.ts +42 -15
- package/dist/SideColumn.js +45 -19
- package/dist/SiteFooter.d.ts +3 -3
- package/dist/SiteFooter.js +4 -3
- package/dist/SiteSearch.d.ts +57 -27
- package/dist/SiteSearch.js +13 -93
- package/dist/Slider.d.ts +27 -0
- package/dist/Slider.js +58 -0
- package/dist/SortableList.d.ts +19 -35
- package/dist/SortableList.js +36 -88
- package/dist/Stack.d.ts +4 -4
- package/dist/StackedBar.d.ts +13 -4
- package/dist/StackedBar.js +12 -7
- package/dist/StateMachine.d.ts +65 -0
- package/dist/StateMachine.js +116 -0
- package/dist/StatusPages.d.ts +28 -10
- package/dist/StatusPages.js +10 -10
- package/dist/Stepper.d.ts +21 -0
- package/dist/Stepper.js +33 -0
- package/dist/Steps.js +4 -3
- package/dist/Switch.d.ts +3 -3
- package/dist/Switch.js +18 -14
- package/dist/Table.d.ts +32 -9
- package/dist/Table.js +50 -20
- package/dist/TableCells.d.ts +24 -21
- package/dist/TableCells.js +68 -27
- package/dist/TableEditCell.d.ts +1 -1
- package/dist/TableOfContents.d.ts +34 -0
- package/dist/TableOfContents.js +23 -0
- package/dist/Tabs.d.ts +31 -16
- package/dist/Tabs.js +97 -22
- package/dist/TextLink.d.ts +18 -5
- package/dist/TextLink.js +19 -6
- package/dist/Textarea.d.ts +12 -1
- package/dist/Textarea.js +15 -2
- package/dist/ToastRegion.d.ts +17 -9
- package/dist/ToastRegion.js +70 -13
- package/dist/Tooltip.d.ts +10 -2
- package/dist/Tooltip.js +32 -11
- package/dist/Video.d.ts +19 -4
- package/dist/Video.js +15 -5
- package/dist/cardContext.d.ts +7 -0
- package/dist/cardContext.js +14 -0
- package/dist/cardControl.d.ts +15 -0
- package/dist/cardControl.js +32 -0
- package/dist/cardForm.d.ts +39 -0
- package/dist/cardForm.js +81 -0
- package/dist/cardWait.js +2 -1
- package/dist/colourScheme.d.ts +12 -2
- package/dist/colourScheme.js +32 -6
- package/dist/control.d.ts +30 -8
- package/dist/control.js +74 -7
- package/dist/copyScript.d.ts +7 -8
- package/dist/copyScript.js +8 -9
- package/dist/core/button.d.ts +33 -0
- package/dist/core/button.js +89 -0
- package/dist/core/control.d.ts +15 -0
- package/dist/core/control.js +14 -0
- package/dist/core/fixtures/button.d.ts +26 -0
- package/dist/core/fixtures/button.js +52 -0
- package/dist/core/fixtures/types.d.ts +13 -0
- package/dist/core/fixtures/types.js +10 -0
- package/dist/core/focus.d.ts +7 -0
- package/dist/core/focus.js +7 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.js +12 -0
- package/dist/core/parity.d.ts +22 -0
- package/dist/core/parity.js +53 -0
- package/dist/core/themeNative.d.ts +62 -0
- package/dist/core/themeNative.js +290 -0
- package/dist/cx.d.ts +17 -5
- package/dist/cx.js +18 -5
- package/dist/dateLocale.d.ts +17 -0
- package/dist/dateLocale.js +30 -0
- package/dist/density.d.ts +17 -3
- package/dist/density.js +30 -19
- package/dist/emptySlot.d.ts +1 -0
- package/dist/fieldAnnounce.d.ts +11 -0
- package/dist/fieldAnnounce.js +36 -0
- package/dist/fieldControl.d.ts +7 -2
- package/dist/fieldControl.js +6 -2
- package/dist/fieldWait.d.ts +3 -3
- package/dist/fieldWait.js +3 -4
- package/dist/flowLayout.d.ts +68 -0
- package/dist/flowLayout.js +105 -0
- package/dist/focus.d.ts +2 -0
- package/dist/focus.js +9 -0
- package/dist/fromXState.d.ts +73 -0
- package/dist/fromXState.js +110 -0
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +15 -0
- package/dist/index.d.ts +37 -11
- package/dist/index.js +24 -2
- package/dist/isoDate.d.ts +8 -1
- package/dist/isoDate.js +20 -1
- package/dist/labelWords.d.ts +16 -7
- package/dist/labelWords.js +14 -12
- package/dist/listRowProps.d.ts +17 -15
- package/dist/modal.d.ts +5 -0
- package/dist/modal.js +21 -1
- package/dist/navFold.js +6 -3
- package/dist/optionCard.d.ts +18 -0
- package/dist/optionCard.js +16 -0
- package/dist/scrollBody.d.ts +16 -0
- package/dist/scrollBody.js +15 -0
- package/dist/scrollEdges.d.ts +7 -0
- package/dist/scrollEdges.js +39 -5
- package/dist/scrollStop.d.ts +6 -2
- package/dist/scrollStop.js +24 -8
- package/dist/shownDate.d.ts +28 -10
- package/dist/shownDate.js +41 -22
- package/dist/siteSearchBody.d.ts +34 -0
- package/dist/siteSearchBody.js +117 -0
- package/dist/size.d.ts +7 -1
- package/dist/sortableDrop.d.ts +44 -0
- package/dist/sortableDrop.js +78 -0
- package/dist/sortableSlide.d.ts +9 -0
- package/dist/sortableSlide.js +70 -0
- package/dist/sortableTitle.d.ts +10 -0
- package/dist/sortableTitle.js +48 -0
- package/dist/stateMachineDots.d.ts +77 -0
- package/dist/stateMachineDots.js +188 -0
- package/dist/stickyColumn.d.ts +2 -2
- package/dist/stickyColumn.js +2 -2
- package/dist/switcher.d.ts +10 -5
- package/dist/switcher.js +7 -5
- package/dist/tableColumns.d.ts +17 -0
- package/dist/tableColumns.js +30 -2
- package/dist/tableEmpty.js +5 -5
- package/dist/tableRow.d.ts +26 -2
- package/dist/tableRow.js +23 -1
- package/dist/tableSort.d.ts +10 -5
- package/dist/tableSort.js +15 -4
- package/dist/target.d.ts +12 -0
- package/dist/target.js +12 -0
- package/dist/textBox.js +1 -1
- package/dist/truncated.d.ts +31 -0
- package/dist/truncated.js +51 -0
- package/dist/typography.d.ts +19 -11
- package/dist/typography.js +11 -13
- package/dist/useFlowLayout.d.ts +38 -0
- package/dist/useFlowLayout.js +122 -0
- package/package.json +5 -3
package/dist/DateField.d.ts
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
|
-
import { type CalendarDate } from "@internationalized/date";
|
|
1
|
+
import { type CalendarDate, type DateValue } from "@internationalized/date";
|
|
2
2
|
import { type ContextType, type ReactElement, type ReactNode } from "react";
|
|
3
3
|
import { type DateFieldProps as AriaDateFieldProps, DateFieldStateContext } from "react-aria-components";
|
|
4
|
-
import {
|
|
4
|
+
import type { Passthrough } from "./props.js";
|
|
5
5
|
import { type LoadingProps } from "./skeleton.js";
|
|
6
|
-
import type
|
|
7
|
-
/** Fixed, whatever the browser's locale: DD/MM/YYYY and Monday-first weeks. */
|
|
8
|
-
export declare const LOCALE = "en-GB";
|
|
9
|
-
export declare const MONTH_OPTIONS: {
|
|
10
|
-
month: number;
|
|
11
|
-
name: string;
|
|
12
|
-
}[];
|
|
6
|
+
import { type ResponsiveSize, type Size } from "./size.js";
|
|
13
7
|
type Segment = NonNullable<ContextType<typeof DateFieldStateContext>>["segments"][number];
|
|
14
8
|
/** The props of a plain `DateField`, without the calendar. */
|
|
15
9
|
export type FieldProps = {
|
|
16
10
|
/** The field's visible label, above it. Without one, name the field with `aria-label`. */
|
|
17
11
|
label?: ReactNode;
|
|
18
|
-
/** A muted line under the field that says more; an error
|
|
12
|
+
/** A muted line under the field that says more; it stays while an error shows under it. */
|
|
19
13
|
hint?: ReactNode;
|
|
20
14
|
/**
|
|
21
|
-
* Marks the field invalid and shows this in red
|
|
15
|
+
* Marks the field invalid and shows this in red under the hint, announced politely, in place of
|
|
22
16
|
* the built-in message (an impossible date, or one outside min/max). Like `Field`'s `error`.
|
|
23
17
|
*/
|
|
24
18
|
error?: ReactNode;
|
|
25
19
|
/**
|
|
26
20
|
* The field's height and text, on the same scale as an `Input`: `sm` is `text-sm`, `md` `text-base`,
|
|
27
21
|
* `lg` `text-lg`, one step down under an `AppShell density="compact"`, and never under 16px on touch.
|
|
22
|
+
* `{ base: "md", md: "lg" }` changes size at the `md` breakpoint (48rem), in CSS, as an `Input`'s does.
|
|
28
23
|
* @default md
|
|
29
24
|
*/
|
|
30
|
-
size?: Size;
|
|
25
|
+
size?: Size | ResponsiveSize;
|
|
31
26
|
/** Disables the field: no typing, no calendar. */
|
|
32
27
|
disabled?: boolean | undefined;
|
|
33
28
|
/** Marks a date required: the field is `aria-required`, and an empty one is invalid. */
|
|
@@ -42,8 +37,15 @@ export type FieldProps = {
|
|
|
42
37
|
minValue?: AriaDateFieldProps<CalendarDate>["minValue"];
|
|
43
38
|
/** The latest date allowed: a later one marks the field invalid with its own message. */
|
|
44
39
|
maxValue?: AriaDateFieldProps<CalendarDate>["maxValue"];
|
|
45
|
-
/** Posts the date in a form as `YYYY-MM-DD` under this key, or an empty string
|
|
40
|
+
/** Posts the date in a form as `YYYY-MM-DD` under this key, or an empty string, whatever the `locale`. */
|
|
46
41
|
name?: AriaDateFieldProps<CalendarDate>["name"];
|
|
42
|
+
/**
|
|
43
|
+
* The locale the field writes its date in, a BCP 47 tag: `en-GB` is DD/MM/YYYY, `en-US`
|
|
44
|
+
* MM/DD/YYYY, `en-ZA` YYYY/MM/DD. It sets the order of the segments, the month names, the
|
|
45
|
+
* calendar's first weekday and the dates in its messages. Without it the field follows the app's
|
|
46
|
+
* own `I18nProvider`, or else the browser's language.
|
|
47
|
+
*/
|
|
48
|
+
locale?: string | undefined;
|
|
47
49
|
} & Passthrough;
|
|
48
50
|
/** The calendar's dropdown names, with their English defaults. */
|
|
49
51
|
type CalendarNames = {
|
|
@@ -57,6 +59,11 @@ type CalendarNames = {
|
|
|
57
59
|
* @default Year
|
|
58
60
|
*/
|
|
59
61
|
yearLabel?: string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* The calendar's footer button that empties the field, for an app in another language.
|
|
64
|
+
* @default Clear
|
|
65
|
+
*/
|
|
66
|
+
clearLabel?: string | undefined;
|
|
60
67
|
};
|
|
61
68
|
export type DateFieldProps = FieldProps & LoadingProps & ({
|
|
62
69
|
/** Adds a calendar button that opens a month view in a popover; the field is a date picker. */
|
|
@@ -67,6 +74,8 @@ export type DateFieldProps = FieldProps & LoadingProps & ({
|
|
|
67
74
|
monthLabel?: undefined;
|
|
68
75
|
/** Only a `calendar` field takes `yearLabel`. */
|
|
69
76
|
yearLabel?: undefined;
|
|
77
|
+
/** Only a `calendar` field takes `clearLabel`. */
|
|
78
|
+
clearLabel?: undefined;
|
|
70
79
|
} | ({
|
|
71
80
|
calendar: true;
|
|
72
81
|
/** Open the calendar on mount. */
|
|
@@ -79,7 +88,10 @@ export declare function fieldFlags(disabled: boolean | undefined, required: bool
|
|
|
79
88
|
};
|
|
80
89
|
/** What the segments show, as the day segment reports it to the field. */
|
|
81
90
|
export type Read = {
|
|
82
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* The date as `YYYY-MM-DD` (`YYYY-MM-DDTHH:mm` with a time) once every segment is filled and the
|
|
93
|
+
* day exists, else `""`.
|
|
94
|
+
*/
|
|
83
95
|
typed: string;
|
|
84
96
|
/** "February 1990 has 28 days." when the day does not exist. */
|
|
85
97
|
impossible: string | null;
|
|
@@ -103,22 +115,41 @@ export declare function forcedInvalid({ impossible, error, }: {
|
|
|
103
115
|
}): {
|
|
104
116
|
isInvalid?: true;
|
|
105
117
|
};
|
|
106
|
-
/**
|
|
107
|
-
export
|
|
118
|
+
/** A field's `minValue` and `maxValue`. */
|
|
119
|
+
export type Bounds = {
|
|
120
|
+
minValue?: DateValue | null | undefined;
|
|
121
|
+
maxValue?: DateValue | null | undefined;
|
|
122
|
+
};
|
|
123
|
+
/** The hint and, under it, the error line: the shared outside of every date field. */
|
|
124
|
+
export declare function Notes({ hint, error, impossible, bounds, time, }: {
|
|
108
125
|
hint: ReactNode;
|
|
109
126
|
error: ReactNode;
|
|
110
127
|
impossible: string | null;
|
|
111
|
-
|
|
128
|
+
bounds: Bounds;
|
|
129
|
+
time?: boolean;
|
|
112
130
|
}): ReactElement;
|
|
113
|
-
|
|
131
|
+
/** The padding table and its `md:` twin, for the data test. */
|
|
132
|
+
export declare const fieldSizeTables: {
|
|
133
|
+
pad: Record<Size, string>;
|
|
134
|
+
padMd: Record<Size, string>;
|
|
135
|
+
};
|
|
136
|
+
/** A date field's padding at `size`. */
|
|
137
|
+
export declare function fieldPad(size: Size | ResponsiveSize): string;
|
|
138
|
+
/** A date field's label look at the type step in force: a `Field`'s. */
|
|
139
|
+
export declare function useLabelClass(): string;
|
|
140
|
+
/** A date field's visible label, with the required mark. */
|
|
141
|
+
export declare function FieldLabel({ label, required, }: {
|
|
142
|
+
label: ReactNode;
|
|
143
|
+
required: boolean | undefined;
|
|
144
|
+
}): ReactElement | null;
|
|
114
145
|
/** A small icon button inside a date field or calendar, without its box size. */
|
|
115
146
|
export declare const iconButtonLook = "inline-flex shrink-0 items-center justify-center rounded-md text-slate-500 transition hover:bg-slate-100 disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
|
|
116
147
|
export declare const iconButtonClass = "inline-flex shrink-0 items-center justify-center rounded-md text-slate-500 transition hover:bg-slate-100 disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600 h-7 w-7";
|
|
117
148
|
/**
|
|
118
|
-
* A segmented
|
|
119
|
-
* `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
|
|
149
|
+
* A segmented date input, in the order of its `locale` (by default the browser's): DD / MM / YYYY
|
|
150
|
+
* in en-GB. Values are `CalendarDate`s; `name` posts it as `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
|
|
120
151
|
* same height as the plain field; `defaultOpen` opens it on mount. While `loading` the label is
|
|
121
152
|
* drawn and the field is a bone of its height.
|
|
122
153
|
*/
|
|
123
|
-
export declare function DateField({ calendar, defaultOpen, monthLabel, yearLabel, loading, loadingLabel, ...field }: DateFieldProps): ReactElement;
|
|
154
|
+
export declare function DateField({ calendar, defaultOpen, monthLabel, yearLabel, clearLabel, loading, loadingLabel, ...field }: DateFieldProps): ReactElement;
|
|
124
155
|
export {};
|
package/dist/DateField.js
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { CalendarDate as CalendarDateClass,
|
|
2
|
+
import { CalendarDate as CalendarDateClass, } from "@internationalized/date";
|
|
3
3
|
import { useContext, useEffect } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { DateFieldStateContext, DateSegment, FieldError, Label, Text, useLocale, } from "react-aria-components";
|
|
5
5
|
import { cx, focusRing } from "./cx.js";
|
|
6
6
|
import { CalendarDateField } from "./DateFieldCalendar.js";
|
|
7
7
|
import { toISODate } from "./isoDate.js";
|
|
8
|
-
import {
|
|
8
|
+
import { ErrorLine, RequiredMark } from "./Field.js";
|
|
9
9
|
import { WaitingField } from "./fieldWait.js";
|
|
10
10
|
import { useLoading } from "./skeleton.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({
|
|
17
|
-
month: i + 1,
|
|
18
|
-
name: MONTHS.format(new Date(Date.UTC(2000, i, 1))),
|
|
19
|
-
}));
|
|
11
|
+
import { useFieldType } from "./density.js";
|
|
12
|
+
import { DATE } from "./shownDate.js";
|
|
13
|
+
import { SegmentedField } from "./SegmentedField.js";
|
|
14
|
+
import { monthNames, shownIn } from "./dateLocale.js";
|
|
15
|
+
import { sizeClass } from "./size.js";
|
|
20
16
|
/** The react-aria flags for `disabled` and `required`, set only when true. */
|
|
21
17
|
export function fieldFlags(disabled, required) {
|
|
22
18
|
return { ...(disabled ? { isDisabled: true } : {}), ...(required ? { isRequired: true } : {}) };
|
|
23
19
|
}
|
|
24
|
-
|
|
20
|
+
const twoDigits = (n) => String(n).padStart(2, "0");
|
|
21
|
+
/** `THH:mm` on the 24-hour clock when the segments have a time, else `""`. */
|
|
22
|
+
function clockOf(editable) {
|
|
23
|
+
const hour = editable.find((segment) => segment.type === "hour");
|
|
24
|
+
if (!hour)
|
|
25
|
+
return "";
|
|
26
|
+
const period = editable.find((segment) => segment.type === "dayPeriod");
|
|
27
|
+
const minute = editable.find((segment) => segment.type === "minute")?.value ?? 0;
|
|
28
|
+
// A 12-hour clock shows 12 for midnight and noon; its day period says which half of the day.
|
|
29
|
+
const hours = period
|
|
30
|
+
? ((hour.value ?? 0) % 12) + (period.value === 1 ? 12 : 0)
|
|
31
|
+
: (hour.value ?? 0) % 24;
|
|
32
|
+
return `T${twoDigits(hours)}:${twoDigits(minute)}`;
|
|
33
|
+
}
|
|
34
|
+
function readSegments(segments, locale) {
|
|
25
35
|
const editable = segments.filter((segment) => segment.isEditable);
|
|
26
36
|
const blank = editable.filter((segment) => segment.isPlaceholder).length;
|
|
27
37
|
const none = { typed: "", impossible: null, partial: blank > 0 && blank < editable.length };
|
|
@@ -34,16 +44,17 @@ function readSegments(segments) {
|
|
|
34
44
|
const first = new CalendarDateClass(year, month, 1);
|
|
35
45
|
const days = first.calendar.getDaysInMonth(first);
|
|
36
46
|
if (day <= days)
|
|
37
|
-
return { ...none, typed: toISODate(first.set({ day })) };
|
|
47
|
+
return { ...none, typed: toISODate(first.set({ day })) + clockOf(editable) };
|
|
38
48
|
return {
|
|
39
49
|
...none,
|
|
40
|
-
impossible: `${
|
|
50
|
+
impossible: `${monthNames(locale)[month - 1] ?? ""} ${year} has ${days} days.`,
|
|
41
51
|
};
|
|
42
52
|
}
|
|
43
53
|
/** One segment. The day segment also reports what the segments show to the field. */
|
|
44
54
|
export function FieldSegment({ segment, onRead, }) {
|
|
45
55
|
const state = useContext(DateFieldStateContext);
|
|
46
|
-
const {
|
|
56
|
+
const { locale } = useLocale();
|
|
57
|
+
const { typed, impossible, partial } = readSegments(state?.segments ?? [], locale);
|
|
47
58
|
useEffect(() => onRead?.({ typed, impossible, partial }), [typed, impossible, partial, onRead]);
|
|
48
59
|
return (_jsx(DateSegment, { segment: segment, className: ({ isFocused, isPlaceholder, type }) => {
|
|
49
60
|
if (type === "literal")
|
|
@@ -68,9 +79,25 @@ export function frameClass({ isInvalid, isFocusWithin, isDisabled, }) {
|
|
|
68
79
|
export function forcedInvalid({ impossible, error, }) {
|
|
69
80
|
return impossible || error ? { isInvalid: true } : {};
|
|
70
81
|
}
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
/**
|
|
83
|
+
* React Aria's own message, with an out-of-range one written in the field's locale the way the field
|
|
84
|
+
* shows its dates: React Aria writes those dates in the browser's locale, whatever the field's.
|
|
85
|
+
*/
|
|
86
|
+
function builtIn({ validationErrors, validationDetails }, { minValue, maxValue }, locale, time) {
|
|
87
|
+
const what = time ? "date and time" : "date";
|
|
88
|
+
if (validationDetails.rangeUnderflow && minValue) {
|
|
89
|
+
return `The ${what} must be on or after ${shownIn(minValue, locale, time)}.`;
|
|
90
|
+
}
|
|
91
|
+
if (validationDetails.rangeOverflow && maxValue) {
|
|
92
|
+
return `The ${what} must be on or before ${shownIn(maxValue, locale, time)}.`;
|
|
93
|
+
}
|
|
94
|
+
return validationErrors.join(" ");
|
|
95
|
+
}
|
|
96
|
+
/** The hint and, under it, the error line: the shared outside of every date field. */
|
|
97
|
+
export function Notes({ hint, error, impossible, bounds, time = false, }) {
|
|
98
|
+
const { locale } = useLocale();
|
|
99
|
+
const { note } = useFieldType();
|
|
100
|
+
return (_jsxs(_Fragment, { children: [hint ? (_jsx(Text, { slot: "description", className: cx("text-slate-500", note), children: hint })) : null, _jsx(FieldError, { className: "block", children: (validation) => (_jsx(ErrorLine, { error: error || (impossible ?? builtIn(validation, bounds, locale, time)) })) })] }));
|
|
74
101
|
}
|
|
75
102
|
/** A `DateField`'s padding, by `size`: the heights of an `Input`. Its type is `controlText`'s, as an `Input`'s. */
|
|
76
103
|
const FIELD_SIZE = {
|
|
@@ -78,34 +105,43 @@ const FIELD_SIZE = {
|
|
|
78
105
|
md: "py-2 pl-2.5 pr-2.5",
|
|
79
106
|
lg: "py-2.5 pl-3 pr-3",
|
|
80
107
|
};
|
|
81
|
-
|
|
108
|
+
/** `FIELD_SIZE` from the `md` breakpoint up, for a responsive size. */
|
|
109
|
+
const FIELD_SIZE_MD = {
|
|
110
|
+
sm: "md:py-1 md:pl-2 md:pr-2",
|
|
111
|
+
md: "md:py-2 md:pl-2.5 md:pr-2.5",
|
|
112
|
+
lg: "md:py-2.5 md:pl-3 md:pr-3",
|
|
113
|
+
};
|
|
114
|
+
/** The padding table and its `md:` twin, for the data test. */
|
|
115
|
+
export const fieldSizeTables = { pad: FIELD_SIZE, padMd: FIELD_SIZE_MD };
|
|
116
|
+
/** A date field's padding at `size`. */
|
|
117
|
+
export function fieldPad(size) {
|
|
118
|
+
return sizeClass(FIELD_SIZE, FIELD_SIZE_MD, size);
|
|
119
|
+
}
|
|
120
|
+
/** A date field's label look at the type step in force: a `Field`'s. */
|
|
121
|
+
export function useLabelClass() {
|
|
122
|
+
return cx(useFieldType().label, "font-medium text-slate-700");
|
|
123
|
+
}
|
|
124
|
+
/** A date field's visible label, with the required mark. */
|
|
125
|
+
export function FieldLabel({ label, required, }) {
|
|
126
|
+
const look = useLabelClass();
|
|
127
|
+
return label ? (_jsxs(Label, { className: look, children: [label, _jsx(RequiredMark, { required: required })] })) : null;
|
|
128
|
+
}
|
|
82
129
|
/** A small icon button inside a date field or calendar, without its box size. */
|
|
83
130
|
export const iconButtonLook = `inline-flex shrink-0 items-center justify-center rounded-md text-slate-500 transition hover:bg-slate-100 disabled:opacity-50 ${focusRing}`;
|
|
84
131
|
export const iconButtonClass = `${iconButtonLook} h-7 w-7`;
|
|
85
132
|
/**
|
|
86
|
-
* A segmented
|
|
87
|
-
* `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
|
|
133
|
+
* A segmented date input, in the order of its `locale` (by default the browser's): DD / MM / YYYY
|
|
134
|
+
* in en-GB. Values are `CalendarDate`s; `name` posts it as `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
|
|
88
135
|
* same height as the plain field; `defaultOpen` opens it on mount. While `loading` the label is
|
|
89
136
|
* drawn and the field is a bone of its height.
|
|
90
137
|
*/
|
|
91
|
-
export function DateField({ calendar, defaultOpen, monthLabel = "Month", yearLabel = "Year", loading, loadingLabel, ...field }) {
|
|
138
|
+
export function DateField({ calendar, defaultOpen, monthLabel = "Month", yearLabel = "Year", clearLabel = "Clear", loading, loadingLabel, ...field }) {
|
|
139
|
+
const labelClass = useLabelClass();
|
|
92
140
|
if (useLoading(loading).loading) {
|
|
93
141
|
return (_jsx(WaitingField, { own: loading, loadingLabel: loadingLabel, label: field.label, look: labelClass, size: field.size, attrs: field }));
|
|
94
142
|
}
|
|
95
143
|
if (calendar) {
|
|
96
|
-
return (_jsx(CalendarDateField, { ...field, labels: { monthLabel, yearLabel }, ...(defaultOpen === undefined ? {} : { defaultOpen }) }));
|
|
144
|
+
return (_jsx(CalendarDateField, { ...field, labels: { monthLabel, yearLabel, clearLabel }, ...(defaultOpen === undefined ? {} : { defaultOpen }) }));
|
|
97
145
|
}
|
|
98
|
-
return _jsx(
|
|
99
|
-
}
|
|
100
|
-
function PlainDateField({ label, hint, error, disabled, required, value, defaultValue, onChange, name, size = "md", ...rest }) {
|
|
101
|
-
const step = useTypeStep();
|
|
102
|
-
const { inner, setInner, shown, impossible, onRead, validate, leaving, onBlurCapture, onLeft } = useShownDate({
|
|
103
|
-
value,
|
|
104
|
-
defaultValue,
|
|
105
|
-
onChange,
|
|
106
|
-
minValue: rest.minValue,
|
|
107
|
-
maxValue: rest.maxValue,
|
|
108
|
-
isRequired: required,
|
|
109
|
-
});
|
|
110
|
-
return (_jsx(I18nProvider, { locale: LOCALE, children: _jsx(AriaDateField, { ...definedProps(rest), ...fieldFlags(disabled, required), value: inner, onChange: setInner, validate: validate, ...forcedInvalid({ impossible, error }), isReadOnly: leaving, onBlur: onLeft, granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: ({ isInvalid }) => (_jsxs(_Fragment, { children: [label ? _jsx(Label, { className: labelClass, children: label }) : null, _jsx("div", { className: "contents", onBlurCapture: onBlurCapture, children: _jsx(DateInput, { className: (state) => cx(frameClass(state), FIELD_SIZE[size], controlText(size, step, true)), children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }), _jsx(ShownInput, { name: name, shown: shown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: impossible, isInvalid: isInvalid })] })) }) }));
|
|
146
|
+
return _jsx(SegmentedField, { ...field, kind: DATE });
|
|
111
147
|
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { type ReactElement } from "react";
|
|
2
2
|
import { type CalendarLabels } from "./DateCalendar.js";
|
|
3
3
|
import { type FieldProps } from "./DateField.js";
|
|
4
|
-
import type
|
|
5
|
-
/** The picker's
|
|
6
|
-
export declare const
|
|
7
|
-
frame: string
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import { type ResponsiveSize, type Size } from "./size.js";
|
|
5
|
+
/** The picker's tables and their `md:` twins (each `_MD` is its table from the `md` breakpoint up), for the data test. */
|
|
6
|
+
export declare const pickerSizeTables: {
|
|
7
|
+
frame: Record<Size, string>;
|
|
8
|
+
frameMd: Record<Size, string>;
|
|
9
|
+
button: Record<Size, string>;
|
|
10
|
+
buttonMd: Record<Size, string>;
|
|
11
|
+
};
|
|
12
|
+
/** The calendar button's box at `size`. */
|
|
13
|
+
export declare function pickerButton(size: Size | ResponsiveSize): string;
|
|
10
14
|
/** The picker's frame at `size`: its gap and padding, and the type of a control at the type step in force. */
|
|
11
|
-
export declare function usePickerFrame(size: Size): string;
|
|
15
|
+
export declare function usePickerFrame(size: Size | ResponsiveSize): string;
|
|
12
16
|
/**
|
|
13
17
|
* The modal `<dialog>` a picker sits in, if any, for its popover's `container`: pass `findDialog` as the
|
|
14
18
|
* picker's `ref`.
|
|
@@ -18,7 +22,7 @@ export declare function useDialogContainer(): {
|
|
|
18
22
|
findDialog: (el: HTMLDivElement | null) => void;
|
|
19
23
|
};
|
|
20
24
|
/** The body of `<DateField calendar>`: the field with a calendar button that opens a month view in a popover. */
|
|
21
|
-
export declare function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, size, ...rest }: FieldProps & {
|
|
25
|
+
export declare function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, locale, size, ...rest }: FieldProps & {
|
|
22
26
|
defaultOpen?: boolean;
|
|
23
27
|
labels: CalendarLabels;
|
|
24
28
|
}): ReactElement;
|
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useContext, useState } from "react";
|
|
3
|
-
import { Button, DatePicker as AriaDatePicker, DateFieldContext, DateInput, Group,
|
|
3
|
+
import { Button, DatePicker as AriaDatePicker, DateFieldContext, DateInput, Group, } from "react-aria-components";
|
|
4
4
|
import { cx } from "./cx.js";
|
|
5
5
|
import { CalendarPopover, calendarIcon } from "./DateCalendar.js";
|
|
6
|
-
import { FieldSegment,
|
|
6
|
+
import { FieldSegment, FieldLabel, fieldFlags, forcedInvalid, Notes, frameClass, iconButtonLook, } from "./DateField.js";
|
|
7
|
+
import { DateLocale } from "./dateLocale.js";
|
|
7
8
|
import { definedProps } from "./props.js";
|
|
8
|
-
import { ShownInput, useShownDate } from "./shownDate.js";
|
|
9
|
+
import { DATE, ShownInput, useShownDate } from "./shownDate.js";
|
|
10
|
+
import { sizeClass } from "./size.js";
|
|
9
11
|
import { controlText, useTypeStep } from "./density.js";
|
|
10
12
|
/** The picker's padding and calendar button, by `size` (its type is `controlText`'s). The button sets the height, so the padding is less than a `DateField`'s. */
|
|
11
|
-
|
|
12
|
-
sm:
|
|
13
|
-
md:
|
|
14
|
-
lg:
|
|
13
|
+
const PICKER_FRAME = {
|
|
14
|
+
sm: "py-0.5 pl-2 pr-0.5",
|
|
15
|
+
md: "py-1 pl-2.5 pr-1",
|
|
16
|
+
lg: "py-1.5 pl-3 pr-1.5",
|
|
15
17
|
};
|
|
18
|
+
const PICKER_FRAME_MD = {
|
|
19
|
+
sm: "md:py-0.5 md:pl-2 md:pr-0.5",
|
|
20
|
+
md: "md:py-1 md:pl-2.5 md:pr-1",
|
|
21
|
+
lg: "md:py-1.5 md:pl-3 md:pr-1.5",
|
|
22
|
+
};
|
|
23
|
+
const PICKER_BUTTON = { sm: "h-5 w-5", md: "h-7 w-7", lg: "h-8 w-8" };
|
|
24
|
+
const PICKER_BUTTON_MD = {
|
|
25
|
+
sm: "md:h-5 md:w-5",
|
|
26
|
+
md: "md:h-7 md:w-7",
|
|
27
|
+
lg: "md:h-8 md:w-8",
|
|
28
|
+
};
|
|
29
|
+
/** The picker's tables and their `md:` twins (each `_MD` is its table from the `md` breakpoint up), for the data test. */
|
|
30
|
+
export const pickerSizeTables = {
|
|
31
|
+
frame: PICKER_FRAME,
|
|
32
|
+
frameMd: PICKER_FRAME_MD,
|
|
33
|
+
button: PICKER_BUTTON,
|
|
34
|
+
buttonMd: PICKER_BUTTON_MD,
|
|
35
|
+
};
|
|
36
|
+
/** The calendar button's box at `size`. */
|
|
37
|
+
export function pickerButton(size) {
|
|
38
|
+
return sizeClass(PICKER_BUTTON, PICKER_BUTTON_MD, size);
|
|
39
|
+
}
|
|
16
40
|
/** The picker's frame at `size`: its gap and padding, and the type of a control at the type step in force. */
|
|
17
41
|
export function usePickerFrame(size) {
|
|
18
|
-
|
|
42
|
+
const pad = sizeClass(PICKER_FRAME, PICKER_FRAME_MD, size);
|
|
43
|
+
return cx("gap-1", pad, controlText(size, useTypeStep(), true));
|
|
19
44
|
}
|
|
20
45
|
/**
|
|
21
46
|
* The picker's input, read-only while `leaving`. Only the field: a read-only picker would also
|
|
@@ -35,16 +60,10 @@ export function useDialogContainer() {
|
|
|
35
60
|
return { container, findDialog };
|
|
36
61
|
}
|
|
37
62
|
/** The body of `<DateField calendar>`: the field with a calendar button that opens a month view in a popover. */
|
|
38
|
-
export function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, size = "md", ...rest }) {
|
|
63
|
+
export function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, locale, size = "md", ...rest }) {
|
|
39
64
|
const frame = usePickerFrame(size);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
defaultValue,
|
|
43
|
-
onChange,
|
|
44
|
-
minValue: rest.minValue,
|
|
45
|
-
maxValue: rest.maxValue,
|
|
46
|
-
isRequired: required,
|
|
47
|
-
});
|
|
65
|
+
const bounds = { minValue: rest.minValue, maxValue: rest.maxValue };
|
|
66
|
+
const { inner, setInner, shown, impossible, onRead, validate, leaving, onBlurCapture, onLeft } = useShownDate({ value, defaultValue, onChange, ...bounds, isRequired: required }, DATE);
|
|
48
67
|
const { container, findDialog } = useDialogContainer();
|
|
49
|
-
return (_jsx(
|
|
68
|
+
return (_jsx(DateLocale, { locale: locale, children: _jsx(AriaDatePicker, { ...definedProps(rest), ...fieldFlags(disabled, required), ref: findDialog, value: inner, onChange: setInner, validate: validate, ...forcedInvalid({ impossible, error }), granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: () => (_jsxs(_Fragment, { children: [_jsx(FieldLabel, { label: label, required: required }), _jsxs(Group, { className: (state) => cx(frameClass(state), frame), children: [_jsx("div", { className: "contents", onBlurCapture: onBlurCapture, children: _jsx(PickerInput, { leaving: leaving, onLeft: onLeft, children: _jsx(DateInput, { className: "flex flex-1", children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }) }), _jsx(Button, { className: cx(iconButtonLook, pickerButton(size)), children: calendarIcon })] }), _jsx(ShownInput, { name: name, shown: shown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: impossible, bounds: bounds }), _jsx(CalendarPopover, { container: container, labels: labels })] })) }) }));
|
|
50
69
|
}
|
|
@@ -9,7 +9,7 @@ export type DateRangePreset = {
|
|
|
9
9
|
label: string;
|
|
10
10
|
value: DateRange;
|
|
11
11
|
};
|
|
12
|
-
export type DateRangePickerProps = Pick<FieldProps, "label" | "hint" | "error" | "size" | "minValue" | "maxValue" | "required" | "disabled"> & Passthrough & {
|
|
12
|
+
export type DateRangePickerProps = Pick<FieldProps, "label" | "hint" | "error" | "size" | "minValue" | "maxValue" | "required" | "disabled" | "locale"> & Passthrough & {
|
|
13
13
|
/** The range, or `null` for none. Reported only when both days are complete, real and in order. */
|
|
14
14
|
value?: DateRange | null | undefined;
|
|
15
15
|
/** The range shown first when the picker holds its own value. */
|
|
@@ -37,11 +37,31 @@ export type DateRangePickerProps = Pick<FieldProps, "label" | "hint" | "error" |
|
|
|
37
37
|
* @default Year
|
|
38
38
|
*/
|
|
39
39
|
yearLabel?: string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The name of the start date's segments, for a screen reader.
|
|
42
|
+
* @default Start date
|
|
43
|
+
*/
|
|
44
|
+
startLabel?: string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The name of the end date's segments, for a screen reader.
|
|
47
|
+
* @default End date
|
|
48
|
+
*/
|
|
49
|
+
endLabel?: string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* The word between the two dates.
|
|
52
|
+
* @default to
|
|
53
|
+
*/
|
|
54
|
+
toLabel?: string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* The calendar's footer button that empties the range.
|
|
57
|
+
* @default Clear
|
|
58
|
+
*/
|
|
59
|
+
clearLabel?: string | undefined;
|
|
40
60
|
};
|
|
41
61
|
/**
|
|
42
|
-
* A from and to date in one field
|
|
62
|
+
* A from and to date in one field, each side in the locale's order, and a calendar button that opens one
|
|
43
63
|
* Monday-first month, where two presses pick the range. `presets` adds the app's ready-made ranges
|
|
44
64
|
* above the month. The range is reported only when both sides are complete, real dates within
|
|
45
65
|
* min/max and the start is on or before the end; otherwise `null`.
|
|
46
66
|
*/
|
|
47
|
-
export declare function DateRangePicker({ label, hint, error, disabled, required, monthLabel, yearLabel, value, defaultValue, onChange, startName, endName, presets, defaultOpen, size, ...rest }: DateRangePickerProps): ReactElement;
|
|
67
|
+
export declare function DateRangePicker({ label, hint, error, disabled, required, monthLabel, yearLabel, startLabel, endLabel, toLabel, clearLabel, value, defaultValue, onChange, startName, endName, presets, defaultOpen, locale, size, ...rest }: DateRangePickerProps): ReactElement;
|
package/dist/DateRangePicker.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import { Button, DateFieldContext, DateInput, DateRangePicker as AriaDateRangePicker, Group,
|
|
3
|
+
import { Button, DateFieldContext, DateInput, DateRangePicker as AriaDateRangePicker, Group, } from "react-aria-components";
|
|
4
4
|
import { cx } from "./cx.js";
|
|
5
5
|
import { RangeCalendarPopover, calendarIcon } from "./DateCalendar.js";
|
|
6
|
-
import { FieldSegment,
|
|
7
|
-
import {
|
|
6
|
+
import { FieldSegment, FieldLabel, fieldFlags, forcedInvalid, frameClass, iconButtonLook, Notes, } from "./DateField.js";
|
|
7
|
+
import { DateLocale } from "./dateLocale.js";
|
|
8
|
+
import { pickerButton, useDialogContainer, usePickerFrame } from "./DateFieldCalendar.js";
|
|
8
9
|
import { definedProps } from "./props.js";
|
|
9
10
|
import { ShownInput, useShownRange } from "./shownDate.js";
|
|
10
11
|
/**
|
|
@@ -24,21 +25,22 @@ function SideInput({ slot, name, side, onRead, }) {
|
|
|
24
25
|
}, children: _jsx(DateInput, { slot: slot, className: "flex", children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }) }));
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
|
-
* A from and to date in one field
|
|
28
|
+
* A from and to date in one field, each side in the locale's order, and a calendar button that opens one
|
|
28
29
|
* Monday-first month, where two presses pick the range. `presets` adds the app's ready-made ranges
|
|
29
30
|
* above the month. The range is reported only when both sides are complete, real dates within
|
|
30
31
|
* min/max and the start is on or before the end; otherwise `null`.
|
|
31
32
|
*/
|
|
32
|
-
export function DateRangePicker({ label, hint, error, disabled, required, monthLabel = "Month", yearLabel = "Year", value, defaultValue, onChange, startName, endName, presets, defaultOpen, size = "md", ...rest }) {
|
|
33
|
+
export function DateRangePicker({ label, hint, error, disabled, required, monthLabel = "Month", yearLabel = "Year", startLabel = "Start date", endLabel = "End date", toLabel = "to", clearLabel = "Clear", value, defaultValue, onChange, startName, endName, presets, defaultOpen, locale, size = "md", ...rest }) {
|
|
33
34
|
const frame = usePickerFrame(size);
|
|
35
|
+
// `rest` carries the bounds, as `Notes` reads them.
|
|
34
36
|
const shown = useShownRange({
|
|
37
|
+
...rest,
|
|
35
38
|
value,
|
|
36
39
|
defaultValue,
|
|
37
40
|
onChange,
|
|
38
|
-
minValue: rest.minValue,
|
|
39
|
-
maxValue: rest.maxValue,
|
|
40
41
|
isRequired: required,
|
|
42
|
+
labels: [startLabel, endLabel],
|
|
41
43
|
});
|
|
42
44
|
const { container, findDialog } = useDialogContainer();
|
|
43
|
-
return (_jsx(
|
|
45
|
+
return (_jsx(DateLocale, { locale: locale, children: _jsx(AriaDateRangePicker, { ...definedProps(rest), ...fieldFlags(disabled, required), ...(defaultOpen === undefined ? {} : { defaultOpen }), ref: findDialog, value: shown.inner, onChange: shown.setInner, validate: shown.validate, ...forcedInvalid({ impossible: shown.problem, error }), granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: () => (_jsxs(_Fragment, { children: [_jsx(FieldLabel, { label: label, required: required }), _jsxs(Group, { className: (state) => cx(frameClass(state), frame), children: [_jsx(SideInput, { slot: "start", name: startLabel, side: shown.start, onRead: shown.onReadStart }), _jsx("span", { "aria-hidden": "true", className: "px-1 text-slate-500", children: toLabel }), _jsx(SideInput, { slot: "end", name: endLabel, side: shown.end, onRead: shown.onReadEnd }), _jsx(Button, { className: cx(iconButtonLook, pickerButton(size), "ml-auto"), children: calendarIcon })] }), _jsx(ShownInput, { name: startName, shown: shown.startShown, isDisabled: disabled }), _jsx(ShownInput, { name: endName, shown: shown.endShown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: shown.problem, bounds: rest }), _jsx(RangeCalendarPopover, { container: container, presets: presets, labels: { monthLabel, yearLabel, clearLabel } })] })) }) }));
|
|
44
46
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CalendarDateTime, DateValue } from "@internationalized/date";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
|
+
import { type FieldProps } from "./DateField.js";
|
|
4
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
5
|
+
export type DateTimeFieldProps = Omit<FieldProps, "value" | "defaultValue" | "onChange" | "minValue" | "maxValue" | "name"> & LoadingProps & {
|
|
6
|
+
/** The date and time shown, controlled, with `onChange`; `null` is an empty field. */
|
|
7
|
+
value?: CalendarDateTime | null | undefined;
|
|
8
|
+
/** The date and time shown first when the field holds its own value. */
|
|
9
|
+
defaultValue?: CalendarDateTime | null | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Called with the date and time once every segment is filled, the day exists and it is within
|
|
12
|
+
* `minValue`/`maxValue`, and with `null` when it stops being one.
|
|
13
|
+
*/
|
|
14
|
+
onChange?: ((value: CalendarDateTime | null) => void) | undefined;
|
|
15
|
+
/** The earliest date and time the field takes; earlier ones are invalid. */
|
|
16
|
+
minValue?: DateValue | null | undefined;
|
|
17
|
+
/** The latest date and time the field takes; later ones are invalid. */
|
|
18
|
+
maxValue?: DateValue | null | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Posts the date and time in a form as `YYYY-MM-DDTHH:mm` (24-hour) under this key, or an empty
|
|
21
|
+
* string, whatever the `locale`.
|
|
22
|
+
*/
|
|
23
|
+
name?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A segmented date and time input, to the minute: the date in the order of its `locale` (by default
|
|
27
|
+
* the browser's), then hours and minutes on the clock the locale uses, 24-hour in en-GB and with
|
|
28
|
+
* AM/PM in en-US. Values are `CalendarDateTime`s; `name` posts it as `YYYY-MM-DDTHH:mm`. It has no
|
|
29
|
+
* calendar. While `loading` the label is drawn and the field is a bone of its height.
|
|
30
|
+
*/
|
|
31
|
+
export declare function DateTimeField({ loading, loadingLabel, ...field }: DateTimeFieldProps): ReactElement;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useLabelClass } from "./DateField.js";
|
|
3
|
+
import { SegmentedField } from "./SegmentedField.js";
|
|
4
|
+
import { WaitingField } from "./fieldWait.js";
|
|
5
|
+
import { DATE_TIME } from "./shownDate.js";
|
|
6
|
+
import { useLoading } from "./skeleton.js";
|
|
7
|
+
/**
|
|
8
|
+
* A segmented date and time input, to the minute: the date in the order of its `locale` (by default
|
|
9
|
+
* the browser's), then hours and minutes on the clock the locale uses, 24-hour in en-GB and with
|
|
10
|
+
* AM/PM in en-US. Values are `CalendarDateTime`s; `name` posts it as `YYYY-MM-DDTHH:mm`. It has no
|
|
11
|
+
* calendar. While `loading` the label is drawn and the field is a bone of its height.
|
|
12
|
+
*/
|
|
13
|
+
export function DateTimeField({ loading, loadingLabel, ...field }) {
|
|
14
|
+
const labelClass = useLabelClass();
|
|
15
|
+
if (useLoading(loading).loading) {
|
|
16
|
+
return (_jsx(WaitingField, { own: loading, loadingLabel: loadingLabel, label: field.label, look: labelClass, size: field.size, attrs: field }));
|
|
17
|
+
}
|
|
18
|
+
return _jsx(SegmentedField, { ...field, kind: DATE_TIME });
|
|
19
|
+
}
|