@manakind/ui-core 0.29.0 → 0.30.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 +5 -1
- package/dist/accordion/accordion.css +89 -0
- package/dist/accordion/accordion.css.d.ts +2 -0
- package/dist/accordion/accordion.d.ts +79 -0
- package/dist/accordion/accordion.d.ts.map +1 -0
- package/dist/accordion/accordion.js +44 -0
- package/dist/accordion/accordion.js.map +1 -0
- package/dist/accordion/index.d.ts +2 -0
- package/dist/accordion/index.d.ts.map +1 -0
- package/dist/accordion/index.js +2 -0
- package/dist/accordion/index.js.map +1 -0
- package/dist/calendar/calendar.d.ts +3 -4
- package/dist/calendar/calendar.d.ts.map +1 -1
- package/dist/calendar/calendar.js +5 -2
- package/dist/calendar/calendar.js.map +1 -1
- package/dist/checkbox/checkbox.d.ts +2 -4
- package/dist/checkbox/checkbox.d.ts.map +1 -1
- package/dist/checkbox/checkbox.js +4 -2
- package/dist/checkbox/checkbox.js.map +1 -1
- package/dist/combobox/combobox.d.ts +3 -3
- package/dist/combobox/combobox.d.ts.map +1 -1
- package/dist/combobox/combobox.js +5 -2
- package/dist/combobox/combobox.js.map +1 -1
- package/dist/dialog/dialog.d.ts +3 -4
- package/dist/dialog/dialog.d.ts.map +1 -1
- package/dist/dialog/dialog.js +4 -2
- package/dist/dialog/dialog.js.map +1 -1
- package/dist/fallback-glyphs.js +3 -3
- package/dist/fallback-glyphs.js.map +1 -1
- package/dist/icon-defaults.d.ts +45 -0
- package/dist/icon-defaults.d.ts.map +1 -0
- package/dist/icon-defaults.js +43 -0
- package/dist/icon-defaults.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/menu/action-menu.d.ts +3 -3
- package/dist/menu/action-menu.d.ts.map +1 -1
- package/dist/menu/action-menu.js +4 -2
- package/dist/menu/action-menu.js.map +1 -1
- package/dist/menu/menu.d.ts +5 -7
- package/dist/menu/menu.d.ts.map +1 -1
- package/dist/menu/menu.js +7 -3
- package/dist/menu/menu.js.map +1 -1
- package/dist/radio-group/index.d.ts +2 -0
- package/dist/radio-group/index.d.ts.map +1 -0
- package/dist/radio-group/index.js +2 -0
- package/dist/radio-group/index.js.map +1 -0
- package/dist/radio-group/radio-group.css +70 -0
- package/dist/radio-group/radio-group.css.d.ts +2 -0
- package/dist/radio-group/radio-group.d.ts +74 -0
- package/dist/radio-group/radio-group.d.ts.map +1 -0
- package/dist/radio-group/radio-group.js +57 -0
- package/dist/radio-group/radio-group.js.map +1 -0
- package/dist/select/select.d.ts +3 -3
- package/dist/select/select.d.ts.map +1 -1
- package/dist/select/select.js +5 -2
- package/dist/select/select.js.map +1 -1
- package/dist/sticky/sticky.css +3 -1
- package/package.json +18 -2
package/README.md
CHANGED
|
@@ -57,7 +57,8 @@ separately, so an app can load only what it renders.
|
|
|
57
57
|
|
|
58
58
|
| Entry | Contents |
|
|
59
59
|
|---|---|
|
|
60
|
-
| `@manakind/ui-core` | Everything below, plus every prop type, the `cx` helper, and the built-in fallback glyphs (`FallbackChevronLeft`, `FallbackChevronRight`, `FallbackCheck`, `FallbackCross`, `FallbackPin`) for compositions that want the same defaults |
|
|
60
|
+
| `@manakind/ui-core` | Everything below, plus every prop type, the `cx` helper, `IconDefaultsProvider` + `useIconDefaults` (a product's glyphs for every icon slot left out), and the built-in fallback glyphs (`FallbackChevronLeft`, `FallbackChevronRight`, `FallbackCheck`, `FallbackCross`, `FallbackPin`) for compositions that want the same defaults |
|
|
61
|
+
| `@manakind/ui-core/accordion` | `Accordion` + `AccordionItem`; a title, a muted summary of what the section holds, and its content |
|
|
61
62
|
| `@manakind/ui-core/alert` | `Alert` |
|
|
62
63
|
| `@manakind/ui-core/avatar` | `Avatar` + `initialsOf` |
|
|
63
64
|
| `@manakind/ui-core/badge` | `Badge` |
|
|
@@ -89,6 +90,7 @@ separately, so an app can load only what it renders.
|
|
|
89
90
|
| `@manakind/ui-core/visually-hidden` | `VisuallyHidden` |
|
|
90
91
|
| `@manakind/ui-core/skeleton` | `Skeleton` |
|
|
91
92
|
| `@manakind/ui-core/spinner` | `Spinner` |
|
|
93
|
+
| `@manakind/ui-core/radio-group` | `RadioGroup` |
|
|
92
94
|
| `@manakind/ui-core/scroll-area` | `ScrollArea` |
|
|
93
95
|
| `@manakind/ui-core/sticky` | `Sticky` |
|
|
94
96
|
| `@manakind/ui-core/empty-state` | `EmptyState` |
|
|
@@ -101,6 +103,7 @@ separately, so an app can load only what it renders.
|
|
|
101
103
|
| `@manakind/ui-core/form-layout` | `FormLayout`, `FormActions` |
|
|
102
104
|
| `@manakind/ui-core/wizard-layout` | `WizardLayout`, `WizardHeader`, `WizardContent`, `WizardFooter` |
|
|
103
105
|
| `@manakind/ui-core/centered-layout` | `CenteredLayout` |
|
|
106
|
+
| `@manakind/ui-core/css/accordion` | Accordion structural CSS; its indicator also needs `css/icon` |
|
|
104
107
|
| `@manakind/ui-core/css/alert` | Alert structural CSS; its icon also needs `css/icon` |
|
|
105
108
|
| `@manakind/ui-core/css/avatar` | Avatar structural CSS; its fallback glyph also needs `css/icon` |
|
|
106
109
|
| `@manakind/ui-core/css/badge` | Badge structural CSS |
|
|
@@ -132,6 +135,7 @@ separately, so an app can load only what it renders.
|
|
|
132
135
|
| `@manakind/ui-core/css/visually-hidden` | VisuallyHidden structural CSS |
|
|
133
136
|
| `@manakind/ui-core/css/skeleton` | Skeleton structural CSS |
|
|
134
137
|
| `@manakind/ui-core/css/spinner` | Spinner structural CSS; its label also needs `css/visually-hidden` |
|
|
138
|
+
| `@manakind/ui-core/css/radio-group` | RadioGroup structural CSS |
|
|
135
139
|
| `@manakind/ui-core/css/scroll-area` | ScrollArea structural CSS |
|
|
136
140
|
| `@manakind/ui-core/css/sticky` | Sticky structural CSS |
|
|
137
141
|
| `@manakind/ui-core/css/empty-state` | EmptyState structural CSS; its glyph also needs `css/icon` |
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@layer components {
|
|
2
|
+
.ds-accordion {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
min-inline-size: 0;
|
|
6
|
+
overflow-wrap: anywhere;
|
|
7
|
+
|
|
8
|
+
& .ds-accordion__item + .ds-accordion__item {
|
|
9
|
+
border-block-start: 1px solid var(--ds-accordion-item-border);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
& .ds-accordion__heading {
|
|
13
|
+
margin: 0;
|
|
14
|
+
font: inherit;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* The title and its summary share a wrapping run of text, and the
|
|
19
|
+
* indicator keeps a column of its own: a long summary takes the next
|
|
20
|
+
* line under the title instead of pushing the chevron out of line.
|
|
21
|
+
*/
|
|
22
|
+
& .ds-accordion__trigger {
|
|
23
|
+
display: grid;
|
|
24
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
25
|
+
align-items: center;
|
|
26
|
+
gap: var(--ds-accordion-trigger-gap);
|
|
27
|
+
inline-size: 100%;
|
|
28
|
+
padding: var(--ds-accordion-trigger-padding);
|
|
29
|
+
border: 0;
|
|
30
|
+
border-radius: var(--ds-accordion-trigger-radius);
|
|
31
|
+
background-color: transparent;
|
|
32
|
+
color: var(--ds-accordion-trigger-text);
|
|
33
|
+
font-family: inherit;
|
|
34
|
+
font-size: var(--ds-accordion-trigger-font-size);
|
|
35
|
+
line-height: inherit;
|
|
36
|
+
text-align: start;
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
|
|
39
|
+
@media (hover: hover) {
|
|
40
|
+
&:hover:not(:disabled) {
|
|
41
|
+
background-color: var(--ds-accordion-trigger-bg-hover);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Drawn inside the button, not 3px out as on other controls: a section
|
|
47
|
+
* spans its container edge to edge, and a container that scrolls (a
|
|
48
|
+
* pinned sidebar) would clip a ring drawn outside it.
|
|
49
|
+
*/
|
|
50
|
+
&:focus-visible {
|
|
51
|
+
outline: 2px solid var(--ds-accordion-focus-ring);
|
|
52
|
+
outline-offset: -2px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* Zag disables the button itself and puts `data-disabled` on the item, not here. */
|
|
56
|
+
&:disabled {
|
|
57
|
+
cursor: not-allowed;
|
|
58
|
+
opacity: var(--ds-opacity-disabled);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
& .ds-accordion__title {
|
|
63
|
+
font-weight: var(--ds-accordion-trigger-font-weight);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
& .ds-accordion__summary {
|
|
67
|
+
color: var(--ds-accordion-summary-text);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* The glyph points right and turns down while its section is open. */
|
|
71
|
+
& .ds-accordion__indicator {
|
|
72
|
+
display: inline-flex;
|
|
73
|
+
color: var(--ds-accordion-indicator-color);
|
|
74
|
+
transition: transform 150ms cubic-bezier(0, 0, 0.2, 1);
|
|
75
|
+
|
|
76
|
+
&[data-state="open"] {
|
|
77
|
+
transform: rotate(90deg);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
& .ds-accordion__content {
|
|
82
|
+
padding: 0 var(--ds-accordion-content-padding) var(--ds-accordion-content-padding);
|
|
83
|
+
|
|
84
|
+
&[hidden] {
|
|
85
|
+
display: none;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import './accordion.css';
|
|
3
|
+
import type { CardHeadingTag } from '../card/card';
|
|
4
|
+
import { type IconSource } from '../icon/icon';
|
|
5
|
+
export type AccordionHeadingTag = Exclude<CardHeadingTag, 'h1'>;
|
|
6
|
+
export interface AccordionProps {
|
|
7
|
+
/** The sections: `AccordionItem`s. */
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
/** Controlled open sections, by `value`. */
|
|
10
|
+
value?: string[];
|
|
11
|
+
/** Sections open at first when uncontrolled. */
|
|
12
|
+
defaultValue?: string[];
|
|
13
|
+
/** Fired with every open section's value whenever one opens or closes. */
|
|
14
|
+
onValueChange?: (value: string[]) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Let several sections be open at once: a sidebar of filters. Off by
|
|
17
|
+
* default, so opening one closes the other, and the open one can still be
|
|
18
|
+
* closed.
|
|
19
|
+
*/
|
|
20
|
+
multiple?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The heading element each section's title sits in, so the sections take
|
|
23
|
+
* their place in the page's outline. Defaults to `h3`.
|
|
24
|
+
*/
|
|
25
|
+
headingLevel?: AccordionHeadingTag;
|
|
26
|
+
/** Extra class names appended after `ds-accordion`. */
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Stacked sections whose titles show and hide what sits under them, built on
|
|
31
|
+
* Ark UI's Accordion: the filters of a list in a sidebar, the questions of
|
|
32
|
+
* an FAQ.
|
|
33
|
+
*
|
|
34
|
+
* Ark owns the behaviour: each title is a button in a heading that says
|
|
35
|
+
* whether its section is expanded and which region it controls, and the
|
|
36
|
+
* arrow keys, Home and End move between the titles. This wrapper contributes
|
|
37
|
+
* the `ds-` classes, the `--ds-accordion-*` bindings and a flat item API.
|
|
38
|
+
*
|
|
39
|
+
* ```tsx
|
|
40
|
+
* <Accordion multiple defaultValue={['state']} headingLevel="h2">
|
|
41
|
+
* <AccordionItem value="state" title="State" summary="Open">
|
|
42
|
+
* …
|
|
43
|
+
* </AccordionItem>
|
|
44
|
+
* <AccordionItem value="category" title="Category" summary="Any">
|
|
45
|
+
* …
|
|
46
|
+
* </AccordionItem>
|
|
47
|
+
* </Accordion>
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* A closed section's content stays mounted, hidden, so state held in it
|
|
51
|
+
* survives closing it.
|
|
52
|
+
*/
|
|
53
|
+
export declare function Accordion({ children, value, defaultValue, onValueChange, multiple, headingLevel, className, }: AccordionProps): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
export interface AccordionItemProps {
|
|
55
|
+
/** Stable id of the section, reported by `onValueChange`. */
|
|
56
|
+
value: string;
|
|
57
|
+
/** The section's title: what its content is about. */
|
|
58
|
+
title: ReactNode;
|
|
59
|
+
/**
|
|
60
|
+
* What the section holds right now, beside the title and muted: a filter's
|
|
61
|
+
* choice ("Open", "High, Low"), so a closed section still says what it does.
|
|
62
|
+
* Part of the title button's name.
|
|
63
|
+
*/
|
|
64
|
+
summary?: ReactNode;
|
|
65
|
+
/** The section's content, shown while it is open. */
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
/** Keep the section closed and its title out of reach. */
|
|
68
|
+
disabled?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Glyph after the title. Must point RIGHT: it turns down while the section
|
|
71
|
+
* is open. Defaults to the `IconDefaultsProvider`'s `chevronRight`.
|
|
72
|
+
*/
|
|
73
|
+
indicator?: IconSource;
|
|
74
|
+
/** Extra class names appended after `ds-accordion__item`. */
|
|
75
|
+
className?: string;
|
|
76
|
+
}
|
|
77
|
+
/** One section of an `Accordion`: a title that opens and closes its content. */
|
|
78
|
+
export declare function AccordionItem({ value, title, summary, children, disabled, indicator: indicatorProp, className, }: AccordionItemProps): import("react/jsx-runtime").JSX.Element;
|
|
79
|
+
//# sourceMappingURL=accordion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accordion.d.ts","sourceRoot":"","sources":["../../src/accordion/accordion.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,SAAS,EAAc,MAAM,OAAO,CAAC;AAClE,OAAO,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrD,MAA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@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Accordion as ArkAccordion } from '@ark-ui/react/accordion';
|
|
3
|
+
import { createContext, useContext } from 'react';
|
|
4
|
+
import './accordion.css';
|
|
5
|
+
import { cx } from '../cx';
|
|
6
|
+
import { Icon } from '../icon/icon';
|
|
7
|
+
import { useIconDefaults } from '../icon-defaults';
|
|
8
|
+
const HeadingContext = createContext('h3');
|
|
9
|
+
/**
|
|
10
|
+
* Stacked sections whose titles show and hide what sits under them, built on
|
|
11
|
+
* Ark UI's Accordion: the filters of a list in a sidebar, the questions of
|
|
12
|
+
* an FAQ.
|
|
13
|
+
*
|
|
14
|
+
* Ark owns the behaviour: each title is a button in a heading that says
|
|
15
|
+
* whether its section is expanded and which region it controls, and the
|
|
16
|
+
* arrow keys, Home and End move between the titles. This wrapper contributes
|
|
17
|
+
* the `ds-` classes, the `--ds-accordion-*` bindings and a flat item API.
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <Accordion multiple defaultValue={['state']} headingLevel="h2">
|
|
21
|
+
* <AccordionItem value="state" title="State" summary="Open">
|
|
22
|
+
* …
|
|
23
|
+
* </AccordionItem>
|
|
24
|
+
* <AccordionItem value="category" title="Category" summary="Any">
|
|
25
|
+
* …
|
|
26
|
+
* </AccordionItem>
|
|
27
|
+
* </Accordion>
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* A closed section's content stays mounted, hidden, so state held in it
|
|
31
|
+
* survives closing it.
|
|
32
|
+
*/
|
|
33
|
+
export function Accordion({ children, value, defaultValue, onValueChange, multiple = false, headingLevel = 'h3', className, }) {
|
|
34
|
+
const handleValueChange = (details) => onValueChange?.(details.value);
|
|
35
|
+
return (_jsx(HeadingContext.Provider, { value: headingLevel, children: _jsx(ArkAccordion.Root, { className: cx('ds-accordion', className), value: value, defaultValue: defaultValue, onValueChange: handleValueChange, multiple: multiple, collapsible: true, children: children }) }));
|
|
36
|
+
}
|
|
37
|
+
/** One section of an `Accordion`: a title that opens and closes its content. */
|
|
38
|
+
export function AccordionItem({ value, title, summary, children, disabled, indicator: indicatorProp, className, }) {
|
|
39
|
+
const Heading = useContext(HeadingContext);
|
|
40
|
+
const icons = useIconDefaults();
|
|
41
|
+
const indicator = indicatorProp ?? icons.chevronRight;
|
|
42
|
+
return (_jsxs(ArkAccordion.Item, { value: value, disabled: disabled, className: cx('ds-accordion__item', className), children: [_jsx(Heading, { className: "ds-accordion__heading", children: _jsxs(ArkAccordion.ItemTrigger, { className: "ds-accordion__trigger", children: [_jsxs("span", { className: "ds-accordion__label", children: [_jsx("span", { className: "ds-accordion__title", children: title }), summary !== undefined && (_jsxs(_Fragment, { children: [' ', _jsx("span", { className: "ds-accordion__summary", children: summary })] }))] }), _jsx(ArkAccordion.ItemIndicator, { className: "ds-accordion__indicator", children: _jsx(Icon, { source: indicator, size: "sm", decorative: true }) })] }) }), _jsx(ArkAccordion.ItemContent, { className: "ds-accordion__content", children: children })] }));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=accordion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accordion.js","sourceRoot":"","sources":["../../src/accordion/accordion.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAkB,UAAU,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,iBAAiB,CAAC;AAEzB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAInD,MAAM,cAAc,GAAG,aAAa,CAAsB,IAAI,CAAC,CAAC;AA0BhE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,SAAS,CAAC,EAC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S,EAAC,uBAAuB,YAAE,OAAO,GAAQ,IACvD,CACJ,IACI,EACP,KAAC,YAAY,CAAC,aAAa,IAAC,SAAS,EAAC,yBAAyB,YAC7D,KAAC,IAAI,IAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAC,IAAI,EAAC,UAAU,SAAG,GACrB,IACJ,GACnB,EACV,KAAC,YAAY,CAAC,WAAW,IAAC,SAAS,EAAC,uBAAuB,YACxD,QAAQ,GACgB,IACT,CACrB,CAAC;AACJ,CAAC","sourcesContent":["import { Accordion as ArkAccordion } from '@ark-ui/react/accordion';\nimport { createContext, type ReactNode, useContext } from 'react';\nimport './accordion.css';\nimport type { CardHeadingTag } from '../card/card';\nimport { cx } from '../cx';\nimport { Icon, type IconSource } from '../icon/icon';\nimport { useIconDefaults } from '../icon-defaults';\n\nexport type AccordionHeadingTag = Exclude<CardHeadingTag, 'h1'>;\n\nconst HeadingContext = createContext<AccordionHeadingTag>('h3');\n\nexport interface AccordionProps {\n /** The sections: `AccordionItem`s. */\n children: ReactNode;\n /** Controlled open sections, by `value`. */\n value?: string[];\n /** Sections open at first when uncontrolled. */\n defaultValue?: string[];\n /** Fired with every open section's value whenever one opens or closes. */\n onValueChange?: (value: string[]) => void;\n /**\n * Let several sections be open at once: a sidebar of filters. Off by\n * default, so opening one closes the other, and the open one can still be\n * closed.\n */\n multiple?: boolean;\n /**\n * The heading element each section's title sits in, so the sections take\n * their place in the page's outline. Defaults to `h3`.\n */\n headingLevel?: AccordionHeadingTag;\n /** Extra class names appended after `ds-accordion`. */\n className?: string;\n}\n\n/**\n * Stacked sections whose titles show and hide what sits under them, built on\n * Ark UI's Accordion: the filters of a list in a sidebar, the questions of\n * an FAQ.\n *\n * Ark owns the behaviour: each title is a button in a heading that says\n * whether its section is expanded and which region it controls, and the\n * arrow keys, Home and End move between the titles. This wrapper contributes\n * the `ds-` classes, the `--ds-accordion-*` bindings and a flat item API.\n *\n * ```tsx\n * <Accordion multiple defaultValue={['state']} headingLevel=\"h2\">\n * <AccordionItem value=\"state\" title=\"State\" summary=\"Open\">\n * …\n * </AccordionItem>\n * <AccordionItem value=\"category\" title=\"Category\" summary=\"Any\">\n * …\n * </AccordionItem>\n * </Accordion>\n * ```\n *\n * A closed section's content stays mounted, hidden, so state held in it\n * survives closing it.\n */\nexport function Accordion({\n children,\n value,\n defaultValue,\n onValueChange,\n multiple = false,\n headingLevel = 'h3',\n className,\n}: AccordionProps) {\n const handleValueChange = (details: { value: string[] }) => onValueChange?.(details.value);\n return (\n <HeadingContext.Provider value={headingLevel}>\n <ArkAccordion.Root\n className={cx('ds-accordion', className)}\n value={value}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n multiple={multiple}\n collapsible\n >\n {children}\n </ArkAccordion.Root>\n </HeadingContext.Provider>\n );\n}\n\nexport interface AccordionItemProps {\n /** Stable id of the section, reported by `onValueChange`. */\n value: string;\n /** The section's title: what its content is about. */\n title: ReactNode;\n /**\n * What the section holds right now, beside the title and muted: a filter's\n * choice (\"Open\", \"High, Low\"), so a closed section still says what it does.\n * Part of the title button's name.\n */\n summary?: ReactNode;\n /** The section's content, shown while it is open. */\n children: ReactNode;\n /** Keep the section closed and its title out of reach. */\n disabled?: boolean;\n /**\n * Glyph after the title. Must point RIGHT: it turns down while the section\n * is open. Defaults to the `IconDefaultsProvider`'s `chevronRight`.\n */\n indicator?: IconSource;\n /** Extra class names appended after `ds-accordion__item`. */\n className?: string;\n}\n\n/** One section of an `Accordion`: a title that opens and closes its content. */\nexport function AccordionItem({\n value,\n title,\n summary,\n children,\n disabled,\n indicator: indicatorProp,\n className,\n}: AccordionItemProps) {\n const Heading = useContext(HeadingContext);\n const icons = useIconDefaults();\n const indicator = indicatorProp ?? icons.chevronRight;\n return (\n <ArkAccordion.Item\n value={value}\n disabled={disabled}\n className={cx('ds-accordion__item', className)}\n >\n <Heading className=\"ds-accordion__heading\">\n <ArkAccordion.ItemTrigger className=\"ds-accordion__trigger\">\n <span className=\"ds-accordion__label\">\n <span className=\"ds-accordion__title\">{title}</span>\n {summary !== undefined && (\n <>\n {' '}\n <span className=\"ds-accordion__summary\">{summary}</span>\n </>\n )}\n </span>\n <ArkAccordion.ItemIndicator className=\"ds-accordion__indicator\">\n <Icon source={indicator} size=\"sm\" decorative />\n </ArkAccordion.ItemIndicator>\n </ArkAccordion.ItemTrigger>\n </Heading>\n <ArkAccordion.ItemContent className=\"ds-accordion__content\">\n {children}\n </ArkAccordion.ItemContent>\n </ArkAccordion.Item>\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/accordion/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,mBAAmB,EACxB,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/accordion/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,aAAa,GAGd,MAAM,aAAa,CAAC","sourcesContent":["export {\n Accordion,\n type AccordionHeadingTag,\n AccordionItem,\n type AccordionItemProps,\n type AccordionProps,\n} from './accordion';\n"]}
|
|
@@ -50,9 +50,8 @@ interface CalendarCommonProps {
|
|
|
50
50
|
/** Shows the days and the choice, pages freely, but lets nothing be chosen. */
|
|
51
51
|
readOnly?: boolean;
|
|
52
52
|
/**
|
|
53
|
-
* Glyph for the "previous month" button. Defaults to
|
|
54
|
-
*
|
|
55
|
-
* own icon set.
|
|
53
|
+
* Glyph for the "previous month" button. Defaults to the
|
|
54
|
+
* `IconDefaultsProvider`'s `chevronLeft`, or a plain built-in one.
|
|
56
55
|
*/
|
|
57
56
|
previousIcon?: IconSource;
|
|
58
57
|
/** Glyph for the "next month" button. Same defaulting rule as {@link CalendarCommonProps.previousIcon}. */
|
|
@@ -110,6 +109,6 @@ export type CalendarProps = CalendarCommonProps & CalendarSelection;
|
|
|
110
109
|
* <Calendar aria-label="Scheduled day" value={day} onValueChange={setDay} autoFocus />
|
|
111
110
|
* ```
|
|
112
111
|
*/
|
|
113
|
-
export declare function Calendar({ 'aria-label': ariaLabel, locale, startOfWeek, min, max, defaultMonth, autoFocus, disabled, readOnly, previousIcon, nextIcon, className, ...selection }: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
112
|
+
export declare function Calendar({ 'aria-label': ariaLabel, locale, startOfWeek, min, max, defaultMonth, autoFocus, disabled, readOnly, previousIcon: previousIconProp, nextIcon: nextIconProp, className, ...selection }: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
114
113
|
export {};
|
|
115
114
|
//# sourceMappingURL=calendar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../../src/calendar/calendar.tsx"],"names":[],"mappings":"AAGA,OAAO,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../../src/calendar/calendar.tsx"],"names":[],"mappings":"AAGA,OAAO,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAExD,UAAU,mBAAmB;IAC3B;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2FAA2F;IAC3F,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uD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,SAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,YAAY,EAAE,gBAAgB,EAC9B,QAAQ,EAAE,YAAY,EACtB,SAAS,EACT,GAAG,SAAS,EACb,EAAE,aAAa,2CA2Hf"}
|
|
@@ -5,7 +5,7 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
5
5
|
import './calendar.css';
|
|
6
6
|
import { IconButton } from '../button/icon-button';
|
|
7
7
|
import { cx } from '../cx';
|
|
8
|
-
import {
|
|
8
|
+
import { useIconDefaults } from '../icon-defaults';
|
|
9
9
|
import { parseIsoDate } from '../iso-date';
|
|
10
10
|
const parseIso = (iso, prop) => parseIsoDate(iso, `Calendar: ${prop}`);
|
|
11
11
|
const parseOptional = (iso, prop) => iso === undefined ? undefined : parseIso(iso, prop);
|
|
@@ -80,7 +80,10 @@ function useFocusedDay(chosen, fallback) {
|
|
|
80
80
|
* <Calendar aria-label="Scheduled day" value={day} onValueChange={setDay} autoFocus />
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
export function Calendar({ 'aria-label': ariaLabel, locale = 'en-GB', startOfWeek, min, max, defaultMonth, autoFocus = false, disabled, readOnly, previousIcon
|
|
83
|
+
export function Calendar({ 'aria-label': ariaLabel, locale = 'en-GB', startOfWeek, min, max, defaultMonth, autoFocus = false, disabled, readOnly, previousIcon: previousIconProp, nextIcon: nextIconProp, className, ...selection }) {
|
|
84
|
+
const icons = useIconDefaults();
|
|
85
|
+
const previousIcon = previousIconProp ?? icons.chevronLeft;
|
|
86
|
+
const nextIcon = nextIconProp ?? icons.chevronRight;
|
|
84
87
|
const rootRef = useRef(null);
|
|
85
88
|
const controlledDates = toDateValues(selection, 'value');
|
|
86
89
|
const initialDates = toDateValues(selection, 'defaultValue');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../src/calendar/calendar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,IAAI,aAAa,EAAkB,MAAM,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,CACJ,GACqB,GACL,GACC,GACL,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import { DatePicker as ArkDatePicker, type DateValue } from '@ark-ui/react/date-picker';\nimport { getLocalTimeZone, today } from '@internationalized/date';\nimport { useEffect, useRef, useState } from 'react';\nimport './calendar.css';\nimport { IconButton } from '../button/icon-button';\nimport { cx } from '../cx';\nimport { ChevronLeft, ChevronRight } from '../fallback-glyphs';\nimport type { IconSource } from '../icon/icon';\nimport { parseIsoDate } from '../iso-date';\n\n/**\n * A stretch of days. Both ends are ISO calendar dates, `YYYY-MM-DD`; `end`\n * is `null` while only the first day is chosen.\n */\nexport interface CalendarRange {\n start: string;\n end: string | null;\n}\n\n/** A day of the week as `Date#getDay()` counts them: 0 is Sunday, 1 is Monday. */\nexport type CalendarWeekday = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\ninterface CalendarCommonProps {\n /**\n * The calendar's name, saying which day is being chosen: \"Scheduled day\",\n * \"Target date\". A calendar has no label of its own, and the month heading\n * changes as the user pages.\n */\n 'aria-label': string;\n /**\n * BCP 47 tag that decides the month and weekday names and, unless\n * `startOfWeek` says otherwise, the first day of the week. Defaults to\n * `en-GB`: English names, Monday first. The products' own date format is\n * not involved; the grid shows day numbers only.\n */\n locale?: string;\n /** The first column, `0` for Sunday through `6` for Saturday. Defaults to the locale's. */\n startOfWeek?: CalendarWeekday;\n /**\n * The earliest day that can be chosen, `YYYY-MM-DD`. Earlier days are\n * shown but cannot be chosen; a value outside the window is still shown\n * as the value.\n */\n min?: string;\n /** The latest day that can be chosen, `YYYY-MM-DD`. */\n max?: string;\n /**\n * Any day of the month shown first when nothing is chosen yet,\n * `YYYY-MM-DD`. Defaults to the month of the chosen day, else this month.\n */\n defaultMonth?: string;\n /**\n * Moves focus to the chosen day (else the first day shown by\n * `defaultMonth`, else today) once the calendar is in the page. For a calendar opened in a popover, so\n * the arrow keys work at once and a screen reader lands on a day.\n */\n autoFocus?: boolean;\n /** Dims the calendar; nothing in it can be focused or chosen. */\n disabled?: boolean;\n /** Shows the days and the choice, pages freely, but lets nothing be chosen. */\n readOnly?: boolean;\n /**\n * Glyph for the \"previous month\" button. Defaults to a plain built-in\n * chevron so `@manakind/ui-core` renders on its own; products pass their\n * own icon set.\n */\n previousIcon?: IconSource;\n /** Glyph for the \"next month\" button. Same defaulting rule as {@link CalendarCommonProps.previousIcon}. */\n nextIcon?: IconSource;\n /** Extra class names appended after `ds-calendar`. */\n className?: string;\n}\n\ninterface CalendarSingleProps {\n /** One day at a time. The default. */\n selectionMode?: 'single';\n /** The chosen day, `YYYY-MM-DD`, or `null` for none. Leave undefined to let the calendar own it. */\n value?: string | null;\n /** The day chosen at first when uncontrolled, or `null` for none. */\n defaultValue?: string | null;\n /**\n * Fired with the ISO date of the day the user chose. Choosing the chosen\n * day again fires nothing, and the calendar never clears: a product that\n * lets the user unschedule does it with a control of its own.\n */\n onValueChange?: (value: string) => void;\n}\n\ninterface CalendarRangeProps {\n /**\n * A first and a last day. The first click chooses the first day and fires\n * with `end: null`; the second click chooses the last day, in either\n * order, and fires with both; a third click starts a new range.\n */\n selectionMode: 'range';\n /** The chosen range, or `null` for none. Leave undefined to let the calendar own it. */\n value?: CalendarRange | null;\n /** The range chosen at first when uncontrolled, or `null` for none. */\n defaultValue?: CalendarRange | null;\n /** Fired with the range so far: `end` is `null` after the first click of a new range. */\n onValueChange?: (value: CalendarRange) => void;\n}\n\ntype CalendarSelection = CalendarSingleProps | CalendarRangeProps;\n\nexport type CalendarProps = CalendarCommonProps & CalendarSelection;\n\nconst parseIso = (iso: string, prop: string): DateValue => parseIsoDate(iso, `Calendar: ${prop}`);\n\nconst parseOptional = (iso: string | undefined, prop: string): DateValue | undefined =>\n iso === undefined ? undefined : parseIso(iso, prop);\n\n/*\n * Zag keeps every selection as a list of dates: one for a day, up to two\n * for a range. The product's typed shape is folded into that list on the\n * way in and rebuilt on the way out.\n */\nfunction toDateValues(\n selection: CalendarSelection,\n prop: 'value' | 'defaultValue',\n): DateValue[] | undefined {\n const given = selection[prop];\n if (given === undefined) return undefined;\n if (given === null) return [];\n if (typeof given === 'string') return [parseIso(given, prop)];\n const dates = [parseIso(given.start, `${prop}.start`)];\n if (given.end !== null) dates.push(parseIso(given.end, `${prop}.end`));\n return dates;\n}\n\n/*\n * Zag's list can be sparse: a range cleared from outside between its two\n * clicks keeps Zag waiting for an end date, and the next click lands at\n * index 1 of an empty list. The dates that are there are the selection.\n */\nfunction report(selection: CalendarSelection, dates: DateValue[]): void {\n const [start, end] = dates.filter((date) => date !== undefined);\n if (!start) return;\n if (selection.selectionMode === 'range') {\n selection.onValueChange?.({ start: start.toString(), end: end?.toString() ?? null });\n return;\n }\n selection.onValueChange?.(start.toString());\n}\n\n/*\n * The day Zag's keyboard focus and the shown month follow. Zag moves it on\n * its own events only, so a value the parent changes to another month\n * would leave the grid on the old one: the calendar owns it, and moves it\n * to the chosen day whenever the parent chooses a new one.\n */\nfunction useFocusedDay(chosen: DateValue | undefined, fallback: DateValue | undefined) {\n const chosenKey = chosen?.toString();\n const [focused, setFocused] = useState(() => ({\n key: chosenKey,\n day: chosen ?? fallback ?? today(getLocalTimeZone()),\n }));\n if (chosenKey !== focused.key) {\n setFocused({ key: chosenKey, day: chosen ?? focused.day });\n }\n const setDay = (day: DateValue) => setFocused((state) => ({ ...state, day }));\n return [focused.day, setDay] as const;\n}\n\n/**\n * A month of days to choose from, built on Ark UI's DatePicker.\n *\n * The grid shows one month at a time with the weekdays across the top and\n * a button pair to turn the page; the days of the neighbouring months fill\n * the first and last rows, and every month has six rows, so the calendar\n * keeps its height as the user pages. One day is chosen at a time, or a\n * first and a last day with `selectionMode=\"range\"`. The value in and out is\n * an ISO calendar date, `YYYY-MM-DD`, as `DateInput` gives: a string a form\n * library and a database both keep as is, with no time zone to get wrong.\n *\n * It is the grid alone. A product puts it in a `Popover` behind a button\n * that shows the choice, or in the page, and gives it `aria-label`; the\n * labels the grid speaks (\"Choose Wednesday 12 June 2024\", \"Previous month\")\n * are English, as Ark's are.\n *\n * ```tsx\n * <Calendar aria-label=\"Scheduled day\" value={day} onValueChange={setDay} autoFocus />\n * ```\n */\nexport function Calendar({\n 'aria-label': ariaLabel,\n locale = 'en-GB',\n startOfWeek,\n min,\n max,\n defaultMonth,\n autoFocus = false,\n disabled,\n readOnly,\n previousIcon = ChevronLeft,\n nextIcon = ChevronRight,\n className,\n ...selection\n}: CalendarProps) {\n const rootRef = useRef<HTMLDivElement>(null);\n const controlledDates = toDateValues(selection, 'value');\n const initialDates = toDateValues(selection, 'defaultValue');\n const [focusedDay, setFocusedDay] = useFocusedDay(\n controlledDates?.[0] ?? initialDates?.[0],\n parseOptional(defaultMonth, 'defaultMonth'),\n );\n const minDate = parseOptional(min, 'min');\n const maxDate = parseOptional(max, 'max');\n\n /*\n * Passed as unavailable days rather than Zag's own `min`/`max`, which clamp\n * a value outside them to the nearest allowed day and show that day as\n * chosen while the parent holds another. Unavailable days are disabled and\n * cannot be chosen, and a value outside the window stays the value.\n */\n const isOutsideWindow = (date: DateValue) =>\n (minDate !== undefined && date.compare(minDate) < 0) ||\n (maxDate !== undefined && date.compare(maxDate) > 0);\n\n /*\n * Zag gives the focused day `tabindex=\"0\"` and every other day `-1`; the\n * one day in the tab order is the one to land on. An effect, because the\n * focus is the browser's.\n */\n useEffect(() => {\n if (!autoFocus) return;\n rootRef.current\n ?.querySelector<HTMLElement>('[data-part=\"table-cell-trigger\"][tabindex=\"0\"]')\n ?.focus({ preventScroll: true });\n }, [autoFocus]);\n\n return (\n <ArkDatePicker.Root\n ref={rootRef}\n className={cx('ds-calendar', className)}\n inline\n closeOnSelect={false}\n fixedWeeks\n outsideDaySelectable\n selectionMode={selection.selectionMode ?? 'single'}\n value={controlledDates}\n defaultValue={initialDates}\n onValueChange={(details) => report(selection, details.value)}\n focusedValue={focusedDay}\n onFocusChange={(details) => setFocusedDay(details.focusedValue)}\n isDateUnavailable={minDate || maxDate ? isOutsideWindow : undefined}\n locale={locale}\n timeZone={getLocalTimeZone()}\n startOfWeek={startOfWeek}\n disabled={disabled}\n readOnly={readOnly}\n >\n <ArkDatePicker.Content\n className=\"ds-calendar__content\"\n aria-label={ariaLabel}\n aria-disabled={disabled || undefined}\n >\n <ArkDatePicker.View view=\"day\">\n <ArkDatePicker.Context>\n {(api) => (\n <>\n <ArkDatePicker.ViewControl className=\"ds-calendar__header\">\n <ArkDatePicker.PrevTrigger asChild>\n <IconButton\n variant=\"tertiary\"\n size=\"sm\"\n icon={previousIcon}\n aria-label=\"Previous month\"\n />\n </ArkDatePicker.PrevTrigger>\n <ArkDatePicker.RangeText className=\"ds-calendar__heading\" aria-live=\"polite\" />\n <ArkDatePicker.NextTrigger asChild>\n <IconButton\n variant=\"tertiary\"\n size=\"sm\"\n icon={nextIcon}\n aria-label=\"Next month\"\n />\n </ArkDatePicker.NextTrigger>\n </ArkDatePicker.ViewControl>\n <ArkDatePicker.Table className=\"ds-calendar__table\">\n <ArkDatePicker.TableHead>\n <ArkDatePicker.TableRow>\n {api.weekDays.map((weekDay) => (\n <ArkDatePicker.TableHeader\n key={weekDay.value.toString()}\n className=\"ds-calendar__weekday\"\n >\n {weekDay.short}\n </ArkDatePicker.TableHeader>\n ))}\n </ArkDatePicker.TableRow>\n </ArkDatePicker.TableHead>\n <ArkDatePicker.TableBody>\n {api.weeks.map((week) => (\n <ArkDatePicker.TableRow key={week[0]?.toString()}>\n {week.map((day) => (\n <ArkDatePicker.TableCell\n key={day.toString()}\n value={day}\n className=\"ds-calendar__cell\"\n >\n <ArkDatePicker.TableCellTrigger className=\"ds-calendar__day\">\n <span className=\"ds-calendar__day-fill\">{day.day}</span>\n </ArkDatePicker.TableCellTrigger>\n </ArkDatePicker.TableCell>\n ))}\n </ArkDatePicker.TableRow>\n ))}\n </ArkDatePicker.TableBody>\n </ArkDatePicker.Table>\n </>\n )}\n </ArkDatePicker.Context>\n </ArkDatePicker.View>\n </ArkDatePicker.Content>\n </ArkDatePicker.Root>\n );\n}\n"]}
|
|
1
|
+
{"version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,YAE7B,KAAC,aAAa,CAAC,gBAAgB,IAAC,SAAS,EAAC,kBAAkB,YAC1D,eAAM,SAAS,EAAC,uBAAuB,YAAE,GAAG,CAAC,GAAG,GAAQ,GACzB,IAN5B,GAAG,CAAC,QAAQ,EAAE,CAOK,CAC3B,CAAC,IAXyB,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAYvB,CAC1B,CAAC,GACsB,IACN,IACrB,CACJ,GACqB,GACL,GACC,GACL,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import { DatePicker as ArkDatePicker, type DateValue } from '@ark-ui/react/date-picker';\nimport { getLocalTimeZone, today } from '@internationalized/date';\nimport { useEffect, useRef, useState } from 'react';\nimport './calendar.css';\nimport { IconButton } from '../button/icon-button';\nimport { cx } from '../cx';\nimport type { IconSource } from '../icon/icon';\nimport { useIconDefaults } from '../icon-defaults';\nimport { parseIsoDate } from '../iso-date';\n\n/**\n * A stretch of days. Both ends are ISO calendar dates, `YYYY-MM-DD`; `end`\n * is `null` while only the first day is chosen.\n */\nexport interface CalendarRange {\n start: string;\n end: string | null;\n}\n\n/** A day of the week as `Date#getDay()` counts them: 0 is Sunday, 1 is Monday. */\nexport type CalendarWeekday = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\ninterface CalendarCommonProps {\n /**\n * The calendar's name, saying which day is being chosen: \"Scheduled day\",\n * \"Target date\". A calendar has no label of its own, and the month heading\n * changes as the user pages.\n */\n 'aria-label': string;\n /**\n * BCP 47 tag that decides the month and weekday names and, unless\n * `startOfWeek` says otherwise, the first day of the week. Defaults to\n * `en-GB`: English names, Monday first. The products' own date format is\n * not involved; the grid shows day numbers only.\n */\n locale?: string;\n /** The first column, `0` for Sunday through `6` for Saturday. Defaults to the locale's. */\n startOfWeek?: CalendarWeekday;\n /**\n * The earliest day that can be chosen, `YYYY-MM-DD`. Earlier days are\n * shown but cannot be chosen; a value outside the window is still shown\n * as the value.\n */\n min?: string;\n /** The latest day that can be chosen, `YYYY-MM-DD`. */\n max?: string;\n /**\n * Any day of the month shown first when nothing is chosen yet,\n * `YYYY-MM-DD`. Defaults to the month of the chosen day, else this month.\n */\n defaultMonth?: string;\n /**\n * Moves focus to the chosen day (else the first day shown by\n * `defaultMonth`, else today) once the calendar is in the page. For a calendar opened in a popover, so\n * the arrow keys work at once and a screen reader lands on a day.\n */\n autoFocus?: boolean;\n /** Dims the calendar; nothing in it can be focused or chosen. */\n disabled?: boolean;\n /** Shows the days and the choice, pages freely, but lets nothing be chosen. */\n readOnly?: boolean;\n /**\n * Glyph for the \"previous month\" button. Defaults to the\n * `IconDefaultsProvider`'s `chevronLeft`, or a plain built-in one.\n */\n previousIcon?: IconSource;\n /** Glyph for the \"next month\" button. Same defaulting rule as {@link CalendarCommonProps.previousIcon}. */\n nextIcon?: IconSource;\n /** Extra class names appended after `ds-calendar`. */\n className?: string;\n}\n\ninterface CalendarSingleProps {\n /** One day at a time. The default. */\n selectionMode?: 'single';\n /** The chosen day, `YYYY-MM-DD`, or `null` for none. Leave undefined to let the calendar own it. */\n value?: string | null;\n /** The day chosen at first when uncontrolled, or `null` for none. */\n defaultValue?: string | null;\n /**\n * Fired with the ISO date of the day the user chose. Choosing the chosen\n * day again fires nothing, and the calendar never clears: a product that\n * lets the user unschedule does it with a control of its own.\n */\n onValueChange?: (value: string) => void;\n}\n\ninterface CalendarRangeProps {\n /**\n * A first and a last day. The first click chooses the first day and fires\n * with `end: null`; the second click chooses the last day, in either\n * order, and fires with both; a third click starts a new range.\n */\n selectionMode: 'range';\n /** The chosen range, or `null` for none. Leave undefined to let the calendar own it. */\n value?: CalendarRange | null;\n /** The range chosen at first when uncontrolled, or `null` for none. */\n defaultValue?: CalendarRange | null;\n /** Fired with the range so far: `end` is `null` after the first click of a new range. */\n onValueChange?: (value: CalendarRange) => void;\n}\n\ntype CalendarSelection = CalendarSingleProps | CalendarRangeProps;\n\nexport type CalendarProps = CalendarCommonProps & CalendarSelection;\n\nconst parseIso = (iso: string, prop: string): DateValue => parseIsoDate(iso, `Calendar: ${prop}`);\n\nconst parseOptional = (iso: string | undefined, prop: string): DateValue | undefined =>\n iso === undefined ? undefined : parseIso(iso, prop);\n\n/*\n * Zag keeps every selection as a list of dates: one for a day, up to two\n * for a range. The product's typed shape is folded into that list on the\n * way in and rebuilt on the way out.\n */\nfunction toDateValues(\n selection: CalendarSelection,\n prop: 'value' | 'defaultValue',\n): DateValue[] | undefined {\n const given = selection[prop];\n if (given === undefined) return undefined;\n if (given === null) return [];\n if (typeof given === 'string') return [parseIso(given, prop)];\n const dates = [parseIso(given.start, `${prop}.start`)];\n if (given.end !== null) dates.push(parseIso(given.end, `${prop}.end`));\n return dates;\n}\n\n/*\n * Zag's list can be sparse: a range cleared from outside between its two\n * clicks keeps Zag waiting for an end date, and the next click lands at\n * index 1 of an empty list. The dates that are there are the selection.\n */\nfunction report(selection: CalendarSelection, dates: DateValue[]): void {\n const [start, end] = dates.filter((date) => date !== undefined);\n if (!start) return;\n if (selection.selectionMode === 'range') {\n selection.onValueChange?.({ start: start.toString(), end: end?.toString() ?? null });\n return;\n }\n selection.onValueChange?.(start.toString());\n}\n\n/*\n * The day Zag's keyboard focus and the shown month follow. Zag moves it on\n * its own events only, so a value the parent changes to another month\n * would leave the grid on the old one: the calendar owns it, and moves it\n * to the chosen day whenever the parent chooses a new one.\n */\nfunction useFocusedDay(chosen: DateValue | undefined, fallback: DateValue | undefined) {\n const chosenKey = chosen?.toString();\n const [focused, setFocused] = useState(() => ({\n key: chosenKey,\n day: chosen ?? fallback ?? today(getLocalTimeZone()),\n }));\n if (chosenKey !== focused.key) {\n setFocused({ key: chosenKey, day: chosen ?? focused.day });\n }\n const setDay = (day: DateValue) => setFocused((state) => ({ ...state, day }));\n return [focused.day, setDay] as const;\n}\n\n/**\n * A month of days to choose from, built on Ark UI's DatePicker.\n *\n * The grid shows one month at a time with the weekdays across the top and\n * a button pair to turn the page; the days of the neighbouring months fill\n * the first and last rows, and every month has six rows, so the calendar\n * keeps its height as the user pages. One day is chosen at a time, or a\n * first and a last day with `selectionMode=\"range\"`. The value in and out is\n * an ISO calendar date, `YYYY-MM-DD`, as `DateInput` gives: a string a form\n * library and a database both keep as is, with no time zone to get wrong.\n *\n * It is the grid alone. A product puts it in a `Popover` behind a button\n * that shows the choice, or in the page, and gives it `aria-label`; the\n * labels the grid speaks (\"Choose Wednesday 12 June 2024\", \"Previous month\")\n * are English, as Ark's are.\n *\n * ```tsx\n * <Calendar aria-label=\"Scheduled day\" value={day} onValueChange={setDay} autoFocus />\n * ```\n */\nexport function Calendar({\n 'aria-label': ariaLabel,\n locale = 'en-GB',\n startOfWeek,\n min,\n max,\n defaultMonth,\n autoFocus = false,\n disabled,\n readOnly,\n previousIcon: previousIconProp,\n nextIcon: nextIconProp,\n className,\n ...selection\n}: CalendarProps) {\n const icons = useIconDefaults();\n const previousIcon = previousIconProp ?? icons.chevronLeft;\n const nextIcon = nextIconProp ?? icons.chevronRight;\n const rootRef = useRef<HTMLDivElement>(null);\n const controlledDates = toDateValues(selection, 'value');\n const initialDates = toDateValues(selection, 'defaultValue');\n const [focusedDay, setFocusedDay] = useFocusedDay(\n controlledDates?.[0] ?? initialDates?.[0],\n parseOptional(defaultMonth, 'defaultMonth'),\n );\n const minDate = parseOptional(min, 'min');\n const maxDate = parseOptional(max, 'max');\n\n /*\n * Passed as unavailable days rather than Zag's own `min`/`max`, which clamp\n * a value outside them to the nearest allowed day and show that day as\n * chosen while the parent holds another. Unavailable days are disabled and\n * cannot be chosen, and a value outside the window stays the value.\n */\n const isOutsideWindow = (date: DateValue) =>\n (minDate !== undefined && date.compare(minDate) < 0) ||\n (maxDate !== undefined && date.compare(maxDate) > 0);\n\n /*\n * Zag gives the focused day `tabindex=\"0\"` and every other day `-1`; the\n * one day in the tab order is the one to land on. An effect, because the\n * focus is the browser's.\n */\n useEffect(() => {\n if (!autoFocus) return;\n rootRef.current\n ?.querySelector<HTMLElement>('[data-part=\"table-cell-trigger\"][tabindex=\"0\"]')\n ?.focus({ preventScroll: true });\n }, [autoFocus]);\n\n return (\n <ArkDatePicker.Root\n ref={rootRef}\n className={cx('ds-calendar', className)}\n inline\n closeOnSelect={false}\n fixedWeeks\n outsideDaySelectable\n selectionMode={selection.selectionMode ?? 'single'}\n value={controlledDates}\n defaultValue={initialDates}\n onValueChange={(details) => report(selection, details.value)}\n focusedValue={focusedDay}\n onFocusChange={(details) => setFocusedDay(details.focusedValue)}\n isDateUnavailable={minDate || maxDate ? isOutsideWindow : undefined}\n locale={locale}\n timeZone={getLocalTimeZone()}\n startOfWeek={startOfWeek}\n disabled={disabled}\n readOnly={readOnly}\n >\n <ArkDatePicker.Content\n className=\"ds-calendar__content\"\n aria-label={ariaLabel}\n aria-disabled={disabled || undefined}\n >\n <ArkDatePicker.View view=\"day\">\n <ArkDatePicker.Context>\n {(api) => (\n <>\n <ArkDatePicker.ViewControl className=\"ds-calendar__header\">\n <ArkDatePicker.PrevTrigger asChild>\n <IconButton\n variant=\"tertiary\"\n size=\"sm\"\n icon={previousIcon}\n aria-label=\"Previous month\"\n />\n </ArkDatePicker.PrevTrigger>\n <ArkDatePicker.RangeText className=\"ds-calendar__heading\" aria-live=\"polite\" />\n <ArkDatePicker.NextTrigger asChild>\n <IconButton\n variant=\"tertiary\"\n size=\"sm\"\n icon={nextIcon}\n aria-label=\"Next month\"\n />\n </ArkDatePicker.NextTrigger>\n </ArkDatePicker.ViewControl>\n <ArkDatePicker.Table className=\"ds-calendar__table\">\n <ArkDatePicker.TableHead>\n <ArkDatePicker.TableRow>\n {api.weekDays.map((weekDay) => (\n <ArkDatePicker.TableHeader\n key={weekDay.value.toString()}\n className=\"ds-calendar__weekday\"\n >\n {weekDay.short}\n </ArkDatePicker.TableHeader>\n ))}\n </ArkDatePicker.TableRow>\n </ArkDatePicker.TableHead>\n <ArkDatePicker.TableBody>\n {api.weeks.map((week) => (\n <ArkDatePicker.TableRow key={week[0]?.toString()}>\n {week.map((day) => (\n <ArkDatePicker.TableCell\n key={day.toString()}\n value={day}\n className=\"ds-calendar__cell\"\n >\n <ArkDatePicker.TableCellTrigger className=\"ds-calendar__day\">\n <span className=\"ds-calendar__day-fill\">{day.day}</span>\n </ArkDatePicker.TableCellTrigger>\n </ArkDatePicker.TableCell>\n ))}\n </ArkDatePicker.TableRow>\n ))}\n </ArkDatePicker.TableBody>\n </ArkDatePicker.Table>\n </>\n )}\n </ArkDatePicker.Context>\n </ArkDatePicker.View>\n </ArkDatePicker.Content>\n </ArkDatePicker.Root>\n );\n}\n"]}
|
|
@@ -51,9 +51,7 @@ export type CheckboxProps = CheckboxName & {
|
|
|
51
51
|
/**
|
|
52
52
|
* Glyph shown in the box while checked.
|
|
53
53
|
*
|
|
54
|
-
* Defaults to a plain built-in
|
|
55
|
-
* renders on its own. Products override it with their own icon set, as
|
|
56
|
-
* they do Select's `itemIndicator`.
|
|
54
|
+
* Defaults to the `IconDefaultsProvider`'s `check`, or a plain built-in one.
|
|
57
55
|
*/
|
|
58
56
|
indicator?: IconSource;
|
|
59
57
|
/** Extra class names appended after the `ds-checkbox` modifiers. */
|
|
@@ -76,6 +74,6 @@ export type CheckboxProps = CheckboxName & {
|
|
|
76
74
|
* `Switch`; a choice between values of which exactly one applies is a
|
|
77
75
|
* `Select`.
|
|
78
76
|
*/
|
|
79
|
-
export declare function Checkbox({ label, checked, defaultChecked, onCheckedChange, size, disabled, invalid, readOnly, required, name, value, indicator, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }: CheckboxProps): import("react/jsx-runtime").JSX.Element;
|
|
77
|
+
export declare function Checkbox({ label, checked, defaultChecked, onCheckedChange, size, disabled, invalid, readOnly, required, name, value, indicator: indicatorProp, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }: CheckboxProps): import("react/jsx-runtime").JSX.Element;
|
|
80
78
|
export {};
|
|
81
79
|
//# sourceMappingURL=checkbox.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrD,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9C;;;;GAIG;AACH,KAAK,YAAY,GACb;IACE,0DAA0D;IAC1D,KAAK,EAAE,SAAS,CAAC;IACjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,8GAA8G;IAC9G,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG;IACzC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uCAAuC;IACvC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,uEAAuE;IACvE,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,yCAAyC;IACzC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8EAA8E;IAC9E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,OAAO,EACP,cAAc,EACd,eAAe,EACf,IAAW,EACX,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,SAAS,EAAE,aAAa,EACxB,SAAS,EACT,YAAY,EAAE,SAAS,EACvB,kBAAkB,EAAE,eAAe,GACpC,EAAE,aAAa,2CAkEf"}
|
|
@@ -3,8 +3,8 @@ import { Checkbox as ArkCheckbox } from '@ark-ui/react/checkbox';
|
|
|
3
3
|
import { useId, useRef } from 'react';
|
|
4
4
|
import './checkbox.css';
|
|
5
5
|
import { cx } from '../cx';
|
|
6
|
-
import { Check } from '../fallback-glyphs';
|
|
7
6
|
import { Icon } from '../icon/icon';
|
|
7
|
+
import { useIconDefaults } from '../icon-defaults';
|
|
8
8
|
/**
|
|
9
9
|
* A choice that is saved with the form, built on Ark UI's Checkbox.
|
|
10
10
|
*
|
|
@@ -22,7 +22,9 @@ import { Icon } from '../icon/icon';
|
|
|
22
22
|
* `Switch`; a choice between values of which exactly one applies is a
|
|
23
23
|
* `Select`.
|
|
24
24
|
*/
|
|
25
|
-
export function Checkbox({ label, checked, defaultChecked, onCheckedChange, size = 'md', disabled, invalid, readOnly, required, name, value, indicator
|
|
25
|
+
export function Checkbox({ label, checked, defaultChecked, onCheckedChange, size = 'md', disabled, invalid, readOnly, required, name, value, indicator: indicatorProp, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }) {
|
|
26
|
+
const icons = useIconDefaults();
|
|
27
|
+
const indicator = indicatorProp ?? icons.check;
|
|
26
28
|
const inputRef = useRef(null);
|
|
27
29
|
/*
|
|
28
30
|
* Zag always names the hidden input by its label part's id, which would
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAkB,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,gBAAgB,CAAC;AACxB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAkB,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,gBAAgB,CAAC;AACxB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AA+DnD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,QAAQ,CAAC,EACvB,KAAK,EACL,OAAO,EACP,cAAc,EACd,eAAe,EACf,IAAI,GAAG,IAAI,EACX,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,SAAS,EAAE,aAAa,EACxB,SAAS,EACT,YAAY,EAAE,SAAS,EACvB,kBAAkB,EAAE,eAAe,GACrB;IACd,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAChC,MAAM,SAAS,GAAG,aAAa,IAAI,KAAK,CAAC,KAAK,CAAC;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IAEhD;;;;;OAKG;IAEH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AAC,WAAW,CAAC,WAAW,IACtB,GAAG,EAAE,QAAQ,gBACD,SAAS,sBACH,eAAe,mBAClB,QAAQ,IAAI,SAAS,GACpC,IACe,CACpB,CAAC;AACJ,CAAC","sourcesContent":["import { Checkbox as ArkCheckbox } from '@ark-ui/react/checkbox';\nimport { type ReactNode, useId, useRef } from 'react';\nimport './checkbox.css';\nimport { cx } from '../cx';\nimport { Icon, type IconSource } from '../icon/icon';\nimport { useIconDefaults } from '../icon-defaults';\n\nexport type CheckboxSize = 'sm' | 'md' | 'lg';\n\n/**\n * A checkbox has to have a name. A visible `label` is the one to reach for:\n * the whole label is the click target. Expressed as a union so an unnamed\n * checkbox is a compile error rather than an axe finding, as `Switch` does.\n */\ntype CheckboxName =\n | {\n /** Visible label. The whole label is the click target. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the control is. Keep the visible words in it, so a voice\n * user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when no visible label fits, such as a row whose text already says what the checkbox is. */\n 'aria-label': string;\n };\n\nexport type CheckboxProps = CheckboxName & {\n /** Controlled checked state. Leave undefined to let the component own it. */\n checked?: boolean;\n /** Initial state when uncontrolled. */\n defaultChecked?: boolean;\n /** Fired with the new state whenever the user toggles the checkbox. */\n onCheckedChange?: (checked: boolean) => void;\n /** Control size and label type scale. */\n size?: CheckboxSize;\n /** Disable the control. It keeps its state and stops responding. */\n disabled?: boolean;\n /**\n * Marks the control invalid for assistive tech and styling (`data-invalid`).\n * Pair it with a message the control points at through `aria-describedby`;\n * a red border alone is not an accessible error.\n */\n invalid?: boolean;\n /** Id of the element that describes the control, such as an error message. */\n 'aria-describedby'?: string;\n /** Show the state without letting the user change it. */\n readOnly?: boolean;\n /** Marks the hidden input required for native form validation. */\n required?: boolean;\n /** Name for native form participation. */\n name?: string;\n /** Value submitted under `name` while checked. Defaults to `on`. */\n value?: string;\n /**\n * Glyph shown in the box while checked.\n *\n * Defaults to the `IconDefaultsProvider`'s `check`, or a plain built-in one.\n */\n indicator?: IconSource;\n /** Extra class names appended after the `ds-checkbox` modifiers. */\n className?: string;\n};\n\n/**\n * A choice that is saved with the form, built on Ark UI's Checkbox.\n *\n * Ark owns the behaviour: a hidden checkbox carries the state, the root is\n * the `<label>` that names it, and Space and pointer toggling come for free.\n * This wrapper contributes `ds-` classes, the `--ds-checkbox-*` bindings, a\n * flat prop API, and the check glyph.\n *\n * ```tsx\n * <Checkbox label=\"Health\" checked={chosen} onCheckedChange={setChosen} />\n * ```\n *\n * A checkbox is for a choice that is submitted later, alone or as one of\n * several that can all be on. A setting that takes effect at once is a\n * `Switch`; a choice between values of which exactly one applies is a\n * `Select`.\n */\nexport function Checkbox({\n label,\n checked,\n defaultChecked,\n onCheckedChange,\n size = 'md',\n disabled,\n invalid,\n readOnly,\n required,\n name,\n value,\n indicator: indicatorProp,\n className,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n}: CheckboxProps) {\n const icons = useIconDefaults();\n const indicator = indicatorProp ?? icons.check;\n const inputRef = useRef<HTMLInputElement>(null);\n\n /*\n * Zag always names the hidden input by its label part's id, which would\n * outrank an `aria-label`. With both given, the visible label is plain\n * text instead, so that id resolves to nothing and the `aria-label` wins;\n * the root is still the `<label>`, so the text stays the click target.\n */\n\n /*\n * Ark hands a checkbox inside a Field the field's control and label ids,\n * so two checkboxes in one field would share an id and both be named by\n * the field's label. A checkbox names itself, so it keeps its own ids and\n * takes only the states from a field around it.\n */\n const ownId = useId();\n const ids = { hiddenInput: `${ownId}:input`, label: `${ownId}:label` };\n\n /*\n * Ark renders the hidden input uncontrolled and syncs it only when its own\n * state changes, so a controlled parent that declines a toggle would leave\n * the native input flipped while the box shows the old state. Restoring\n * the parent's value after Ark has read the input keeps the two agreeing,\n * as Switch does.\n */\n const handleCheckedChange = (details: { checked: boolean | 'indeterminate' }) => {\n onCheckedChange?.(details.checked === true);\n if (checked !== undefined && inputRef.current) inputRef.current.checked = checked;\n };\n\n return (\n <ArkCheckbox.Root\n ids={ids}\n className={cx('ds-checkbox', `ds-checkbox--${size}`, className)}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n disabled={disabled}\n invalid={invalid}\n readOnly={readOnly}\n required={required}\n name={name}\n value={value}\n >\n <ArkCheckbox.Control className=\"ds-checkbox__control\">\n <ArkCheckbox.Indicator className=\"ds-checkbox__indicator\">\n <Icon source={indicator} size=\"sm\" decorative />\n </ArkCheckbox.Indicator>\n </ArkCheckbox.Control>\n {label &&\n (ariaLabel ? (\n <span className=\"ds-checkbox__label\">{label}</span>\n ) : (\n <ArkCheckbox.Label className=\"ds-checkbox__label\">{label}</ArkCheckbox.Label>\n ))}\n <ArkCheckbox.HiddenInput\n ref={inputRef}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-readonly={readOnly || undefined}\n />\n </ArkCheckbox.Root>\n );\n}\n"]}
|
|
@@ -93,9 +93,9 @@ export interface ComboboxProps {
|
|
|
93
93
|
status?: ReactNode;
|
|
94
94
|
/** Adds the facet column, with its pins. The list becomes a grid. */
|
|
95
95
|
facets?: ComboboxFacets;
|
|
96
|
-
/** Glyph of a row's pin. Defaults to the
|
|
96
|
+
/** Glyph of a row's pin. Defaults to the `IconDefaultsProvider`'s `pin`. */
|
|
97
97
|
pinIcon?: IconSource;
|
|
98
|
-
/** Glyph of the pinned chip's remove button. Defaults to the
|
|
98
|
+
/** Glyph of the pinned chip's remove button. Defaults to the `IconDefaultsProvider`'s `cross`. */
|
|
99
99
|
removeIcon?: IconSource;
|
|
100
100
|
/** Control height and type scale. */
|
|
101
101
|
size?: ComboboxSize;
|
|
@@ -152,5 +152,5 @@ export interface ComboboxProps {
|
|
|
152
152
|
* The field reads the `--ds-input-*` keys and the list the `--ds-select-*`
|
|
153
153
|
* keys, so it reads as one family with `Input` and `Select`.
|
|
154
154
|
*/
|
|
155
|
-
export declare function Combobox({ items, inputValue, onInputValueChange, onSelect, label, 'aria-label': ariaLabel, placeholder, emptyText, toolbar, status, facets, pinIcon, removeIcon, size, disabled, invalid, className, inputRef, }: ComboboxProps): import("react/jsx-runtime").JSX.Element;
|
|
155
|
+
export declare function Combobox({ items, inputValue, onInputValueChange, onSelect, label, 'aria-label': ariaLabel, placeholder, emptyText, toolbar, status, facets, pinIcon: pinIconProp, removeIcon: removeIconProp, size, disabled, invalid, className, inputRef, }: ComboboxProps): import("react/jsx-runtime").JSX.Element;
|
|
156
156
|
//# sourceMappingURL=combobox.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../src/combobox/combobox.tsx"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,GAAG,EAST,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../src/combobox/combobox.tsx"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,GAAG,EAST,MAAM,OAAO,CAAC;AAIf,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAIrD,OAAO,wCAAwC,CAAC;AAChD,OAAO,gBAAgB,CAAC;AAExB,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9C,sFAAsF;AACtF,MAAM,WAAW,aAAa;IAC5B,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;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B,8DAA8D;IAC9D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gGAAgG;IAChG,QAAQ,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAClC;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,KAAK,EACL,YAAY,EAAE,SAAS,EACvB,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,MAAM,EACN,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,cAAc,EAC1B,IAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,QAAQ,GACT,EAAE,aAAa,2CAkVf"}
|
|
@@ -5,9 +5,9 @@ import { getTabbableEdges, getTabbables, isComposingEvent } from '@zag-js/dom-qu
|
|
|
5
5
|
import { useCallback, useContext, useEffect, useId, useMemo, useRef, useState, } from 'react';
|
|
6
6
|
import { flushSync } from 'react-dom';
|
|
7
7
|
import { cx } from '../cx';
|
|
8
|
-
import { Cross, Pin } from '../fallback-glyphs';
|
|
9
8
|
import { groupItems } from '../group-items';
|
|
10
9
|
import { Icon } from '../icon/icon';
|
|
10
|
+
import { useIconDefaults } from '../icon-defaults';
|
|
11
11
|
import { PortalContainerContext } from '../portal-container';
|
|
12
12
|
import { Tooltip } from '../tooltip/tooltip';
|
|
13
13
|
import '../visually-hidden/visually-hidden.css';
|
|
@@ -58,7 +58,10 @@ const HEADER_CONTROLS = 'button, input, label, a[href], [tabindex]:not([tabindex
|
|
|
58
58
|
* The field reads the `--ds-input-*` keys and the list the `--ds-select-*`
|
|
59
59
|
* keys, so it reads as one family with `Input` and `Select`.
|
|
60
60
|
*/
|
|
61
|
-
export function Combobox({ items, inputValue, onInputValueChange, onSelect, label, 'aria-label': ariaLabel, placeholder, emptyText, toolbar, status, facets, pinIcon
|
|
61
|
+
export function Combobox({ items, inputValue, onInputValueChange, onSelect, label, 'aria-label': ariaLabel, placeholder, emptyText, toolbar, status, facets, pinIcon: pinIconProp, removeIcon: removeIconProp, size = 'md', disabled, invalid, className, inputRef, }) {
|
|
62
|
+
const icons = useIconDefaults();
|
|
63
|
+
const pinIcon = pinIconProp ?? icons.pin;
|
|
64
|
+
const removeIcon = removeIconProp ?? icons.cross;
|
|
62
65
|
const id = useId();
|
|
63
66
|
const inputId = `${id}-input`;
|
|
64
67
|
const labelId = `${id}-label`;
|