@godxjp/ui 19.6.0 → 20.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/README.md +8 -2
- package/dist/app/theme-axes.d.ts +2 -0
- package/dist/app/theme-axes.js +45 -0
- package/dist/components/charts/chart-cartesian.d.ts +2 -1
- package/dist/components/charts/chart-cartesian.js +52 -3
- package/dist/components/charts/chart-category-axis.d.ts +55 -0
- package/dist/components/charts/chart-category-axis.js +93 -0
- package/dist/components/charts/chart-frame.d.ts +10 -1
- package/dist/components/charts/chart-frame.js +19 -3
- package/dist/components/charts/compact-bar-trend.d.ts +1 -1
- package/dist/components/charts/compact-bar-trend.js +2 -0
- package/dist/components/charts/pie-chart.d.ts +1 -1
- package/dist/components/charts/pie-chart.js +12 -1
- package/dist/components/charts/recharts-peer.d.ts +49 -0
- package/dist/components/charts/recharts-peer.js +45 -0
- package/dist/components/data-display/card.d.ts +14 -3
- package/dist/components/data-display/card.js +22 -4
- package/dist/components/data-display/code-block.js +6 -2
- package/dist/components/data-display/collapsible.d.ts +23 -4
- package/dist/components/data-display/collapsible.js +119 -4
- package/dist/components/data-display/data-table.d.ts +39 -4
- package/dist/components/data-display/data-table.js +802 -270
- package/dist/components/data-display/descriptions.d.ts +27 -6
- package/dist/components/data-display/descriptions.js +58 -17
- package/dist/components/data-display/index.d.ts +5 -1
- package/dist/components/data-display/index.js +4 -0
- package/dist/components/data-display/legend.d.ts +15 -0
- package/dist/components/data-display/legend.js +11 -0
- package/dist/components/data-display/list-row.d.ts +10 -1
- package/dist/components/data-display/list-row.js +8 -2
- package/dist/components/data-display/popover.d.ts +60 -7
- package/dist/components/data-display/popover.js +268 -39
- package/dist/components/data-display/progress.d.ts +50 -2
- package/dist/components/data-display/progress.js +57 -9
- package/dist/components/data-display/range-timeline.d.ts +38 -0
- package/dist/components/data-display/range-timeline.js +161 -0
- package/dist/components/data-display/scroll-area.js +13 -2
- package/dist/components/data-display/service-launcher-card.js +10 -10
- package/dist/components/data-display/table.d.ts +11 -3
- package/dist/components/data-display/table.js +48 -18
- package/dist/components/data-display/tree-list.js +4 -9
- package/dist/components/data-entry/calendar.d.ts +2 -2
- package/dist/components/data-entry/calendar.js +79 -33
- package/dist/components/data-entry/cascader.d.ts +1 -1
- package/dist/components/data-entry/cascader.js +188 -24
- package/dist/components/data-entry/checkbox.d.ts +19 -6
- package/dist/components/data-entry/checkbox.js +55 -16
- package/dist/components/data-entry/choice-option.d.ts +1 -1
- package/dist/components/data-entry/color-picker.d.ts +1 -1
- package/dist/components/data-entry/color-picker.js +17 -5
- package/dist/components/data-entry/control-appearance.d.ts +64 -0
- package/dist/components/data-entry/control-appearance.js +39 -0
- package/dist/components/data-entry/control-surface.d.ts +61 -0
- package/dist/components/data-entry/control-surface.js +39 -0
- package/dist/components/data-entry/date-picker.d.ts +1 -1
- package/dist/components/data-entry/date-picker.js +344 -113
- package/dist/components/data-entry/date-range-picker.d.ts +2 -2
- package/dist/components/data-entry/date-range-picker.js +278 -140
- package/dist/components/data-entry/field.js +0 -1
- package/dist/components/data-entry/form-field.d.ts +1 -1
- package/dist/components/data-entry/form-field.js +39 -4
- package/dist/components/data-entry/form.d.ts +4 -0
- package/dist/components/data-entry/form.js +5 -3
- package/dist/components/data-entry/index.d.ts +7 -3
- package/dist/components/data-entry/index.js +10 -1
- package/dist/components/data-entry/input-otp.d.ts +1 -1
- package/dist/components/data-entry/input.d.ts +12 -34
- package/dist/components/data-entry/input.js +92 -24
- package/dist/components/data-entry/label.d.ts +3 -2
- package/dist/components/data-entry/label.js +23 -10
- package/dist/components/data-entry/month-picker.d.ts +2 -2
- package/dist/components/data-entry/month-picker.js +47 -10
- package/dist/components/data-entry/month-range-picker.d.ts +2 -2
- package/dist/components/data-entry/month-range-picker.js +51 -11
- package/dist/components/data-entry/number-input.d.ts +7 -0
- package/dist/components/data-entry/number-input.js +147 -98
- package/dist/components/data-entry/password-input.d.ts +1 -1
- package/dist/components/data-entry/radio.d.ts +1 -1
- package/dist/components/data-entry/radio.js +61 -13
- package/dist/components/data-entry/search-input.d.ts +1 -1
- package/dist/components/data-entry/search-input.js +16 -2
- package/dist/components/data-entry/search-select.d.ts +2 -2
- package/dist/components/data-entry/search-select.js +209 -78
- package/dist/components/data-entry/select.d.ts +22 -4
- package/dist/components/data-entry/select.js +215 -163
- package/dist/components/data-entry/slider.d.ts +9 -1
- package/dist/components/data-entry/slider.js +87 -9
- package/dist/components/data-entry/switch.d.ts +3 -0
- package/dist/components/data-entry/switch.js +29 -3
- package/dist/components/data-entry/textarea.d.ts +14 -56
- package/dist/components/data-entry/textarea.js +80 -33
- package/dist/components/data-entry/time-picker.d.ts +2 -2
- package/dist/components/data-entry/time-picker.js +333 -109
- package/dist/components/data-entry/time-range-picker.d.ts +5 -0
- package/dist/components/data-entry/time-range-picker.js +89 -0
- package/dist/components/data-entry/transfer.d.ts +1 -1
- package/dist/components/data-entry/transfer.js +99 -31
- package/dist/components/data-entry/tree-select-strategy.d.ts +1 -1
- package/dist/components/data-entry/tree-select.d.ts +1 -1
- package/dist/components/data-entry/tree-select.js +197 -92
- package/dist/components/data-entry/tree-utils.d.ts +1 -1
- package/dist/components/data-entry/tree-utils.js +7 -14
- package/dist/components/data-entry/upload-files.d.ts +2 -0
- package/dist/components/data-entry/upload-files.js +31 -0
- package/dist/components/data-entry/upload-request.d.ts +4 -0
- package/dist/components/data-entry/upload-request.js +53 -0
- package/dist/components/data-entry/upload-types.d.ts +28 -0
- package/dist/components/data-entry/upload-types.js +2 -0
- package/dist/components/data-entry/upload.d.ts +2 -2
- package/dist/components/data-entry/upload.js +482 -117
- package/dist/components/feedback/dialog.d.ts +105 -38
- package/dist/components/feedback/dialog.js +268 -193
- package/dist/components/feedback/overlay-close-focus.d.ts +31 -0
- package/dist/components/feedback/overlay-close-focus.js +31 -0
- package/dist/components/feedback/overlay-header-tone.d.ts +1 -1
- package/dist/components/feedback/sheet.d.ts +53 -11
- package/dist/components/feedback/sheet.js +150 -81
- package/dist/components/feedback/tooltip.d.ts +51 -7
- package/dist/components/feedback/tooltip.js +107 -25
- package/dist/components/general/button.d.ts +1 -1
- package/dist/components/general/button.js +7 -3
- package/dist/components/general/index.d.ts +1 -0
- package/dist/components/general/index.js +2 -0
- package/dist/components/general/logo.d.ts +17 -0
- package/dist/components/general/logo.js +22 -16
- package/dist/components/general/typography.d.ts +3 -0
- package/dist/components/general/typography.js +15 -1
- package/dist/components/general/visually-hidden.d.ts +3 -0
- package/dist/components/general/visually-hidden.js +9 -0
- package/dist/components/layout/app-launcher.d.ts +34 -0
- package/dist/components/layout/app-launcher.js +228 -0
- package/dist/components/layout/app-shell.d.ts +3 -1
- package/dist/components/layout/app-shell.js +69 -12
- package/dist/components/layout/aspect-ratio.js +0 -1
- package/dist/components/layout/auth-divider.js +0 -1
- package/dist/components/layout/breadcrumb.d.ts +14 -2
- package/dist/components/layout/breadcrumb.js +46 -4
- package/dist/components/layout/flex.d.ts +1 -1
- package/dist/components/layout/flex.js +41 -3
- package/dist/components/layout/index.d.ts +3 -0
- package/dist/components/layout/index.js +5 -1
- package/dist/components/layout/nav-surface.d.ts +26 -0
- package/dist/components/layout/nav-surface.js +17 -0
- package/dist/components/layout/org-switcher.d.ts +5 -1
- package/dist/components/layout/org-switcher.js +25 -4
- package/dist/components/layout/page-container.d.ts +1 -1
- package/dist/components/layout/page-container.js +5 -3
- package/dist/components/layout/responsive-grid.d.ts +16 -2
- package/dist/components/layout/responsive-grid.js +29 -2
- package/dist/components/layout/separator.js +0 -1
- package/dist/components/layout/sidebar.js +4 -1
- package/dist/components/layout/split-pane.d.ts +14 -1
- package/dist/components/layout/split-pane.js +26 -13
- package/dist/components/layout/topbar-item.d.ts +3 -0
- package/dist/components/layout/topbar-item.js +19 -5
- package/dist/components/layout/topbar.d.ts +1 -1
- package/dist/components/layout/topbar.js +27 -6
- package/dist/components/navigation/app-setting-picker.js +21 -2
- package/dist/components/navigation/app-setting-toggle.d.ts +16 -0
- package/dist/components/navigation/app-setting-toggle.js +96 -0
- package/dist/components/navigation/dropdown-menu.d.ts +227 -18
- package/dist/components/navigation/dropdown-menu.js +402 -118
- package/dist/components/navigation/index.d.ts +2 -0
- package/dist/components/navigation/index.js +2 -0
- package/dist/components/navigation/pagination-utils.d.ts +2 -1
- package/dist/components/navigation/pagination.d.ts +2 -2
- package/dist/components/navigation/pagination.js +155 -83
- package/dist/components/navigation/steps.d.ts +2 -2
- package/dist/components/navigation/steps.js +29 -4
- package/dist/components/navigation/tabs.d.ts +29 -16
- package/dist/components/navigation/tabs.js +374 -144
- package/dist/components/ui/accordion.d.ts +50 -5
- package/dist/components/ui/accordion.js +239 -33
- package/dist/components/ui/aspect-ratio.d.ts +23 -2
- package/dist/components/ui/aspect-ratio.js +15 -13
- package/dist/components/ui/avatar.d.ts +29 -4
- package/dist/components/ui/avatar.js +111 -25
- package/dist/components/ui/hover-card.d.ts +42 -4
- package/dist/components/ui/hover-card.js +183 -27
- package/dist/components/ui/input-otp.d.ts +26 -28
- package/dist/components/ui/input-otp.js +50 -7
- package/dist/components/ui/label.js +0 -1
- package/dist/components/ui/password-input.d.ts +36 -2
- package/dist/components/ui/password-input.js +27 -7
- package/dist/components/ui/rating.d.ts +25 -0
- package/dist/components/ui/rating.js +67 -27
- package/dist/components/ui/segmented.d.ts +12 -3
- package/dist/components/ui/segmented.js +17 -2
- package/dist/components/ui/separator.d.ts +12 -2
- package/dist/components/ui/separator.js +30 -9
- package/dist/components/ui/tag-input.d.ts +45 -0
- package/dist/components/ui/tag-input.js +109 -27
- package/dist/components/ui/toggle-group.d.ts +50 -5
- package/dist/components/ui/toggle-group.js +79 -20
- package/dist/components/ui/toggle.d.ts +31 -5
- package/dist/components/ui/toggle.js +42 -3
- package/dist/form/form-context.d.ts +29 -0
- package/dist/form/form-context.js +44 -4
- package/dist/form/form-field-array.d.ts +22 -0
- package/dist/form/form-field-array.js +50 -0
- package/dist/form/form-field-control.d.ts +2 -1
- package/dist/form/form-field-control.js +116 -40
- package/dist/form/form-root.d.ts +2 -1
- package/dist/form/form-root.js +142 -23
- package/dist/form/index.d.ts +3 -1
- package/dist/form/index.js +12 -1
- package/dist/i18n/messages/en.json +64 -5
- package/dist/i18n/messages/ja.json +64 -5
- package/dist/i18n/messages/vi.json +64 -5
- package/dist/inertia/index.d.ts +20 -0
- package/dist/inertia/index.js +60 -1
- package/dist/lib/control-styles.d.ts +25 -3
- package/dist/lib/control-styles.js +9 -3
- package/dist/lib/datetime/picker-format.d.ts +8 -0
- package/dist/lib/datetime/picker-format.js +54 -0
- package/dist/lib/slot.d.ts +32 -0
- package/dist/lib/slot.js +22 -0
- package/dist/lib/variants.d.ts +22 -3
- package/dist/lib/variants.js +56 -1
- package/dist/props/components/app.prop.d.ts +25 -1
- package/dist/props/components/charts.prop.d.ts +21 -0
- package/dist/props/components/data-display.prop.d.ts +72 -4
- package/dist/props/components/data-entry.prop.d.ts +718 -46
- package/dist/props/components/form.prop.d.ts +142 -4
- package/dist/props/components/general.prop.d.ts +17 -1
- package/dist/props/components/index.d.ts +3 -3
- package/dist/props/components/layout.prop.d.ts +281 -11
- package/dist/props/components/navigation.prop.d.ts +114 -4
- package/dist/props/registry.d.ts +397 -11
- package/dist/props/registry.js +526 -11
- package/dist/props/vocabulary/content.prop.d.ts +1 -1
- package/dist/props/vocabulary/data.prop.d.ts +179 -1
- package/dist/props/vocabulary/index.d.ts +5 -5
- package/dist/props/vocabulary/interaction.prop.d.ts +68 -3
- package/dist/props/vocabulary/layout.prop.d.ts +57 -1
- package/dist/props/vocabulary/navigation.prop.d.ts +40 -0
- package/dist/props/vocabulary/shared.prop.d.ts +33 -0
- package/dist/styles/badge-layout.css +2 -1
- package/dist/styles/card-layout.css +26 -4
- package/dist/styles/chart-layout.css +15 -0
- package/dist/styles/control.css +657 -15
- package/dist/styles/core.css +5 -2
- package/dist/styles/data-display-layout.css +313 -6
- package/dist/styles/data-entry-layout.css +13 -0
- package/dist/styles/focus-ring.css +4 -0
- package/dist/styles/index.css +5 -2
- package/dist/styles/layout.css +327 -4
- package/dist/styles/navigation-layout.css +227 -0
- package/dist/styles/shell-layout.css +369 -13
- package/dist/styles/table-layout.css +95 -6
- package/dist/styles/text-layout.css +10 -4
- package/dist/tokens/base.css +2 -1
- package/dist/tokens/components/badge.css +1 -0
- package/dist/tokens/components/chart.css +6 -0
- package/dist/tokens/components/control.css +79 -2
- package/dist/tokens/components/data-display.css +20 -0
- package/dist/tokens/components/descriptions.css +11 -0
- package/dist/tokens/components/flex.css +8 -0
- package/dist/tokens/components/navigation.css +55 -0
- package/dist/tokens/components/shell.css +53 -3
- package/dist/tokens/components/table.css +14 -0
- package/dist/tokens/foundation.css +2 -0
- package/dist/tokens/semantic/layout.css +9 -0
- package/docs/COMPONENTS.md +9 -3
- package/docs/CONSUMER-RULES.md +13 -0
- package/docs/DESIGN-AUTHORITY.md +145 -83
- package/docs/DEVELOPMENT.md +4 -3
- package/docs/FORMS.md +151 -6
- package/docs/FRAME-COVERAGE-REPORT.md +32 -17
- package/docs/README.md +15 -15
- package/docs/STANDARDS-vocabulary-tokens.md +1 -1
- package/docs/TESTING.md +15 -6
- package/docs/WHAT-BELONGS-HERE.md +179 -0
- package/docs/charts/cjk-category-axis.tsx +81 -0
- package/docs/data-display/card/index.tsx +22 -0
- package/docs/data-display/data-table/examples/antd-parity.tsx +257 -0
- package/docs/data-display/data-table/index.tsx +23 -0
- package/docs/data-display/descriptions.tsx +41 -0
- package/docs/data-display/legend.tsx +145 -0
- package/docs/data-display/progress.tsx +32 -0
- package/docs/data-display/scroll-area.tsx +31 -25
- package/docs/data-display/table.tsx +104 -45
- package/docs/data-display/timeline.tsx +41 -0
- package/docs/data-entry/date-picker.tsx +85 -0
- package/docs/data-entry/date-range-picker.tsx +26 -0
- package/docs/data-entry/form-dynamic-fields.tsx +199 -0
- package/docs/data-entry/form.tsx +74 -4
- package/docs/data-entry/input-otp.tsx +24 -0
- package/docs/data-entry/input.tsx +46 -1
- package/docs/data-entry/month-range-picker.tsx +1 -1
- package/docs/data-entry/segmented.tsx +1 -1
- package/docs/data-entry/select.tsx +29 -2
- package/docs/data-entry/switch.tsx +41 -0
- package/docs/data-entry/textarea.tsx +38 -0
- package/docs/data-entry/time-picker.tsx +85 -1
- package/docs/data-entry/time-range-picker.tsx +55 -0
- package/docs/data-entry/transfer.tsx +17 -0
- package/docs/data-entry/upload.tsx +56 -12
- package/docs/feedback/sheet.tsx +1 -1
- package/docs/feedback/tooltip.tsx +1 -1
- package/docs/general/activity.tsx +2 -2
- package/docs/general/button/index.tsx +14 -1
- package/docs/general/typography.tsx +14 -1
- package/docs/layout/app-launcher.tsx +151 -0
- package/docs/layout/app-shell-arrangements.tsx +225 -0
- package/docs/layout/app-shell.tsx +11 -0
- package/docs/layout/aspect-ratio.tsx +1 -1
- package/docs/layout/flex.tsx +50 -0
- package/docs/layout/responsive-grid.tsx +21 -1
- package/docs/layout/topbar.tsx +5 -9
- package/docs/navigation/app-setting-picker.tsx +37 -1
- package/docs/navigation/app-setting-toggle.tsx +111 -0
- package/docs/navigation/breadcrumb.tsx +48 -0
- package/docs/navigation/dropdown-menu.tsx +21 -0
- package/docs/navigation/pagination.tsx +52 -0
- package/docs/navigation/steps.tsx +37 -0
- package/docs/navigation/tabs.tsx +97 -1
- package/docs/query/button-refetch.tsx +1 -0
- package/package.json +28 -8
- package/scripts/_agent-setup.mjs +182 -3
- package/scripts/consumer-rule.md +98 -0
- package/scripts/guinea-pig-skill.md +322 -0
- package/scripts/init-guinea-pig.mjs +84 -0
- package/scripts/postinstall.mjs +13 -2
- package/scripts/ui-audit.mjs +351 -37
- /package/dist/tokens/{antd.generated.css → derived.css} +0 -0
|
@@ -18,6 +18,15 @@ export type SegmentedProp = {
|
|
|
18
18
|
/** Uncontrolled initial selection. */
|
|
19
19
|
defaultValue?: string;
|
|
20
20
|
onValueChange?: (value: string) => void;
|
|
21
|
+
/**
|
|
22
|
+
* antd `block` — stretch the bar to its container and share the width EQUALLY between the
|
|
23
|
+
* choices, so the selected pill does not resize as the label changes length.
|
|
24
|
+
*/
|
|
25
|
+
block?: boolean;
|
|
26
|
+
/** antd `vertical` — stack the choices in a column. Arrow keys follow the axis. */
|
|
27
|
+
vertical?: boolean;
|
|
28
|
+
/** Control height tier: `md` (default), `sm` or `lg` — the same tiers as every other control. */
|
|
29
|
+
size?: "sm" | "md" | "lg";
|
|
21
30
|
/** Disable the whole group. */
|
|
22
31
|
disabled?: boolean;
|
|
23
32
|
/** Form field name — submits the selected value with the form. */
|
|
@@ -30,8 +39,8 @@ export type SegmentedProp = {
|
|
|
30
39
|
};
|
|
31
40
|
export type SegmentedProps = SegmentedProp;
|
|
32
41
|
/**
|
|
33
|
-
* Segmented — one-of-N from a small, closed, always-visible set.
|
|
34
|
-
* (docs/DESIGN-AUTHORITY.md
|
|
42
|
+
* Segmented — one-of-N from a small, closed, always-visible set. The established enterprise
|
|
43
|
+
* `Segmented` control (docs/DESIGN-AUTHORITY.md) drawn on Radix's RadioGroup,
|
|
35
44
|
* which is this repo's authority for behaviour primitives.
|
|
36
45
|
*
|
|
37
46
|
* WHY NOT `ToggleGroup`. A ToggleGroup is a row of PRESSED buttons: `aria-pressed`, independently
|
|
@@ -42,7 +51,7 @@ export type SegmentedProps = SegmentedProp;
|
|
|
42
51
|
* distinction and it is not a skin.
|
|
43
52
|
*
|
|
44
53
|
* The primitive gives roving tabindex, arrow-key traversal (RTL-aware), the radiogroup/radio roles
|
|
45
|
-
* and the hidden input a native form submit needs. This file adds
|
|
54
|
+
* and the hidden input a native form submit needs. This file adds that geometry and nothing
|
|
46
55
|
* else — the focus mark comes from `ui-focus-ring`, the ONE source in styles/focus-ring.css.
|
|
47
56
|
*/
|
|
48
57
|
export declare const Segmented: React.ForwardRefExoticComponent<SegmentedProp & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -3,15 +3,30 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
|
|
5
5
|
import { cn } from "../../lib/utils.js";
|
|
6
|
-
const Segmented = React.forwardRef(function Segmented2({
|
|
6
|
+
const Segmented = React.forwardRef(function Segmented2({
|
|
7
|
+
options,
|
|
8
|
+
value,
|
|
9
|
+
defaultValue,
|
|
10
|
+
onValueChange,
|
|
11
|
+
disabled,
|
|
12
|
+
block = false,
|
|
13
|
+
vertical = false,
|
|
14
|
+
size,
|
|
15
|
+
name,
|
|
16
|
+
id,
|
|
17
|
+
className,
|
|
18
|
+
...props
|
|
19
|
+
}, ref) {
|
|
7
20
|
return /* @__PURE__ */ jsx(
|
|
8
21
|
RadioGroupPrimitive.Root,
|
|
9
22
|
{
|
|
10
23
|
ref,
|
|
11
24
|
id,
|
|
12
25
|
"data-slot": "segmented",
|
|
26
|
+
"data-block": block ? "true" : void 0,
|
|
27
|
+
"data-size": size,
|
|
13
28
|
className: cn("ui-segmented", className),
|
|
14
|
-
orientation: "horizontal",
|
|
29
|
+
orientation: vertical ? "vertical" : "horizontal",
|
|
15
30
|
value,
|
|
16
31
|
defaultValue,
|
|
17
32
|
onValueChange,
|
|
@@ -2,10 +2,20 @@ import * as React from "react";
|
|
|
2
2
|
export type { SeparatorProp, SeparatorProp as SeparatorProps, } from "../../props/components/layout.prop.js";
|
|
3
3
|
/**
|
|
4
4
|
* ACCESSIBILITY — the whole point of the labelled form is that the label is ANNOUNCED, exactly
|
|
5
|
-
* ONCE. Without a label the rule stays `decorative` (
|
|
6
|
-
*
|
|
5
|
+
* ONCE. Without a label the rule stays `decorative` (`role="none"`), which is right: a section
|
|
6
|
+
* rule carries no information.
|
|
7
|
+
*
|
|
8
|
+
* SUBSTRATE — React Aria Components. Its `Separator` has no `decorative` prop: `useSeparator`
|
|
9
|
+
* emits `role="separator"` unconditionally (and `aria-orientation="vertical"` on the vertical
|
|
10
|
+
* rule), and it drops `children` entirely. Both are handled in the `render` override below, which
|
|
11
|
+
* is RAC's supported escape hatch for owning the element: it hands us the computed DOM props and
|
|
12
|
+
* the ref, and we decide what element carries them.
|
|
7
13
|
*/
|
|
8
14
|
export declare const Separator: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
15
|
+
labelSize?: "2xs" | "xs" | "sm" | "md";
|
|
16
|
+
space?: import("../../props/index.js").GapProp;
|
|
17
|
+
hideBelow?: import("../../props/index.js").BreakpointProp;
|
|
18
|
+
hideFrom?: import("../../props/index.js").BreakpointProp;
|
|
9
19
|
orientation?: import("../../props/index.js").OrientationProp;
|
|
10
20
|
label?: string;
|
|
11
21
|
labelAlign?: import("../../props/index.js").TextAlignProp;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
2
|
import * as React from "react";
|
|
4
|
-
import
|
|
3
|
+
import { Separator as AriaSeparator } from "react-aria-components";
|
|
4
|
+
import { padStepToken } from "../../lib/variants.js";
|
|
5
5
|
import { cn } from "../../lib/utils.js";
|
|
6
6
|
const Separator = React.forwardRef(
|
|
7
7
|
({
|
|
8
8
|
className,
|
|
9
|
+
labelSize,
|
|
10
|
+
space,
|
|
11
|
+
hideBelow,
|
|
12
|
+
hideFrom,
|
|
13
|
+
style,
|
|
9
14
|
orientation = "horizontal",
|
|
10
15
|
decorative,
|
|
11
16
|
label,
|
|
@@ -24,24 +29,40 @@ const Separator = React.forwardRef(
|
|
|
24
29
|
}
|
|
25
30
|
const isDecorative = decorative ?? !labelled;
|
|
26
31
|
return /* @__PURE__ */ jsx(
|
|
27
|
-
|
|
32
|
+
AriaSeparator,
|
|
28
33
|
{
|
|
29
34
|
ref,
|
|
35
|
+
elementType: "div",
|
|
30
36
|
"data-slot": "separator",
|
|
37
|
+
"data-label-size": labelSize,
|
|
38
|
+
"data-hide-below": hideBelow,
|
|
39
|
+
"data-hide-from": hideFrom,
|
|
40
|
+
style: {
|
|
41
|
+
...style,
|
|
42
|
+
...space === void 0 ? void 0 : { marginBlock: padStepToken(space) }
|
|
43
|
+
},
|
|
31
44
|
"data-orientation": orientation,
|
|
32
45
|
"data-tone": tone,
|
|
33
46
|
"data-labelled": labelled ? "" : void 0,
|
|
34
47
|
"data-label-align": labelled ? labelAlign : void 0,
|
|
35
48
|
orientation,
|
|
36
|
-
decorative: isDecorative,
|
|
37
49
|
"aria-label": labelled && !isDecorative ? label : void 0,
|
|
38
50
|
className: cn("ui-separator", className),
|
|
39
51
|
...props,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
render: ({ role, "aria-orientation": ariaOrientation, ...domProps }) => /* @__PURE__ */ jsx(
|
|
53
|
+
"div",
|
|
54
|
+
{
|
|
55
|
+
role: isDecorative ? "none" : role,
|
|
56
|
+
"aria-orientation": isDecorative ? void 0 : ariaOrientation,
|
|
57
|
+
...props,
|
|
58
|
+
...domProps,
|
|
59
|
+
children: labelled ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
60
|
+
/* @__PURE__ */ jsx("span", { className: "ui-separator-rule", "aria-hidden": "true" }),
|
|
61
|
+
/* @__PURE__ */ jsx("span", { className: "ui-separator-label", "aria-hidden": isDecorative ? void 0 : true, children: label }),
|
|
62
|
+
/* @__PURE__ */ jsx("span", { className: "ui-separator-rule", "aria-hidden": "true" })
|
|
63
|
+
] }) : null
|
|
64
|
+
}
|
|
65
|
+
)
|
|
45
66
|
}
|
|
46
67
|
);
|
|
47
68
|
}
|
|
@@ -1,13 +1,58 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import type { AllowClearProp, ControlStatusProp, ControlVariantProp, MaxTagCountProp, MaxTagPlaceholderProp, SizeProp } from "../../props/vocabulary/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* TagInput is this library's answer to antd's `Select mode="tags"` — a free-text token field — so
|
|
5
|
+
* it takes the same token-level props antd puts on that mode.
|
|
6
|
+
*/
|
|
2
7
|
export type TagInputProps = {
|
|
3
8
|
value?: string[];
|
|
4
9
|
defaultValue?: string[];
|
|
5
10
|
onValueChange?: (tags: string[]) => void;
|
|
6
11
|
placeholder?: string;
|
|
7
12
|
disabled?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Read-only: the tags stay visible, selectable and submitted, but nothing can be added or
|
|
15
|
+
* removed — the draft field is read-only, the chip removers and the clear ✕ are withdrawn, and
|
|
16
|
+
* the container reports `aria-readonly`. Mirrors Select's readOnly contract (still focusable and
|
|
17
|
+
* still in the tab order, unlike `disabled`).
|
|
18
|
+
*/
|
|
19
|
+
readOnly?: boolean;
|
|
8
20
|
name?: string;
|
|
9
21
|
className?: string;
|
|
10
22
|
id?: string;
|
|
11
23
|
"aria-label"?: string;
|
|
24
|
+
/** Control height tier (antd `size`) — the shared `--control-height` ladder. */
|
|
25
|
+
size?: SizeProp;
|
|
26
|
+
/** Validation status (antd `status`). `error` also sets `aria-invalid`; `warning` recolours only. */
|
|
27
|
+
status?: ControlStatusProp;
|
|
28
|
+
/** Control surface (antd `variant`). Default `outlined`. */
|
|
29
|
+
variant?: ControlVariantProp;
|
|
30
|
+
/** Hard ceiling on how many tags may be held (antd `maxCount`). Further input is refused. */
|
|
31
|
+
maxCount?: number;
|
|
32
|
+
/**
|
|
33
|
+
* antd `allowClear` — a single ✕ that drops EVERY tag at once. Off by default (antd's own
|
|
34
|
+
* default for a tags field). The object form replaces the icon and/or the accessible label.
|
|
35
|
+
*/
|
|
36
|
+
allowClear?: AllowClearProp;
|
|
37
|
+
/** Fired after every tag is dropped through the ✕ (antd `onClear`). */
|
|
38
|
+
onClear?: () => void;
|
|
39
|
+
/** How many chips render before the rest collapse into the overflow node (antd `maxTagCount`). */
|
|
40
|
+
maxTagCount?: MaxTagCountProp;
|
|
41
|
+
/** The node standing in for what `maxTagCount` hid (antd `maxTagPlaceholder`). */
|
|
42
|
+
maxTagPlaceholder?: MaxTagPlaceholderProp;
|
|
43
|
+
/** Render one chip yourself (antd `tagRender`) — receives the value and an `onClose` remover. */
|
|
44
|
+
tagRender?: (props: {
|
|
45
|
+
value: string;
|
|
46
|
+
label: React.ReactNode;
|
|
47
|
+
onClose: () => void;
|
|
48
|
+
index: number;
|
|
49
|
+
disabled: boolean;
|
|
50
|
+
}) => React.ReactNode;
|
|
51
|
+
/**
|
|
52
|
+
* Characters that commit the draft into a tag (antd `tokenSeparators`). Default `[","]`; Enter
|
|
53
|
+
* always commits and is not a separator. Pasting a run containing a separator splits it into
|
|
54
|
+
* several tags, which is antd's behaviour and the reason the prop exists.
|
|
55
|
+
*/
|
|
56
|
+
tokenSeparators?: string[];
|
|
12
57
|
};
|
|
13
58
|
export declare const TagInput: React.ForwardRefExoticComponent<TagInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { X } from "lucide-react";
|
|
5
5
|
import { useTranslation } from "../../i18n/use-translation.js";
|
|
6
6
|
import { cn } from "../../lib/utils.js";
|
|
7
|
+
import {
|
|
8
|
+
applyMaxTagCount,
|
|
9
|
+
controlSurfaceAttrs,
|
|
10
|
+
resolveAllowClear
|
|
11
|
+
} from "../data-entry/control-surface.js";
|
|
12
|
+
function escapeForCharClass(character) {
|
|
13
|
+
return character.replace(/[\\\]^-]/g, "\\$&");
|
|
14
|
+
}
|
|
7
15
|
const TagInput = React.forwardRef(
|
|
8
16
|
({
|
|
9
17
|
value,
|
|
@@ -11,10 +19,21 @@ const TagInput = React.forwardRef(
|
|
|
11
19
|
onValueChange,
|
|
12
20
|
placeholder,
|
|
13
21
|
disabled,
|
|
22
|
+
readOnly,
|
|
14
23
|
name,
|
|
15
24
|
className,
|
|
16
25
|
id,
|
|
17
|
-
"aria-label": ariaLabel
|
|
26
|
+
"aria-label": ariaLabel,
|
|
27
|
+
size,
|
|
28
|
+
status,
|
|
29
|
+
variant,
|
|
30
|
+
maxCount,
|
|
31
|
+
allowClear,
|
|
32
|
+
onClear,
|
|
33
|
+
maxTagCount,
|
|
34
|
+
maxTagPlaceholder,
|
|
35
|
+
tagRender,
|
|
36
|
+
tokenSeparators = [","]
|
|
18
37
|
}, ref) => {
|
|
19
38
|
const { t } = useTranslation();
|
|
20
39
|
const [internal, setInternal] = React.useState(defaultValue);
|
|
@@ -27,11 +46,25 @@ const TagInput = React.forwardRef(
|
|
|
27
46
|
const add = (raw) => {
|
|
28
47
|
const tag = raw.trim();
|
|
29
48
|
if (!tag || tags.includes(tag)) return;
|
|
49
|
+
if (maxCount !== void 0 && tags.length >= maxCount) return;
|
|
30
50
|
commit([...tags, tag]);
|
|
31
51
|
};
|
|
52
|
+
const addAll = (raw) => {
|
|
53
|
+
let next = [...tags];
|
|
54
|
+
const pieces = tokenSeparators.length ? raw.split(new RegExp(`[${tokenSeparators.map(escapeForCharClass).join("")}]`)) : [raw];
|
|
55
|
+
for (const piece of pieces) {
|
|
56
|
+
const tag = piece.trim();
|
|
57
|
+
if (!tag || next.includes(tag)) continue;
|
|
58
|
+
if (maxCount !== void 0 && next.length >= maxCount) break;
|
|
59
|
+
next = [...next, tag];
|
|
60
|
+
}
|
|
61
|
+
if (next.length !== tags.length) commit(next);
|
|
62
|
+
};
|
|
32
63
|
const removeAt = (i) => commit(tags.filter((_, idx) => idx !== i));
|
|
33
64
|
const onKeyDown = (e) => {
|
|
34
|
-
if (
|
|
65
|
+
if (readOnly) return;
|
|
66
|
+
if (e.nativeEvent.isComposing) return;
|
|
67
|
+
if (e.key === "Enter" || tokenSeparators.includes(e.key)) {
|
|
35
68
|
e.preventDefault();
|
|
36
69
|
add(draft);
|
|
37
70
|
setDraft("");
|
|
@@ -39,35 +72,63 @@ const TagInput = React.forwardRef(
|
|
|
39
72
|
removeAt(tags.length - 1);
|
|
40
73
|
}
|
|
41
74
|
};
|
|
75
|
+
const clearControl = resolveAllowClear(allowClear, false, t("common.clear"));
|
|
76
|
+
const showClear = clearControl.enabled && tags.length > 0 && !disabled && !readOnly;
|
|
77
|
+
const clearAll = () => {
|
|
78
|
+
commit([]);
|
|
79
|
+
onClear?.();
|
|
80
|
+
};
|
|
81
|
+
const chips = tags.map((tag, index) => ({ value: tag, label: tag, index }));
|
|
82
|
+
const {
|
|
83
|
+
visible: visibleChips,
|
|
84
|
+
omitted: omittedChips,
|
|
85
|
+
overflow
|
|
86
|
+
} = applyMaxTagCount(chips, maxTagCount, maxTagPlaceholder);
|
|
42
87
|
return /* @__PURE__ */ jsxs(
|
|
43
88
|
"div",
|
|
44
89
|
{
|
|
45
90
|
"data-slot": "tag-input",
|
|
46
91
|
"aria-disabled": disabled || void 0,
|
|
47
|
-
|
|
92
|
+
"aria-readonly": readOnly || void 0,
|
|
93
|
+
...controlSurfaceAttrs({ variant, status, size }),
|
|
94
|
+
"aria-invalid": status === "error" ? true : void 0,
|
|
95
|
+
className: cn(
|
|
96
|
+
"ui-tag-input ui-control-surface",
|
|
97
|
+
disabled && "ui-tag-input-disabled",
|
|
98
|
+
className
|
|
99
|
+
),
|
|
48
100
|
children: [
|
|
49
|
-
tags.length > 0 ? /* @__PURE__ */
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
101
|
+
tags.length > 0 ? /* @__PURE__ */ jsxs("ul", { role: "list", className: "ui-tag-input-list", "data-slot": "tag-input-list", children: [
|
|
102
|
+
visibleChips.map((chip) => /* @__PURE__ */ jsx(
|
|
103
|
+
"li",
|
|
104
|
+
{
|
|
105
|
+
role: "listitem",
|
|
106
|
+
className: "ui-tag-input-chip",
|
|
107
|
+
"data-slot": "tag-input-chip",
|
|
108
|
+
children: tagRender ? tagRender({
|
|
109
|
+
value: chip.value,
|
|
110
|
+
label: chip.label,
|
|
111
|
+
index: chip.index,
|
|
112
|
+
disabled: Boolean(disabled) || Boolean(readOnly),
|
|
113
|
+
onClose: () => removeAt(chip.index)
|
|
114
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
115
|
+
chip.value,
|
|
116
|
+
!disabled && !readOnly ? /* @__PURE__ */ jsx(
|
|
117
|
+
"button",
|
|
118
|
+
{
|
|
119
|
+
type: "button",
|
|
120
|
+
className: "ui-tag-input-remove",
|
|
121
|
+
"aria-label": t("ui.tagInput.removeTag", { tag: chip.value }),
|
|
122
|
+
onClick: () => removeAt(chip.index),
|
|
123
|
+
children: /* @__PURE__ */ jsx(X, { "aria-hidden": "true" })
|
|
124
|
+
}
|
|
125
|
+
) : null
|
|
126
|
+
] })
|
|
127
|
+
},
|
|
128
|
+
chip.value
|
|
129
|
+
)),
|
|
130
|
+
omittedChips.length > 0 ? /* @__PURE__ */ jsx("li", { role: "listitem", className: "ui-tag-input-chip", "data-slot": "tag-input-overflow", children: overflow ?? t("dataEntry.selection.overflow", { count: omittedChips.length }) }) : null
|
|
131
|
+
] }) : null,
|
|
71
132
|
/* @__PURE__ */ jsx(
|
|
72
133
|
"input",
|
|
73
134
|
{
|
|
@@ -76,12 +137,21 @@ const TagInput = React.forwardRef(
|
|
|
76
137
|
type: "text",
|
|
77
138
|
className: "ui-tag-input-field",
|
|
78
139
|
value: draft,
|
|
79
|
-
placeholder: tags.length === 0 ? placeholder : void 0,
|
|
140
|
+
placeholder: tags.length === 0 && !readOnly ? placeholder : void 0,
|
|
80
141
|
disabled,
|
|
142
|
+
readOnly,
|
|
81
143
|
"aria-label": ariaLabel ?? t("ui.tagInput.inputLabel"),
|
|
82
144
|
onChange: (e) => setDraft(e.target.value),
|
|
83
145
|
onKeyDown,
|
|
146
|
+
onPaste: (e) => {
|
|
147
|
+
const text = e.clipboardData.getData("text");
|
|
148
|
+
if (!tokenSeparators.some((separator) => text.includes(separator))) return;
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
addAll(text);
|
|
151
|
+
setDraft("");
|
|
152
|
+
},
|
|
84
153
|
onBlur: () => {
|
|
154
|
+
if (readOnly) return;
|
|
85
155
|
if (draft.trim()) {
|
|
86
156
|
add(draft);
|
|
87
157
|
setDraft("");
|
|
@@ -89,6 +159,18 @@ const TagInput = React.forwardRef(
|
|
|
89
159
|
}
|
|
90
160
|
}
|
|
91
161
|
),
|
|
162
|
+
showClear ? /* @__PURE__ */ jsx(
|
|
163
|
+
"button",
|
|
164
|
+
{
|
|
165
|
+
type: "button",
|
|
166
|
+
tabIndex: -1,
|
|
167
|
+
"aria-label": clearControl.label,
|
|
168
|
+
"data-slot": "tag-input-clear",
|
|
169
|
+
className: "ui-control-inline-affix-action ui-tag-input-clear",
|
|
170
|
+
onClick: clearAll,
|
|
171
|
+
children: clearControl.clearIcon ?? /* @__PURE__ */ jsx(X, { className: "ui-control-inline-affix-icon", "aria-hidden": "true" })
|
|
172
|
+
}
|
|
173
|
+
) : null,
|
|
92
174
|
/* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "sr-only", "data-slot": "tag-input-status", children: t("ui.tagInput.tagCount", { count: tags.length }) }),
|
|
93
175
|
name ? /* @__PURE__ */ jsx("input", { type: "hidden", name, value: tags.join(",") }) : null
|
|
94
176
|
]
|
|
@@ -1,19 +1,64 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
|
|
3
2
|
import { type ToggleCountFields, type ToggleProp } from "./toggle.js";
|
|
4
3
|
type ToggleGroupVariant = ToggleProp["variant"];
|
|
5
4
|
type ToggleGroupSize = ToggleProp["size"];
|
|
6
|
-
|
|
5
|
+
type ToggleGroupBaseProp = Omit<React.ComponentPropsWithoutRef<"div">, "defaultValue" | "dir"> & {
|
|
7
6
|
variant?: ToggleGroupVariant;
|
|
8
7
|
size?: ToggleGroupSize;
|
|
9
|
-
|
|
8
|
+
/** Disable every item at once — RAC `isDisabled`. */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** Which way the arrow keys walk the group. */
|
|
11
|
+
orientation?: "horizontal" | "vertical";
|
|
12
|
+
/**
|
|
13
|
+
* Writing direction. It still lands on the DOM node, but React Aria reads the direction it
|
|
14
|
+
* navigates by from the ambient locale (`I18nProvider`), NOT from this attribute — where Radix
|
|
15
|
+
* read this prop directly. An RTL app must set the locale, not just `dir`.
|
|
16
|
+
*/
|
|
17
|
+
dir?: "ltr" | "rtl";
|
|
18
|
+
/**
|
|
19
|
+
* Accepted for source compatibility with the Radix era, where it wrapped arrow-key focus around
|
|
20
|
+
* the ends. React Aria's toolbar navigation stops at the ends and has no equivalent switch, so
|
|
21
|
+
* this prop no longer changes anything.
|
|
22
|
+
*/
|
|
23
|
+
loop?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* `type` is the discriminant, exactly as it was under Radix: `"single"` reports the one selected
|
|
27
|
+
* value as a string (`""` once it is deselected), `"multiple"` reports an array. React Aria models
|
|
28
|
+
* both as `selectionMode` + a `Set` of keys — that Set is built and unpacked here so the public
|
|
29
|
+
* shape stays a string / an array of strings.
|
|
30
|
+
*/
|
|
31
|
+
type ToggleGroupSingleProp = ToggleGroupBaseProp & {
|
|
32
|
+
type: "single";
|
|
33
|
+
value?: string;
|
|
34
|
+
defaultValue?: string;
|
|
35
|
+
onValueChange?: (value: string) => void;
|
|
36
|
+
};
|
|
37
|
+
type ToggleGroupMultipleProp = ToggleGroupBaseProp & {
|
|
38
|
+
type: "multiple";
|
|
39
|
+
value?: string[];
|
|
40
|
+
defaultValue?: string[];
|
|
41
|
+
onValueChange?: (value: string[]) => void;
|
|
42
|
+
};
|
|
43
|
+
type ToggleGroupProp = ToggleGroupSingleProp | ToggleGroupMultipleProp;
|
|
44
|
+
export declare const ToggleGroup: React.ForwardRefExoticComponent<ToggleGroupProp & React.RefAttributes<HTMLDivElement>>;
|
|
10
45
|
/** Same vocabulary as `Toggle` and `Button` — one counter pill for the whole library. */
|
|
11
|
-
export type ToggleGroupItemProp = React.ComponentPropsWithoutRef<
|
|
46
|
+
export type ToggleGroupItemProp = Omit<React.ComponentPropsWithoutRef<"button">, "value"> & ToggleCountFields & {
|
|
47
|
+
/**
|
|
48
|
+
* This item's key in the group's value. React Aria calls it `id` (the key it stores in
|
|
49
|
+
* `selectedKeys`); the public spelling stays `value`, as it was under Radix.
|
|
50
|
+
*/
|
|
51
|
+
value: string;
|
|
12
52
|
variant?: ToggleGroupVariant;
|
|
13
53
|
size?: ToggleGroupSize;
|
|
14
54
|
};
|
|
15
55
|
export type ToggleGroupItemProps = ToggleGroupItemProp;
|
|
16
|
-
export declare const ToggleGroupItem: React.ForwardRefExoticComponent<Omit<
|
|
56
|
+
export declare const ToggleGroupItem: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "value"> & ToggleCountFields & {
|
|
57
|
+
/**
|
|
58
|
+
* This item's key in the group's value. React Aria calls it `id` (the key it stores in
|
|
59
|
+
* `selectedKeys`); the public spelling stays `value`, as it was under Radix.
|
|
60
|
+
*/
|
|
61
|
+
value: string;
|
|
17
62
|
variant?: ToggleGroupVariant;
|
|
18
63
|
size?: ToggleGroupSize;
|
|
19
64
|
} & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,26 +1,77 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
ToggleButton,
|
|
6
|
+
ToggleButtonGroup,
|
|
7
|
+
ToggleGroupStateContext
|
|
8
|
+
} from "react-aria-components";
|
|
5
9
|
import { cn } from "../../lib/utils.js";
|
|
6
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
restoreDomProps,
|
|
12
|
+
toggleVariants,
|
|
13
|
+
useCounterPill
|
|
14
|
+
} from "./toggle.js";
|
|
7
15
|
const ToggleGroupContext = React.createContext({});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
function toSelectedKeys(value) {
|
|
17
|
+
if (value == null) {
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
return new Set(value);
|
|
22
|
+
}
|
|
23
|
+
return new Set(value === "" ? [] : [value]);
|
|
24
|
+
}
|
|
25
|
+
const ToggleGroup = React.forwardRef(
|
|
26
|
+
// No destructuring defaults: an unset prop must stay `undefined` so the emitted attribute is
|
|
27
|
+
// either absent or a declared union member.
|
|
28
|
+
// is NOT in the `sm | md | lg` size union — the group advertised an invalid value for its own
|
|
29
|
+
// type.) The real default lives in `toggleVariants`, applied per item.
|
|
30
|
+
({
|
|
31
|
+
className,
|
|
32
|
+
variant,
|
|
33
|
+
size,
|
|
34
|
+
children,
|
|
35
|
+
type,
|
|
36
|
+
value,
|
|
37
|
+
defaultValue,
|
|
38
|
+
onValueChange,
|
|
39
|
+
disabled,
|
|
40
|
+
loop: _loop,
|
|
41
|
+
...props
|
|
42
|
+
}, ref) => {
|
|
43
|
+
const context = React.useMemo(() => ({ variant, size }), [variant, size]);
|
|
44
|
+
const selectedKeys = React.useMemo(() => toSelectedKeys(value), [value]);
|
|
45
|
+
const defaultSelectedKeys = React.useMemo(() => toSelectedKeys(defaultValue), [defaultValue]);
|
|
46
|
+
const handleSelectionChange = (keys) => {
|
|
47
|
+
const next = [...keys].map(String);
|
|
48
|
+
if (type === "single") {
|
|
49
|
+
onValueChange?.(next[0] ?? "");
|
|
50
|
+
} else {
|
|
51
|
+
onValueChange?.(next);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return /* @__PURE__ */ jsx(
|
|
55
|
+
ToggleButtonGroup,
|
|
56
|
+
{
|
|
57
|
+
ref,
|
|
58
|
+
"data-slot": "toggle-group",
|
|
59
|
+
"data-variant": variant,
|
|
60
|
+
"data-size": size,
|
|
61
|
+
className: cn("ui-toggle-group", className),
|
|
62
|
+
...props,
|
|
63
|
+
selectionMode: type,
|
|
64
|
+
selectedKeys,
|
|
65
|
+
defaultSelectedKeys,
|
|
66
|
+
onSelectionChange: handleSelectionChange,
|
|
67
|
+
isDisabled: disabled,
|
|
68
|
+
render: (domProps) => /* @__PURE__ */ jsx("div", { ...props, ...domProps, tabIndex: props.tabIndex ?? domProps.tabIndex }),
|
|
69
|
+
children: /* @__PURE__ */ jsx(ToggleGroupContext.Provider, { value: context, children })
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
ToggleGroup.displayName = "ToggleGroup";
|
|
24
75
|
const ToggleGroupItem = React.forwardRef(
|
|
25
76
|
({
|
|
26
77
|
className,
|
|
@@ -32,6 +83,8 @@ const ToggleGroupItem = React.forwardRef(
|
|
|
32
83
|
countLabel,
|
|
33
84
|
children,
|
|
34
85
|
"aria-label": ariaLabel,
|
|
86
|
+
value,
|
|
87
|
+
disabled,
|
|
35
88
|
...props
|
|
36
89
|
}, ref) => {
|
|
37
90
|
const context = React.useContext(ToggleGroupContext);
|
|
@@ -44,16 +97,22 @@ const ToggleGroupItem = React.forwardRef(
|
|
|
44
97
|
countLabel,
|
|
45
98
|
ariaLabel
|
|
46
99
|
});
|
|
100
|
+
const groupState = React.useContext(ToggleGroupStateContext);
|
|
101
|
+
const isPressed = groupState?.selectedKeys.has(value) ?? false;
|
|
47
102
|
return /* @__PURE__ */ jsxs(
|
|
48
|
-
|
|
103
|
+
ToggleButton,
|
|
49
104
|
{
|
|
50
105
|
ref,
|
|
51
106
|
"data-slot": "toggle-group-item",
|
|
107
|
+
"data-state": isPressed ? "on" : "off",
|
|
52
108
|
"data-variant": resolvedVariant,
|
|
53
109
|
"data-size": resolvedSize,
|
|
54
110
|
"aria-label": resolvedAriaLabel,
|
|
55
111
|
className: cn(toggleVariants({ variant: resolvedVariant, size: resolvedSize }), className),
|
|
56
112
|
...props,
|
|
113
|
+
id: value,
|
|
114
|
+
isDisabled: disabled,
|
|
115
|
+
render: (domProps) => restoreDomProps(props, domProps),
|
|
57
116
|
children: [
|
|
58
117
|
children,
|
|
59
118
|
pill
|
|
@@ -62,7 +121,7 @@ const ToggleGroupItem = React.forwardRef(
|
|
|
62
121
|
);
|
|
63
122
|
}
|
|
64
123
|
);
|
|
65
|
-
ToggleGroupItem.displayName =
|
|
124
|
+
ToggleGroupItem.displayName = "ToggleGroupItem";
|
|
66
125
|
export {
|
|
67
126
|
ToggleGroup,
|
|
68
127
|
ToggleGroupItem
|