@calcifer-design/ui 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Breadcrumb/Breadcrumb.d.ts +24 -0
- package/dist/components/Breadcrumb/Breadcrumb.js +48 -0
- package/dist/components/Breadcrumb/Breadcrumb.module.js +10 -0
- package/dist/components/Breadcrumb/Breadcrumb_module.css +49 -0
- package/dist/components/CardList/CardList.d.ts +30 -0
- package/dist/components/CardList/CardList.js +35 -0
- package/dist/components/CardList/CardList.module.js +7 -0
- package/dist/components/CardList/CardList_module.css +20 -0
- package/dist/components/Checkbox/Checkbox.d.ts +23 -0
- package/dist/components/Checkbox/Checkbox.js +33 -0
- package/dist/components/Checkbox/Checkbox.module.js +6 -0
- package/dist/components/Checkbox/Checkbox_module.css +16 -0
- package/dist/components/DatePicker/Calendar.d.ts +19 -0
- package/dist/components/DatePicker/Calendar.js +207 -0
- package/dist/components/DatePicker/DatePicker.d.ts +72 -0
- package/dist/components/DatePicker/DatePicker.js +116 -0
- package/dist/components/DatePicker/DatePicker.module.js +14 -0
- package/dist/components/DatePicker/DatePicker_module.css +112 -0
- package/dist/components/DatePicker/calendarDate.d.ts +46 -0
- package/dist/components/DatePicker/calendarDate.js +117 -0
- package/dist/components/Descriptions/Descriptions.d.ts +25 -0
- package/dist/components/Descriptions/Descriptions.js +44 -0
- package/dist/components/Descriptions/Descriptions.module.js +8 -0
- package/dist/components/Descriptions/Descriptions_module.css +47 -0
- package/dist/components/Field/Field.d.ts +118 -0
- package/dist/components/Field/Field.js +90 -0
- package/dist/components/Field/PickerField.d.ts +41 -0
- package/dist/components/Field/PickerField.js +115 -0
- package/dist/components/Field/PickerField.module.js +8 -0
- package/dist/components/Field/PickerField_module.css +36 -0
- package/dist/components/FilterBar/FilterBar.d.ts +55 -0
- package/dist/components/FilterBar/FilterBar.js +138 -0
- package/dist/components/FilterBar/FilterBar.module.js +13 -0
- package/dist/components/FilterBar/FilterBar_module.css +98 -0
- package/dist/components/Form/Form.d.ts +48 -0
- package/dist/components/Form/Form.js +38 -0
- package/dist/components/Form/Form.module.js +5 -0
- package/dist/components/Form/FormContext.d.ts +15 -0
- package/dist/components/Form/FormContext.js +20 -0
- package/dist/components/Form/Form_module.css +6 -0
- package/dist/components/PageShell/PageShell.d.ts +27 -0
- package/dist/components/PageShell/PageShell.js +35 -0
- package/dist/components/PageShell/PageShell.module.js +9 -0
- package/dist/components/PageShell/PageShell_module.css +56 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +35 -0
- package/dist/components/RadioGroup/RadioGroup.js +64 -0
- package/dist/components/RadioGroup/RadioGroup.module.js +6 -0
- package/dist/components/RadioGroup/RadioGroup_module.css +13 -0
- package/dist/components/Segmented/Segmented.d.ts +49 -0
- package/dist/components/Segmented/Segmented.js +55 -0
- package/dist/components/Segmented/Segmented.module.js +7 -0
- package/dist/components/Segmented/Segmented_module.css +75 -0
- package/dist/components/Select/Select.d.ts +42 -0
- package/dist/components/Select/Select.js +90 -0
- package/dist/components/Select/Select.module.js +9 -0
- package/dist/components/Select/Select_module.css +70 -0
- package/dist/components/Steps/Steps.d.ts +30 -0
- package/dist/components/Steps/Steps.js +63 -0
- package/dist/components/Steps/Steps.module.js +10 -0
- package/dist/components/Steps/Steps_module.css +126 -0
- package/dist/components/Switch/Switch.d.ts +23 -0
- package/dist/components/Switch/Switch.js +25 -0
- package/dist/components/Switch/Switch.module.js +6 -0
- package/dist/components/Switch/Switch_module.css +41 -0
- package/dist/components/TextArea/TextArea.d.ts +16 -0
- package/dist/components/TextArea/TextArea.js +28 -0
- package/dist/components/TextArea/TextArea.module.js +5 -0
- package/dist/components/TextArea/TextArea_module.css +12 -0
- package/dist/components/TextInput/TextInput.d.ts +17 -0
- package/dist/components/TextInput/TextInput.js +18 -0
- package/dist/components/TimePicker/TimePicker.d.ts +19 -0
- package/dist/components/TimePicker/TimePicker.js +17 -0
- package/dist/components/Timeline/Timeline.d.ts +39 -0
- package/dist/components/Timeline/Timeline.js +109 -0
- package/dist/components/Timeline/Timeline.module.js +12 -0
- package/dist/components/Timeline/Timeline_module.css +99 -0
- package/dist/components/Toolbar/InsideToolbarContext.d.ts +6 -0
- package/dist/components/Toolbar/InsideToolbarContext.js +3 -0
- package/dist/components/Toolbar/Toolbar.d.ts +46 -0
- package/dist/components/Toolbar/Toolbar.js +43 -0
- package/dist/components/Toolbar/Toolbar.module.js +7 -0
- package/dist/components/Toolbar/Toolbar_module.css +26 -0
- package/dist/components/Tree/Tree.d.ts +81 -0
- package/dist/components/Tree/Tree.js +232 -0
- package/dist/components/Tree/Tree.module.js +12 -0
- package/dist/components/Tree/Tree_module.css +124 -0
- package/dist/components/Tree/treeIndex.d.ts +23 -0
- package/dist/components/Tree/treeIndex.js +33 -0
- package/dist/components/TreeSelect/TreeSelect.d.ts +61 -0
- package/dist/components/TreeSelect/TreeSelect.js +117 -0
- package/dist/components/TreeSelect/TreeSelect.module.js +7 -0
- package/dist/components/TreeSelect/TreeSelect_module.css +22 -0
- package/dist/components/Upload/Upload.d.ts +66 -0
- package/dist/components/Upload/Upload.js +287 -0
- package/dist/components/Upload/Upload.module.js +12 -0
- package/dist/components/Upload/Upload_module.css +96 -0
- package/dist/components/ViewField/ViewField.d.ts +26 -0
- package/dist/components/ViewField/ViewField.js +29 -0
- package/dist/components/ViewField/ViewField.module.js +6 -0
- package/dist/components/ViewField/ViewField_module.css +17 -0
- package/dist/hooks/useFormReset.d.ts +10 -0
- package/dist/hooks/useFormReset.js +34 -0
- package/dist/icons/CalendarIcon.d.ts +2 -0
- package/dist/icons/CalendarIcon.js +26 -0
- package/dist/icons/CheckIcon.d.ts +6 -0
- package/dist/icons/CheckIcon.js +17 -0
- package/dist/icons/ChevronDownIcon.d.ts +6 -0
- package/dist/icons/ChevronDownIcon.js +17 -0
- package/dist/icons/MinusIcon.d.ts +5 -0
- package/dist/icons/MinusIcon.js +16 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +23 -0
- package/dist/styles/field.module.js +15 -0
- package/dist/styles/field_module.css +133 -0
- package/dist/styles/pair.module.js +6 -0
- package/dist/styles/pair_module.css +18 -0
- package/dist/styles/popup_module.css +6 -0
- package/package.json +2 -2
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Form } from "@base-ui/react/form";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { FormValuesContext } from "./FormContext.js";
|
|
5
|
+
import Form_module from "./Form.module.js";
|
|
6
|
+
function holdsSameMessages(first, second) {
|
|
7
|
+
const firstEntries = Object.entries(first ?? {});
|
|
8
|
+
return firstEntries.length === Object.keys(second ?? {}).length && firstEntries.every(([name, message])=>second?.[name] === message);
|
|
9
|
+
}
|
|
10
|
+
function Form_Form({ onSubmit, errors, noValidate = true, children, id, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }) {
|
|
11
|
+
const [overriddenValues] = useState(()=>new Map());
|
|
12
|
+
const [heldErrors, setHeldErrors] = useState(errors);
|
|
13
|
+
const [submittedSinceHeld, setSubmittedSinceHeld] = useState(false);
|
|
14
|
+
if (errors !== heldErrors && (submittedSinceHeld || !holdsSameMessages(errors, heldErrors))) {
|
|
15
|
+
setHeldErrors(errors);
|
|
16
|
+
setSubmittedSinceHeld(false);
|
|
17
|
+
}
|
|
18
|
+
return /*#__PURE__*/ jsx(FormValuesContext.Provider, {
|
|
19
|
+
value: overriddenValues,
|
|
20
|
+
children: /*#__PURE__*/ jsx(Form, {
|
|
21
|
+
className: Form_module.root,
|
|
22
|
+
id: id,
|
|
23
|
+
"aria-label": ariaLabel,
|
|
24
|
+
"aria-labelledby": ariaLabelledBy,
|
|
25
|
+
noValidate: noValidate,
|
|
26
|
+
errors: heldErrors,
|
|
27
|
+
onFormSubmit: (values)=>{
|
|
28
|
+
setSubmittedSinceHeld(true);
|
|
29
|
+
onSubmit({
|
|
30
|
+
...values,
|
|
31
|
+
...Object.fromEntries(overriddenValues)
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
children: children
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export { Form_Form as Form };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a control hands `Form` when the value Base UI would read off its DOM element is not the one
|
|
3
|
+
* a caller wants: an `Upload`'s `File`s rather than a file input's fake path, a `DatePicker`'s
|
|
4
|
+
* `null` rather than an empty string. `null` here means no `Form` is around, which is also how
|
|
5
|
+
* `FieldMessages` knows to leave a plain `<form>`'s frames exactly as they were. Internal: not
|
|
6
|
+
* exported from `src/index.ts`, like `InsideToolbarContext`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const FormValuesContext: import("react").Context<Map<string, unknown> | null>;
|
|
9
|
+
/** Internal. True inside a `Form`, whose error entries only Base UI's own error part can read. */
|
|
10
|
+
export declare function useInsideForm(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Internal. Submits `value` under `name` in place of what Base UI reads. Leave `name` undefined
|
|
13
|
+
* for a disabled control: it submits nothing, as a disabled input does.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useFormValue(name: string | undefined, value: unknown): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect } from "react";
|
|
2
|
+
const FormValuesContext = createContext(null);
|
|
3
|
+
function useInsideForm() {
|
|
4
|
+
return null !== useContext(FormValuesContext);
|
|
5
|
+
}
|
|
6
|
+
function useFormValue(name, value) {
|
|
7
|
+
const values = useContext(FormValuesContext);
|
|
8
|
+
useEffect(()=>{
|
|
9
|
+
if (null === values || void 0 === name) return;
|
|
10
|
+
values.set(name, value);
|
|
11
|
+
return ()=>{
|
|
12
|
+
values.delete(name);
|
|
13
|
+
};
|
|
14
|
+
}, [
|
|
15
|
+
values,
|
|
16
|
+
name,
|
|
17
|
+
value
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
export { FormValuesContext, useFormValue, useInsideForm };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
interface PageShellBaseProps {
|
|
3
|
+
/** Becomes the `banner` landmark, as long as the shell is not inside a sectioning element. */
|
|
4
|
+
header?: ReactNode;
|
|
5
|
+
/** Becomes the `contentinfo` landmark, on the same condition as `header`. */
|
|
6
|
+
footer?: ReactNode;
|
|
7
|
+
/** The page's content: the `main` landmark. */
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
/** The id of `main`, which the skip link targets. */
|
|
10
|
+
mainId?: string;
|
|
11
|
+
/** The skip link's text; `SkipLink`'s own default applies otherwise. */
|
|
12
|
+
skipLinkLabel?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
interface PageShellWithSidebar extends PageShellBaseProps {
|
|
15
|
+
/** Becomes a `complementary` landmark, stacked above the content at narrow widths. */
|
|
16
|
+
sidebar: ReactNode;
|
|
17
|
+
/** The sidebar's landmark name. Required with it: a page may have several, and each needs one. */
|
|
18
|
+
sidebarLabel: string;
|
|
19
|
+
}
|
|
20
|
+
interface PageShellWithoutSidebar extends PageShellBaseProps {
|
|
21
|
+
sidebar?: undefined;
|
|
22
|
+
sidebarLabel?: undefined;
|
|
23
|
+
}
|
|
24
|
+
export type PageShellProps = PageShellWithSidebar | PageShellWithoutSidebar;
|
|
25
|
+
/** The page's landmarks, in reading order, with a skip link in front of them. */
|
|
26
|
+
export declare function PageShell({ header, sidebar, sidebarLabel, footer, children, mainId, skipLinkLabel, }: PageShellProps): import("react").JSX.Element;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { SkipLink } from "../SkipLink/SkipLink.js";
|
|
3
|
+
import PageShell_module from "./PageShell.module.js";
|
|
4
|
+
function PageShell({ header, sidebar, sidebarLabel, footer, children, mainId = 'main', skipLinkLabel }) {
|
|
5
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
6
|
+
className: PageShell_module.root,
|
|
7
|
+
"data-has-sidebar": sidebar ? '' : void 0,
|
|
8
|
+
children: [
|
|
9
|
+
/*#__PURE__*/ jsx(SkipLink, {
|
|
10
|
+
targetId: mainId,
|
|
11
|
+
children: skipLinkLabel
|
|
12
|
+
}),
|
|
13
|
+
header ? /*#__PURE__*/ jsx("header", {
|
|
14
|
+
className: PageShell_module.header,
|
|
15
|
+
children: header
|
|
16
|
+
}) : null,
|
|
17
|
+
sidebar ? /*#__PURE__*/ jsx("aside", {
|
|
18
|
+
className: PageShell_module.sidebar,
|
|
19
|
+
"aria-label": sidebarLabel,
|
|
20
|
+
children: sidebar
|
|
21
|
+
}) : null,
|
|
22
|
+
/*#__PURE__*/ jsx("main", {
|
|
23
|
+
id: mainId,
|
|
24
|
+
className: PageShell_module.main,
|
|
25
|
+
tabIndex: -1,
|
|
26
|
+
children: children
|
|
27
|
+
}),
|
|
28
|
+
footer ? /*#__PURE__*/ jsx("footer", {
|
|
29
|
+
className: PageShell_module.footer,
|
|
30
|
+
children: footer
|
|
31
|
+
}) : null
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export { PageShell };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.root-GtYdg {
|
|
2
|
+
grid-template: "header"
|
|
3
|
+
"sidebar"
|
|
4
|
+
"main" 1fr
|
|
5
|
+
"footer"
|
|
6
|
+
/ minmax(0, 1fr);
|
|
7
|
+
min-height: 100dvh;
|
|
8
|
+
display: grid;
|
|
9
|
+
position: relative;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.header-YzERL {
|
|
13
|
+
padding: var(--space-3) var(--space-4);
|
|
14
|
+
border-bottom: 1px solid var(--color-border);
|
|
15
|
+
grid-area: header;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.sidebar-acwxu {
|
|
19
|
+
padding: var(--space-4);
|
|
20
|
+
border-bottom: 1px solid var(--color-border);
|
|
21
|
+
grid-area: sidebar;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.main-A7fFb {
|
|
25
|
+
padding: var(--space-5) var(--space-4);
|
|
26
|
+
grid-area: main;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.main-A7fFb:focus-visible {
|
|
30
|
+
outline-offset: calc(var(--focus-ring-width) * -1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.footer-O0lU7 {
|
|
34
|
+
padding: var(--space-3) var(--space-4);
|
|
35
|
+
border-top: 1px solid var(--color-border);
|
|
36
|
+
grid-area: footer;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@media (width >= 48rem) {
|
|
40
|
+
.root-GtYdg[data-has-sidebar] {
|
|
41
|
+
grid-template: "header header"
|
|
42
|
+
"sidebar main" 1fr
|
|
43
|
+
"footer footer"
|
|
44
|
+
/ 16rem minmax(0, 1fr);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.sidebar-acwxu {
|
|
48
|
+
border-inline-end: 1px solid var(--color-border);
|
|
49
|
+
border-bottom: 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.main-A7fFb {
|
|
53
|
+
padding-inline: var(--space-5);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type FieldFrameProps } from '../Field/Field.js';
|
|
3
|
+
export interface RadioOption {
|
|
4
|
+
/** Submitted with the form, and what `value`/`onValueChange` speak in. */
|
|
5
|
+
value: string;
|
|
6
|
+
/** The visible text, and that one radio's accessible name. */
|
|
7
|
+
label: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface RadioGroupProps extends FieldFrameProps {
|
|
11
|
+
/** Names the group. Rendered as a plain element, not a `<label>` — see the note below. */
|
|
12
|
+
label: string;
|
|
13
|
+
options: RadioOption[];
|
|
14
|
+
/** Sits under the options and joins the group's `aria-describedby`. */
|
|
15
|
+
description?: ReactNode;
|
|
16
|
+
/** Controlled. Pair it with `onValueChange`; use `defaultValue` for an uncontrolled group. */
|
|
17
|
+
value?: string;
|
|
18
|
+
defaultValue?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The newly chosen option's value. One argument, as on every other control in the tier:
|
|
21
|
+
* Base UI calls its own callback `(value, eventDetails)` and this wrapper drops the second,
|
|
22
|
+
* which no consumer can read without a cast.
|
|
23
|
+
*/
|
|
24
|
+
onValueChange?: (value: string) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Called when the focus leaves a radio. A form library marks a field touched on blur, and the
|
|
27
|
+
* adapter in `FormExample` spreads one `onBlur` onto every control; without this prop the
|
|
28
|
+
* group silently dropped it. React's blur bubbles, so moving between the options with the
|
|
29
|
+
* arrow keys fires it too — a form library counts that as touched either way.
|
|
30
|
+
*/
|
|
31
|
+
onBlur?: () => void;
|
|
32
|
+
/** `horizontal` wraps the options along a row; the arrow keys work on both axes either way. */
|
|
33
|
+
orientation?: 'vertical' | 'horizontal';
|
|
34
|
+
}
|
|
35
|
+
export declare function RadioGroup({ label, options, name, description, error, value, defaultValue, onValueChange, onBlur, required, disabled, orientation, }: RadioGroupProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Field } from "@base-ui/react/field";
|
|
3
|
+
import { Radio } from "@base-ui/react/radio";
|
|
4
|
+
import { RadioGroup } from "@base-ui/react/radio-group";
|
|
5
|
+
import { useId } from "react";
|
|
6
|
+
import field_module from "../../styles/field.module.js";
|
|
7
|
+
import { FieldMessages, RequiredMark } from "../Field/Field.js";
|
|
8
|
+
import RadioGroup_module from "./RadioGroup.module.js";
|
|
9
|
+
function RadioGroup_RadioGroup({ label, options, name, description, error, value, defaultValue, onValueChange, onBlur, required = false, disabled = false, orientation = 'vertical' }) {
|
|
10
|
+
const labelId = useId();
|
|
11
|
+
return /*#__PURE__*/ jsxs(Field.Root, {
|
|
12
|
+
className: field_module.frame,
|
|
13
|
+
name: name,
|
|
14
|
+
disabled: disabled,
|
|
15
|
+
invalid: void 0 !== error,
|
|
16
|
+
children: [
|
|
17
|
+
/*#__PURE__*/ jsxs("span", {
|
|
18
|
+
className: field_module.legend,
|
|
19
|
+
id: labelId,
|
|
20
|
+
"data-disabled": disabled ? '' : void 0,
|
|
21
|
+
children: [
|
|
22
|
+
label,
|
|
23
|
+
/*#__PURE__*/ jsx(RequiredMark, {
|
|
24
|
+
when: required
|
|
25
|
+
})
|
|
26
|
+
]
|
|
27
|
+
}),
|
|
28
|
+
/*#__PURE__*/ jsx(RadioGroup, {
|
|
29
|
+
className: field_module.options,
|
|
30
|
+
"data-orientation": orientation,
|
|
31
|
+
"aria-labelledby": labelId,
|
|
32
|
+
value: value,
|
|
33
|
+
defaultValue: defaultValue,
|
|
34
|
+
onValueChange: (nextValue)=>onValueChange?.(nextValue),
|
|
35
|
+
onBlur: onBlur,
|
|
36
|
+
required: required,
|
|
37
|
+
children: options.map((option)=>/*#__PURE__*/ jsx(Field.Item, {
|
|
38
|
+
disabled: option.disabled,
|
|
39
|
+
children: /*#__PURE__*/ jsxs(Field.Label, {
|
|
40
|
+
className: field_module.optionLabel,
|
|
41
|
+
children: [
|
|
42
|
+
/*#__PURE__*/ jsx(Radio.Root, {
|
|
43
|
+
className: [
|
|
44
|
+
field_module.controlBox,
|
|
45
|
+
RadioGroup_module.dot
|
|
46
|
+
].join(' '),
|
|
47
|
+
value: option.value,
|
|
48
|
+
children: /*#__PURE__*/ jsx(Radio.Indicator, {
|
|
49
|
+
className: RadioGroup_module.mark
|
|
50
|
+
})
|
|
51
|
+
}),
|
|
52
|
+
option.label
|
|
53
|
+
]
|
|
54
|
+
})
|
|
55
|
+
}, option.value))
|
|
56
|
+
}),
|
|
57
|
+
/*#__PURE__*/ jsx(FieldMessages, {
|
|
58
|
+
description: description,
|
|
59
|
+
error: error
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export { RadioGroup_RadioGroup as RadioGroup };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface SegmentedOption {
|
|
3
|
+
/** What `value` and `onValueChange` speak in. The empty string is a value like any other. */
|
|
4
|
+
value: string;
|
|
5
|
+
/** The visible text, and the option's accessible name. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Sits before the label. Decorative: it stays out of the accessible name. */
|
|
8
|
+
icon?: ReactNode;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface SegmentedBaseProps {
|
|
12
|
+
options: SegmentedOption[];
|
|
13
|
+
/**
|
|
14
|
+
* Controlled. Pair it with `onValueChange`; use `defaultValue` for an uncontrolled one. A value
|
|
15
|
+
* no option holds shows the first enabled option as chosen, and reports nothing.
|
|
16
|
+
*/
|
|
17
|
+
value?: string;
|
|
18
|
+
/** Leave this and `value` out, or name no option, and the first enabled option is chosen. */
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The newly chosen option's value. One argument, as on every other control in the library, and
|
|
22
|
+
* it fires only for a change: pressing the option already chosen reports nothing.
|
|
23
|
+
*/
|
|
24
|
+
onValueChange?: (value: string) => void;
|
|
25
|
+
size?: 'sm' | 'md';
|
|
26
|
+
}
|
|
27
|
+
interface SegmentedNamedByLabel extends SegmentedBaseProps {
|
|
28
|
+
/** Names the group. One of this and `aria-labelledby` is required. */
|
|
29
|
+
'aria-label': string;
|
|
30
|
+
'aria-labelledby'?: undefined;
|
|
31
|
+
}
|
|
32
|
+
interface SegmentedNamedByElement extends SegmentedBaseProps {
|
|
33
|
+
'aria-label'?: undefined;
|
|
34
|
+
/** The id of the element that names the group. */
|
|
35
|
+
'aria-labelledby': string;
|
|
36
|
+
}
|
|
37
|
+
export type SegmentedProps = SegmentedNamedByLabel | SegmentedNamedByElement;
|
|
38
|
+
/**
|
|
39
|
+
* Choose exactly one of a few options. Each is a toggle button, and the group is one tab stop
|
|
40
|
+
* whose arrow keys, Home and End move focus without changing the choice.
|
|
41
|
+
*
|
|
42
|
+
* Tab lands on the chosen option. Base UI's `ToggleGroup` has no prop for that and roves from the
|
|
43
|
+
* first enabled option, so while focus is outside the group each `Toggle` is told its `tabIndex`.
|
|
44
|
+
* Inside it Base UI roves as usual: an override there would leave the chosen option as a second
|
|
45
|
+
* stop on the way out. A disabled chosen option cannot take focus, so Base UI decides then too,
|
|
46
|
+
* and inside a `Toolbar` the toolbar owns the stop.
|
|
47
|
+
*/
|
|
48
|
+
export declare function Segmented({ options, value, defaultValue, onValueChange, size, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, }: SegmentedProps): import("react").JSX.Element;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Toggle } from "@base-ui/react/toggle";
|
|
3
|
+
import { ToggleGroup } from "@base-ui/react/toggle-group";
|
|
4
|
+
import { useContext, useState } from "react";
|
|
5
|
+
import { InsideToolbarContext } from "../Toolbar/InsideToolbarContext.js";
|
|
6
|
+
import Segmented_module from "./Segmented.module.js";
|
|
7
|
+
function chosenIndexOf(options, value) {
|
|
8
|
+
const namedIndex = options.findIndex((option)=>option.value === value);
|
|
9
|
+
return -1 === namedIndex ? options.findIndex((option)=>!option.disabled) : namedIndex;
|
|
10
|
+
}
|
|
11
|
+
function Segmented({ options, value, defaultValue, onValueChange, size = 'md', 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }) {
|
|
12
|
+
const insideToolbar = useContext(InsideToolbarContext);
|
|
13
|
+
const [heldValue, setHeldValue] = useState(defaultValue);
|
|
14
|
+
const [focusedValue, setFocusedValue] = useState(null);
|
|
15
|
+
const chosenIndex = chosenIndexOf(options, value ?? heldValue);
|
|
16
|
+
const focusIsInside = options.some((option)=>option.value === focusedValue && !option.disabled);
|
|
17
|
+
const chosenOption = options[chosenIndex];
|
|
18
|
+
const placesTabStop = !insideToolbar && !focusIsInside && chosenOption && !chosenOption.disabled;
|
|
19
|
+
return /*#__PURE__*/ jsx(ToggleGroup, {
|
|
20
|
+
className: Segmented_module.root,
|
|
21
|
+
"data-size": size,
|
|
22
|
+
"aria-label": ariaLabel,
|
|
23
|
+
"aria-labelledby": ariaLabelledBy,
|
|
24
|
+
value: -1 === chosenIndex ? [] : [
|
|
25
|
+
String(chosenIndex)
|
|
26
|
+
],
|
|
27
|
+
onBlur: (event)=>{
|
|
28
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setFocusedValue(null);
|
|
29
|
+
},
|
|
30
|
+
onValueChange: (nextIndexes)=>{
|
|
31
|
+
const nextOption = options[Number(nextIndexes[0] ?? -1)];
|
|
32
|
+
if (!nextOption) return;
|
|
33
|
+
setHeldValue(nextOption.value);
|
|
34
|
+
onValueChange?.(nextOption.value);
|
|
35
|
+
},
|
|
36
|
+
children: options.map((option, index)=>/*#__PURE__*/ jsxs(Toggle, {
|
|
37
|
+
className: Segmented_module.option,
|
|
38
|
+
value: String(index),
|
|
39
|
+
disabled: option.disabled,
|
|
40
|
+
onFocus: ()=>setFocusedValue(option.value),
|
|
41
|
+
...placesTabStop ? {
|
|
42
|
+
tabIndex: index === chosenIndex ? 0 : -1
|
|
43
|
+
} : null,
|
|
44
|
+
children: [
|
|
45
|
+
option.icon ? /*#__PURE__*/ jsx("span", {
|
|
46
|
+
className: Segmented_module.icon,
|
|
47
|
+
"aria-hidden": "true",
|
|
48
|
+
children: option.icon
|
|
49
|
+
}) : null,
|
|
50
|
+
option.label
|
|
51
|
+
]
|
|
52
|
+
}, option.value))
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export { Segmented };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
.root-FcEzI {
|
|
2
|
+
gap: var(--space-1);
|
|
3
|
+
max-width: 100%;
|
|
4
|
+
padding: var(--space-1);
|
|
5
|
+
border: 1px solid var(--color-border-strong);
|
|
6
|
+
border-radius: var(--radius-md);
|
|
7
|
+
background: var(--color-surface-2);
|
|
8
|
+
flex-wrap: wrap;
|
|
9
|
+
display: inline-flex;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.option-l_IQ8 {
|
|
13
|
+
justify-content: center;
|
|
14
|
+
align-items: center;
|
|
15
|
+
gap: var(--space-2);
|
|
16
|
+
min-height: var(--size-touch);
|
|
17
|
+
min-width: var(--size-touch);
|
|
18
|
+
padding: var(--space-1) var(--space-3);
|
|
19
|
+
border-radius: var(--radius-sm);
|
|
20
|
+
color: var(--color-text-muted);
|
|
21
|
+
font-size: var(--text-md);
|
|
22
|
+
font-weight: 500;
|
|
23
|
+
line-height: var(--leading-snug);
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
transition-property: background-color, color;
|
|
26
|
+
transition-duration: var(--motion-duration-1);
|
|
27
|
+
transition-timing-function: var(--motion-ease);
|
|
28
|
+
-webkit-tap-highlight-color: transparent;
|
|
29
|
+
background: none;
|
|
30
|
+
border: 0;
|
|
31
|
+
flex: auto;
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.root-FcEzI[data-size="sm"] .option-l_IQ8 {
|
|
36
|
+
min-width: 2.5rem;
|
|
37
|
+
min-height: 2.5rem;
|
|
38
|
+
font-size: var(--text-sm);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@media (hover: hover) {
|
|
42
|
+
.option-l_IQ8:hover:not([data-disabled], [data-pressed]) {
|
|
43
|
+
background: var(--color-surface-3);
|
|
44
|
+
color: var(--color-text);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.option-l_IQ8[data-pressed] {
|
|
49
|
+
background: var(--color-accent);
|
|
50
|
+
color: var(--color-accent-text);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@media (forced-colors: active) {
|
|
54
|
+
.option-l_IQ8[data-pressed] {
|
|
55
|
+
forced-color-adjust: none;
|
|
56
|
+
color: highlighttext;
|
|
57
|
+
background: highlight;
|
|
58
|
+
outline-color: canvastext;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.option-l_IQ8[data-disabled] {
|
|
63
|
+
cursor: not-allowed;
|
|
64
|
+
opacity: .45;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.icon-kkAqg {
|
|
68
|
+
display: inline-flex;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.icon-kkAqg > svg {
|
|
72
|
+
width: 1rem;
|
|
73
|
+
height: 1rem;
|
|
74
|
+
}
|
|
75
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type FieldFrameProps } from '../Field/Field.js';
|
|
3
|
+
import type { PopupAlign, PopupSide } from '../Popover/Popover.js';
|
|
4
|
+
export interface SelectOption {
|
|
5
|
+
/** Submitted with the form, and what `value`/`onValueChange` speak in. */
|
|
6
|
+
value: string;
|
|
7
|
+
/** The visible text, on the option and — once chosen — on the trigger. */
|
|
8
|
+
label: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface SelectProps extends FieldFrameProps {
|
|
12
|
+
/** The visible label, and the trigger's accessible name. */
|
|
13
|
+
label: string;
|
|
14
|
+
options: SelectOption[];
|
|
15
|
+
/** Sits under the trigger and joins its `aria-describedby`. */
|
|
16
|
+
description?: ReactNode;
|
|
17
|
+
/** Shown on the trigger while nothing is chosen. */
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
/**
|
|
20
|
+
* `null` is a real state — a select that has been cleared — so it is in the type rather than
|
|
21
|
+
* narrowed away. Use with `onValueChange` for a controlled select; `defaultValue` otherwise.
|
|
22
|
+
*/
|
|
23
|
+
value?: string | null;
|
|
24
|
+
defaultValue?: string | null;
|
|
25
|
+
/**
|
|
26
|
+
* The chosen value, or `null` once the select has been cleared. One argument, as on every
|
|
27
|
+
* other control in the tier: Base UI calls its own callback `(value, eventDetails)` and this
|
|
28
|
+
* wrapper drops the second, which no consumer can read without a cast.
|
|
29
|
+
*/
|
|
30
|
+
onValueChange?: (value: string | null) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Called when the focus leaves the trigger — including when the popup opens and takes it.
|
|
33
|
+
* A form library marks a field touched on blur, and the adapter in `FormExample` spreads one
|
|
34
|
+
* `onBlur` onto every control; without this prop the select silently dropped it.
|
|
35
|
+
*/
|
|
36
|
+
onBlur?: () => void;
|
|
37
|
+
side?: PopupSide;
|
|
38
|
+
align?: PopupAlign;
|
|
39
|
+
/** Gap between the trigger and the popup, in pixels. */
|
|
40
|
+
sideOffset?: number;
|
|
41
|
+
}
|
|
42
|
+
export declare function Select({ label, options, name, description, error, required, disabled, placeholder, value, defaultValue, onValueChange, onBlur, side, align, sideOffset, }: SelectProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Field } from "@base-ui/react/field";
|
|
3
|
+
import { Select } from "@base-ui/react/select";
|
|
4
|
+
import { CheckIcon } from "../../icons/CheckIcon.js";
|
|
5
|
+
import { ChevronDownIcon } from "../../icons/ChevronDownIcon.js";
|
|
6
|
+
import field_module from "../../styles/field.module.js";
|
|
7
|
+
import popup_module from "../../styles/popup.module.js";
|
|
8
|
+
import { FieldMessages, RequiredMark } from "../Field/Field.js";
|
|
9
|
+
import Select_module from "./Select.module.js";
|
|
10
|
+
function Select_Select({ label, options, name, description, error, required = false, disabled = false, placeholder = 'Select…', value, defaultValue, onValueChange, onBlur, side = 'bottom', align = 'start', sideOffset = 8 }) {
|
|
11
|
+
return /*#__PURE__*/ jsxs(Field.Root, {
|
|
12
|
+
className: field_module.frame,
|
|
13
|
+
name: name,
|
|
14
|
+
disabled: disabled,
|
|
15
|
+
invalid: void 0 !== error,
|
|
16
|
+
children: [
|
|
17
|
+
/*#__PURE__*/ jsxs(Field.Label, {
|
|
18
|
+
className: field_module.label,
|
|
19
|
+
nativeLabel: false,
|
|
20
|
+
render: /*#__PURE__*/ jsx("span", {}),
|
|
21
|
+
children: [
|
|
22
|
+
label,
|
|
23
|
+
/*#__PURE__*/ jsx(RequiredMark, {
|
|
24
|
+
when: required
|
|
25
|
+
})
|
|
26
|
+
]
|
|
27
|
+
}),
|
|
28
|
+
/*#__PURE__*/ jsxs(Select.Root, {
|
|
29
|
+
items: options,
|
|
30
|
+
value: value,
|
|
31
|
+
defaultValue: defaultValue,
|
|
32
|
+
onValueChange: (nextValue)=>onValueChange?.(nextValue),
|
|
33
|
+
required: required,
|
|
34
|
+
children: [
|
|
35
|
+
/*#__PURE__*/ jsxs(Select.Trigger, {
|
|
36
|
+
className: [
|
|
37
|
+
field_module.control,
|
|
38
|
+
Select_module.trigger
|
|
39
|
+
].join(' '),
|
|
40
|
+
onBlur: onBlur,
|
|
41
|
+
children: [
|
|
42
|
+
/*#__PURE__*/ jsx(Select.Value, {
|
|
43
|
+
className: Select_module.value,
|
|
44
|
+
placeholder: placeholder
|
|
45
|
+
}),
|
|
46
|
+
/*#__PURE__*/ jsx(Select.Icon, {
|
|
47
|
+
className: Select_module.icon,
|
|
48
|
+
children: /*#__PURE__*/ jsx(ChevronDownIcon, {})
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
}),
|
|
52
|
+
/*#__PURE__*/ jsx(Select.Portal, {
|
|
53
|
+
children: /*#__PURE__*/ jsx(Select.Positioner, {
|
|
54
|
+
className: popup_module.layer,
|
|
55
|
+
side: side,
|
|
56
|
+
align: align,
|
|
57
|
+
sideOffset: sideOffset,
|
|
58
|
+
alignItemWithTrigger: false,
|
|
59
|
+
children: /*#__PURE__*/ jsx(Select.Popup, {
|
|
60
|
+
className: popup_module.surface,
|
|
61
|
+
"data-popup": "select",
|
|
62
|
+
children: /*#__PURE__*/ jsx(Select.List, {
|
|
63
|
+
children: options.map((option)=>/*#__PURE__*/ jsxs(Select.Item, {
|
|
64
|
+
className: Select_module.option,
|
|
65
|
+
value: option.value,
|
|
66
|
+
disabled: option.disabled,
|
|
67
|
+
children: [
|
|
68
|
+
/*#__PURE__*/ jsx(Select.ItemText, {
|
|
69
|
+
children: option.label
|
|
70
|
+
}),
|
|
71
|
+
/*#__PURE__*/ jsx(Select.ItemIndicator, {
|
|
72
|
+
className: Select_module.indicator,
|
|
73
|
+
children: /*#__PURE__*/ jsx(CheckIcon, {})
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
}, option.value))
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
]
|
|
82
|
+
}),
|
|
83
|
+
/*#__PURE__*/ jsx(FieldMessages, {
|
|
84
|
+
description: description,
|
|
85
|
+
error: error
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export { Select_Select as Select };
|