@puzzle-ui/ui 0.0.0-stage → 0.2.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 +97 -2
- package/dist/LICENSE +21 -0
- package/dist/components/actions/button/button-content.cjs +41 -0
- package/dist/components/actions/button/button-content.cjs.map +1 -0
- package/dist/components/actions/button/button-content.js +41 -0
- package/dist/components/actions/button/button-content.js.map +1 -0
- package/dist/components/actions/button/button.css +191 -0
- package/dist/components/actions/button/button.types.d.cts +30 -0
- package/dist/components/actions/button/button.types.d.ts +30 -0
- package/dist/components/actions/button/index.cjs +80 -0
- package/dist/components/actions/button/index.cjs.map +1 -0
- package/dist/components/actions/button/index.d.cts +3 -0
- package/dist/components/actions/button/index.d.ts +3 -0
- package/dist/components/actions/button/index.js +80 -0
- package/dist/components/actions/button/index.js.map +1 -0
- package/dist/components/actions/button-group/button-group.css +64 -0
- package/dist/components/actions/button-group/index.cjs +25 -0
- package/dist/components/actions/button-group/index.cjs.map +1 -0
- package/dist/components/actions/button-group/index.d.cts +14 -0
- package/dist/components/actions/button-group/index.d.ts +14 -0
- package/dist/components/actions/button-group/index.js +25 -0
- package/dist/components/actions/button-group/index.js.map +1 -0
- package/dist/components/actions/toggle-group/index.cjs +124 -0
- package/dist/components/actions/toggle-group/index.cjs.map +1 -0
- package/dist/components/actions/toggle-group/index.d.cts +10 -0
- package/dist/components/actions/toggle-group/index.d.ts +10 -0
- package/dist/components/actions/toggle-group/index.js +124 -0
- package/dist/components/actions/toggle-group/index.js.map +1 -0
- package/dist/components/actions/toggle-group/toggle-group.css +67 -0
- package/dist/components/actions/toggle-group/toggle-group.types.d.cts +54 -0
- package/dist/components/actions/toggle-group/toggle-group.types.d.ts +54 -0
- package/dist/components/data-display/alert/alert.css +128 -0
- package/dist/components/data-display/alert/alert.types.d.cts +14 -0
- package/dist/components/data-display/alert/alert.types.d.ts +14 -0
- package/dist/components/data-display/alert/alert.utils.cjs +11 -0
- package/dist/components/data-display/alert/alert.utils.cjs.map +1 -0
- package/dist/components/data-display/alert/alert.utils.js +11 -0
- package/dist/components/data-display/alert/alert.utils.js.map +1 -0
- package/dist/components/data-display/alert/index.cjs +103 -0
- package/dist/components/data-display/alert/index.cjs.map +1 -0
- package/dist/components/data-display/alert/index.d.cts +3 -0
- package/dist/components/data-display/alert/index.d.ts +3 -0
- package/dist/components/data-display/alert/index.js +103 -0
- package/dist/components/data-display/alert/index.js.map +1 -0
- package/dist/components/data-display/avatar/avatar.css +30 -0
- package/dist/components/data-display/avatar/index.cjs +42 -0
- package/dist/components/data-display/avatar/index.cjs.map +1 -0
- package/dist/components/data-display/avatar/index.d.cts +10 -0
- package/dist/components/data-display/avatar/index.d.ts +10 -0
- package/dist/components/data-display/avatar/index.js +42 -0
- package/dist/components/data-display/avatar/index.js.map +1 -0
- package/dist/components/data-display/badge/badge.css +91 -0
- package/dist/components/data-display/badge/index.cjs +31 -0
- package/dist/components/data-display/badge/index.cjs.map +1 -0
- package/dist/components/data-display/badge/index.d.cts +18 -0
- package/dist/components/data-display/badge/index.d.ts +18 -0
- package/dist/components/data-display/badge/index.js +31 -0
- package/dist/components/data-display/badge/index.js.map +1 -0
- package/dist/components/data-display/card/card.css +164 -0
- package/dist/components/data-display/card/index.cjs +42 -0
- package/dist/components/data-display/card/index.cjs.map +1 -0
- package/dist/components/data-display/card/index.d.cts +29 -0
- package/dist/components/data-display/card/index.d.ts +29 -0
- package/dist/components/data-display/card/index.js +35 -0
- package/dist/components/data-display/card/index.js.map +1 -0
- package/dist/components/data-display/image/image.css +80 -0
- package/dist/components/data-display/image/image.types.d.cts +154 -0
- package/dist/components/data-display/image/image.types.d.ts +154 -0
- package/dist/components/data-display/image/image.utils.cjs +55 -0
- package/dist/components/data-display/image/image.utils.cjs.map +1 -0
- package/dist/components/data-display/image/image.utils.js +51 -0
- package/dist/components/data-display/image/image.utils.js.map +1 -0
- package/dist/components/data-display/image/index.cjs +176 -0
- package/dist/components/data-display/image/index.cjs.map +1 -0
- package/dist/components/data-display/image/index.d.cts +3 -0
- package/dist/components/data-display/image/index.d.ts +3 -0
- package/dist/components/data-display/image/index.js +176 -0
- package/dist/components/data-display/image/index.js.map +1 -0
- package/dist/components/data-display/image/use-image-state.cjs +54 -0
- package/dist/components/data-display/image/use-image-state.cjs.map +1 -0
- package/dist/components/data-display/image/use-image-state.js +54 -0
- package/dist/components/data-display/image/use-image-state.js.map +1 -0
- package/dist/components/data-display/paper/index.cjs +16 -0
- package/dist/components/data-display/paper/index.cjs.map +1 -0
- package/dist/components/data-display/paper/index.d.cts +8 -0
- package/dist/components/data-display/paper/index.d.ts +8 -0
- package/dist/components/data-display/paper/index.js +16 -0
- package/dist/components/data-display/paper/index.js.map +1 -0
- package/dist/components/data-display/paper/paper.css +40 -0
- package/dist/components/data-display/progress/circular-progress.cjs +75 -0
- package/dist/components/data-display/progress/circular-progress.cjs.map +1 -0
- package/dist/components/data-display/progress/circular-progress.css +21 -0
- package/dist/components/data-display/progress/circular-progress.d.cts +9 -0
- package/dist/components/data-display/progress/circular-progress.d.ts +9 -0
- package/dist/components/data-display/progress/circular-progress.js +75 -0
- package/dist/components/data-display/progress/circular-progress.js.map +1 -0
- package/dist/components/data-display/progress/linear-progress.cjs +32 -0
- package/dist/components/data-display/progress/linear-progress.cjs.map +1 -0
- package/dist/components/data-display/progress/linear-progress.css +39 -0
- package/dist/components/data-display/progress/linear-progress.d.cts +5 -0
- package/dist/components/data-display/progress/linear-progress.d.ts +5 -0
- package/dist/components/data-display/progress/linear-progress.js +32 -0
- package/dist/components/data-display/progress/linear-progress.js.map +1 -0
- package/dist/components/data-display/progress/types.d.cts +5 -0
- package/dist/components/data-display/progress/types.d.ts +5 -0
- package/dist/components/data-display/progress/utils.cjs +16 -0
- package/dist/components/data-display/progress/utils.cjs.map +1 -0
- package/dist/components/data-display/progress/utils.js +15 -0
- package/dist/components/data-display/progress/utils.js.map +1 -0
- package/dist/components/data-display/skeleton/index.cjs +18 -0
- package/dist/components/data-display/skeleton/index.cjs.map +1 -0
- package/dist/components/data-display/skeleton/index.d.cts +10 -0
- package/dist/components/data-display/skeleton/index.d.ts +10 -0
- package/dist/components/data-display/skeleton/index.js +18 -0
- package/dist/components/data-display/skeleton/index.js.map +1 -0
- package/dist/components/data-display/skeleton/skeleton.css +47 -0
- package/dist/components/editors/text-editor/editor.cjs +620 -0
- package/dist/components/editors/text-editor/editor.cjs.map +1 -0
- package/dist/components/editors/text-editor/editor.d.cts +1 -0
- package/dist/components/editors/text-editor/editor.d.ts +1 -0
- package/dist/components/editors/text-editor/editor.js +620 -0
- package/dist/components/editors/text-editor/editor.js.map +1 -0
- package/dist/components/editors/text-editor/index.cjs +39 -0
- package/dist/components/editors/text-editor/index.cjs.map +1 -0
- package/dist/components/editors/text-editor/index.d.cts +13 -0
- package/dist/components/editors/text-editor/index.d.ts +13 -0
- package/dist/components/editors/text-editor/index.js +38 -0
- package/dist/components/editors/text-editor/index.js.map +1 -0
- package/dist/components/editors/text-editor/text-document.cjs +406 -0
- package/dist/components/editors/text-editor/text-document.cjs.map +1 -0
- package/dist/components/editors/text-editor/text-document.js +391 -0
- package/dist/components/editors/text-editor/text-document.js.map +1 -0
- package/dist/components/editors/text-editor/text-editor-toolbar.cjs +251 -0
- package/dist/components/editors/text-editor/text-editor-toolbar.cjs.map +1 -0
- package/dist/components/editors/text-editor/text-editor-toolbar.css +16 -0
- package/dist/components/editors/text-editor/text-editor-toolbar.d.cts +7 -0
- package/dist/components/editors/text-editor/text-editor-toolbar.d.ts +7 -0
- package/dist/components/editors/text-editor/text-editor-toolbar.js +251 -0
- package/dist/components/editors/text-editor/text-editor-toolbar.js.map +1 -0
- package/dist/components/editors/text-editor/text-editor.css +116 -0
- package/dist/components/editors/text-editor/text-editor.types.d.cts +37 -0
- package/dist/components/editors/text-editor/text-editor.types.d.ts +37 -0
- package/dist/components/editors/text-editor/text-parser.cjs +262 -0
- package/dist/components/editors/text-editor/text-parser.cjs.map +1 -0
- package/dist/components/editors/text-editor/text-parser.js +261 -0
- package/dist/components/editors/text-editor/text-parser.js.map +1 -0
- package/dist/components/editors/text-editor/text-renderer.cjs +85 -0
- package/dist/components/editors/text-editor/text-renderer.cjs.map +1 -0
- package/dist/components/editors/text-editor/text-renderer.d.cts +7 -0
- package/dist/components/editors/text-editor/text-renderer.d.ts +7 -0
- package/dist/components/editors/text-editor/text-renderer.js +85 -0
- package/dist/components/editors/text-editor/text-renderer.js.map +1 -0
- package/dist/components/forms/autocomplete/autocomplete.css +384 -0
- package/dist/components/forms/autocomplete/autocomplete.types.d.cts +86 -0
- package/dist/components/forms/autocomplete/autocomplete.types.d.ts +86 -0
- package/dist/components/forms/autocomplete/autocomplete.utils.cjs +47 -0
- package/dist/components/forms/autocomplete/autocomplete.utils.cjs.map +1 -0
- package/dist/components/forms/autocomplete/autocomplete.utils.js +44 -0
- package/dist/components/forms/autocomplete/autocomplete.utils.js.map +1 -0
- package/dist/components/forms/autocomplete/index.cjs +532 -0
- package/dist/components/forms/autocomplete/index.cjs.map +1 -0
- package/dist/components/forms/autocomplete/index.d.cts +3 -0
- package/dist/components/forms/autocomplete/index.d.ts +3 -0
- package/dist/components/forms/autocomplete/index.js +532 -0
- package/dist/components/forms/autocomplete/index.js.map +1 -0
- package/dist/components/forms/checkbox/checkbox.css +146 -0
- package/dist/components/forms/checkbox/index.cjs +80 -0
- package/dist/components/forms/checkbox/index.cjs.map +1 -0
- package/dist/components/forms/checkbox/index.d.cts +20 -0
- package/dist/components/forms/checkbox/index.d.ts +20 -0
- package/dist/components/forms/checkbox/index.js +80 -0
- package/dist/components/forms/checkbox/index.js.map +1 -0
- package/dist/components/forms/date-picker/date-picker.css +478 -0
- package/dist/components/forms/date-picker/date-picker.types.d.cts +75 -0
- package/dist/components/forms/date-picker/date-picker.types.d.ts +75 -0
- package/dist/components/forms/date-picker/date-picker.utils.cjs +76 -0
- package/dist/components/forms/date-picker/date-picker.utils.cjs.map +1 -0
- package/dist/components/forms/date-picker/date-picker.utils.js +64 -0
- package/dist/components/forms/date-picker/date-picker.utils.js.map +1 -0
- package/dist/components/forms/date-picker/index.cjs +572 -0
- package/dist/components/forms/date-picker/index.cjs.map +1 -0
- package/dist/components/forms/date-picker/index.d.cts +3 -0
- package/dist/components/forms/date-picker/index.d.ts +3 -0
- package/dist/components/forms/date-picker/index.js +572 -0
- package/dist/components/forms/date-picker/index.js.map +1 -0
- package/dist/components/forms/file-upload/file-upload.css +290 -0
- package/dist/components/forms/file-upload/file-upload.types.d.cts +51 -0
- package/dist/components/forms/file-upload/file-upload.types.d.ts +51 -0
- package/dist/components/forms/file-upload/file-upload.utils.cjs +76 -0
- package/dist/components/forms/file-upload/file-upload.utils.cjs.map +1 -0
- package/dist/components/forms/file-upload/file-upload.utils.js +72 -0
- package/dist/components/forms/file-upload/file-upload.utils.js.map +1 -0
- package/dist/components/forms/file-upload/index.cjs +346 -0
- package/dist/components/forms/file-upload/index.cjs.map +1 -0
- package/dist/components/forms/file-upload/index.d.cts +3 -0
- package/dist/components/forms/file-upload/index.d.ts +3 -0
- package/dist/components/forms/file-upload/index.js +346 -0
- package/dist/components/forms/file-upload/index.js.map +1 -0
- package/dist/components/forms/form-field/form-field-state.cjs +25 -0
- package/dist/components/forms/form-field/form-field-state.cjs.map +1 -0
- package/dist/components/forms/form-field/form-field-state.js +25 -0
- package/dist/components/forms/form-field/form-field-state.js.map +1 -0
- package/dist/components/forms/form-field/form-field.css +44 -0
- package/dist/components/forms/form-field/index.cjs +61 -0
- package/dist/components/forms/form-field/index.cjs.map +1 -0
- package/dist/components/forms/form-field/index.d.cts +23 -0
- package/dist/components/forms/form-field/index.d.ts +23 -0
- package/dist/components/forms/form-field/index.js +61 -0
- package/dist/components/forms/form-field/index.js.map +1 -0
- package/dist/components/forms/input/index.d.cts +4 -0
- package/dist/components/forms/input/index.d.ts +4 -0
- package/dist/components/forms/input/input.css +153 -0
- package/dist/components/forms/input/number-input.cjs +192 -0
- package/dist/components/forms/input/number-input.cjs.map +1 -0
- package/dist/components/forms/input/number-input.d.cts +20 -0
- package/dist/components/forms/input/number-input.d.ts +20 -0
- package/dist/components/forms/input/number-input.js +192 -0
- package/dist/components/forms/input/number-input.js.map +1 -0
- package/dist/components/forms/input/text-area-input.cjs +47 -0
- package/dist/components/forms/input/text-area-input.cjs.map +1 -0
- package/dist/components/forms/input/text-area-input.d.cts +8 -0
- package/dist/components/forms/input/text-area-input.d.ts +8 -0
- package/dist/components/forms/input/text-area-input.js +47 -0
- package/dist/components/forms/input/text-area-input.js.map +1 -0
- package/dist/components/forms/input/text-input.cjs +47 -0
- package/dist/components/forms/input/text-input.cjs.map +1 -0
- package/dist/components/forms/input/text-input.d.cts +9 -0
- package/dist/components/forms/input/text-input.d.ts +9 -0
- package/dist/components/forms/input/text-input.js +47 -0
- package/dist/components/forms/input/text-input.js.map +1 -0
- package/dist/components/forms/label/index.cjs +26 -0
- package/dist/components/forms/label/index.cjs.map +1 -0
- package/dist/components/forms/label/index.d.cts +8 -0
- package/dist/components/forms/label/index.d.ts +8 -0
- package/dist/components/forms/label/index.js +26 -0
- package/dist/components/forms/label/index.js.map +1 -0
- package/dist/components/forms/label/label.css +22 -0
- package/dist/components/forms/radio-group/index.cjs +226 -0
- package/dist/components/forms/radio-group/index.cjs.map +1 -0
- package/dist/components/forms/radio-group/index.d.cts +5 -0
- package/dist/components/forms/radio-group/index.d.ts +5 -0
- package/dist/components/forms/radio-group/index.js +225 -0
- package/dist/components/forms/radio-group/index.js.map +1 -0
- package/dist/components/forms/radio-group/radio-group.css +222 -0
- package/dist/components/forms/radio-group/radio-group.types.d.cts +51 -0
- package/dist/components/forms/radio-group/radio-group.types.d.ts +51 -0
- package/dist/components/forms/radio-group/radio-group.utils.cjs +22 -0
- package/dist/components/forms/radio-group/radio-group.utils.cjs.map +1 -0
- package/dist/components/forms/radio-group/radio-group.utils.js +21 -0
- package/dist/components/forms/radio-group/radio-group.utils.js.map +1 -0
- package/dist/components/forms/select/index.cjs +468 -0
- package/dist/components/forms/select/index.cjs.map +1 -0
- package/dist/components/forms/select/index.d.cts +112 -0
- package/dist/components/forms/select/index.d.ts +112 -0
- package/dist/components/forms/select/index.js +468 -0
- package/dist/components/forms/select/index.js.map +1 -0
- package/dist/components/forms/select/select.css +363 -0
- package/dist/components/forms/slider/index.cjs +93 -0
- package/dist/components/forms/slider/index.cjs.map +1 -0
- package/dist/components/forms/slider/index.d.cts +37 -0
- package/dist/components/forms/slider/index.d.ts +37 -0
- package/dist/components/forms/slider/index.js +93 -0
- package/dist/components/forms/slider/index.js.map +1 -0
- package/dist/components/forms/slider/slider.css +202 -0
- package/dist/components/forms/stepper/index.cjs +113 -0
- package/dist/components/forms/stepper/index.cjs.map +1 -0
- package/dist/components/forms/stepper/index.d.cts +48 -0
- package/dist/components/forms/stepper/index.d.ts +48 -0
- package/dist/components/forms/stepper/index.js +113 -0
- package/dist/components/forms/stepper/index.js.map +1 -0
- package/dist/components/forms/stepper/stepper.css +241 -0
- package/dist/components/forms/switch/index.cjs +45 -0
- package/dist/components/forms/switch/index.cjs.map +1 -0
- package/dist/components/forms/switch/index.d.cts +11 -0
- package/dist/components/forms/switch/index.d.ts +11 -0
- package/dist/components/forms/switch/index.js +45 -0
- package/dist/components/forms/switch/index.js.map +1 -0
- package/dist/components/forms/switch/switch.css +142 -0
- package/dist/components/layout/app-bar/app-bar.css +197 -0
- package/dist/components/layout/app-bar/index.cjs +150 -0
- package/dist/components/layout/app-bar/index.cjs.map +1 -0
- package/dist/components/layout/app-bar/index.d.cts +21 -0
- package/dist/components/layout/app-bar/index.d.ts +21 -0
- package/dist/components/layout/app-bar/index.js +150 -0
- package/dist/components/layout/app-bar/index.js.map +1 -0
- package/dist/components/layout/background/background.css +160 -0
- package/dist/components/layout/background/index.cjs +34 -0
- package/dist/components/layout/background/index.cjs.map +1 -0
- package/dist/components/layout/background/index.d.cts +23 -0
- package/dist/components/layout/background/index.d.ts +23 -0
- package/dist/components/layout/background/index.js +34 -0
- package/dist/components/layout/background/index.js.map +1 -0
- package/dist/components/layout/bottom-navigation/bottom-navigation.css +108 -0
- package/dist/components/layout/bottom-navigation/index.cjs +51 -0
- package/dist/components/layout/bottom-navigation/index.cjs.map +1 -0
- package/dist/components/layout/bottom-navigation/index.d.cts +19 -0
- package/dist/components/layout/bottom-navigation/index.d.ts +19 -0
- package/dist/components/layout/bottom-navigation/index.js +50 -0
- package/dist/components/layout/bottom-navigation/index.js.map +1 -0
- package/dist/components/layout/breadcrumbs/breadcrumbs.css +80 -0
- package/dist/components/layout/breadcrumbs/index.cjs +38 -0
- package/dist/components/layout/breadcrumbs/index.cjs.map +1 -0
- package/dist/components/layout/breadcrumbs/index.d.cts +18 -0
- package/dist/components/layout/breadcrumbs/index.d.ts +18 -0
- package/dist/components/layout/breadcrumbs/index.js +38 -0
- package/dist/components/layout/breadcrumbs/index.js.map +1 -0
- package/dist/components/layout/collapsable-sidebar/collapsable-sidebar.css +240 -0
- package/dist/components/layout/collapsable-sidebar/index.cjs +107 -0
- package/dist/components/layout/collapsable-sidebar/index.cjs.map +1 -0
- package/dist/components/layout/collapsable-sidebar/index.d.cts +35 -0
- package/dist/components/layout/collapsable-sidebar/index.d.ts +35 -0
- package/dist/components/layout/collapsable-sidebar/index.js +107 -0
- package/dist/components/layout/collapsable-sidebar/index.js.map +1 -0
- package/dist/components/layout/container/container.css +24 -0
- package/dist/components/layout/container/container.utils.cjs +11 -0
- package/dist/components/layout/container/container.utils.cjs.map +1 -0
- package/dist/components/layout/container/container.utils.d.cts +1 -0
- package/dist/components/layout/container/container.utils.d.ts +1 -0
- package/dist/components/layout/container/container.utils.js +11 -0
- package/dist/components/layout/container/container.utils.js.map +1 -0
- package/dist/components/layout/container/index.cjs +17 -0
- package/dist/components/layout/container/index.cjs.map +1 -0
- package/dist/components/layout/container/index.d.cts +11 -0
- package/dist/components/layout/container/index.d.ts +11 -0
- package/dist/components/layout/container/index.js +17 -0
- package/dist/components/layout/container/index.js.map +1 -0
- package/dist/components/layout/page-layout/index.cjs +80 -0
- package/dist/components/layout/page-layout/index.cjs.map +1 -0
- package/dist/components/layout/page-layout/index.d.cts +61 -0
- package/dist/components/layout/page-layout/index.d.ts +61 -0
- package/dist/components/layout/page-layout/index.js +80 -0
- package/dist/components/layout/page-layout/index.js.map +1 -0
- package/dist/components/layout/page-layout/page-layout.css +88 -0
- package/dist/components/layout/resizable-panels/index.cjs +226 -0
- package/dist/components/layout/resizable-panels/index.cjs.map +1 -0
- package/dist/components/layout/resizable-panels/index.d.cts +59 -0
- package/dist/components/layout/resizable-panels/index.d.ts +59 -0
- package/dist/components/layout/resizable-panels/index.js +224 -0
- package/dist/components/layout/resizable-panels/index.js.map +1 -0
- package/dist/components/layout/resizable-panels/resizable-panels.css +121 -0
- package/dist/components/layout/resizable-panels/resizable-panels.utils.cjs +107 -0
- package/dist/components/layout/resizable-panels/resizable-panels.utils.cjs.map +1 -0
- package/dist/components/layout/resizable-panels/resizable-panels.utils.js +105 -0
- package/dist/components/layout/resizable-panels/resizable-panels.utils.js.map +1 -0
- package/dist/components/layout/section/index.cjs +15 -0
- package/dist/components/layout/section/index.cjs.map +1 -0
- package/dist/components/layout/section/index.d.cts +2 -0
- package/dist/components/layout/section/index.d.ts +2 -0
- package/dist/components/layout/section/index.js +15 -0
- package/dist/components/layout/section/index.js.map +1 -0
- package/dist/components/layout/section/section.css +71 -0
- package/dist/components/layout/section/types.d.cts +13 -0
- package/dist/components/layout/section/types.d.ts +13 -0
- package/dist/components/layout/section-stack/index.cjs +29 -0
- package/dist/components/layout/section-stack/index.cjs.map +1 -0
- package/dist/components/layout/section-stack/index.d.cts +8 -0
- package/dist/components/layout/section-stack/index.d.ts +8 -0
- package/dist/components/layout/section-stack/index.js +29 -0
- package/dist/components/layout/section-stack/index.js.map +1 -0
- package/dist/components/layout/sidebar/index.cjs +16 -0
- package/dist/components/layout/sidebar/index.cjs.map +1 -0
- package/dist/components/layout/sidebar/index.d.cts +7 -0
- package/dist/components/layout/sidebar/index.d.ts +7 -0
- package/dist/components/layout/sidebar/index.js +16 -0
- package/dist/components/layout/sidebar/index.js.map +1 -0
- package/dist/components/layout/sidebar/sidebar.css +21 -0
- package/dist/components/layout/stack/index.cjs +30 -0
- package/dist/components/layout/stack/index.cjs.map +1 -0
- package/dist/components/layout/stack/index.d.cts +31 -0
- package/dist/components/layout/stack/index.d.ts +31 -0
- package/dist/components/layout/stack/index.js +30 -0
- package/dist/components/layout/stack/index.js.map +1 -0
- package/dist/components/layout/stack/stack.css +303 -0
- package/dist/components/navigation/accordion/accordion.css +97 -0
- package/dist/components/navigation/accordion/index.cjs +107 -0
- package/dist/components/navigation/accordion/index.cjs.map +1 -0
- package/dist/components/navigation/accordion/index.d.cts +48 -0
- package/dist/components/navigation/accordion/index.d.ts +48 -0
- package/dist/components/navigation/accordion/index.js +107 -0
- package/dist/components/navigation/accordion/index.js.map +1 -0
- package/dist/components/navigation/carousel/carousel.css +283 -0
- package/dist/components/navigation/carousel/controller.cjs +46 -0
- package/dist/components/navigation/carousel/controller.cjs.map +1 -0
- package/dist/components/navigation/carousel/controller.d.cts +16 -0
- package/dist/components/navigation/carousel/controller.d.ts +16 -0
- package/dist/components/navigation/carousel/controller.js +45 -0
- package/dist/components/navigation/carousel/controller.js.map +1 -0
- package/dist/components/navigation/carousel/index.cjs +494 -0
- package/dist/components/navigation/carousel/index.cjs.map +1 -0
- package/dist/components/navigation/carousel/index.d.cts +27 -0
- package/dist/components/navigation/carousel/index.d.ts +27 -0
- package/dist/components/navigation/carousel/index.js +494 -0
- package/dist/components/navigation/carousel/index.js.map +1 -0
- package/dist/components/navigation/link/index.cjs +40 -0
- package/dist/components/navigation/link/index.cjs.map +1 -0
- package/dist/components/navigation/link/index.d.cts +3 -0
- package/dist/components/navigation/link/index.d.ts +3 -0
- package/dist/components/navigation/link/index.js +40 -0
- package/dist/components/navigation/link/index.js.map +1 -0
- package/dist/components/navigation/link/link.css +31 -0
- package/dist/components/navigation/link/types.d.cts +12 -0
- package/dist/components/navigation/link/types.d.ts +12 -0
- package/dist/components/navigation/tabs/index.cjs +111 -0
- package/dist/components/navigation/tabs/index.cjs.map +1 -0
- package/dist/components/navigation/tabs/index.d.cts +30 -0
- package/dist/components/navigation/tabs/index.d.ts +30 -0
- package/dist/components/navigation/tabs/index.js +110 -0
- package/dist/components/navigation/tabs/index.js.map +1 -0
- package/dist/components/navigation/tabs/tabs.css +216 -0
- package/dist/components/navigation/tree-view/index.cjs +455 -0
- package/dist/components/navigation/tree-view/index.cjs.map +1 -0
- package/dist/components/navigation/tree-view/index.d.cts +96 -0
- package/dist/components/navigation/tree-view/index.d.ts +96 -0
- package/dist/components/navigation/tree-view/index.js +455 -0
- package/dist/components/navigation/tree-view/index.js.map +1 -0
- package/dist/components/navigation/tree-view/tree-view.css +258 -0
- package/dist/components/overlays/backdrop/backdrop.css +10 -0
- package/dist/components/overlays/backdrop/index.cjs +70 -0
- package/dist/components/overlays/backdrop/index.cjs.map +1 -0
- package/dist/components/overlays/backdrop/index.d.cts +12 -0
- package/dist/components/overlays/backdrop/index.d.ts +12 -0
- package/dist/components/overlays/backdrop/index.js +70 -0
- package/dist/components/overlays/backdrop/index.js.map +1 -0
- package/dist/components/overlays/command/command.css +154 -0
- package/dist/components/overlays/command/command.types.d.cts +36 -0
- package/dist/components/overlays/command/command.types.d.ts +36 -0
- package/dist/components/overlays/command/command.utils.cjs +39 -0
- package/dist/components/overlays/command/command.utils.cjs.map +1 -0
- package/dist/components/overlays/command/command.utils.js +35 -0
- package/dist/components/overlays/command/command.utils.js.map +1 -0
- package/dist/components/overlays/command/index.cjs +274 -0
- package/dist/components/overlays/command/index.cjs.map +1 -0
- package/dist/components/overlays/command/index.d.cts +4 -0
- package/dist/components/overlays/command/index.d.ts +4 -0
- package/dist/components/overlays/command/index.js +273 -0
- package/dist/components/overlays/command/index.js.map +1 -0
- package/dist/components/overlays/dialog/dialog.css +121 -0
- package/dist/components/overlays/dialog/index.cjs +80 -0
- package/dist/components/overlays/dialog/index.cjs.map +1 -0
- package/dist/components/overlays/dialog/index.d.cts +35 -0
- package/dist/components/overlays/dialog/index.d.ts +35 -0
- package/dist/components/overlays/dialog/index.js +80 -0
- package/dist/components/overlays/dialog/index.js.map +1 -0
- package/dist/components/overlays/drawer/drawer.css +133 -0
- package/dist/components/overlays/drawer/index.cjs +90 -0
- package/dist/components/overlays/drawer/index.cjs.map +1 -0
- package/dist/components/overlays/drawer/index.d.cts +11 -0
- package/dist/components/overlays/drawer/index.d.ts +11 -0
- package/dist/components/overlays/drawer/index.js +90 -0
- package/dist/components/overlays/drawer/index.js.map +1 -0
- package/dist/components/overlays/drawer/use-resize-bar.cjs +152 -0
- package/dist/components/overlays/drawer/use-resize-bar.cjs.map +1 -0
- package/dist/components/overlays/drawer/use-resize-bar.js +152 -0
- package/dist/components/overlays/drawer/use-resize-bar.js.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-content.cjs +132 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-content.cjs.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-content.d.cts +3 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-content.d.ts +3 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-content.js +132 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-content.js.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-items.cjs +136 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-items.cjs.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-items.d.cts +7 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-items.d.ts +7 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-items.js +132 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-items.js.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-radio.cjs +76 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-radio.cjs.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-radio.d.cts +4 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-radio.d.ts +4 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-radio.js +75 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-radio.js.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-trigger.cjs +96 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-trigger.cjs.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-trigger.d.cts +3 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-trigger.d.ts +3 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-trigger.js +96 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-trigger.js.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.cjs +111 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.cjs.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.context.cjs +21 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.context.cjs.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.context.js +18 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.context.js.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.css +127 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.d.cts +3 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.d.ts +3 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.js +111 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.js.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.types.d.cts +66 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.types.d.ts +66 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.utils.cjs +44 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.utils.cjs.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.utils.js +39 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu.utils.js.map +1 -0
- package/dist/components/overlays/dropdown-menu/index.cjs +31 -0
- package/dist/components/overlays/dropdown-menu/index.cjs.map +1 -0
- package/dist/components/overlays/dropdown-menu/index.d.cts +19 -0
- package/dist/components/overlays/dropdown-menu/index.d.ts +19 -0
- package/dist/components/overlays/dropdown-menu/index.js +22 -0
- package/dist/components/overlays/dropdown-menu/index.js.map +1 -0
- package/dist/components/overlays/floating-position/calculate-position.cjs +94 -0
- package/dist/components/overlays/floating-position/calculate-position.cjs.map +1 -0
- package/dist/components/overlays/floating-position/calculate-position.js +89 -0
- package/dist/components/overlays/floating-position/calculate-position.js.map +1 -0
- package/dist/components/overlays/floating-position/use-floating-position.cjs +89 -0
- package/dist/components/overlays/floating-position/use-floating-position.cjs.map +1 -0
- package/dist/components/overlays/floating-position/use-floating-position.js +89 -0
- package/dist/components/overlays/floating-position/use-floating-position.js.map +1 -0
- package/dist/components/overlays/notification/index.cjs +142 -0
- package/dist/components/overlays/notification/index.cjs.map +1 -0
- package/dist/components/overlays/notification/index.d.cts +16 -0
- package/dist/components/overlays/notification/index.d.ts +16 -0
- package/dist/components/overlays/notification/index.js +139 -0
- package/dist/components/overlays/notification/index.js.map +1 -0
- package/dist/components/overlays/notification/notification-provider.cjs +69 -0
- package/dist/components/overlays/notification/notification-provider.cjs.map +1 -0
- package/dist/components/overlays/notification/notification-provider.d.cts +3 -0
- package/dist/components/overlays/notification/notification-provider.d.ts +3 -0
- package/dist/components/overlays/notification/notification-provider.js +68 -0
- package/dist/components/overlays/notification/notification-provider.js.map +1 -0
- package/dist/components/overlays/notification/notification.css +172 -0
- package/dist/components/overlays/notification/notification.types.d.cts +41 -0
- package/dist/components/overlays/notification/notification.types.d.ts +41 -0
- package/dist/components/overlays/notification/notification.utils.cjs +23 -0
- package/dist/components/overlays/notification/notification.utils.cjs.map +1 -0
- package/dist/components/overlays/notification/notification.utils.js +22 -0
- package/dist/components/overlays/notification/notification.utils.js.map +1 -0
- package/dist/components/overlays/notification/use-notification.cjs +12 -0
- package/dist/components/overlays/notification/use-notification.cjs.map +1 -0
- package/dist/components/overlays/notification/use-notification.d.cts +3 -0
- package/dist/components/overlays/notification/use-notification.d.ts +3 -0
- package/dist/components/overlays/notification/use-notification.js +12 -0
- package/dist/components/overlays/notification/use-notification.js.map +1 -0
- package/dist/components/overlays/overlay-stack/index.cjs +195 -0
- package/dist/components/overlays/overlay-stack/index.cjs.map +1 -0
- package/dist/components/overlays/overlay-stack/index.js +193 -0
- package/dist/components/overlays/overlay-stack/index.js.map +1 -0
- package/dist/components/overlays/popout/index.cjs +196 -0
- package/dist/components/overlays/popout/index.cjs.map +1 -0
- package/dist/components/overlays/popout/index.d.cts +26 -0
- package/dist/components/overlays/popout/index.d.ts +26 -0
- package/dist/components/overlays/popout/index.js +195 -0
- package/dist/components/overlays/popout/index.js.map +1 -0
- package/dist/components/overlays/popout/popout.css +15 -0
- package/dist/components/overlays/popover/index.cjs +163 -0
- package/dist/components/overlays/popover/index.cjs.map +1 -0
- package/dist/components/overlays/popover/index.d.cts +28 -0
- package/dist/components/overlays/popover/index.d.ts +28 -0
- package/dist/components/overlays/popover/index.js +163 -0
- package/dist/components/overlays/popover/index.js.map +1 -0
- package/dist/components/overlays/popover/popover.css +56 -0
- package/dist/components/overlays/portal/index.cjs +33 -0
- package/dist/components/overlays/portal/index.cjs.map +1 -0
- package/dist/components/overlays/portal/index.d.cts +15 -0
- package/dist/components/overlays/portal/index.d.ts +15 -0
- package/dist/components/overlays/portal/index.js +33 -0
- package/dist/components/overlays/portal/index.js.map +1 -0
- package/dist/components/overlays/portal/target.cjs +17 -0
- package/dist/components/overlays/portal/target.cjs.map +1 -0
- package/dist/components/overlays/portal/target.css +3 -0
- package/dist/components/overlays/portal/target.d.cts +7 -0
- package/dist/components/overlays/portal/target.d.ts +7 -0
- package/dist/components/overlays/portal/target.js +17 -0
- package/dist/components/overlays/portal/target.js.map +1 -0
- package/dist/components/overlays/tooltip/index.cjs +71 -0
- package/dist/components/overlays/tooltip/index.cjs.map +1 -0
- package/dist/components/overlays/tooltip/index.d.cts +24 -0
- package/dist/components/overlays/tooltip/index.d.ts +24 -0
- package/dist/components/overlays/tooltip/index.js +71 -0
- package/dist/components/overlays/tooltip/index.js.map +1 -0
- package/dist/components/overlays/tooltip/tooltip.css +67 -0
- package/dist/components/typography/heading.cjs +14 -0
- package/dist/components/typography/heading.cjs.map +1 -0
- package/dist/components/typography/heading.d.cts +11 -0
- package/dist/components/typography/heading.d.ts +11 -0
- package/dist/components/typography/heading.js +14 -0
- package/dist/components/typography/heading.js.map +1 -0
- package/dist/components/typography/text.cjs +14 -0
- package/dist/components/typography/text.cjs.map +1 -0
- package/dist/components/typography/text.d.cts +12 -0
- package/dist/components/typography/text.d.ts +12 -0
- package/dist/components/typography/text.js +14 -0
- package/dist/components/typography/text.js.map +1 -0
- package/dist/components/utilities/preview/highlight.cjs +79 -0
- package/dist/components/utilities/preview/highlight.cjs.map +1 -0
- package/dist/components/utilities/preview/highlight.js +79 -0
- package/dist/components/utilities/preview/highlight.js.map +1 -0
- package/dist/components/utilities/preview/index.cjs +391 -0
- package/dist/components/utilities/preview/index.cjs.map +1 -0
- package/dist/components/utilities/preview/index.d.cts +20 -0
- package/dist/components/utilities/preview/index.d.ts +20 -0
- package/dist/components/utilities/preview/index.js +391 -0
- package/dist/components/utilities/preview/index.js.map +1 -0
- package/dist/components/utilities/preview/preview.css +268 -0
- package/dist/components/utilities/scroll-lock/index.cjs +124 -0
- package/dist/components/utilities/scroll-lock/index.cjs.map +1 -0
- package/dist/components/utilities/scroll-lock/index.d.cts +6 -0
- package/dist/components/utilities/scroll-lock/index.d.ts +6 -0
- package/dist/components/utilities/scroll-lock/index.js +124 -0
- package/dist/components/utilities/scroll-lock/index.js.map +1 -0
- package/dist/components/utilities/transition/index.cjs +171 -0
- package/dist/components/utilities/transition/index.cjs.map +1 -0
- package/dist/components/utilities/transition/index.d.cts +27 -0
- package/dist/components/utilities/transition/index.d.ts +27 -0
- package/dist/components/utilities/transition/index.js +171 -0
- package/dist/components/utilities/transition/index.js.map +1 -0
- package/dist/components/utilities/transition/transition.css +130 -0
- package/dist/index.cjs +159 -0
- package/dist/index.d.cts +86 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +70 -0
- package/package.json +65 -4
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_radio_group_utils = require("./radio-group.utils.cjs");
|
|
3
|
+
;/* empty css */
|
|
4
|
+
let _puzzle_ui_core = require("@puzzle-ui/core");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
let _puzzle_ui_hooks = require("@puzzle-ui/hooks");
|
|
8
|
+
// src/components/forms/radio-group/index.tsx
|
|
9
|
+
const RadioGroupContext = (0, react.createContext)(null);
|
|
10
|
+
const useRadioGroupContext = () => {
|
|
11
|
+
const context = (0, react.useContext)(RadioGroupContext);
|
|
12
|
+
if (!context) throw new Error("Radio must be rendered inside a RadioGroup.");
|
|
13
|
+
return context;
|
|
14
|
+
};
|
|
15
|
+
const Radio = ({ value, label, children, description, disabled = false, className, style, id, ref, onChange, onFocus, onKeyDown, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...inputProps }) => {
|
|
16
|
+
const context = useRadioGroupContext();
|
|
17
|
+
const generatedId = (0, react.useId)();
|
|
18
|
+
const inputId = id ?? generatedId;
|
|
19
|
+
const descriptionId = description != null ? `${inputId}-description` : void 0;
|
|
20
|
+
const radioLabel = label ?? children;
|
|
21
|
+
const labelId = radioLabel != null ? `${inputId}-label` : void 0;
|
|
22
|
+
const isDisabled = context.disabled || disabled;
|
|
23
|
+
const isSelected = context.value === value;
|
|
24
|
+
const isRequired = Boolean(context.name) && context.required && context.requiredValue === value;
|
|
25
|
+
const describedBy = require_radio_group_utils.mergeDescribedBy(context.describedBy, ariaDescribedBy, descriptionId);
|
|
26
|
+
const rovingRef = context.rovingFocus.getItemRef(value);
|
|
27
|
+
const setInputRef = (0, react.useCallback)((node) => {
|
|
28
|
+
rovingRef(node);
|
|
29
|
+
if (typeof ref === "function") ref(node);
|
|
30
|
+
else if (ref) ref.current = node;
|
|
31
|
+
}, [ref, rovingRef]);
|
|
32
|
+
const handleFocus = (event) => {
|
|
33
|
+
context.rovingFocus.onItemFocus(value);
|
|
34
|
+
if (context.keyboardNavigationRef.current) {
|
|
35
|
+
context.keyboardNavigationRef.current = false;
|
|
36
|
+
context.selectValue(value);
|
|
37
|
+
}
|
|
38
|
+
onFocus?.(event);
|
|
39
|
+
};
|
|
40
|
+
const handleKeyDown = (event) => {
|
|
41
|
+
onKeyDown?.(event);
|
|
42
|
+
if (event.defaultPrevented || isDisabled) return;
|
|
43
|
+
const isHorizontalArrow = event.key === "ArrowLeft" || event.key === "ArrowRight";
|
|
44
|
+
const isVerticalArrow = event.key === "ArrowUp" || event.key === "ArrowDown";
|
|
45
|
+
const isArrowKey = isHorizontalArrow || isVerticalArrow;
|
|
46
|
+
const isSupportedArrow = context.orientation === "horizontal" ? isHorizontalArrow : isVerticalArrow;
|
|
47
|
+
if (isArrowKey && !isSupportedArrow) {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const activeElement = event.currentTarget.ownerDocument.activeElement;
|
|
52
|
+
context.keyboardNavigationRef.current = true;
|
|
53
|
+
context.rovingFocus.onItemKeyDown(event, value);
|
|
54
|
+
if (event.currentTarget.ownerDocument.activeElement === activeElement) context.keyboardNavigationRef.current = false;
|
|
55
|
+
};
|
|
56
|
+
const handleChange = (event) => {
|
|
57
|
+
onChange?.(event);
|
|
58
|
+
if (!event.defaultPrevented) context.selectValue(value);
|
|
59
|
+
};
|
|
60
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
61
|
+
className: (0, _puzzle_ui_core.cn)("puzzle-radio", `puzzle-radio--${context.size}`, isSelected && "puzzle-radio--checked", isDisabled && "puzzle-radio--disabled", className),
|
|
62
|
+
style,
|
|
63
|
+
"data-state": isSelected ? "checked" : "unchecked",
|
|
64
|
+
"data-disabled": isDisabled ? "true" : void 0,
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
67
|
+
...inputProps,
|
|
68
|
+
ref: setInputRef,
|
|
69
|
+
id: inputId,
|
|
70
|
+
className: "puzzle-radio__input",
|
|
71
|
+
type: "radio",
|
|
72
|
+
name: context.name,
|
|
73
|
+
form: context.form,
|
|
74
|
+
value,
|
|
75
|
+
checked: isSelected,
|
|
76
|
+
disabled: isDisabled,
|
|
77
|
+
required: isRequired,
|
|
78
|
+
tabIndex: context.rovingFocus.getItemTabIndex(value, isDisabled),
|
|
79
|
+
"aria-labelledby": inputProps["aria-labelledby"] ?? (inputProps["aria-label"] ? void 0 : labelId),
|
|
80
|
+
"aria-describedby": describedBy,
|
|
81
|
+
"aria-invalid": context.invalid ? true : ariaInvalid,
|
|
82
|
+
"data-state": isSelected ? "checked" : "unchecked",
|
|
83
|
+
onChange: handleChange,
|
|
84
|
+
onFocus: handleFocus,
|
|
85
|
+
onKeyDown: handleKeyDown
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
88
|
+
className: "puzzle-radio__control",
|
|
89
|
+
"aria-hidden": "true"
|
|
90
|
+
}),
|
|
91
|
+
(radioLabel != null || description != null) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
92
|
+
className: "puzzle-radio__content",
|
|
93
|
+
children: [radioLabel != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
94
|
+
id: labelId,
|
|
95
|
+
className: "puzzle-radio__label",
|
|
96
|
+
children: radioLabel
|
|
97
|
+
}), description != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
98
|
+
id: descriptionId,
|
|
99
|
+
className: "puzzle-radio__description",
|
|
100
|
+
children: description
|
|
101
|
+
})]
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const isRadioElement = (child) => (0, react.isValidElement)(child) && child.type === Radio;
|
|
107
|
+
const getRadioElements = (children) => react.Children.toArray(children).flatMap((child) => {
|
|
108
|
+
if ((0, react.isValidElement)(child) && child.type === react.Fragment) return getRadioElements(child.props.children);
|
|
109
|
+
return isRadioElement(child) ? [child] : [];
|
|
110
|
+
});
|
|
111
|
+
const RadioGroupRoot = ({ value, defaultValue, onValueChange, name, form, label, description, error, invalid, required = false, disabled = false, orientation = "vertical", size = "md", dir = "ltr", loop = true, children, id, className, style, role, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-labelledby": ariaLabelledBy, ...rootProps }) => {
|
|
112
|
+
const generatedId = (0, react.useId)();
|
|
113
|
+
const groupId = id ?? generatedId;
|
|
114
|
+
const descriptionId = description != null ? `${groupId}-description` : void 0;
|
|
115
|
+
const errorState = require_radio_group_utils.resolveRadioGroupError(error, invalid);
|
|
116
|
+
const errorId = errorState.hasError ? `${groupId}-error` : void 0;
|
|
117
|
+
const describedBy = require_radio_group_utils.mergeDescribedBy(ariaDescribedBy, descriptionId, errorId);
|
|
118
|
+
const groupName = name?.trim() || void 0;
|
|
119
|
+
const [uncontrolledValue, setUncontrolledValue] = (0, react.useState)(() => defaultValue);
|
|
120
|
+
const isControlled = value !== void 0;
|
|
121
|
+
const selectedValue = isControlled ? value ?? void 0 : uncontrolledValue;
|
|
122
|
+
const radioElements = getRadioElements(children);
|
|
123
|
+
const seenValues = /* @__PURE__ */ new Set();
|
|
124
|
+
for (const radio of radioElements) {
|
|
125
|
+
const radioValue = radio.props.value;
|
|
126
|
+
if (seenValues.has(radioValue)) throw new Error("RadioGroup radio values must be unique.");
|
|
127
|
+
seenValues.add(radioValue);
|
|
128
|
+
}
|
|
129
|
+
const firstEnabledValue = radioElements.find((radio) => !disabled && !radio.props.disabled)?.props.value;
|
|
130
|
+
const selectedFocusValue = radioElements.find((radio) => radio.props.value === selectedValue && !disabled && !radio.props.disabled)?.props.value ?? firstEnabledValue;
|
|
131
|
+
const focusItems = radioElements.map((radio) => ({
|
|
132
|
+
id: radio.props.value,
|
|
133
|
+
disabled: disabled || radio.props.disabled
|
|
134
|
+
}));
|
|
135
|
+
const rovingFocus = (0, _puzzle_ui_hooks.useRovingFocus)({
|
|
136
|
+
items: focusItems,
|
|
137
|
+
orientation,
|
|
138
|
+
dir,
|
|
139
|
+
loop,
|
|
140
|
+
initialActiveId: selectedFocusValue
|
|
141
|
+
});
|
|
142
|
+
(0, react.useEffect)(() => {
|
|
143
|
+
if (selectedFocusValue !== void 0) rovingFocus.onItemFocus(selectedFocusValue);
|
|
144
|
+
}, [selectedFocusValue, rovingFocus.onItemFocus]);
|
|
145
|
+
const keyboardNavigationRef = (0, react.useRef)(false);
|
|
146
|
+
const selectValue = (0, react.useCallback)((nextValue) => {
|
|
147
|
+
if (selectedValue === nextValue) return;
|
|
148
|
+
if (!isControlled) setUncontrolledValue(nextValue);
|
|
149
|
+
onValueChange?.(nextValue);
|
|
150
|
+
}, [
|
|
151
|
+
isControlled,
|
|
152
|
+
onValueChange,
|
|
153
|
+
selectedValue
|
|
154
|
+
]);
|
|
155
|
+
const contextValue = {
|
|
156
|
+
value: selectedValue,
|
|
157
|
+
name: groupName,
|
|
158
|
+
form,
|
|
159
|
+
disabled,
|
|
160
|
+
required,
|
|
161
|
+
requiredValue: firstEnabledValue,
|
|
162
|
+
orientation,
|
|
163
|
+
size,
|
|
164
|
+
invalid: errorState.isInvalid,
|
|
165
|
+
describedBy,
|
|
166
|
+
keyboardNavigationRef,
|
|
167
|
+
rovingFocus,
|
|
168
|
+
selectValue
|
|
169
|
+
};
|
|
170
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RadioGroupContext.Provider, {
|
|
171
|
+
value: contextValue,
|
|
172
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
|
|
173
|
+
...rootProps,
|
|
174
|
+
id: groupId,
|
|
175
|
+
form,
|
|
176
|
+
disabled,
|
|
177
|
+
className: (0, _puzzle_ui_core.cn)("puzzle-radio-group", className),
|
|
178
|
+
style,
|
|
179
|
+
role: role ?? "radiogroup",
|
|
180
|
+
dir,
|
|
181
|
+
"aria-labelledby": ariaLabelledBy,
|
|
182
|
+
"aria-describedby": describedBy,
|
|
183
|
+
"aria-invalid": errorState.isInvalid ? true : ariaInvalid,
|
|
184
|
+
"aria-required": required || void 0,
|
|
185
|
+
"aria-disabled": disabled || void 0,
|
|
186
|
+
"data-orientation": orientation,
|
|
187
|
+
"data-disabled": disabled ? "true" : void 0,
|
|
188
|
+
"data-invalid": errorState.isInvalid ? "true" : void 0,
|
|
189
|
+
"data-size": size,
|
|
190
|
+
children: [
|
|
191
|
+
label != null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("legend", {
|
|
192
|
+
id: `${groupId}-label`,
|
|
193
|
+
className: "puzzle-radio-group__legend",
|
|
194
|
+
children: [label, required && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
195
|
+
className: "puzzle-radio-group__required",
|
|
196
|
+
"aria-hidden": "true",
|
|
197
|
+
children: "*"
|
|
198
|
+
})]
|
|
199
|
+
}),
|
|
200
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
201
|
+
className: "puzzle-radio-group__options",
|
|
202
|
+
"data-orientation": orientation,
|
|
203
|
+
children
|
|
204
|
+
}),
|
|
205
|
+
description != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
206
|
+
id: descriptionId,
|
|
207
|
+
className: "puzzle-radio-group__description",
|
|
208
|
+
children: description
|
|
209
|
+
}),
|
|
210
|
+
errorState.hasError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
211
|
+
id: errorId,
|
|
212
|
+
className: "puzzle-radio-group__error",
|
|
213
|
+
role: "alert",
|
|
214
|
+
"aria-live": "polite",
|
|
215
|
+
"aria-atomic": "true",
|
|
216
|
+
children: errorState.errorContent
|
|
217
|
+
})
|
|
218
|
+
]
|
|
219
|
+
})
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
const RadioGroup = RadioGroupRoot;
|
|
223
|
+
exports.Radio = Radio;
|
|
224
|
+
exports.RadioGroup = RadioGroup;
|
|
225
|
+
|
|
226
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createContext","useContext","useId","mergeDescribedBy","useCallback","cn","isValidElement","Children","Fragment","resolveRadioGroupError","useState","useRovingFocus","useRef"],"sources":["../../../../src/components/forms/radio-group/index.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n Children,\n Fragment,\n createContext,\n isValidElement,\n useCallback,\n useContext,\n useEffect,\n useId,\n useRef,\n useState,\n type ChangeEvent,\n type FocusEvent,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n} from \"react\";\n\nimport { cn } from \"@puzzle-ui/core\";\nimport { useRovingFocus, type UseRovingFocusReturn } from \"@puzzle-ui/hooks\";\n\nimport type {\n RadioGroupOrientation,\n RadioGroupProps,\n RadioGroupSize,\n RadioProps,\n} from \"./radio-group.types\";\n\nimport { mergeDescribedBy, resolveRadioGroupError } from \"./radio-group.utils\";\n\nimport \"./radio-group.css\";\n\ntype RadioGroupContextValue = {\n value: string | undefined;\n name: string | undefined;\n form: string | undefined;\n disabled: boolean;\n required: boolean;\n requiredValue: string | undefined;\n orientation: RadioGroupOrientation;\n size: RadioGroupSize;\n invalid: boolean;\n describedBy: string | undefined;\n keyboardNavigationRef: { current: boolean };\n rovingFocus: UseRovingFocusReturn<HTMLInputElement>;\n selectValue: (value: string) => void;\n};\n\nconst RadioGroupContext = createContext<RadioGroupContextValue | null>(null);\n\nconst useRadioGroupContext = () => {\n const context = useContext(RadioGroupContext);\n\n if (!context) {\n throw new Error(\"Radio must be rendered inside a RadioGroup.\");\n }\n\n return context;\n};\n\nconst Radio = ({\n value,\n label,\n children,\n description,\n disabled = false,\n className,\n style,\n id,\n ref,\n onChange,\n onFocus,\n onKeyDown,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n ...inputProps\n}: RadioProps) => {\n const context = useRadioGroupContext();\n\n const generatedId = useId();\n const inputId = id ?? generatedId;\n\n const descriptionId =\n description != null ? `${inputId}-description` : undefined;\n\n const radioLabel = label ?? children;\n const labelId = radioLabel != null ? `${inputId}-label` : undefined;\n\n const isDisabled = context.disabled || disabled;\n const isSelected = context.value === value;\n\n const isRequired =\n Boolean(context.name) &&\n context.required &&\n context.requiredValue === value;\n\n const describedBy = mergeDescribedBy(\n context.describedBy,\n ariaDescribedBy,\n descriptionId,\n );\n\n const rovingRef = context.rovingFocus.getItemRef(value);\n\n const setInputRef = useCallback(\n (node: HTMLInputElement | null) => {\n rovingRef(node);\n\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n },\n [ref, rovingRef],\n );\n\n const handleFocus = (event: FocusEvent<HTMLInputElement>) => {\n context.rovingFocus.onItemFocus(value);\n\n if (context.keyboardNavigationRef.current) {\n context.keyboardNavigationRef.current = false;\n context.selectValue(value);\n }\n\n onFocus?.(event);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event);\n\n if (event.defaultPrevented || isDisabled) {\n return;\n }\n\n const isHorizontalArrow =\n event.key === \"ArrowLeft\" || event.key === \"ArrowRight\";\n\n const isVerticalArrow =\n event.key === \"ArrowUp\" || event.key === \"ArrowDown\";\n\n const isArrowKey = isHorizontalArrow || isVerticalArrow;\n\n const isSupportedArrow =\n context.orientation === \"horizontal\"\n ? isHorizontalArrow\n : isVerticalArrow;\n\n // Prevent the browser's native radio navigation from\n // moving focus in the wrong orientation.\n if (isArrowKey && !isSupportedArrow) {\n event.preventDefault();\n return;\n }\n\n const activeElement = event.currentTarget.ownerDocument.activeElement;\n\n context.keyboardNavigationRef.current = true;\n\n context.rovingFocus.onItemKeyDown(event, value);\n\n // The focus event normally consumes this flag. If focus\n // did not change (e.g. one-item group), clear it here.\n if (event.currentTarget.ownerDocument.activeElement === activeElement) {\n context.keyboardNavigationRef.current = false;\n }\n };\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n\n if (!event.defaultPrevented) {\n context.selectValue(value);\n }\n };\n\n return (\n <label\n className={cn(\n \"puzzle-radio\",\n `puzzle-radio--${context.size}`,\n isSelected && \"puzzle-radio--checked\",\n isDisabled && \"puzzle-radio--disabled\",\n className,\n )}\n style={style}\n data-state={isSelected ? \"checked\" : \"unchecked\"}\n data-disabled={isDisabled ? \"true\" : undefined}\n >\n <input\n {...inputProps}\n ref={setInputRef}\n id={inputId}\n className=\"puzzle-radio__input\"\n type=\"radio\"\n name={context.name}\n form={context.form}\n value={value}\n checked={isSelected}\n disabled={isDisabled}\n required={isRequired}\n tabIndex={context.rovingFocus.getItemTabIndex(value, isDisabled)}\n // The wrapping label also contains the description; name the radio by\n // its label text only and expose the description via aria-describedby.\n aria-labelledby={\n inputProps[\"aria-labelledby\"] ??\n (inputProps[\"aria-label\"] ? undefined : labelId)\n }\n aria-describedby={describedBy}\n aria-invalid={context.invalid ? true : ariaInvalid}\n data-state={isSelected ? \"checked\" : \"unchecked\"}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n />\n\n <span className=\"puzzle-radio__control\" aria-hidden=\"true\" />\n\n {(radioLabel != null || description != null) && (\n <span className=\"puzzle-radio__content\">\n {radioLabel != null && (\n <span id={labelId} className=\"puzzle-radio__label\">\n {radioLabel}\n </span>\n )}\n\n {description != null && (\n <span id={descriptionId} className=\"puzzle-radio__description\">\n {description}\n </span>\n )}\n </span>\n )}\n </label>\n );\n};\n\ntype RadioElement = ReactElement<RadioProps, typeof Radio>;\n\nconst isRadioElement = (child: ReactNode): child is RadioElement =>\n isValidElement<RadioProps>(child) && child.type === Radio;\n\nconst getRadioElements = (children: ReactNode): RadioElement[] =>\n Children.toArray(children).flatMap((child): RadioElement[] => {\n if (\n isValidElement<{ children?: ReactNode }>(child) &&\n child.type === Fragment\n ) {\n return getRadioElements(child.props.children);\n }\n\n return isRadioElement(child) ? [child] : [];\n });\n\nconst RadioGroupRoot = ({\n value,\n defaultValue,\n onValueChange,\n name,\n form,\n label,\n description,\n error,\n invalid,\n required = false,\n disabled = false,\n orientation = \"vertical\",\n size = \"md\",\n dir = \"ltr\",\n loop = true,\n children,\n id,\n className,\n style,\n role,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n \"aria-labelledby\": ariaLabelledBy,\n ...rootProps\n}: RadioGroupProps): ReactElement => {\n const generatedId = useId();\n const groupId = id ?? generatedId;\n\n const descriptionId =\n description != null ? `${groupId}-description` : undefined;\n\n const errorState = resolveRadioGroupError(error, invalid);\n\n const errorId = errorState.hasError ? `${groupId}-error` : undefined;\n\n const describedBy = mergeDescribedBy(ariaDescribedBy, descriptionId, errorId);\n\n const groupName = name?.trim() || undefined;\n\n const [uncontrolledValue, setUncontrolledValue] = useState<\n string | undefined\n >(() => defaultValue);\n\n const isControlled = value !== undefined;\n\n const selectedValue = isControlled ? (value ?? undefined) : uncontrolledValue;\n\n const radioElements = getRadioElements(children);\n\n const seenValues = new Set<string>();\n\n for (const radio of radioElements) {\n const radioValue = radio.props.value;\n\n if (seenValues.has(radioValue)) {\n throw new Error(\"RadioGroup radio values must be unique.\");\n }\n\n seenValues.add(radioValue);\n }\n\n const firstEnabledValue = radioElements.find(\n (radio) => !disabled && !radio.props.disabled,\n )?.props.value;\n\n const selectedFocusValue =\n radioElements.find(\n (radio) =>\n radio.props.value === selectedValue &&\n !disabled &&\n !radio.props.disabled,\n )?.props.value ?? firstEnabledValue;\n\n const focusItems = radioElements.map((radio) => ({\n id: radio.props.value,\n disabled: disabled || radio.props.disabled,\n }));\n\n const rovingFocus = useRovingFocus<HTMLInputElement>({\n items: focusItems,\n orientation,\n dir,\n loop,\n initialActiveId: selectedFocusValue,\n });\n\n useEffect(() => {\n if (selectedFocusValue !== undefined) {\n rovingFocus.onItemFocus(selectedFocusValue);\n }\n }, [selectedFocusValue, rovingFocus.onItemFocus]);\n\n const keyboardNavigationRef = useRef(false);\n\n const selectValue = useCallback(\n (nextValue: string) => {\n if (selectedValue === nextValue) {\n return;\n }\n\n if (!isControlled) {\n setUncontrolledValue(nextValue);\n }\n\n onValueChange?.(nextValue);\n },\n [isControlled, onValueChange, selectedValue],\n );\n\n const contextValue: RadioGroupContextValue = {\n value: selectedValue,\n name: groupName,\n form,\n disabled,\n required,\n requiredValue: firstEnabledValue,\n orientation,\n size,\n invalid: errorState.isInvalid,\n describedBy,\n keyboardNavigationRef,\n rovingFocus,\n selectValue,\n };\n\n return (\n <RadioGroupContext.Provider value={contextValue}>\n <fieldset\n {...rootProps}\n id={groupId}\n form={form}\n disabled={disabled}\n className={cn(\"puzzle-radio-group\", className)}\n style={style}\n role={role ?? \"radiogroup\"}\n dir={dir}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={describedBy}\n aria-invalid={errorState.isInvalid ? true : ariaInvalid}\n aria-required={required || undefined}\n aria-disabled={disabled || undefined}\n data-orientation={orientation}\n data-disabled={disabled ? \"true\" : undefined}\n data-invalid={errorState.isInvalid ? \"true\" : undefined}\n data-size={size}\n >\n {label != null && (\n <legend\n id={`${groupId}-label`}\n className=\"puzzle-radio-group__legend\"\n >\n {label}\n\n {required && (\n <span className=\"puzzle-radio-group__required\" aria-hidden=\"true\">\n *\n </span>\n )}\n </legend>\n )}\n\n <div\n className=\"puzzle-radio-group__options\"\n data-orientation={orientation}\n >\n {children}\n </div>\n\n {description != null && (\n <div id={descriptionId} className=\"puzzle-radio-group__description\">\n {description}\n </div>\n )}\n\n {errorState.hasError && (\n <div\n id={errorId}\n className=\"puzzle-radio-group__error\"\n role=\"alert\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {errorState.errorContent}\n </div>\n )}\n </fieldset>\n </RadioGroupContext.Provider>\n );\n};\n\nconst RadioGroup = RadioGroupRoot;\n\nexport {\n RadioGroup,\n Radio,\n type RadioGroupProps,\n type RadioProps,\n type RadioGroupOrientation,\n type RadioGroupSize,\n};\n"],"mappings":";;;;;;;;AAkDA,MAAM,qBAAA,GAAoBA,MAAAA,cAAAA,CAA6C,IAAI;AAE3E,MAAM,6BAA6B;CACjC,MAAM,WAAA,GAAUC,MAAAA,WAAAA,CAAW,iBAAiB;CAE5C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,6CAA6C;CAG/D,OAAO;AACT;AAEA,MAAM,SAAS,EACb,OACA,OACA,UACA,aACA,WAAW,OACX,WACA,OACA,IACA,KACA,UACA,SACA,WACA,oBAAoB,iBACpB,gBAAgB,aAChB,GAAG,iBACa;CAChB,MAAM,UAAU,qBAAqB;CAErC,MAAM,eAAA,GAAcC,MAAAA,MAAAA,CAAM;CAC1B,MAAM,UAAU,MAAM;CAEtB,MAAM,gBACJ,eAAe,OAAO,GAAG,QAAQ,gBAAgB,KAAA;CAEnD,MAAM,aAAa,SAAS;CAC5B,MAAM,UAAU,cAAc,OAAO,GAAG,QAAQ,UAAU,KAAA;CAE1D,MAAM,aAAa,QAAQ,YAAY;CACvC,MAAM,aAAa,QAAQ,UAAU;CAErC,MAAM,aACJ,QAAQ,QAAQ,IAAI,KACpB,QAAQ,YACR,QAAQ,kBAAkB;CAE5B,MAAM,cAAcC,0BAAAA,iBAClB,QAAQ,aACR,iBACA,aACF;CAEA,MAAM,YAAY,QAAQ,YAAY,WAAW,KAAK;CAEtD,MAAM,eAAA,GAAcC,MAAAA,YAAAA,EACjB,SAAkC;EACjC,UAAU,IAAI;EAEd,IAAI,OAAO,QAAQ,YACjB,IAAI,IAAI;OACH,IAAI,KACT,IAAI,UAAU;CAElB,GACA,CAAC,KAAK,SAAS,CACjB;CAEA,MAAM,eAAe,UAAwC;EAC3D,QAAQ,YAAY,YAAY,KAAK;EAErC,IAAI,QAAQ,sBA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A,MAAM,aAAa"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RadioGroupOrientation, RadioGroupProps, RadioGroupSize, RadioProps } from "./radio-group.types.cjs";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
declare const Radio: ({ value, label, children, description, disabled, className, style, id, ref, onChange, onFocus, onKeyDown, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...inputProps }: RadioProps) => import("react").JSX.Element;
|
|
4
|
+
declare const RadioGroup: ({ value, defaultValue, onValueChange, name, form, label, description, error, invalid, required, disabled, orientation, size, dir, loop, children, id, className, style, role, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-labelledby": ariaLabelledBy, ...rootProps }: RadioGroupProps) => ReactElement;
|
|
5
|
+
export { Radio, RadioGroup, type RadioGroupOrientation, type RadioGroupProps, type RadioGroupSize, type RadioProps };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RadioGroupOrientation, RadioGroupProps, RadioGroupSize, RadioProps } from "./radio-group.types.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
declare const Radio: ({ value, label, children, description, disabled, className, style, id, ref, onChange, onFocus, onKeyDown, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...inputProps }: RadioProps) => import("react").JSX.Element;
|
|
4
|
+
declare const RadioGroup: ({ value, defaultValue, onValueChange, name, form, label, description, error, invalid, required, disabled, orientation, size, dir, loop, children, id, className, style, role, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-labelledby": ariaLabelledBy, ...rootProps }: RadioGroupProps) => ReactElement;
|
|
5
|
+
export { Radio, RadioGroup, type RadioGroupOrientation, type RadioGroupProps, type RadioGroupSize, type RadioProps };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { mergeDescribedBy, resolveRadioGroupError } from "./radio-group.utils.js";
|
|
3
|
+
import "./radio-group.css";
|
|
4
|
+
import { cn } from "@puzzle-ui/core";
|
|
5
|
+
import { Children, Fragment, createContext, isValidElement, useCallback, useContext, useEffect, useId, useRef, useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useRovingFocus } from "@puzzle-ui/hooks";
|
|
8
|
+
// src/components/forms/radio-group/index.tsx
|
|
9
|
+
const RadioGroupContext = createContext(null);
|
|
10
|
+
const useRadioGroupContext = () => {
|
|
11
|
+
const context = useContext(RadioGroupContext);
|
|
12
|
+
if (!context) throw new Error("Radio must be rendered inside a RadioGroup.");
|
|
13
|
+
return context;
|
|
14
|
+
};
|
|
15
|
+
const Radio = ({ value, label, children, description, disabled = false, className, style, id, ref, onChange, onFocus, onKeyDown, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...inputProps }) => {
|
|
16
|
+
const context = useRadioGroupContext();
|
|
17
|
+
const generatedId = useId();
|
|
18
|
+
const inputId = id ?? generatedId;
|
|
19
|
+
const descriptionId = description != null ? `${inputId}-description` : void 0;
|
|
20
|
+
const radioLabel = label ?? children;
|
|
21
|
+
const labelId = radioLabel != null ? `${inputId}-label` : void 0;
|
|
22
|
+
const isDisabled = context.disabled || disabled;
|
|
23
|
+
const isSelected = context.value === value;
|
|
24
|
+
const isRequired = Boolean(context.name) && context.required && context.requiredValue === value;
|
|
25
|
+
const describedBy = mergeDescribedBy(context.describedBy, ariaDescribedBy, descriptionId);
|
|
26
|
+
const rovingRef = context.rovingFocus.getItemRef(value);
|
|
27
|
+
const setInputRef = useCallback((node) => {
|
|
28
|
+
rovingRef(node);
|
|
29
|
+
if (typeof ref === "function") ref(node);
|
|
30
|
+
else if (ref) ref.current = node;
|
|
31
|
+
}, [ref, rovingRef]);
|
|
32
|
+
const handleFocus = (event) => {
|
|
33
|
+
context.rovingFocus.onItemFocus(value);
|
|
34
|
+
if (context.keyboardNavigationRef.current) {
|
|
35
|
+
context.keyboardNavigationRef.current = false;
|
|
36
|
+
context.selectValue(value);
|
|
37
|
+
}
|
|
38
|
+
onFocus?.(event);
|
|
39
|
+
};
|
|
40
|
+
const handleKeyDown = (event) => {
|
|
41
|
+
onKeyDown?.(event);
|
|
42
|
+
if (event.defaultPrevented || isDisabled) return;
|
|
43
|
+
const isHorizontalArrow = event.key === "ArrowLeft" || event.key === "ArrowRight";
|
|
44
|
+
const isVerticalArrow = event.key === "ArrowUp" || event.key === "ArrowDown";
|
|
45
|
+
const isArrowKey = isHorizontalArrow || isVerticalArrow;
|
|
46
|
+
const isSupportedArrow = context.orientation === "horizontal" ? isHorizontalArrow : isVerticalArrow;
|
|
47
|
+
if (isArrowKey && !isSupportedArrow) {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const activeElement = event.currentTarget.ownerDocument.activeElement;
|
|
52
|
+
context.keyboardNavigationRef.current = true;
|
|
53
|
+
context.rovingFocus.onItemKeyDown(event, value);
|
|
54
|
+
if (event.currentTarget.ownerDocument.activeElement === activeElement) context.keyboardNavigationRef.current = false;
|
|
55
|
+
};
|
|
56
|
+
const handleChange = (event) => {
|
|
57
|
+
onChange?.(event);
|
|
58
|
+
if (!event.defaultPrevented) context.selectValue(value);
|
|
59
|
+
};
|
|
60
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
61
|
+
className: cn("puzzle-radio", `puzzle-radio--${context.size}`, isSelected && "puzzle-radio--checked", isDisabled && "puzzle-radio--disabled", className),
|
|
62
|
+
style,
|
|
63
|
+
"data-state": isSelected ? "checked" : "unchecked",
|
|
64
|
+
"data-disabled": isDisabled ? "true" : void 0,
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ jsx("input", {
|
|
67
|
+
...inputProps,
|
|
68
|
+
ref: setInputRef,
|
|
69
|
+
id: inputId,
|
|
70
|
+
className: "puzzle-radio__input",
|
|
71
|
+
type: "radio",
|
|
72
|
+
name: context.name,
|
|
73
|
+
form: context.form,
|
|
74
|
+
value,
|
|
75
|
+
checked: isSelected,
|
|
76
|
+
disabled: isDisabled,
|
|
77
|
+
required: isRequired,
|
|
78
|
+
tabIndex: context.rovingFocus.getItemTabIndex(value, isDisabled),
|
|
79
|
+
"aria-labelledby": inputProps["aria-labelledby"] ?? (inputProps["aria-label"] ? void 0 : labelId),
|
|
80
|
+
"aria-describedby": describedBy,
|
|
81
|
+
"aria-invalid": context.invalid ? true : ariaInvalid,
|
|
82
|
+
"data-state": isSelected ? "checked" : "unchecked",
|
|
83
|
+
onChange: handleChange,
|
|
84
|
+
onFocus: handleFocus,
|
|
85
|
+
onKeyDown: handleKeyDown
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ jsx("span", {
|
|
88
|
+
className: "puzzle-radio__control",
|
|
89
|
+
"aria-hidden": "true"
|
|
90
|
+
}),
|
|
91
|
+
(radioLabel != null || description != null) && /* @__PURE__ */ jsxs("span", {
|
|
92
|
+
className: "puzzle-radio__content",
|
|
93
|
+
children: [radioLabel != null && /* @__PURE__ */ jsx("span", {
|
|
94
|
+
id: labelId,
|
|
95
|
+
className: "puzzle-radio__label",
|
|
96
|
+
children: radioLabel
|
|
97
|
+
}), description != null && /* @__PURE__ */ jsx("span", {
|
|
98
|
+
id: descriptionId,
|
|
99
|
+
className: "puzzle-radio__description",
|
|
100
|
+
children: description
|
|
101
|
+
})]
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const isRadioElement = (child) => isValidElement(child) && child.type === Radio;
|
|
107
|
+
const getRadioElements = (children) => Children.toArray(children).flatMap((child) => {
|
|
108
|
+
if (isValidElement(child) && child.type === Fragment) return getRadioElements(child.props.children);
|
|
109
|
+
return isRadioElement(child) ? [child] : [];
|
|
110
|
+
});
|
|
111
|
+
const RadioGroupRoot = ({ value, defaultValue, onValueChange, name, form, label, description, error, invalid, required = false, disabled = false, orientation = "vertical", size = "md", dir = "ltr", loop = true, children, id, className, style, role, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-labelledby": ariaLabelledBy, ...rootProps }) => {
|
|
112
|
+
const generatedId = useId();
|
|
113
|
+
const groupId = id ?? generatedId;
|
|
114
|
+
const descriptionId = description != null ? `${groupId}-description` : void 0;
|
|
115
|
+
const errorState = resolveRadioGroupError(error, invalid);
|
|
116
|
+
const errorId = errorState.hasError ? `${groupId}-error` : void 0;
|
|
117
|
+
const describedBy = mergeDescribedBy(ariaDescribedBy, descriptionId, errorId);
|
|
118
|
+
const groupName = name?.trim() || void 0;
|
|
119
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(() => defaultValue);
|
|
120
|
+
const isControlled = value !== void 0;
|
|
121
|
+
const selectedValue = isControlled ? value ?? void 0 : uncontrolledValue;
|
|
122
|
+
const radioElements = getRadioElements(children);
|
|
123
|
+
const seenValues = /* @__PURE__ */ new Set();
|
|
124
|
+
for (const radio of radioElements) {
|
|
125
|
+
const radioValue = radio.props.value;
|
|
126
|
+
if (seenValues.has(radioValue)) throw new Error("RadioGroup radio values must be unique.");
|
|
127
|
+
seenValues.add(radioValue);
|
|
128
|
+
}
|
|
129
|
+
const firstEnabledValue = radioElements.find((radio) => !disabled && !radio.props.disabled)?.props.value;
|
|
130
|
+
const selectedFocusValue = radioElements.find((radio) => radio.props.value === selectedValue && !disabled && !radio.props.disabled)?.props.value ?? firstEnabledValue;
|
|
131
|
+
const focusItems = radioElements.map((radio) => ({
|
|
132
|
+
id: radio.props.value,
|
|
133
|
+
disabled: disabled || radio.props.disabled
|
|
134
|
+
}));
|
|
135
|
+
const rovingFocus = useRovingFocus({
|
|
136
|
+
items: focusItems,
|
|
137
|
+
orientation,
|
|
138
|
+
dir,
|
|
139
|
+
loop,
|
|
140
|
+
initialActiveId: selectedFocusValue
|
|
141
|
+
});
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (selectedFocusValue !== void 0) rovingFocus.onItemFocus(selectedFocusValue);
|
|
144
|
+
}, [selectedFocusValue, rovingFocus.onItemFocus]);
|
|
145
|
+
const keyboardNavigationRef = useRef(false);
|
|
146
|
+
const selectValue = useCallback((nextValue) => {
|
|
147
|
+
if (selectedValue === nextValue) return;
|
|
148
|
+
if (!isControlled) setUncontrolledValue(nextValue);
|
|
149
|
+
onValueChange?.(nextValue);
|
|
150
|
+
}, [
|
|
151
|
+
isControlled,
|
|
152
|
+
onValueChange,
|
|
153
|
+
selectedValue
|
|
154
|
+
]);
|
|
155
|
+
const contextValue = {
|
|
156
|
+
value: selectedValue,
|
|
157
|
+
name: groupName,
|
|
158
|
+
form,
|
|
159
|
+
disabled,
|
|
160
|
+
required,
|
|
161
|
+
requiredValue: firstEnabledValue,
|
|
162
|
+
orientation,
|
|
163
|
+
size,
|
|
164
|
+
invalid: errorState.isInvalid,
|
|
165
|
+
describedBy,
|
|
166
|
+
keyboardNavigationRef,
|
|
167
|
+
rovingFocus,
|
|
168
|
+
selectValue
|
|
169
|
+
};
|
|
170
|
+
return /* @__PURE__ */ jsx(RadioGroupContext.Provider, {
|
|
171
|
+
value: contextValue,
|
|
172
|
+
children: /* @__PURE__ */ jsxs("fieldset", {
|
|
173
|
+
...rootProps,
|
|
174
|
+
id: groupId,
|
|
175
|
+
form,
|
|
176
|
+
disabled,
|
|
177
|
+
className: cn("puzzle-radio-group", className),
|
|
178
|
+
style,
|
|
179
|
+
role: role ?? "radiogroup",
|
|
180
|
+
dir,
|
|
181
|
+
"aria-labelledby": ariaLabelledBy,
|
|
182
|
+
"aria-describedby": describedBy,
|
|
183
|
+
"aria-invalid": errorState.isInvalid ? true : ariaInvalid,
|
|
184
|
+
"aria-required": required || void 0,
|
|
185
|
+
"aria-disabled": disabled || void 0,
|
|
186
|
+
"data-orientation": orientation,
|
|
187
|
+
"data-disabled": disabled ? "true" : void 0,
|
|
188
|
+
"data-invalid": errorState.isInvalid ? "true" : void 0,
|
|
189
|
+
"data-size": size,
|
|
190
|
+
children: [
|
|
191
|
+
label != null && /* @__PURE__ */ jsxs("legend", {
|
|
192
|
+
id: `${groupId}-label`,
|
|
193
|
+
className: "puzzle-radio-group__legend",
|
|
194
|
+
children: [label, required && /* @__PURE__ */ jsx("span", {
|
|
195
|
+
className: "puzzle-radio-group__required",
|
|
196
|
+
"aria-hidden": "true",
|
|
197
|
+
children: "*"
|
|
198
|
+
})]
|
|
199
|
+
}),
|
|
200
|
+
/* @__PURE__ */ jsx("div", {
|
|
201
|
+
className: "puzzle-radio-group__options",
|
|
202
|
+
"data-orientation": orientation,
|
|
203
|
+
children
|
|
204
|
+
}),
|
|
205
|
+
description != null && /* @__PURE__ */ jsx("div", {
|
|
206
|
+
id: descriptionId,
|
|
207
|
+
className: "puzzle-radio-group__description",
|
|
208
|
+
children: description
|
|
209
|
+
}),
|
|
210
|
+
errorState.hasError && /* @__PURE__ */ jsx("div", {
|
|
211
|
+
id: errorId,
|
|
212
|
+
className: "puzzle-radio-group__error",
|
|
213
|
+
role: "alert",
|
|
214
|
+
"aria-live": "polite",
|
|
215
|
+
"aria-atomic": "true",
|
|
216
|
+
children: errorState.errorContent
|
|
217
|
+
})
|
|
218
|
+
]
|
|
219
|
+
})
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
const RadioGroup = RadioGroupRoot;
|
|
223
|
+
export { Radio, RadioGroup };
|
|
224
|
+
|
|
225
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/components/forms/radio-group/index.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n Children,\n Fragment,\n createContext,\n isValidElement,\n useCallback,\n useContext,\n useEffect,\n useId,\n useRef,\n useState,\n type ChangeEvent,\n type FocusEvent,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n} from \"react\";\n\nimport { cn } from \"@puzzle-ui/core\";\nimport { useRovingFocus, type UseRovingFocusReturn } from \"@puzzle-ui/hooks\";\n\nimport type {\n RadioGroupOrientation,\n RadioGroupProps,\n RadioGroupSize,\n RadioProps,\n} from \"./radio-group.types\";\n\nimport { mergeDescribedBy, resolveRadioGroupError } from \"./radio-group.utils\";\n\nimport \"./radio-group.css\";\n\ntype RadioGroupContextValue = {\n value: string | undefined;\n name: string | undefined;\n form: string | undefined;\n disabled: boolean;\n required: boolean;\n requiredValue: string | undefined;\n orientation: RadioGroupOrientation;\n size: RadioGroupSize;\n invalid: boolean;\n describedBy: string | undefined;\n keyboardNavigationRef: { current: boolean };\n rovingFocus: UseRovingFocusReturn<HTMLInputElement>;\n selectValue: (value: string) => void;\n};\n\nconst RadioGroupContext = createContext<RadioGroupContextValue | null>(null);\n\nconst useRadioGroupContext = () => {\n const context = useContext(RadioGroupContext);\n\n if (!context) {\n throw new Error(\"Radio must be rendered inside a RadioGroup.\");\n }\n\n return context;\n};\n\nconst Radio = ({\n value,\n label,\n children,\n description,\n disabled = false,\n className,\n style,\n id,\n ref,\n onChange,\n onFocus,\n onKeyDown,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n ...inputProps\n}: RadioProps) => {\n const context = useRadioGroupContext();\n\n const generatedId = useId();\n const inputId = id ?? generatedId;\n\n const descriptionId =\n description != null ? `${inputId}-description` : undefined;\n\n const radioLabel = label ?? children;\n const labelId = radioLabel != null ? `${inputId}-label` : undefined;\n\n const isDisabled = context.disabled || disabled;\n const isSelected = context.value === value;\n\n const isRequired =\n Boolean(context.name) &&\n context.required &&\n context.requiredValue === value;\n\n const describedBy = mergeDescribedBy(\n context.describedBy,\n ariaDescribedBy,\n descriptionId,\n );\n\n const rovingRef = context.rovingFocus.getItemRef(value);\n\n const setInputRef = useCallback(\n (node: HTMLInputElement | null) => {\n rovingRef(node);\n\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n },\n [ref, rovingRef],\n );\n\n const handleFocus = (event: FocusEvent<HTMLInputElement>) => {\n context.rovingFocus.onItemFocus(value);\n\n if (context.keyboardNavigationRef.current) {\n context.keyboardNavigationRef.current = false;\n context.selectValue(value);\n }\n\n onFocus?.(event);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event);\n\n if (event.defaultPrevented || isDisabled) {\n return;\n }\n\n const isHorizontalArrow =\n event.key === \"ArrowLeft\" || event.key === \"ArrowRight\";\n\n const isVerticalArrow =\n event.key === \"ArrowUp\" || event.key === \"ArrowDown\";\n\n const isArrowKey = isHorizontalArrow || isVerticalArrow;\n\n const isSupportedArrow =\n context.orientation === \"horizontal\"\n ? isHorizontalArrow\n : isVerticalArrow;\n\n // Prevent the browser's native radio navigation from\n // moving focus in the wrong orientation.\n if (isArrowKey && !isSupportedArrow) {\n event.preventDefault();\n return;\n }\n\n const activeElement = event.currentTarget.ownerDocument.activeElement;\n\n context.keyboardNavigationRef.current = true;\n\n context.rovingFocus.onItemKeyDown(event, value);\n\n // The focus event normally consumes this flag. If focus\n // did not change (e.g. one-item group), clear it here.\n if (event.currentTarget.ownerDocument.activeElement === activeElement) {\n context.keyboardNavigationRef.current = false;\n }\n };\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n\n if (!event.defaultPrevented) {\n context.selectValue(value);\n }\n };\n\n return (\n <label\n className={cn(\n \"puzzle-radio\",\n `puzzle-radio--${context.size}`,\n isSelected && \"puzzle-radio--checked\",\n isDisabled && \"puzzle-radio--disabled\",\n className,\n )}\n style={style}\n data-state={isSelected ? \"checked\" : \"unchecked\"}\n data-disabled={isDisabled ? \"true\" : undefined}\n >\n <input\n {...inputProps}\n ref={setInputRef}\n id={inputId}\n className=\"puzzle-radio__input\"\n type=\"radio\"\n name={context.name}\n form={context.form}\n value={value}\n checked={isSelected}\n disabled={isDisabled}\n required={isRequired}\n tabIndex={context.rovingFocus.getItemTabIndex(value, isDisabled)}\n // The wrapping label also contains the description; name the radio by\n // its label text only and expose the description via aria-describedby.\n aria-labelledby={\n inputProps[\"aria-labelledby\"] ??\n (inputProps[\"aria-label\"] ? undefined : labelId)\n }\n aria-describedby={describedBy}\n aria-invalid={context.invalid ? true : ariaInvalid}\n data-state={isSelected ? \"checked\" : \"unchecked\"}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n />\n\n <span className=\"puzzle-radio__control\" aria-hidden=\"true\" />\n\n {(radioLabel != null || description != null) && (\n <span className=\"puzzle-radio__content\">\n {radioLabel != null && (\n <span id={labelId} className=\"puzzle-radio__label\">\n {radioLabel}\n </span>\n )}\n\n {description != null && (\n <span id={descriptionId} className=\"puzzle-radio__description\">\n {description}\n </span>\n )}\n </span>\n )}\n </label>\n );\n};\n\ntype RadioElement = ReactElement<RadioProps, typeof Radio>;\n\nconst isRadioElement = (child: ReactNode): child is RadioElement =>\n isValidElement<RadioProps>(child) && child.type === Radio;\n\nconst getRadioElements = (children: ReactNode): RadioElement[] =>\n Children.toArray(children).flatMap((child): RadioElement[] => {\n if (\n isValidElement<{ children?: ReactNode }>(child) &&\n child.type === Fragment\n ) {\n return getRadioElements(child.props.children);\n }\n\n return isRadioElement(child) ? [child] : [];\n });\n\nconst RadioGroupRoot = ({\n value,\n defaultValue,\n onValueChange,\n name,\n form,\n label,\n description,\n error,\n invalid,\n required = false,\n disabled = false,\n orientation = \"vertical\",\n size = \"md\",\n dir = \"ltr\",\n loop = true,\n children,\n id,\n className,\n style,\n role,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n \"aria-labelledby\": ariaLabelledBy,\n ...rootProps\n}: RadioGroupProps): ReactElement => {\n const generatedId = useId();\n const groupId = id ?? generatedId;\n\n const descriptionId =\n description != null ? `${groupId}-description` : undefined;\n\n const errorState = resolveRadioGroupError(error, invalid);\n\n const errorId = errorState.hasError ? `${groupId}-error` : undefined;\n\n const describedBy = mergeDescribedBy(ariaDescribedBy, descriptionId, errorId);\n\n const groupName = name?.trim() || undefined;\n\n const [uncontrolledValue, setUncontrolledValue] = useState<\n string | undefined\n >(() => defaultValue);\n\n const isControlled = value !== undefined;\n\n const selectedValue = isControlled ? (value ?? undefined) : uncontrolledValue;\n\n const radioElements = getRadioElements(children);\n\n const seenValues = new Set<string>();\n\n for (const radio of radioElements) {\n const radioValue = radio.props.value;\n\n if (seenValues.has(radioValue)) {\n throw new Error(\"RadioGroup radio values must be unique.\");\n }\n\n seenValues.add(radioValue);\n }\n\n const firstEnabledValue = radioElements.find(\n (radio) => !disabled && !radio.props.disabled,\n )?.props.value;\n\n const selectedFocusValue =\n radioElements.find(\n (radio) =>\n radio.props.value === selectedValue &&\n !disabled &&\n !radio.props.disabled,\n )?.props.value ?? firstEnabledValue;\n\n const focusItems = radioElements.map((radio) => ({\n id: radio.props.value,\n disabled: disabled || radio.props.disabled,\n }));\n\n const rovingFocus = useRovingFocus<HTMLInputElement>({\n items: focusItems,\n orientation,\n dir,\n loop,\n initialActiveId: selectedFocusValue,\n });\n\n useEffect(() => {\n if (selectedFocusValue !== undefined) {\n rovingFocus.onItemFocus(selectedFocusValue);\n }\n }, [selectedFocusValue, rovingFocus.onItemFocus]);\n\n const keyboardNavigationRef = useRef(false);\n\n const selectValue = useCallback(\n (nextValue: string) => {\n if (selectedValue === nextValue) {\n return;\n }\n\n if (!isControlled) {\n setUncontrolledValue(nextValue);\n }\n\n onValueChange?.(nextValue);\n },\n [isControlled, onValueChange, selectedValue],\n );\n\n const contextValue: RadioGroupContextValue = {\n value: selectedValue,\n name: groupName,\n form,\n disabled,\n required,\n requiredValue: firstEnabledValue,\n orientation,\n size,\n invalid: errorState.isInvalid,\n describedBy,\n keyboardNavigationRef,\n rovingFocus,\n selectValue,\n };\n\n return (\n <RadioGroupContext.Provider value={contextValue}>\n <fieldset\n {...rootProps}\n id={groupId}\n form={form}\n disabled={disabled}\n className={cn(\"puzzle-radio-group\", className)}\n style={style}\n role={role ?? \"radiogroup\"}\n dir={dir}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={describedBy}\n aria-invalid={errorState.isInvalid ? true : ariaInvalid}\n aria-required={required || undefined}\n aria-disabled={disabled || undefined}\n data-orientation={orientation}\n data-disabled={disabled ? \"true\" : undefined}\n data-invalid={errorState.isInvalid ? \"true\" : undefined}\n data-size={size}\n >\n {label != null && (\n <legend\n id={`${groupId}-label`}\n className=\"puzzle-radio-group__legend\"\n >\n {label}\n\n {required && (\n <span className=\"puzzle-radio-group__required\" aria-hidden=\"true\">\n *\n </span>\n )}\n </legend>\n )}\n\n <div\n className=\"puzzle-radio-group__options\"\n data-orientation={orientation}\n >\n {children}\n </div>\n\n {description != null && (\n <div id={descriptionId} className=\"puzzle-radio-group__description\">\n {description}\n </div>\n )}\n\n {errorState.hasError && (\n <div\n id={errorId}\n className=\"puzzle-radio-group__error\"\n role=\"alert\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {errorState.errorContent}\n </div>\n )}\n </fieldset>\n </RadioGroupContext.Provider>\n );\n};\n\nconst RadioGroup = RadioGroupRoot;\n\nexport {\n RadioGroup,\n Radio,\n type RadioGroupProps,\n type RadioProps,\n type RadioGroupOrientation,\n type RadioGroupSize,\n};\n"],"mappings":";;;;;;;;AAkDA,MAAM,oBAAoB,cAA6C,IAAI;AAE3E,MAAM,6BAA6B;CACjC,MAAM,UAAU,WAAW,iBAAiB;CAE5C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,6CAA6C;CAG/D,OAAO;AACT;AAEA,MAAM,SAAS,EACb,OACA,OACA,UACA,aACA,WAAW,OACX,WACA,OACA,IACA,KACA,UACA,SACA,WACA,oBAAoB,iBACpB,gBAAgB,aAChB,GAAG,iBACa;CAChB,MAAM,UAAU,qBAAqB;CAErC,MAAM,cAAc,MAAM;CAC1B,MAAM,UAAU,MAAM;CAEtB,MAAM,gBACJ,eAAe,OAAO,GAAG,QAAQ,gBAAgB,KAAA;CAEnD,MAAM,aAAa,SAAS;CAC5B,MAAM,UAAU,cAAc,OAAO,GAAG,QAAQ,UAAU,KAAA;CAE1D,MAAM,aAAa,QAAQ,YAAY;CACvC,MAAM,aAAa,QAAQ,UAAU;CAErC,MAAM,aACJ,QAAQ,QAAQ,IAAI,KACp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