@techsio/ui-kit 0.57.0 → 0.59.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 +128 -133
- package/dist/atoms/action-icon.js +9 -8
- package/dist/atoms/button.js +114 -18
- package/dist/atoms/checkbox.js +77 -17
- package/dist/atoms/hotkeys.js +26 -7
- package/dist/atoms/icon.js +5 -5
- package/dist/atoms/image.js +118 -3
- package/dist/atoms/input.js +57 -9
- package/dist/atoms/label.js +13 -4
- package/dist/atoms/link-button.js +15 -12
- package/dist/atoms/link.js +18 -4
- package/dist/atoms/numeric-input.js +362 -84
- package/dist/atoms/rating.js +306 -73
- package/dist/atoms/skeleton.js +18 -14
- package/dist/atoms/status-text.js +31 -18
- package/dist/atoms/textarea.js +59 -12
- package/dist/atoms/tooltip.js +64 -43
- package/dist/hotkeys.js +1 -0
- package/dist/internal/choice-control.js +173 -0
- package/dist/internal/combobox-query-sync.js +11 -0
- package/dist/internal/date-picker-coordinator.js +56 -40
- package/dist/internal/date-picker-dom.js +44 -0
- package/dist/internal/date-picker-input.js +30 -0
- package/dist/internal/described-by.js +23 -18
- package/dist/internal/form-control-lifecycle.js +122 -0
- package/dist/internal/molecules/command.context.js +1 -0
- package/dist/internal/molecules/drawer.context.js +1 -0
- package/dist/internal/molecules/vertical-navigation.context.js +1 -0
- package/dist/internal/molecules/vertical-navigation.styles.js +9 -2
- package/dist/internal/numeric-input-editing.js +87 -0
- package/dist/internal/organisms/sidebar.context.js +1 -0
- package/dist/internal/organisms/sidebar.focus.js +1 -0
- package/dist/internal/overlay-portal.js +72 -0
- package/dist/internal/reduced-motion.js +1 -0
- package/dist/internal/use-effective-disabled.js +8 -0
- package/dist/molecules/accordion.js +44 -30
- package/dist/molecules/availability-status.js +1 -0
- package/dist/molecules/breadcrumb.js +11 -11
- package/dist/molecules/carousel.js +279 -97
- package/dist/molecules/cascade-select.js +327 -81
- package/dist/molecules/chart.js +427 -78
- package/dist/molecules/color-select.js +181 -62
- package/dist/molecules/combobox.js +537 -182
- package/dist/molecules/command.js +2 -1
- package/dist/molecules/date-picker.js +629 -119
- package/dist/molecules/dialog.js +89 -48
- package/dist/molecules/drawer.js +63 -6
- package/dist/molecules/file-upload.js +373 -37
- package/dist/molecules/form-checkbox.js +65 -22
- package/dist/molecules/form-error-summary.js +29 -5
- package/dist/molecules/form-input.js +26 -30
- package/dist/molecules/form-numeric-input.js +11 -9
- package/dist/molecules/form-textarea.js +26 -23
- package/dist/molecules/menu.js +170 -47
- package/dist/molecules/pagination.js +100 -28
- package/dist/molecules/phone-input.js +172 -37
- package/dist/molecules/popover.js +53 -26
- package/dist/molecules/price-block.js +1 -0
- package/dist/molecules/product-card.js +85 -23
- package/dist/molecules/quantity-field.js +4 -2
- package/dist/molecules/radio-card.js +102 -30
- package/dist/molecules/radio-group.js +108 -31
- package/dist/molecules/search-form.js +116 -13
- package/dist/molecules/select.js +226 -81
- package/dist/molecules/slider.js +141 -30
- package/dist/molecules/steps.js +181 -50
- package/dist/molecules/switch.js +86 -20
- package/dist/molecules/tabs.js +227 -31
- package/dist/molecules/toast.js +155 -53
- package/dist/molecules/totals-summary.js +2 -1
- package/dist/molecules/tour.js +9 -5
- package/dist/molecules/tree-view.js +255 -109
- package/dist/molecules/vertical-navigation.js +8 -4
- package/dist/organisms/data-table.fields.js +26 -5
- package/dist/organisms/data-table.helpers.js +6 -2
- package/dist/organisms/data-table.js +587 -154
- package/dist/organisms/footer.js +18 -11
- package/dist/organisms/gallery.js +61 -24
- package/dist/organisms/header.js +106 -32
- package/dist/organisms/line-item.js +1 -0
- package/dist/organisms/sidebar.js +1 -0
- package/dist/organisms/table.js +22 -7
- package/dist/src/atoms/action-icon.d.ts +10 -10
- package/dist/src/atoms/action-icon.d.ts.map +1 -1
- package/dist/src/atoms/badge.d.ts +3 -3
- package/dist/src/atoms/badge.d.ts.map +1 -1
- package/dist/src/atoms/button.d.ts +47 -24
- package/dist/src/atoms/button.d.ts.map +1 -1
- package/dist/src/atoms/checkbox.d.ts +6 -5
- package/dist/src/atoms/checkbox.d.ts.map +1 -1
- package/dist/src/atoms/hotkeys.d.ts +3 -2
- package/dist/src/atoms/hotkeys.d.ts.map +1 -1
- package/dist/src/atoms/icon.d.ts +18 -17
- package/dist/src/atoms/icon.d.ts.map +1 -1
- package/dist/src/atoms/image.d.ts +38 -7
- package/dist/src/atoms/image.d.ts.map +1 -1
- package/dist/src/atoms/input.d.ts +23 -14
- package/dist/src/atoms/input.d.ts.map +1 -1
- package/dist/src/atoms/label.d.ts +4 -4
- package/dist/src/atoms/label.d.ts.map +1 -1
- package/dist/src/atoms/link-button.d.ts +78 -31
- package/dist/src/atoms/link-button.d.ts.map +1 -1
- package/dist/src/atoms/link.d.ts +30 -9
- package/dist/src/atoms/link.d.ts.map +1 -1
- package/dist/src/atoms/numeric-input.d.ts +24 -19
- package/dist/src/atoms/numeric-input.d.ts.map +1 -1
- package/dist/src/atoms/rating.d.ts +54 -26
- package/dist/src/atoms/rating.d.ts.map +1 -1
- package/dist/src/atoms/skeleton.d.ts +9 -9
- package/dist/src/atoms/skeleton.d.ts.map +1 -1
- package/dist/src/atoms/status-text.d.ts +21 -13
- package/dist/src/atoms/status-text.d.ts.map +1 -1
- package/dist/src/atoms/textarea.d.ts +22 -20
- package/dist/src/atoms/textarea.d.ts.map +1 -1
- package/dist/src/atoms/tooltip.d.ts +5 -5
- package/dist/src/atoms/tooltip.d.ts.map +1 -1
- package/dist/src/hotkeys.d.ts +1 -1
- package/dist/src/hotkeys.d.ts.map +1 -1
- package/dist/src/internal/choice-control.d.ts +18 -0
- package/dist/src/internal/choice-control.d.ts.map +1 -0
- package/dist/src/internal/combobox-query-sync.d.ts +4 -0
- package/dist/src/internal/combobox-query-sync.d.ts.map +1 -0
- package/dist/src/internal/date-picker-coordinator.d.ts +7 -1
- package/dist/src/internal/date-picker-coordinator.d.ts.map +1 -1
- package/dist/src/internal/date-picker-dom.d.ts +10 -0
- package/dist/src/internal/date-picker-dom.d.ts.map +1 -0
- package/dist/src/internal/date-picker-input.d.ts +7 -0
- package/dist/src/internal/date-picker-input.d.ts.map +1 -0
- package/dist/src/internal/described-by.d.ts +7 -1
- package/dist/src/internal/described-by.d.ts.map +1 -1
- package/dist/src/internal/form-control-lifecycle.d.ts +22 -0
- package/dist/src/internal/form-control-lifecycle.d.ts.map +1 -0
- package/dist/src/internal/molecules/vertical-navigation.context.d.ts +1 -1
- package/dist/src/internal/molecules/vertical-navigation.context.d.ts.map +1 -1
- package/dist/src/internal/molecules/vertical-navigation.styles.d.ts +21 -0
- package/dist/src/internal/molecules/vertical-navigation.styles.d.ts.map +1 -1
- package/dist/src/internal/numeric-input-editing.d.ts +13 -0
- package/dist/src/internal/numeric-input-editing.d.ts.map +1 -0
- package/dist/src/internal/overlay-portal.d.ts +18 -0
- package/dist/src/internal/overlay-portal.d.ts.map +1 -0
- package/dist/src/internal/use-effective-disabled.d.ts +4 -0
- package/dist/src/internal/use-effective-disabled.d.ts.map +1 -0
- package/dist/src/molecules/accordion.d.ts +25 -19
- package/dist/src/molecules/accordion.d.ts.map +1 -1
- package/dist/src/molecules/availability-status.d.ts +4 -1
- package/dist/src/molecules/availability-status.d.ts.map +1 -1
- package/dist/src/molecules/breadcrumb.d.ts +2 -2
- package/dist/src/molecules/breadcrumb.d.ts.map +1 -1
- package/dist/src/molecules/carousel.d.ts +51 -52
- package/dist/src/molecules/carousel.d.ts.map +1 -1
- package/dist/src/molecules/cascade-select.d.ts +23 -8
- package/dist/src/molecules/cascade-select.d.ts.map +1 -1
- package/dist/src/molecules/chart.d.ts +18 -1
- package/dist/src/molecules/chart.d.ts.map +1 -1
- package/dist/src/molecules/color-select.d.ts +19 -3
- package/dist/src/molecules/color-select.d.ts.map +1 -1
- package/dist/src/molecules/combobox.d.ts +27 -5
- package/dist/src/molecules/combobox.d.ts.map +1 -1
- package/dist/src/molecules/command.d.ts +1 -1
- package/dist/src/molecules/date-picker.d.ts +30 -4
- package/dist/src/molecules/date-picker.d.ts.map +1 -1
- package/dist/src/molecules/dialog.d.ts +17 -4
- package/dist/src/molecules/dialog.d.ts.map +1 -1
- package/dist/src/molecules/drawer.d.ts +4 -4
- package/dist/src/molecules/drawer.d.ts.map +1 -1
- package/dist/src/molecules/file-upload.d.ts +11 -6
- package/dist/src/molecules/file-upload.d.ts.map +1 -1
- package/dist/src/molecules/form-checkbox.d.ts +7 -2
- package/dist/src/molecules/form-checkbox.d.ts.map +1 -1
- package/dist/src/molecules/form-error-summary.d.ts +4 -3
- package/dist/src/molecules/form-error-summary.d.ts.map +1 -1
- package/dist/src/molecules/form-input.d.ts +5 -6
- package/dist/src/molecules/form-input.d.ts.map +1 -1
- package/dist/src/molecules/form-numeric-input.d.ts +5 -5
- package/dist/src/molecules/form-numeric-input.d.ts.map +1 -1
- package/dist/src/molecules/form-textarea.d.ts +5 -6
- package/dist/src/molecules/form-textarea.d.ts.map +1 -1
- package/dist/src/molecules/menu.d.ts +17 -3
- package/dist/src/molecules/menu.d.ts.map +1 -1
- package/dist/src/molecules/pagination.d.ts +1 -1
- package/dist/src/molecules/pagination.d.ts.map +1 -1
- package/dist/src/molecules/phone-input.d.ts +4 -1
- package/dist/src/molecules/phone-input.d.ts.map +1 -1
- package/dist/src/molecules/popover.d.ts +7 -1
- package/dist/src/molecules/popover.d.ts.map +1 -1
- package/dist/src/molecules/price-block.d.ts +1 -1
- package/dist/src/molecules/price-block.d.ts.map +1 -1
- package/dist/src/molecules/product-card.d.ts +127 -27
- package/dist/src/molecules/product-card.d.ts.map +1 -1
- package/dist/src/molecules/quantity-field.d.ts +1 -1
- package/dist/src/molecules/quantity-field.d.ts.map +1 -1
- package/dist/src/molecules/radio-card.d.ts +10 -3
- package/dist/src/molecules/radio-card.d.ts.map +1 -1
- package/dist/src/molecules/radio-group.d.ts +15 -6
- package/dist/src/molecules/radio-group.d.ts.map +1 -1
- package/dist/src/molecules/search-form.d.ts +37 -12
- package/dist/src/molecules/search-form.d.ts.map +1 -1
- package/dist/src/molecules/select.d.ts +34 -29
- package/dist/src/molecules/select.d.ts.map +1 -1
- package/dist/src/molecules/slider.d.ts +23 -2
- package/dist/src/molecules/slider.d.ts.map +1 -1
- package/dist/src/molecules/steps.d.ts +30 -10
- package/dist/src/molecules/steps.d.ts.map +1 -1
- package/dist/src/molecules/switch.d.ts +54 -33
- package/dist/src/molecules/switch.d.ts.map +1 -1
- package/dist/src/molecules/tabs.d.ts +11 -11
- package/dist/src/molecules/tabs.d.ts.map +1 -1
- package/dist/src/molecules/toast.d.ts +38 -14
- package/dist/src/molecules/toast.d.ts.map +1 -1
- package/dist/src/molecules/totals-summary.d.ts +1 -1
- package/dist/src/molecules/totals-summary.d.ts.map +1 -1
- package/dist/src/molecules/tour.d.ts +1 -1
- package/dist/src/molecules/tour.d.ts.map +1 -1
- package/dist/src/molecules/tree-view.d.ts +16 -20
- package/dist/src/molecules/tree-view.d.ts.map +1 -1
- package/dist/src/molecules/vertical-navigation.d.ts +2 -2
- package/dist/src/molecules/vertical-navigation.d.ts.map +1 -1
- package/dist/src/organisms/data-table.d.ts +28 -3
- package/dist/src/organisms/data-table.d.ts.map +1 -1
- package/dist/src/organisms/data-table.fields.d.ts +4 -1
- package/dist/src/organisms/data-table.fields.d.ts.map +1 -1
- package/dist/src/organisms/data-table.helpers.d.ts +5 -12
- package/dist/src/organisms/data-table.helpers.d.ts.map +1 -1
- package/dist/src/organisms/footer.d.ts +5 -5
- package/dist/src/organisms/footer.d.ts.map +1 -1
- package/dist/src/organisms/gallery.d.ts +11 -9
- package/dist/src/organisms/gallery.d.ts.map +1 -1
- package/dist/src/organisms/header.d.ts +24 -22
- package/dist/src/organisms/header.d.ts.map +1 -1
- package/dist/src/organisms/table.d.ts +14 -14
- package/dist/src/organisms/table.d.ts.map +1 -1
- package/dist/src/templates/accordion.d.ts +8 -6
- package/dist/src/templates/accordion.d.ts.map +1 -1
- package/dist/src/templates/breadcrumb.d.ts +1 -1
- package/dist/src/templates/breadcrumb.d.ts.map +1 -1
- package/dist/src/templates/carousel.d.ts +3 -3
- package/dist/src/templates/carousel.d.ts.map +1 -1
- package/dist/src/templates/facet-filter-panel.d.ts +9 -3
- package/dist/src/templates/facet-filter-panel.d.ts.map +1 -1
- package/dist/src/templates/gallery.d.ts +2 -2
- package/dist/src/templates/gallery.d.ts.map +1 -1
- package/dist/src/templates/numeric-input.d.ts +1 -1
- package/dist/src/templates/numeric-input.d.ts.map +1 -1
- package/dist/src/templates/popover.d.ts +4 -2
- package/dist/src/templates/popover.d.ts.map +1 -1
- package/dist/src/templates/product-card.d.ts +12 -4
- package/dist/src/templates/product-card.d.ts.map +1 -1
- package/dist/src/templates/search-suggestions.d.ts +1 -1
- package/dist/src/templates/select.d.ts +7 -2
- package/dist/src/templates/select.d.ts.map +1 -1
- package/dist/src/templates/tabs.d.ts +8 -7
- package/dist/src/templates/tabs.d.ts.map +1 -1
- package/dist/src/theme/theme-config.d.ts +9 -16
- package/dist/src/theme/theme-config.d.ts.map +1 -1
- package/dist/src/theme/theme-provider.d.ts +16 -21
- package/dist/src/theme/theme-provider.d.ts.map +1 -1
- package/dist/src/theme/theme-toggle.d.ts.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/templates/accordion.js +3 -1
- package/dist/templates/breadcrumb.js +11 -4
- package/dist/templates/carousel.js +3 -6
- package/dist/templates/facet-filter-panel.js +121 -52
- package/dist/templates/gallery.js +6 -2
- package/dist/templates/numeric-input.js +6 -1
- package/dist/templates/popover.js +6 -1
- package/dist/templates/product-card.js +52 -26
- package/dist/templates/select.js +6 -1
- package/dist/templates/tabs.js +4 -2
- package/dist/theme/theme-config.js +8 -16
- package/dist/theme/theme-provider.js +89 -63
- package/dist/theme/theme-toggle.js +17 -9
- package/dist/utils.js +11 -1
- package/package.json +9 -5
- package/src/tokens/_base.css +4 -3
- package/src/tokens/_business-atoms.css +96 -0
- package/src/tokens/_foundation-overrides.css +251 -0
- package/src/tokens/_reset.css +10 -10
- package/src/tokens/_scheme-scopes.css +4194 -0
- package/src/tokens/_semantic.css +1 -23
- package/src/tokens/_tokens-base.css +36 -32
- package/src/tokens/_typography.css +2 -1
- package/src/tokens/components/_form-control.css +149 -6
- package/src/tokens/components/_popup-surface.css +15 -29
- package/src/tokens/components/atoms/_action-icon.css +49 -0
- package/src/tokens/components/atoms/_button.css +77 -0
- package/src/tokens/components/atoms/_checkbox.css +47 -4
- package/src/tokens/components/atoms/_hotkeys.css +2 -0
- package/src/tokens/components/atoms/_icon.css +60 -7
- package/src/tokens/components/atoms/_image.css +18 -0
- package/src/tokens/components/atoms/_input.css +20 -0
- package/src/tokens/components/atoms/_label.css +3 -7
- package/src/tokens/components/atoms/_link.css +47 -5
- package/src/tokens/components/atoms/_numeric-input.css +121 -2
- package/src/tokens/components/atoms/_rating.css +55 -6
- package/src/tokens/components/atoms/_skeleton.css +12 -2
- package/src/tokens/components/atoms/_status-text.css +35 -5
- package/src/tokens/components/atoms/_textarea.css +32 -3
- package/src/tokens/components/atoms/_tooltip.css +25 -0
- package/src/tokens/components/molecules/_accordion.css +46 -5
- package/src/tokens/components/molecules/_breadcrumb.css +15 -4
- package/src/tokens/components/molecules/_carousel.css +67 -0
- package/src/tokens/components/molecules/_cascade-select.css +104 -0
- package/src/tokens/components/molecules/_chart.css +32 -16
- package/src/tokens/components/molecules/_color-select.css +21 -0
- package/src/tokens/components/molecules/_combobox.css +81 -0
- package/src/tokens/components/molecules/_command.css +1 -0
- package/src/tokens/components/molecules/_date-picker.css +66 -10
- package/src/tokens/components/molecules/_dialog.css +36 -4
- package/src/tokens/components/molecules/_drawer.css +39 -3
- package/src/tokens/components/molecules/_file-upload.css +16 -1
- package/src/tokens/components/molecules/_menu.css +17 -0
- package/src/tokens/components/molecules/_pagination.css +19 -0
- package/src/tokens/components/molecules/_phone-input.css +20 -5
- package/src/tokens/components/molecules/_popover.css +34 -0
- package/src/tokens/components/molecules/_product-card.css +70 -0
- package/src/tokens/components/molecules/_radio-card.css +35 -0
- package/src/tokens/components/molecules/_radio-group.css +8 -0
- package/src/tokens/components/molecules/_select.css +33 -0
- package/src/tokens/components/molecules/_slider.css +5 -0
- package/src/tokens/components/molecules/_steps.css +52 -0
- package/src/tokens/components/molecules/_switch.css +59 -10
- package/src/tokens/components/molecules/_tabs.css +61 -3
- package/src/tokens/components/molecules/_toast.css +60 -0
- package/src/tokens/components/molecules/_totals-summary.css +22 -22
- package/src/tokens/components/molecules/_tour.css +16 -1
- package/src/tokens/components/molecules/_tree-view.css +27 -3
- package/src/tokens/components/molecules/_vertical-navigation.css +21 -3
- package/src/tokens/components/organisms/_data-table.css +97 -0
- package/src/tokens/components/organisms/_footer.css +9 -0
- package/src/tokens/components/organisms/_gallery.css +11 -0
- package/src/tokens/components/organisms/_header.css +22 -0
- package/src/tokens/components/organisms/_sidebar.css +1 -1
- package/src/tokens/components/organisms/_table.css +31 -0
- package/src/tokens/components/templates/_facet-filter-panel.css +11 -1
- package/src/tokens/figma/akros/variables.css +15 -6
- package/src/tokens/figma/brand-overrides.css +171 -57
- package/src/tokens/figma/business/variables.css +15 -6
- package/src/tokens/figma/cyber/variables.css +115 -38
- package/src/tokens/figma/cyber-dark/variables.css +115 -38
- package/src/tokens/figma/dark/variables.css +13 -4
- package/src/tokens/figma/light/variables.css +62 -49
- package/src/tokens/figma/{neo → n1}/variables.css +123 -114
- package/src/tokens/figma/variables.css +658 -249
- package/src/tokens/theme.css +24 -4
- package/src/tokens/_colors.css +0 -5
- package/src/tokens/figma/neo-dark/variables.css +0 -457
package/dist/molecules/tour.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx } from "react/jsx-runtime";
|
|
2
3
|
import { Portal, mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
3
4
|
import { connect, machine } from "@zag-js/tour";
|
|
@@ -13,10 +14,10 @@ const tourStyles = tv({
|
|
|
13
14
|
content: "tour-layer tour-content tour-border relative flex flex-col gap-tour-content rounded-tour bg-tour-bg p-tour text-tour-fg shadow-tour outline-hidden",
|
|
14
15
|
arrow: "tour-arrow",
|
|
15
16
|
arrowTip: "bg-tour-arrow-bg",
|
|
16
|
-
title: "pe-tour-title font-tour-title text-tour-title-size",
|
|
17
|
-
description: "text-tour-body-size text-tour-description-fg",
|
|
18
|
-
progressText: "text-tour-progress-fg text-tour-progress-size",
|
|
19
|
-
actions: "flex flex-wrap items-center justify-end gap-tour-actions pt-tour-actions",
|
|
17
|
+
title: "shrink-0 pe-tour-title font-tour-title text-tour-title-size",
|
|
18
|
+
description: "focus-visible:tour-scroll-focus min-h-0 overflow-y-auto overscroll-contain text-tour-body-size text-tour-description-fg",
|
|
19
|
+
progressText: "shrink-0 text-tour-progress-fg text-tour-progress-size",
|
|
20
|
+
actions: "flex shrink-0 flex-wrap items-center justify-end gap-tour-actions pt-tour-actions",
|
|
20
21
|
closeTrigger: "absolute end-tour-close top-tour-close"
|
|
21
22
|
}
|
|
22
23
|
});
|
|
@@ -249,10 +250,13 @@ Tour.Description = function({ children, className, ref, ...props }) {
|
|
|
249
250
|
const api = useTourContext();
|
|
250
251
|
return /*#__PURE__*/ jsx("div", {
|
|
251
252
|
...mergeProps(props, api.getDescriptionProps()),
|
|
253
|
+
"aria-label": props["aria-label"] ?? "Tour guidance",
|
|
252
254
|
className: tourStyles().description({
|
|
253
255
|
className
|
|
254
256
|
}),
|
|
255
257
|
ref: ref,
|
|
258
|
+
role: props.role ?? "group",
|
|
259
|
+
tabIndex: props.tabIndex ?? 0,
|
|
256
260
|
children: children ?? api.step?.description
|
|
257
261
|
});
|
|
258
262
|
};
|
|
@@ -287,7 +291,7 @@ Tour.ActionTrigger = function({ action, children, disabled, onClick, type = "but
|
|
|
287
291
|
});
|
|
288
292
|
return /*#__PURE__*/ jsx(Button, {
|
|
289
293
|
...mergeProps(props, machineProps),
|
|
290
|
-
"aria-label": props["aria-label"] ?? (null
|
|
294
|
+
"aria-label": props["aria-label"] ?? (null == children ? machineLabel : void 0),
|
|
291
295
|
disabled: disabled || machineDisabled,
|
|
292
296
|
onClick: (event)=>{
|
|
293
297
|
onClick?.(event);
|
|
@@ -1,12 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { normalizeProps, useMachine } from "@zag-js/react";
|
|
3
|
-
import {
|
|
3
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
4
|
+
import { collection as tree_view_collection, connect, machine, splitProps } from "@zag-js/tree-view";
|
|
5
|
+
import { createContext, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
4
6
|
import { Icon } from "../atoms/icon.js";
|
|
5
7
|
import { tv } from "../utils.js";
|
|
6
|
-
|
|
8
|
+
function inheritDisabledState(nodes, parentDisabled = false) {
|
|
9
|
+
return nodes.map((node)=>{
|
|
10
|
+
const disabled = parentDisabled || Boolean(node.disabled);
|
|
11
|
+
return {
|
|
12
|
+
...node,
|
|
13
|
+
...disabled ? {
|
|
14
|
+
disabled: true
|
|
15
|
+
} : {},
|
|
16
|
+
...node.children ? {
|
|
17
|
+
children: inheritDisabledState(node.children, disabled)
|
|
18
|
+
} : {}
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function canSelectNode(node, behavior) {
|
|
23
|
+
if (node.disabled) return false;
|
|
24
|
+
if ("leaf-only" === behavior && node.children?.length) return false;
|
|
25
|
+
return "custom" !== behavior || false !== node.selectable;
|
|
26
|
+
}
|
|
27
|
+
function recoverTreeFocus(root, previous, api, target) {
|
|
28
|
+
if (!previous) return false;
|
|
29
|
+
const unavailable = !previous.isConnected || Boolean(previous.closest('[hidden], [data-disabled], [data-part="branch-content"][data-state="closed"]'));
|
|
30
|
+
if (!unavailable) return false;
|
|
31
|
+
const active = root.ownerDocument.activeElement;
|
|
32
|
+
if (active !== root.ownerDocument.body && !root.contains(active)) return true;
|
|
33
|
+
if (target) api.focus(target);
|
|
34
|
+
else root.querySelector('[data-part="tree"]')?.focus();
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
7
37
|
const treeViewVariants = tv({
|
|
8
38
|
slots: {
|
|
9
|
-
root: "relative rounded-tree-view bg-tree-view-root-bg",
|
|
39
|
+
root: "relative min-w-0 rounded-tree-view bg-tree-view-root-bg text-tree-view-fg-base",
|
|
10
40
|
label: [
|
|
11
41
|
"font-tree-view-label text-tree-view-label-fg"
|
|
12
42
|
],
|
|
@@ -31,16 +61,18 @@ const treeViewVariants = tv({
|
|
|
31
61
|
"transition-colors duration-200 motion-reduce:transition-none"
|
|
32
62
|
],
|
|
33
63
|
branchControl: [
|
|
34
|
-
"flex-1"
|
|
64
|
+
"min-w-0 flex-1"
|
|
35
65
|
],
|
|
36
66
|
branchText: [
|
|
37
|
-
"flex-1"
|
|
67
|
+
"wrap-anywhere min-w-0 flex-1"
|
|
38
68
|
],
|
|
39
69
|
branchIndicator: [
|
|
40
|
-
"
|
|
41
|
-
"
|
|
70
|
+
"flex min-h-tree-view-target min-w-tree-view-target shrink-0 cursor-pointer items-center justify-center self-stretch text-tree-view-fg-base",
|
|
71
|
+
"focus-visible:outline focus-visible:outline-tree-view-ring",
|
|
72
|
+
"data-disabled:cursor-not-allowed",
|
|
42
73
|
"transition duration-200 motion-reduce:transition-none"
|
|
43
74
|
],
|
|
75
|
+
indicatorIcon: "data-[state=open]:token-icon-tree-indicator-open",
|
|
44
76
|
branchContent: [
|
|
45
77
|
"relative",
|
|
46
78
|
"data-[state=closed]:hidden"
|
|
@@ -52,15 +84,13 @@ const treeViewVariants = tv({
|
|
|
52
84
|
],
|
|
53
85
|
item: [
|
|
54
86
|
"hover:bg-tree-view-node-bg-hover hover:text-tree-view-fg-hover",
|
|
55
|
-
"data-selected:hover:bg-tree-view-node-bg-hover",
|
|
56
|
-
"data-selected:hover:text-tree-view-fg-hover",
|
|
57
87
|
"focus-visible:outline-(style:--default-ring-style) focus-visible:outline-(length:--default-ring-width)",
|
|
58
88
|
"focus-visible:outline-tree-view-ring",
|
|
59
89
|
"focus-visible:outline-offset-(length:--default-ring-offset)",
|
|
60
90
|
"transition-colors duration-200 motion-reduce:transition-none"
|
|
61
91
|
],
|
|
62
92
|
itemText: [
|
|
63
|
-
"flex-1"
|
|
93
|
+
"wrap-anywhere min-w-0 flex-1"
|
|
64
94
|
],
|
|
65
95
|
nodeIcon: [
|
|
66
96
|
"hover:text-tree-view-icon-hover",
|
|
@@ -75,7 +105,7 @@ const treeViewVariants = tv({
|
|
|
75
105
|
],
|
|
76
106
|
class: [
|
|
77
107
|
"relative",
|
|
78
|
-
"ms-
|
|
108
|
+
"ms-tree-view-level",
|
|
79
109
|
"data-[depth=1]:ms-0"
|
|
80
110
|
]
|
|
81
111
|
},
|
|
@@ -87,9 +117,9 @@ const treeViewVariants = tv({
|
|
|
87
117
|
class: [
|
|
88
118
|
"flex items-center gap-tree-view-icon p-tree-view-node-padding",
|
|
89
119
|
"cursor-pointer",
|
|
90
|
-
"data-selected:text-tree-view-fg-selected",
|
|
91
|
-
"group-hover:text-tree-view-fg-hover",
|
|
92
|
-
"
|
|
120
|
+
"tree-view-selection data-selected:bg-tree-view-node-bg-selected data-selected:text-tree-view-node-fg-selected",
|
|
121
|
+
"data-selected:group-hover:text-tree-view-node-fg-selected data-selected:hover:bg-tree-view-node-bg-selected data-selected:hover:text-tree-view-node-fg-selected",
|
|
122
|
+
"group-hover:text-tree-view-fg-hover"
|
|
93
123
|
]
|
|
94
124
|
}
|
|
95
125
|
],
|
|
@@ -134,38 +164,133 @@ function useTreeViewNodeContext() {
|
|
|
134
164
|
if (!context) throw new Error("TreeView node components must be used within a node provider");
|
|
135
165
|
return context;
|
|
136
166
|
}
|
|
137
|
-
function TreeView({
|
|
167
|
+
function TreeView({ data, size, selectionBehavior = "all", children, className, ...props }) {
|
|
138
168
|
const generatedId = useId();
|
|
139
|
-
const
|
|
140
|
-
const collection =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
169
|
+
const [machineProps, rootProps] = splitProps(props);
|
|
170
|
+
const collection = useMemo(()=>tree_view_collection({
|
|
171
|
+
nodeToValue: (node)=>node.id,
|
|
172
|
+
nodeToString: (node)=>node.name,
|
|
173
|
+
rootNode: {
|
|
174
|
+
id: "ROOT",
|
|
175
|
+
name: "",
|
|
176
|
+
children: inheritDisabledState(data)
|
|
177
|
+
}
|
|
178
|
+
}), [
|
|
179
|
+
data
|
|
180
|
+
]);
|
|
181
|
+
const nodes = new Map();
|
|
182
|
+
const visit = (items, parents = [])=>{
|
|
183
|
+
for (const node of items){
|
|
184
|
+
nodes.set(node.id, {
|
|
185
|
+
node,
|
|
186
|
+
parents
|
|
187
|
+
});
|
|
188
|
+
if (node.children) visit(node.children, [
|
|
189
|
+
...parents,
|
|
190
|
+
node.id
|
|
191
|
+
]);
|
|
147
192
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
193
|
+
};
|
|
194
|
+
visit(collection.rootNode.children ?? []);
|
|
195
|
+
const allowed = (value)=>{
|
|
196
|
+
const node = nodes.get(value)?.node;
|
|
197
|
+
return Boolean(node && canSelectNode(node, selectionBehavior));
|
|
198
|
+
};
|
|
199
|
+
const filterSelection = (values)=>[
|
|
200
|
+
...new Set(values)
|
|
201
|
+
].filter(allowed);
|
|
202
|
+
const [selection, setSelection] = useState(()=>machineProps.defaultSelectedValue ?? []);
|
|
203
|
+
const [focus, setFocus] = useState(()=>machineProps.defaultFocusedValue ?? null);
|
|
204
|
+
const rootElement = useRef(null);
|
|
205
|
+
const lastFocused = useRef(null);
|
|
206
|
+
const previousNodes = useRef(nodes);
|
|
207
|
+
const recovery = useRef(null);
|
|
208
|
+
const selectionRecovery = useRef(null);
|
|
209
|
+
const expanded = machineProps.expandedValue;
|
|
210
|
+
const [localExpanded, setLocalExpanded] = useState(()=>machineProps.defaultExpandedValue ?? []);
|
|
211
|
+
const expandedValues = expanded ?? localExpanded;
|
|
212
|
+
const visible = [
|
|
213
|
+
...nodes.entries()
|
|
214
|
+
].filter(([, entry])=>!entry.node.disabled && entry.parents.every((parent)=>expandedValues.includes(parent)));
|
|
215
|
+
const requestedFocus = void 0 === machineProps.focusedValue ? focus : machineProps.focusedValue;
|
|
216
|
+
const previousParents = requestedFocus ? previousNodes.current.get(requestedFocus)?.parents ?? [] : [];
|
|
217
|
+
const visibleIds = visible.map(([value])=>value);
|
|
218
|
+
const previousIds = [
|
|
219
|
+
...previousNodes.current.keys()
|
|
220
|
+
];
|
|
221
|
+
const previousIndex = requestedFocus ? previousIds.indexOf(requestedFocus) : -1;
|
|
222
|
+
const neighbors = [
|
|
223
|
+
...previousIds.slice(previousIndex + 1),
|
|
224
|
+
...previousIds.slice(0, Math.max(0, previousIndex)).reverse()
|
|
225
|
+
];
|
|
226
|
+
const focusTarget = requestedFocus && visibleIds.includes(requestedFocus) ? requestedFocus : [
|
|
227
|
+
...previousParents
|
|
228
|
+
].reverse().find((value)=>visibleIds.includes(value)) ?? neighbors.find((value)=>visibleIds.includes(value)) ?? visibleIds[0] ?? null;
|
|
229
|
+
const selectedValue = filterSelection(machineProps.selectedValue ?? selection);
|
|
230
|
+
const service = useMachine(machine, {
|
|
231
|
+
expandOnClick: true,
|
|
232
|
+
typeahead: true,
|
|
233
|
+
...machineProps,
|
|
234
|
+
id: machineProps.id ?? generatedId,
|
|
151
235
|
collection,
|
|
152
|
-
dir,
|
|
153
|
-
selectionMode,
|
|
154
|
-
expandedValue,
|
|
155
236
|
selectedValue,
|
|
156
|
-
focusedValue,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
237
|
+
focusedValue: focusTarget,
|
|
238
|
+
onSelectionChange: (details)=>{
|
|
239
|
+
const selected = filterSelection(details.selectedValue);
|
|
240
|
+
if (void 0 === machineProps.selectedValue) setSelection(selected);
|
|
241
|
+
machineProps.onSelectionChange?.({
|
|
242
|
+
...details,
|
|
243
|
+
selectedValue: selected,
|
|
244
|
+
selectedNodes: selected.map((value)=>nodes.get(value)?.node).filter((node)=>Boolean(node))
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
onExpandedChange: (details)=>{
|
|
248
|
+
if (void 0 === expanded) setLocalExpanded(details.expandedValue);
|
|
249
|
+
machineProps.onExpandedChange?.(details);
|
|
250
|
+
},
|
|
251
|
+
onFocusChange: (details)=>{
|
|
252
|
+
if (void 0 === machineProps.focusedValue) setFocus(details.focusedValue);
|
|
253
|
+
machineProps.onFocusChange?.(details);
|
|
254
|
+
}
|
|
164
255
|
});
|
|
165
|
-
const api =
|
|
256
|
+
const api = connect(service, normalizeProps);
|
|
166
257
|
const styles = treeViewVariants({
|
|
167
258
|
size
|
|
168
259
|
});
|
|
260
|
+
useEffect(()=>{
|
|
261
|
+
const requestedSelection = machineProps.selectedValue ?? selection;
|
|
262
|
+
const selectionKey = JSON.stringify([
|
|
263
|
+
requestedSelection,
|
|
264
|
+
selectedValue
|
|
265
|
+
]);
|
|
266
|
+
if (requestedSelection.join("\0") === selectedValue.join("\0")) selectionRecovery.current = null;
|
|
267
|
+
else {
|
|
268
|
+
if (void 0 === machineProps.selectedValue) setSelection(selectedValue);
|
|
269
|
+
if (selectionRecovery.current !== selectionKey) {
|
|
270
|
+
selectionRecovery.current = selectionKey;
|
|
271
|
+
machineProps.onSelectionChange?.({
|
|
272
|
+
focusedValue: focusTarget,
|
|
273
|
+
selectedValue,
|
|
274
|
+
selectedNodes: selectedValue.map((value)=>nodes.get(value)?.node).filter((node)=>Boolean(node))
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
useEffect(()=>{
|
|
280
|
+
const root = rootElement.current;
|
|
281
|
+
if (!root) return;
|
|
282
|
+
const key = `${requestedFocus}:${focusTarget}`;
|
|
283
|
+
if (requestedFocus !== focusTarget && recovery.current !== key) {
|
|
284
|
+
recovery.current = key;
|
|
285
|
+
if (void 0 === machineProps.focusedValue) setFocus(focusTarget);
|
|
286
|
+
machineProps.onFocusChange?.({
|
|
287
|
+
focusedValue: focusTarget,
|
|
288
|
+
focusedNode: focusTarget ? nodes.get(focusTarget)?.node ?? null : null
|
|
289
|
+
});
|
|
290
|
+
} else if (requestedFocus === focusTarget) recovery.current = null;
|
|
291
|
+
if (recoverTreeFocus(root, lastFocused.current, api, focusTarget)) lastFocused.current = null;
|
|
292
|
+
if (requestedFocus === focusTarget || null == requestedFocus) previousNodes.current = nodes;
|
|
293
|
+
});
|
|
169
294
|
return /*#__PURE__*/ jsx(TreeViewContext.Provider, {
|
|
170
295
|
value: {
|
|
171
296
|
api,
|
|
@@ -177,8 +302,16 @@ function TreeView({ id, data, size, selectionBehavior = "all", dir = "ltr", sele
|
|
|
177
302
|
className: styles.root({
|
|
178
303
|
className
|
|
179
304
|
}),
|
|
180
|
-
...api.getRootProps(),
|
|
181
|
-
|
|
305
|
+
...mergeProps(rootProps, api.getRootProps()),
|
|
306
|
+
onBlurCapture: (event)=>{
|
|
307
|
+
rootProps.onBlurCapture?.(event);
|
|
308
|
+
if (event.relatedTarget && !event.currentTarget.contains(event.relatedTarget)) lastFocused.current = null;
|
|
309
|
+
},
|
|
310
|
+
onFocusCapture: (event)=>{
|
|
311
|
+
rootProps.onFocusCapture?.(event);
|
|
312
|
+
lastFocused.current = event.target;
|
|
313
|
+
},
|
|
314
|
+
ref: rootElement,
|
|
182
315
|
children: children
|
|
183
316
|
})
|
|
184
317
|
});
|
|
@@ -195,26 +328,49 @@ TreeView.Label = function({ children, className, ...props }) {
|
|
|
195
328
|
});
|
|
196
329
|
};
|
|
197
330
|
TreeView.Tree = function({ children, className, ...props }) {
|
|
198
|
-
const { api, styles } = useTreeViewContext();
|
|
331
|
+
const { api, styles, selectionBehavior } = useTreeViewContext();
|
|
199
332
|
return /*#__PURE__*/ jsx("div", {
|
|
200
333
|
className: styles.tree({
|
|
201
334
|
className
|
|
202
335
|
}),
|
|
203
|
-
...api.getTreeProps(),
|
|
204
|
-
|
|
336
|
+
...mergeProps(props, api.getTreeProps()),
|
|
337
|
+
onKeyDown: (event)=>{
|
|
338
|
+
props.onKeyDown?.(event);
|
|
339
|
+
if (event.defaultPrevented) return;
|
|
340
|
+
if ((event.metaKey || event.ctrlKey) && "a" === event.key.toLowerCase()) {
|
|
341
|
+
event.preventDefault();
|
|
342
|
+
if (api.getTreeProps()["aria-multiselectable"]) api.select();
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const target = event.target.closest('[data-part="branch-control"]');
|
|
346
|
+
const branch = target?.dataset.value ? api.collection.findNode(target.dataset.value) : void 0;
|
|
347
|
+
if (branch && !branch.disabled && !canSelectNode(branch, selectionBehavior ?? "all") && ("Enter" === event.key || " " === event.key)) {
|
|
348
|
+
event.preventDefault();
|
|
349
|
+
if (api.expandedValue.includes(branch.id)) api.collapse([
|
|
350
|
+
branch.id
|
|
351
|
+
]);
|
|
352
|
+
else api.expand([
|
|
353
|
+
branch.id
|
|
354
|
+
]);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
api.getTreeProps().onKeyDown?.(event);
|
|
358
|
+
},
|
|
359
|
+
role: "tree",
|
|
205
360
|
children: children
|
|
206
361
|
});
|
|
207
362
|
};
|
|
208
363
|
TreeView.NodeProvider = function({ node, indexPath, children }) {
|
|
209
364
|
const { api } = useTreeViewContext();
|
|
365
|
+
const collectionNode = api.collection.findNode(node.id) ?? node;
|
|
210
366
|
const nodeProps = {
|
|
211
|
-
node,
|
|
367
|
+
node: collectionNode,
|
|
212
368
|
indexPath
|
|
213
369
|
};
|
|
214
370
|
const nodeState = api.getNodeState(nodeProps);
|
|
215
371
|
return /*#__PURE__*/ jsx(TreeViewNodeContext.Provider, {
|
|
216
372
|
value: {
|
|
217
|
-
node,
|
|
373
|
+
node: collectionNode,
|
|
218
374
|
indexPath,
|
|
219
375
|
nodeProps,
|
|
220
376
|
nodeState
|
|
@@ -247,40 +403,31 @@ TreeView.BranchTrigger = function({ children, className, ...props }) {
|
|
|
247
403
|
TreeView.BranchControl = function({ children, className, ...props }) {
|
|
248
404
|
const { api, styles, selectionBehavior } = useTreeViewContext();
|
|
249
405
|
const { node, nodeProps, nodeState } = useTreeViewNodeContext();
|
|
250
|
-
const isSelectable = (()=>{
|
|
251
|
-
switch(selectionBehavior){
|
|
252
|
-
case "all":
|
|
253
|
-
return true;
|
|
254
|
-
case "leaf-only":
|
|
255
|
-
return false;
|
|
256
|
-
case "custom":
|
|
257
|
-
return false !== node.selectable;
|
|
258
|
-
default:
|
|
259
|
-
return true;
|
|
260
|
-
}
|
|
261
|
-
})();
|
|
262
406
|
const controlProps = api.getBranchControlProps(nodeProps);
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
407
|
+
const isSelectable = "leaf-only" !== selectionBehavior && ("custom" !== selectionBehavior || false !== node.selectable);
|
|
408
|
+
const finalProps = {
|
|
409
|
+
...mergeProps(props, controlProps),
|
|
410
|
+
onClick: (event)=>{
|
|
411
|
+
props.onClick?.(event);
|
|
412
|
+
if (event.defaultPrevented || nodeState.disabled) return;
|
|
413
|
+
if (isSelectable) controlProps.onClick?.(event);
|
|
414
|
+
else {
|
|
415
|
+
event.stopPropagation();
|
|
416
|
+
if (nodeState.expanded) api.collapse([
|
|
417
|
+
node.id
|
|
418
|
+
]);
|
|
419
|
+
else api.expand([
|
|
420
|
+
node.id
|
|
421
|
+
]);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
277
424
|
};
|
|
278
425
|
return /*#__PURE__*/ jsx("div", {
|
|
279
426
|
className: styles.branchControl({
|
|
280
427
|
className
|
|
281
428
|
}),
|
|
282
429
|
...finalProps,
|
|
283
|
-
|
|
430
|
+
tabIndex: nodeState.disabled ? -1 : controlProps.tabIndex,
|
|
284
431
|
children: children
|
|
285
432
|
});
|
|
286
433
|
};
|
|
@@ -298,25 +445,34 @@ TreeView.BranchText = function({ children, className }) {
|
|
|
298
445
|
TreeView.BranchIndicator = function({ icon = "token-icon-tree-indicator", className }) {
|
|
299
446
|
const { api, styles } = useTreeViewContext();
|
|
300
447
|
const { node, nodeProps, nodeState } = useTreeViewNodeContext();
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
id
|
|
307
|
-
]);
|
|
308
|
-
};
|
|
309
|
-
return /*#__PURE__*/ jsx(Icon, {
|
|
448
|
+
return /*#__PURE__*/ jsx("button", {
|
|
449
|
+
...api.getBranchIndicatorProps(nodeProps),
|
|
450
|
+
"aria-expanded": nodeState.expanded,
|
|
451
|
+
"aria-hidden": void 0,
|
|
452
|
+
"aria-label": `${nodeState.expanded ? "Collapse" : "Expand"} ${node.name}`,
|
|
310
453
|
className: styles.branchIndicator({
|
|
311
454
|
className
|
|
312
455
|
}),
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
456
|
+
disabled: nodeState.disabled,
|
|
457
|
+
onClick: (event)=>{
|
|
458
|
+
event.stopPropagation();
|
|
459
|
+
if (nodeState.disabled) return;
|
|
460
|
+
if (nodeState.expanded) api.collapse([
|
|
461
|
+
node.id
|
|
462
|
+
]);
|
|
463
|
+
else api.expand([
|
|
464
|
+
node.id
|
|
465
|
+
]);
|
|
466
|
+
},
|
|
467
|
+
onMouseDown: (event)=>event.preventDefault(),
|
|
468
|
+
tabIndex: -1,
|
|
469
|
+
type: "button",
|
|
470
|
+
children: /*#__PURE__*/ jsx(Icon, {
|
|
471
|
+
className: styles.indicatorIcon(),
|
|
472
|
+
"data-state": nodeState.expanded ? "open" : "closed",
|
|
473
|
+
icon: icon,
|
|
474
|
+
size: "current"
|
|
475
|
+
})
|
|
320
476
|
});
|
|
321
477
|
};
|
|
322
478
|
TreeView.BranchContent = function({ children, className, ...props }) {
|
|
@@ -344,34 +500,24 @@ TreeView.IndentGuide = function({ className }) {
|
|
|
344
500
|
TreeView.Item = function({ children, className, ...props }) {
|
|
345
501
|
const { api, styles, selectionBehavior } = useTreeViewContext();
|
|
346
502
|
const { node, nodeProps, nodeState } = useTreeViewNodeContext();
|
|
347
|
-
const isSelectable =
|
|
348
|
-
switch(selectionBehavior){
|
|
349
|
-
case "all":
|
|
350
|
-
case "leaf-only":
|
|
351
|
-
return true;
|
|
352
|
-
case "custom":
|
|
353
|
-
return false !== node.selectable;
|
|
354
|
-
default:
|
|
355
|
-
return true;
|
|
356
|
-
}
|
|
357
|
-
})();
|
|
503
|
+
const isSelectable = "custom" !== selectionBehavior || false !== node.selectable;
|
|
358
504
|
const itemProps = api.getItemProps(nodeProps);
|
|
359
|
-
const finalProps =
|
|
360
|
-
...itemProps,
|
|
361
|
-
onClick: (
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
"aria-selected": void 0,
|
|
366
|
-
"data-disabled": !isSelectable || nodeState.disabled || void 0
|
|
505
|
+
const finalProps = {
|
|
506
|
+
...mergeProps(props, itemProps),
|
|
507
|
+
onClick: (event)=>{
|
|
508
|
+
props.onClick?.(event);
|
|
509
|
+
if (!event.defaultPrevented && isSelectable) itemProps.onClick?.(event);
|
|
510
|
+
}
|
|
367
511
|
};
|
|
368
512
|
return /*#__PURE__*/ jsx("div", {
|
|
369
513
|
className: styles.item({
|
|
370
514
|
className
|
|
371
515
|
}),
|
|
372
516
|
...finalProps,
|
|
517
|
+
"aria-selected": isSelectable && !nodeState.disabled ? nodeState.selected : void 0,
|
|
373
518
|
"data-selected": nodeState.selected || void 0,
|
|
374
|
-
|
|
519
|
+
role: "treeitem",
|
|
520
|
+
tabIndex: nodeState.disabled ? -1 : itemProps.tabIndex,
|
|
375
521
|
children: children
|
|
376
522
|
});
|
|
377
523
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
"use client";
|
|
2
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { connect, machine } from "@zag-js/collapsible";
|
|
3
5
|
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
4
6
|
import { useContext, useId } from "react";
|
|
5
7
|
import { Button } from "../atoms/button.js";
|
|
@@ -7,7 +9,6 @@ import { Icon } from "../atoms/icon.js";
|
|
|
7
9
|
import { LinkButton } from "../atoms/link-button.js";
|
|
8
10
|
import { VerticalNavigationBranchContext, VerticalNavigationContext, VerticalNavigationDepthContext, useVerticalNavigationBranchContext, useVerticalNavigationContext } from "../internal/molecules/vertical-navigation.context.js";
|
|
9
11
|
import { verticalNavigationStyles } from "../internal/molecules/vertical-navigation.styles.js";
|
|
10
|
-
import * as __rspack_external__zag_js_collapsible_508ff486 from "@zag-js/collapsible";
|
|
11
12
|
function VerticalNavigation({ size = "md", maxIndentDepth = 3, dir, className, children, ...props }) {
|
|
12
13
|
return /*#__PURE__*/ jsx(VerticalNavigationContext.Provider, {
|
|
13
14
|
value: {
|
|
@@ -91,6 +92,7 @@ VerticalNavigation.Link = function({ current = false, className, ...props }) {
|
|
|
91
92
|
}).link({
|
|
92
93
|
className
|
|
93
94
|
}),
|
|
95
|
+
composition: true,
|
|
94
96
|
"data-current": current || void 0,
|
|
95
97
|
"data-current-path": branch?.containsCurrent || void 0,
|
|
96
98
|
"data-part": "link",
|
|
@@ -102,7 +104,7 @@ VerticalNavigation.Link = function({ current = false, className, ...props }) {
|
|
|
102
104
|
VerticalNavigation.Branch = function({ id, open, defaultOpen, onOpenChange, disabled, getRootNode, containsCurrent = false, children, className, ...props }) {
|
|
103
105
|
const { dir } = useVerticalNavigationContext();
|
|
104
106
|
const generatedId = useId();
|
|
105
|
-
const service = useMachine(
|
|
107
|
+
const service = useMachine(machine, {
|
|
106
108
|
id: id ?? generatedId,
|
|
107
109
|
dir,
|
|
108
110
|
open,
|
|
@@ -111,7 +113,7 @@ VerticalNavigation.Branch = function({ id, open, defaultOpen, onOpenChange, disa
|
|
|
111
113
|
disabled,
|
|
112
114
|
getRootNode
|
|
113
115
|
});
|
|
114
|
-
const api =
|
|
116
|
+
const api = connect(service, normalizeProps);
|
|
115
117
|
return /*#__PURE__*/ jsx(VerticalNavigationBranchContext.Provider, {
|
|
116
118
|
value: {
|
|
117
119
|
api,
|
|
@@ -131,7 +133,7 @@ VerticalNavigation.Branch = function({ id, open, defaultOpen, onOpenChange, disa
|
|
|
131
133
|
};
|
|
132
134
|
VerticalNavigation.BranchTrigger = function({ className, disabled, ...props }) {
|
|
133
135
|
const { size } = useVerticalNavigationContext();
|
|
134
|
-
const { api } = useVerticalNavigationBranchContext();
|
|
136
|
+
const { api, containsCurrent } = useVerticalNavigationBranchContext();
|
|
135
137
|
return /*#__PURE__*/ jsx(Button, {
|
|
136
138
|
...mergeProps(props, api.getTriggerProps()),
|
|
137
139
|
className: verticalNavigationStyles({
|
|
@@ -139,6 +141,8 @@ VerticalNavigation.BranchTrigger = function({ className, disabled, ...props }) {
|
|
|
139
141
|
}).trigger({
|
|
140
142
|
className
|
|
141
143
|
}),
|
|
144
|
+
composition: true,
|
|
145
|
+
"data-current-path": containsCurrent || void 0,
|
|
142
146
|
"data-part": "branch-trigger",
|
|
143
147
|
"data-scope": "vertical-navigation",
|
|
144
148
|
disabled: disabled || api.disabled,
|