@masaraxui/react 1.0.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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/components/accordion/accordion.d.ts +30 -0
- package/dist/components/accordion/accordion.js +191 -0
- package/dist/components/accordion/index.d.ts +25 -0
- package/dist/components/accordion/index.js +18 -0
- package/dist/components/alert/alert.d.ts +15 -0
- package/dist/components/alert/alert.js +152 -0
- package/dist/components/alert/index.d.ts +21 -0
- package/dist/components/alert/index.js +16 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +65 -0
- package/dist/components/alert-dialog/alert-dialog.js +309 -0
- package/dist/components/alert-dialog/index.d.ts +33 -0
- package/dist/components/alert-dialog/index.js +22 -0
- package/dist/components/autocomplete/autocomplete.d.ts +31 -0
- package/dist/components/autocomplete/autocomplete.js +241 -0
- package/dist/components/autocomplete/index.d.ts +25 -0
- package/dist/components/autocomplete/index.js +18 -0
- package/dist/components/avatar/avatar.d.ts +15 -0
- package/dist/components/avatar/avatar.js +93 -0
- package/dist/components/avatar/index.d.ts +17 -0
- package/dist/components/avatar/index.js +14 -0
- package/dist/components/badge/badge.d.ts +19 -0
- package/dist/components/badge/badge.js +87 -0
- package/dist/components/badge/index.d.ts +17 -0
- package/dist/components/badge/index.js +14 -0
- package/dist/components/breadcrumbs/breadcrumbs.d.ts +14 -0
- package/dist/components/breadcrumbs/breadcrumbs.js +84 -0
- package/dist/components/breadcrumbs/index.d.ts +15 -0
- package/dist/components/breadcrumbs/index.js +13 -0
- package/dist/components/button/button.d.ts +10 -0
- package/dist/components/button/button.js +49 -0
- package/dist/components/button/index.d.ts +15 -0
- package/dist/components/button/index.js +13 -0
- package/dist/components/button-group/button-group.d.ts +26 -0
- package/dist/components/button-group/button-group.js +82 -0
- package/dist/components/button-group/index.d.ts +16 -0
- package/dist/components/button-group/index.js +14 -0
- package/dist/components/calendar/calendar.d.ts +71 -0
- package/dist/components/calendar/calendar.js +283 -0
- package/dist/components/calendar/index.d.ts +91 -0
- package/dist/components/calendar/index.js +29 -0
- package/dist/components/calendar-year-picker/calendar-year-picker.d.ts +61 -0
- package/dist/components/calendar-year-picker/calendar-year-picker.js +411 -0
- package/dist/components/calendar-year-picker/index.d.ts +43 -0
- package/dist/components/calendar-year-picker/index.js +18 -0
- package/dist/components/calendar-year-picker/year-picker-context.d.ts +28 -0
- package/dist/components/calendar-year-picker/year-picker-context.js +39 -0
- package/dist/components/card/card.d.ts +22 -0
- package/dist/components/card/card.js +141 -0
- package/dist/components/card/index.d.ts +23 -0
- package/dist/components/card/index.js +17 -0
- package/dist/components/checkbox/checkbox.d.ts +22 -0
- package/dist/components/checkbox/checkbox.js +124 -0
- package/dist/components/checkbox/index.d.ts +19 -0
- package/dist/components/checkbox/index.js +15 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts +14 -0
- package/dist/components/checkbox-group/checkbox-group.js +33 -0
- package/dist/components/checkbox-group/index.d.ts +3 -0
- package/dist/components/checkbox-group/index.js +3 -0
- package/dist/components/chip/chip.d.ts +14 -0
- package/dist/components/chip/chip.js +67 -0
- package/dist/components/chip/index.d.ts +15 -0
- package/dist/components/chip/index.js +13 -0
- package/dist/components/close-button/close-button.d.ts +8 -0
- package/dist/components/close-button/close-button.js +33 -0
- package/dist/components/close-button/index.d.ts +13 -0
- package/dist/components/close-button/index.js +12 -0
- package/dist/components/color-area/color-area.d.ts +11 -0
- package/dist/components/color-area/color-area.js +70 -0
- package/dist/components/color-area/index.d.ts +15 -0
- package/dist/components/color-area/index.js +13 -0
- package/dist/components/color-field/color-field.d.ts +9 -0
- package/dist/components/color-field/color-field.js +29 -0
- package/dist/components/color-field/index.d.ts +22 -0
- package/dist/components/color-field/index.js +18 -0
- package/dist/components/color-input-group/color-input-group.d.ts +19 -0
- package/dist/components/color-input-group/color-input-group.js +98 -0
- package/dist/components/color-input-group/index.d.ts +19 -0
- package/dist/components/color-input-group/index.js +15 -0
- package/dist/components/color-picker/color-picker.d.ts +21 -0
- package/dist/components/color-picker/color-picker.js +86 -0
- package/dist/components/color-picker/index.d.ts +17 -0
- package/dist/components/color-picker/index.js +14 -0
- package/dist/components/color-slider/color-slider.d.ts +50 -0
- package/dist/components/color-slider/color-slider.js +205 -0
- package/dist/components/color-slider/index.d.ts +19 -0
- package/dist/components/color-slider/index.js +15 -0
- package/dist/components/color-swatch/color-swatch.d.ts +8 -0
- package/dist/components/color-swatch/color-swatch.js +31 -0
- package/dist/components/color-swatch/index.d.ts +13 -0
- package/dist/components/color-swatch/index.js +12 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.d.ts +20 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.js +149 -0
- package/dist/components/color-swatch-picker/index.d.ts +19 -0
- package/dist/components/color-swatch-picker/index.js +15 -0
- package/dist/components/combo-box/combo-box.d.ts +34 -0
- package/dist/components/combo-box/combo-box.js +116 -0
- package/dist/components/combo-box/index.d.ts +20 -0
- package/dist/components/combo-box/index.js +16 -0
- package/dist/components/date-field/date-field.d.ts +9 -0
- package/dist/components/date-field/date-field.js +29 -0
- package/dist/components/date-field/index.d.ts +26 -0
- package/dist/components/date-field/index.js +20 -0
- package/dist/components/date-input-group/date-input-group.d.ts +25 -0
- package/dist/components/date-input-group/date-input-group.js +146 -0
- package/dist/components/date-input-group/index.d.ts +23 -0
- package/dist/components/date-input-group/index.js +17 -0
- package/dist/components/date-picker/date-picker.d.ts +30 -0
- package/dist/components/date-picker/date-picker.js +151 -0
- package/dist/components/date-picker/index.d.ts +31 -0
- package/dist/components/date-picker/index.js +15 -0
- package/dist/components/date-range-picker/date-range-picker.d.ts +36 -0
- package/dist/components/date-range-picker/date-range-picker.js +173 -0
- package/dist/components/date-range-picker/index.d.ts +36 -0
- package/dist/components/date-range-picker/index.js +16 -0
- package/dist/components/description/description.d.ts +9 -0
- package/dist/components/description/description.js +22 -0
- package/dist/components/description/index.d.ts +13 -0
- package/dist/components/description/index.js +12 -0
- package/dist/components/disclosure/disclosure.d.ts +27 -0
- package/dist/components/disclosure/disclosure.js +157 -0
- package/dist/components/disclosure/index.d.ts +23 -0
- package/dist/components/disclosure/index.js +17 -0
- package/dist/components/disclosure-group/disclosure-group.d.ts +8 -0
- package/dist/components/disclosure-group/disclosure-group.js +35 -0
- package/dist/components/disclosure-group/index.d.ts +15 -0
- package/dist/components/disclosure-group/index.js +13 -0
- package/dist/components/disclosure-group/use-disclosure-group-navigation.d.ts +14 -0
- package/dist/components/disclosure-group/use-disclosure-group-navigation.js +51 -0
- package/dist/components/drawer/drawer.d.ts +84 -0
- package/dist/components/drawer/drawer.js +439 -0
- package/dist/components/drawer/index.d.ts +69 -0
- package/dist/components/drawer/index.js +22 -0
- package/dist/components/dropdown/dropdown.d.ts +38 -0
- package/dist/components/dropdown/dropdown.js +156 -0
- package/dist/components/dropdown/index.d.ts +29 -0
- package/dist/components/dropdown/index.js +20 -0
- package/dist/components/empty-state/empty-state.d.ts +7 -0
- package/dist/components/empty-state/empty-state.js +20 -0
- package/dist/components/empty-state/index.d.ts +13 -0
- package/dist/components/empty-state/index.js +12 -0
- package/dist/components/error-message/error-message.d.ts +9 -0
- package/dist/components/error-message/error-message.js +22 -0
- package/dist/components/error-message/index.d.ts +13 -0
- package/dist/components/error-message/index.js +12 -0
- package/dist/components/field-error/field-error.d.ts +8 -0
- package/dist/components/field-error/field-error.js +21 -0
- package/dist/components/field-error/index.d.ts +13 -0
- package/dist/components/field-error/index.js +12 -0
- package/dist/components/fieldset/fieldset.d.ts +16 -0
- package/dist/components/fieldset/fieldset.js +88 -0
- package/dist/components/fieldset/index.d.ts +19 -0
- package/dist/components/fieldset/index.js +15 -0
- package/dist/components/form/form.d.ts +7 -0
- package/dist/components/form/form.js +13 -0
- package/dist/components/form/index.d.ts +11 -0
- package/dist/components/form/index.js +11 -0
- package/dist/components/header/header.d.ts +7 -0
- package/dist/components/header/header.js +21 -0
- package/dist/components/header/index.d.ts +9 -0
- package/dist/components/header/index.js +10 -0
- package/dist/components/icons.d.ts +18 -0
- package/dist/components/icons.js +243 -0
- package/dist/components/index.d.ts +84 -0
- package/dist/components/input/index.d.ts +13 -0
- package/dist/components/input/index.js +12 -0
- package/dist/components/input/input.d.ts +8 -0
- package/dist/components/input/input.js +31 -0
- package/dist/components/input-group/index.d.ts +21 -0
- package/dist/components/input-group/index.js +16 -0
- package/dist/components/input-group/input-group.d.ts +20 -0
- package/dist/components/input-group/input-group.js +129 -0
- package/dist/components/input-otp/index.d.ts +22 -0
- package/dist/components/input-otp/index.js +21 -0
- package/dist/components/input-otp/input-otp.d.ts +26 -0
- package/dist/components/input-otp/input-otp.js +139 -0
- package/dist/components/kbd/index.d.ts +19 -0
- package/dist/components/kbd/index.js +15 -0
- package/dist/components/kbd/kbd.constants.d.ts +3 -0
- package/dist/components/kbd/kbd.constants.js +51 -0
- package/dist/components/kbd/kbd.d.ts +24 -0
- package/dist/components/kbd/kbd.js +76 -0
- package/dist/components/label/index.d.ts +13 -0
- package/dist/components/label/index.js +12 -0
- package/dist/components/label/label.d.ts +8 -0
- package/dist/components/label/label.js +27 -0
- package/dist/components/link/index.d.ts +15 -0
- package/dist/components/link/index.js +13 -0
- package/dist/components/link/link.d.ts +10 -0
- package/dist/components/link/link.js +59 -0
- package/dist/components/list-box/index.d.ts +23 -0
- package/dist/components/list-box/index.js +18 -0
- package/dist/components/list-box/list-box.d.ts +9 -0
- package/dist/components/list-box/list-box.js +23 -0
- package/dist/components/list-box-item/index.d.ts +15 -0
- package/dist/components/list-box-item/index.js +13 -0
- package/dist/components/list-box-item/list-box-item.d.ts +15 -0
- package/dist/components/list-box-item/list-box-item.js +77 -0
- package/dist/components/list-box-section/index.d.ts +10 -0
- package/dist/components/list-box-section/index.js +10 -0
- package/dist/components/list-box-section/list-box-section.d.ts +8 -0
- package/dist/components/list-box-section/list-box-section.js +22 -0
- package/dist/components/menu/index.d.ts +24 -0
- package/dist/components/menu/index.js +18 -0
- package/dist/components/menu/menu.d.ts +9 -0
- package/dist/components/menu/menu.js +20 -0
- package/dist/components/menu-item/index.d.ts +17 -0
- package/dist/components/menu-item/index.js +14 -0
- package/dist/components/menu-item/menu-item.d.ts +20 -0
- package/dist/components/menu-item/menu-item.js +123 -0
- package/dist/components/menu-section/index.d.ts +10 -0
- package/dist/components/menu-section/index.js +10 -0
- package/dist/components/menu-section/menu-section.d.ts +8 -0
- package/dist/components/menu-section/menu-section.js +22 -0
- package/dist/components/meter/index.d.ts +34 -0
- package/dist/components/meter/index.js +15 -0
- package/dist/components/meter/meter.d.ts +29 -0
- package/dist/components/meter/meter.js +108 -0
- package/dist/components/modal/index.d.ts +33 -0
- package/dist/components/modal/index.js +22 -0
- package/dist/components/modal/modal.d.ts +53 -0
- package/dist/components/modal/modal.js +288 -0
- package/dist/components/number-field/index.d.ts +21 -0
- package/dist/components/number-field/index.js +16 -0
- package/dist/components/number-field/number-field.d.ts +20 -0
- package/dist/components/number-field/number-field.js +127 -0
- package/dist/components/pagination/index.d.ts +64 -0
- package/dist/components/pagination/index.js +21 -0
- package/dist/components/pagination/pagination.d.ts +84 -0
- package/dist/components/pagination/pagination.js +230 -0
- package/dist/components/popover/index.d.ts +23 -0
- package/dist/components/popover/index.js +17 -0
- package/dist/components/popover/popover.d.ts +24 -0
- package/dist/components/popover/popover.js +153 -0
- package/dist/components/progress-bar/index.d.ts +34 -0
- package/dist/components/progress-bar/index.js +15 -0
- package/dist/components/progress-bar/progress-bar.d.ts +29 -0
- package/dist/components/progress-bar/progress-bar.js +108 -0
- package/dist/components/progress-circle/index.d.ts +34 -0
- package/dist/components/progress-circle/index.js +15 -0
- package/dist/components/progress-circle/progress-circle.d.ts +29 -0
- package/dist/components/progress-circle/progress-circle.js +126 -0
- package/dist/components/rac/components.d.ts +1 -0
- package/dist/components/rac/index.d.ts +5 -0
- package/dist/components/rac/index.js +3 -0
- package/dist/components/rac/types.d.ts +3 -0
- package/dist/components/rac/utils.d.ts +1 -0
- package/dist/components/radio/index.d.ts +19 -0
- package/dist/components/radio/index.js +15 -0
- package/dist/components/radio/radio.d.ts +21 -0
- package/dist/components/radio/radio.js +97 -0
- package/dist/components/radio-group/index.d.ts +13 -0
- package/dist/components/radio-group/index.js +12 -0
- package/dist/components/radio-group/radio-group.d.ts +8 -0
- package/dist/components/radio-group/radio-group.js +27 -0
- package/dist/components/range-calendar/index.d.ts +91 -0
- package/dist/components/range-calendar/index.js +29 -0
- package/dist/components/range-calendar/range-calendar.d.ts +71 -0
- package/dist/components/range-calendar/range-calendar.js +298 -0
- package/dist/components/scroll-shadow/index.d.ts +21 -0
- package/dist/components/scroll-shadow/index.js +13 -0
- package/dist/components/scroll-shadow/scroll-shadow.d.ts +32 -0
- package/dist/components/scroll-shadow/scroll-shadow.js +76 -0
- package/dist/components/scroll-shadow/use-scroll-shadow.d.ts +11 -0
- package/dist/components/scroll-shadow/use-scroll-shadow.js +121 -0
- package/dist/components/search-field/index.d.ts +21 -0
- package/dist/components/search-field/index.js +16 -0
- package/dist/components/search-field/search-field.d.ts +23 -0
- package/dist/components/search-field/search-field.js +127 -0
- package/dist/components/select/index.d.ts +21 -0
- package/dist/components/select/index.js +16 -0
- package/dist/components/select/select.d.ts +24 -0
- package/dist/components/select/select.js +140 -0
- package/dist/components/separator/index.d.ts +13 -0
- package/dist/components/separator/index.js +12 -0
- package/dist/components/separator/separator.d.ts +8 -0
- package/dist/components/separator/separator.js +27 -0
- package/dist/components/skeleton/index.d.ts +13 -0
- package/dist/components/skeleton/index.js +12 -0
- package/dist/components/skeleton/skeleton.d.ts +7 -0
- package/dist/components/skeleton/skeleton.js +25 -0
- package/dist/components/slider/index.d.ts +23 -0
- package/dist/components/slider/index.js +17 -0
- package/dist/components/slider/slider.d.ts +23 -0
- package/dist/components/slider/slider.js +177 -0
- package/dist/components/spinner/index.d.ts +13 -0
- package/dist/components/spinner/index.js +12 -0
- package/dist/components/spinner/spinner.d.ts +7 -0
- package/dist/components/spinner/spinner.js +88 -0
- package/dist/components/surface/index.d.ts +14 -0
- package/dist/components/surface/index.js +13 -0
- package/dist/components/surface/surface.d.ts +12 -0
- package/dist/components/surface/surface.js +34 -0
- package/dist/components/switch/index.d.ts +21 -0
- package/dist/components/switch/index.js +16 -0
- package/dist/components/switch/switch.d.ts +20 -0
- package/dist/components/switch/switch.js +118 -0
- package/dist/components/switch-group/index.d.ts +13 -0
- package/dist/components/switch-group/index.js +12 -0
- package/dist/components/switch-group/switch-group.d.ts +7 -0
- package/dist/components/switch-group/switch-group.js +25 -0
- package/dist/components/table/index.d.ts +38 -0
- package/dist/components/table/index.js +25 -0
- package/dist/components/table/table.d.ts +50 -0
- package/dist/components/table/table.js +283 -0
- package/dist/components/tabs/index.d.ts +25 -0
- package/dist/components/tabs/index.js +18 -0
- package/dist/components/tabs/tabs.d.ts +37 -0
- package/dist/components/tabs/tabs.js +156 -0
- package/dist/components/tag/index.d.ts +15 -0
- package/dist/components/tag/index.js +13 -0
- package/dist/components/tag/tag.d.ts +14 -0
- package/dist/components/tag/tag.js +85 -0
- package/dist/components/tag-group/index.d.ts +15 -0
- package/dist/components/tag-group/index.js +14 -0
- package/dist/components/tag-group/tag-group.d.ts +20 -0
- package/dist/components/tag-group/tag-group.js +59 -0
- package/dist/components/text/index.d.ts +13 -0
- package/dist/components/text/index.js +12 -0
- package/dist/components/text/text.d.ts +8 -0
- package/dist/components/text/text.js +25 -0
- package/dist/components/textarea/index.d.ts +13 -0
- package/dist/components/textarea/index.js +12 -0
- package/dist/components/textarea/textarea.d.ts +8 -0
- package/dist/components/textarea/textarea.js +27 -0
- package/dist/components/textfield/index.d.ts +14 -0
- package/dist/components/textfield/index.js +13 -0
- package/dist/components/textfield/textfield.d.ts +18 -0
- package/dist/components/textfield/textfield.js +39 -0
- package/dist/components/time-field/index.d.ts +26 -0
- package/dist/components/time-field/index.js +20 -0
- package/dist/components/time-field/time-field.d.ts +9 -0
- package/dist/components/time-field/time-field.js +29 -0
- package/dist/components/toast/constants.d.ts +6 -0
- package/dist/components/toast/constants.js +15 -0
- package/dist/components/toast/index.d.ts +75 -0
- package/dist/components/toast/index.js +23 -0
- package/dist/components/toast/toast-queue.d.ts +70 -0
- package/dist/components/toast/toast-queue.js +147 -0
- package/dist/components/toast/toast.d.ts +69 -0
- package/dist/components/toast/toast.js +365 -0
- package/dist/components/toggle-button/index.d.ts +13 -0
- package/dist/components/toggle-button/index.js +12 -0
- package/dist/components/toggle-button/toggle-button.d.ts +8 -0
- package/dist/components/toggle-button/toggle-button.js +36 -0
- package/dist/components/toggle-button-group/index.d.ts +16 -0
- package/dist/components/toggle-button-group/index.js +14 -0
- package/dist/components/toggle-button-group/toggle-button-group.d.ts +25 -0
- package/dist/components/toggle-button-group/toggle-button-group.js +70 -0
- package/dist/components/toolbar/index.d.ts +19 -0
- package/dist/components/toolbar/index.js +12 -0
- package/dist/components/toolbar/toolbar.d.ts +11 -0
- package/dist/components/toolbar/toolbar.js +39 -0
- package/dist/components/tooltip/index.d.ts +19 -0
- package/dist/components/tooltip/index.js +15 -0
- package/dist/components/tooltip/tooltip.d.ts +20 -0
- package/dist/components/tooltip/tooltip.js +106 -0
- package/dist/hooks/index.d.ts +9 -0
- package/dist/hooks/use-css-variable.d.ts +36 -0
- package/dist/hooks/use-css-variable.js +72 -0
- package/dist/hooks/use-is-hydrated.d.ts +19 -0
- package/dist/hooks/use-is-hydrated.js +28 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts +2 -0
- package/dist/hooks/use-isomorphic-layout-effect.js +6 -0
- package/dist/hooks/use-list-data.d.ts +111 -0
- package/dist/hooks/use-list-data.js +296 -0
- package/dist/hooks/use-measured-height.d.ts +4 -0
- package/dist/hooks/use-measured-height.js +47 -0
- package/dist/hooks/use-media-query.d.ts +6 -0
- package/dist/hooks/use-media-query.js +50 -0
- package/dist/hooks/use-mounted.d.ts +1 -0
- package/dist/hooks/use-mounted.js +15 -0
- package/dist/hooks/use-overlay-state.d.ts +52 -0
- package/dist/hooks/use-overlay-state.js +70 -0
- package/dist/hooks/use-safe-layout-effect.d.ts +2 -0
- package/dist/hooks/use-safe-layout-effect.js +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +190 -0
- package/dist/prerelease.d.ts +4 -0
- package/dist/prerelease.js +50 -0
- package/dist/styles.css +2 -0
- package/dist/utils/assertion.d.ts +9 -0
- package/dist/utils/assertion.js +3 -0
- package/dist/utils/calendar.d.ts +12 -0
- package/dist/utils/calendar.js +52 -0
- package/dist/utils/children.d.ts +9 -0
- package/dist/utils/children.js +17 -0
- package/dist/utils/compose.d.ts +7 -0
- package/dist/utils/compose.js +18 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/logger.d.ts +23 -0
- package/dist/utils/logger.js +78 -0
- package/dist/utils/tv.d.ts +3 -0
- package/dist/utils/variants.d.ts +73 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +5 -0
- package/package.json +406 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Key, Selection } from "@react-types/shared";
|
|
2
|
+
export interface ListOptions<T> {
|
|
3
|
+
/** Initial items in the list. */
|
|
4
|
+
initialItems?: T[];
|
|
5
|
+
/** The keys for the initially selected items. */
|
|
6
|
+
initialSelectedKeys?: "all" | Iterable<Key>;
|
|
7
|
+
/** The initial text to filter the list by. */
|
|
8
|
+
initialFilterText?: string;
|
|
9
|
+
/** A function that returns a unique key for an item object. */
|
|
10
|
+
getKey?: (item: T) => Key;
|
|
11
|
+
/** A function that returns whether a item matches the current filter text. */
|
|
12
|
+
filter?: (item: T, filterText: string) => boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ListData<T> {
|
|
15
|
+
/** The items in the list. */
|
|
16
|
+
items: T[];
|
|
17
|
+
/** The keys of the currently selected items in the list. */
|
|
18
|
+
selectedKeys: Selection;
|
|
19
|
+
/** Sets the selected keys. */
|
|
20
|
+
setSelectedKeys(keys: Selection): void;
|
|
21
|
+
/** Adds the given keys to the current selected keys. */
|
|
22
|
+
addKeysToSelection(keys: Selection): void;
|
|
23
|
+
/** Removes the given keys from the current selected keys. */
|
|
24
|
+
removeKeysFromSelection(keys: Selection): void;
|
|
25
|
+
/** The current filter text. */
|
|
26
|
+
filterText: string;
|
|
27
|
+
/** Sets the filter text. */
|
|
28
|
+
setFilterText(filterText: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Gets an item from the list by key.
|
|
31
|
+
* @param key - The key of the item to retrieve.
|
|
32
|
+
*/
|
|
33
|
+
getItem(key: Key): T | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Inserts items into the list at the given index.
|
|
36
|
+
* @param index - The index to insert into.
|
|
37
|
+
* @param values - The values to insert.
|
|
38
|
+
*/
|
|
39
|
+
insert(index: number, ...values: T[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Inserts items into the list before the item at the given key.
|
|
42
|
+
* @param key - The key of the item to insert before.
|
|
43
|
+
* @param values - The values to insert.
|
|
44
|
+
*/
|
|
45
|
+
insertBefore(key: Key, ...values: T[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* Inserts items into the list after the item at the given key.
|
|
48
|
+
* @param key - The key of the item to insert after.
|
|
49
|
+
* @param values - The values to insert.
|
|
50
|
+
*/
|
|
51
|
+
insertAfter(key: Key, ...values: T[]): void;
|
|
52
|
+
/**
|
|
53
|
+
* Appends items to the list.
|
|
54
|
+
* @param values - The values to insert.
|
|
55
|
+
*/
|
|
56
|
+
append(...values: T[]): void;
|
|
57
|
+
/**
|
|
58
|
+
* Prepends items to the list.
|
|
59
|
+
* @param value - The value to insert.
|
|
60
|
+
*/
|
|
61
|
+
prepend(...values: T[]): void;
|
|
62
|
+
/**
|
|
63
|
+
* Removes items from the list by their keys.
|
|
64
|
+
* @param keys - The keys of the item to remove.
|
|
65
|
+
*/
|
|
66
|
+
remove(...keys: Key[]): void;
|
|
67
|
+
/**
|
|
68
|
+
* Removes all items from the list that are currently
|
|
69
|
+
* in the set of selected items.
|
|
70
|
+
*/
|
|
71
|
+
removeSelectedItems(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Moves an item within the list.
|
|
74
|
+
* @param key - The key of the item to move.
|
|
75
|
+
* @param toIndex - The index to move the item to.
|
|
76
|
+
*/
|
|
77
|
+
move(key: Key, toIndex: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* Moves one or more items before a given key.
|
|
80
|
+
* @param key - The key of the item to move the items before.
|
|
81
|
+
* @param keys - The keys of the items to move.
|
|
82
|
+
*/
|
|
83
|
+
moveBefore(key: Key, keys: Iterable<Key>): void;
|
|
84
|
+
/**
|
|
85
|
+
* Moves one or more items after a given key.
|
|
86
|
+
* @param key - The key of the item to move the items after.
|
|
87
|
+
* @param keys - The keys of the items to move.
|
|
88
|
+
*/
|
|
89
|
+
moveAfter(key: Key, keys: Iterable<Key>): void;
|
|
90
|
+
/**
|
|
91
|
+
* Updates an item in the list.
|
|
92
|
+
* @param key - The key of the item to update.
|
|
93
|
+
* @param newValue - The new value for the item, or a function that returns the new value based on the previous value.
|
|
94
|
+
*/
|
|
95
|
+
update(key: Key, newValue: T | ((prev: T) => T)): void;
|
|
96
|
+
}
|
|
97
|
+
export interface ListState<T> {
|
|
98
|
+
items: T[];
|
|
99
|
+
selectedKeys: Selection;
|
|
100
|
+
filterText: string;
|
|
101
|
+
}
|
|
102
|
+
interface CreateListOptions<T, C> extends ListOptions<T> {
|
|
103
|
+
cursor?: C;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Manages state for an immutable list data structure, and provides convenience methods to
|
|
107
|
+
* update the data over time.
|
|
108
|
+
*/
|
|
109
|
+
export declare function useListData<T>(options: ListOptions<T>): ListData<T>;
|
|
110
|
+
export declare function createListActions<T, C>(opts: CreateListOptions<T, C>, dispatch: (updater: (state: ListState<T>) => ListState<T>) => void): Omit<ListData<T>, "items" | "selectedKeys" | "getItem" | "filterText">;
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { useState, useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*
|
|
15
|
+
* This file is based on the useListData hook from @react-stately/data package.
|
|
16
|
+
* Original source: https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/data/src/useListData.ts
|
|
17
|
+
*
|
|
18
|
+
* Why we copied this code instead of using @react-stately/data as a dependency:
|
|
19
|
+
* We copied this implementation to avoid adding @react-stately/data as a dependency, which is a
|
|
20
|
+
* large package that would significantly increase our bundle size. We maintain full attribution to
|
|
21
|
+
* Adobe and comply with the Apache License 2.0 requirements.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Manages state for an immutable list data structure, and provides convenience methods to
|
|
25
|
+
* update the data over time.
|
|
26
|
+
*/
|
|
27
|
+
function useListData(options) {
|
|
28
|
+
const {
|
|
29
|
+
filter,
|
|
30
|
+
getKey = item => item.id ?? item.key,
|
|
31
|
+
initialFilterText = "",
|
|
32
|
+
initialItems = [],
|
|
33
|
+
initialSelectedKeys
|
|
34
|
+
} = options;
|
|
35
|
+
|
|
36
|
+
// Store both items and filteredItems in state so we can go back to the unfiltered list
|
|
37
|
+
const [state, setState] = useState({
|
|
38
|
+
items: initialItems,
|
|
39
|
+
selectedKeys: initialSelectedKeys === "all" ? "all" : new Set(initialSelectedKeys || []),
|
|
40
|
+
filterText: initialFilterText
|
|
41
|
+
});
|
|
42
|
+
const filteredItems = useMemo(() => filter ? state.items.filter(item => filter(item, state.filterText)) : state.items, [state.items, state.filterText, filter]);
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
items: filteredItems,
|
|
46
|
+
...createListActions({
|
|
47
|
+
getKey
|
|
48
|
+
}, setState),
|
|
49
|
+
getItem(key) {
|
|
50
|
+
return state.items.find(item => getKey(item) === key);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createListActions(opts, dispatch) {
|
|
55
|
+
const {
|
|
56
|
+
cursor,
|
|
57
|
+
getKey
|
|
58
|
+
} = opts;
|
|
59
|
+
return {
|
|
60
|
+
setSelectedKeys(selectedKeys) {
|
|
61
|
+
dispatch(state => ({
|
|
62
|
+
...state,
|
|
63
|
+
selectedKeys
|
|
64
|
+
}));
|
|
65
|
+
},
|
|
66
|
+
addKeysToSelection(selectedKeys) {
|
|
67
|
+
dispatch(state => {
|
|
68
|
+
if (state.selectedKeys === "all") {
|
|
69
|
+
return state;
|
|
70
|
+
}
|
|
71
|
+
if (selectedKeys === "all") {
|
|
72
|
+
return {
|
|
73
|
+
...state,
|
|
74
|
+
selectedKeys: "all"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
...state,
|
|
79
|
+
selectedKeys: new Set([...state.selectedKeys, ...selectedKeys])
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
removeKeysFromSelection(selectedKeys) {
|
|
84
|
+
dispatch(state => {
|
|
85
|
+
if (selectedKeys === "all") {
|
|
86
|
+
return {
|
|
87
|
+
...state,
|
|
88
|
+
selectedKeys: new Set()
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const selection = state.selectedKeys === "all" ? new Set(state.items.map(getKey)) : new Set(state.selectedKeys);
|
|
92
|
+
for (const key of selectedKeys) {
|
|
93
|
+
selection.delete(key);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
...state,
|
|
97
|
+
selectedKeys: selection
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
setFilterText(filterText) {
|
|
102
|
+
dispatch(state => ({
|
|
103
|
+
...state,
|
|
104
|
+
filterText
|
|
105
|
+
}));
|
|
106
|
+
},
|
|
107
|
+
insert(index, ...values) {
|
|
108
|
+
dispatch(state => insert(state, index, ...values));
|
|
109
|
+
},
|
|
110
|
+
insertBefore(key, ...values) {
|
|
111
|
+
dispatch(state => {
|
|
112
|
+
let index = state.items.findIndex(item => getKey?.(item) === key);
|
|
113
|
+
if (index === -1) {
|
|
114
|
+
if (state.items.length === 0) {
|
|
115
|
+
index = 0;
|
|
116
|
+
} else {
|
|
117
|
+
return state;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return insert(state, index, ...values);
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
insertAfter(key, ...values) {
|
|
124
|
+
dispatch(state => {
|
|
125
|
+
let index = state.items.findIndex(item => getKey?.(item) === key);
|
|
126
|
+
if (index === -1) {
|
|
127
|
+
if (state.items.length === 0) {
|
|
128
|
+
index = 0;
|
|
129
|
+
} else {
|
|
130
|
+
return state;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return insert(state, index + 1, ...values);
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
prepend(...values) {
|
|
137
|
+
dispatch(state => insert(state, 0, ...values));
|
|
138
|
+
},
|
|
139
|
+
append(...values) {
|
|
140
|
+
dispatch(state => insert(state, state.items.length, ...values));
|
|
141
|
+
},
|
|
142
|
+
remove(...keys) {
|
|
143
|
+
dispatch(state => {
|
|
144
|
+
const keySet = new Set(keys);
|
|
145
|
+
const items = state.items.filter(item => !keySet.has(getKey(item)));
|
|
146
|
+
let selection = "all";
|
|
147
|
+
if (state.selectedKeys !== "all") {
|
|
148
|
+
selection = new Set(state.selectedKeys);
|
|
149
|
+
for (const key of keys) {
|
|
150
|
+
selection.delete(key);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (cursor == null && items.length === 0) {
|
|
154
|
+
selection = new Set();
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
...state,
|
|
158
|
+
items,
|
|
159
|
+
selectedKeys: selection
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
removeSelectedItems() {
|
|
164
|
+
dispatch(state => {
|
|
165
|
+
if (state.selectedKeys === "all") {
|
|
166
|
+
return {
|
|
167
|
+
...state,
|
|
168
|
+
items: [],
|
|
169
|
+
selectedKeys: new Set()
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const selectedKeys = state.selectedKeys;
|
|
173
|
+
const items = state.items.filter(item => !selectedKeys.has(getKey(item)));
|
|
174
|
+
return {
|
|
175
|
+
...state,
|
|
176
|
+
items,
|
|
177
|
+
selectedKeys: new Set()
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
move(key, toIndex) {
|
|
182
|
+
dispatch(state => {
|
|
183
|
+
const index = state.items.findIndex(item => getKey(item) === key);
|
|
184
|
+
if (index === -1) {
|
|
185
|
+
return state;
|
|
186
|
+
}
|
|
187
|
+
const copy = state.items.slice();
|
|
188
|
+
const [item] = copy.splice(index, 1);
|
|
189
|
+
if (item !== undefined) {
|
|
190
|
+
copy.splice(toIndex, 0, item);
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
...state,
|
|
194
|
+
items: copy
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
moveBefore(key, keys) {
|
|
199
|
+
dispatch(state => {
|
|
200
|
+
const toIndex = state.items.findIndex(item => getKey(item) === key);
|
|
201
|
+
if (toIndex === -1) {
|
|
202
|
+
return state;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Find indices of keys to move. Sort them so that the order in the list is retained.
|
|
206
|
+
const keyArray = Array.isArray(keys) ? keys : [...keys];
|
|
207
|
+
const indices = keyArray.map(key => state.items.findIndex(item => getKey(item) === key)).sort((a, b) => a - b);
|
|
208
|
+
return move(state, indices, toIndex);
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
moveAfter(key, keys) {
|
|
212
|
+
dispatch(state => {
|
|
213
|
+
const toIndex = state.items.findIndex(item => getKey(item) === key);
|
|
214
|
+
if (toIndex === -1) {
|
|
215
|
+
return state;
|
|
216
|
+
}
|
|
217
|
+
const keyArray = Array.isArray(keys) ? keys : [...keys];
|
|
218
|
+
const indices = keyArray.map(key => state.items.findIndex(item => getKey(item) === key)).sort((a, b) => a - b);
|
|
219
|
+
return move(state, indices, toIndex + 1);
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
update(key, newValue) {
|
|
223
|
+
dispatch(state => {
|
|
224
|
+
const index = state.items.findIndex(item => getKey(item) === key);
|
|
225
|
+
if (index === -1) {
|
|
226
|
+
return state;
|
|
227
|
+
}
|
|
228
|
+
const currentItem = state.items[index];
|
|
229
|
+
if (currentItem === undefined) {
|
|
230
|
+
return state;
|
|
231
|
+
}
|
|
232
|
+
let updatedValue;
|
|
233
|
+
if (typeof newValue === "function") {
|
|
234
|
+
updatedValue = newValue(currentItem);
|
|
235
|
+
} else {
|
|
236
|
+
updatedValue = newValue;
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
...state,
|
|
240
|
+
items: [...state.items.slice(0, index), updatedValue, ...state.items.slice(index + 1)]
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function insert(state, index, ...values) {
|
|
247
|
+
return {
|
|
248
|
+
...state,
|
|
249
|
+
items: [...state.items.slice(0, index), ...values, ...state.items.slice(index)]
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function move(state, indices, toIndex) {
|
|
253
|
+
// Shift the target down by the number of items being moved from before the target
|
|
254
|
+
toIndex -= indices.filter(index => index < toIndex).length;
|
|
255
|
+
const moves = indices.map(from => ({
|
|
256
|
+
from,
|
|
257
|
+
to: toIndex++
|
|
258
|
+
}));
|
|
259
|
+
|
|
260
|
+
// Shift later from indices down if they have a larger index
|
|
261
|
+
for (let i = 0; i < moves.length; i++) {
|
|
262
|
+
const a = moves[i];
|
|
263
|
+
for (let j = i; j < moves.length; j++) {
|
|
264
|
+
const b = moves[j];
|
|
265
|
+
if (b.from > a.from) {
|
|
266
|
+
b.from--;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Interleave the moves so they can be applied one by one rather than all at once
|
|
272
|
+
for (let i = 0; i < moves.length; i++) {
|
|
273
|
+
const a = moves[i];
|
|
274
|
+
for (let j = moves.length - 1; j > i; j--) {
|
|
275
|
+
const b = moves[j];
|
|
276
|
+
if (b.from < a.to) {
|
|
277
|
+
a.to++;
|
|
278
|
+
} else {
|
|
279
|
+
b.from++;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const copy = state.items.slice();
|
|
284
|
+
for (const moveItem of moves) {
|
|
285
|
+
const [item] = copy.splice(moveItem.from, 1);
|
|
286
|
+
if (item !== undefined) {
|
|
287
|
+
copy.splice(moveItem.to, 0, item);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
...state,
|
|
292
|
+
items: copy
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export { createListActions, useListData };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
const useMeasuredHeight = ref => {
|
|
5
|
+
const [height, setHeight] = useState(undefined);
|
|
6
|
+
const calculateHeight = useCallback(() => {
|
|
7
|
+
if (ref.current) {
|
|
8
|
+
const measuredHeight = ref.current.scrollHeight;
|
|
9
|
+
setHeight(prevHeight => {
|
|
10
|
+
// Only update if height actually changed
|
|
11
|
+
return prevHeight !== measuredHeight ? measuredHeight : prevHeight;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}, [ref]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const element = ref.current;
|
|
17
|
+
if (!element) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Use ResizeObserver's initial notification instead of manual call
|
|
22
|
+
const resizeObserver = new ResizeObserver(calculateHeight);
|
|
23
|
+
|
|
24
|
+
// Optimize MutationObserver callback
|
|
25
|
+
const mutationObserver = new MutationObserver(mutations => {
|
|
26
|
+
// Check if any mutation is aria-hidden before calculating
|
|
27
|
+
const hasAriaHiddenChange = mutations.some(mutation => mutation.type === "attributes" && mutation.attributeName === "aria-hidden");
|
|
28
|
+
if (hasAriaHiddenChange) {
|
|
29
|
+
calculateHeight();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
resizeObserver.observe(element);
|
|
33
|
+
mutationObserver.observe(element, {
|
|
34
|
+
attributeFilter: ["aria-hidden"],
|
|
35
|
+
attributes: true
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
resizeObserver.disconnect();
|
|
39
|
+
mutationObserver.disconnect();
|
|
40
|
+
};
|
|
41
|
+
}, [ref, calculateHeight]);
|
|
42
|
+
return {
|
|
43
|
+
height
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { useMeasuredHeight };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect.js';
|
|
4
|
+
|
|
5
|
+
const IS_SERVER = typeof window === "undefined";
|
|
6
|
+
function useMediaQuery(query, {
|
|
7
|
+
defaultValue = false,
|
|
8
|
+
initializeWithValue = true
|
|
9
|
+
} = {}) {
|
|
10
|
+
const getMatches = query => {
|
|
11
|
+
if (IS_SERVER) {
|
|
12
|
+
return defaultValue;
|
|
13
|
+
}
|
|
14
|
+
return window.matchMedia(query).matches;
|
|
15
|
+
};
|
|
16
|
+
const [matches, setMatches] = useState(() => {
|
|
17
|
+
if (initializeWithValue) {
|
|
18
|
+
return getMatches(query);
|
|
19
|
+
}
|
|
20
|
+
return defaultValue;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Handles the change event of the media query.
|
|
24
|
+
function handleChange() {
|
|
25
|
+
setMatches(getMatches(query));
|
|
26
|
+
}
|
|
27
|
+
useIsomorphicLayoutEffect(() => {
|
|
28
|
+
const matchMedia = window.matchMedia(query);
|
|
29
|
+
|
|
30
|
+
// Triggered at the first client-side load and if query changes
|
|
31
|
+
handleChange();
|
|
32
|
+
|
|
33
|
+
// Use deprecated `addListener` and `removeListener` to support Safari < 14 (#135)
|
|
34
|
+
if (matchMedia.addListener) {
|
|
35
|
+
matchMedia.addListener(handleChange);
|
|
36
|
+
} else {
|
|
37
|
+
matchMedia.addEventListener("change", handleChange);
|
|
38
|
+
}
|
|
39
|
+
return () => {
|
|
40
|
+
if (matchMedia.removeListener) {
|
|
41
|
+
matchMedia.removeListener(handleChange);
|
|
42
|
+
} else {
|
|
43
|
+
matchMedia.removeEventListener("change", handleChange);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}, [query]);
|
|
47
|
+
return matches;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { useMediaQuery };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useIsMounted(): () => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
function useIsMounted() {
|
|
5
|
+
const isMounted = useRef(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
isMounted.current = true;
|
|
8
|
+
return () => {
|
|
9
|
+
isMounted.current = false;
|
|
10
|
+
};
|
|
11
|
+
}, []);
|
|
12
|
+
return useCallback(() => isMounted.current, []);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { useIsMounted };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface UseOverlayStateProps {
|
|
2
|
+
/**
|
|
3
|
+
* Whether the overlay is currently open (controlled)
|
|
4
|
+
*/
|
|
5
|
+
isOpen?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the overlay is open by default (uncontrolled)
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Handler that is called when the overlay's open state changes
|
|
13
|
+
*/
|
|
14
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface UseOverlayStateReturn {
|
|
17
|
+
/**
|
|
18
|
+
* Whether the overlay is currently open
|
|
19
|
+
*/
|
|
20
|
+
readonly isOpen: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Sets the overlay's open state
|
|
23
|
+
*/
|
|
24
|
+
setOpen(isOpen: boolean): void;
|
|
25
|
+
/**
|
|
26
|
+
* Opens the overlay
|
|
27
|
+
*/
|
|
28
|
+
open(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Closes the overlay
|
|
31
|
+
*/
|
|
32
|
+
close(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Toggles the overlay's open state
|
|
35
|
+
*/
|
|
36
|
+
toggle(): void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Hook to manage overlay trigger state (Modal, AlertDialog, Popover, etc.)
|
|
40
|
+
* Provides methods to open, close, and toggle the overlay
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* const state = useOverlayState();
|
|
45
|
+
*
|
|
46
|
+
* <Button onPress={state.open}>Open Dialog</Button>
|
|
47
|
+
* <Modal isOpen={state.isOpen} onOpenChange={state.setOpen}>
|
|
48
|
+
* <Button onPress={state.close}>Close</Button>
|
|
49
|
+
* </Modal>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const useOverlayState: (props?: UseOverlayStateProps) => UseOverlayStateReturn;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hook to manage overlay trigger state (Modal, AlertDialog, Popover, etc.)
|
|
6
|
+
* Provides methods to open, close, and toggle the overlay
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const state = useOverlayState();
|
|
11
|
+
*
|
|
12
|
+
* <Button onPress={state.open}>Open Dialog</Button>
|
|
13
|
+
* <Modal isOpen={state.isOpen} onOpenChange={state.setOpen}>
|
|
14
|
+
* <Button onPress={state.close}>Close</Button>
|
|
15
|
+
* </Modal>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
const useOverlayState = (props = {}) => {
|
|
19
|
+
const {
|
|
20
|
+
defaultOpen = false,
|
|
21
|
+
isOpen: controlledIsOpen,
|
|
22
|
+
onOpenChange
|
|
23
|
+
} = props;
|
|
24
|
+
|
|
25
|
+
// Internal state for uncontrolled mode
|
|
26
|
+
const [uncontrolledIsOpen, setUncontrolledIsOpen] = useState(defaultOpen);
|
|
27
|
+
|
|
28
|
+
// Determine if controlled
|
|
29
|
+
const isControlled = controlledIsOpen !== undefined;
|
|
30
|
+
const isOpen = isControlled ? controlledIsOpen : uncontrolledIsOpen;
|
|
31
|
+
|
|
32
|
+
// Keep a stable reference to onOpenChange to avoid recreating callbacks
|
|
33
|
+
const onOpenChangeRef = useRef(onOpenChange);
|
|
34
|
+
|
|
35
|
+
// Update ref in effect to avoid updating during render
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
onOpenChangeRef.current = onOpenChange;
|
|
38
|
+
}, [onOpenChange]);
|
|
39
|
+
|
|
40
|
+
// Stable setter function that works for both controlled and uncontrolled modes
|
|
41
|
+
const setOpen = useCallback(nextIsOpen => {
|
|
42
|
+
// Always call the onChange callback if provided
|
|
43
|
+
onOpenChangeRef.current?.(nextIsOpen);
|
|
44
|
+
|
|
45
|
+
// Update internal state only in uncontrolled mode
|
|
46
|
+
if (!isControlled) {
|
|
47
|
+
setUncontrolledIsOpen(nextIsOpen);
|
|
48
|
+
}
|
|
49
|
+
}, [isControlled]);
|
|
50
|
+
|
|
51
|
+
// Memoized convenience methods
|
|
52
|
+
const open = useCallback(() => {
|
|
53
|
+
setOpen(true);
|
|
54
|
+
}, [setOpen]);
|
|
55
|
+
const close = useCallback(() => {
|
|
56
|
+
setOpen(false);
|
|
57
|
+
}, [setOpen]);
|
|
58
|
+
const toggle = useCallback(() => {
|
|
59
|
+
setOpen(!isOpen);
|
|
60
|
+
}, [setOpen, isOpen]);
|
|
61
|
+
return {
|
|
62
|
+
close,
|
|
63
|
+
isOpen,
|
|
64
|
+
open,
|
|
65
|
+
setOpen,
|
|
66
|
+
toggle
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { useOverlayState };
|
package/dist/index.d.ts
ADDED