@qw-ui/core 0.3.0-next.40 → 0.3.0-next.43
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 +21 -37
- package/dist/action-sheet/action-sheet.d.ts +110 -0
- package/dist/action-sheet/index.d.ts +2 -0
- package/dist/action-sheet/index.js +2 -0
- package/dist/action-sheet-Cvcr1S_m.js +183 -0
- package/dist/action-sheet-Cvcr1S_m.js.map +1 -0
- package/dist/area-picker/area-picker.d.ts +113 -0
- package/dist/area-picker/index.d.ts +1 -0
- package/dist/area-picker/index.js +348 -0
- package/dist/area-picker/index.js.map +1 -0
- package/dist/aria-description-CimD2M_C.js +13 -0
- package/dist/aria-description-CimD2M_C.js.map +1 -0
- package/dist/aria-description.d.ts +2 -0
- package/dist/avatar/avatar-load.d.ts +76 -0
- package/dist/avatar/avatar.d.ts +22 -5
- package/dist/avatar/index.d.ts +1 -0
- package/dist/avatar/index.js +57 -18
- package/dist/avatar/index.js.map +1 -1
- package/dist/avatar-load-w9dq05oV.js +139 -0
- package/dist/avatar-load-w9dq05oV.js.map +1 -0
- package/dist/back-top/back-top.d.ts +77 -0
- package/dist/back-top/index.d.ts +1 -0
- package/dist/back-top/index.js +189 -0
- package/dist/back-top/index.js.map +1 -0
- package/dist/badge/badge.d.ts +9 -0
- package/dist/badge/index.js +14 -1
- package/dist/badge/index.js.map +1 -1
- package/dist/button/button.d.ts +13 -0
- package/dist/button/index.js +3 -5
- package/dist/button/index.js.map +1 -1
- package/dist/calendar/calendar.d.ts +100 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +2 -0
- package/dist/calendar-CmpK3stz.js +363 -0
- package/dist/calendar-CmpK3stz.js.map +1 -0
- package/dist/card/card.d.ts +68 -0
- package/dist/card/index.d.ts +2 -0
- package/dist/card/index.js +2 -0
- package/dist/card-DRtWa6Cr.js +107 -0
- package/dist/card-DRtWa6Cr.js.map +1 -0
- package/dist/cascader/cascader.d.ts +115 -0
- package/dist/cascader/index.d.ts +1 -0
- package/dist/cascader/index.js +2 -0
- package/dist/cascader-D-xMjs7P.js +333 -0
- package/dist/cascader-D-xMjs7P.js.map +1 -0
- package/dist/cell/cell.d.ts +41 -0
- package/dist/cell/index.d.ts +1 -0
- package/dist/cell/index.js +43 -0
- package/dist/cell/index.js.map +1 -0
- package/dist/check-list/check-list.d.ts +78 -0
- package/dist/check-list/index.d.ts +2 -0
- package/dist/check-list/index.js +2 -0
- package/dist/check-list-BvZHQt5w.js +60 -0
- package/dist/check-list-BvZHQt5w.js.map +1 -0
- package/dist/checkbox/checkbox.d.ts +59 -0
- package/dist/checkbox/index.d.ts +2 -0
- package/dist/checkbox/index.js +2 -0
- package/dist/checkbox-BlndJrz5.js +127 -0
- package/dist/checkbox-BlndJrz5.js.map +1 -0
- package/dist/checkbox-group/checkbox-group.d.ts +86 -0
- package/dist/checkbox-group/index.d.ts +3 -0
- package/dist/checkbox-group/index.js +2 -0
- package/dist/checkbox-group-gGfsTv-e.js +223 -0
- package/dist/checkbox-group-gGfsTv-e.js.map +1 -0
- package/dist/choice-group-C4c9m0qe.js +373 -0
- package/dist/choice-group-C4c9m0qe.js.map +1 -0
- package/dist/circle/circle.d.ts +97 -0
- package/dist/circle/index.d.ts +1 -0
- package/dist/circle/index.js +119 -0
- package/dist/circle/index.js.map +1 -0
- package/dist/collapse/collapse.d.ts +98 -0
- package/dist/collapse/index.d.ts +2 -0
- package/dist/collapse/index.js +2 -0
- package/dist/collapse-B969h7-H.js +226 -0
- package/dist/collapse-B969h7-H.js.map +1 -0
- package/dist/countdown/countdown.d.ts +114 -0
- package/dist/countdown/index.d.ts +1 -0
- package/dist/countdown/index.js +309 -0
- package/dist/countdown/index.js.map +1 -0
- package/dist/date-picker/date-picker.d.ts +168 -0
- package/dist/date-picker/index.d.ts +1 -0
- package/dist/date-picker/index.js +401 -0
- package/dist/date-picker/index.js.map +1 -0
- package/dist/descriptions/descriptions.d.ts +69 -0
- package/dist/descriptions/index.d.ts +1 -0
- package/dist/descriptions/index.js +86 -0
- package/dist/descriptions/index.js.map +1 -0
- package/dist/dialog/dialog.d.ts +32 -3
- package/dist/dialog/index.js +58 -3
- package/dist/dialog/index.js.map +1 -1
- package/dist/divider/divider.d.ts +18 -2
- package/dist/divider/index.js +20 -2
- package/dist/divider/index.js.map +1 -1
- package/dist/dropdown/dropdown.d.ts +172 -0
- package/dist/dropdown/index.d.ts +2 -0
- package/dist/dropdown/index.js +467 -0
- package/dist/dropdown/index.js.map +1 -0
- package/dist/ellipsis/ellipsis-layout.d.ts +34 -0
- package/dist/ellipsis/ellipsis.d.ts +88 -0
- package/dist/ellipsis/index.d.ts +2 -0
- package/dist/ellipsis/index.js +320 -0
- package/dist/ellipsis/index.js.map +1 -0
- package/dist/empty/empty-illustration.d.ts +3 -0
- package/dist/empty/empty.d.ts +43 -1
- package/dist/empty/index.js +2 -21
- package/dist/empty-CAgyvhUI.js +166 -0
- package/dist/empty-CAgyvhUI.js.map +1 -0
- package/dist/field/field.d.ts +95 -0
- package/dist/field/index.d.ts +2 -0
- package/dist/field/index.js +2 -0
- package/dist/field-DMHGIMZF.js +241 -0
- package/dist/field-DMHGIMZF.js.map +1 -0
- package/dist/floating-bubble/floating-bubble.d.ts +116 -0
- package/dist/floating-bubble/index.d.ts +1 -0
- package/dist/floating-bubble/index.js +333 -0
- package/dist/floating-bubble/index.js.map +1 -0
- package/dist/floating-panel/floating-panel.d.ts +80 -0
- package/dist/floating-panel/index.d.ts +2 -0
- package/dist/floating-panel/index.js +2 -0
- package/dist/floating-panel-Cbm5njBJ.js +363 -0
- package/dist/floating-panel-Cbm5njBJ.js.map +1 -0
- package/dist/footer/footer.d.ts +94 -0
- package/dist/footer/index.d.ts +1 -0
- package/dist/footer/index.js +154 -0
- package/dist/footer/index.js.map +1 -0
- package/dist/form/connect.d.ts +6 -0
- package/dist/form/form.d.ts +100 -0
- package/dist/form/ids.d.ts +14 -0
- package/dist/form/index.d.ts +13 -0
- package/dist/form/index.js +3 -0
- package/dist/form/methods.d.ts +5 -0
- package/dist/form/model.d.ts +24 -0
- package/dist/form/native.d.ts +25 -0
- package/dist/form/rules.d.ts +40 -0
- package/dist/form/ssr.d.ts +7 -0
- package/dist/form/types.d.ts +150 -0
- package/dist/form-BAGkIEMY.js +1354 -0
- package/dist/form-BAGkIEMY.js.map +1 -0
- package/dist/format-BDUY0C_c.js +89 -0
- package/dist/format-BDUY0C_c.js.map +1 -0
- package/dist/gesture-_SRHIvBm.js +30 -0
- package/dist/gesture-_SRHIvBm.js.map +1 -0
- package/dist/grid/grid-item.d.ts +22 -0
- package/dist/grid/grid.d.ts +42 -0
- package/dist/grid/index.d.ts +2 -0
- package/dist/grid/index.js +73 -0
- package/dist/grid/index.js.map +1 -0
- package/dist/icon/icon.d.ts +37 -1
- package/dist/icon/identity.d.ts +3 -0
- package/dist/icon/index.js +2 -20
- package/dist/icon-Cgdbnk1u.js +77 -0
- package/dist/icon-Cgdbnk1u.js.map +1 -0
- package/dist/image/image-load.d.ts +24 -0
- package/dist/image/image.d.ts +45 -8
- package/dist/image/index.d.ts +1 -0
- package/dist/image/index.js +116 -14
- package/dist/image/index.js.map +1 -1
- package/dist/image-preview/image-preview.d.ts +124 -0
- package/dist/image-preview/index.d.ts +1 -0
- package/dist/image-preview/index.js +450 -0
- package/dist/image-preview/index.js.map +1 -0
- package/dist/index-bar/index-bar.d.ts +121 -0
- package/dist/index-bar/index.d.ts +1 -0
- package/dist/index-bar/index.js +386 -0
- package/dist/index-bar/index.js.map +1 -0
- package/dist/index.d.ts +107 -14
- package/dist/index.js +148 -14
- package/dist/index.js.map +1 -0
- package/dist/infinite-scroll/index.d.ts +1 -0
- package/dist/infinite-scroll/index.js +248 -0
- package/dist/infinite-scroll/index.js.map +1 -0
- package/dist/infinite-scroll/infinite-scroll.d.ts +95 -0
- package/dist/input/index.js +181 -22
- package/dist/input/index.js.map +1 -1
- package/dist/input/input.d.ts +44 -1
- package/dist/layer-IpFrl5--.js +414 -0
- package/dist/layer-IpFrl5--.js.map +1 -0
- package/dist/layout-BRSqi4AQ.js +43 -0
- package/dist/layout-BRSqi4AQ.js.map +1 -0
- package/dist/layout.d.ts +13 -0
- package/dist/list/index.d.ts +2 -0
- package/dist/list/index.js +2 -0
- package/dist/list/list.d.ts +30 -0
- package/dist/list-6-iz-Irh.js +28 -0
- package/dist/list-6-iz-Irh.js.map +1 -0
- package/dist/loading/index.js +45 -2
- package/dist/loading/index.js.map +1 -1
- package/dist/loading/loading.d.ts +45 -2
- package/dist/modal-dialog-machine-CF9_z3Dm.js +487 -0
- package/dist/modal-dialog-machine-CF9_z3Dm.js.map +1 -0
- package/dist/modal-dialog-machine.d.ts +21 -0
- package/dist/modal-dismissable-lifetime.d.ts +21 -0
- package/dist/modal-registry.d.ts +24 -0
- package/dist/modal-render-hydration.d.ts +35 -0
- package/dist/modal-render-runtime.d.ts +19 -0
- package/dist/modal-render-scope.d.ts +63 -0
- package/dist/nav-bar/index.d.ts +1 -0
- package/dist/nav-bar/index.js +115 -0
- package/dist/nav-bar/index.js.map +1 -0
- package/dist/nav-bar/nav-bar.d.ts +76 -0
- package/dist/notice-bar/index.d.ts +2 -0
- package/dist/notice-bar/index.js +2 -0
- package/dist/notice-bar/notice-bar.d.ts +103 -0
- package/dist/notice-bar-DMpwLvRb.js +231 -0
- package/dist/notice-bar-DMpwLvRb.js.map +1 -0
- package/dist/notify/index.d.ts +1 -0
- package/dist/notify/index.js +251 -0
- package/dist/notify/index.js.map +1 -0
- package/dist/notify/notify.d.ts +123 -0
- package/dist/number-keyboard/index.d.ts +1 -0
- package/dist/number-keyboard/index.js +333 -0
- package/dist/number-keyboard/index.js.map +1 -0
- package/dist/number-keyboard/number-keyboard.d.ts +141 -0
- package/dist/page-indicator/index.d.ts +1 -0
- package/dist/page-indicator/index.js +138 -0
- package/dist/page-indicator/index.js.map +1 -0
- package/dist/page-indicator/page-indicator.d.ts +93 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +198 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/pagination/pagination.d.ts +125 -0
- package/dist/password-input/index.d.ts +1 -0
- package/dist/password-input/index.js +317 -0
- package/dist/password-input/index.js.map +1 -0
- package/dist/password-input/password-input.d.ts +144 -0
- package/dist/picker/index.d.ts +8 -0
- package/dist/picker/index.js +2 -0
- package/dist/picker/picker-machine.d.ts +80 -0
- package/dist/picker/picker.d.ts +121 -0
- package/dist/picker/platform.d.ts +84 -0
- package/dist/picker/selection-connect.d.ts +90 -0
- package/dist/picker/selection-model.d.ts +211 -0
- package/dist/picker-BykFntQN.js +1675 -0
- package/dist/picker-BykFntQN.js.map +1 -0
- package/dist/popover/index.d.ts +3 -0
- package/dist/popover/index.js +253 -0
- package/dist/popover/index.js.map +1 -0
- package/dist/popover/layer.d.ts +44 -0
- package/dist/popover/popover.d.ts +104 -0
- package/dist/popover/positioning.d.ts +132 -0
- package/dist/popup/index.d.ts +2 -0
- package/dist/popup/index.js +2 -0
- package/dist/popup/popup.d.ts +60 -0
- package/dist/popup-z5d8IYCt.js +576 -0
- package/dist/popup-z5d8IYCt.js.map +1 -0
- package/dist/portal-BHCNTWhg.js +78 -0
- package/dist/portal-BHCNTWhg.js.map +1 -0
- package/dist/portal.d.ts +61 -0
- package/dist/price/format.d.ts +19 -0
- package/dist/price/index.d.ts +1 -0
- package/dist/price/index.js +154 -0
- package/dist/price/index.js.map +1 -0
- package/dist/price/price.d.ts +88 -0
- package/dist/progress/index.d.ts +1 -0
- package/dist/progress/index.js +2 -0
- package/dist/progress/progress.d.ts +32 -0
- package/dist/progress-f3iYEfdA.js +37 -0
- package/dist/progress-f3iYEfdA.js.map +1 -0
- package/dist/pull-refresh/index.d.ts +1 -0
- package/dist/pull-refresh/index.js +414 -0
- package/dist/pull-refresh/index.js.map +1 -0
- package/dist/pull-refresh/pull-refresh.d.ts +118 -0
- package/dist/radio-group/index.d.ts +3 -0
- package/dist/radio-group/index.js +2 -0
- package/dist/radio-group/radio-group.d.ts +78 -0
- package/dist/radio-group-BOIMuqnS.js +230 -0
- package/dist/radio-group-BOIMuqnS.js.map +1 -0
- package/dist/rate/index.d.ts +1 -0
- package/dist/rate/index.js +2 -0
- package/dist/rate/rate-form.d.ts +28 -0
- package/dist/rate/rate.d.ts +144 -0
- package/dist/rate-5XsU2QkY.js +631 -0
- package/dist/rate-5XsU2QkY.js.map +1 -0
- package/dist/reorder/index.d.ts +1 -0
- package/dist/reorder/index.js +720 -0
- package/dist/reorder/index.js.map +1 -0
- package/dist/reorder/reorder.d.ts +190 -0
- package/dist/result/index.d.ts +1 -0
- package/dist/result/index.js +123 -0
- package/dist/result/index.js.map +1 -0
- package/dist/result/result.d.ts +88 -0
- package/dist/safe-area/index.d.ts +1 -0
- package/dist/safe-area/index.js +42 -0
- package/dist/safe-area/index.js.map +1 -0
- package/dist/safe-area/safe-area.d.ts +28 -0
- package/dist/search-bar/index.js +3 -1
- package/dist/search-bar/index.js.map +1 -1
- package/dist/search-bar/search-bar.d.ts +4 -0
- package/dist/segmented/index.d.ts +2 -0
- package/dist/segmented/index.js +2 -0
- package/dist/segmented/segmented.d.ts +127 -0
- package/dist/segmented-BaU38_L4.js +367 -0
- package/dist/segmented-BaU38_L4.js.map +1 -0
- package/dist/selection-form-BOM_odUk.js +88 -0
- package/dist/selection-form-BOM_odUk.js.map +1 -0
- package/dist/selection-form.d.ts +27 -0
- package/dist/selection-ivXqO1eu.js +55 -0
- package/dist/selection-ivXqO1eu.js.map +1 -0
- package/dist/selection.d.ts +29 -0
- package/dist/selector/choice-group.d.ts +114 -0
- package/dist/selector/index.d.ts +2 -0
- package/dist/selector/index.js +2 -0
- package/dist/selector/selector.d.ts +90 -0
- package/dist/selector-BU2MMJ4N.js +93 -0
- package/dist/selector-BU2MMJ4N.js.map +1 -0
- package/dist/share-sheet/index.d.ts +1 -0
- package/dist/share-sheet/index.js +138 -0
- package/dist/share-sheet/index.js.map +1 -0
- package/dist/share-sheet/share-sheet.d.ts +139 -0
- package/dist/skeleton/index.js +51 -2
- package/dist/skeleton/index.js.map +1 -1
- package/dist/skeleton/skeleton.d.ts +34 -3
- package/dist/slider/index.d.ts +1 -0
- package/dist/slider/index.js +482 -0
- package/dist/slider/index.js.map +1 -0
- package/dist/slider/slider.d.ts +174 -0
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +52 -0
- package/dist/space/index.js.map +1 -0
- package/dist/space/space.d.ts +46 -0
- package/dist/statistic/index.d.ts +1 -0
- package/dist/statistic/index.js +152 -0
- package/dist/statistic/index.js.map +1 -0
- package/dist/statistic/statistic.d.ts +101 -0
- package/dist/stepper/index.js +62 -3
- package/dist/stepper/index.js.map +1 -1
- package/dist/stepper/stepper.d.ts +44 -4
- package/dist/steps/index.d.ts +1 -0
- package/dist/steps/index.js +72 -0
- package/dist/steps/index.js.map +1 -0
- package/dist/steps/steps.d.ts +67 -0
- package/dist/sticky/index.d.ts +1 -0
- package/dist/sticky/index.js +145 -0
- package/dist/sticky/index.js.map +1 -0
- package/dist/sticky/sticky.d.ts +70 -0
- package/dist/swipe-action/index.d.ts +1 -0
- package/dist/swipe-action/index.js +417 -0
- package/dist/swipe-action/index.js.map +1 -0
- package/dist/swipe-action/swipe-action.d.ts +148 -0
- package/dist/swiper/gesture.d.ts +32 -0
- package/dist/swiper/index.d.ts +1 -0
- package/dist/swiper/index.js +2 -0
- package/dist/swiper/swiper.d.ts +177 -0
- package/dist/swiper-BKivDkHp.js +550 -0
- package/dist/swiper-BKivDkHp.js.map +1 -0
- package/dist/switch/index.js +135 -10
- package/dist/switch/index.js.map +1 -1
- package/dist/switch/switch.d.ts +93 -6
- package/dist/tabbar/index.js +46 -1
- package/dist/tabbar/index.js.map +1 -1
- package/dist/tabbar/tabbar.d.ts +50 -0
- package/dist/tabs/index.js +22 -1
- package/dist/tabs/index.js.map +1 -1
- package/dist/tabs/tabs.d.ts +12 -8
- package/dist/tag/index.js +123 -2
- package/dist/tag/index.js.map +1 -1
- package/dist/tag/tag.d.ts +67 -1
- package/dist/textarea/index.d.ts +2 -0
- package/dist/textarea/index.js +2 -242
- package/dist/textarea/platform.d.ts +22 -0
- package/dist/textarea/textarea.d.ts +165 -46
- package/dist/textarea-qbnruDUG.js +775 -0
- package/dist/textarea-qbnruDUG.js.map +1 -0
- package/dist/time-picker/index.d.ts +1 -0
- package/dist/time-picker/index.js +228 -0
- package/dist/time-picker/index.js.map +1 -0
- package/dist/time-picker/time-picker.d.ts +83 -0
- package/dist/timeline/index.d.ts +1 -0
- package/dist/timeline/index.js +131 -0
- package/dist/timeline/index.js.map +1 -0
- package/dist/timeline/timeline.d.ts +79 -0
- package/dist/toast/index.js +47 -4
- package/dist/toast/index.js.map +1 -1
- package/dist/toast/toast.d.ts +26 -3
- package/dist/top-bar/index.js +16 -2
- package/dist/top-bar/index.js.map +1 -1
- package/dist/top-bar/top-bar.d.ts +13 -2
- package/dist/tree-select/index.d.ts +1 -0
- package/dist/tree-select/index.js +512 -0
- package/dist/tree-select/index.js.map +1 -0
- package/dist/tree-select/tree-select.d.ts +215 -0
- package/dist/typography/index.d.ts +1 -0
- package/dist/typography/index.js +82 -0
- package/dist/typography/index.js.map +1 -0
- package/dist/typography/typography.d.ts +54 -0
- package/dist/upload/index.d.ts +1 -0
- package/dist/upload/index.js +458 -0
- package/dist/upload/index.js.map +1 -0
- package/dist/upload/upload.d.ts +172 -0
- package/dist/virtual-list/index.d.ts +1 -0
- package/dist/virtual-list/index.js +445 -0
- package/dist/virtual-list/index.js.map +1 -0
- package/dist/virtual-list/virtual-list.d.ts +160 -0
- package/dist/visual-manifest.d.ts +6 -0
- package/dist/watermark/index.d.ts +1 -0
- package/dist/watermark/index.js +260 -0
- package/dist/watermark/index.js.map +1 -0
- package/dist/watermark/watermark.d.ts +106 -0
- package/package.json +399 -50
- package/dist/empty/index.js.map +0 -1
- package/dist/icon/index.js.map +0 -1
- package/dist/textarea/index.js.map +0 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { i as toggleSelectionValue, n as normalizeSelectionValue, r as selectionItemKey, t as normalizeSelectionItems } from "./selection-ivXqO1eu.js";
|
|
2
|
+
import { n as trackSelectionForm, t as syncSelectionInputs } from "./selection-form-BOM_odUk.js";
|
|
3
|
+
import { createMachine } from "@zag-js/core";
|
|
4
|
+
import { dataAttr, visuallyHiddenStyle } from "@zag-js/dom-query";
|
|
5
|
+
//#region src/checkbox-group/checkbox-group.ts
|
|
6
|
+
function createCheckboxGroupProps(props) {
|
|
7
|
+
return {
|
|
8
|
+
...props,
|
|
9
|
+
items: normalizeSelectionItems(props.items),
|
|
10
|
+
value: props.value === void 0 ? void 0 : normalizeSelectionValue(props.value),
|
|
11
|
+
defaultValue: normalizeSelectionValue(props.defaultValue),
|
|
12
|
+
orientation: props.orientation ?? "vertical"
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const sameValues = (a, b) => !!b && a.length === b.length && a.every((value, index) => value === b[index]);
|
|
16
|
+
const rootId = (scope) => `checkbox-group:${scope.id}`;
|
|
17
|
+
const inputId = (scope, value) => `${rootId(scope)}:input:${selectionItemKey(value)}`;
|
|
18
|
+
function sync(params) {
|
|
19
|
+
const value = params.context.get("value");
|
|
20
|
+
syncSelectionInputs(params.scope, params.prop("items").map((item) => ({
|
|
21
|
+
id: inputId(params.scope, item.value),
|
|
22
|
+
checked: value.includes(item.value)
|
|
23
|
+
})));
|
|
24
|
+
}
|
|
25
|
+
function changeFor(params, value) {
|
|
26
|
+
const item = params.prop("items").find((entry) => entry.value === value);
|
|
27
|
+
if (!item) return null;
|
|
28
|
+
return toggleSelectionValue(params.context.get("value"), item, {
|
|
29
|
+
min: params.prop("min"),
|
|
30
|
+
max: params.prop("max"),
|
|
31
|
+
readOnly: params.prop("readOnly"),
|
|
32
|
+
disabled: params.prop("disabled") || params.context.get("disabledIds").includes(inputId(params.scope, value))
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Zag owns the bindable lifecycle; shared Core rules own all selection behavior. */
|
|
36
|
+
const checkboxGroupMachine = createMachine({
|
|
37
|
+
props: ({ props }) => ({
|
|
38
|
+
...props,
|
|
39
|
+
label: props.label ?? "",
|
|
40
|
+
items: normalizeSelectionItems(props.items ?? []),
|
|
41
|
+
defaultValue: normalizeSelectionValue(props.defaultValue),
|
|
42
|
+
value: props.value === void 0 ? void 0 : normalizeSelectionValue(props.value),
|
|
43
|
+
orientation: props.orientation ?? "vertical"
|
|
44
|
+
}),
|
|
45
|
+
initialState: () => "ready",
|
|
46
|
+
context({ prop, bindable }) {
|
|
47
|
+
return {
|
|
48
|
+
value: bindable(() => ({
|
|
49
|
+
defaultValue: prop("defaultValue"),
|
|
50
|
+
value: prop("value"),
|
|
51
|
+
isEqual: sameValues,
|
|
52
|
+
onChange: (value) => prop("onValueChange")?.({ value: [...value] })
|
|
53
|
+
})),
|
|
54
|
+
disabledIds: bindable(() => ({
|
|
55
|
+
defaultValue: [],
|
|
56
|
+
isEqual: sameValues
|
|
57
|
+
}))
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
watch({ track, context, action }) {
|
|
61
|
+
track([() => context.hash("value")], () => action(["syncInputs"]));
|
|
62
|
+
},
|
|
63
|
+
effects: ["trackForm"],
|
|
64
|
+
on: {
|
|
65
|
+
"VALUE.SET": { actions: ["setValue"] },
|
|
66
|
+
"VALUE.TOGGLE": { actions: ["toggleValue"] }
|
|
67
|
+
},
|
|
68
|
+
states: { ready: {} },
|
|
69
|
+
implementations: {
|
|
70
|
+
effects: { trackForm(params) {
|
|
71
|
+
return trackSelectionForm({
|
|
72
|
+
scope: params.scope,
|
|
73
|
+
rootId: rootId(params.scope),
|
|
74
|
+
form: () => params.prop("form"),
|
|
75
|
+
getState: () => params.prop("items").map((item) => ({
|
|
76
|
+
id: inputId(params.scope, item.value),
|
|
77
|
+
checked: params.context.get("value").includes(item.value)
|
|
78
|
+
})),
|
|
79
|
+
onReset: () => params.context.set("value", normalizeSelectionValue(params.prop("defaultValue"))),
|
|
80
|
+
onDisabledChange: (ids) => params.context.set("disabledIds", [...ids])
|
|
81
|
+
}).stop;
|
|
82
|
+
} },
|
|
83
|
+
actions: {
|
|
84
|
+
syncInputs: sync,
|
|
85
|
+
setValue(params) {
|
|
86
|
+
if (params.event.type === "VALUE.SET") params.context.set("value", normalizeSelectionValue(params.event.value));
|
|
87
|
+
queueMicrotask(() => sync(params));
|
|
88
|
+
},
|
|
89
|
+
toggleValue(params) {
|
|
90
|
+
if (params.event.type === "VALUE.TOGGLE") {
|
|
91
|
+
const change = changeFor(params, params.event.value);
|
|
92
|
+
if (change && !change.blocked) params.context.set("value", change.value);
|
|
93
|
+
}
|
|
94
|
+
queueMicrotask(() => sync(params));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
function connect(service, normalize) {
|
|
100
|
+
const id = rootId(service.scope);
|
|
101
|
+
const items = service.prop("items");
|
|
102
|
+
const value = service.context.get("value");
|
|
103
|
+
const disabled = (item) => !!service.prop("disabled") || !!item.disabled || service.context.get("disabledIds").includes(inputId(service.scope, item.value));
|
|
104
|
+
const enabled = items.filter((item) => !disabled(item));
|
|
105
|
+
const requiredAnchor = service.prop("required") && !enabled.some((item) => value.includes(item.value)) ? enabled[0]?.value : void 0;
|
|
106
|
+
const resolve = ({ value }) => {
|
|
107
|
+
const item = items.find((entry) => entry.value === value);
|
|
108
|
+
if (!item) throw new RangeError("CheckboxGroup item value is not present in items");
|
|
109
|
+
return item;
|
|
110
|
+
};
|
|
111
|
+
const part = (name) => ({
|
|
112
|
+
"data-scope": "checkbox-group",
|
|
113
|
+
"data-part": name
|
|
114
|
+
});
|
|
115
|
+
const itemData = (item) => ({
|
|
116
|
+
"data-state": value.includes(item.value) ? "checked" : "unchecked",
|
|
117
|
+
"data-disabled": dataAttr(disabled(item)),
|
|
118
|
+
"data-readonly": dataAttr(service.prop("readOnly")),
|
|
119
|
+
"data-invalid": dataAttr(service.prop("invalid"))
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
value: [...value],
|
|
123
|
+
items: items.map((item) => ({ ...item })),
|
|
124
|
+
label: service.prop("label"),
|
|
125
|
+
description: service.prop("description") ?? "",
|
|
126
|
+
setValue: (value) => service.send({
|
|
127
|
+
type: "VALUE.SET",
|
|
128
|
+
value
|
|
129
|
+
}),
|
|
130
|
+
toggleValue: (value) => service.send({
|
|
131
|
+
type: "VALUE.TOGGLE",
|
|
132
|
+
value
|
|
133
|
+
}),
|
|
134
|
+
getRootProps: () => normalize.element({
|
|
135
|
+
...part("root"),
|
|
136
|
+
id,
|
|
137
|
+
disabled: !!service.prop("disabled"),
|
|
138
|
+
form: service.prop("form"),
|
|
139
|
+
dir: service.prop("dir"),
|
|
140
|
+
"data-orientation": service.prop("orientation"),
|
|
141
|
+
"data-disabled": dataAttr(service.prop("disabled")),
|
|
142
|
+
"data-readonly": dataAttr(service.prop("readOnly")),
|
|
143
|
+
"data-required": dataAttr(service.prop("required")),
|
|
144
|
+
"data-invalid": dataAttr(service.prop("invalid")),
|
|
145
|
+
"aria-invalid": service.prop("invalid") || void 0,
|
|
146
|
+
"aria-describedby": service.prop("description") ? `${id}:description` : void 0
|
|
147
|
+
}),
|
|
148
|
+
getLabelProps: () => normalize.element({
|
|
149
|
+
...part("label"),
|
|
150
|
+
id: `${id}:label`
|
|
151
|
+
}),
|
|
152
|
+
getDescriptionProps: () => normalize.element({
|
|
153
|
+
...part("description"),
|
|
154
|
+
id: `${id}:description`
|
|
155
|
+
}),
|
|
156
|
+
getItemProps: (props) => {
|
|
157
|
+
const item = resolve(props);
|
|
158
|
+
return normalize.label({
|
|
159
|
+
...part("item"),
|
|
160
|
+
...itemData(item),
|
|
161
|
+
htmlFor: inputId(service.scope, item.value)
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
getInputProps(props) {
|
|
165
|
+
const item = resolve(props);
|
|
166
|
+
return normalize.input({
|
|
167
|
+
...part("input"),
|
|
168
|
+
...itemData(item),
|
|
169
|
+
id: inputId(service.scope, item.value),
|
|
170
|
+
type: "checkbox",
|
|
171
|
+
value: item.value,
|
|
172
|
+
checked: value.includes(item.value),
|
|
173
|
+
disabled: !!service.prop("disabled") || !!item.disabled,
|
|
174
|
+
readOnly: !!service.prop("readOnly"),
|
|
175
|
+
required: requiredAnchor === item.value,
|
|
176
|
+
name: service.prop("name"),
|
|
177
|
+
form: service.prop("form"),
|
|
178
|
+
"aria-checked": value.includes(item.value),
|
|
179
|
+
"aria-readonly": service.prop("readOnly") || void 0,
|
|
180
|
+
"aria-invalid": service.prop("invalid") || void 0,
|
|
181
|
+
"aria-labelledby": `${id}:text:${selectionItemKey(item.value)}`,
|
|
182
|
+
"aria-describedby": item.description ? `${id}:description:${selectionItemKey(item.value)}` : void 0,
|
|
183
|
+
style: visuallyHiddenStyle,
|
|
184
|
+
onChange() {},
|
|
185
|
+
onClick(event) {
|
|
186
|
+
const change = changeFor(service, item.value);
|
|
187
|
+
if (!change || change.blocked) event.preventDefault();
|
|
188
|
+
service.send({
|
|
189
|
+
type: "VALUE.TOGGLE",
|
|
190
|
+
value: item.value
|
|
191
|
+
});
|
|
192
|
+
queueMicrotask(() => sync(service));
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
getControlProps: (props) => {
|
|
197
|
+
const item = resolve(props);
|
|
198
|
+
return normalize.element({
|
|
199
|
+
...part("control"),
|
|
200
|
+
...itemData(item),
|
|
201
|
+
"aria-hidden": true
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
getTextProps: (props) => {
|
|
205
|
+
const item = resolve(props);
|
|
206
|
+
return normalize.element({
|
|
207
|
+
...part("text"),
|
|
208
|
+
id: `${id}:text:${selectionItemKey(item.value)}`
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
getItemDescriptionProps: (props) => {
|
|
212
|
+
const item = resolve(props);
|
|
213
|
+
return normalize.element({
|
|
214
|
+
...part("item-description"),
|
|
215
|
+
id: `${id}:description:${selectionItemKey(item.value)}`
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
export { connect as n, createCheckboxGroupProps as r, checkboxGroupMachine as t };
|
|
222
|
+
|
|
223
|
+
//# sourceMappingURL=checkbox-group-gGfsTv-e.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox-group-gGfsTv-e.js","names":[],"sources":["../src/checkbox-group/checkbox-group.ts"],"sourcesContent":["import { createMachine, type Machine, type Params, type Service } from \"@zag-js/core\";\nimport { dataAttr, visuallyHiddenStyle } from \"@zag-js/dom-query\";\nimport type { NormalizeProps, PropTypes } from \"@zag-js/types\";\nimport { normalizeSelectionItems, normalizeSelectionValue, selectionItemKey, toggleSelectionValue, type QwSelectionItem } from \"../selection.js\";\nimport { syncSelectionInputs, trackSelectionForm } from \"../selection-form.js\";\n\nexport interface QwCheckboxGroupProps {\n /** Stable instance id; adapters supply an SSR-safe id when omitted. */\n id?: string;\n /** Accessible group name rendered as a native fieldset legend. */\n label: string;\n /** Optional group supporting text linked through aria-describedby. */\n description?: string;\n /** Ordered options with unique non-empty values and accessible text labels. */\n items: QwSelectionItem[];\n /** Controlled ordered values; duplicates are removed, unknown values retained. */\n value?: string[];\n /** Uncontrolled initial values and the requested target on form reset. */\n defaultValue?: string[];\n /** Minimum selected count for user removals; defaults to zero. */\n min?: number;\n /** Maximum selected count for user additions; defaults to unlimited. */\n max?: number;\n /** Disable all options and exclude them from native submission. */\n disabled?: boolean;\n /** Prevent user changes while retaining focus and submitted values. */\n readOnly?: boolean;\n /** Require at least one enabled, rendered option through native validation. */\n required?: boolean;\n /** Expose invalid group and input semantics; caller supplies error text. */\n invalid?: boolean;\n /** Native field name; selected enabled options submit repeated name/value pairs. */\n name?: string;\n /** Form id for inputs associated with an external form. */\n form?: string;\n /** Visual layout direction; native Tab order remains the option order. */\n orientation?: \"vertical\" | \"horizontal\";\n /** Text and layout direction. */\n dir?: \"ltr\" | \"rtl\";\n /** One update request for each accepted value change, including form reset. */\n onValueChange?: (details: { value: string[] }) => void;\n}\nexport interface QwCheckboxGroupSchema {\n props: QwCheckboxGroupProps & { defaultValue: string[]; orientation: \"vertical\" | \"horizontal\" };\n context: { value: string[]; disabledIds: string[] };\n state: \"ready\";\n action: \"setValue\" | \"toggleValue\" | \"syncInputs\";\n effect: \"trackForm\";\n event: { type: \"VALUE.SET\"; value: string[] } | { type: \"VALUE.TOGGLE\"; value: string };\n}\nexport type QwCheckboxGroupMachine = Machine<QwCheckboxGroupSchema>;\nexport type QwCheckboxGroupService = Service<QwCheckboxGroupSchema>;\nexport interface QwCheckboxGroupItemProps { value: string }\n\nexport function createCheckboxGroupProps(props: QwCheckboxGroupProps): Partial<QwCheckboxGroupSchema[\"props\"]> {\n return { ...props, items: normalizeSelectionItems(props.items), value: props.value === undefined ? undefined : normalizeSelectionValue(props.value), defaultValue: normalizeSelectionValue(props.defaultValue), orientation: props.orientation ?? \"vertical\" };\n}\nconst sameValues = (a: string[], b: string[] | undefined) => !!b && a.length === b.length && a.every((value, index) => value === b[index]);\nconst rootId = (scope: QwCheckboxGroupService[\"scope\"]) => `checkbox-group:${scope.id}`;\nconst inputId = (scope: QwCheckboxGroupService[\"scope\"], value: string) => `${rootId(scope)}:input:${selectionItemKey(value)}`;\ntype GroupParams = Pick<Params<QwCheckboxGroupSchema>, \"scope\" | \"context\" | \"prop\">;\nfunction sync(params: GroupParams) {\n const value = params.context.get(\"value\");\n syncSelectionInputs(params.scope, params.prop(\"items\").map((item) => ({ id: inputId(params.scope, item.value), checked: value.includes(item.value) })));\n}\nfunction changeFor(params: GroupParams, value: string) {\n const item = params.prop(\"items\").find((entry) => entry.value === value);\n if (!item) return null;\n return toggleSelectionValue(params.context.get(\"value\"), item, {\n min: params.prop(\"min\"), max: params.prop(\"max\"), readOnly: params.prop(\"readOnly\"),\n disabled: params.prop(\"disabled\") || params.context.get(\"disabledIds\").includes(inputId(params.scope, value)),\n });\n}\n\n/** Zag owns the bindable lifecycle; shared Core rules own all selection behavior. */\nexport const checkboxGroupMachine: QwCheckboxGroupMachine = createMachine<QwCheckboxGroupSchema>({\n props: ({ props }) => ({ ...props, label: props.label ?? \"\", items: normalizeSelectionItems(props.items ?? []), defaultValue: normalizeSelectionValue(props.defaultValue), value: props.value === undefined ? undefined : normalizeSelectionValue(props.value), orientation: props.orientation ?? \"vertical\" }),\n initialState: () => \"ready\",\n context({ prop, bindable }) {\n return {\n value: bindable(() => ({ defaultValue: prop(\"defaultValue\"), value: prop(\"value\"), isEqual: sameValues, onChange: (value) => prop(\"onValueChange\")?.({ value: [...value] }) })),\n disabledIds: bindable<string[]>(() => ({ defaultValue: [], isEqual: sameValues })),\n };\n },\n watch({ track, context, action }) { track([() => context.hash(\"value\")], () => action([\"syncInputs\"])); },\n effects: [\"trackForm\"],\n on: { \"VALUE.SET\": { actions: [\"setValue\"] }, \"VALUE.TOGGLE\": { actions: [\"toggleValue\"] } },\n states: { ready: {} },\n implementations: {\n effects: { trackForm(params) {\n const tracker = trackSelectionForm({\n scope: params.scope, rootId: rootId(params.scope), form: () => params.prop(\"form\"),\n getState: () => params.prop(\"items\").map((item) => ({ id: inputId(params.scope, item.value), checked: params.context.get(\"value\").includes(item.value) })),\n onReset: () => params.context.set(\"value\", normalizeSelectionValue(params.prop(\"defaultValue\"))),\n onDisabledChange: (ids) => params.context.set(\"disabledIds\", [...ids]),\n });\n return tracker.stop;\n } },\n actions: {\n syncInputs: sync,\n setValue(params) { if (params.event.type === \"VALUE.SET\") params.context.set(\"value\", normalizeSelectionValue(params.event.value)); queueMicrotask(() => sync(params)); },\n toggleValue(params) {\n if (params.event.type === \"VALUE.TOGGLE\") {\n const change = changeFor(params, params.event.value);\n if (change && !change.blocked) params.context.set(\"value\", change.value);\n }\n queueMicrotask(() => sync(params));\n },\n },\n },\n});\n\nexport interface QwCheckboxGroupApi<T extends PropTypes = PropTypes> {\n value: string[]; items: QwSelectionItem[]; label: string; description: string;\n setValue(value: string[]): void;\n toggleValue(value: string): void;\n getRootProps(): T[\"element\"];\n getLabelProps(): T[\"element\"];\n getDescriptionProps(): T[\"element\"];\n getItemProps(item: QwCheckboxGroupItemProps): T[\"label\"];\n getInputProps(item: QwCheckboxGroupItemProps): T[\"input\"];\n getControlProps(item: QwCheckboxGroupItemProps): T[\"element\"];\n getTextProps(item: QwCheckboxGroupItemProps): T[\"element\"];\n getItemDescriptionProps(item: QwCheckboxGroupItemProps): T[\"element\"];\n}\n\nexport function connect<T extends PropTypes>(service: QwCheckboxGroupService, normalize: NormalizeProps<T>): QwCheckboxGroupApi<T> {\n const id = rootId(service.scope);\n const items = service.prop(\"items\");\n const value = service.context.get(\"value\");\n const disabled = (item: QwSelectionItem) => !!service.prop(\"disabled\") || !!item.disabled || service.context.get(\"disabledIds\").includes(inputId(service.scope, item.value));\n const enabled = items.filter((item) => !disabled(item));\n const requiredAnchor = service.prop(\"required\") && !enabled.some((item) => value.includes(item.value)) ? enabled[0]?.value : undefined;\n const resolve = ({ value }: QwCheckboxGroupItemProps) => { const item = items.find((entry) => entry.value === value); if (!item) throw new RangeError(\"CheckboxGroup item value is not present in items\"); return item; };\n const part = (name: string) => ({ \"data-scope\": \"checkbox-group\", \"data-part\": name });\n const itemData = (item: QwSelectionItem) => ({ \"data-state\": value.includes(item.value) ? \"checked\" : \"unchecked\", \"data-disabled\": dataAttr(disabled(item)), \"data-readonly\": dataAttr(service.prop(\"readOnly\")), \"data-invalid\": dataAttr(service.prop(\"invalid\")) });\n return {\n value: [...value], items: items.map((item) => ({ ...item })), label: service.prop(\"label\"), description: service.prop(\"description\") ?? \"\",\n setValue: (value) => service.send({ type: \"VALUE.SET\", value }),\n toggleValue: (value) => service.send({ type: \"VALUE.TOGGLE\", value }),\n getRootProps: () => normalize.element({ ...part(\"root\"), id, disabled: !!service.prop(\"disabled\"), form: service.prop(\"form\"), dir: service.prop(\"dir\"), \"data-orientation\": service.prop(\"orientation\"), \"data-disabled\": dataAttr(service.prop(\"disabled\")), \"data-readonly\": dataAttr(service.prop(\"readOnly\")), \"data-required\": dataAttr(service.prop(\"required\")), \"data-invalid\": dataAttr(service.prop(\"invalid\")), \"aria-invalid\": service.prop(\"invalid\") || undefined, \"aria-describedby\": service.prop(\"description\") ? `${id}:description` : undefined }),\n getLabelProps: () => normalize.element({ ...part(\"label\"), id: `${id}:label` }),\n getDescriptionProps: () => normalize.element({ ...part(\"description\"), id: `${id}:description` }),\n getItemProps: (props) => { const item = resolve(props); return normalize.label({ ...part(\"item\"), ...itemData(item), htmlFor: inputId(service.scope, item.value) }); },\n getInputProps(props) {\n const item = resolve(props);\n return normalize.input({\n ...part(\"input\"), ...itemData(item), id: inputId(service.scope, item.value), type: \"checkbox\", value: item.value,\n checked: value.includes(item.value), disabled: !!service.prop(\"disabled\") || !!item.disabled, readOnly: !!service.prop(\"readOnly\"),\n required: requiredAnchor === item.value, name: service.prop(\"name\"), form: service.prop(\"form\"),\n \"aria-checked\": value.includes(item.value), \"aria-readonly\": service.prop(\"readOnly\") || undefined, \"aria-invalid\": service.prop(\"invalid\") || undefined,\n \"aria-labelledby\": `${id}:text:${selectionItemKey(item.value)}`, \"aria-describedby\": item.description ? `${id}:description:${selectionItemKey(item.value)}` : undefined,\n style: visuallyHiddenStyle, onChange() {},\n onClick(event) {\n const change = changeFor(service, item.value);\n if (!change || change.blocked) event.preventDefault();\n service.send({ type: \"VALUE.TOGGLE\", value: item.value });\n queueMicrotask(() => sync(service));\n },\n });\n },\n getControlProps: (props) => { const item = resolve(props); return normalize.element({ ...part(\"control\"), ...itemData(item), \"aria-hidden\": true }); },\n getTextProps: (props) => { const item = resolve(props); return normalize.element({ ...part(\"text\"), id: `${id}:text:${selectionItemKey(item.value)}` }); },\n getItemDescriptionProps: (props) => { const item = resolve(props); return normalize.element({ ...part(\"item-description\"), id: `${id}:description:${selectionItemKey(item.value)}` }); },\n };\n}\n"],"mappings":";;;;;AAsDA,SAAgB,yBAAyB,OAAsE;C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UAAU,QAAQ;IAAE,GAAG,KAAK,MAAM;IAAG,IAAI,GAAG,GAAG,QAAQ,iBAAiB,KAAK,KAAK;GAAI,CAAC;EAAG;EACzJ,0BAA0B,UAAU;GAAE,MAAM,OAAO,QAAQ,KAAK;GAAG,OAAO,UAAU,QAAQ;IAAE,GAAG,KAAK,kBAAkB;IAAG,IAAI,GAAG,GAAG,eAAe,iBAAiB,KAAK,KAAK;GAAI,CAAC;EAAG;CACzL;AACF"}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { o as resolveIconState } from "./icon-Cgdbnk1u.js";
|
|
2
|
+
import { i as toggleSelectionValue, n as normalizeSelectionValue, r as selectionItemKey, t as normalizeSelectionItems } from "./selection-ivXqO1eu.js";
|
|
3
|
+
import { t as mergeDescriptionIds } from "./aria-description-CimD2M_C.js";
|
|
4
|
+
import { n as trackSelectionForm, t as syncSelectionInputs } from "./selection-form-BOM_odUk.js";
|
|
5
|
+
import { createMachine } from "@zag-js/core";
|
|
6
|
+
import { dataAttr, getComputedStyle, getEventKey, visuallyHiddenStyle } from "@zag-js/dom-query";
|
|
7
|
+
//#region src/selector/choice-group.ts
|
|
8
|
+
/**
|
|
9
|
+
* Private choice-group kernel shared by Selector and CheckList.
|
|
10
|
+
* Value/limit rules come from `selection.ts`; native input sync, reset and
|
|
11
|
+
* fieldset tracking come from `selection-form.ts`. Not exported from any root.
|
|
12
|
+
*/
|
|
13
|
+
function normalizeChoiceItems(items, family) {
|
|
14
|
+
return normalizeSelectionItems(items).map((entry) => {
|
|
15
|
+
const item = entry;
|
|
16
|
+
if (typeof item.label !== "string" || !item.label.trim()) throw new TypeError(`${family} item labels must be nonempty accessible text`);
|
|
17
|
+
if (item.extra !== void 0 && typeof item.extra !== "string") throw new TypeError(`${family} item extra must be text`);
|
|
18
|
+
return { ...item };
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function normalizeChoiceValue(value = [], multiple = false) {
|
|
22
|
+
const values = normalizeSelectionValue(value);
|
|
23
|
+
return multiple ? values : values.slice(0, 1);
|
|
24
|
+
}
|
|
25
|
+
function createChoiceGroupProps(props, family) {
|
|
26
|
+
if (typeof props.label !== "string" || !props.label.trim()) throw new TypeError(`${family} requires a nonempty accessible group label`);
|
|
27
|
+
if (props.id !== void 0 && (typeof props.id !== "string" || !props.id.trim())) throw new TypeError(`${family} requires a nonempty instance id when provided`);
|
|
28
|
+
const multiple = !!props.multiple;
|
|
29
|
+
return {
|
|
30
|
+
...props,
|
|
31
|
+
multiple,
|
|
32
|
+
items: normalizeChoiceItems(props.items ?? [], family),
|
|
33
|
+
value: props.value === void 0 ? void 0 : normalizeChoiceValue(props.value, multiple),
|
|
34
|
+
defaultValue: normalizeChoiceValue(props.defaultValue, multiple),
|
|
35
|
+
loop: props.loop ?? true
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const same = (a, b) => !!b && a.length === b.length && a.every((value, index) => value === b[index]);
|
|
39
|
+
/** One machine per family; `family` is the data-scope and id prefix. */
|
|
40
|
+
function createChoiceGroupMachine(family) {
|
|
41
|
+
const ids = choiceIds(family);
|
|
42
|
+
const current = (params) => normalizeChoiceValue(params.context.get("value"), params.prop("multiple"));
|
|
43
|
+
const isDisabled = (params, item) => !!params.prop("disabled") || !!item.disabled || params.context.get("disabledIds").includes(ids.input(params.scope, item.value));
|
|
44
|
+
const sync = (params) => {
|
|
45
|
+
const values = current(params);
|
|
46
|
+
syncSelectionInputs(params.scope, params.prop("items").map((item) => ({
|
|
47
|
+
id: ids.input(params.scope, item.value),
|
|
48
|
+
checked: values.includes(item.value)
|
|
49
|
+
})));
|
|
50
|
+
};
|
|
51
|
+
const change = (params, value, selectOnly) => choiceChange(params, value, selectOnly, isDisabled, current);
|
|
52
|
+
return createMachine({
|
|
53
|
+
props: ({ props }) => createChoiceGroupProps({
|
|
54
|
+
...props,
|
|
55
|
+
label: props.label ?? "",
|
|
56
|
+
items: props.items ?? []
|
|
57
|
+
}, family),
|
|
58
|
+
initialState: () => "ready",
|
|
59
|
+
context({ prop, bindable }) {
|
|
60
|
+
return {
|
|
61
|
+
value: bindable(() => ({
|
|
62
|
+
defaultValue: prop("defaultValue"),
|
|
63
|
+
value: prop("value"),
|
|
64
|
+
isEqual: same,
|
|
65
|
+
onChange: (value) => prop("onValueChange")?.({
|
|
66
|
+
value: [...value],
|
|
67
|
+
items: value.flatMap((entry) => prop("items").filter((item) => item.value === entry).map((item) => ({ ...item })))
|
|
68
|
+
})
|
|
69
|
+
})),
|
|
70
|
+
focusedValue: bindable(() => ({ defaultValue: null })),
|
|
71
|
+
disabledIds: bindable(() => ({
|
|
72
|
+
defaultValue: [],
|
|
73
|
+
isEqual: same
|
|
74
|
+
}))
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
watch({ track, context, prop, action }) {
|
|
78
|
+
track([() => context.hash("value"), () => context.hash("disabledIds")], () => action(["syncInputs"]));
|
|
79
|
+
track([() => prop("multiple")], () => action(["normalizeMode"]));
|
|
80
|
+
},
|
|
81
|
+
effects: ["trackForm"],
|
|
82
|
+
on: {
|
|
83
|
+
"VALUE.SET": { actions: ["setValue"] },
|
|
84
|
+
"VALUE.TOGGLE": { actions: ["toggleValue"] },
|
|
85
|
+
"VALUE.SELECT": { actions: ["selectValue"] },
|
|
86
|
+
FOCUS: { actions: ["setFocus"] }
|
|
87
|
+
},
|
|
88
|
+
states: { ready: {} },
|
|
89
|
+
implementations: {
|
|
90
|
+
effects: { trackForm(params) {
|
|
91
|
+
return trackSelectionForm({
|
|
92
|
+
scope: params.scope,
|
|
93
|
+
rootId: ids.root(params.scope),
|
|
94
|
+
form: () => params.prop("form"),
|
|
95
|
+
getState: () => params.prop("items").map((item) => ({
|
|
96
|
+
id: ids.input(params.scope, item.value),
|
|
97
|
+
checked: current(params).includes(item.value)
|
|
98
|
+
})),
|
|
99
|
+
onReset: () => params.context.set("value", normalizeChoiceValue(params.prop("defaultValue"), params.prop("multiple"))),
|
|
100
|
+
onDisabledChange: (list) => params.context.set("disabledIds", [...list])
|
|
101
|
+
}).stop;
|
|
102
|
+
} },
|
|
103
|
+
actions: {
|
|
104
|
+
syncInputs: sync,
|
|
105
|
+
normalizeMode(params) {
|
|
106
|
+
params.context.set("value", current(params));
|
|
107
|
+
queueMicrotask(() => sync(params));
|
|
108
|
+
},
|
|
109
|
+
setValue(params) {
|
|
110
|
+
if (params.event.type === "VALUE.SET") params.context.set("value", normalizeChoiceValue(params.event.value, params.prop("multiple")));
|
|
111
|
+
queueMicrotask(() => sync(params));
|
|
112
|
+
},
|
|
113
|
+
toggleValue(params) {
|
|
114
|
+
if (params.event.type === "VALUE.TOGGLE") {
|
|
115
|
+
const next = change(params, params.event.value, false);
|
|
116
|
+
if (next) params.context.set("value", next);
|
|
117
|
+
}
|
|
118
|
+
queueMicrotask(() => sync(params));
|
|
119
|
+
},
|
|
120
|
+
selectValue(params) {
|
|
121
|
+
if (params.event.type === "VALUE.SELECT") {
|
|
122
|
+
const next = change(params, params.event.value, true);
|
|
123
|
+
if (next) params.context.set("value", next);
|
|
124
|
+
}
|
|
125
|
+
queueMicrotask(() => sync(params));
|
|
126
|
+
},
|
|
127
|
+
setFocus(params) {
|
|
128
|
+
if (params.event.type === "FOCUS") params.context.set("focusedValue", params.event.value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function choiceIds(family) {
|
|
135
|
+
const root = (scope) => `${family}:${scope.id}`;
|
|
136
|
+
return {
|
|
137
|
+
root,
|
|
138
|
+
input: (scope, value) => `${root(scope)}:input:${selectionItemKey(value)}`
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function choiceChange(params, value, selectOnly, isDisabled, current) {
|
|
142
|
+
const item = params.prop("items").find((entry) => entry.value === value);
|
|
143
|
+
if (!item || isDisabled(params, item) || params.prop("readOnly") || item.readOnly) return null;
|
|
144
|
+
const values = current(params);
|
|
145
|
+
if (!params.prop("multiple")) {
|
|
146
|
+
if (!values.includes(value)) return [value];
|
|
147
|
+
return selectOnly || params.prop("required") ? null : [];
|
|
148
|
+
}
|
|
149
|
+
const result = toggleSelectionValue(values, item, {
|
|
150
|
+
min: params.prop("min"),
|
|
151
|
+
max: params.prop("max")
|
|
152
|
+
});
|
|
153
|
+
return result.blocked ? null : result.value;
|
|
154
|
+
}
|
|
155
|
+
/** SSR-pure getters; client handlers use the Zag DOM scope only inside events. */
|
|
156
|
+
function connectChoiceGroup(family, service, normalize) {
|
|
157
|
+
const ids = choiceIds(family);
|
|
158
|
+
const id = ids.root(service.scope), multiple = service.prop("multiple"), items = service.prop("items");
|
|
159
|
+
const values = normalizeChoiceValue(service.context.get("value"), multiple);
|
|
160
|
+
const isDisabled = (item) => !!service.prop("disabled") || !!item.disabled || service.context.get("disabledIds").includes(ids.input(service.scope, item.value));
|
|
161
|
+
const readOnly = (item) => !!service.prop("readOnly") || !!item.readOnly;
|
|
162
|
+
const current = (params) => normalizeChoiceValue(params.context.get("value"), params.prop("multiple"));
|
|
163
|
+
const sync = () => {
|
|
164
|
+
const now = current(service);
|
|
165
|
+
syncSelectionInputs(service.scope, service.prop("items").map((item) => ({
|
|
166
|
+
id: ids.input(service.scope, item.value),
|
|
167
|
+
checked: now.includes(item.value)
|
|
168
|
+
})));
|
|
169
|
+
};
|
|
170
|
+
const enabled = items.filter((item) => !isDisabled(item));
|
|
171
|
+
const focused = service.context.get("focusedValue");
|
|
172
|
+
const tabAnchor = enabled.find((item) => item.value === focused) ?? enabled.find((item) => values.includes(item.value)) ?? enabled[0];
|
|
173
|
+
const requiredAnchor = service.prop("required") && !enabled.some((item) => values.includes(item.value)) ? enabled[0]?.value : void 0;
|
|
174
|
+
const resolve = ({ value }) => {
|
|
175
|
+
const item = items.find((entry) => entry.value === value);
|
|
176
|
+
if (!item) throw new RangeError(`${family} item is not present in items`);
|
|
177
|
+
return item;
|
|
178
|
+
};
|
|
179
|
+
const key = (item) => selectionItemKey(item.value);
|
|
180
|
+
const part = (name) => ({
|
|
181
|
+
"data-scope": family,
|
|
182
|
+
"data-part": name
|
|
183
|
+
});
|
|
184
|
+
const data = (item) => ({
|
|
185
|
+
"data-state": values.includes(item.value) ? "checked" : "unchecked",
|
|
186
|
+
"data-disabled": dataAttr(isDisabled(item)),
|
|
187
|
+
"data-readonly": dataAttr(readOnly(item)),
|
|
188
|
+
"data-invalid": dataAttr(service.prop("invalid"))
|
|
189
|
+
});
|
|
190
|
+
const describedBy = (item) => mergeDescriptionIds(item.description ? `${id}:description:${key(item)}` : void 0, item.extra ? `${id}:extra:${key(item)}` : void 0);
|
|
191
|
+
return {
|
|
192
|
+
value: [...values],
|
|
193
|
+
items: items.map((item) => ({ ...item })),
|
|
194
|
+
label: service.prop("label"),
|
|
195
|
+
description: service.prop("description") ?? "",
|
|
196
|
+
setValue: (value) => service.send({
|
|
197
|
+
type: "VALUE.SET",
|
|
198
|
+
value: normalizeChoiceValue(value, multiple)
|
|
199
|
+
}),
|
|
200
|
+
toggleValue: (value) => service.send({
|
|
201
|
+
type: "VALUE.TOGGLE",
|
|
202
|
+
value
|
|
203
|
+
}),
|
|
204
|
+
clearValue: () => service.send({
|
|
205
|
+
type: "VALUE.SET",
|
|
206
|
+
value: []
|
|
207
|
+
}),
|
|
208
|
+
getRootProps: (extra = {}) => normalize.element({
|
|
209
|
+
...part("root"),
|
|
210
|
+
...extra,
|
|
211
|
+
id,
|
|
212
|
+
role: multiple ? "group" : "radiogroup",
|
|
213
|
+
disabled: !!service.prop("disabled"),
|
|
214
|
+
form: service.prop("form"),
|
|
215
|
+
dir: service.prop("dir"),
|
|
216
|
+
"aria-labelledby": `${id}:label`,
|
|
217
|
+
"aria-describedby": mergeDescriptionIds(service.prop("description") ? `${id}:description` : void 0, service.prop("describedBy")),
|
|
218
|
+
"aria-required": !multiple && service.prop("required") || void 0,
|
|
219
|
+
"aria-readonly": !multiple && service.prop("readOnly") || void 0,
|
|
220
|
+
"aria-disabled": service.prop("disabled") || items.length > 0 && !enabled.length || void 0,
|
|
221
|
+
"aria-invalid": service.prop("invalid") || void 0,
|
|
222
|
+
"data-selection-mode": multiple ? "multiple" : "single",
|
|
223
|
+
"data-disabled": dataAttr(service.prop("disabled")),
|
|
224
|
+
"data-readonly": dataAttr(service.prop("readOnly")),
|
|
225
|
+
"data-invalid": dataAttr(service.prop("invalid"))
|
|
226
|
+
}),
|
|
227
|
+
getLabelProps: () => normalize.element({
|
|
228
|
+
...part("label"),
|
|
229
|
+
id: `${id}:label`,
|
|
230
|
+
style: service.prop("hideLabel") ? visuallyHiddenStyle : void 0
|
|
231
|
+
}),
|
|
232
|
+
getDescriptionProps: () => normalize.element({
|
|
233
|
+
...part("description"),
|
|
234
|
+
id: `${id}:description`,
|
|
235
|
+
hidden: !service.prop("description")
|
|
236
|
+
}),
|
|
237
|
+
getGroupProps: (name) => normalize.element(part(name)),
|
|
238
|
+
getItemState: (props) => {
|
|
239
|
+
const item = resolve(props);
|
|
240
|
+
return {
|
|
241
|
+
selected: values.includes(item.value),
|
|
242
|
+
disabled: isDisabled(item),
|
|
243
|
+
readOnly: readOnly(item)
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
getItemProps: (props, name) => {
|
|
247
|
+
const item = resolve(props);
|
|
248
|
+
return normalize.label({
|
|
249
|
+
...part(name),
|
|
250
|
+
...data(item),
|
|
251
|
+
htmlFor: ids.input(service.scope, item.value)
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
getInputProps(props) {
|
|
255
|
+
const item = resolve(props), disabled = isDisabled(item), selected = values.includes(item.value);
|
|
256
|
+
return normalize.input({
|
|
257
|
+
...part("input"),
|
|
258
|
+
...data(item),
|
|
259
|
+
id: ids.input(service.scope, item.value),
|
|
260
|
+
type: multiple ? "checkbox" : "radio",
|
|
261
|
+
value: item.value,
|
|
262
|
+
checked: selected,
|
|
263
|
+
disabled: !!service.prop("disabled") || !!item.disabled,
|
|
264
|
+
readOnly: readOnly(item),
|
|
265
|
+
name: disabled ? void 0 : service.prop("name") || (multiple ? void 0 : service.scope.id),
|
|
266
|
+
form: service.prop("form"),
|
|
267
|
+
required: multiple ? requiredAnchor === item.value : !!service.prop("required") && !disabled,
|
|
268
|
+
tabIndex: multiple ? 0 : tabAnchor?.value === item.value ? 0 : -1,
|
|
269
|
+
"aria-checked": selected,
|
|
270
|
+
"aria-readonly": multiple && readOnly(item) || void 0,
|
|
271
|
+
"aria-invalid": service.prop("invalid") || void 0,
|
|
272
|
+
"aria-labelledby": `${id}:text:${key(item)}`,
|
|
273
|
+
"aria-describedby": describedBy(item),
|
|
274
|
+
style: visuallyHiddenStyle,
|
|
275
|
+
onChange() {},
|
|
276
|
+
onFocus() {
|
|
277
|
+
service.send({
|
|
278
|
+
type: "FOCUS",
|
|
279
|
+
value: item.value
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
onClick(event) {
|
|
283
|
+
if (event.defaultPrevented) return;
|
|
284
|
+
if (!choiceChange(service, item.value, false, (_, entry) => isDisabled(entry), current)) event.preventDefault();
|
|
285
|
+
service.send({
|
|
286
|
+
type: "VALUE.TOGGLE",
|
|
287
|
+
value: item.value
|
|
288
|
+
});
|
|
289
|
+
queueMicrotask(sync);
|
|
290
|
+
},
|
|
291
|
+
onKeyDown(event) {
|
|
292
|
+
if (event.defaultPrevented || event.ctrlKey || event.altKey || event.metaKey) return;
|
|
293
|
+
if (event.key === " " || event.key === "Enter") {
|
|
294
|
+
event.preventDefault();
|
|
295
|
+
if (!event.repeat) service.send({
|
|
296
|
+
type: "VALUE.TOGGLE",
|
|
297
|
+
value: item.value
|
|
298
|
+
});
|
|
299
|
+
queueMicrotask(sync);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (![
|
|
303
|
+
"ArrowLeft",
|
|
304
|
+
"ArrowRight",
|
|
305
|
+
"ArrowUp",
|
|
306
|
+
"ArrowDown",
|
|
307
|
+
"Home",
|
|
308
|
+
"End"
|
|
309
|
+
].includes(event.key)) return;
|
|
310
|
+
event.preventDefault();
|
|
311
|
+
const candidates = service.prop("items").filter((entry) => !isDisabled(entry));
|
|
312
|
+
if (!candidates.length || isDisabled(item)) return;
|
|
313
|
+
const direction = service.prop("dir");
|
|
314
|
+
const pressed = getEventKey(event, { dir: direction === "rtl" || direction === "ltr" ? direction : getComputedStyle(event.currentTarget).direction === "rtl" ? "rtl" : "ltr" }), index = candidates.findIndex((entry) => entry.value === item.value);
|
|
315
|
+
let target = pressed === "Home" ? 0 : pressed === "End" ? candidates.length - 1 : index + (pressed === "ArrowRight" || pressed === "ArrowDown" ? 1 : -1);
|
|
316
|
+
if (service.prop("loop")) target = (target + candidates.length) % candidates.length;
|
|
317
|
+
const next = candidates[target];
|
|
318
|
+
if (!next) return;
|
|
319
|
+
service.scope.getById(ids.input(service.scope, next.value))?.focus();
|
|
320
|
+
service.send({
|
|
321
|
+
type: "FOCUS",
|
|
322
|
+
value: next.value
|
|
323
|
+
});
|
|
324
|
+
if (!multiple) service.send({
|
|
325
|
+
type: "VALUE.SELECT",
|
|
326
|
+
value: next.value
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
},
|
|
331
|
+
getItemPartProps: (props, name) => normalize.element({
|
|
332
|
+
...part(name),
|
|
333
|
+
...data(resolve(props))
|
|
334
|
+
}),
|
|
335
|
+
getTextProps: (props, name) => normalize.element({
|
|
336
|
+
...part(name),
|
|
337
|
+
id: `${id}:text:${key(resolve(props))}`
|
|
338
|
+
}),
|
|
339
|
+
getItemDescriptionProps: (props, name) => {
|
|
340
|
+
const item = resolve(props);
|
|
341
|
+
return normalize.element({
|
|
342
|
+
...part(name),
|
|
343
|
+
id: `${id}:description:${key(item)}`,
|
|
344
|
+
hidden: !item.description
|
|
345
|
+
});
|
|
346
|
+
},
|
|
347
|
+
getExtraProps: (props, name) => {
|
|
348
|
+
const item = resolve(props);
|
|
349
|
+
return normalize.element({
|
|
350
|
+
...part(name),
|
|
351
|
+
id: `${id}:extra:${key(item)}`,
|
|
352
|
+
hidden: !item.extra
|
|
353
|
+
});
|
|
354
|
+
},
|
|
355
|
+
getCheckProps: (props, name) => {
|
|
356
|
+
const item = resolve(props);
|
|
357
|
+
return normalize.element({
|
|
358
|
+
...part(name),
|
|
359
|
+
...data(item),
|
|
360
|
+
"aria-hidden": true,
|
|
361
|
+
hidden: !values.includes(item.value)
|
|
362
|
+
});
|
|
363
|
+
},
|
|
364
|
+
getCheckIconState: (props) => resolveIconState({
|
|
365
|
+
id: `${id}:check:${key(resolve(props))}`,
|
|
366
|
+
name: "check"
|
|
367
|
+
})
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
//#endregion
|
|
371
|
+
export { normalizeChoiceValue as a, normalizeChoiceItems as i, createChoiceGroupMachine as n, createChoiceGroupProps as r, connectChoiceGroup as t };
|
|
372
|
+
|
|
373
|
+
//# sourceMappingURL=choice-group-C4c9m0qe.js.map
|