@xds/core 1.0.0 → 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/banner.d.ts +4 -1
- package/dist/checkbox.d.ts +4 -1
- package/dist/date-picker.d.ts +10 -4
- package/dist/date-picker.js +5 -4
- package/dist/date-range-picker.d.ts +10 -4
- package/dist/date-range-picker.js +9 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/labels.d.ts +27 -0
- package/dist/labels.js +19 -0
- package/dist/preview/components.d.ts +35 -17
- package/dist/radio-group.d.ts +7 -1
- package/dist/root.d.ts +25 -0
- package/dist/root.js +25 -0
- package/dist/segmented-control.d.ts +4 -1
- package/dist/select.d.ts +7 -1
- package/dist/slider.d.ts +4 -1
- package/dist/switch.d.ts +4 -1
- package/dist/tabs.d.ts +4 -2
- package/dist/text-field.d.ts +19 -3
- package/package.json +2 -2
package/dist/banner.d.ts
CHANGED
|
@@ -25,7 +25,10 @@ export type BannerTone = keyof typeof TONE;
|
|
|
25
25
|
export type BannerBaseProps = {
|
|
26
26
|
tone?: BannerTone;
|
|
27
27
|
title?: string;
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Names the close control for assistive technology. The `dismiss` label of a `Labels` provider
|
|
30
|
+
* unless set.
|
|
31
|
+
*/
|
|
29
32
|
dismissLabel?: string;
|
|
30
33
|
};
|
|
31
34
|
export declare function bannerClass(tone?: BannerTone): string;
|
package/dist/checkbox.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { switchClass as checkboxClass, switchLabelClass as checkboxLabelClass } from "./switch.ts";
|
|
2
2
|
/** Checkbox's props in every framework, short of `onChange`. */
|
|
3
3
|
export type CheckboxBaseProps = {
|
|
4
|
-
|
|
4
|
+
/** Leave it out for a checkbox that keeps its own state, from `defaultChecked`. */
|
|
5
|
+
checked?: boolean;
|
|
6
|
+
/** Whether a checkbox that keeps its own state starts checked. */
|
|
7
|
+
defaultChecked?: boolean;
|
|
5
8
|
/** Shown beside the box. Pressing it toggles too. */
|
|
6
9
|
label?: string;
|
|
7
10
|
/** Names the checkbox for assistive technology when there is no visible label. */
|
package/dist/date-picker.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type DateValue } from "@internationalized/date";
|
|
2
2
|
import type * as datePicker from "@zag-js/date-picker";
|
|
3
|
+
import { type ComponentLabels } from "./labels.ts";
|
|
3
4
|
/** A day of the calendar without a time or a time zone, as `YYYY-MM-DD`. */
|
|
4
5
|
export type IsoDate = string;
|
|
5
6
|
/** DatePicker's props in every framework, short of `onChange`. */
|
|
@@ -21,9 +22,12 @@ export type DatePickerBaseProps = {
|
|
|
21
22
|
/** The name the day is submitted under with a form, as `YYYY-MM-DD`. */
|
|
22
23
|
name?: string;
|
|
23
24
|
disabled?: boolean;
|
|
24
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Names the calendar's button to the month before, for assistive technology. The
|
|
27
|
+
* `previousMonth` label of a `Labels` provider unless set.
|
|
28
|
+
*/
|
|
25
29
|
previousLabel?: string;
|
|
26
|
-
/** Names the
|
|
30
|
+
/** Names the button to the month after, as `previousLabel` does, from `nextMonth`. */
|
|
27
31
|
nextLabel?: string;
|
|
28
32
|
/** Formats dates and calendar headings in a fixed locale (avoids SSR locale mismatches). */
|
|
29
33
|
locale?: string;
|
|
@@ -67,15 +71,17 @@ export declare function datePickerMachineProps(props: DatePickerBaseProps, optio
|
|
|
67
71
|
locale: string;
|
|
68
72
|
onChange: (value: IsoDate) => void;
|
|
69
73
|
gutter?: number;
|
|
74
|
+
/** The labels of the closest `Labels` provider, for those the props leave out. */
|
|
75
|
+
labels?: ComponentLabels;
|
|
70
76
|
}): datePicker.Props;
|
|
71
77
|
/**
|
|
72
78
|
* Zag's strings that the calendar shows assistive technology. A day is named by its long
|
|
73
79
|
* localized name alone ("Tuesday, March 10, 2026"): its grid cell says whether it is selected
|
|
74
80
|
* and whether it is today, where Zag would add English words for both. The month buttons take
|
|
75
|
-
* `previousLabel` and `nextLabel
|
|
81
|
+
* `previousLabel` and `nextLabel`, or else the `labels` of a provider. Zag's other strings name parts that are not drawn, or whose
|
|
76
82
|
* names `datePickerTriggerAttrs` and `datePickerContentAttrs` replace.
|
|
77
83
|
*/
|
|
78
|
-
export declare function datePickerTranslations(props: Pick<DatePickerBaseProps, "previousLabel" | "nextLabel"
|
|
84
|
+
export declare function datePickerTranslations(props: Pick<DatePickerBaseProps, "previousLabel" | "nextLabel">, labels?: ComponentLabels): datePicker.IntlTranslations;
|
|
79
85
|
/**
|
|
80
86
|
* Spread over Zag's props of the field, the trigger, after them: a button that says it opens a
|
|
81
87
|
* dialog, the calendar, named by the chosen day (or the placeholder) and then the label, as a
|
package/dist/date-picker.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { space } from "@xds/tokens";
|
|
2
2
|
import { getLocalTimeZone, parseDate, today } from "@internationalized/date";
|
|
3
3
|
import { buttonClass } from "./button.js";
|
|
4
|
+
import { DEFAULT_LABELS } from "./labels.js";
|
|
4
5
|
export function parseIsoDate(value) {
|
|
5
6
|
if (value === undefined || !/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
6
7
|
return undefined;
|
|
@@ -67,14 +68,14 @@ export function datePickerMachineProps(props, options) {
|
|
|
67
68
|
minView: "day",
|
|
68
69
|
maxView: "day",
|
|
69
70
|
positioning: { placement: "bottom-start", gutter: options.gutter ?? space[1] },
|
|
70
|
-
translations: datePickerTranslations(props),
|
|
71
|
+
translations: datePickerTranslations(props, options.labels),
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
|
-
export function datePickerTranslations(props) {
|
|
74
|
+
export function datePickerTranslations(props, labels = DEFAULT_LABELS) {
|
|
74
75
|
return {
|
|
75
76
|
dayCell: (state) => state.valueText,
|
|
76
|
-
previousTrigger: () => props.previousLabel ??
|
|
77
|
-
nextTrigger: () => props.nextLabel ??
|
|
77
|
+
previousTrigger: () => props.previousLabel ?? labels.previousMonth,
|
|
78
|
+
nextTrigger: () => props.nextLabel ?? labels.nextMonth,
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
export function datePickerTriggerAttrs(props, ids) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type DateValue } from "@internationalized/date";
|
|
2
2
|
import type * as datePicker from "@zag-js/date-picker";
|
|
3
3
|
import { type DatePickerBaseProps, type IsoDate } from "./date-picker.ts";
|
|
4
|
+
import { type ComponentLabels } from "./labels.ts";
|
|
4
5
|
/** The first and the last day of a range, both chosen, `start` no later than `end`. */
|
|
5
6
|
export type DateRange = {
|
|
6
7
|
start: IsoDate;
|
|
@@ -21,9 +22,12 @@ export type DateRangePickerBaseProps = Omit<DatePickerBaseProps, "value" | "name
|
|
|
21
22
|
startName?: string;
|
|
22
23
|
/** The name the last day is submitted under with a form, as `YYYY-MM-DD`. */
|
|
23
24
|
endName?: string;
|
|
24
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Names the first day in the calendar's summary and for assistive technology. The `start`
|
|
27
|
+
* label of a `Labels` provider unless set.
|
|
28
|
+
*/
|
|
25
29
|
startLabel?: string;
|
|
26
|
-
/** Names the last day, as `startLabel` does the first
|
|
30
|
+
/** Names the last day, as `startLabel` does the first, from `end`. */
|
|
27
31
|
endLabel?: string;
|
|
28
32
|
};
|
|
29
33
|
/**
|
|
@@ -68,17 +72,19 @@ export declare function dateRangeMachineProps(props: DateRangePickerBaseProps, s
|
|
|
68
72
|
onDraft: (draft: RangeDraft | null) => void;
|
|
69
73
|
onChange: (value: DateRange) => void;
|
|
70
74
|
gutter?: number;
|
|
75
|
+
/** The labels of the closest `Labels` provider, for those the props leave out. */
|
|
76
|
+
labels?: ComponentLabels;
|
|
71
77
|
}): datePicker.Props;
|
|
72
78
|
/**
|
|
73
79
|
* DatePicker's strings, with the two ends named by `startLabel` and `endLabel` ahead of the
|
|
74
80
|
* day: "Check-in, Tuesday, March 10, 2026". A range of one day is both.
|
|
75
81
|
*/
|
|
76
|
-
export declare function dateRangeTranslations(props: Pick<DateRangePickerBaseProps, "previousLabel" | "nextLabel" | "startLabel" | "endLabel"
|
|
82
|
+
export declare function dateRangeTranslations(props: Pick<DateRangePickerBaseProps, "previousLabel" | "nextLabel" | "startLabel" | "endLabel">, labels?: ComponentLabels): datePicker.IntlTranslations;
|
|
77
83
|
/**
|
|
78
84
|
* The summary above the months: each end after its label, or a dash until it is chosen.
|
|
79
85
|
* "Check-in: Mar 20, 2026", "Check-out: –".
|
|
80
86
|
*/
|
|
81
|
-
export declare function rangeSummary(shown: RangeDraft, props: Pick<DateRangePickerBaseProps, "startLabel" | "endLabel">, locale: string): {
|
|
87
|
+
export declare function rangeSummary(shown: RangeDraft, props: Pick<DateRangePickerBaseProps, "startLabel" | "endLabel">, locale: string, labels?: ComponentLabels): {
|
|
82
88
|
start: string;
|
|
83
89
|
end: string;
|
|
84
90
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { space } from "@xds/tokens";
|
|
2
2
|
import { getLocalTimeZone, parseDate } from "@internationalized/date";
|
|
3
3
|
import { datePickerTranslations, formatDay, openingDay, parseIsoDate, } from "./date-picker.js";
|
|
4
|
+
import { DEFAULT_LABELS } from "./labels.js";
|
|
4
5
|
export function daysBetween(from, to) {
|
|
5
6
|
return Math.round((Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`)) / 86_400_000);
|
|
6
7
|
}
|
|
@@ -67,25 +68,25 @@ export function dateRangeMachineProps(props, shown, options) {
|
|
|
67
68
|
minView: "day",
|
|
68
69
|
maxView: "day",
|
|
69
70
|
positioning: { placement: "bottom-start", gutter: options.gutter ?? space[1] },
|
|
70
|
-
translations: dateRangeTranslations(props),
|
|
71
|
+
translations: dateRangeTranslations(props, options.labels),
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
|
-
export function dateRangeTranslations(props) {
|
|
74
|
-
const start = props.startLabel ??
|
|
75
|
-
const end = props.endLabel ??
|
|
74
|
+
export function dateRangeTranslations(props, labels = DEFAULT_LABELS) {
|
|
75
|
+
const start = props.startLabel ?? labels.start;
|
|
76
|
+
const end = props.endLabel ?? labels.end;
|
|
76
77
|
return {
|
|
77
|
-
...datePickerTranslations(props),
|
|
78
|
+
...datePickerTranslations(props, labels),
|
|
78
79
|
dayCell: (state) => [state.firstInRange && start, state.lastInRange && end, state.valueText]
|
|
79
80
|
.filter(Boolean)
|
|
80
81
|
.join(", "),
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
|
-
export function rangeSummary(shown, props, locale) {
|
|
84
|
+
export function rangeSummary(shown, props, locale, labels = DEFAULT_LABELS) {
|
|
84
85
|
const [start, end] = shown;
|
|
85
86
|
const day = (value) => value === undefined ? "–" : formatDay(value, locale);
|
|
86
87
|
return {
|
|
87
|
-
start: `${props.startLabel ??
|
|
88
|
-
end: `${props.endLabel ??
|
|
88
|
+
start: `${props.startLabel ?? labels.start}: ${day(start)}`,
|
|
89
|
+
end: `${props.endLabel ?? labels.end}: ${day(end)}`,
|
|
89
90
|
};
|
|
90
91
|
}
|
|
91
92
|
export function rangeMonthViews(api, months) {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { ACCORDION_PARTS, type AccordionBaseProps, type AccordionItemBase, focus
|
|
|
2
2
|
export { afterAnimations } from "./animation.ts";
|
|
3
3
|
export { AVATAR_SIZE, type AvatarBaseProps, type AvatarSize, avatarClass, avatarInitials, pictureClass, } from "./avatar.ts";
|
|
4
4
|
export { type AvatarStackBaseProps, avatarStack, avatarStackClass, avatarStackItemClass, avatarStackRestClass, } from "./avatar-stack.ts";
|
|
5
|
+
export { isControlled, onFormReset, type RootAttributes, rootAttributes } from "./root.ts";
|
|
5
6
|
export { type BadgeBaseProps, type BadgeTone, badgeClass, badgeDotClass } from "./badge.ts";
|
|
6
7
|
export { BANNER_PARTS, type BannerBaseProps, type BannerTone, bannerClass, bannerIconClass, bannerIconPath, bannerRole, } from "./banner.ts";
|
|
7
8
|
export { BUTTON_ICON, type ButtonBaseProps, type ButtonVariant, buttonClass, type ControlSize, ICON_BUTTON_BOX, type IconButtonBaseProps, isHeld, } from "./button.ts";
|
|
@@ -20,6 +21,7 @@ export { leaveEscapeToFields } from "./escape.ts";
|
|
|
20
21
|
export { focusWithoutRing } from "./focus.ts";
|
|
21
22
|
export { type IconBaseProps, type IconName, type IconSize, iconClass } from "./icon.ts";
|
|
22
23
|
export { initials } from "./initials.ts";
|
|
24
|
+
export { type ComponentLabels, DEFAULT_LABELS, mergeLabels } from "./labels.ts";
|
|
23
25
|
export { LIST_ROW_PARTS, type ListRowBaseProps, listRowClass, listRowDescriptionClass, listRowTitleClass, PRESSABLE_ROW, } from "./list-row.ts";
|
|
24
26
|
export { MEDIA_CARD_PARTS, type MediaCardBaseProps, type MediaCardLayout, mediaCardContentClass, mediaCardIds, mediaCardThumbnailClass, } from "./media-card.ts";
|
|
25
27
|
export { firstMenuValue, layoutRect, type MenuBaseProps, type MenuItem, menuItemClass, opensOnPress, } from "./menu.ts";
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { ACCORDION_PARTS, focusTitleOnClick, setPanelOpen, } from "./accordion.j
|
|
|
2
2
|
export { afterAnimations } from "./animation.js";
|
|
3
3
|
export { AVATAR_SIZE, avatarClass, avatarInitials, pictureClass, } from "./avatar.js";
|
|
4
4
|
export { avatarStack, avatarStackClass, avatarStackItemClass, avatarStackRestClass, } from "./avatar-stack.js";
|
|
5
|
+
export { isControlled, onFormReset, rootAttributes } from "./root.js";
|
|
5
6
|
export { badgeClass, badgeDotClass } from "./badge.js";
|
|
6
7
|
export { BANNER_PARTS, bannerClass, bannerIconClass, bannerIconPath, bannerRole, } from "./banner.js";
|
|
7
8
|
export { BUTTON_ICON, buttonClass, ICON_BUTTON_BOX, isHeld, } from "./button.js";
|
|
@@ -19,6 +20,7 @@ export { leaveEscapeToFields } from "./escape.js";
|
|
|
19
20
|
export { focusWithoutRing } from "./focus.js";
|
|
20
21
|
export { iconClass } from "./icon.js";
|
|
21
22
|
export { initials } from "./initials.js";
|
|
23
|
+
export { DEFAULT_LABELS, mergeLabels } from "./labels.js";
|
|
22
24
|
export { LIST_ROW_PARTS, listRowClass, listRowDescriptionClass, listRowTitleClass, PRESSABLE_ROW, } from "./list-row.js";
|
|
23
25
|
export { MEDIA_CARD_PARTS, mediaCardContentClass, mediaCardIds, mediaCardThumbnailClass, } from "./media-card.js";
|
|
24
26
|
export { firstMenuValue, layoutRect, menuItemClass, opensOnPress, } from "./menu.js";
|
package/dist/labels.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The names the components give their own parts, in English, by key: a banner's dismiss control,
|
|
3
|
+
* a search field's clear control, a calendar's month buttons, the ends of a range. Every client
|
|
4
|
+
* has the same keys and defaults, which `labels` in design/components.json lists;
|
|
5
|
+
* `labels.test.ts` holds this to it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_LABELS: {
|
|
8
|
+
readonly close: "Close";
|
|
9
|
+
readonly back: "Back";
|
|
10
|
+
readonly dismiss: "Dismiss";
|
|
11
|
+
readonly clear: "Clear";
|
|
12
|
+
readonly previousMonth: "Previous month";
|
|
13
|
+
readonly nextMonth: "Next month";
|
|
14
|
+
readonly start: "Start";
|
|
15
|
+
readonly end: "End";
|
|
16
|
+
readonly done: "Done";
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The built-in labels in effect, by key. A library's `Labels` provider gives the components
|
|
20
|
+
* inside it the ones it names, in the app's language, over those of the providers around it; a
|
|
21
|
+
* label the app passes to a component wins over both.
|
|
22
|
+
*/
|
|
23
|
+
export type ComponentLabels = {
|
|
24
|
+
-readonly [K in keyof typeof DEFAULT_LABELS]: string;
|
|
25
|
+
};
|
|
26
|
+
/** The labels inside a provider: the outer ones, with those the inner one names replaced. */
|
|
27
|
+
export declare function mergeLabels(outer: ComponentLabels | undefined, inner: Partial<ComponentLabels> | undefined): ComponentLabels;
|
package/dist/labels.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const DEFAULT_LABELS = {
|
|
2
|
+
close: "Close",
|
|
3
|
+
back: "Back",
|
|
4
|
+
dismiss: "Dismiss",
|
|
5
|
+
clear: "Clear",
|
|
6
|
+
previousMonth: "Previous month",
|
|
7
|
+
nextMonth: "Next month",
|
|
8
|
+
start: "Start",
|
|
9
|
+
end: "End",
|
|
10
|
+
done: "Done",
|
|
11
|
+
};
|
|
12
|
+
export function mergeLabels(outer, inner) {
|
|
13
|
+
const merged = { ...(outer ?? DEFAULT_LABELS) };
|
|
14
|
+
for (const [key, value] of Object.entries(inner ?? {})) {
|
|
15
|
+
if (value !== undefined && key in DEFAULT_LABELS)
|
|
16
|
+
merged[key] = value;
|
|
17
|
+
}
|
|
18
|
+
return merged;
|
|
19
|
+
}
|
|
@@ -15,11 +15,13 @@ import type { ComponentDefaults } from "../defaults.ts";
|
|
|
15
15
|
import type { DialogBaseProps } from "../dialog.ts";
|
|
16
16
|
import type { EmptyStateBaseProps } from "../empty-state.ts";
|
|
17
17
|
import type { IconBaseProps } from "../icon.ts";
|
|
18
|
+
import type { ComponentLabels } from "../labels.ts";
|
|
18
19
|
import type { ListRowBaseProps } from "../list-row.ts";
|
|
19
20
|
import type { MediaCardBaseProps } from "../media-card.ts";
|
|
20
21
|
import type { MenuBaseProps } from "../menu.ts";
|
|
21
22
|
import type { ProgressBarBaseProps } from "../progress-bar.ts";
|
|
22
23
|
import type { RadioGroupBaseProps } from "../radio-group.ts";
|
|
24
|
+
import type { RootAttributes } from "../root.ts";
|
|
23
25
|
import type { SectionHeaderBaseProps } from "../section-header.ts";
|
|
24
26
|
import type { SegmentedControlBaseProps } from "../segmented-control.ts";
|
|
25
27
|
import type { SelectBaseProps } from "../select.ts";
|
|
@@ -62,7 +64,7 @@ interface Own<N> {
|
|
|
62
64
|
onDismiss?: () => void;
|
|
63
65
|
children: N;
|
|
64
66
|
};
|
|
65
|
-
Button: ButtonBaseProps & {
|
|
67
|
+
Button: ButtonBaseProps & Focus & {
|
|
66
68
|
onPress?: () => void;
|
|
67
69
|
children?: N;
|
|
68
70
|
};
|
|
@@ -73,8 +75,8 @@ interface Own<N> {
|
|
|
73
75
|
class?: string;
|
|
74
76
|
children?: N;
|
|
75
77
|
};
|
|
76
|
-
Checkbox: CheckboxBaseProps & {
|
|
77
|
-
onChange
|
|
78
|
+
Checkbox: CheckboxBaseProps & Focus & {
|
|
79
|
+
onChange?: (checked: boolean) => void;
|
|
78
80
|
};
|
|
79
81
|
Chip: ChipBaseProps & {
|
|
80
82
|
onPress?: () => void;
|
|
@@ -103,7 +105,7 @@ interface Own<N> {
|
|
|
103
105
|
Icon: IconBaseProps & {
|
|
104
106
|
class?: string;
|
|
105
107
|
};
|
|
106
|
-
IconButton: IconButtonBaseProps & {
|
|
108
|
+
IconButton: IconButtonBaseProps & Focus & {
|
|
107
109
|
onPress?: () => void;
|
|
108
110
|
};
|
|
109
111
|
ListRow: ListRowBaseProps & {
|
|
@@ -121,20 +123,20 @@ interface Own<N> {
|
|
|
121
123
|
};
|
|
122
124
|
ProgressBar: ProgressBarBaseProps;
|
|
123
125
|
RadioGroup: RadioGroupBaseProps & {
|
|
124
|
-
onChange
|
|
126
|
+
onChange?: (value: string) => void;
|
|
125
127
|
};
|
|
126
|
-
SearchField: SearchFieldBaseProps & {
|
|
127
|
-
onChange
|
|
128
|
+
SearchField: SearchFieldBaseProps & Focus & {
|
|
129
|
+
onChange?: (value: string) => void;
|
|
128
130
|
onSubmit?: (value: string) => void;
|
|
129
131
|
};
|
|
130
132
|
SectionHeader: SectionHeaderBaseProps & {
|
|
131
133
|
action?: Action;
|
|
132
134
|
};
|
|
133
135
|
SegmentedControl: SegmentedControlBaseProps<string> & {
|
|
134
|
-
onChange
|
|
136
|
+
onChange?: (value: string) => void;
|
|
135
137
|
};
|
|
136
138
|
Select: SelectBaseProps & {
|
|
137
|
-
onChange
|
|
139
|
+
onChange?: (value: string) => void;
|
|
138
140
|
};
|
|
139
141
|
Sidebar: SidebarBaseProps & {
|
|
140
142
|
onChange: (value: string) => void;
|
|
@@ -143,22 +145,22 @@ interface Own<N> {
|
|
|
143
145
|
};
|
|
144
146
|
Skeleton: SkeletonBaseProps;
|
|
145
147
|
Slider: SliderBaseProps & {
|
|
146
|
-
onChange
|
|
148
|
+
onChange?: (value: number) => void;
|
|
147
149
|
};
|
|
148
150
|
Spinner: SpinnerBaseProps;
|
|
149
|
-
Switch: SwitchBaseProps & {
|
|
150
|
-
onChange
|
|
151
|
+
Switch: SwitchBaseProps & Focus & {
|
|
152
|
+
onChange?: (checked: boolean) => void;
|
|
151
153
|
};
|
|
152
154
|
Tabs: TabsBaseProps<string> & {
|
|
153
|
-
onChange
|
|
155
|
+
onChange?: (value: string) => void;
|
|
154
156
|
};
|
|
155
157
|
Text: TextBaseProps & {
|
|
156
158
|
as?: keyof HTMLElementTagNameMap;
|
|
157
159
|
class?: string;
|
|
158
160
|
children: N;
|
|
159
161
|
};
|
|
160
|
-
TextField: TextFieldBaseProps & {
|
|
161
|
-
onChange
|
|
162
|
+
TextField: TextFieldBaseProps & Focus & {
|
|
163
|
+
onChange?: (value: string) => void;
|
|
162
164
|
leading?: N;
|
|
163
165
|
trailing?: N;
|
|
164
166
|
};
|
|
@@ -170,10 +172,21 @@ interface Own<N> {
|
|
|
170
172
|
children: N;
|
|
171
173
|
};
|
|
172
174
|
}
|
|
173
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* When the element the component is focused through, its native button or input, takes and
|
|
177
|
+
* loses the focus. A library passes its framework's event; the data reads none.
|
|
178
|
+
*/
|
|
179
|
+
type Focus = {
|
|
180
|
+
onFocus?: () => void;
|
|
181
|
+
onBlur?: () => void;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* What an app puts on a component's root element, beside its root part: a class (React's
|
|
185
|
+
* `className`), an `id`, and `data-*` attributes.
|
|
186
|
+
*/
|
|
174
187
|
type Root = {
|
|
175
188
|
class?: string;
|
|
176
|
-
};
|
|
189
|
+
} & RootAttributes;
|
|
177
190
|
export type Components<N> = {
|
|
178
191
|
[K in keyof Own<N>]: Own<N>[K] & Root;
|
|
179
192
|
} & {
|
|
@@ -182,6 +195,11 @@ export type Components<N> = {
|
|
|
182
195
|
value: ComponentDefaults;
|
|
183
196
|
children: N;
|
|
184
197
|
};
|
|
198
|
+
/** The names the components inside give their own parts, in place of the English ones. */
|
|
199
|
+
Labels: {
|
|
200
|
+
value: Partial<ComponentLabels>;
|
|
201
|
+
children: N;
|
|
202
|
+
};
|
|
185
203
|
};
|
|
186
204
|
export type ComponentName = keyof Components<unknown>;
|
|
187
205
|
declare const NODE: unique symbol;
|
package/dist/radio-group.d.ts
CHANGED
|
@@ -9,8 +9,14 @@ export type RadioGroupBaseProps<Value extends string = string> = {
|
|
|
9
9
|
/** The group's visible legend, which also names it for assistive technology. */
|
|
10
10
|
label: string;
|
|
11
11
|
options: readonly RadioOption<Value>[];
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The chosen option, `undefined` while nothing is chosen. Leave it out for a group that keeps
|
|
14
|
+
* its own choice, from `defaultValue`: the group is controlled whenever `value` is given, even
|
|
15
|
+
* as `undefined`.
|
|
16
|
+
*/
|
|
13
17
|
value?: Value | undefined;
|
|
18
|
+
/** The first choice of a group that keeps its own, without `value`. */
|
|
19
|
+
defaultValue?: Value | undefined;
|
|
14
20
|
/** Disables the whole group. */
|
|
15
21
|
disabled?: boolean;
|
|
16
22
|
/** What is wrong and how to fix it, under the options. Clear it when the choice changes. */
|
package/dist/root.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every web component puts on its root element, beside the app's class and style: an `id`,
|
|
3
|
+
* and `data-*` attributes, such as the `data-testid` a test finds it by. The root is the
|
|
4
|
+
* component's outermost element, or the surface of an overlay: the panel of a Dialog, a Menu, a
|
|
5
|
+
* Tooltip or a Toast.
|
|
6
|
+
*/
|
|
7
|
+
export type RootAttributes = {
|
|
8
|
+
id?: string | undefined;
|
|
9
|
+
} & {
|
|
10
|
+
[name: `data-${string}`]: string | number | boolean | undefined;
|
|
11
|
+
};
|
|
12
|
+
/** The `id` and `data-*` attributes among a component's props, to spread on its root element. */
|
|
13
|
+
export declare function rootAttributes(props: object): RootAttributes;
|
|
14
|
+
/**
|
|
15
|
+
* Whether a component is controlled: whether the app gives it the prop that holds its state,
|
|
16
|
+
* even as `undefined`. A component left without it keeps its own state, from its default, and
|
|
17
|
+
* still reports each change.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isControlled(props: object, name: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Calls `reset` each time the form that `element` is in is reset, once the form has put its
|
|
22
|
+
* fields back to their defaults: the event comes before it does. A control that keeps its own
|
|
23
|
+
* value sets it back to its default there, as the native field has. Returns what stops it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function onFormReset(element: Element | null | undefined, reset: () => void): () => void;
|
package/dist/root.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function rootAttributes(props) {
|
|
2
|
+
const attributes = {};
|
|
3
|
+
for (const [name, value] of Object.entries(props)) {
|
|
4
|
+
if (name === "id" || name.startsWith("data-"))
|
|
5
|
+
attributes[name] = value;
|
|
6
|
+
}
|
|
7
|
+
return attributes;
|
|
8
|
+
}
|
|
9
|
+
export function isControlled(props, name) {
|
|
10
|
+
return name in props;
|
|
11
|
+
}
|
|
12
|
+
export function onFormReset(element, reset) {
|
|
13
|
+
const form = element?.closest("form");
|
|
14
|
+
if (!form)
|
|
15
|
+
return () => { };
|
|
16
|
+
let timer;
|
|
17
|
+
const listener = () => {
|
|
18
|
+
timer = setTimeout(reset);
|
|
19
|
+
};
|
|
20
|
+
form.addEventListener("reset", listener);
|
|
21
|
+
return () => {
|
|
22
|
+
form.removeEventListener("reset", listener);
|
|
23
|
+
clearTimeout(timer);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -4,7 +4,10 @@ export type SegmentedControlBaseProps<Value extends string> = {
|
|
|
4
4
|
value: Value;
|
|
5
5
|
label: string;
|
|
6
6
|
}[];
|
|
7
|
-
|
|
7
|
+
/** The chosen segment. Leave it out for a control that keeps its own, from `defaultValue`. */
|
|
8
|
+
value?: Value;
|
|
9
|
+
/** The first segment of a control that keeps its own, without `value`. Defaults to the first. */
|
|
10
|
+
defaultValue?: Value;
|
|
8
11
|
/** Says what is being chosen, for assistive technology. */
|
|
9
12
|
"aria-label": string;
|
|
10
13
|
/** Stretches to the width of its container. */
|
package/dist/select.d.ts
CHANGED
|
@@ -9,8 +9,14 @@ export type SelectBaseProps<Value extends string = string> = {
|
|
|
9
9
|
/** Always visible, like a TextField's. */
|
|
10
10
|
label: string;
|
|
11
11
|
options: readonly SelectOption<Value>[];
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The chosen option, `undefined` while nothing is chosen. Leave it out for a select that keeps
|
|
14
|
+
* its own choice, from `defaultValue`: it is controlled whenever `value` is given, even as
|
|
15
|
+
* `undefined`.
|
|
16
|
+
*/
|
|
13
17
|
value?: Value | undefined;
|
|
18
|
+
/** The first choice of a select that keeps its own, without `value`. */
|
|
19
|
+
defaultValue?: Value | undefined;
|
|
14
20
|
/** Shown in the field while nothing is chosen. */
|
|
15
21
|
placeholder?: string;
|
|
16
22
|
/** Help shown under the field. Replaced by `error` while there is one. */
|
package/dist/slider.d.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
export type SliderBaseProps = {
|
|
3
3
|
/** Shown above the track, and names the slider for assistive technology. */
|
|
4
4
|
label: string;
|
|
5
|
-
value
|
|
5
|
+
/** Leave it out for a slider that keeps its own value, from `defaultValue`. */
|
|
6
|
+
value?: number;
|
|
7
|
+
/** The first value of a slider that keeps its own, without `value`. Defaults to `min`. */
|
|
8
|
+
defaultValue?: number;
|
|
6
9
|
/** Defaults to 0. */
|
|
7
10
|
min?: number;
|
|
8
11
|
/** Defaults to 100. */
|
package/dist/switch.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** Switch's props in every framework, short of `onChange`. */
|
|
2
2
|
export type SwitchBaseProps = {
|
|
3
|
-
|
|
3
|
+
/** Leave it out for a switch that keeps its own state, from `defaultChecked`. */
|
|
4
|
+
checked?: boolean;
|
|
5
|
+
/** Whether a switch that keeps its own state starts on. */
|
|
6
|
+
defaultChecked?: boolean;
|
|
4
7
|
/** Shown beside the switch. Pressing it toggles too. */
|
|
5
8
|
label?: string;
|
|
6
9
|
/** Names the switch for assistive technology when there is no visible label. */
|
package/dist/tabs.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ export type TabsBaseProps<Value extends string> = {
|
|
|
6
6
|
label: string;
|
|
7
7
|
icon?: IconName;
|
|
8
8
|
}[];
|
|
9
|
-
/** The selected tab. */
|
|
10
|
-
value
|
|
9
|
+
/** The selected tab. Leave it out for tabs that keep their own, from `defaultValue`. */
|
|
10
|
+
value?: Value;
|
|
11
|
+
/** The first tab of tabs that keep their own, without `value`. Defaults to the first. */
|
|
12
|
+
defaultValue?: Value;
|
|
11
13
|
/** Says what the tabs switch between, for assistive technology. */
|
|
12
14
|
label: string;
|
|
13
15
|
/** The tabs share the width equally instead of being as wide as their labels. */
|
package/dist/text-field.d.ts
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
export type TextFieldBaseProps = {
|
|
3
3
|
/** Always visible. A placeholder is not a label: it disappears as soon as the person types. */
|
|
4
4
|
label: string;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The text. Leave it out for a field that keeps its own, from `defaultValue`: the field is
|
|
7
|
+
* controlled whenever `value` is given.
|
|
8
|
+
*/
|
|
9
|
+
value?: string;
|
|
10
|
+
/** The first text of a field that keeps its own, without `value`. */
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
/** The text can be selected and copied but not changed, and is still submitted with a form. */
|
|
13
|
+
readOnly?: boolean;
|
|
6
14
|
/** Help shown under the field. Replaced by `error` while there is one. */
|
|
7
15
|
description?: string;
|
|
8
16
|
/** What is wrong and how to fix it. Clear it when the value changes. */
|
|
@@ -25,11 +33,19 @@ export type TextFieldBaseProps = {
|
|
|
25
33
|
export type TextFieldType = "text" | "email" | "password" | "search" | "tel" | "url" | "number" | (string & {});
|
|
26
34
|
/** SearchField's props in every framework, short of `onChange` and `onSubmit`. */
|
|
27
35
|
export type SearchFieldBaseProps = {
|
|
28
|
-
|
|
36
|
+
/** The query. Leave it out for a field that keeps its own, from `defaultValue`. */
|
|
37
|
+
value?: string;
|
|
38
|
+
/** The first query of a field that keeps its own, without `value`. */
|
|
39
|
+
defaultValue?: string;
|
|
40
|
+
/** The query can be selected and copied but not changed. */
|
|
41
|
+
readOnly?: boolean;
|
|
29
42
|
/** The accessible name. It is not shown: the search icon says what the field is for. */
|
|
30
43
|
label: string;
|
|
31
44
|
placeholder?: string;
|
|
32
45
|
disabled?: boolean;
|
|
33
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Names the control that empties the field, for assistive technology. The `clear` label of a
|
|
48
|
+
* `Labels` provider unless set.
|
|
49
|
+
*/
|
|
34
50
|
clearLabel?: string;
|
|
35
51
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xds/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "What the xds web component libraries share: prop types, class recipes and DOM helpers. Install a framework's package instead.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design-system",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@xds/tokens": "1.
|
|
37
|
+
"@xds/tokens": "1.1.0",
|
|
38
38
|
"@internationalized/date": "3.12.4",
|
|
39
39
|
"@zag-js/date-picker": "2.0.0-next.4"
|
|
40
40
|
},
|