@ratio-ui/core 0.1.1 → 0.3.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/README.md +2 -0
- package/dist/catalogue.json +2829 -72
- package/dist/components/alert/Alert.d.ts +18 -0
- package/dist/components/alert/Alert.js +67 -0
- package/dist/components/alert/index.d.ts +2 -0
- package/dist/components/alert/index.js +1 -0
- package/dist/components/alert-dialog/AlertDialog.d.ts +48 -0
- package/dist/components/alert-dialog/AlertDialog.js +76 -0
- package/dist/components/alert-dialog/index.d.ts +2 -0
- package/dist/components/alert-dialog/index.js +1 -0
- package/dist/components/app-shell/AppShell.d.ts +22 -0
- package/dist/components/app-shell/AppShell.js +39 -0
- package/dist/components/app-shell/context.js +5 -0
- package/dist/components/app-shell/index.d.ts +2 -0
- package/dist/components/app-shell/index.js +1 -0
- package/dist/components/avatar/Avatar.d.ts +22 -0
- package/dist/components/avatar/Avatar.js +38 -0
- package/dist/components/avatar/index.d.ts +2 -0
- package/dist/components/avatar/index.js +1 -0
- package/dist/components/button/Button.d.ts +37 -0
- package/dist/components/button/Button.js +41 -0
- package/dist/components/button/index.d.ts +2 -0
- package/dist/components/button/index.js +1 -0
- package/dist/components/calendar/Calendar.d.ts +20 -0
- package/dist/components/calendar/Calendar.js +119 -0
- package/dist/components/calendar/index.d.ts +2 -0
- package/dist/components/calendar/index.js +1 -0
- package/dist/components/card/Card.d.ts +33 -0
- package/dist/components/card/Card.js +53 -0
- package/dist/components/card/index.d.ts +2 -0
- package/dist/components/card/index.js +1 -0
- package/dist/components/checkbox/Checkbox.d.ts +10 -0
- package/dist/components/checkbox/Checkbox.js +28 -0
- package/dist/components/checkbox/index.d.ts +2 -0
- package/dist/components/checkbox/index.js +1 -0
- package/dist/components/checkbox-list/CheckboxList.d.ts +36 -0
- package/dist/components/checkbox-list/CheckboxList.js +93 -0
- package/dist/components/checkbox-list/index.d.ts +2 -0
- package/dist/components/checkbox-list/index.js +1 -0
- package/dist/components/collapsible/Collapsible.d.ts +24 -0
- package/dist/components/collapsible/Collapsible.js +58 -0
- package/dist/components/collapsible/index.d.ts +2 -0
- package/dist/components/collapsible/index.js +1 -0
- package/dist/components/data-table/DataTable.d.ts +65 -0
- package/dist/components/data-table/DataTable.js +141 -0
- package/dist/components/data-table/index.d.ts +2 -0
- package/dist/components/data-table/index.js +1 -0
- package/dist/components/date-picker/DatePicker.d.ts +33 -0
- package/dist/components/date-picker/DatePicker.js +104 -0
- package/dist/components/date-picker/index.d.ts +2 -0
- package/dist/components/date-picker/index.js +1 -0
- package/dist/components/date-range-picker/DateRangePicker.d.ts +39 -0
- package/dist/components/date-range-picker/DateRangePicker.js +142 -0
- package/dist/components/date-range-picker/index.d.ts +2 -0
- package/dist/components/date-range-picker/index.js +1 -0
- package/dist/components/definition/Definition.d.ts +14 -0
- package/dist/components/definition/Definition.js +29 -0
- package/dist/components/definition/index.d.ts +2 -0
- package/dist/components/definition/index.js +1 -0
- package/dist/components/dialog/Dialog.d.ts +44 -0
- package/dist/components/dialog/Dialog.js +79 -0
- package/dist/components/dialog/index.d.ts +2 -0
- package/dist/components/dialog/index.js +1 -0
- package/dist/components/dropdown-menu/DropdownMenu.d.ts +73 -0
- package/dist/components/dropdown-menu/DropdownMenu.js +116 -0
- package/dist/components/dropdown-menu/index.d.ts +2 -0
- package/dist/components/dropdown-menu/index.js +1 -0
- package/dist/components/empty-state/EmptyState.d.ts +15 -0
- package/dist/components/empty-state/EmptyState.js +30 -0
- package/dist/components/empty-state/index.d.ts +2 -0
- package/dist/components/empty-state/index.js +1 -0
- package/dist/components/field/Field.d.ts +35 -0
- package/dist/components/field/Field.js +67 -0
- package/dist/components/field/Label.d.ts +8 -0
- package/dist/components/field/Label.js +13 -0
- package/dist/components/field/index.d.ts +3 -0
- package/dist/components/field/index.js +3 -0
- package/dist/components/filter-tabs/FilterTabs.d.ts +28 -0
- package/dist/components/filter-tabs/FilterTabs.js +37 -0
- package/dist/components/filter-tabs/index.d.ts +2 -0
- package/dist/components/filter-tabs/index.js +1 -0
- package/dist/components/global-search/GlobalSearch.d.ts +51 -0
- package/dist/components/global-search/GlobalSearch.js +144 -0
- package/dist/components/global-search/index.d.ts +2 -0
- package/dist/components/global-search/index.js +1 -0
- package/dist/components/icon/registry.d.ts +3 -2
- package/dist/components/icon/registry.js +57 -1
- package/dist/components/input/Input.d.ts +19 -0
- package/dist/components/input/Input.js +26 -0
- package/dist/components/input/index.d.ts +2 -0
- package/dist/components/input/index.js +1 -0
- package/dist/components/input-group/InputGroup.d.ts +42 -0
- package/dist/components/input-group/InputGroup.js +83 -0
- package/dist/components/input-group/index.d.ts +2 -0
- package/dist/components/input-group/index.js +1 -0
- package/dist/components/kbd/Kbd.d.ts +17 -0
- package/dist/components/kbd/Kbd.js +21 -0
- package/dist/components/kbd/index.d.ts +2 -0
- package/dist/components/kbd/index.js +1 -0
- package/dist/components/link/Link.d.ts +22 -0
- package/dist/components/link/Link.js +31 -0
- package/dist/components/link/index.d.ts +2 -0
- package/dist/components/link/index.js +1 -0
- package/dist/components/link-provider/LinkProvider.d.ts +29 -0
- package/dist/components/link-provider/LinkProvider.js +15 -0
- package/dist/components/link-provider/RatioLink.js +18 -0
- package/dist/components/link-provider/context.js +4 -0
- package/dist/components/link-provider/index.d.ts +2 -0
- package/dist/components/link-provider/index.js +1 -0
- package/dist/components/media-grid/MediaGrid.d.ts +49 -0
- package/dist/components/media-grid/MediaGrid.js +303 -0
- package/dist/components/media-grid/index.d.ts +2 -0
- package/dist/components/media-grid/index.js +1 -0
- package/dist/components/metric-strip/MetricStrip.d.ts +23 -0
- package/dist/components/metric-strip/MetricStrip.js +39 -0
- package/dist/components/metric-strip/index.d.ts +2 -0
- package/dist/components/metric-strip/index.js +1 -0
- package/dist/components/money-input/MoneyInput.d.ts +30 -0
- package/dist/components/money-input/MoneyInput.js +72 -0
- package/dist/components/money-input/index.d.ts +2 -0
- package/dist/components/money-input/index.js +1 -0
- package/dist/components/page-header/PageHeader.d.ts +37 -0
- package/dist/components/page-header/PageHeader.js +62 -0
- package/dist/components/page-header/index.d.ts +2 -0
- package/dist/components/page-header/index.js +1 -0
- package/dist/components/pagination/Pagination.d.ts +18 -0
- package/dist/components/pagination/Pagination.js +59 -0
- package/dist/components/pagination/index.d.ts +2 -0
- package/dist/components/pagination/index.js +1 -0
- package/dist/components/popover/Popover.d.ts +27 -0
- package/dist/components/popover/Popover.js +47 -0
- package/dist/components/popover/index.d.ts +2 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/save-bar/SaveBar.d.ts +27 -0
- package/dist/components/save-bar/SaveBar.js +37 -0
- package/dist/components/save-bar/index.d.ts +2 -0
- package/dist/components/save-bar/index.js +1 -0
- package/dist/components/search-field/SearchField.d.ts +23 -0
- package/dist/components/search-field/SearchField.js +66 -0
- package/dist/components/search-field/index.d.ts +2 -0
- package/dist/components/search-field/index.js +1 -0
- package/dist/components/select/Select.d.ts +40 -0
- package/dist/components/select/Select.js +84 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/index.js +1 -0
- package/dist/components/side-nav/SideNav.d.ts +64 -0
- package/dist/components/side-nav/SideNav.js +194 -0
- package/dist/components/side-nav/index.d.ts +2 -0
- package/dist/components/side-nav/index.js +1 -0
- package/dist/components/skeleton/Skeleton.d.ts +13 -0
- package/dist/components/skeleton/Skeleton.js +21 -0
- package/dist/components/skeleton/index.d.ts +2 -0
- package/dist/components/skeleton/index.js +1 -0
- package/dist/components/spinner/Spinner.d.ts +11 -0
- package/dist/components/spinner/Spinner.js +16 -0
- package/dist/components/spinner/index.d.ts +2 -0
- package/dist/components/spinner/index.js +1 -0
- package/dist/components/status-pill/StatusPill.d.ts +14 -0
- package/dist/components/status-pill/StatusPill.js +19 -0
- package/dist/components/status-pill/index.d.ts +2 -0
- package/dist/components/status-pill/index.js +1 -0
- package/dist/components/summary-chips/SummaryChips.d.ts +17 -0
- package/dist/components/summary-chips/SummaryChips.js +19 -0
- package/dist/components/summary-chips/index.d.ts +2 -0
- package/dist/components/summary-chips/index.js +1 -0
- package/dist/components/switch/Switch.d.ts +10 -0
- package/dist/components/switch/Switch.js +20 -0
- package/dist/components/switch/index.d.ts +2 -0
- package/dist/components/switch/index.js +1 -0
- package/dist/components/table/Table.d.ts +46 -0
- package/dist/components/table/Table.js +87 -0
- package/dist/components/table/index.d.ts +2 -0
- package/dist/components/table/index.js +1 -0
- package/dist/components/table-loader/TableLoader.d.ts +31 -0
- package/dist/components/table-loader/TableLoader.js +35 -0
- package/dist/components/table-loader/index.d.ts +2 -0
- package/dist/components/table-loader/index.js +1 -0
- package/dist/components/tabs/Tabs.d.ts +23 -0
- package/dist/components/tabs/Tabs.js +41 -0
- package/dist/components/tabs/index.d.ts +2 -0
- package/dist/components/tabs/index.js +1 -0
- package/dist/components/tag-input/TagInput.d.ts +44 -0
- package/dist/components/tag-input/TagInput.js +102 -0
- package/dist/components/tag-input/index.d.ts +2 -0
- package/dist/components/tag-input/index.js +1 -0
- package/dist/components/textarea/Textarea.d.ts +15 -0
- package/dist/components/textarea/Textarea.js +21 -0
- package/dist/components/textarea/index.d.ts +2 -0
- package/dist/components/textarea/index.js +1 -0
- package/dist/components/toaster/Toaster.d.ts +32 -0
- package/dist/components/toaster/Toaster.js +89 -0
- package/dist/components/toaster/index.d.ts +2 -0
- package/dist/components/toaster/index.js +1 -0
- package/dist/components/tooltip/Tooltip.d.ts +18 -0
- package/dist/components/tooltip/Tooltip.js +35 -0
- package/dist/components/tooltip/index.d.ts +2 -0
- package/dist/components/tooltip/index.js +1 -0
- package/dist/components/top-bar/StoreSwitcher.d.ts +26 -0
- package/dist/components/top-bar/StoreSwitcher.js +48 -0
- package/dist/components/top-bar/TopBar.d.ts +24 -0
- package/dist/components/top-bar/TopBar.js +53 -0
- package/dist/components/top-bar/index.d.ts +3 -0
- package/dist/components/top-bar/index.js +3 -0
- package/dist/components/unit-input/UnitInput.d.ts +33 -0
- package/dist/components/unit-input/UnitInput.js +47 -0
- package/dist/components/unit-input/index.d.ts +2 -0
- package/dist/components/unit-input/index.js +1 -0
- package/dist/index.d.ts +102 -1
- package/dist/index.js +54 -2
- package/dist/lib/cn.js +38 -27
- package/dist/lib/format.d.ts +92 -0
- package/dist/lib/format.js +222 -0
- package/dist/styles.css +1 -1
- package/package.json +205 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
// src/components/card/Card.tsx
|
|
3
|
+
/**
|
|
4
|
+
* A container for a panel of content: a 1px hairline border on white, no shadow and 24px of padding. The design system
|
|
5
|
+
* has no cards, so this is only the hairline container.
|
|
6
|
+
*/
|
|
7
|
+
function Card(props) {
|
|
8
|
+
return /* @__PURE__ */ jsx("div", {
|
|
9
|
+
"data-slot": "card",
|
|
10
|
+
...props,
|
|
11
|
+
className: "rt:flex rt:flex-col rt:gap-6 rt:rounded-lg rt:border rt:border-border rt:bg-background rt:p-6"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/** The top of a card: its title and description, stacked. */
|
|
15
|
+
function CardHeader(props) {
|
|
16
|
+
return /* @__PURE__ */ jsx("div", {
|
|
17
|
+
"data-slot": "card-header",
|
|
18
|
+
...props,
|
|
19
|
+
className: "rt:flex rt:flex-col rt:gap-1"
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** The title of a card, set in the B4 text style. */
|
|
23
|
+
function CardTitle({ as: Tag = "h3", ...rest }) {
|
|
24
|
+
return /* @__PURE__ */ jsx(Tag, {
|
|
25
|
+
"data-slot": "card-title",
|
|
26
|
+
...rest,
|
|
27
|
+
className: "rt:text-b4 rt:text-foreground"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** A line under the title that says what the card holds. */
|
|
31
|
+
function CardDescription(props) {
|
|
32
|
+
return /* @__PURE__ */ jsx("p", {
|
|
33
|
+
"data-slot": "card-description",
|
|
34
|
+
...props,
|
|
35
|
+
className: "rt:text-b3 rt:text-foreground-subdued"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** The body of a card. */
|
|
39
|
+
function CardContent(props) {
|
|
40
|
+
return /* @__PURE__ */ jsx("div", {
|
|
41
|
+
"data-slot": "card-content",
|
|
42
|
+
...props
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** The foot of a card, a row for its actions. */
|
|
46
|
+
function CardFooter(props) {
|
|
47
|
+
return /* @__PURE__ */ jsx("div", {
|
|
48
|
+
"data-slot": "card-footer",
|
|
49
|
+
...props,
|
|
50
|
+
className: "rt:flex rt:items-center rt:gap-2"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Card, CardContent, CardContentProps, CardDescription, CardDescriptionProps, CardFooter, CardFooterProps, CardHeader, CardHeaderProps, CardProps, CardTitle, CardTitleProps } from "./Card.js";
|
|
2
|
+
export { Card, CardContent, type CardContentProps, CardDescription, type CardDescriptionProps, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, type CardTitleProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "./Card.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JSX } from "react";
|
|
2
|
+
import { Checkbox } from "@base-ui/react/checkbox";
|
|
3
|
+
/** The props of Checkbox: Base UI's checkbox props, except className, style and render. Give it an aria-label or a label that points to it. */
|
|
4
|
+
export type CheckboxProps = Omit<Checkbox.Root.Props, 'className' | 'style' | 'render'>;
|
|
5
|
+
/**
|
|
6
|
+
* A 14px box with a 4px radius, drawn with a hairline ring and filled in the primary colour when checked. Set
|
|
7
|
+
* indeterminate for a select-all that stands for some rows. An invisible 24px area around the box takes the tap.
|
|
8
|
+
*/
|
|
9
|
+
declare function Checkbox$1({ ...props }: CheckboxProps): JSX.Element;
|
|
10
|
+
export { Checkbox$1 as Checkbox };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cn } from "../../lib/cn.js";
|
|
2
|
+
import { Icon } from "../icon/Icon.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { Checkbox } from "@base-ui/react/checkbox";
|
|
5
|
+
// src/components/checkbox/Checkbox.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A 14px box with a 4px radius, drawn with a hairline ring and filled in the primary colour when checked. Set
|
|
8
|
+
* indeterminate for a select-all that stands for some rows. An invisible 24px area around the box takes the tap.
|
|
9
|
+
*/
|
|
10
|
+
function Checkbox$1({ ...props }) {
|
|
11
|
+
return /* @__PURE__ */ jsx(Checkbox.Root, {
|
|
12
|
+
"data-slot": "checkbox",
|
|
13
|
+
className: cn("rt:peer rt:relative rt:flex rt:size-3.5 rt:shrink-0 rt:cursor-pointer rt:items-center rt:justify-center rt:rounded-sm rt:bg-background rt:shadow-ring-hairline rt:transition-colors rt:outline-none", "rt:after:absolute rt:after:-inset-1.25", "rt:hover:bg-primary-tint rt:data-checked:bg-primary rt:data-checked:shadow-none rt:data-checked:hover:bg-primary-hover", "rt:data-indeterminate:bg-primary rt:data-indeterminate:shadow-none rt:data-indeterminate:hover:bg-primary-hover", "rt:focus-visible:focus-ring rt:forced-outline", "rt:aria-invalid:shadow-ring-invalid rt:aria-invalid:data-checked:shadow-ring-invalid rt:aria-invalid:data-indeterminate:shadow-ring-invalid", "rt:data-disabled:cursor-not-allowed rt:data-disabled:opacity-50", "rt:disabled:cursor-not-allowed rt:disabled:opacity-50"),
|
|
14
|
+
...props,
|
|
15
|
+
children: /* @__PURE__ */ jsx(Checkbox.Indicator, {
|
|
16
|
+
"data-slot": "checkbox-indicator",
|
|
17
|
+
className: "rt:flex rt:items-center rt:justify-center rt:text-primary-foreground",
|
|
18
|
+
children: props.indeterminate ? /* @__PURE__ */ jsx("span", {
|
|
19
|
+
"data-slot": "checkbox-dash",
|
|
20
|
+
className: "rt:block rt:h-px rt:w-2 rt:rounded-sm rt:bg-primary-foreground"
|
|
21
|
+
}) : /* @__PURE__ */ jsx(Icon, {
|
|
22
|
+
name: "check",
|
|
23
|
+
size: 8
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export { Checkbox$1 as Checkbox };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Checkbox } from "./Checkbox.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { HTMLAttributes, JSX } from "react";
|
|
2
|
+
/** One option in a CheckboxList. */
|
|
3
|
+
export type CheckboxListItem = {
|
|
4
|
+
/** The value reported in the list of chosen values. */
|
|
5
|
+
value: string;
|
|
6
|
+
/** The label beside the box. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** An optional line under the label. */
|
|
9
|
+
description?: string;
|
|
10
|
+
/** Stops this item being toggled, and select-all leaves it as it is. */
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** The props of CheckboxList. */
|
|
14
|
+
export type CheckboxListProps = Omit<HTMLAttributes<HTMLDivElement>, 'className' | 'style' | 'title' | 'onChange' | 'defaultValue'> & {
|
|
15
|
+
/** The heading. The count of chosen items sits beside it. */
|
|
16
|
+
title: string;
|
|
17
|
+
/** The options. */
|
|
18
|
+
items: CheckboxListItem[];
|
|
19
|
+
/** The chosen values, when controlled. */
|
|
20
|
+
value?: string[];
|
|
21
|
+
/** The chosen values to start with, when not controlled. */
|
|
22
|
+
defaultValue?: string[];
|
|
23
|
+
/** Called with the new list of chosen values. */
|
|
24
|
+
onValueChange?: (value: string[]) => void;
|
|
25
|
+
/** Adds a "Select all" box that is mixed while only some are chosen. */
|
|
26
|
+
selectAll?: boolean;
|
|
27
|
+
/** The label of the select-all box. Defaults to "Select all". */
|
|
28
|
+
selectAllLabel?: string;
|
|
29
|
+
/** Writes the count in the heading from the chosen and total counts, already formatted. Defaults to "4 of 6". */
|
|
30
|
+
countLabel?: (chosen: string, total: string) => string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A titled list of checkboxes with the count of chosen items in the heading ("4 of 6"), an optional description under
|
|
34
|
+
* each label and an optional select-all.
|
|
35
|
+
*/
|
|
36
|
+
export declare function CheckboxList({ title, items, value, defaultValue, onValueChange, selectAll, selectAllLabel, countLabel, ...rest }: CheckboxListProps): JSX.Element;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { formatCount } from "../../lib/format.js";
|
|
2
|
+
import { Checkbox } from "../checkbox/Checkbox.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useId, useState } from "react";
|
|
5
|
+
// src/components/checkbox-list/CheckboxList.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A titled list of checkboxes with the count of chosen items in the heading ("4 of 6"), an optional description under
|
|
8
|
+
* each label and an optional select-all.
|
|
9
|
+
*/
|
|
10
|
+
function CheckboxList({ title, items, value, defaultValue, onValueChange, selectAll, selectAllLabel = "Select all", countLabel = (c, t) => `${c} of ${t}`, ...rest }) {
|
|
11
|
+
const [inner, setInner] = useState(defaultValue ?? []);
|
|
12
|
+
const chosen = value ?? inner;
|
|
13
|
+
const baseId = useId();
|
|
14
|
+
const set = (next) => {
|
|
15
|
+
if (value === void 0) setInner(next);
|
|
16
|
+
onValueChange?.(next);
|
|
17
|
+
};
|
|
18
|
+
const chosenCount = items.filter((i) => chosen.includes(i.value)).length;
|
|
19
|
+
const toggleable = items.filter((i) => !i.disabled);
|
|
20
|
+
const allOn = toggleable.length > 0 && toggleable.every((i) => chosen.includes(i.value));
|
|
21
|
+
const someOn = chosenCount > 0;
|
|
22
|
+
const toggleAll = () => {
|
|
23
|
+
const locked = chosen.filter((v) => !toggleable.some((i) => i.value === v));
|
|
24
|
+
set(allOn ? locked : [...locked, ...toggleable.map((i) => i.value)]);
|
|
25
|
+
};
|
|
26
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
27
|
+
"data-slot": "checkbox-list",
|
|
28
|
+
role: "group",
|
|
29
|
+
"aria-labelledby": `${baseId}-title`,
|
|
30
|
+
...rest,
|
|
31
|
+
className: "rt:flex rt:flex-col rt:gap-3",
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsx("div", {
|
|
34
|
+
className: "rt:flex rt:items-baseline rt:justify-between rt:gap-3",
|
|
35
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
36
|
+
id: `${baseId}-title`,
|
|
37
|
+
className: "rt:text-b4 rt:text-foreground",
|
|
38
|
+
children: [title, /* @__PURE__ */ jsx("span", {
|
|
39
|
+
"data-slot": "checkbox-list-count",
|
|
40
|
+
className: "rt:ml-2 rt:text-b3 rt:text-foreground-subdued",
|
|
41
|
+
children: countLabel(formatCount(chosenCount), formatCount(items.length))
|
|
42
|
+
})]
|
|
43
|
+
})
|
|
44
|
+
}),
|
|
45
|
+
selectAll ? /* @__PURE__ */ jsxs("div", {
|
|
46
|
+
className: "rt:flex rt:items-center rt:gap-2",
|
|
47
|
+
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
48
|
+
id: `${baseId}-all`,
|
|
49
|
+
checked: allOn,
|
|
50
|
+
indeterminate: someOn && !allOn,
|
|
51
|
+
onCheckedChange: toggleAll,
|
|
52
|
+
disabled: toggleable.length === 0,
|
|
53
|
+
"aria-label": selectAllLabel
|
|
54
|
+
}), /* @__PURE__ */ jsx("label", {
|
|
55
|
+
htmlFor: `${baseId}-all`,
|
|
56
|
+
className: "rt:cursor-pointer rt:text-b3 rt:text-foreground",
|
|
57
|
+
children: selectAllLabel
|
|
58
|
+
})]
|
|
59
|
+
}) : null,
|
|
60
|
+
/* @__PURE__ */ jsx("ul", {
|
|
61
|
+
className: "rt:flex rt:flex-col rt:gap-3",
|
|
62
|
+
children: items.map((item, index) => {
|
|
63
|
+
const id = `${baseId}-${index}`;
|
|
64
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
65
|
+
className: "rt:flex rt:items-start rt:gap-2",
|
|
66
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
67
|
+
className: "rt:mt-0.5 rt:flex",
|
|
68
|
+
children: /* @__PURE__ */ jsx(Checkbox, {
|
|
69
|
+
id,
|
|
70
|
+
"aria-labelledby": `${id}-label`,
|
|
71
|
+
disabled: item.disabled,
|
|
72
|
+
checked: chosen.includes(item.value),
|
|
73
|
+
onCheckedChange: (on) => set(on ? [...chosen, item.value] : chosen.filter((v) => v !== item.value))
|
|
74
|
+
})
|
|
75
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
76
|
+
className: "rt:flex rt:flex-col",
|
|
77
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
78
|
+
id: `${id}-label`,
|
|
79
|
+
htmlFor: id,
|
|
80
|
+
className: "rt:cursor-pointer rt:text-b3 rt:text-foreground",
|
|
81
|
+
children: item.label
|
|
82
|
+
}), item.description ? /* @__PURE__ */ jsx("span", {
|
|
83
|
+
className: "rt:text-b3 rt:text-foreground-subdued",
|
|
84
|
+
children: item.description
|
|
85
|
+
}) : null]
|
|
86
|
+
})]
|
|
87
|
+
}, item.value);
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
export { CheckboxList };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CheckboxList } from "./CheckboxList.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SummaryChip } from "../summary-chips/SummaryChips.js";
|
|
2
|
+
import "../summary-chips/index.js";
|
|
3
|
+
import { JSX, ReactNode, Ref } from "react";
|
|
4
|
+
/** The props of Collapsible. */
|
|
5
|
+
export interface CollapsibleProps {
|
|
6
|
+
/** The section heading, shown on the trigger. */
|
|
7
|
+
title: string;
|
|
8
|
+
/** The values to show as chips while the section is closed. */
|
|
9
|
+
summary?: readonly SummaryChip[];
|
|
10
|
+
/** Whether the section is open, when controlled. */
|
|
11
|
+
open?: boolean;
|
|
12
|
+
/** Whether the section starts open, when uncontrolled. Defaults to closed. */
|
|
13
|
+
defaultOpen?: boolean;
|
|
14
|
+
/** Called when the section opens or closes. */
|
|
15
|
+
onOpenChange?: (open: boolean) => void;
|
|
16
|
+
/** Stops the section from opening or closing. */
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
/** The section's content, shown when open. */
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
/** Receives the rendered root. */
|
|
21
|
+
ref?: Ref<HTMLDivElement>;
|
|
22
|
+
}
|
|
23
|
+
/** A section that opens and closes on its heading and, while closed, still shows its values as chips. The panel appears and disappears with no height animation. */
|
|
24
|
+
export declare function Collapsible({ title, summary, open: openProp, defaultOpen, onOpenChange, disabled, children, ref }: CollapsibleProps): JSX.Element;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Icon } from "../icon/Icon.js";
|
|
2
|
+
import { SummaryChips } from "../summary-chips/SummaryChips.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { Collapsible } from "@base-ui/react/collapsible";
|
|
6
|
+
// src/components/collapsible/Collapsible.tsx
|
|
7
|
+
/** A section that opens and closes on its heading and, while closed, still shows its values as chips. The panel appears and disappears with no height animation. */
|
|
8
|
+
function Collapsible$1({ title, summary, open: openProp, defaultOpen = false, onOpenChange, disabled, children, ref }) {
|
|
9
|
+
const [inner, setInner] = useState(defaultOpen);
|
|
10
|
+
const open = openProp ?? inner;
|
|
11
|
+
return /* @__PURE__ */ jsxs(Collapsible.Root, {
|
|
12
|
+
ref,
|
|
13
|
+
open,
|
|
14
|
+
onOpenChange: (next) => {
|
|
15
|
+
setInner(next);
|
|
16
|
+
onOpenChange?.(next);
|
|
17
|
+
},
|
|
18
|
+
disabled,
|
|
19
|
+
className: "rt:flex rt:flex-col rt:gap-2",
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ jsxs(Collapsible.Trigger, {
|
|
22
|
+
className: "rt:group rt:flex rt:h-7 rt:w-full rt:cursor-pointer rt:items-center rt:gap-2 rt:rounded-md rt:border-0 rt:bg-transparent rt:p-0 rt:text-left rt:text-b3 rt:text-foreground rt:transition-colors rt:focus-visible:focus-ring rt:disabled:cursor-not-allowed rt:disabled:opacity-50 rt:data-disabled:opacity-50",
|
|
23
|
+
children: [
|
|
24
|
+
/* @__PURE__ */ jsx("span", {
|
|
25
|
+
className: "rt:group-data-panel-open:hidden",
|
|
26
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
27
|
+
name: "chevron-right",
|
|
28
|
+
size: 8
|
|
29
|
+
})
|
|
30
|
+
}),
|
|
31
|
+
/* @__PURE__ */ jsx("span", {
|
|
32
|
+
className: "rt:hidden rt:group-data-panel-open:inline",
|
|
33
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
34
|
+
name: "nav-caret-down",
|
|
35
|
+
size: 8
|
|
36
|
+
})
|
|
37
|
+
}),
|
|
38
|
+
/* @__PURE__ */ jsx("span", {
|
|
39
|
+
className: "rt:text-c2",
|
|
40
|
+
children: title
|
|
41
|
+
})
|
|
42
|
+
]
|
|
43
|
+
}),
|
|
44
|
+
/* @__PURE__ */ jsx(Collapsible.Panel, {
|
|
45
|
+
className: "rt:flex rt:flex-col rt:gap-2",
|
|
46
|
+
children
|
|
47
|
+
}),
|
|
48
|
+
!open && summary ? /* @__PURE__ */ jsx("div", {
|
|
49
|
+
"data-slot": "collapsible-summary",
|
|
50
|
+
children: /* @__PURE__ */ jsx(SummaryChips, {
|
|
51
|
+
items: summary,
|
|
52
|
+
"aria-label": `${title} summary`
|
|
53
|
+
})
|
|
54
|
+
}) : null
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export { Collapsible$1 as Collapsible };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Collapsible } from "./Collapsible.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { TableProps } from "../table/Table.js";
|
|
2
|
+
import "../table/index.js";
|
|
3
|
+
import { JSX, ReactNode } from "react";
|
|
4
|
+
import { RowData } from "@tanstack/react-table";
|
|
5
|
+
/** The sort the parent has applied: the id of a column and whether it runs from high to low. */
|
|
6
|
+
export type DataTableSort = {
|
|
7
|
+
id: string;
|
|
8
|
+
desc: boolean;
|
|
9
|
+
};
|
|
10
|
+
/** One column of a DataTable. */
|
|
11
|
+
export type DataTableColumn<T> = {
|
|
12
|
+
/** A stable key for the column, also the id passed to `onSortChange`. */
|
|
13
|
+
id: string;
|
|
14
|
+
/** The heading text. */
|
|
15
|
+
header: string;
|
|
16
|
+
/** Draws the cell for one row. */
|
|
17
|
+
cell: (row: T) => ReactNode;
|
|
18
|
+
/** Aligns the heading and cells to the right with tabular figures. Defaults to false. */
|
|
19
|
+
numeric?: boolean;
|
|
20
|
+
/** Cuts a long value off with an ellipsis so it stays on one line. Defaults to false. */
|
|
21
|
+
truncate?: boolean;
|
|
22
|
+
/** Lets the heading ask the parent to sort by this column. Defaults to false. */
|
|
23
|
+
sortable?: boolean;
|
|
24
|
+
/** Keeps the column on a phone; a column that is not essential is hidden there, and with none marked the first stays. Defaults to false. */
|
|
25
|
+
essential?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** The props of DataTable: the attributes of Table, plus the columns, the rows and the state the parent owns. */
|
|
28
|
+
export type DataTableProps<T> = Omit<TableProps, 'children'> & {
|
|
29
|
+
/** The columns, in order. */
|
|
30
|
+
columns: DataTableColumn<T>[];
|
|
31
|
+
/** The rows of the page on show, already sorted by the parent. */
|
|
32
|
+
data: T[];
|
|
33
|
+
/** A stable id for a row. */
|
|
34
|
+
getRowId: (row: T) => string;
|
|
35
|
+
/** Ids of the selected rows. Pass it with `onSelectedIdsChange` to show a checkbox column. */
|
|
36
|
+
selectedIds?: string[];
|
|
37
|
+
/** Called with the ids that are selected after a change. */
|
|
38
|
+
onSelectedIdsChange?: (ids: string[]) => void;
|
|
39
|
+
/** The label of one row's checkbox: "RYZE - 2mg", which the table prefixes with "Select ". Defaults to "Select row N". */
|
|
40
|
+
getRowLabel?: (row: T) => string;
|
|
41
|
+
/** The sort the parent applied, or null for none. */
|
|
42
|
+
sort?: DataTableSort | null;
|
|
43
|
+
/** Called with the next sort, or null to clear it. The parent sorts and passes new data. */
|
|
44
|
+
onSortChange?: (sort: DataTableSort | null) => void;
|
|
45
|
+
/** The page on show, counting from 1. Pass with `pageSize`, `total` and `onPageChange` to show the footer. */
|
|
46
|
+
page?: number;
|
|
47
|
+
/** How many results one page holds. */
|
|
48
|
+
pageSize?: number;
|
|
49
|
+
/** How many results there are in all, across every page. */
|
|
50
|
+
total?: number;
|
|
51
|
+
/** Called with the page to show. */
|
|
52
|
+
onPageChange?: (page: number) => void;
|
|
53
|
+
/** Where a row leads. The first data cell of the row becomes a link to it. On a router, LinkProvider draws it with the app's own link. */
|
|
54
|
+
rowHref?: (row: T) => string;
|
|
55
|
+
/** Shown in place of the rows when there are none and the table is not loading. Usually an EmptyState. */
|
|
56
|
+
empty?: ReactNode;
|
|
57
|
+
/** Shown in place of the whole table while loading, usually a TableLoader. A falsy value shows the table. */
|
|
58
|
+
loading?: ReactNode;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A data table on Table with TanStack Table v9: a selection column, server-side sorting and paging, alignment,
|
|
62
|
+
* one-line truncation, row links, and empty and loading slots. The parent owns the state (sort, page, selection) and
|
|
63
|
+
* passes it in. On phones it keeps the columns marked essential and hides the rest.
|
|
64
|
+
*/
|
|
65
|
+
export declare function DataTable<T extends RowData>({ columns: allColumns, data, getRowId, selectedIds, onSelectedIdsChange, getRowLabel, sort, onSortChange, page, pageSize, total, onPageChange, rowHref, empty, loading, ...rest }: DataTableProps<T>): JSX.Element;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Checkbox } from "../checkbox/Checkbox.js";
|
|
2
|
+
import { RatioLink } from "../link-provider/RatioLink.js";
|
|
3
|
+
import { Pagination } from "../pagination/Pagination.js";
|
|
4
|
+
import { Table, TableBody, TableBox, TableCell, TableHead, TableHeader, TableRow } from "../table/Table.js";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useMemo, useSyncExternalStore } from "react";
|
|
7
|
+
import { FlexRender, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
|
|
8
|
+
// src/components/data-table/DataTable.tsx
|
|
9
|
+
const features = tableFeatures({
|
|
10
|
+
rowSortingFeature,
|
|
11
|
+
rowSelectionFeature
|
|
12
|
+
});
|
|
13
|
+
const PHONE_QUERY = "(max-width: 39.99rem)";
|
|
14
|
+
function subscribePhone(notify) {
|
|
15
|
+
const list = window.matchMedia(PHONE_QUERY);
|
|
16
|
+
list.addEventListener("change", notify);
|
|
17
|
+
return () => list.removeEventListener("change", notify);
|
|
18
|
+
}
|
|
19
|
+
function usePhone() {
|
|
20
|
+
return useSyncExternalStore(subscribePhone, () => window.matchMedia(PHONE_QUERY).matches, () => false);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A data table on Table with TanStack Table v9: a selection column, server-side sorting and paging, alignment,
|
|
24
|
+
* one-line truncation, row links, and empty and loading slots. The parent owns the state (sort, page, selection) and
|
|
25
|
+
* passes it in. On phones it keeps the columns marked essential and hides the rest.
|
|
26
|
+
*/
|
|
27
|
+
function DataTable({ columns: allColumns, data, getRowId, selectedIds, onSelectedIdsChange, getRowLabel, sort = null, onSortChange, page, pageSize, total, onPageChange, rowHref, empty, loading, ...rest }) {
|
|
28
|
+
const phone = usePhone();
|
|
29
|
+
const columns = useMemo(() => {
|
|
30
|
+
if (!phone) return allColumns;
|
|
31
|
+
const essential = allColumns.filter((c) => c.essential);
|
|
32
|
+
return essential.length > 0 ? essential : allColumns.slice(0, 1);
|
|
33
|
+
}, [phone, allColumns]);
|
|
34
|
+
const selectable = selectedIds !== void 0;
|
|
35
|
+
const defs = useMemo(() => columns.map((c) => ({
|
|
36
|
+
id: c.id,
|
|
37
|
+
header: c.header,
|
|
38
|
+
accessorFn: () => null,
|
|
39
|
+
cell: ({ row }) => c.cell(row.original),
|
|
40
|
+
enableSorting: c.sortable === true,
|
|
41
|
+
sortDescFirst: false
|
|
42
|
+
})), [columns]);
|
|
43
|
+
const sorting = sort ? [sort] : [];
|
|
44
|
+
const rowSelection = useMemo(() => Object.fromEntries((selectedIds ?? []).map((id) => [id, true])), [selectedIds]);
|
|
45
|
+
const table = useTable({
|
|
46
|
+
features,
|
|
47
|
+
columns: defs,
|
|
48
|
+
data,
|
|
49
|
+
getRowId,
|
|
50
|
+
manualSorting: true,
|
|
51
|
+
enableRowSelection: selectable,
|
|
52
|
+
state: {
|
|
53
|
+
sorting,
|
|
54
|
+
rowSelection
|
|
55
|
+
},
|
|
56
|
+
onSortingChange: (updater) => {
|
|
57
|
+
const next = typeof updater === "function" ? updater(sorting) : updater;
|
|
58
|
+
onSortChange?.(next[0] ? {
|
|
59
|
+
id: next[0].id,
|
|
60
|
+
desc: next[0].desc
|
|
61
|
+
} : null);
|
|
62
|
+
},
|
|
63
|
+
onRowSelectionChange: (updater) => {
|
|
64
|
+
const next = typeof updater === "function" ? updater(rowSelection) : updater;
|
|
65
|
+
onSelectedIdsChange?.(Object.keys(next).filter((id) => next[id]));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const rows = table.getRowModel().rows;
|
|
69
|
+
const colSpan = columns.length + (selectable ? 1 : 0);
|
|
70
|
+
const hasFooter = page !== void 0 && pageSize !== void 0 && total !== void 0 && onPageChange !== void 0;
|
|
71
|
+
const byId = new Map(columns.map((c) => [c.id, c]));
|
|
72
|
+
if (loading) return /* @__PURE__ */ jsx(Fragment, { children: loading });
|
|
73
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
74
|
+
"data-slot": "data-table",
|
|
75
|
+
className: "rt:flex rt:w-full rt:flex-col rt:gap-2",
|
|
76
|
+
children: [/* @__PURE__ */ jsx(TableBox, { children: /* @__PURE__ */ jsxs(Table, {
|
|
77
|
+
...rest,
|
|
78
|
+
children: [/* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { children: [selectable ? /* @__PURE__ */ jsx(TableHead, { children: /* @__PURE__ */ jsx(Checkbox, {
|
|
79
|
+
"aria-label": "Select all rows",
|
|
80
|
+
checked: table.getIsAllRowsSelected() && rows.length > 0,
|
|
81
|
+
indeterminate: rows.some((r) => r.getIsSelected()) && !table.getIsAllRowsSelected(),
|
|
82
|
+
onCheckedChange: () => table.toggleAllRowsSelected()
|
|
83
|
+
}) }) : null, table.getHeaderGroups()[0]?.headers.map((h) => {
|
|
84
|
+
const c = byId.get(h.column.id);
|
|
85
|
+
if (!c) return null;
|
|
86
|
+
const sorted = h.column.getIsSorted();
|
|
87
|
+
return /* @__PURE__ */ jsx(TableHead, {
|
|
88
|
+
numeric: c.numeric,
|
|
89
|
+
"aria-sort": sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : void 0,
|
|
90
|
+
children: c.sortable ? /* @__PURE__ */ jsxs("button", {
|
|
91
|
+
type: "button",
|
|
92
|
+
"aria-label": `Sort by ${c.header}`,
|
|
93
|
+
className: "rt:inline-flex rt:cursor-pointer rt:items-center rt:gap-1 rt:uppercase rt:focus-visible:focus-ring",
|
|
94
|
+
onClick: () => h.column.toggleSorting(),
|
|
95
|
+
children: [/* @__PURE__ */ jsx(FlexRender, { header: h }), /* @__PURE__ */ jsx("span", {
|
|
96
|
+
"aria-hidden": "true",
|
|
97
|
+
children: sorted === "asc" ? "↑" : sorted === "desc" ? "↓" : null
|
|
98
|
+
})]
|
|
99
|
+
}) : /* @__PURE__ */ jsx(FlexRender, { header: h })
|
|
100
|
+
}, h.id);
|
|
101
|
+
})] }) }), /* @__PURE__ */ jsx(TableBody, { children: rows.length === 0 ? /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, {
|
|
102
|
+
colSpan,
|
|
103
|
+
children: empty
|
|
104
|
+
}) }) : rows.map((row, index) => /* @__PURE__ */ jsxs(TableRow, {
|
|
105
|
+
selected: row.getIsSelected(),
|
|
106
|
+
children: [selectable ? /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Checkbox, {
|
|
107
|
+
"aria-label": getRowLabel ? `Select ${getRowLabel(row.original)}` : `Select row ${index + 1}`,
|
|
108
|
+
checked: row.getIsSelected(),
|
|
109
|
+
onCheckedChange: () => row.toggleSelected()
|
|
110
|
+
}) }) : null, row.getAllCells().map((cell, i) => {
|
|
111
|
+
const c = byId.get(cell.column.id);
|
|
112
|
+
if (!c) return null;
|
|
113
|
+
const content = /* @__PURE__ */ jsx(FlexRender, { cell });
|
|
114
|
+
const linked = rowHref && i === 0 ? /* @__PURE__ */ jsx(RatioLink, {
|
|
115
|
+
href: rowHref(row.original),
|
|
116
|
+
className: "rt:focus-visible:focus-ring",
|
|
117
|
+
children: content
|
|
118
|
+
}) : content;
|
|
119
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
120
|
+
numeric: c.numeric,
|
|
121
|
+
"data-numeric": c.numeric ? "true" : void 0,
|
|
122
|
+
children: c.truncate ? /* @__PURE__ */ jsx("span", {
|
|
123
|
+
className: "rt:block rt:max-w-64 rt:truncate",
|
|
124
|
+
children: linked
|
|
125
|
+
}) : linked
|
|
126
|
+
}, cell.id);
|
|
127
|
+
})]
|
|
128
|
+
}, row.id)) })]
|
|
129
|
+
}) }), hasFooter ? /* @__PURE__ */ jsx("div", {
|
|
130
|
+
"data-slot": "data-table-pagination",
|
|
131
|
+
className: "rt:rounded-lg rt:border rt:border-border rt:bg-background rt:px-2",
|
|
132
|
+
children: /* @__PURE__ */ jsx(Pagination, {
|
|
133
|
+
page,
|
|
134
|
+
pageSize,
|
|
135
|
+
total,
|
|
136
|
+
onPageChange
|
|
137
|
+
})
|
|
138
|
+
}) : null]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
export { DataTable };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTable } from "./DataTable.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CalendarProps } from "../calendar/Calendar.js";
|
|
2
|
+
import "../calendar/index.js";
|
|
3
|
+
import { InputGroupSize } from "../input-group/InputGroup.js";
|
|
4
|
+
import "../input-group/index.js";
|
|
5
|
+
import { InputHTMLAttributes, JSX, Ref } from "react";
|
|
6
|
+
/**
|
|
7
|
+
* The props of DatePicker: the HTML attributes of an input, except className, style, size and the ones the field sets itself,
|
|
8
|
+
* with the day as a Date in and out. Mark an invalid field with aria-invalid, which draws the error ring around the group.
|
|
9
|
+
*/
|
|
10
|
+
export type DatePickerProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'className' | 'style' | 'size' | 'type' | 'value' | 'defaultValue' | 'onChange' | 'min' | 'max'> & {
|
|
11
|
+
/** The day, or null for an empty field. Pass it to control the field. */
|
|
12
|
+
value?: Date | null;
|
|
13
|
+
/** The starting day when the field is not controlled. Defaults to empty. */
|
|
14
|
+
defaultValue?: Date | null;
|
|
15
|
+
/** Called with the day when a typed date is complete or a day is picked, and with null when the text is cleared. */
|
|
16
|
+
onValueChange?: (value: Date | null) => void;
|
|
17
|
+
/** The days that cannot be picked in the calendar, for example { before: new Date() }. */
|
|
18
|
+
disabledDays?: CalendarProps['disabled'];
|
|
19
|
+
/** The first month the calendar can show. */
|
|
20
|
+
startMonth?: Date;
|
|
21
|
+
/** The last month the calendar can show. */
|
|
22
|
+
endMonth?: Date;
|
|
23
|
+
/** The height in px: 36 for forms, 32 for fields inside a table. Defaults to 36. */
|
|
24
|
+
size?: InputGroupSize;
|
|
25
|
+
/** Receives the input element. */
|
|
26
|
+
ref?: Ref<HTMLInputElement>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A field that shows a day as DD/MM/YYYY, reads a typed date through the format module and opens a calendar in a popover
|
|
30
|
+
* from the button at its end. Text that is not a date is marked invalid when the field loses focus, and reports nothing.
|
|
31
|
+
* Under a name, a form submits the day as YYYY-MM-DD (empty when there is none), never the text on screen.
|
|
32
|
+
*/
|
|
33
|
+
export declare function DatePicker({ value, defaultValue, onValueChange, disabledDays, startMonth, endMonth, size, placeholder, readOnly, disabled, onBlur, ref, name, 'aria-invalid': ariaInvalid, ...rest }: DatePickerProps): JSX.Element;
|