@xds/solid 1.0.1 → 1.1.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/dom/Accordion.js +3 -2
- package/dist/dom/Avatar.js +17 -13
- package/dist/dom/AvatarStack.js +17 -13
- package/dist/dom/Badge.js +12 -10
- package/dist/dom/Banner.js +25 -15
- package/dist/dom/Button.js +10 -3
- package/dist/dom/Card.js +31 -26
- package/dist/dom/Checkbox.js +49 -24
- package/dist/dom/Chip.js +21 -17
- package/dist/dom/ChipBar.js +17 -13
- package/dist/dom/CountBadge.js +28 -23
- package/dist/dom/DatePicker.js +13 -7
- package/dist/dom/DateRangePicker.js +16 -10
- package/dist/dom/Dialog.js +3 -2
- package/dist/dom/Divider.js +12 -10
- package/dist/dom/EmptyState.js +14 -11
- package/dist/dom/Icon.js +30 -19
- package/dist/dom/IconButton.js +10 -3
- package/dist/dom/Labels.js +26 -0
- package/dist/dom/ListRow.js +34 -28
- package/dist/dom/MediaCard.js +32 -23
- package/dist/dom/Menu.js +3 -1
- package/dist/dom/ProgressBar.js +27 -15
- package/dist/dom/RadioGroup.js +44 -23
- package/dist/dom/SearchField.js +58 -32
- package/dist/dom/SectionHeader.js +17 -10
- package/dist/dom/SegmentedControl.js +33 -19
- package/dist/dom/Select.js +18 -5
- package/dist/dom/Sidebar.js +17 -13
- package/dist/dom/Skeleton.js +15 -13
- package/dist/dom/Slider.js +15 -7
- package/dist/dom/Spinner.js +23 -17
- package/dist/dom/Switch.js +49 -24
- package/dist/dom/Tabs.js +16 -6
- package/dist/dom/Text.js +6 -3
- package/dist/dom/TextField.js +37 -19
- package/dist/dom/Thumbnail.js +21 -14
- package/dist/dom/Toast.js +19 -20
- package/dist/dom/Tooltip.js +10 -6
- package/dist/dom/controllable.js +44 -0
- package/dist/dom/index.js +2 -1
- package/dist/dom/preview.js +2 -0
- package/dist/dom/root.js +16 -4
- package/dist/dom/trigger.js +5 -3
- package/dist/source/Accordion.jsx +3 -2
- package/dist/source/Avatar.d.ts +1 -1
- package/dist/source/Avatar.jsx +2 -1
- package/dist/source/AvatarStack.d.ts +1 -1
- package/dist/source/AvatarStack.jsx +2 -1
- package/dist/source/Badge.d.ts +1 -1
- package/dist/source/Badge.jsx +2 -1
- package/dist/source/Banner.d.ts +1 -1
- package/dist/source/Banner.jsx +5 -2
- package/dist/source/Button.d.ts +5 -1
- package/dist/source/Button.jsx +5 -2
- package/dist/source/Card.d.ts +1 -1
- package/dist/source/Card.jsx +3 -2
- package/dist/source/Checkbox.d.ts +10 -4
- package/dist/source/Checkbox.jsx +18 -6
- package/dist/source/Chip.d.ts +1 -1
- package/dist/source/Chip.jsx +2 -1
- package/dist/source/ChipBar.d.ts +1 -1
- package/dist/source/ChipBar.jsx +2 -1
- package/dist/source/CountBadge.d.ts +1 -1
- package/dist/source/CountBadge.jsx +3 -2
- package/dist/source/DatePicker.jsx +13 -7
- package/dist/source/DateRangePicker.jsx +16 -10
- package/dist/source/Dialog.jsx +3 -2
- package/dist/source/Divider.d.ts +1 -1
- package/dist/source/Divider.jsx +2 -1
- package/dist/source/EmptyState.d.ts +1 -1
- package/dist/source/EmptyState.jsx +2 -1
- package/dist/source/Icon.d.ts +1 -1
- package/dist/source/Icon.jsx +2 -1
- package/dist/source/IconButton.d.ts +5 -1
- package/dist/source/IconButton.jsx +5 -2
- package/dist/source/Labels.d.ts +17 -0
- package/dist/source/Labels.jsx +11 -0
- package/dist/source/ListRow.d.ts +1 -1
- package/dist/source/ListRow.jsx +3 -2
- package/dist/source/MediaCard.d.ts +1 -1
- package/dist/source/MediaCard.jsx +3 -2
- package/dist/source/Menu.d.ts +1 -1
- package/dist/source/Menu.jsx +3 -1
- package/dist/source/ProgressBar.d.ts +1 -1
- package/dist/source/ProgressBar.jsx +2 -1
- package/dist/source/RadioGroup.d.ts +5 -2
- package/dist/source/RadioGroup.jsx +18 -5
- package/dist/source/SearchField.d.ts +11 -3
- package/dist/source/SearchField.jsx +26 -12
- package/dist/source/SectionHeader.d.ts +1 -1
- package/dist/source/SectionHeader.jsx +2 -1
- package/dist/source/SegmentedControl.d.ts +4 -3
- package/dist/source/SegmentedControl.jsx +16 -5
- package/dist/source/Select.d.ts +4 -1
- package/dist/source/Select.jsx +16 -5
- package/dist/source/Sidebar.d.ts +1 -1
- package/dist/source/Sidebar.jsx +2 -1
- package/dist/source/Skeleton.jsx +2 -2
- package/dist/source/Slider.d.ts +2 -2
- package/dist/source/Slider.jsx +14 -6
- package/dist/source/Spinner.d.ts +1 -1
- package/dist/source/Spinner.jsx +2 -1
- package/dist/source/Switch.d.ts +10 -4
- package/dist/source/Switch.jsx +18 -6
- package/dist/source/Tabs.d.ts +2 -2
- package/dist/source/Tabs.jsx +16 -5
- package/dist/source/Text.d.ts +1 -1
- package/dist/source/Text.jsx +2 -1
- package/dist/source/TextField.d.ts +12 -3
- package/dist/source/TextField.jsx +24 -9
- package/dist/source/Thumbnail.d.ts +1 -1
- package/dist/source/Thumbnail.jsx +2 -1
- package/dist/source/Toast.d.ts +1 -1
- package/dist/source/Toast.jsx +2 -1
- package/dist/source/Tooltip.jsx +4 -3
- package/dist/source/controllable.d.ts +30 -0
- package/dist/source/controllable.js +30 -0
- package/dist/source/index.d.ts +1 -0
- package/dist/source/index.js +1 -0
- package/dist/source/preview.jsx +2 -1
- package/dist/source/root.d.ts +14 -4
- package/dist/source/root.js +7 -2
- package/dist/source/trigger.d.ts +4 -2
- package/dist/source/trigger.js +2 -2
- package/package.json +3 -3
- package/styles.css +4 -0
- package/tailwind.css +1 -1
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { type SearchFieldBaseProps } from "@xds/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
3
|
+
import { type RootProps } from "./root.ts";
|
|
3
4
|
export type SearchFieldProps = SearchFieldBaseProps & RootProps & {
|
|
4
|
-
onChange
|
|
5
|
+
onChange?: (value: string) => void;
|
|
6
|
+
onFocus?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
|
|
7
|
+
onBlur?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
|
|
8
|
+
/** The native input. */
|
|
9
|
+
ref?: JSX.Ref<HTMLInputElement>;
|
|
5
10
|
/** Called with the query on Enter, or on the search key of a software keyboard. */
|
|
6
11
|
onSubmit?: (value: string) => void;
|
|
7
12
|
};
|
|
@@ -11,5 +16,8 @@ export type SearchFieldProps = SearchFieldBaseProps & RootProps & {
|
|
|
11
16
|
*
|
|
12
17
|
* Use it to filter or search what is on the screen. For a value that is saved with a form,
|
|
13
18
|
* use a TextField, which has a visible label.
|
|
19
|
+
*
|
|
20
|
+
* Without `value` it keeps its own query, from `defaultValue`. A read-only one has no control
|
|
21
|
+
* that clears it, and Escape leaves it as it is.
|
|
14
22
|
*/
|
|
15
|
-
export declare function SearchField(props: SearchFieldProps):
|
|
23
|
+
export declare function SearchField(props: SearchFieldProps): JSX.Element;
|
|
@@ -1,35 +1,49 @@
|
|
|
1
|
-
import { classes, rootPart } from "@xds/core";
|
|
1
|
+
import { classes, isControlled, rootPart } from "@xds/core";
|
|
2
2
|
import { Show } from "solid-js";
|
|
3
|
+
import { composeRefs, createControllable, resetWithForm } from "./controllable.js";
|
|
3
4
|
import { keepValue } from "./controlled.js";
|
|
4
5
|
import { Icon } from "./Icon.jsx";
|
|
6
|
+
import { useLabels } from "./Labels.jsx";
|
|
7
|
+
import { rootAttributes } from "./root.js";
|
|
5
8
|
const ROOT = rootPart("SearchField");
|
|
6
9
|
export function SearchField(props) {
|
|
10
|
+
const labels = useLabels();
|
|
7
11
|
let input;
|
|
8
|
-
|
|
12
|
+
const controlled = () => isControlled(props, "value");
|
|
13
|
+
const defaultValue = () => props.defaultValue ?? "";
|
|
14
|
+
const value = createControllable({
|
|
15
|
+
controlled,
|
|
16
|
+
value: () => props.value ?? "",
|
|
17
|
+
defaultValue,
|
|
18
|
+
onChange: (next) => props.onChange?.(next),
|
|
19
|
+
});
|
|
20
|
+
resetWithForm(() => input, controlled, value.reset);
|
|
21
|
+
const clearable = () => value.value() !== "" && !props.disabled && !props.readOnly;
|
|
22
|
+
return (<div {...rootAttributes(props)} class={classes("xds-text-field", ROOT, props.class)} style={props.style}>
|
|
9
23
|
<div class="xds-text-field__control xds-text-field__control--pill xds-text-field__group">
|
|
10
24
|
<span class="xds-text-field__slot xds-text-field__slot--leading">
|
|
11
25
|
<Icon name="search" size="sm"/>
|
|
12
26
|
</span>
|
|
13
|
-
<input ref={(element) => (input = element)} type="text" role="searchbox" class="xds-text-field__input" aria-label={props.label} enterkeyhint="search" placeholder={props.placeholder} value={
|
|
14
|
-
|
|
27
|
+
<input ref={composeRefs((element) => (input = element), () => props.ref)} type="text" role="searchbox" class="xds-text-field__input" aria-label={props.label} enterkeyhint="search" placeholder={props.placeholder} value={value.value()} defaultValue={controlled() ? value.value() : defaultValue()} disabled={props.disabled} readonly={props.readOnly} data-uses-escape={clearable() ? "" : undefined} onInput={(event) => {
|
|
28
|
+
value.set(event.currentTarget.value);
|
|
15
29
|
if (!event.isComposing)
|
|
16
|
-
keepValue(event.currentTarget,
|
|
17
|
-
}} onCompositionEnd={(event) => keepValue(event.currentTarget, () => props.
|
|
30
|
+
keepValue(event.currentTarget, value.value);
|
|
31
|
+
}} onCompositionEnd={(event) => keepValue(event.currentTarget, value.value)} onFocus={(event) => props.onFocus?.(event)} onBlur={(event) => props.onBlur?.(event)} onKeyDown={(event) => {
|
|
18
32
|
if (event.isComposing)
|
|
19
33
|
return;
|
|
20
34
|
if (event.key === "Enter" && props.onSubmit) {
|
|
21
35
|
event.preventDefault();
|
|
22
|
-
props.onSubmit(
|
|
36
|
+
props.onSubmit(value.value());
|
|
23
37
|
}
|
|
24
|
-
if (event.key === "Escape" &&
|
|
38
|
+
if (event.key === "Escape" && clearable()) {
|
|
25
39
|
event.stopPropagation();
|
|
26
|
-
|
|
40
|
+
value.set("");
|
|
27
41
|
}
|
|
28
42
|
}}/>
|
|
29
|
-
<Show when={
|
|
43
|
+
<Show when={clearable()}>
|
|
30
44
|
<span class="xds-text-field__slot xds-text-field__slot--trailing">
|
|
31
|
-
<button type="button" aria-label={props.clearLabel ??
|
|
32
|
-
|
|
45
|
+
<button type="button" aria-label={props.clearLabel ?? labels().clear} onClick={() => {
|
|
46
|
+
value.set("");
|
|
33
47
|
input.focus();
|
|
34
48
|
}} class="-me-1 flex size-xds-target-min cursor-pointer items-center justify-center rounded-xds-full hover:text-xds-field-text focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-xds-border-focus focus-visible:outline-solid">
|
|
35
49
|
<Icon name="circle-x" size="sm"/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SectionHeaderBaseProps } from "@xds/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
3
|
export type SectionHeaderProps = SectionHeaderBaseProps & RootProps & {
|
|
4
4
|
/** A link-like action at the end, such as "See all". */
|
|
5
5
|
action?: {
|
|
@@ -3,10 +3,11 @@ import { dynamic } from "@solidjs/web";
|
|
|
3
3
|
import { Show } from "solid-js";
|
|
4
4
|
import { Button } from "./Button.jsx";
|
|
5
5
|
import { Icon } from "./Icon.jsx";
|
|
6
|
+
import { rootAttributes } from "./root.js";
|
|
6
7
|
const ROOT = rootPart("SectionHeader");
|
|
7
8
|
export function SectionHeader(props) {
|
|
8
9
|
const Heading = dynamic(() => `h${props.level ?? 2}`);
|
|
9
|
-
return (<div class={classes(ROOT, SECTION_HEADER_PARTS.root, props.class)} style={props.style}>
|
|
10
|
+
return (<div {...rootAttributes(props)} class={classes(ROOT, SECTION_HEADER_PARTS.root, props.class)} style={props.style}>
|
|
10
11
|
<div class={SECTION_HEADER_PARTS.lead}>
|
|
11
12
|
<Show when={props.icon}>
|
|
12
13
|
{(icon) => (<span class={SECTION_HEADER_PARTS.icon}>
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type SegmentedControlBaseProps } from "@xds/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
3
|
export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> & RootProps & {
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: Value) => void;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* A choice between a few views or modes, all visible at once. The selected segment is outlined
|
|
8
8
|
* as well as filled, so the choice does not depend on telling two greys apart.
|
|
9
9
|
*
|
|
10
|
-
* It is a group of native radio buttons, so the arrow keys move between segments.
|
|
10
|
+
* It is a group of native radio buttons, so the arrow keys move between segments. Without
|
|
11
|
+
* `value` it keeps its own choice, from `defaultValue`, or the first segment.
|
|
11
12
|
*/
|
|
12
13
|
export declare function SegmentedControl<Value extends string>(props: SegmentedControlProps<Value>): import("@solidjs/web").JSX.Element;
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import { classes, rootPart, segmentedControlClass, segmentedControlOptionClass, segmentedControlSegmentClass, } from "@xds/core";
|
|
1
|
+
import { classes, isControlled, rootPart, segmentedControlClass, segmentedControlOptionClass, segmentedControlSegmentClass, } from "@xds/core";
|
|
2
2
|
import { createUniqueId, For } from "solid-js";
|
|
3
|
+
import { createControllable } from "./controllable.js";
|
|
3
4
|
import { keepChecked } from "./controlled.js";
|
|
5
|
+
import { rootAttributes } from "./root.js";
|
|
4
6
|
const ROOT = rootPart("SegmentedControl");
|
|
5
7
|
export function SegmentedControl(props) {
|
|
6
8
|
const name = createUniqueId();
|
|
7
9
|
let group;
|
|
8
|
-
|
|
10
|
+
const value = createControllable({
|
|
11
|
+
controlled: () => isControlled(props, "value"),
|
|
12
|
+
value: () => props.value,
|
|
13
|
+
defaultValue: () => props.defaultValue ?? props.options[0]?.value,
|
|
14
|
+
onChange: (next) => {
|
|
15
|
+
if (next !== undefined)
|
|
16
|
+
props.onChange?.(next);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
return (<div {...rootAttributes(props)} ref={(element) => (group = element)} aria-label={props["aria-label"]} role="radiogroup" class={classes(ROOT, segmentedControlClass(props.fullWidth), props.class)} style={props.style}>
|
|
9
20
|
<For each={props.options}>
|
|
10
21
|
{(option) => (<label class={segmentedControlOptionClass(props.fullWidth)}>
|
|
11
|
-
<input type="radio" name={name} value={option.value} class="peer sr-only" checked={option.value ===
|
|
12
|
-
|
|
22
|
+
<input type="radio" name={name} value={option.value} class="peer sr-only" checked={option.value === value.value()} defaultChecked={option.value === value.value()} onChange={() => {
|
|
23
|
+
value.set(option.value);
|
|
13
24
|
for (const input of group.querySelectorAll("input")) {
|
|
14
|
-
keepChecked(input, () => input.value ===
|
|
25
|
+
keepChecked(input, () => input.value === value.value());
|
|
15
26
|
}
|
|
16
27
|
}}/>
|
|
17
28
|
<span class={segmentedControlSegmentClass}>{option.label}</span>
|
package/dist/source/Select.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { JSX } from "@solidjs/web";
|
|
|
3
3
|
import { type RootProps } from "./root.ts";
|
|
4
4
|
export type { SelectOption } from "@xds/core";
|
|
5
5
|
export type SelectProps<Value extends string = string> = SelectBaseProps<Value> & RootProps & {
|
|
6
|
-
onChange
|
|
6
|
+
onChange?: (value: Value) => void;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* A field for choosing one option from a list too long to show at once. Closed, it looks like a
|
|
@@ -14,5 +14,8 @@ export type SelectProps<Value extends string = string> = SelectBaseProps<Value>
|
|
|
14
14
|
* The field is a button that says it opens a list box and whether the list is open. In the list
|
|
15
15
|
* the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
16
16
|
* selected for assistive technology and marked with a check.
|
|
17
|
+
*
|
|
18
|
+
* Without `value` it keeps its own choice, from `defaultValue`. Given `value`, even as
|
|
19
|
+
* `undefined`, it shows that.
|
|
17
20
|
*/
|
|
18
21
|
export declare function Select<Value extends string = string>(props: SelectProps<Value>): JSX.Element;
|
package/dist/source/Select.jsx
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import { space } from "@xds/tokens";
|
|
2
|
-
import { classes, keepListKeys, readCssPx, selectOptionIds, underlayLayerStyle, } from "@xds/core";
|
|
2
|
+
import { classes, isControlled, keepListKeys, readCssPx, selectOptionIds, underlayLayerStyle, } from "@xds/core";
|
|
3
3
|
import * as select from "@zag-js/select";
|
|
4
4
|
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
5
5
|
import { createMemo, createUniqueId, For, Show } from "solid-js";
|
|
6
|
+
import { createControllable } from "./controllable.js";
|
|
6
7
|
import { Icon } from "./Icon.jsx";
|
|
7
8
|
import { modalPopover } from "./modal-popover.js";
|
|
8
9
|
import { Portal } from "./portal.jsx";
|
|
9
10
|
import { createPresence } from "./presence.js";
|
|
10
|
-
import { withStyle } from "./root.js";
|
|
11
|
+
import { rootAttributes, withStyle } from "./root.js";
|
|
11
12
|
export function Select(props) {
|
|
12
13
|
const id = createUniqueId();
|
|
13
14
|
const valueId = `${id}-value`;
|
|
14
15
|
const descriptionId = `${id}-description`;
|
|
15
16
|
const errorId = `${id}-error`;
|
|
16
17
|
const invalid = () => props.error !== undefined;
|
|
18
|
+
const value = createControllable({
|
|
19
|
+
controlled: () => isControlled(props, "value"),
|
|
20
|
+
value: () => props.value,
|
|
21
|
+
defaultValue: () => props.defaultValue,
|
|
22
|
+
onChange: (next) => {
|
|
23
|
+
if (next !== undefined)
|
|
24
|
+
props.onChange?.(next);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
17
27
|
const collection = createMemo(() => select.collection({
|
|
18
28
|
items: [...props.options],
|
|
19
29
|
itemToValue: (option) => option.value,
|
|
@@ -21,12 +31,13 @@ export function Select(props) {
|
|
|
21
31
|
}));
|
|
22
32
|
const service = useMachine(select.machine, () => ({
|
|
23
33
|
id,
|
|
34
|
+
ids: { root: props.id },
|
|
24
35
|
collection: collection(),
|
|
25
|
-
value:
|
|
36
|
+
value: value.value() === undefined ? [] : [value.value()],
|
|
26
37
|
onValueChange: (details) => {
|
|
27
38
|
const next = details.value[0];
|
|
28
39
|
if (next !== undefined)
|
|
29
|
-
|
|
40
|
+
value.set(next);
|
|
30
41
|
},
|
|
31
42
|
disabled: props.disabled,
|
|
32
43
|
invalid: invalid(),
|
|
@@ -39,7 +50,7 @@ export function Select(props) {
|
|
|
39
50
|
},
|
|
40
51
|
}));
|
|
41
52
|
const api = createMemo(() => select.connect(service, normalizeProps));
|
|
42
|
-
const root = withStyle(() => api().getRootProps(), () => props.style);
|
|
53
|
+
const root = withStyle(() => api().getRootProps(), () => props.style, rootAttributes(props));
|
|
43
54
|
const current = () => select.connect(service, normalizeProps);
|
|
44
55
|
const labelProps = createMemo(() => {
|
|
45
56
|
const { for: _, ...rest } = api().getLabelProps();
|
package/dist/source/Sidebar.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type SidebarBaseProps } from "@xds/core";
|
|
2
2
|
import type { JSX } from "@solidjs/web";
|
|
3
3
|
import { type Element } from "solid-js";
|
|
4
|
-
import type
|
|
4
|
+
import { type RootProps } from "./root.ts";
|
|
5
5
|
export type { SidebarItem, SidebarSection } from "@xds/core";
|
|
6
6
|
export type SidebarProps<Value extends string = string> = SidebarBaseProps<Value> & RootProps & {
|
|
7
7
|
onChange: (value: Value) => void;
|
package/dist/source/Sidebar.jsx
CHANGED
|
@@ -2,13 +2,14 @@ import { classes, rootPart, SIDEBAR_PARTS, sidebarClass, sidebarCount, sidebarIc
|
|
|
2
2
|
import { createMemo, createUniqueId, For, Show } from "solid-js";
|
|
3
3
|
import { Icon } from "./Icon.jsx";
|
|
4
4
|
import { PlaceRow } from "./ListRow.jsx";
|
|
5
|
+
import { rootAttributes } from "./root.js";
|
|
5
6
|
import { TooltipBeside } from "./Tooltip.jsx";
|
|
6
7
|
import { withTrigger } from "./trigger.js";
|
|
7
8
|
const ROOT = rootPart("Sidebar");
|
|
8
9
|
export function Sidebar(props) {
|
|
9
10
|
const id = createUniqueId();
|
|
10
11
|
const collapsed = () => props.collapsed ?? false;
|
|
11
|
-
return (<nav aria-label={props.label} class={classes(ROOT, sidebarClass(collapsed()), props.class)} style={props.style}>
|
|
12
|
+
return (<nav {...rootAttributes(props)} aria-label={props.label} class={classes(ROOT, sidebarClass(collapsed()), props.class)} style={props.style}>
|
|
12
13
|
<Show when={props.header}>
|
|
13
14
|
{(header) => <div class={SIDEBAR_PARTS.edge}>{header()}</div>}
|
|
14
15
|
</Show>
|
package/dist/source/Skeleton.jsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { classes, rootPart, skeletonClass, skeletonSize, } from "@xds/core";
|
|
2
2
|
import { useDefaults } from "./Defaults.jsx";
|
|
3
|
-
import { layStyle } from "./root.js";
|
|
3
|
+
import { layStyle, rootAttributes } from "./root.js";
|
|
4
4
|
const ROOT = rootPart("Skeleton");
|
|
5
5
|
export function Skeleton(props) {
|
|
6
6
|
const defaults = useDefaults("Skeleton");
|
|
7
7
|
const shape = () => props.shape ?? defaults().shape;
|
|
8
|
-
return (<span aria-hidden="true" class={classes(ROOT, skeletonClass(shape()), props.class)} style={layStyle(skeletonSize({ shape: shape(), width: props.width, height: props.height }), props.style)}/>);
|
|
8
|
+
return (<span {...rootAttributes(props)} aria-hidden="true" class={classes(ROOT, skeletonClass(shape()), props.class)} style={layStyle(skeletonSize({ shape: shape(), width: props.width, height: props.height }), props.style)}/>);
|
|
9
9
|
}
|
package/dist/source/Slider.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type SliderBaseProps } from "@xds/core";
|
|
2
2
|
import { type RootProps } from "./root.ts";
|
|
3
3
|
export type SliderProps = SliderBaseProps & RootProps & {
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: number) => void;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Picks a number in a range by dragging the thumb, or by pressing the track where it should
|
|
8
8
|
* go. The values snap to `step`.
|
|
9
9
|
*
|
|
10
10
|
* It is a slider named by its label with its value, minimum and maximum, and each arrow key
|
|
11
|
-
* moves it one step.
|
|
11
|
+
* moves it one step. Without `value` it keeps its own, from `defaultValue`, or `min`.
|
|
12
12
|
*/
|
|
13
13
|
export declare function Slider(props: SliderProps): import("@solidjs/web").JSX.Element;
|
package/dist/source/Slider.jsx
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
import { classes, focusThumbOnPress, sliderArrowValue, sliderPageSize, sliderValueText, } from "@xds/core";
|
|
1
|
+
import { classes, focusThumbOnPress, isControlled, sliderArrowValue, sliderPageSize, sliderValueText, } from "@xds/core";
|
|
2
2
|
import * as slider from "@zag-js/slider";
|
|
3
3
|
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
4
4
|
import { createMemo, createUniqueId, Show } from "solid-js";
|
|
5
|
-
import {
|
|
5
|
+
import { createControllable } from "./controllable.js";
|
|
6
|
+
import { rootAttributes, withStyle } from "./root.js";
|
|
6
7
|
export function Slider(props) {
|
|
7
8
|
const id = createUniqueId();
|
|
8
9
|
const min = () => props.min ?? 0;
|
|
9
10
|
const max = () => props.max ?? 100;
|
|
10
11
|
const step = () => props.step ?? 1;
|
|
11
12
|
const pageSize = () => sliderPageSize({ min: min(), max: max(), step: step() });
|
|
13
|
+
const value = createControllable({
|
|
14
|
+
controlled: () => isControlled(props, "value"),
|
|
15
|
+
value: () => props.value ?? min(),
|
|
16
|
+
defaultValue: () => props.defaultValue ?? min(),
|
|
17
|
+
onChange: (next) => props.onChange?.(next),
|
|
18
|
+
});
|
|
12
19
|
const service = useMachine(slider.machine, () => ({
|
|
13
20
|
id,
|
|
21
|
+
ids: { root: props.id },
|
|
14
22
|
name: props.name,
|
|
15
|
-
value: [
|
|
16
|
-
onValueChange: (details) =>
|
|
23
|
+
value: [value.value()],
|
|
24
|
+
onValueChange: (details) => value.set(details.value[0] ?? min()),
|
|
17
25
|
min: min(),
|
|
18
26
|
max: max(),
|
|
19
27
|
step: step(),
|
|
@@ -23,7 +31,7 @@ export function Slider(props) {
|
|
|
23
31
|
getAriaValueText: (details) => sliderValueText(details.value, props.locale),
|
|
24
32
|
}));
|
|
25
33
|
const api = createMemo(() => slider.connect(service, normalizeProps));
|
|
26
|
-
const root = withStyle(() => api().getRootProps(), () => props.style);
|
|
34
|
+
const root = withStyle(() => api().getRootProps(), () => props.style, rootAttributes(props));
|
|
27
35
|
const thumb = mergeProps(() => api().getThumbProps({ index: 0 }), {
|
|
28
36
|
draggable: "false",
|
|
29
37
|
onKeyDown: (event) => {
|
|
@@ -57,7 +65,7 @@ export function Slider(props) {
|
|
|
57
65
|
<Show when={props.showValue}>
|
|
58
66
|
|
|
59
67
|
<output {...api().getValueTextProps()} aria-live="off" class="xds-slider__output">
|
|
60
|
-
{sliderValueText(api().value[0] ??
|
|
68
|
+
{sliderValueText(api().value[0] ?? value.value(), props.locale)}
|
|
61
69
|
</output>
|
|
62
70
|
</Show>
|
|
63
71
|
<div {...control} class="xds-slider__control">
|
package/dist/source/Spinner.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SpinnerBaseProps } from "@xds/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
3
|
export type SpinnerProps = SpinnerBaseProps & RootProps;
|
|
4
4
|
/**
|
|
5
5
|
* Says that something is in progress and how long is unknown. Takes the color of the text around
|
package/dist/source/Spinner.jsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { classes, rootPart, spinnerClass } from "@xds/core";
|
|
2
2
|
import { useDefaults } from "./Defaults.jsx";
|
|
3
|
+
import { rootAttributes } from "./root.js";
|
|
3
4
|
const ROOT = rootPart("Spinner");
|
|
4
5
|
export function Spinner(props) {
|
|
5
6
|
const defaults = useDefaults("Spinner");
|
|
6
|
-
return (<span class={classes(ROOT, "inline-flex shrink-0", props.class)} style={props.style} role={props.label ? "status" : undefined} aria-label={props.label || undefined} aria-hidden={props.label ? undefined : "true"}>
|
|
7
|
+
return (<span {...rootAttributes(props)} class={classes(ROOT, "inline-flex shrink-0", props.class)} style={props.style} role={props.label ? "status" : undefined} aria-label={props.label || undefined} aria-hidden={props.label ? undefined : "true"}>
|
|
7
8
|
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" class={spinnerClass(props.size ?? defaults().size)}>
|
|
8
9
|
<circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" opacity="0.25"/>
|
|
9
10
|
<path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" stroke-width="3" stroke-linecap="round"/>
|
package/dist/source/Switch.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { type SwitchBaseProps } from "@xds/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
3
|
+
import { type RootProps } from "./root.ts";
|
|
3
4
|
export type SwitchProps = SwitchBaseProps & RootProps & {
|
|
4
|
-
onChange
|
|
5
|
+
onChange?: (checked: boolean) => void;
|
|
6
|
+
onFocus?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
|
|
7
|
+
onBlur?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
|
|
8
|
+
/** The native checkbox, which has the switch role. */
|
|
9
|
+
ref?: JSX.Ref<HTMLInputElement>;
|
|
5
10
|
};
|
|
6
11
|
/**
|
|
7
12
|
* Turns a setting on or off, and takes effect at once. For a choice that is applied later,
|
|
8
13
|
* with a form, use a Checkbox.
|
|
9
14
|
*
|
|
10
15
|
* It is a native checkbox with the switch role, so the keyboard, forms and screen readers
|
|
11
|
-
* treat it as one. The input is hidden and the track is drawn beside it.
|
|
16
|
+
* treat it as one. The input is hidden and the track is drawn beside it. Without `checked` it
|
|
17
|
+
* keeps its own state, from `defaultChecked`.
|
|
12
18
|
*/
|
|
13
|
-
export declare function Switch(props: SwitchProps):
|
|
19
|
+
export declare function Switch(props: SwitchProps): JSX.Element;
|
package/dist/source/Switch.jsx
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import { classes, rootPart, switchClass, switchLabelClass, switchThumbClass, switchTrackClass, } from "@xds/core";
|
|
1
|
+
import { classes, isControlled, rootPart, switchClass, switchLabelClass, switchThumbClass, switchTrackClass, } from "@xds/core";
|
|
2
2
|
import { Show } from "solid-js";
|
|
3
|
+
import { composeRefs, createControllable, resetWithForm } from "./controllable.js";
|
|
3
4
|
import { keepChecked } from "./controlled.js";
|
|
5
|
+
import { rootAttributes } from "./root.js";
|
|
4
6
|
const ROOT = rootPart("Switch");
|
|
5
7
|
export function Switch(props) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const controlled = () => isControlled(props, "checked");
|
|
9
|
+
const defaultChecked = () => props.defaultChecked ?? false;
|
|
10
|
+
const checked = createControllable({
|
|
11
|
+
controlled,
|
|
12
|
+
value: () => props.checked ?? false,
|
|
13
|
+
defaultValue: defaultChecked,
|
|
14
|
+
onChange: (next) => props.onChange?.(next),
|
|
15
|
+
});
|
|
16
|
+
let input;
|
|
17
|
+
resetWithForm(() => input, controlled, checked.reset);
|
|
18
|
+
return (<label {...rootAttributes(props)} class={classes(ROOT, switchClass, props.class)} style={props.style}>
|
|
19
|
+
<input ref={composeRefs((element) => (input = element), () => props.ref)} type="checkbox" role="switch" aria-checked={checked.value() ? "true" : "false"} aria-label={props["aria-label"]} class="peer sr-only" checked={checked.value()} defaultChecked={controlled() ? checked.value() : defaultChecked()} disabled={props.disabled} onChange={(event) => {
|
|
20
|
+
checked.set(event.currentTarget.checked);
|
|
21
|
+
keepChecked(event.currentTarget, checked.value);
|
|
22
|
+
}} onFocus={(event) => props.onFocus?.(event)} onBlur={(event) => props.onBlur?.(event)}/>
|
|
11
23
|
<span class={switchTrackClass}>
|
|
12
24
|
<span class={switchThumbClass}/>
|
|
13
25
|
</span>
|
package/dist/source/Tabs.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TabsBaseProps } from "@xds/core";
|
|
2
2
|
import { type RootProps } from "./root.ts";
|
|
3
3
|
export type TabsProps<Value extends string> = TabsBaseProps<Value> & RootProps & {
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: Value) => void;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Switches between views inside one screen. For two to four short modes a SegmentedControl is
|
|
@@ -9,6 +9,6 @@ export type TabsProps<Value extends string> = TabsBaseProps<Value> & RootProps &
|
|
|
9
9
|
*
|
|
10
10
|
* The selected tab is underlined as well as darker, so the choice does not depend on color.
|
|
11
11
|
* This is only the row: the app shows the view that matches `value`. The arrow keys move
|
|
12
|
-
* between tabs.
|
|
12
|
+
* between tabs. Without `value` they keep their own, from `defaultValue`, or the first tab.
|
|
13
13
|
*/
|
|
14
14
|
export declare function Tabs<Value extends string>(props: TabsProps<Value>): import("@solidjs/web").JSX.Element;
|
package/dist/source/Tabs.jsx
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
import { classes, tabStopIndex, tabsClass } from "@xds/core";
|
|
1
|
+
import { classes, isControlled, tabStopIndex, tabsClass } from "@xds/core";
|
|
2
2
|
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
3
3
|
import * as tabs from "@zag-js/tabs";
|
|
4
4
|
import { createMemo, createUniqueId, For, Show } from "solid-js";
|
|
5
|
+
import { createControllable } from "./controllable.js";
|
|
5
6
|
import { Icon } from "./Icon.jsx";
|
|
6
|
-
import { withStyle } from "./root.js";
|
|
7
|
+
import { rootAttributes, withStyle } from "./root.js";
|
|
7
8
|
export function Tabs(props) {
|
|
8
9
|
const id = createUniqueId();
|
|
10
|
+
const value = createControllable({
|
|
11
|
+
controlled: () => isControlled(props, "value"),
|
|
12
|
+
value: () => props.value,
|
|
13
|
+
defaultValue: () => props.defaultValue ?? props.items[0]?.value,
|
|
14
|
+
onChange: (next) => {
|
|
15
|
+
if (next !== undefined)
|
|
16
|
+
props.onChange?.(next);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
9
19
|
const service = useMachine(tabs.machine, () => ({
|
|
10
20
|
id,
|
|
11
|
-
|
|
12
|
-
|
|
21
|
+
ids: { root: props.id },
|
|
22
|
+
value: value.value() ?? null,
|
|
23
|
+
onValueChange: (details) => value.set(details.value),
|
|
13
24
|
}));
|
|
14
25
|
const api = createMemo(() => tabs.connect(service, normalizeProps));
|
|
15
|
-
const root = withStyle(() => api().getRootProps(), () => props.style);
|
|
26
|
+
const root = withStyle(() => api().getRootProps(), () => props.style, rootAttributes(props));
|
|
16
27
|
return (<div {...root} class={classes(tabsClass(props.fullWidth), props.class)}>
|
|
17
28
|
<div {...api().getListProps()} aria-label={props.label} class="xds-tabs__list">
|
|
18
29
|
<For each={props.items}>
|
package/dist/source/Text.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TextBaseProps } from "@xds/core";
|
|
2
2
|
import { type ValidComponent } from "@solidjs/web";
|
|
3
3
|
import type { Element } from "solid-js";
|
|
4
|
-
import type
|
|
4
|
+
import { type RootProps } from "./root.ts";
|
|
5
5
|
export type TextProps = TextBaseProps & RootProps & {
|
|
6
6
|
/** The element to render. Pick it for the document outline (`h1`, `h2`, `p`), not for looks. */
|
|
7
7
|
as?: ValidComponent;
|
package/dist/source/Text.jsx
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { classes, rootPart, textClass } from "@xds/core";
|
|
2
2
|
import { dynamic } from "@solidjs/web";
|
|
3
3
|
import { useDefaults } from "./Defaults.jsx";
|
|
4
|
+
import { rootAttributes } from "./root.js";
|
|
4
5
|
const ROOT = rootPart("Text");
|
|
5
6
|
export function Text(props) {
|
|
6
7
|
const Tag = dynamic(() => props.as ?? "p");
|
|
7
8
|
const defaults = useDefaults("Text");
|
|
8
|
-
return (<Tag class={classes(ROOT, textClass({
|
|
9
|
+
return (<Tag {...rootAttributes(props)} class={classes(ROOT, textClass({
|
|
9
10
|
variant: props.variant ?? defaults().variant,
|
|
10
11
|
tone: props.tone ?? defaults().tone,
|
|
11
12
|
}), props.class)} style={props.style}>
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { type TextFieldBaseProps } from "@xds/core";
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
2
3
|
import { type Element } from "solid-js";
|
|
3
|
-
import type
|
|
4
|
+
import { type RootProps } from "./root.ts";
|
|
5
|
+
type Field = HTMLInputElement | HTMLTextAreaElement;
|
|
4
6
|
export type TextFieldProps = TextFieldBaseProps & RootProps & {
|
|
5
|
-
onChange
|
|
7
|
+
onChange?: (value: string) => void;
|
|
8
|
+
onFocus?: JSX.FocusEventHandler<Field, FocusEvent>;
|
|
9
|
+
onBlur?: JSX.FocusEventHandler<Field, FocusEvent>;
|
|
10
|
+
/** The native input, or the text area of a field of several lines. */
|
|
11
|
+
ref?: JSX.Ref<Field>;
|
|
6
12
|
/**
|
|
7
13
|
* Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
|
|
8
14
|
* unless it sets its own.
|
|
@@ -18,5 +24,8 @@ export type TextFieldProps = TextFieldBaseProps & RootProps & {
|
|
|
18
24
|
*
|
|
19
25
|
* An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
|
|
20
26
|
* the person edits the value.
|
|
27
|
+
*
|
|
28
|
+
* Without `value` it keeps its own text, from `defaultValue`.
|
|
21
29
|
*/
|
|
22
|
-
export declare function TextField(props: TextFieldProps):
|
|
30
|
+
export declare function TextField(props: TextFieldProps): JSX.Element;
|
|
31
|
+
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { classes } from "@xds/core";
|
|
1
|
+
import { classes, isControlled } from "@xds/core";
|
|
2
2
|
import { children, createEffect, createUniqueId, onSettled, Show } from "solid-js";
|
|
3
|
+
import { composeRefs, createControllable, resetWithForm } from "./controllable.js";
|
|
3
4
|
import { keepValue } from "./controlled.js";
|
|
5
|
+
import { rootAttributes } from "./root.js";
|
|
4
6
|
export function TextField(props) {
|
|
5
7
|
const id = createUniqueId();
|
|
6
8
|
const descriptionId = `${id}-description`;
|
|
@@ -9,6 +11,15 @@ export function TextField(props) {
|
|
|
9
11
|
const trailing = children(() => props.trailing);
|
|
10
12
|
const invalid = () => props.error !== undefined;
|
|
11
13
|
let input;
|
|
14
|
+
const controlled = () => isControlled(props, "value");
|
|
15
|
+
const defaultValue = () => props.defaultValue ?? "";
|
|
16
|
+
const value = createControllable({
|
|
17
|
+
controlled,
|
|
18
|
+
value: () => props.value ?? "",
|
|
19
|
+
defaultValue,
|
|
20
|
+
onChange: (next) => props.onChange?.(next),
|
|
21
|
+
});
|
|
22
|
+
resetWithForm(() => input, controlled, value.reset);
|
|
12
23
|
onSettled(() => {
|
|
13
24
|
if (input instanceof HTMLTextAreaElement)
|
|
14
25
|
input.setSelectionRange(0, 0);
|
|
@@ -21,8 +32,8 @@ export function TextField(props) {
|
|
|
21
32
|
const shared = (box) => ({
|
|
22
33
|
id,
|
|
23
34
|
class: box ? "xds-text-field__input xds-text-field__control" : "xds-text-field__input",
|
|
24
|
-
value:
|
|
25
|
-
defaultValue:
|
|
35
|
+
value: value.value(),
|
|
36
|
+
defaultValue: controlled() ? value.value() : defaultValue(),
|
|
26
37
|
placeholder: props.placeholder,
|
|
27
38
|
name: props.name,
|
|
28
39
|
maxlength: props.maxLength,
|
|
@@ -30,18 +41,22 @@ export function TextField(props) {
|
|
|
30
41
|
autocomplete: props.autoComplete,
|
|
31
42
|
required: props.required,
|
|
32
43
|
disabled: props.disabled,
|
|
44
|
+
readonly: props.readOnly,
|
|
33
45
|
"aria-invalid": invalid() ? "true" : undefined,
|
|
34
46
|
"aria-errormessage": invalid() ? errorId : undefined,
|
|
35
47
|
"aria-describedby": invalid() ? errorId : props.description ? descriptionId : undefined,
|
|
36
48
|
onInput: (event) => {
|
|
37
|
-
|
|
49
|
+
value.set(event.currentTarget.value);
|
|
38
50
|
if (!event.isComposing)
|
|
39
|
-
keepValue(event.currentTarget,
|
|
51
|
+
keepValue(event.currentTarget, value.value);
|
|
40
52
|
},
|
|
41
|
-
onCompositionEnd: (event) => keepValue(event.currentTarget,
|
|
53
|
+
onCompositionEnd: (event) => keepValue(event.currentTarget, value.value),
|
|
54
|
+
onFocus: (event) => props.onFocus?.(event),
|
|
55
|
+
onBlur: (event) => props.onBlur?.(event),
|
|
42
56
|
});
|
|
43
|
-
const
|
|
44
|
-
|
|
57
|
+
const ref = composeRefs((element) => (input = element), () => props.ref);
|
|
58
|
+
const field = (box) => props.multiline ? (<textarea ref={ref} rows={props.rows ?? 3} {...shared(box)}/>) : (<input ref={ref} type={props.type ?? "text"} {...shared(box)}/>);
|
|
59
|
+
return (<div {...rootAttributes(props)} class={classes("xds-text-field", props.class)} style={props.style}>
|
|
45
60
|
<label for={id} class="xds-text-field__label">
|
|
46
61
|
{props.label}
|
|
47
62
|
</label>
|
|
@@ -68,7 +83,7 @@ export function TextField(props) {
|
|
|
68
83
|
</span>
|
|
69
84
|
<Show when={props.maxLength !== undefined}>
|
|
70
85
|
<span class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums">
|
|
71
|
-
{
|
|
86
|
+
{value.value().length}/{props.maxLength}
|
|
72
87
|
</span>
|
|
73
88
|
</Show>
|
|
74
89
|
</div>
|