@arshad-shah/cynosure 0.2.0 → 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 +3 -3
- package/dist/components/Accordion/Accordion.d.ts +14 -0
- package/dist/components/Accordion/Accordion.js.map +1 -1
- package/dist/components/Announcer/Announcer.d.ts +1 -0
- package/dist/components/Announcer/Announcer.js.map +1 -1
- package/dist/components/AppShell/AppShell.d.ts +22 -1
- package/dist/components/AppShell/AppShell.js +95 -83
- package/dist/components/AppShell/AppShell.js.map +1 -1
- package/dist/components/AppShell/index.d.ts +1 -1
- package/dist/components/AspectRatio/AspectRatio.d.ts +29 -0
- package/dist/components/AspectRatio/AspectRatio.js +21 -0
- package/dist/components/AspectRatio/AspectRatio.js.map +1 -0
- package/dist/components/AspectRatio/index.d.ts +1 -0
- package/dist/components/Avatar/Avatar.d.ts +96 -0
- package/dist/components/Avatar/Avatar.js +90 -0
- package/dist/components/Avatar/Avatar.js.map +1 -0
- package/dist/components/Avatar/index.d.ts +1 -0
- package/dist/components/Badge/Badge.d.ts +6 -0
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +55 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js +85 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -0
- package/dist/components/Breadcrumbs/index.d.ts +1 -0
- package/dist/components/Button/Button.d.ts +13 -2
- package/dist/components/Button/Button.js +28 -26
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Calendar/Calendar.d.ts +65 -7
- package/dist/components/Calendar/Calendar.js +207 -95
- package/dist/components/Calendar/Calendar.js.map +1 -1
- package/dist/components/Calendar/dates.d.ts +4 -0
- package/dist/components/Calendar/dates.js +41 -27
- package/dist/components/Calendar/dates.js.map +1 -1
- package/dist/components/Calendar/index.d.ts +1 -1
- package/dist/components/Card/Card.d.ts +27 -0
- package/dist/components/Card/Card.js +48 -36
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/Card/index.d.ts +1 -1
- package/dist/components/Checkbox/Checkbox.d.ts +8 -1
- package/dist/components/Checkbox/Checkbox.js +7 -6
- package/dist/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/Checkbox/ChoiceRow.d.ts +17 -1
- package/dist/components/Checkbox/ChoiceRow.js +19 -18
- package/dist/components/Checkbox/ChoiceRow.js.map +1 -1
- package/dist/components/Checklist/Checklist.d.ts +65 -0
- package/dist/components/Checklist/Checklist.js +163 -0
- package/dist/components/Checklist/Checklist.js.map +1 -0
- package/dist/components/Checklist/index.d.ts +1 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +5 -0
- package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/components/ColorField/ColorField.d.ts +12 -0
- package/dist/components/ColorField/ColorField.js +19 -19
- package/dist/components/ColorField/ColorField.js.map +1 -1
- package/dist/components/ColorSwatches/ColorSwatches.d.ts +5 -0
- package/dist/components/ColorSwatches/ColorSwatches.js +6 -6
- package/dist/components/ColorSwatches/ColorSwatches.js.map +1 -1
- package/dist/components/Combobox/Combobox.d.ts +20 -1
- package/dist/components/Combobox/Combobox.js +38 -34
- package/dist/components/Combobox/Combobox.js.map +1 -1
- package/dist/components/CommandPalette/CommandPalette.d.ts +9 -0
- package/dist/components/CommandPalette/CommandPalette.js +10 -10
- package/dist/components/CommandPalette/CommandPalette.js.map +1 -1
- package/dist/components/CompareSlider/CompareSlider.d.ts +4 -0
- package/dist/components/CompareSlider/CompareSlider.js +4 -4
- package/dist/components/CompareSlider/CompareSlider.js.map +1 -1
- package/dist/components/Container/Container.d.ts +44 -0
- package/dist/components/Container/Container.js +24 -0
- package/dist/components/Container/Container.js.map +1 -0
- package/dist/components/Container/index.d.ts +1 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +11 -0
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/components/CopyButton/CopyButton.d.ts +8 -0
- package/dist/components/CopyButton/CopyButton.js.map +1 -1
- package/dist/components/DateField/DateField.d.ts +17 -0
- package/dist/components/DateField/DateField.js +6 -6
- package/dist/components/DateField/DateField.js.map +1 -1
- package/dist/components/DescriptionList/DescriptionList.d.ts +3 -0
- package/dist/components/DescriptionList/DescriptionList.js.map +1 -1
- package/dist/components/Dialog/Dialog.d.ts +16 -2
- package/dist/components/Dialog/Dialog.js +82 -70
- package/dist/components/Dialog/Dialog.js.map +1 -1
- package/dist/components/Disclosure/Disclosure.d.ts +7 -0
- package/dist/components/Disclosure/Disclosure.js.map +1 -1
- package/dist/components/Divider/Divider.d.ts +59 -0
- package/dist/components/Divider/Divider.js +32 -0
- package/dist/components/Divider/Divider.js.map +1 -0
- package/dist/components/Divider/index.d.ts +1 -0
- package/dist/components/DocumentViewport/DocumentViewport.d.ts +8 -0
- package/dist/components/DocumentViewport/DocumentViewport.js.map +1 -1
- package/dist/components/EmptyState/EmptyState.d.ts +3 -0
- package/dist/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/Field/Field.d.ts +6 -0
- package/dist/components/Field/Field.js.map +1 -1
- package/dist/components/FileDrop/FileDrop.d.ts +8 -0
- package/dist/components/FileDrop/FileDrop.js.map +1 -1
- package/dist/components/FloatingToolbar/FloatingToolbar.d.ts +4 -0
- package/dist/components/FloatingToolbar/FloatingToolbar.js +4 -4
- package/dist/components/FloatingToolbar/FloatingToolbar.js.map +1 -1
- package/dist/components/Grid/Grid.d.ts +33 -7
- package/dist/components/Grid/Grid.js +46 -25
- package/dist/components/Grid/Grid.js.map +1 -1
- package/dist/components/Grid/index.d.ts +1 -1
- package/dist/components/Heading/Heading.d.ts +57 -0
- package/dist/components/Heading/Heading.js +33 -0
- package/dist/components/Heading/Heading.js.map +1 -0
- package/dist/components/Heading/index.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.js.map +1 -1
- package/dist/components/IconButton/IconButton.d.ts +1 -0
- package/dist/components/IconButton/IconButton.js.map +1 -1
- package/dist/components/Image/Image.d.ts +62 -0
- package/dist/components/Image/Image.js +75 -0
- package/dist/components/Image/Image.js.map +1 -0
- package/dist/components/Image/index.d.ts +1 -0
- package/dist/components/Inline/Inline.d.ts +7 -3
- package/dist/components/Inline/Inline.js +19 -13
- package/dist/components/Inline/Inline.js.map +1 -1
- package/dist/components/Kbd/Kbd.d.ts +2 -0
- package/dist/components/Kbd/Kbd.js.map +1 -1
- package/dist/components/KeyValueEditor/KeyValueEditor.d.ts +7 -0
- package/dist/components/KeyValueEditor/KeyValueEditor.js +8 -8
- package/dist/components/KeyValueEditor/KeyValueEditor.js.map +1 -1
- package/dist/components/Link/Link.d.ts +7 -0
- package/dist/components/Link/Link.js.map +1 -1
- package/dist/components/LoadingDots/LoadingDots.d.ts +2 -0
- package/dist/components/LoadingDots/LoadingDots.js.map +1 -1
- package/dist/components/Menu/Menu.d.ts +13 -1
- package/dist/components/Menu/Menu.js +37 -35
- package/dist/components/Menu/Menu.js.map +1 -1
- package/dist/components/Notice/Notice.d.ts +5 -0
- package/dist/components/Notice/Notice.js.map +1 -1
- package/dist/components/NumberField/NumberField.d.ts +17 -0
- package/dist/components/NumberField/NumberField.js +8 -8
- package/dist/components/NumberField/NumberField.js.map +1 -1
- package/dist/components/PageHeader/PageHeader.d.ts +61 -0
- package/dist/components/PageHeader/PageHeader.js +63 -0
- package/dist/components/PageHeader/PageHeader.js.map +1 -0
- package/dist/components/PageHeader/index.d.ts +1 -0
- package/dist/components/Pagination/Pagination.d.ts +77 -0
- package/dist/components/Pagination/Pagination.js +120 -0
- package/dist/components/Pagination/Pagination.js.map +1 -0
- package/dist/components/Pagination/index.d.ts +1 -0
- package/dist/components/PanZoomCanvas/PanZoomCanvas.d.ts +4 -0
- package/dist/components/PanZoomCanvas/PanZoomCanvas.js.map +1 -1
- package/dist/components/Popover/Popover.d.ts +10 -0
- package/dist/components/Popover/Popover.js.map +1 -1
- package/dist/components/ProgressBar/ProgressBar.d.ts +5 -0
- package/dist/components/ProgressBar/ProgressBar.js.map +1 -1
- package/dist/components/ProgressOverlay/ProgressOverlay.d.ts +3 -0
- package/dist/components/ProgressOverlay/ProgressOverlay.js.map +1 -1
- package/dist/components/Prose/Prose.d.ts +1 -0
- package/dist/components/Prose/Prose.js.map +1 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +13 -0
- package/dist/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +9 -0
- package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/components/Select/Select.d.ts +18 -1
- package/dist/components/Select/Select.js +97 -88
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/index.d.ts +1 -0
- package/dist/components/SelectionFrame/SelectionFrame.d.ts +6 -0
- package/dist/components/SelectionFrame/SelectionFrame.js.map +1 -1
- package/dist/components/SideNav/SideNav.d.ts +37 -1
- package/dist/components/SideNav/SideNav.js +100 -73
- package/dist/components/SideNav/SideNav.js.map +1 -1
- package/dist/components/SideNav/index.d.ts +1 -1
- package/dist/components/SignaturePad/SignaturePad.d.ts +3 -0
- package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
- package/dist/components/Skeleton/Skeleton.d.ts +1 -0
- package/dist/components/Skeleton/Skeleton.js.map +1 -1
- package/dist/components/Slider/Slider.d.ts +11 -0
- package/dist/components/Slider/Slider.js +6 -6
- package/dist/components/Slider/Slider.js.map +1 -1
- package/dist/components/SortableList/SortableList.d.ts +6 -0
- package/dist/components/SortableList/SortableList.js.map +1 -1
- package/dist/components/SplitPane/SplitPane.d.ts +5 -0
- package/dist/components/SplitPane/SplitPane.js +4 -4
- package/dist/components/SplitPane/SplitPane.js.map +1 -1
- package/dist/components/Stack/Stack.d.ts +7 -3
- package/dist/components/Stack/Stack.js +18 -12
- package/dist/components/Stack/Stack.js.map +1 -1
- package/dist/components/Stack/index.d.ts +1 -0
- package/dist/components/Stack/space.d.ts +18 -0
- package/dist/components/Stack/space.js +12 -0
- package/dist/components/Stack/space.js.map +1 -0
- package/dist/components/Steps/Steps.d.ts +4 -0
- package/dist/components/Steps/Steps.js.map +1 -1
- package/dist/components/Table/Table.d.ts +12 -0
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Tabs/Tabs.d.ts +14 -0
- package/dist/components/Tabs/Tabs.js +4 -4
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/TagInput/TagInput.d.ts +18 -0
- package/dist/components/TagInput/TagInput.js +5 -5
- package/dist/components/TagInput/TagInput.js.map +1 -1
- package/dist/components/Text/Text.d.ts +72 -0
- package/dist/components/Text/Text.js +30 -0
- package/dist/components/Text/Text.js.map +1 -0
- package/dist/components/Text/index.d.ts +1 -0
- package/dist/components/TextArea/TextArea.d.ts +10 -0
- package/dist/components/TextArea/TextArea.js +4 -4
- package/dist/components/TextArea/TextArea.js.map +1 -1
- package/dist/components/TextField/TextField.d.ts +13 -0
- package/dist/components/TextField/TextField.js +4 -4
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/components/ThemeToggle/ThemeToggle.d.ts +4 -0
- package/dist/components/ThemeToggle/ThemeToggle.js.map +1 -1
- package/dist/components/TimeField/TimeField.d.ts +62 -8
- package/dist/components/TimeField/TimeField.js +308 -72
- package/dist/components/TimeField/TimeField.js.map +1 -1
- package/dist/components/Toast/Toast.d.ts +25 -1
- package/dist/components/Toast/Toast.js +134 -125
- package/dist/components/Toast/Toast.js.map +1 -1
- package/dist/components/Toast/index.d.ts +1 -1
- package/dist/components/Toolbar/Toolbar.d.ts +3 -0
- package/dist/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +1 -0
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/Tree/Tree.d.ts +8 -0
- package/dist/components/Tree/Tree.js.map +1 -1
- package/dist/components/VirtualList/VirtualList.d.ts +8 -0
- package/dist/components/VirtualList/VirtualList.js +4 -4
- package/dist/components/VirtualList/VirtualList.js.map +1 -1
- package/dist/components/ZoomControls/ZoomControls.d.ts +4 -0
- package/dist/components/ZoomControls/ZoomControls.js.map +1 -1
- package/dist/foundations/ChoiceBase/ChoiceBase.d.ts +1 -0
- package/dist/foundations/ChoiceBase/ChoiceBase.js.map +1 -1
- package/dist/foundations/HiddenValue/HiddenValue.d.ts +3 -0
- package/dist/foundations/HiddenValue/HiddenValue.js.map +1 -1
- package/dist/foundations/Icon/Icon.d.ts +3 -0
- package/dist/foundations/Icon/Icon.js.map +1 -1
- package/dist/foundations/image-outcome.d.ts +15 -0
- package/dist/foundations/image-outcome.js +39 -0
- package/dist/foundations/image-outcome.js.map +1 -0
- package/dist/foundations/option-icon.d.ts +26 -0
- package/dist/foundations/option-icon.js +16 -0
- package/dist/foundations/option-icon.js.map +1 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +476 -474
- package/dist/icons/keywords.d.ts +249 -0
- package/dist/icons/keywords.js +1728 -0
- package/dist/icons/keywords.js.map +1 -0
- package/dist/index.d.ts +20 -9
- package/dist/index.js +240 -213
- package/dist/styles/aspect-ratio.css +1 -0
- package/dist/styles/avatar.css +1 -0
- package/dist/styles/breadcrumbs.css +1 -0
- package/dist/styles/calendar.css +1 -1
- package/dist/styles/card.css +1 -1
- package/dist/styles/checkbox.css +1 -1
- package/dist/styles/checklist.css +1 -0
- package/dist/styles/container.css +1 -0
- package/dist/styles/divider.css +1 -0
- package/dist/styles/generated-css.d.ts +1 -1
- package/dist/styles/generated-css.js +1 -1
- package/dist/styles/generated-css.js.map +1 -1
- package/dist/styles/grid.css +1 -1
- package/dist/styles/heading.css +1 -0
- package/dist/styles/image.css +1 -0
- package/dist/styles/menu.css +1 -1
- package/dist/styles/page-header.css +1 -0
- package/dist/styles/pagination.css +1 -0
- package/dist/styles/side-nav.css +1 -1
- package/dist/styles/stack.css +1 -1
- package/dist/styles/text.css +1 -0
- package/dist/styles/time-field.css +1 -1
- package/dist/styles/toast.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme/CynosureTheme.d.ts +4 -0
- package/dist/theme/CynosureTheme.js.map +1 -1
- package/dist/tokens/to-css.js +12 -12
- package/dist/tokens/to-css.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from "react";
|
|
2
|
+
import { type Space } from "../Stack/space.js";
|
|
3
|
+
export interface ContainerTokens {
|
|
4
|
+
/** Widest a `size="sm"` container gets, gutters included. */
|
|
5
|
+
sizeSm: string;
|
|
6
|
+
/** Widest a `size="md"` container gets, gutters included. */
|
|
7
|
+
sizeMd: string;
|
|
8
|
+
/** Widest a `size="lg"` container gets, gutters included. */
|
|
9
|
+
sizeLg: string;
|
|
10
|
+
/** Widest a `size="xl"` container gets, gutters included. */
|
|
11
|
+
sizeXl: string;
|
|
12
|
+
/** Side gutters when the `padding` prop is not set. */
|
|
13
|
+
padding: string;
|
|
14
|
+
}
|
|
15
|
+
declare module "../../tokens/schema.js" {
|
|
16
|
+
interface ComponentTokens {
|
|
17
|
+
container: ContainerTokens;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export interface ContainerProps {
|
|
21
|
+
/** Widest the column gets, gutters included; `full` has no limit. Default "lg". */
|
|
22
|
+
size?: "sm" | "md" | "lg" | "xl" | "full";
|
|
23
|
+
/**
|
|
24
|
+
* Space token for the gutters at the inline start and end. They never get narrower than the device's safe area
|
|
25
|
+
* (a phone's notch or rounded corners). Default: the `--cy-container-padding` token (space 6).
|
|
26
|
+
*/
|
|
27
|
+
padding?: Space | undefined;
|
|
28
|
+
/** Space token of padding at the block start and end (top and bottom). Default: none. */
|
|
29
|
+
paddingBlock?: Space | undefined;
|
|
30
|
+
/** Centre the column in the space around it. `false` keeps it at the inline start. Default true. */
|
|
31
|
+
center?: boolean;
|
|
32
|
+
/** Element to render: `main` for the page's main content, once per page. Default "div". */
|
|
33
|
+
as?: "div" | "main" | "section" | "article";
|
|
34
|
+
/** Added to the root element, for layout. */
|
|
35
|
+
className?: string;
|
|
36
|
+
/** Layout only. Change the widths through the --cy-container-* tokens. */
|
|
37
|
+
style?: CSSProperties;
|
|
38
|
+
/** The page content. */
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
/** Set on the root element, for tests. */
|
|
41
|
+
"data-testid"?: string;
|
|
42
|
+
}
|
|
43
|
+
/** The page column: centres its content, caps its width and adds side gutters, so every page lines up. */
|
|
44
|
+
export declare const Container: import("react").ForwardRefExoticComponent<ContainerProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { space as i } from "../Stack/space.js";
|
|
3
|
+
import { forwardRef as u } from "react";
|
|
4
|
+
import { jsx as v } from "react/jsx-runtime";
|
|
5
|
+
var _ = u(function({ size: n = "lg", padding: t, paddingBlock: e, center: a = !0, as: c = "div", className: o, style: f, children: s, ...m }, p) {
|
|
6
|
+
const l = c, r = {};
|
|
7
|
+
return t && (r["--_pad-inline"] = i(t)), e && (r["--_pad-block"] = i(e)), /* @__PURE__ */ v(l, {
|
|
8
|
+
ref: p,
|
|
9
|
+
...m,
|
|
10
|
+
className: `cy-container${o ? ` ${o}` : ""}`,
|
|
11
|
+
"data-size": n,
|
|
12
|
+
"data-center": a ? "" : void 0,
|
|
13
|
+
style: {
|
|
14
|
+
...r,
|
|
15
|
+
...f
|
|
16
|
+
},
|
|
17
|
+
children: s
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
export {
|
|
21
|
+
_ as Container
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=Container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Container.js","names":["space","forwardRef","jsx","Container","size","padding","paddingBlock","center","as","className","style","children","rest","ref","Tag","vars"],"sources":["../../../src/components/Container/Container.tsx"],"sourcesContent":["import { type CSSProperties, type ElementType, forwardRef, type ReactNode } from \"react\";\nimport { type Space, space } from \"../Stack/space.js\";\n\nexport interface ContainerTokens {\n /** Widest a `size=\"sm\"` container gets, gutters included. */\n sizeSm: string;\n /** Widest a `size=\"md\"` container gets, gutters included. */\n sizeMd: string;\n /** Widest a `size=\"lg\"` container gets, gutters included. */\n sizeLg: string;\n /** Widest a `size=\"xl\"` container gets, gutters included. */\n sizeXl: string;\n /** Side gutters when the `padding` prop is not set. */\n padding: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n container: ContainerTokens;\n }\n}\n\nexport interface ContainerProps {\n /** Widest the column gets, gutters included; `full` has no limit. Default \"lg\". */\n size?: \"sm\" | \"md\" | \"lg\" | \"xl\" | \"full\";\n /**\n * Space token for the gutters at the inline start and end. They never get narrower than the device's safe area\n * (a phone's notch or rounded corners). Default: the `--cy-container-padding` token (space 6).\n */\n padding?: Space | undefined;\n /** Space token of padding at the block start and end (top and bottom). Default: none. */\n paddingBlock?: Space | undefined;\n /** Centre the column in the space around it. `false` keeps it at the inline start. Default true. */\n center?: boolean;\n /** Element to render: `main` for the page's main content, once per page. Default \"div\". */\n as?: \"div\" | \"main\" | \"section\" | \"article\";\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Change the widths through the --cy-container-* tokens. */\n style?: CSSProperties;\n /** The page content. */\n children?: ReactNode;\n /** Set on the root element, for tests. */\n \"data-testid\"?: string;\n}\n\n/** The page column: centres its content, caps its width and adds side gutters, so every page lines up. */\nexport const Container = forwardRef<HTMLElement, ContainerProps>(function Container(\n { size = \"lg\", padding, paddingBlock, center = true, as = \"div\", className, style, children, ...rest },\n ref,\n) {\n const Tag = as as ElementType;\n const vars: Record<string, string> = {};\n if (padding) vars[\"--_pad-inline\"] = space(padding);\n if (paddingBlock) vars[\"--_pad-block\"] = space(paddingBlock);\n return (\n <Tag\n ref={ref}\n {...rest}\n className={`cy-container${className ? ` ${className}` : \"\"}`}\n data-size={size}\n data-center={center ? \"\" : undefined}\n style={{ ...vars, ...style } as CSSProperties}\n >\n {children}\n </Tag>\n );\n});\n"],"mappings":";;;;AA+CA,IAAaG,IAAYF,EAAwC,SAC/D,EAAE,MAAAG,IAAO,MAAM,SAAAC,GAAS,cAAAC,GAAc,QAAAC,IAAS,IAAM,IAAAC,IAAK,OAAO,WAAAC,GAAW,OAAAC,GAAO,UAAAC,GAAU,GAAGC,EAAA,GAChGC,GACA;AACA,QAAMC,IAAMN,GACNO,IAA+B,CAAC;AACtC,SAAIV,MAASU,EAAK,eAAA,IAAmBf,EAAMK,CAAO,IAC9CC,MAAcS,EAAK,cAAA,IAAkBf,EAAMM,CAAY,IAEzD,gBAAAJ,EAACY,GAAD;AAAA,IACO,KAAAD;AAAA,IACL,GAAID;AAAA,IACJ,WAAW,eAAeH,IAAY,IAAIA,CAAA,KAAc,EAAA;AAAA,IACxD,aAAWL;AAAA,IACX,eAAaG,IAAS,KAAK;AAAA,IAC3B,OAAO;AAAA,MAAE,GAAGQ;AAAA,MAAM,GAAGL;AAAA,IAAM;AAAA,IAE1B,UAAAC;AAAA,EACE,CAAA;AAET,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Container, type ContainerProps, type ContainerTokens } from "./Container.js";
|
|
@@ -2,13 +2,21 @@ import { type CSSProperties, type KeyboardEvent, type MouseEvent, type PointerEv
|
|
|
2
2
|
import { type MenuEntry } from "../Menu/Menu.js";
|
|
3
3
|
/** Spread onto the one element that opens the menu (a row, a card, a canvas). */
|
|
4
4
|
export interface ContextMenuTargetProps {
|
|
5
|
+
/** Spread onto the target: focus returns to it when the menu closes. */
|
|
5
6
|
ref: Ref<HTMLElement>;
|
|
7
|
+
/** Spread onto the target: opens the menu on right-click, in place of the browser's own menu. */
|
|
6
8
|
onContextMenu: (event: MouseEvent<HTMLElement>) => void;
|
|
9
|
+
/** Spread onto the target: opens the menu on Shift+F10 or the context menu key while the target has focus. */
|
|
7
10
|
onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
|
|
11
|
+
/** Spread onto the target: starts the long press that opens the menu on touch screens. */
|
|
8
12
|
onPointerDown: (event: PointerEvent<HTMLElement>) => void;
|
|
13
|
+
/** Spread onto the target: cancels the long press when the finger moves (a scroll). */
|
|
9
14
|
onPointerMove: (event: PointerEvent<HTMLElement>) => void;
|
|
15
|
+
/** Spread onto the target: cancels the long press when the finger lifts early. */
|
|
10
16
|
onPointerUp: () => void;
|
|
17
|
+
/** Spread onto the target: cancels the long press when the browser takes over the touch. */
|
|
11
18
|
onPointerCancel: () => void;
|
|
19
|
+
/** Spread onto the target: tells assistive tech that Shift+F10 opens the menu. */
|
|
12
20
|
"aria-keyshortcuts": "Shift+F10";
|
|
13
21
|
}
|
|
14
22
|
export interface ContextMenuProps {
|
|
@@ -16,12 +24,15 @@ export interface ContextMenuProps {
|
|
|
16
24
|
children: (props: ContextMenuTargetProps) => ReactNode;
|
|
17
25
|
/** Accessible name of the menu. */
|
|
18
26
|
label: string;
|
|
27
|
+
/** The commands, as in `Menu`: items, or sections of items with a group name. */
|
|
19
28
|
items: MenuEntry[];
|
|
29
|
+
/** Called when an item is chosen, with its `value`. */
|
|
20
30
|
onSelect: (value: string) => void;
|
|
21
31
|
/** Called when the menu opens or closes, e.g. to highlight the row it belongs to. */
|
|
22
32
|
onOpenChange?: ((open: boolean) => void) | undefined;
|
|
23
33
|
/** The browser's own menu shows instead. */
|
|
24
34
|
disabled?: boolean;
|
|
35
|
+
/** Added to the menu panel, for layout. */
|
|
25
36
|
className?: string;
|
|
26
37
|
/** Layout only, applied to the panel. */
|
|
27
38
|
style?: CSSProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","names":["_Fragment","MenuPanel","useCallback","useEffect","useId","useRef","useState","Fragment$1","jsx","jsxs","LONG_PRESS","SLOP","point","x","y","ContextMenu","children","label","items","onSelect","onOpenChange","disabled","className","style","id","open","setOpen","target","anchor","press","changed","show","at","close","first","cancelPress","event","fromKeyboard","p"],"sources":["../../../src/components/ContextMenu/ContextMenu.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type MouseEvent,\n type PointerEvent,\n type ReactNode,\n type Ref,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\";\nimport type { VirtualAnchor } from \"../../overlay/use-anchored-position.js\";\nimport { type MenuEntry, MenuPanel } from \"../Menu/Menu.js\";\n\n/** Spread onto the one element that opens the menu (a row, a card, a canvas). */\nexport interface ContextMenuTargetProps {\n ref: Ref<HTMLElement>;\n onContextMenu: (event: MouseEvent<HTMLElement>) => void;\n onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n onPointerDown: (event: PointerEvent<HTMLElement>) => void;\n onPointerMove: (event: PointerEvent<HTMLElement>) => void;\n onPointerUp: () => void;\n onPointerCancel: () => void;\n \"aria-keyshortcuts\": \"Shift+F10\";\n}\n\nexport interface ContextMenuProps {\n /** Render the target: `(props) => <div {...props} tabIndex={0}>…</div>`. Make it focusable for keyboard users. */\n children: (props: ContextMenuTargetProps) => ReactNode;\n /** Accessible name of the menu. */\n label: string;\n items: MenuEntry[];\n onSelect: (value: string) => void;\n /** Called when the menu opens or closes, e.g. to highlight the row it belongs to. */\n onOpenChange?: ((open: boolean) => void) | undefined;\n /** The browser's own menu shows instead. */\n disabled?: boolean;\n className?: string;\n /** Layout only, applied to the panel. */\n style?: CSSProperties;\n}\n\n/** How long a touch must stay down to open the menu (iOS fires no contextmenu event). */\nconst LONG_PRESS = 500;\n/** How far a touch may drift before it counts as a scroll instead of a long press. */\nconst SLOP = 10;\n\nconst point = (x: number, y: number): VirtualAnchor => ({\n getBoundingClientRect: () => new DOMRect(x, y, 0, 0),\n});\n\n/**\n * A menu of commands for one thing, opened where the person points: right-click, a long press on touch screens,\n * or Shift+F10 / the context menu key on the focused target. The menu itself behaves like `Menu`.\n */\nexport function ContextMenu({\n children,\n label,\n items,\n onSelect,\n onOpenChange,\n disabled = false,\n className,\n style,\n}: ContextMenuProps) {\n const id = useId();\n const [open, setOpen] = useState(false);\n const target = useRef<HTMLElement>(null);\n const anchor = useRef<HTMLElement | VirtualAnchor | null>(null);\n const press = useRef<{ x: number; y: number; timer: ReturnType<typeof setTimeout> } | null>(null);\n const changed = useRef(onOpenChange);\n changed.current = onOpenChange;\n\n const show = useCallback((at: HTMLElement | VirtualAnchor) => {\n anchor.current = at;\n setOpen(true);\n }, []);\n const close = useCallback(() => setOpen(false), []);\n const first = useRef(true);\n useEffect(() => {\n if (first.current) {\n first.current = false;\n return;\n }\n changed.current?.(open);\n }, [open]);\n\n const cancelPress = () => {\n if (press.current) clearTimeout(press.current.timer);\n press.current = null;\n };\n useEffect(() => cancelPress, []);\n\n return (\n <>\n {children({\n ref: target,\n \"aria-keyshortcuts\": \"Shift+F10\",\n onContextMenu: (event) => {\n if (disabled) return;\n event.preventDefault();\n cancelPress();\n // A keyboard-made contextmenu event has no pointer position: place the menu at the target instead.\n const fromKeyboard = event.clientX === 0 && event.clientY === 0;\n show(fromKeyboard ? event.currentTarget : point(event.clientX, event.clientY));\n },\n onKeyDown: (event) => {\n if (disabled || event.target !== event.currentTarget) return;\n if (event.key === \"ContextMenu\" || (event.key === \"F10\" && event.shiftKey)) {\n event.preventDefault();\n show(event.currentTarget);\n }\n },\n onPointerDown: (event) => {\n if (disabled || event.pointerType !== \"touch\") return;\n const { clientX: x, clientY: y } = event;\n cancelPress();\n press.current = { x, y, timer: setTimeout(() => show(point(x, y)), LONG_PRESS) };\n },\n onPointerMove: (event) => {\n const p = press.current;\n if (p && Math.hypot(event.clientX - p.x, event.clientY - p.y) > SLOP) cancelPress();\n },\n onPointerUp: cancelPress,\n onPointerCancel: cancelPress,\n })}\n <MenuPanel\n id={id}\n label={label}\n items={items}\n onSelect={onSelect}\n open={open}\n onClose={close}\n focusOn=\"first\"\n anchor={anchor}\n placement=\"bottom\"\n offset={2}\n inside={[]}\n returnFocus={target}\n className={className}\n style={style}\n />\n </>\n );\n}\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"ContextMenu.js","names":["_Fragment","MenuPanel","useCallback","useEffect","useId","useRef","useState","Fragment$1","jsx","jsxs","LONG_PRESS","SLOP","point","x","y","ContextMenu","children","label","items","onSelect","onOpenChange","disabled","className","style","id","open","setOpen","target","anchor","press","changed","show","at","close","first","cancelPress","event","fromKeyboard","p"],"sources":["../../../src/components/ContextMenu/ContextMenu.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type MouseEvent,\n type PointerEvent,\n type ReactNode,\n type Ref,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\";\nimport type { VirtualAnchor } from \"../../overlay/use-anchored-position.js\";\nimport { type MenuEntry, MenuPanel } from \"../Menu/Menu.js\";\n\n/** Spread onto the one element that opens the menu (a row, a card, a canvas). */\nexport interface ContextMenuTargetProps {\n /** Spread onto the target: focus returns to it when the menu closes. */\n ref: Ref<HTMLElement>;\n /** Spread onto the target: opens the menu on right-click, in place of the browser's own menu. */\n onContextMenu: (event: MouseEvent<HTMLElement>) => void;\n /** Spread onto the target: opens the menu on Shift+F10 or the context menu key while the target has focus. */\n onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n /** Spread onto the target: starts the long press that opens the menu on touch screens. */\n onPointerDown: (event: PointerEvent<HTMLElement>) => void;\n /** Spread onto the target: cancels the long press when the finger moves (a scroll). */\n onPointerMove: (event: PointerEvent<HTMLElement>) => void;\n /** Spread onto the target: cancels the long press when the finger lifts early. */\n onPointerUp: () => void;\n /** Spread onto the target: cancels the long press when the browser takes over the touch. */\n onPointerCancel: () => void;\n /** Spread onto the target: tells assistive tech that Shift+F10 opens the menu. */\n \"aria-keyshortcuts\": \"Shift+F10\";\n}\n\nexport interface ContextMenuProps {\n /** Render the target: `(props) => <div {...props} tabIndex={0}>…</div>`. Make it focusable for keyboard users. */\n children: (props: ContextMenuTargetProps) => ReactNode;\n /** Accessible name of the menu. */\n label: string;\n /** The commands, as in `Menu`: items, or sections of items with a group name. */\n items: MenuEntry[];\n /** Called when an item is chosen, with its `value`. */\n onSelect: (value: string) => void;\n /** Called when the menu opens or closes, e.g. to highlight the row it belongs to. */\n onOpenChange?: ((open: boolean) => void) | undefined;\n /** The browser's own menu shows instead. */\n disabled?: boolean;\n /** Added to the menu panel, for layout. */\n className?: string;\n /** Layout only, applied to the panel. */\n style?: CSSProperties;\n}\n\n/** How long a touch must stay down to open the menu (iOS fires no contextmenu event). */\nconst LONG_PRESS = 500;\n/** How far a touch may drift before it counts as a scroll instead of a long press. */\nconst SLOP = 10;\n\nconst point = (x: number, y: number): VirtualAnchor => ({\n getBoundingClientRect: () => new DOMRect(x, y, 0, 0),\n});\n\n/**\n * A menu of commands for one thing, opened where the person points: right-click, a long press on touch screens,\n * or Shift+F10 / the context menu key on the focused target. The menu itself behaves like `Menu`.\n */\nexport function ContextMenu({\n children,\n label,\n items,\n onSelect,\n onOpenChange,\n disabled = false,\n className,\n style,\n}: ContextMenuProps) {\n const id = useId();\n const [open, setOpen] = useState(false);\n const target = useRef<HTMLElement>(null);\n const anchor = useRef<HTMLElement | VirtualAnchor | null>(null);\n const press = useRef<{ x: number; y: number; timer: ReturnType<typeof setTimeout> } | null>(null);\n const changed = useRef(onOpenChange);\n changed.current = onOpenChange;\n\n const show = useCallback((at: HTMLElement | VirtualAnchor) => {\n anchor.current = at;\n setOpen(true);\n }, []);\n const close = useCallback(() => setOpen(false), []);\n const first = useRef(true);\n useEffect(() => {\n if (first.current) {\n first.current = false;\n return;\n }\n changed.current?.(open);\n }, [open]);\n\n const cancelPress = () => {\n if (press.current) clearTimeout(press.current.timer);\n press.current = null;\n };\n useEffect(() => cancelPress, []);\n\n return (\n <>\n {children({\n ref: target,\n \"aria-keyshortcuts\": \"Shift+F10\",\n onContextMenu: (event) => {\n if (disabled) return;\n event.preventDefault();\n cancelPress();\n // A keyboard-made contextmenu event has no pointer position: place the menu at the target instead.\n const fromKeyboard = event.clientX === 0 && event.clientY === 0;\n show(fromKeyboard ? event.currentTarget : point(event.clientX, event.clientY));\n },\n onKeyDown: (event) => {\n if (disabled || event.target !== event.currentTarget) return;\n if (event.key === \"ContextMenu\" || (event.key === \"F10\" && event.shiftKey)) {\n event.preventDefault();\n show(event.currentTarget);\n }\n },\n onPointerDown: (event) => {\n if (disabled || event.pointerType !== \"touch\") return;\n const { clientX: x, clientY: y } = event;\n cancelPress();\n press.current = { x, y, timer: setTimeout(() => show(point(x, y)), LONG_PRESS) };\n },\n onPointerMove: (event) => {\n const p = press.current;\n if (p && Math.hypot(event.clientX - p.x, event.clientY - p.y) > SLOP) cancelPress();\n },\n onPointerUp: cancelPress,\n onPointerCancel: cancelPress,\n })}\n <MenuPanel\n id={id}\n label={label}\n items={items}\n onSelect={onSelect}\n open={open}\n onClose={close}\n focusOn=\"first\"\n anchor={anchor}\n placement=\"bottom\"\n offset={2}\n inside={[]}\n returnFocus={target}\n className={className}\n style={style}\n />\n </>\n );\n}\n"],"mappings":";;;;AAwDA,IAAMU,IAAa,KAEbC,IAAO,IAEPC,IAAA,CAASC,GAAWC,OAA8B,EACtD,uBAAA,MAA6B,IAAI,QAAQD,GAAGC,GAAG,GAAG,CAAC,EACrD;AAMA,SAAgBC,EAAY,EAC1B,UAAAC,GACA,OAAAC,GACA,OAAAC,GACA,UAAAC,GACA,cAAAC,GACA,UAAAC,IAAW,IACX,WAAAC,GACA,OAAAC,EAAA,GACmB;AACnB,QAAMC,IAAKpB,EAAM,GACX,CAACqB,GAAMC,CAAA,IAAWpB,EAAS,EAAK,GAChCqB,IAAStB,EAAoB,IAAI,GACjCuB,IAASvB,EAA2C,IAAI,GACxDwB,IAAQxB,EAA8E,IAAI,GAC1FyB,IAAUzB,EAAOe,CAAY;AACnC,EAAAU,EAAQ,UAAUV;AAElB,QAAMW,IAAO7B,EAAA,CAAa8B,MAAoC;AAC5D,IAAAJ,EAAO,UAAUI,GACjBN,EAAQ,EAAI;AAAA,EACd,GAAG,CAAC,CAAC,GACCO,IAAQ/B,EAAA,MAAkBwB,EAAQ,EAAK,GAAG,CAAC,CAAC,GA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AAChB,MAAIS,KAAK,KAAK,MAAMF,EAAM,UAAUE,EAAE,GAAGF,EAAM,UAAUE,EAAE,CAAC,IAAI3B,KAAMwB,EAAY;AAAA,IACpF;AAAA,IACA,aAAaA;AAAA,IACb,iBAAiBA;AAAA,EACnB,CAAC,GACD,gBAAA3B,EAACP,GAAD;AAAA,IACM,IAAAuB;AAAA,IACG,OAAAP;AAAA,IACA,OAAAC;AAAA,IACG,UAAAC;AAAA,IACJ,MAAAM;AAAA,IACN,SAASQ;AAAA,IACT,SAAQ;AAAA,IACA,QAAAL;AAAA,IACR,WAAU;AAAA,IACV,QAAQ;AAAA,IACR,QAAQ,CAAC;AAAA,IACT,aAAaD;AAAA,IACF,WAAAL;AAAA,IACJ,OAAAC;AAAA,EACR,CAAA,CACD,EAAA,CAAA;AAEN"}
|
|
@@ -13,6 +13,7 @@ export interface CopyButtonLabels {
|
|
|
13
13
|
export interface CopyButtonProps {
|
|
14
14
|
/** The text to copy (or a function that returns it when clicked). */
|
|
15
15
|
value: string | (() => string);
|
|
16
|
+
/** Replace the built-in English text: the button's name before copying, after a copy and after a failure. */
|
|
16
17
|
labels?: Partial<CopyButtonLabels>;
|
|
17
18
|
/** Milliseconds before the button goes back to its copy state (default 2000). */
|
|
18
19
|
timeout?: number;
|
|
@@ -21,12 +22,19 @@ export interface CopyButtonProps {
|
|
|
21
22
|
* document, `chrome.runtime` messaging) or tests. A rejection or throw shows the failed state.
|
|
22
23
|
*/
|
|
23
24
|
copy?: (text: string) => Promise<void> | void;
|
|
25
|
+
/** Called after a successful copy, with the text that was copied. */
|
|
24
26
|
onCopy?: (text: string) => void;
|
|
27
|
+
/** Called when copying fails, with the error. */
|
|
25
28
|
onError?: (error: unknown) => void;
|
|
29
|
+
/** Size of the button. Default "md". */
|
|
26
30
|
size?: Size;
|
|
31
|
+
/** Fill style of the button. Default "ghost". */
|
|
27
32
|
variant?: ButtonVariant;
|
|
33
|
+
/** Where the label tooltip appears. Default "top". */
|
|
28
34
|
tooltipPlacement?: Placement;
|
|
35
|
+
/** The button cannot be pressed. */
|
|
29
36
|
disabled?: boolean;
|
|
37
|
+
/** Added to the root element, for layout. */
|
|
30
38
|
className?: string;
|
|
31
39
|
/** Layout only. */
|
|
32
40
|
style?: CSSProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CopyButton.js","names":["copy","copyIcon","IconButton","check","copy","xCircle","useEffect","useRef","useState","jsx","jsxs","DEFAULT_LABELS","writeClipboard","text","CopyButton","value","labels","timeout","copy$1","onCopy","onError","size","variant","tooltipPlacement","disabled","className","style","state","setState","message","setMessage","timer","settle","next","run","content","resolve","error","label"],"sources":["../../../src/components/CopyButton/CopyButton.tsx"],"sourcesContent":["import { type CSSProperties, useEffect, useRef, useState } from \"react\";\nimport { check } from \"../../icons/check.js\";\nimport { copy as copyIcon } from \"../../icons/copy.js\";\nimport { xCircle } from \"../../icons/x-circle.js\";\nimport type { Placement } from \"../../overlay/position.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport type { ButtonVariant } from \"../Button/Button.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\n\nexport interface CopyButtonLabels {\n /** Name and tooltip before copying. */\n copy: string;\n /** Name, tooltip and announcement after a successful copy. */\n copied: string;\n /** Name, tooltip and announcement when the clipboard refused. */\n failed: string;\n}\n\nexport interface CopyButtonProps {\n /** The text to copy (or a function that returns it when clicked). */\n value: string | (() => string);\n labels?: Partial<CopyButtonLabels>;\n /** Milliseconds before the button goes back to its copy state (default 2000). */\n timeout?: number;\n /**\n * Writes to the clipboard. Defaults to `navigator.clipboard.writeText`; pass your own for extensions (an offscreen\n * document, `chrome.runtime` messaging) or tests. A rejection or throw shows the failed state.\n */\n copy?: (text: string) => Promise<void> | void;\n onCopy?: (text: string) => void;\n onError?: (error: unknown) => void;\n size?: Size;\n variant?: ButtonVariant;\n tooltipPlacement?: Placement;\n disabled?: boolean;\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n}\n\ntype State = \"idle\" | \"copied\" | \"failed\";\nconst DEFAULT_LABELS: CopyButtonLabels = { copy: \"Copy\", copied: \"Copied\", failed: \"Could not copy\" };\n\nconst writeClipboard = (text: string) => {\n if (!navigator.clipboard?.writeText) throw new Error(\"Clipboard unavailable\");\n return navigator.clipboard.writeText(text);\n};\n\n/** An IconButton that copies a value, swaps to a check (or an error) and announces the result. Never throws. */\nexport function CopyButton({\n value,\n labels,\n timeout = 2000,\n copy = writeClipboard,\n onCopy,\n onError,\n size = \"md\",\n variant = \"ghost\",\n tooltipPlacement,\n disabled,\n className,\n style,\n}: CopyButtonProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const [state, setState] = useState<State>(\"idle\");\n const [message, setMessage] = useState(\"\");\n const timer = useRef<ReturnType<typeof setTimeout>>(undefined);\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const settle = (next: State) => {\n setState(next);\n setMessage(next === \"copied\" ? text.copied : text.failed);\n clearTimeout(timer.current);\n timer.current = setTimeout(() => {\n setState(\"idle\");\n setMessage(\"\");\n }, timeout);\n };\n\n const run = async () => {\n // Clear the live region first, so copying again while it still says \"Copied\" is announced again.\n setMessage(\"\");\n try {\n const content = typeof value === \"function\" ? value() : value;\n await copy(content);\n await new Promise((resolve) => setTimeout(resolve));\n settle(\"copied\");\n onCopy?.(content);\n } catch (error) {\n await new Promise((resolve) => setTimeout(resolve));\n settle(\"failed\");\n onError?.(error);\n }\n };\n\n const label = state === \"copied\" ? text.copied : state === \"failed\" ? text.failed : text.copy;\n return (\n <span\n className={className ? `cy-copy-button ${className}` : \"cy-copy-button\"}\n data-state={state}\n style={style}\n >\n <IconButton\n icon={state === \"copied\" ? check : state === \"failed\" ? xCircle : copyIcon}\n label={label}\n size={size}\n variant={variant}\n disabled={disabled}\n onClick={() => void run()}\n {...(tooltipPlacement ? { tooltipPlacement } : {})}\n />\n <span className=\"cy-copy-button-status cy-reset\" role=\"status\">\n {message}\n </span>\n </span>\n );\n}\n"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"CopyButton.js","names":["copy","copyIcon","IconButton","check","copy","xCircle","useEffect","useRef","useState","jsx","jsxs","DEFAULT_LABELS","writeClipboard","text","CopyButton","value","labels","timeout","copy$1","onCopy","onError","size","variant","tooltipPlacement","disabled","className","style","state","setState","message","setMessage","timer","settle","next","run","content","resolve","error","label"],"sources":["../../../src/components/CopyButton/CopyButton.tsx"],"sourcesContent":["import { type CSSProperties, useEffect, useRef, useState } from \"react\";\nimport { check } from \"../../icons/check.js\";\nimport { copy as copyIcon } from \"../../icons/copy.js\";\nimport { xCircle } from \"../../icons/x-circle.js\";\nimport type { Placement } from \"../../overlay/position.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport type { ButtonVariant } from \"../Button/Button.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\n\nexport interface CopyButtonLabels {\n /** Name and tooltip before copying. */\n copy: string;\n /** Name, tooltip and announcement after a successful copy. */\n copied: string;\n /** Name, tooltip and announcement when the clipboard refused. */\n failed: string;\n}\n\nexport interface CopyButtonProps {\n /** The text to copy (or a function that returns it when clicked). */\n value: string | (() => string);\n /** Replace the built-in English text: the button's name before copying, after a copy and after a failure. */\n labels?: Partial<CopyButtonLabels>;\n /** Milliseconds before the button goes back to its copy state (default 2000). */\n timeout?: number;\n /**\n * Writes to the clipboard. Defaults to `navigator.clipboard.writeText`; pass your own for extensions (an offscreen\n * document, `chrome.runtime` messaging) or tests. A rejection or throw shows the failed state.\n */\n copy?: (text: string) => Promise<void> | void;\n /** Called after a successful copy, with the text that was copied. */\n onCopy?: (text: string) => void;\n /** Called when copying fails, with the error. */\n onError?: (error: unknown) => void;\n /** Size of the button. Default \"md\". */\n size?: Size;\n /** Fill style of the button. Default \"ghost\". */\n variant?: ButtonVariant;\n /** Where the label tooltip appears. Default \"top\". */\n tooltipPlacement?: Placement;\n /** The button cannot be pressed. */\n disabled?: boolean;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n}\n\ntype State = \"idle\" | \"copied\" | \"failed\";\nconst DEFAULT_LABELS: CopyButtonLabels = { copy: \"Copy\", copied: \"Copied\", failed: \"Could not copy\" };\n\nconst writeClipboard = (text: string) => {\n if (!navigator.clipboard?.writeText) throw new Error(\"Clipboard unavailable\");\n return navigator.clipboard.writeText(text);\n};\n\n/** An IconButton that copies a value, swaps to a check (or an error) and announces the result. Never throws. */\nexport function CopyButton({\n value,\n labels,\n timeout = 2000,\n copy = writeClipboard,\n onCopy,\n onError,\n size = \"md\",\n variant = \"ghost\",\n tooltipPlacement,\n disabled,\n className,\n style,\n}: CopyButtonProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const [state, setState] = useState<State>(\"idle\");\n const [message, setMessage] = useState(\"\");\n const timer = useRef<ReturnType<typeof setTimeout>>(undefined);\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const settle = (next: State) => {\n setState(next);\n setMessage(next === \"copied\" ? text.copied : text.failed);\n clearTimeout(timer.current);\n timer.current = setTimeout(() => {\n setState(\"idle\");\n setMessage(\"\");\n }, timeout);\n };\n\n const run = async () => {\n // Clear the live region first, so copying again while it still says \"Copied\" is announced again.\n setMessage(\"\");\n try {\n const content = typeof value === \"function\" ? value() : value;\n await copy(content);\n await new Promise((resolve) => setTimeout(resolve));\n settle(\"copied\");\n onCopy?.(content);\n } catch (error) {\n await new Promise((resolve) => setTimeout(resolve));\n settle(\"failed\");\n onError?.(error);\n }\n };\n\n const label = state === \"copied\" ? text.copied : state === \"failed\" ? text.failed : text.copy;\n return (\n <span\n className={className ? `cy-copy-button ${className}` : \"cy-copy-button\"}\n data-state={state}\n style={style}\n >\n <IconButton\n icon={state === \"copied\" ? check : state === \"failed\" ? xCircle : copyIcon}\n label={label}\n size={size}\n variant={variant}\n disabled={disabled}\n onClick={() => void run()}\n {...(tooltipPlacement ? { tooltipPlacement } : {})}\n />\n <span className=\"cy-copy-button-status cy-reset\" role=\"status\">\n {message}\n </span>\n </span>\n );\n}\n"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AI,QAAA,CAASD,MAAY,WAAWA,CAAO,CAAC,GAClDJ,EAAO,QAAQ,GACfZ,IAAUiB,CAAK;AAAA,IACjB;AAAA,EACF,GAEMC,IAAQX,MAAU,WAAWd,EAAK,SAASc,MAAU,WAAWd,EAAK,SAASA,EAAK;AACzF,SACE,gBAAAH,EAAC,QAAD;AAAA,IACE,WAAWe,IAAY,kBAAkBA,CAAA,KAAc;AAAA,IACvD,cAAYE;AAAA,IACL,OAAAD;AAAA,IAHT,UAAA,CAKE,gBAAAjB,EAACP,GAAD;AAAA,MACE,MAAMyB,MAAU,WAAWxB,IAAQwB,MAAU,WAAWtB,IAAUJ;AAAAA,MAC3D,OAAAqC;AAAA,MACD,MAAAjB;AAAA,MACG,SAAAC;AAAA,MACC,UAAAE;AAAA,MACV,SAAA,MAAA;AAAe,QAAKU,EAAI;AAAA;AAAA,MACxB,GAAKX,IAAmB,EAAE,kBAAAA,EAAiB,IAAI,CAAC;AAAA,IACjD,CAAA,GACD,gBAAAd,EAAC,QAAD;AAAA,MAAM,WAAU;AAAA,MAAiC,MAAK;AAAA,MACnD,UAAAoB;AAAA,IACG,CAAA,CACF;AAAA,E;AAEV"}
|
|
@@ -12,30 +12,47 @@ export interface DateFieldLabels {
|
|
|
12
12
|
next: string;
|
|
13
13
|
}
|
|
14
14
|
export interface DateFieldProps {
|
|
15
|
+
/** Visible label; it names the field. */
|
|
15
16
|
label: ReactNode;
|
|
17
|
+
/** Visually hide the label (it still names the field). Prefer visible labels. */
|
|
16
18
|
labelHidden?: boolean;
|
|
19
|
+
/** Help text shown below the field. */
|
|
17
20
|
description?: ReactNode;
|
|
18
21
|
/** Your own error; it replaces the field's own messages. */
|
|
19
22
|
error?: ReactNode;
|
|
20
23
|
/** `YYYY-MM-DD`, or null when empty. */
|
|
21
24
|
value?: string | null;
|
|
25
|
+
/** Starting date when uncontrolled, as `YYYY-MM-DD`. */
|
|
22
26
|
defaultValue?: string | null;
|
|
23
27
|
/** A valid, available date (or null when cleared), when typing is finished or a day is picked. */
|
|
24
28
|
onChange?: (date: string | null) => void;
|
|
29
|
+
/** Earliest date that can be typed or picked, as `YYYY-MM-DD`. */
|
|
25
30
|
min?: string | undefined;
|
|
31
|
+
/** Latest date that can be typed or picked, as `YYYY-MM-DD`. */
|
|
26
32
|
max?: string | undefined;
|
|
33
|
+
/** Return true for dates that cannot be chosen (fully booked, weekends). */
|
|
27
34
|
isDateDisabled?: ((date: string) => boolean) | undefined;
|
|
28
35
|
/** The calendar's locale and first day of the week. */
|
|
29
36
|
locale?: string | undefined;
|
|
37
|
+
/** 0 Sunday to 6 Saturday. Default: the locale's first day, else Monday. */
|
|
30
38
|
weekStartsOn?: number | undefined;
|
|
39
|
+
/** What the calendar counts as today, as `YYYY-MM-DD`. Default: the device's date. */
|
|
31
40
|
today?: string | undefined;
|
|
41
|
+
/** Name the field's text is submitted under in a form. */
|
|
32
42
|
name?: string | undefined;
|
|
43
|
+
/** Id of the form it belongs to, when it is not inside that form. */
|
|
33
44
|
form?: string | undefined;
|
|
45
|
+
/** Marks the field as required for form validation. */
|
|
34
46
|
required?: boolean | undefined;
|
|
47
|
+
/** Turns off the field and the calendar button. */
|
|
35
48
|
disabled?: boolean | undefined;
|
|
49
|
+
/** The date can be read but not changed; the calendar button is hidden. */
|
|
36
50
|
readOnly?: boolean | undefined;
|
|
51
|
+
/** Size of the field. Default "md". */
|
|
37
52
|
size?: Size;
|
|
53
|
+
/** Replace the built-in English text: the calendar button, the two error messages and the month buttons. */
|
|
38
54
|
labels?: Partial<DateFieldLabels>;
|
|
55
|
+
/** Added to the root element, for layout. */
|
|
39
56
|
className?: string;
|
|
40
57
|
/** Layout only. */
|
|
41
58
|
style?: CSSProperties;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useControllableState as _ } from "../../foundations/controllable.js";
|
|
3
3
|
import { IconButton as G } from "../IconButton/IconButton.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { Popover as J } from "../Popover/Popover.js";
|
|
5
|
+
import { addDays as Q, addMonths as V, isISODate as b } from "../Calendar/dates.js";
|
|
6
|
+
import { Calendar as W } from "../Calendar/Calendar.js";
|
|
7
7
|
import { TextField as X } from "../TextField/TextField.js";
|
|
8
8
|
import { calendar as Z } from "../../icons/calendar.js";
|
|
9
9
|
import { useEffect as H, useId as ee, useRef as oe, useState as D } from "react";
|
|
@@ -39,7 +39,7 @@ function de({ label: c, labelHidden: t, description: C, error: Y, value: I, defa
|
|
|
39
39
|
const h = o === null ? r : b(u(o)) ? u(o) : null;
|
|
40
40
|
if (!h) return;
|
|
41
41
|
e.preventDefault();
|
|
42
|
-
const B = e.key === "ArrowUp" ? 1 : -1, y = e.shiftKey ?
|
|
42
|
+
const B = e.key === "ArrowUp" ? 1 : -1, y = e.shiftKey ? V(h, B) : Q(h, B);
|
|
43
43
|
l !== void 0 && y < l || a !== void 0 && y > a || k(y);
|
|
44
44
|
};
|
|
45
45
|
return H(() => {
|
|
@@ -65,7 +65,7 @@ function de({ label: c, labelHidden: t, description: C, error: Y, value: I, defa
|
|
|
65
65
|
size: j,
|
|
66
66
|
className: S ? `cy-date-field ${S}` : "cy-date-field",
|
|
67
67
|
...$ ? { style: $ } : {},
|
|
68
|
-
addonEnd: !d && /* @__PURE__ */ s(
|
|
68
|
+
addonEnd: !d && /* @__PURE__ */ s(J, {
|
|
69
69
|
label: n.open,
|
|
70
70
|
open: v,
|
|
71
71
|
onOpenChange: M,
|
|
@@ -83,7 +83,7 @@ function de({ label: c, labelHidden: t, description: C, error: Y, value: I, defa
|
|
|
83
83
|
children: /* @__PURE__ */ s("div", {
|
|
84
84
|
id: `${m}-calendar`,
|
|
85
85
|
className: "cy-date-field-calendar",
|
|
86
|
-
children: /* @__PURE__ */ s(
|
|
86
|
+
children: /* @__PURE__ */ s(W, {
|
|
87
87
|
value: o !== null && b(u(o)) ? u(o) : r,
|
|
88
88
|
onChange: (e) => {
|
|
89
89
|
k(e), M(!1), w.current?.focus();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateField.js","names":["useControllableState","IconButton","addDays","addMonths","isISODate","Calendar","Popover","TextField","calendar","useEffect","useId","useRef","useState","jsx","DEFAULT_LABELS","normalise","text","m","DateField","label","labelHidden","description","error","value","defaultValue","onChange","min","max","isDateDisabled","locale","weekStartsOn","today","name","form","required","disabled","readOnly","size","labels","className","style","id","current","setCurrent","draft","setDraft","problem","setProblem","open","setOpen","input","available","date","commit","typed","choose","onKeyDown","event","from","by","next","props"],"sources":["../../../src/components/DateField/DateField.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactNode,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { calendar } from \"../../icons/calendar.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Calendar } from \"../Calendar/Calendar.js\";\nimport { addDays, addMonths, isISODate } from \"../Calendar/dates.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Popover } from \"../Popover/Popover.js\";\nimport { TextField } from \"../TextField/TextField.js\";\n\nexport interface DateFieldLabels {\n /** The button that opens the calendar. Default \"Choose a date\". */\n open: string;\n /** Shown when the text is not a date. Default \"Enter a date as YYYY-MM-DD\". */\n invalid: string;\n /** Shown when the date is outside `min` and `max`, or not available. Default \"This date is not available\". */\n unavailable: string;\n /** The calendar's month buttons. */\n previous: string;\n next: string;\n}\n\nexport interface DateFieldProps {\n label: ReactNode;\n labelHidden?: boolean;\n description?: ReactNode;\n /** Your own error; it replaces the field's own messages. */\n error?: ReactNode;\n /** `YYYY-MM-DD`, or null when empty. */\n value?: string | null;\n defaultValue?: string | null;\n /** A valid, available date (or null when cleared), when typing is finished or a day is picked. */\n onChange?: (date: string | null) => void;\n min?: string | undefined;\n max?: string | undefined;\n isDateDisabled?: ((date: string) => boolean) | undefined;\n /** The calendar's locale and first day of the week. */\n locale?: string | undefined;\n weekStartsOn?: number | undefined;\n today?: string | undefined;\n name?: string | undefined;\n form?: string | undefined;\n required?: boolean | undefined;\n disabled?: boolean | undefined;\n readOnly?: boolean | undefined;\n size?: Size;\n labels?: Partial<DateFieldLabels>;\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: DateFieldLabels = {\n open: \"Choose a date\",\n invalid: \"Enter a date as YYYY-MM-DD\",\n unavailable: \"This date is not available\",\n previous: \"Previous month\",\n next: \"Next month\",\n};\n\n/** `2026-1-5`, `2026/01/05` and `2026.1.5` all read as `2026-01-05`; anything else is left as it was typed. */\nconst normalise = (text: string) => {\n const m = /^\\s*(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})\\s*$/.exec(text);\n return m\n ? `${m[1]}-${(m[2] as string).padStart(2, \"0\")}-${(m[3] as string).padStart(2, \"0\")}`\n : text.trim();\n};\n\n/**\n * A date in a form: type it as `YYYY-MM-DD`, step it with the arrows, or pick it from a Calendar in a popover. The\n * value is a plain date string (no time, no time zone) and is only reported once it is a real, available date.\n */\nexport function DateField({\n label,\n labelHidden,\n description,\n error,\n value,\n defaultValue = null,\n onChange,\n min,\n max,\n isDateDisabled,\n locale,\n weekStartsOn,\n today,\n name,\n form,\n required,\n disabled = false,\n readOnly = false,\n size = \"md\",\n labels,\n className,\n style,\n}: DateFieldProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const [current, setCurrent] = useControllableState<string | null>(value, defaultValue, onChange);\n const [draft, setDraft] = useState<string | null>(null);\n const [problem, setProblem] = useState<string | null>(null);\n const [open, setOpen] = useState(false);\n const input = useRef<HTMLInputElement>(null);\n\n const available = (date: string) =>\n !(min !== undefined && date < min) && !(max !== undefined && date > max) && !isDateDisabled?.(date);\n /** Takes what was typed: a real, available date is kept; anything else is explained and left for correcting. */\n const commit = () => {\n if (draft === null) return;\n const typed = normalise(draft);\n if (typed === \"\") {\n setDraft(null);\n setProblem(null);\n if (current !== null) setCurrent(null);\n return;\n }\n if (!isISODate(typed)) return setProblem(text.invalid);\n if (!available(typed)) return setProblem(text.unavailable);\n setDraft(null);\n setProblem(null);\n if (typed !== current) setCurrent(typed);\n };\n const choose = (date: string) => {\n setDraft(null);\n setProblem(null);\n if (date !== current) setCurrent(date);\n };\n\n // Up and Down step the date by a day (Shift: a month), skipping nothing: limits stop it.\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === \"Enter\") commit();\n if ((event.key !== \"ArrowUp\" && event.key !== \"ArrowDown\") || readOnly) return;\n const from = draft === null ? current : isISODate(normalise(draft)) ? normalise(draft) : null;\n if (!from) return;\n event.preventDefault();\n const by = event.key === \"ArrowUp\" ? 1 : -1;\n const next = event.shiftKey ? addMonths(from, by) : addDays(from, by);\n if ((min !== undefined && next < min) || (max !== undefined && next > max)) return;\n choose(next);\n };\n\n // The picker opens on the chosen day (the APG date picker), not on its first button.\n useEffect(() => {\n if (!open) return;\n document\n .getElementById(`${id}-calendar`)\n ?.querySelector<HTMLElement>('[data-date][tabindex=\"0\"]')\n ?.focus();\n }, [open, id]);\n\n return (\n <TextField\n ref={input}\n label={label}\n {...(labelHidden ? { labelHidden } : {})}\n {...(description !== undefined ? { description } : {})}\n {...((error ?? problem) != null ? { error: error ?? problem } : {})}\n value={draft ?? current ?? \"\"}\n onChange={setDraft}\n onBlur={commit}\n onKeyDown={onKeyDown}\n placeholder=\"YYYY-MM-DD\"\n inputMode=\"numeric\"\n autoComplete=\"off\"\n name={name}\n form={form}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n size={size}\n className={className ? `cy-date-field ${className}` : \"cy-date-field\"}\n {...(style ? { style } : {})}\n addonEnd={\n !readOnly && (\n <Popover\n label={text.open}\n open={open}\n onOpenChange={setOpen}\n placement=\"bottom\"\n size=\"sm\"\n trigger={(props) => (\n <IconButton\n {...props}\n icon={calendar}\n label={text.open}\n variant=\"ghost\"\n size=\"sm\"\n disabled={disabled}\n className=\"cy-date-field-open\"\n />\n )}\n >\n <div id={`${id}-calendar`} className=\"cy-date-field-calendar\">\n <Calendar\n value={draft !== null && isISODate(normalise(draft)) ? normalise(draft) : current}\n onChange={(date) => {\n choose(date);\n setOpen(false);\n input.current?.focus();\n }}\n min={min}\n max={max}\n isDateDisabled={isDateDisabled}\n locale={locale}\n weekStartsOn={weekStartsOn}\n today={today}\n size=\"sm\"\n labels={{ previous: text.previous, next: text.next }}\n />\n </div>\n </Popover>\n )\n }\n />\n );\n}\n"],"mappings":";;;;;;;;;;AA4DA,IAAMc,KAAkC;AAAA,EACtC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,UAAU;AAAA,EACV,MAAM;AACR,GAGMC,IAAA,CAAaC,MAAiB;AAClC,QAAMC,IAAI,8CAA8C,KAAKD,CAAI;AACjE,SAAOC,IACH,GAAGA,EAAE,CAAA,CAAA,IAAOA,EAAE,CAAA,EAAc,SAAS,GAAG,GAAG,CAAA,IAAMA,EAAE,CAAA,EAAc,SAAS,GAAG,GAAG,CAAA,KAChFD,EAAK,KAAK;AAChB;AAMA,SAAgBE,GAAU,EACxB,OAAAC,GACA,aAAAC,GACA,aAAAC,GACA,OAAAC,GACA,OAAAC,GACA,cAAAC,IAAe,MACf,UAAAC,GACA,KAAAC,GACA,KAAAC,GACA,gBAAAC,GACA,QAAAC,GACA,cAAAC,GACA,OAAAC,GACA,MAAAC,GACA,MAAAC,GACA,UAAAC,GACA,UAAAC,IAAW,IACX,UAAAC,IAAW,IACX,MAAAC,IAAO,MACP,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACiB;AACjB,QAAMxB,IAAO;AAAA,IAAE,GAAGF;AAAA,IAAgB,GAAGwB;AAAA,EAAO,GACtCG,IAAK/B,GAAM,GACX,CAACgC,GAASC,CAAA,IAAc3C,EAAoCuB,GAAOC,GAAcC,CAAQ,GACzF,CAACmB,GAAOC,CAAA,IAAYjC,EAAwB,IAAI,GAChD,CAACkC,GAASC,CAAA,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QAAe,WAAU;AAAA,QACnC,UAAA,gBAAA5B,EAACR,GAAD;AAAA,UACE,OAAOuC,MAAU,QAAQxC,EAAUW,EAAU6B,CAAK,CAAC,IAAI7B,EAAU6B,CAAK,IAAIF;AAAA,UAC1E,UAAA,CAAWU,MAAS;AAClB,YAAAG,EAAOH,CAAI,GACXH,EAAQ,EAAK,GACbC,EAAM,SAAS,MAAM;AAAA,UACvB;AAAA,UACK,KAAAxB;AAAA,UACA,KAAAC;AAAA,UACW,gBAAAC;AAAA,UACR,QAAAC;AAAA,UACM,cAAAC;AAAA,UACP,OAAAC;AAAA,UACP,MAAK;AAAA,UACL,QAAQ;AAAA,YAAE,UAAUf,EAAK;AAAA,YAAU,MAAMA,EAAK;AAAA,UAAK;AAAA,QACpD,CAAA;AAAA,MACE,CAAA;AAAA,IACE,CAAA;AAAA,EAGd,CAAA;AAEL"}
|
|
1
|
+
{"version":3,"file":"DateField.js","names":["useControllableState","IconButton","Popover","addDays","addMonths","isISODate","Calendar","TextField","calendar","useEffect","useId","useRef","useState","jsx","DEFAULT_LABELS","normalise","text","m","DateField","label","labelHidden","description","error","value","defaultValue","onChange","min","max","isDateDisabled","locale","weekStartsOn","today","name","form","required","disabled","readOnly","size","labels","className","style","id","current","setCurrent","draft","setDraft","problem","setProblem","open","setOpen","input","available","date","commit","typed","choose","onKeyDown","event","from","by","next","props"],"sources":["../../../src/components/DateField/DateField.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactNode,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { calendar } from \"../../icons/calendar.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Calendar } from \"../Calendar/Calendar.js\";\nimport { addDays, addMonths, isISODate } from \"../Calendar/dates.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Popover } from \"../Popover/Popover.js\";\nimport { TextField } from \"../TextField/TextField.js\";\n\nexport interface DateFieldLabels {\n /** The button that opens the calendar. Default \"Choose a date\". */\n open: string;\n /** Shown when the text is not a date. Default \"Enter a date as YYYY-MM-DD\". */\n invalid: string;\n /** Shown when the date is outside `min` and `max`, or not available. Default \"This date is not available\". */\n unavailable: string;\n /** The calendar's month buttons. */\n previous: string;\n next: string;\n}\n\nexport interface DateFieldProps {\n /** Visible label; it names the field. */\n label: ReactNode;\n /** Visually hide the label (it still names the field). Prefer visible labels. */\n labelHidden?: boolean;\n /** Help text shown below the field. */\n description?: ReactNode;\n /** Your own error; it replaces the field's own messages. */\n error?: ReactNode;\n /** `YYYY-MM-DD`, or null when empty. */\n value?: string | null;\n /** Starting date when uncontrolled, as `YYYY-MM-DD`. */\n defaultValue?: string | null;\n /** A valid, available date (or null when cleared), when typing is finished or a day is picked. */\n onChange?: (date: string | null) => void;\n /** Earliest date that can be typed or picked, as `YYYY-MM-DD`. */\n min?: string | undefined;\n /** Latest date that can be typed or picked, as `YYYY-MM-DD`. */\n max?: string | undefined;\n /** Return true for dates that cannot be chosen (fully booked, weekends). */\n isDateDisabled?: ((date: string) => boolean) | undefined;\n /** The calendar's locale and first day of the week. */\n locale?: string | undefined;\n /** 0 Sunday to 6 Saturday. Default: the locale's first day, else Monday. */\n weekStartsOn?: number | undefined;\n /** What the calendar counts as today, as `YYYY-MM-DD`. Default: the device's date. */\n today?: string | undefined;\n /** Name the field's text is submitted under in a form. */\n name?: string | undefined;\n /** Id of the form it belongs to, when it is not inside that form. */\n form?: string | undefined;\n /** Marks the field as required for form validation. */\n required?: boolean | undefined;\n /** Turns off the field and the calendar button. */\n disabled?: boolean | undefined;\n /** The date can be read but not changed; the calendar button is hidden. */\n readOnly?: boolean | undefined;\n /** Size of the field. Default \"md\". */\n size?: Size;\n /** Replace the built-in English text: the calendar button, the two error messages and the month buttons. */\n labels?: Partial<DateFieldLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: DateFieldLabels = {\n open: \"Choose a date\",\n invalid: \"Enter a date as YYYY-MM-DD\",\n unavailable: \"This date is not available\",\n previous: \"Previous month\",\n next: \"Next month\",\n};\n\n/** `2026-1-5`, `2026/01/05` and `2026.1.5` all read as `2026-01-05`; anything else is left as it was typed. */\nconst normalise = (text: string) => {\n const m = /^\\s*(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})\\s*$/.exec(text);\n return m\n ? `${m[1]}-${(m[2] as string).padStart(2, \"0\")}-${(m[3] as string).padStart(2, \"0\")}`\n : text.trim();\n};\n\n/**\n * A date in a form: type it as `YYYY-MM-DD`, step it with the arrows, or pick it from a Calendar in a popover. The\n * value is a plain date string (no time, no time zone) and is only reported once it is a real, available date.\n */\nexport function DateField({\n label,\n labelHidden,\n description,\n error,\n value,\n defaultValue = null,\n onChange,\n min,\n max,\n isDateDisabled,\n locale,\n weekStartsOn,\n today,\n name,\n form,\n required,\n disabled = false,\n readOnly = false,\n size = \"md\",\n labels,\n className,\n style,\n}: DateFieldProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const [current, setCurrent] = useControllableState<string | null>(value, defaultValue, onChange);\n const [draft, setDraft] = useState<string | null>(null);\n const [problem, setProblem] = useState<string | null>(null);\n const [open, setOpen] = useState(false);\n const input = useRef<HTMLInputElement>(null);\n\n const available = (date: string) =>\n !(min !== undefined && date < min) && !(max !== undefined && date > max) && !isDateDisabled?.(date);\n /** Takes what was typed: a real, available date is kept; anything else is explained and left for correcting. */\n const commit = () => {\n if (draft === null) return;\n const typed = normalise(draft);\n if (typed === \"\") {\n setDraft(null);\n setProblem(null);\n if (current !== null) setCurrent(null);\n return;\n }\n if (!isISODate(typed)) return setProblem(text.invalid);\n if (!available(typed)) return setProblem(text.unavailable);\n setDraft(null);\n setProblem(null);\n if (typed !== current) setCurrent(typed);\n };\n const choose = (date: string) => {\n setDraft(null);\n setProblem(null);\n if (date !== current) setCurrent(date);\n };\n\n // Up and Down step the date by a day (Shift: a month), skipping nothing: limits stop it.\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === \"Enter\") commit();\n if ((event.key !== \"ArrowUp\" && event.key !== \"ArrowDown\") || readOnly) return;\n const from = draft === null ? current : isISODate(normalise(draft)) ? normalise(draft) : null;\n if (!from) return;\n event.preventDefault();\n const by = event.key === \"ArrowUp\" ? 1 : -1;\n const next = event.shiftKey ? addMonths(from, by) : addDays(from, by);\n if ((min !== undefined && next < min) || (max !== undefined && next > max)) return;\n choose(next);\n };\n\n // The picker opens on the chosen day (the APG date picker), not on its first button.\n useEffect(() => {\n if (!open) return;\n document\n .getElementById(`${id}-calendar`)\n ?.querySelector<HTMLElement>('[data-date][tabindex=\"0\"]')\n ?.focus();\n }, [open, id]);\n\n return (\n <TextField\n ref={input}\n label={label}\n {...(labelHidden ? { labelHidden } : {})}\n {...(description !== undefined ? { description } : {})}\n {...((error ?? problem) != null ? { error: error ?? problem } : {})}\n value={draft ?? current ?? \"\"}\n onChange={setDraft}\n onBlur={commit}\n onKeyDown={onKeyDown}\n placeholder=\"YYYY-MM-DD\"\n inputMode=\"numeric\"\n autoComplete=\"off\"\n name={name}\n form={form}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n size={size}\n className={className ? `cy-date-field ${className}` : \"cy-date-field\"}\n {...(style ? { style } : {})}\n addonEnd={\n !readOnly && (\n <Popover\n label={text.open}\n open={open}\n onOpenChange={setOpen}\n placement=\"bottom\"\n size=\"sm\"\n trigger={(props) => (\n <IconButton\n {...props}\n icon={calendar}\n label={text.open}\n variant=\"ghost\"\n size=\"sm\"\n disabled={disabled}\n className=\"cy-date-field-open\"\n />\n )}\n >\n <div id={`${id}-calendar`} className=\"cy-date-field-calendar\">\n <Calendar\n value={draft !== null && isISODate(normalise(draft)) ? normalise(draft) : current}\n onChange={(date) => {\n choose(date);\n setOpen(false);\n input.current?.focus();\n }}\n min={min}\n max={max}\n isDateDisabled={isDateDisabled}\n locale={locale}\n weekStartsOn={weekStartsOn}\n today={today}\n size=\"sm\"\n labels={{ previous: text.previous, next: text.next }}\n />\n </div>\n </Popover>\n )\n }\n />\n );\n}\n"],"mappings":";;;;;;;;;;AA6EA,IAAMc,KAAkC;AAAA,EACtC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,UAAU;AAAA,EACV,MAAM;AACR,GAGMC,IAAA,CAAaC,MAAiB;AAClC,QAAMC,IAAI,8CAA8C,KAAKD,CAAI;AACjE,SAAOC,IACH,GAAGA,EAAE,CAAA,CAAA,IAAOA,EAAE,CAAA,EAAc,SAAS,GAAG,GAAG,CAAA,IAAMA,EAAE,CAAA,EAAc,SAAS,GAAG,GAAG,CAAA,KAChFD,EAAK,KAAK;AAChB;AAMA,SAAgBE,GAAU,EACxB,OAAAC,GACA,aAAAC,GACA,aAAAC,GACA,OAAAC,GACA,OAAAC,GACA,cAAAC,IAAe,MACf,UAAAC,GACA,KAAAC,GACA,KAAAC,GACA,gBAAAC,GACA,QAAAC,GACA,cAAAC,GACA,OAAAC,GACA,MAAAC,GACA,MAAAC,GACA,UAAAC,GACA,UAAAC,IAAW,IACX,UAAAC,IAAW,IACX,MAAAC,IAAO,MACP,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACiB;AACjB,QAAMxB,IAAO;AAAA,IAAE,GAAGF;AAAA,IAAgB,GAAGwB;AAAA,EAAO,GACtCG,IAAK/B,GAAM,GACX,CAACgC,GAASC,CAAA,IAAc3C,EAAoCuB,GAAOC,GAAcC,CAAQ,GACzF,CAACmB,GAAOC,CAAA,IAAYjC,EAAwB,IAAI,GAChD,CAACkC,GAASC,CAAA,IAAcnC,EAAwB,IAAI,GACpD,CAACoC,GAAMC,CAAA,IAAWrC,EAAS,EAAK,GAChCsC,IAAQvC,GAAyB,IAAI,GAErCwC,IAAA,CAAaC,MACjB,EAAE1B,MAAQ,UAAa0B,IAAO1B,MAAQ,EAAEC,MAAQ,UAAayB,IAAOzB,MAAQ,CAACC,IAAiBwB,CA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GACbC,EAAM,SAAS,MAAM;AAAA,UACvB;AAAA,UACK,KAAAxB;AAAA,UACA,KAAAC;AAAA,UACW,gBAAAC;AAAA,UACR,QAAAC;AAAA,UACM,cAAAC;AAAA,UACP,OAAAC;AAAA,UACP,MAAK;AAAA,UACL,QAAQ;AAAA,YAAE,UAAUf,EAAK;AAAA,YAAU,MAAMA,EAAK;AAAA,UAAK;AAAA,QACpD,CAAA;AAAA,MACE,CAAA;AAAA,IACE,CAAA;AAAA,EAGd,CAAA;AAEL"}
|
|
@@ -21,6 +21,7 @@ export interface DescriptionItem {
|
|
|
21
21
|
detail: ReactNode | ReactNode[];
|
|
22
22
|
}
|
|
23
23
|
export interface DescriptionListProps {
|
|
24
|
+
/** The terms and their details, in order. */
|
|
24
25
|
items: DescriptionItem[];
|
|
25
26
|
/**
|
|
26
27
|
* `inline`: terms beside their details. `stacked`: terms above. `auto` (default): inline when the list is at least
|
|
@@ -29,7 +30,9 @@ export interface DescriptionListProps {
|
|
|
29
30
|
layout?: "auto" | "inline" | "stacked";
|
|
30
31
|
/** Lines between rows. */
|
|
31
32
|
divided?: boolean;
|
|
33
|
+
/** Text size. Default "md". */
|
|
32
34
|
size?: Size;
|
|
35
|
+
/** Added to the root element, for layout. */
|
|
33
36
|
className?: string;
|
|
34
37
|
/** Layout only. Restyle through --cy-description-list-* tokens. */
|
|
35
38
|
style?: CSSProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DescriptionList.js","names":["jsx","jsxs","DescriptionList","items","layout","divided","size","className","style","item","i","detail","j"],"sources":["../../../src/components/DescriptionList/DescriptionList.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode } from \"react\";\nimport type { Size } from \"../../tokens/schema.js\";\n\nexport interface DescriptionListTokens {\n /** Widest the term column gets when terms sit beside their details. */\n termWidth: string;\n /** Space between the term and detail columns. */\n columnGap: string;\n /** Space between rows. */\n rowGap: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n descriptionList: DescriptionListTokens;\n }\n}\n\nexport interface DescriptionItem {\n /** Defaults to the term when it is a string. */\n id?: string;\n term: ReactNode;\n /** One detail, or several for a term with more than one value. */\n detail: ReactNode | ReactNode[];\n}\n\nexport interface DescriptionListProps {\n items: DescriptionItem[];\n /**\n * `inline`: terms beside their details. `stacked`: terms above. `auto` (default): inline when the list is at least\n * 28rem wide, stacked when narrower (it follows the list's own width, not the window's).\n */\n layout?: \"auto\" | \"inline\" | \"stacked\";\n /** Lines between rows. */\n divided?: boolean;\n size?: Size;\n className?: string;\n /** Layout only. Restyle through --cy-description-list-* tokens. */\n style?: CSSProperties;\n}\n\n/** Term and detail pairs: settings summaries, metadata, the facts about a record. */\nexport function DescriptionList({\n items,\n layout = \"auto\",\n divided = false,\n size = \"md\",\n className,\n style,\n}: DescriptionListProps) {\n return (\n <div\n className={className ? `cy-description-list ${className}` : \"cy-description-list\"}\n data-layout={layout}\n data-size={size}\n data-divided={divided ? \"\" : undefined}\n style={style}\n >\n <dl className=\"cy-description-list-list cy-reset\">\n {items.map((item, i) => (\n <div\n key={item.id ?? (typeof item.term === \"string\" ? item.term : i)}\n className=\"cy-description-list-row cy-reset\"\n >\n <dt className=\"cy-description-list-term cy-reset\">{item.term}</dt>\n {(Array.isArray(item.detail) ? item.detail : [item.detail]).map((detail, j) => (\n <dd key={j} className=\"cy-description-list-detail cy-reset\">\n {detail}\n </dd>\n ))}\n </div>\n ))}\n </dl>\n </div>\n );\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"DescriptionList.js","names":["jsx","jsxs","DescriptionList","items","layout","divided","size","className","style","item","i","detail","j"],"sources":["../../../src/components/DescriptionList/DescriptionList.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode } from \"react\";\nimport type { Size } from \"../../tokens/schema.js\";\n\nexport interface DescriptionListTokens {\n /** Widest the term column gets when terms sit beside their details. */\n termWidth: string;\n /** Space between the term and detail columns. */\n columnGap: string;\n /** Space between rows. */\n rowGap: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n descriptionList: DescriptionListTokens;\n }\n}\n\nexport interface DescriptionItem {\n /** Defaults to the term when it is a string. */\n id?: string;\n term: ReactNode;\n /** One detail, or several for a term with more than one value. */\n detail: ReactNode | ReactNode[];\n}\n\nexport interface DescriptionListProps {\n /** The terms and their details, in order. */\n items: DescriptionItem[];\n /**\n * `inline`: terms beside their details. `stacked`: terms above. `auto` (default): inline when the list is at least\n * 28rem wide, stacked when narrower (it follows the list's own width, not the window's).\n */\n layout?: \"auto\" | \"inline\" | \"stacked\";\n /** Lines between rows. */\n divided?: boolean;\n /** Text size. Default \"md\". */\n size?: Size;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-description-list-* tokens. */\n style?: CSSProperties;\n}\n\n/** Term and detail pairs: settings summaries, metadata, the facts about a record. */\nexport function DescriptionList({\n items,\n layout = \"auto\",\n divided = false,\n size = \"md\",\n className,\n style,\n}: DescriptionListProps) {\n return (\n <div\n className={className ? `cy-description-list ${className}` : \"cy-description-list\"}\n data-layout={layout}\n data-size={size}\n data-divided={divided ? \"\" : undefined}\n style={style}\n >\n <dl className=\"cy-description-list-list cy-reset\">\n {items.map((item, i) => (\n <div\n key={item.id ?? (typeof item.term === \"string\" ? item.term : i)}\n className=\"cy-description-list-row cy-reset\"\n >\n <dt className=\"cy-description-list-term cy-reset\">{item.term}</dt>\n {(Array.isArray(item.detail) ? item.detail : [item.detail]).map((detail, j) => (\n <dd key={j} className=\"cy-description-list-detail cy-reset\">\n {detail}\n </dd>\n ))}\n </div>\n ))}\n </dl>\n </div>\n );\n}\n"],"mappings":";;AA6CA,SAAgBE,EAAgB,EAC9B,OAAAC,GACA,QAAAC,IAAS,QACT,SAAAC,IAAU,IACV,MAAAC,IAAO,MACP,WAAAC,GACA,OAAAC,EAAA,GACuB;AACvB,SACE,gBAAAR,EAAC,OAAD;AAAA,IACE,WAAWO,IAAY,uBAAuBA,CAAA,KAAc;AAAA,IAC5D,eAAaH;AAAA,IACb,aAAWE;AAAA,IACX,gBAAcD,IAAU,KAAK;AAAA,IACtB,OAAAG;AAAA,IAEP,UAAA,gBAAAR,EAAC,MAAD;AAAA,MAAI,WAAU;AAAA,MACX,UAAAG,EAAM,IAAA,CAAKM,GAAMC,MAChB,gBAAAT,EAAC,OAAD;AAAA,QAEE,WAAU;AAAA,QAFZ,UAAA,CAIE,gBAAAD,EAAC,MAAD;AAAA,UAAI,WAAU;AAAA,UAAqC,UAAAS,EAAK;AAAA,QAAS,CAAA,IAC/D,MAAM,QAAQA,EAAK,MAAM,IAAIA,EAAK,SAAS,CAACA,EAAK,MAAM,GAAG,IAAA,CAAKE,GAAQC,MACvE,gBAAAZ,EAAC,MAAD;AAAA,UAAY,WAAU;AAAA,UACnB,UAAAW;AAAA,QACC,GAFKC,CAEL,CACL,CACE;AAAA,MATE,GAAAH,EAAK,OAAO,OAAOA,EAAK,QAAS,WAAWA,EAAK,OAAOC,EAS1D,CACN;AAAA,IACC,CAAA;AAAA,EACD,CAAA;AAET"}
|
|
@@ -18,8 +18,11 @@ export interface DialogLabels {
|
|
|
18
18
|
close: string;
|
|
19
19
|
}
|
|
20
20
|
export interface DialogProps {
|
|
21
|
+
/** Whether the dialog is open, when you control it. */
|
|
21
22
|
open?: boolean;
|
|
23
|
+
/** Open on first render when uncontrolled. */
|
|
22
24
|
defaultOpen?: boolean;
|
|
25
|
+
/** Called with `false` when the dialog closes itself: Escape, the backdrop or the close button. */
|
|
23
26
|
onOpenChange?: (open: boolean) => void;
|
|
24
27
|
/** Heading of the dialog; also its accessible name. */
|
|
25
28
|
title: ReactNode;
|
|
@@ -31,19 +34,30 @@ export interface DialogProps {
|
|
|
31
34
|
size?: Size;
|
|
32
35
|
/** Escape, the backdrop and the close button close it (default). `false` leaves only your actions. */
|
|
33
36
|
dismissible?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Keep the content in the DOM while the dialog is closed. By default a closed dialog renders nothing inside it: the
|
|
39
|
+
* content mounts when it opens and unmounts once the closing transition has ended, so every opening starts fresh.
|
|
40
|
+
* Set it for content whose state must survive closing (a half-filled form) or that is expensive to rebuild.
|
|
41
|
+
* Default false.
|
|
42
|
+
*/
|
|
43
|
+
keepMounted?: boolean;
|
|
44
|
+
/** Replace the built-in English text: the close button's name. */
|
|
34
45
|
labels?: Partial<DialogLabels>;
|
|
46
|
+
/** Added to the panel, for layout. */
|
|
35
47
|
className?: string;
|
|
36
48
|
/** Layout only, applied to the panel. Restyle through --cy-dialog-* tokens. */
|
|
37
49
|
style?: CSSProperties;
|
|
50
|
+
/** The content; it scrolls when it is taller than the dialog. */
|
|
38
51
|
children?: ReactNode;
|
|
39
52
|
}
|
|
40
53
|
/** Internal: a Sheet is the same dialog docked to an edge. */
|
|
41
54
|
export interface DialogFrameProps extends DialogProps {
|
|
42
55
|
side?: "bottom" | "end" | "start";
|
|
43
56
|
}
|
|
44
|
-
export declare function DialogFrame({ open, defaultOpen, onOpenChange, title, description, actions, size, dismissible, labels, side, className, style, children, }: DialogFrameProps): import("react").JSX.Element;
|
|
57
|
+
export declare function DialogFrame({ open, defaultOpen, onOpenChange, title, description, actions, size, dismissible, keepMounted, labels, side, className, style, children, }: DialogFrameProps): import("react").JSX.Element;
|
|
45
58
|
/**
|
|
46
59
|
* Modal dialog in the top layer: focus moves in, stays in and comes back; Escape, the backdrop and the close button
|
|
47
|
-
* dismiss it. In a container narrower than about 36rem it becomes a bottom sheet.
|
|
60
|
+
* dismiss it. In a container narrower than about 36rem it becomes a bottom sheet. Its content is mounted only while
|
|
61
|
+
* it is open (and while it closes), unless `keepMounted`.
|
|
48
62
|
*/
|
|
49
63
|
export declare function Dialog(props: DialogProps): import("react").JSX.Element;
|