@react-md/core 1.0.0-next.19 → 1.0.0-next.20
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/dist/CoreProviders.js.map +1 -1
- package/dist/NoSsr.js.map +1 -1
- package/dist/RootHtml.js.map +1 -1
- package/dist/SsrProvider.js.map +1 -1
- package/dist/_core.scss +10 -9
- package/dist/app-bar/AppBar.js.map +1 -1
- package/dist/app-bar/AppBarTitle.js.map +1 -1
- package/dist/app-bar/_app-bar.scss +0 -4
- package/dist/app-bar/styles.js.map +1 -1
- package/dist/autocomplete/Autocomplete.js.map +1 -1
- package/dist/autocomplete/AutocompleteChip.js +1 -1
- package/dist/autocomplete/AutocompleteChip.js.map +1 -1
- package/dist/autocomplete/AutocompleteCircularProgress.js.map +1 -1
- package/dist/autocomplete/AutocompleteClearButton.js +1 -1
- package/dist/autocomplete/AutocompleteClearButton.js.map +1 -1
- package/dist/autocomplete/AutocompleteDropdownButton.js +1 -1
- package/dist/autocomplete/AutocompleteDropdownButton.js.map +1 -1
- package/dist/autocomplete/AutocompleteListboxChildren.js.map +1 -1
- package/dist/autocomplete/_autocomplete.scss +15 -13
- package/dist/autocomplete/autocompleteStyles.js.map +1 -1
- package/dist/autocomplete/types.js.map +1 -1
- package/dist/autocomplete/useAutocomplete.js +1 -1
- package/dist/autocomplete/useAutocomplete.js.map +1 -1
- package/dist/autocomplete/utils.js.map +1 -1
- package/dist/avatar/Avatar.js.map +1 -1
- package/dist/avatar/styles.js.map +1 -1
- package/dist/badge/Badge.js.map +1 -1
- package/dist/badge/styles.js.map +1 -1
- package/dist/box/Box.js +2 -1
- package/dist/box/Box.js.map +1 -1
- package/dist/box/_box.scss +24 -1
- package/dist/box/styles.d.ts +11 -0
- package/dist/box/styles.js +4 -3
- package/dist/box/styles.js.map +1 -1
- package/dist/button/AsyncButton.js.map +1 -1
- package/dist/button/Button.js.map +1 -1
- package/dist/button/ButtonUnstyled.js.map +1 -1
- package/dist/button/FloatingActionButton.js.map +1 -1
- package/dist/button/TooltippedButton.js.map +1 -1
- package/dist/button/buttonStyles.js.map +1 -1
- package/dist/card/Card.d.ts +4 -13
- package/dist/card/Card.js +3 -3
- package/dist/card/Card.js.map +1 -1
- package/dist/card/CardContent.js.map +1 -1
- package/dist/card/CardFooter.js.map +1 -1
- package/dist/card/CardHeader.js.map +1 -1
- package/dist/card/CardSubtitle.js.map +1 -1
- package/dist/card/CardTitle.js.map +1 -1
- package/dist/card/ClickableCard.js.map +1 -1
- package/dist/card/_card.scss +5 -0
- package/dist/card/styles.js.map +1 -1
- package/dist/chip/Chip.js +1 -1
- package/dist/chip/Chip.js.map +1 -1
- package/dist/chip/styles.js.map +1 -1
- package/dist/dialog/Dialog.d.ts +4 -4
- package/dist/dialog/Dialog.js.map +1 -1
- package/dist/dialog/DialogContent.js.map +1 -1
- package/dist/dialog/DialogFooter.js.map +1 -1
- package/dist/dialog/DialogHeader.js.map +1 -1
- package/dist/dialog/DialogTitle.js.map +1 -1
- package/dist/dialog/FixedDialog.js +8 -5
- package/dist/dialog/FixedDialog.js.map +1 -1
- package/dist/dialog/NestedDialogProvider.js.map +1 -1
- package/dist/dialog/styles.d.ts +12 -3
- package/dist/dialog/styles.js.map +1 -1
- package/dist/divider/Divider.js.map +1 -1
- package/dist/divider/styles.js.map +1 -1
- package/dist/draggable/useDraggable.d.ts +3 -0
- package/dist/draggable/useDraggable.js +20 -5
- package/dist/draggable/useDraggable.js.map +1 -1
- package/dist/draggable/utils.js.map +1 -1
- package/dist/expansion-panel/ExpansionList.js.map +1 -1
- package/dist/expansion-panel/ExpansionPanel.js.map +1 -1
- package/dist/expansion-panel/ExpansionPanelHeader.js +1 -1
- package/dist/expansion-panel/ExpansionPanelHeader.js.map +1 -1
- package/dist/expansion-panel/expansionPanelStyles.js.map +1 -1
- package/dist/expansion-panel/useExpansionList.js.map +1 -1
- package/dist/expansion-panel/useExpansionPanels.js.map +1 -1
- package/dist/files/FileInput.js +1 -1
- package/dist/files/FileInput.js.map +1 -1
- package/dist/files/styles.js.map +1 -1
- package/dist/files/useFileUpload.js.map +1 -1
- package/dist/files/utils.d.ts +31 -1
- package/dist/files/utils.js +30 -0
- package/dist/files/utils.js.map +1 -1
- package/dist/focus/useFocusContainer.d.ts +5 -7
- package/dist/focus/useFocusContainer.js +5 -7
- package/dist/focus/useFocusContainer.js.map +1 -1
- package/dist/form/Checkbox.js.map +1 -1
- package/dist/form/Fieldset.js.map +1 -1
- package/dist/form/Form.js.map +1 -1
- package/dist/form/FormMessage.js.map +1 -1
- package/dist/form/FormMessageContainer.js.map +1 -1
- package/dist/form/FormMessageCounter.js.map +1 -1
- package/dist/form/InputToggle.js.map +1 -1
- package/dist/form/InputToggleIcon.js +1 -1
- package/dist/form/InputToggleIcon.js.map +1 -1
- package/dist/form/Label.js.map +1 -1
- package/dist/form/Legend.js.map +1 -1
- package/dist/form/Listbox.js.map +1 -1
- package/dist/form/ListboxProvider.js.map +1 -1
- package/dist/form/MenuItemCheckbox.js.map +1 -1
- package/dist/form/MenuItemFileInput.d.ts +1 -4
- package/dist/form/MenuItemFileInput.js +15 -6
- package/dist/form/MenuItemFileInput.js.map +1 -1
- package/dist/form/MenuItemInputToggle.js.map +1 -1
- package/dist/form/MenuItemRadio.js.map +1 -1
- package/dist/form/MenuItemSwitch.js.map +1 -1
- package/dist/form/MenuItemTextField.js.map +1 -1
- package/dist/form/NativeSelect.js +1 -1
- package/dist/form/NativeSelect.js.map +1 -1
- package/dist/form/OptGroup.js.map +1 -1
- package/dist/form/Option.js +4 -4
- package/dist/form/Option.js.map +1 -1
- package/dist/form/Password.js +2 -2
- package/dist/form/Password.js.map +1 -1
- package/dist/form/Radio.js.map +1 -1
- package/dist/form/ResizingTextAreaWrapper.js.map +1 -1
- package/dist/form/Select.js +1 -1
- package/dist/form/Select.js.map +1 -1
- package/dist/form/SelectedOption.js.map +1 -1
- package/dist/form/Slider.js +9 -62
- package/dist/form/Slider.js.map +1 -1
- package/dist/form/SliderContainer.js.map +1 -1
- package/dist/form/SliderMark.js.map +1 -1
- package/dist/form/SliderMarkLabel.js.map +1 -1
- package/dist/form/SliderThumb.js +1 -0
- package/dist/form/SliderThumb.js.map +1 -1
- package/dist/form/SliderTrack.js.map +1 -1
- package/dist/form/SliderValueMarks.js.map +1 -1
- package/dist/form/SliderValueTooltip.js.map +1 -1
- package/dist/form/Switch.js.map +1 -1
- package/dist/form/SwitchTrack.js.map +1 -1
- package/dist/form/TextArea.js.map +1 -1
- package/dist/form/TextField.js.map +1 -1
- package/dist/form/TextFieldAddon.js.map +1 -1
- package/dist/form/TextFieldContainer.js.map +1 -1
- package/dist/form/_form.scss +313 -269
- package/dist/form/formMessageContainerStyles.js.map +1 -1
- package/dist/form/formMessageStyles.js.map +1 -1
- package/dist/form/inputToggleStyles.js.map +1 -1
- package/dist/form/menuItemInputToggleStyles.js.map +1 -1
- package/dist/form/nativeSelectStyles.js.map +1 -1
- package/dist/form/optionStyles.js.map +1 -1
- package/dist/form/passwordStyles.js.map +1 -1
- package/dist/form/selectStyles.js.map +1 -1
- package/dist/form/selectUtils.js.map +1 -1
- package/dist/form/sliderUtils.d.ts +2 -7
- package/dist/form/sliderUtils.js +5 -5
- package/dist/form/sliderUtils.js.map +1 -1
- package/dist/form/switchStyles.js.map +1 -1
- package/dist/form/textAreaStyles.js.map +1 -1
- package/dist/form/textFieldContainerStyles.js.map +1 -1
- package/dist/form/textFieldStyles.js.map +1 -1
- package/dist/form/types.js.map +1 -1
- package/dist/form/useCheckboxGroup.d.ts +2 -2
- package/dist/form/useCheckboxGroup.js.map +1 -1
- package/dist/form/useCombobox.js.map +1 -1
- package/dist/form/useEditableCombobox.js.map +1 -1
- package/dist/form/useFormReset.js.map +1 -1
- package/dist/form/useNumberField.js.map +1 -1
- package/dist/form/useRadioGroup.d.ts +1 -1
- package/dist/form/useRadioGroup.js.map +1 -1
- package/dist/form/useRangeSlider.d.ts +1 -0
- package/dist/form/useRangeSlider.js.map +1 -1
- package/dist/form/useResizingTextArea.js.map +1 -1
- package/dist/form/useSelectCombobox.js.map +1 -1
- package/dist/form/useSlider.d.ts +1 -3
- package/dist/form/useSlider.js.map +1 -1
- package/dist/form/useSliderDraggable.d.ts +9 -0
- package/dist/form/useSliderDraggable.js +44 -0
- package/dist/form/useSliderDraggable.js.map +1 -0
- package/dist/form/useTextField.d.ts +24 -14
- package/dist/form/useTextField.js +7 -5
- package/dist/form/useTextField.js.map +1 -1
- package/dist/form/useTextFieldContainerAddons.js.map +1 -1
- package/dist/form/validation.js +2 -0
- package/dist/form/validation.js.map +1 -1
- package/dist/hoverMode/useHoverMode.d.ts +64 -3
- package/dist/hoverMode/useHoverMode.js.map +1 -1
- package/dist/hoverMode/useHoverModeProvider.d.ts +22 -12
- package/dist/hoverMode/useHoverModeProvider.js +21 -11
- package/dist/hoverMode/useHoverModeProvider.js.map +1 -1
- package/dist/icon/FontIcon.js.map +1 -1
- package/dist/icon/IconRotator.js.map +1 -1
- package/dist/icon/MaterialIcon.js.map +1 -1
- package/dist/icon/MaterialSymbol.js.map +1 -1
- package/dist/icon/SVGIcon.js.map +1 -1
- package/dist/icon/TextIconSpacing.js.map +1 -1
- package/dist/icon/{iconConfig.js → config.js} +1 -1
- package/dist/icon/config.js.map +1 -0
- package/dist/icon/materialConfig.js.map +1 -1
- package/dist/icon/styles.js.map +1 -1
- package/dist/interaction/Ripple.js.map +1 -1
- package/dist/interaction/RippleContainer.js.map +1 -1
- package/dist/interaction/UserInteractionModeProvider.js.map +1 -1
- package/dist/interaction/_interaction.scss +2 -2
- package/dist/interaction/useElementInteraction.d.ts +24 -25
- package/dist/interaction/useElementInteraction.js +20 -21
- package/dist/interaction/useElementInteraction.js.map +1 -1
- package/dist/interaction/useHigherContrastChildren.d.ts +8 -6
- package/dist/interaction/useHigherContrastChildren.js +10 -8
- package/dist/interaction/useHigherContrastChildren.js.map +1 -1
- package/dist/interaction/utils.js.map +1 -1
- package/dist/layout/LayoutAppBar.js.map +1 -1
- package/dist/layout/LayoutNav.js.map +1 -1
- package/dist/layout/LayoutWindowSplitter.js.map +1 -1
- package/dist/layout/Main.js.map +1 -1
- package/dist/layout/_layout.scss +4 -0
- package/dist/layout/layoutNavStyles.js.map +1 -1
- package/dist/layout/layoutWindowSplitterStyles.js.map +1 -1
- package/dist/layout/mainStyles.js.map +1 -1
- package/dist/layout/useExpandableLayout.d.ts +12 -14
- package/dist/layout/useExpandableLayout.js +13 -15
- package/dist/layout/useExpandableLayout.js.map +1 -1
- package/dist/layout/useHorizontalLayoutTransition.js.map +1 -1
- package/dist/layout/useLayoutAppBarHeight.js.map +1 -1
- package/dist/layout/useLayoutTree.d.ts +4 -3
- package/dist/layout/useLayoutTree.js +4 -3
- package/dist/layout/useLayoutTree.js.map +1 -1
- package/dist/layout/useLayoutWindowSplitter.js.map +1 -1
- package/dist/layout/useMainTabIndex.js.map +1 -1
- package/dist/layout/useResizableLayout.d.ts +13 -16
- package/dist/layout/useResizableLayout.js +13 -16
- package/dist/layout/useResizableLayout.js.map +1 -1
- package/dist/layout/useTemporaryLayout.d.ts +14 -9
- package/dist/layout/useTemporaryLayout.js +12 -10
- package/dist/layout/useTemporaryLayout.js.map +1 -1
- package/dist/link/Link.js.map +1 -1
- package/dist/link/SkipToMainContent.js.map +1 -1
- package/dist/link/styles.js.map +1 -1
- package/dist/list/List.js.map +1 -1
- package/dist/list/ListItem.js +1 -1
- package/dist/list/ListItem.js.map +1 -1
- package/dist/list/ListItemAddon.js.map +1 -1
- package/dist/list/ListItemChildren.js.map +1 -1
- package/dist/list/ListItemLink.js.map +1 -1
- package/dist/list/ListItemText.js.map +1 -1
- package/dist/list/ListSubheader.js.map +1 -1
- package/dist/list/listItemStyles.js.map +1 -1
- package/dist/list/listStyles.js.map +1 -1
- package/dist/list/types.js.map +1 -1
- package/dist/media-queries/AppSizeProvider.d.ts +1 -1
- package/dist/media-queries/AppSizeProvider.js +1 -1
- package/dist/media-queries/AppSizeProvider.js.map +1 -1
- package/dist/media-queries/useMediaQuery.d.ts +3 -3
- package/dist/media-queries/useMediaQuery.js +3 -3
- package/dist/media-queries/useMediaQuery.js.map +1 -1
- package/dist/menu/DropdownMenu.js.map +1 -1
- package/dist/menu/Menu.js.map +1 -1
- package/dist/menu/MenuBar.js.map +1 -1
- package/dist/menu/MenuButton.js +1 -1
- package/dist/menu/MenuButton.js.map +1 -1
- package/dist/menu/MenuConfigurationProvider.js.map +1 -1
- package/dist/menu/MenuItem.js.map +1 -1
- package/dist/menu/MenuItemButton.js +1 -1
- package/dist/menu/MenuItemButton.js.map +1 -1
- package/dist/menu/MenuItemCircularProgress.js.map +1 -1
- package/dist/menu/MenuItemGroup.js.map +1 -1
- package/dist/menu/MenuItemSeparator.js.map +1 -1
- package/dist/menu/MenuSheet.js.map +1 -1
- package/dist/menu/MenuVisibilityProvider.js.map +1 -1
- package/dist/menu/MenuWidget.js.map +1 -1
- package/dist/menu/MenuWidgetKeyboardProvider.js.map +1 -1
- package/dist/menu/useContextMenu.js.map +1 -1
- package/dist/menu/useMenuBarProvider.js.map +1 -1
- package/dist/movement/types.js.map +1 -1
- package/dist/movement/useKeyboardMovementProvider.js.map +1 -1
- package/dist/movement/utils.js.map +1 -1
- package/dist/navigation/CollapsibleNavGroup.js.map +1 -1
- package/dist/navigation/DefaultNavigationRenderer.js.map +1 -1
- package/dist/navigation/NavGroup.js.map +1 -1
- package/dist/navigation/NavItem.js.map +1 -1
- package/dist/navigation/NavItemButton.js +1 -1
- package/dist/navigation/NavItemButton.js.map +1 -1
- package/dist/navigation/NavItemLink.js.map +1 -1
- package/dist/navigation/NavSubheader.d.ts +1 -1
- package/dist/navigation/NavSubheader.js +1 -1
- package/dist/navigation/NavSubheader.js.map +1 -1
- package/dist/navigation/Navigation.js.map +1 -1
- package/dist/navigation/navGroupStyles.js.map +1 -1
- package/dist/navigation/navItemStyles.js.map +1 -1
- package/dist/navigation/types.js.map +1 -1
- package/dist/navigation/useActiveHeadingId.d.ts +1 -1
- package/dist/navigation/useActiveHeadingId.js +4 -4
- package/dist/navigation/useActiveHeadingId.js.map +1 -1
- package/dist/navigation/useNavigationExpansion.js.map +1 -1
- package/dist/navigation/useTableOfContentsHeadings.d.ts +75 -0
- package/dist/navigation/useTableOfContentsHeadings.js +91 -0
- package/dist/navigation/useTableOfContentsHeadings.js.map +1 -0
- package/dist/objectFit.js.map +1 -1
- package/dist/overlay/Overlay.js +1 -1
- package/dist/overlay/Overlay.js.map +1 -1
- package/dist/overlay/overlayStyles.d.ts +7 -3
- package/dist/overlay/overlayStyles.js.map +1 -1
- package/dist/portal/Portal.js.map +1 -1
- package/dist/portal/PortalContainerProvider.js.map +1 -1
- package/dist/positioning/createHorizontalPosition.js.map +1 -1
- package/dist/positioning/createVerticalPosition.js.map +1 -1
- package/dist/positioning/useFixedPositioning.d.ts +11 -8
- package/dist/positioning/useFixedPositioning.js +7 -6
- package/dist/positioning/useFixedPositioning.js.map +1 -1
- package/dist/progress/CircularProgress.js.map +1 -1
- package/dist/progress/LinearProgress.js.map +1 -1
- package/dist/progress/_progress.scss +2 -1
- package/dist/responsive-item/ResponsiveItem.js.map +1 -1
- package/dist/responsive-item/ResponsiveItemOverlay.js.map +1 -1
- package/dist/responsive-item/responsiveItemOverlayStyles.js.map +1 -1
- package/dist/responsive-item/responsiveItemStyles.js.map +1 -1
- package/dist/scroll/ScrollLock.js.map +1 -1
- package/dist/scroll/useScrollLock.d.ts +1 -1
- package/dist/scroll/useScrollLock.js +1 -1
- package/dist/scroll/useScrollLock.js.map +1 -1
- package/dist/searching/fuzzy.d.ts +1 -1
- package/dist/searching/fuzzy.js.map +1 -1
- package/dist/searching/useFuzzyMatch.js.map +1 -1
- package/dist/segmented-button/SegmentedButton.js +1 -1
- package/dist/segmented-button/SegmentedButton.js.map +1 -1
- package/dist/segmented-button/SegmentedButtonContainer.js.map +1 -1
- package/dist/segmented-button/_segmented-button.scss +40 -0
- package/dist/segmented-button/segmentedButtonContainerStyles.js.map +1 -1
- package/dist/segmented-button/segmentedButtonStyles.js.map +1 -1
- package/dist/sheet/Sheet.js.map +1 -1
- package/dist/sheet/styles.js.map +1 -1
- package/dist/snackbar/DefaultToastRenderer.js.map +1 -1
- package/dist/snackbar/Snackbar.js.map +1 -1
- package/dist/snackbar/Toast.js.map +1 -1
- package/dist/snackbar/ToastActionButton.js.map +1 -1
- package/dist/snackbar/ToastCloseButton.js +1 -1
- package/dist/snackbar/ToastCloseButton.js.map +1 -1
- package/dist/snackbar/ToastContent.js.map +1 -1
- package/dist/snackbar/ToastManager.js.map +1 -1
- package/dist/snackbar/ToastManagerProvider.js.map +1 -1
- package/dist/snackbar/snackbarStyles.js.map +1 -1
- package/dist/snackbar/toastContentStyles.js.map +1 -1
- package/dist/snackbar/toastStyles.js.map +1 -1
- package/dist/snackbar/useCurrentToastActions.js.map +1 -1
- package/dist/storage/internalUtils.d.ts +19 -0
- package/dist/storage/internalUtils.js +22 -0
- package/dist/storage/internalUtils.js.map +1 -0
- package/dist/storage/types.d.ts +75 -0
- package/dist/storage/types.js +3 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/storage/useStorage.d.ts +113 -0
- package/dist/storage/useStorage.js +247 -0
- package/dist/storage/useStorage.js.map +1 -0
- package/dist/storage/utils.d.ts +94 -0
- package/dist/storage/utils.js +106 -0
- package/dist/storage/utils.js.map +1 -0
- package/dist/suspense/CircularProgressSuspense.js.map +1 -1
- package/dist/suspense/NullSuspense.js.map +1 -1
- package/dist/table/StickyTableSection.js.map +1 -1
- package/dist/table/Table.js.map +1 -1
- package/dist/table/TableBody.js.map +1 -1
- package/dist/table/TableCell.js +1 -1
- package/dist/table/TableCell.js.map +1 -1
- package/dist/table/TableCellContent.js.map +1 -1
- package/dist/table/TableCheckbox.js.map +1 -1
- package/dist/table/TableConfigurationProvider.js.map +1 -1
- package/dist/table/TableContainer.js.map +1 -1
- package/dist/table/TableContainerProvider.js.map +1 -1
- package/dist/table/TableFooter.js.map +1 -1
- package/dist/table/TableHeader.js.map +1 -1
- package/dist/table/TableRadio.js.map +1 -1
- package/dist/table/TableRow.js.map +1 -1
- package/dist/table/_table.scss +0 -1
- package/dist/table/tableCellStyles.js.map +1 -1
- package/dist/table/tableFooterStyles.js.map +1 -1
- package/dist/table/tableHeaderStyles.js.map +1 -1
- package/dist/table/tableRowStyles.js.map +1 -1
- package/dist/table/tableStyles.js.map +1 -1
- package/dist/table/useStickyTableSection.js.map +1 -1
- package/dist/table/useTableSectionConfig.js.map +1 -1
- package/dist/tabs/SimpleTabPanel.d.ts +17 -0
- package/dist/tabs/SimpleTabPanel.js +21 -0
- package/dist/tabs/SimpleTabPanel.js.map +1 -0
- package/dist/tabs/SimpleTabPanels.d.ts +17 -0
- package/dist/tabs/SimpleTabPanels.js +18 -0
- package/dist/tabs/SimpleTabPanels.js.map +1 -0
- package/dist/tabs/Tab.js.map +1 -1
- package/dist/tabs/TabList.d.ts +8 -25
- package/dist/tabs/TabList.js +4 -6
- package/dist/tabs/TabList.js.map +1 -1
- package/dist/tabs/TabListScrollButton.js +2 -1
- package/dist/tabs/TabListScrollButton.js.map +1 -1
- package/dist/tabs/_tabs.scss +50 -14
- package/dist/tabs/tabIndicatorStyles.js.map +1 -1
- package/dist/tabs/tabListScrollButtonStyles.js.map +1 -1
- package/dist/tabs/tabListStyles.d.ts +9 -0
- package/dist/tabs/tabListStyles.js +2 -1
- package/dist/tabs/tabListStyles.js.map +1 -1
- package/dist/tabs/tabStyles.d.ts +7 -0
- package/dist/tabs/tabStyles.js.map +1 -1
- package/dist/tabs/types.d.ts +25 -0
- package/dist/tabs/types.js +24 -0
- package/dist/tabs/types.js.map +1 -0
- package/dist/tabs/useMaxTabPanelHeight.d.ts +82 -0
- package/dist/tabs/useMaxTabPanelHeight.js +95 -0
- package/dist/tabs/useMaxTabPanelHeight.js.map +1 -0
- package/dist/tabs/useTabList.d.ts +4 -2
- package/dist/tabs/useTabList.js +24 -6
- package/dist/tabs/useTabList.js.map +1 -1
- package/dist/tabs/useTabs.d.ts +53 -68
- package/dist/tabs/useTabs.js +6 -2
- package/dist/tabs/useTabs.js.map +1 -1
- package/dist/tabs/utils.d.ts +4 -0
- package/dist/tabs/utils.js +5 -0
- package/dist/tabs/utils.js.map +1 -1
- package/dist/test-utils/drag.d.ts +1 -0
- package/dist/test-utils/index.d.ts +6 -4
- package/dist/test-utils/index.js +6 -4
- package/dist/test-utils/index.js.map +1 -1
- package/dist/test-utils/jest-globals/index.d.ts +4 -0
- package/dist/test-utils/jest-globals/index.js +6 -0
- package/dist/test-utils/jest-globals/index.js.map +1 -0
- package/dist/test-utils/jest-globals/match-media.d.ts +32 -0
- package/dist/test-utils/jest-globals/match-media.js +35 -0
- package/dist/test-utils/jest-globals/match-media.js.map +1 -0
- package/dist/test-utils/jest-globals/resize-observer.d.ts +5 -0
- package/dist/test-utils/jest-globals/resize-observer.js +10 -0
- package/dist/test-utils/jest-globals/resize-observer.js.map +1 -0
- package/dist/test-utils/jest-globals/setup.d.ts +1 -0
- package/dist/test-utils/{jest-setup.js → jest-globals/setup.js} +4 -3
- package/dist/test-utils/jest-globals/setup.js.map +1 -0
- package/dist/test-utils/{timers.d.ts → jest-globals/timers.d.ts} +2 -2
- package/dist/test-utils/{timers.js → jest-globals/timers.js} +2 -2
- package/dist/test-utils/jest-globals/timers.js.map +1 -0
- package/dist/test-utils/jest-globals/uploadMenuItemFileInput.d.ts +32 -0
- package/dist/test-utils/jest-globals/uploadMenuItemFileInput.js +39 -0
- package/dist/test-utils/jest-globals/uploadMenuItemFileInput.js.map +1 -0
- package/dist/test-utils/mocks/IntersectionObserver.js.map +1 -0
- package/dist/test-utils/{ResizeObserver.d.ts → mocks/ResizeObserver.d.ts} +16 -23
- package/dist/test-utils/{ResizeObserver.js → mocks/ResizeObserver.js} +17 -38
- package/dist/test-utils/mocks/ResizeObserver.js.map +1 -0
- package/dist/test-utils/mocks/match-media-implementation.d.ts +42 -0
- package/dist/test-utils/mocks/match-media-implementation.js +46 -0
- package/dist/test-utils/mocks/match-media-implementation.js.map +1 -0
- package/dist/test-utils/mocks/match-media.d.ts +32 -0
- package/dist/test-utils/mocks/match-media.js +39 -0
- package/dist/test-utils/mocks/match-media.js.map +1 -0
- package/dist/test-utils/polyfills/IntersectionObserver.js +1 -1
- package/dist/test-utils/polyfills/IntersectionObserver.js.map +1 -1
- package/dist/test-utils/polyfills/ResizeObserver.js +1 -1
- package/dist/test-utils/polyfills/ResizeObserver.js.map +1 -1
- package/dist/test-utils/polyfills/matchMedia.js +1 -1
- package/dist/test-utils/polyfills/matchMedia.js.map +1 -1
- package/dist/test-utils/queries/index.d.ts +2 -0
- package/dist/test-utils/queries/index.js +4 -0
- package/dist/test-utils/queries/index.js.map +1 -0
- package/dist/test-utils/queries/select.d.ts +67 -0
- package/dist/test-utils/queries/select.js +69 -0
- package/dist/test-utils/queries/select.js.map +1 -0
- package/dist/test-utils/queries/slider.d.ts +126 -0
- package/dist/test-utils/queries/slider.js +136 -0
- package/dist/test-utils/queries/slider.js.map +1 -0
- package/dist/test-utils/queries/types.d.ts +8 -0
- package/dist/test-utils/queries/types.js +5 -0
- package/dist/test-utils/queries/types.js.map +1 -0
- package/dist/test-utils/render.js.map +1 -1
- package/dist/test-utils/utils/createFileList.d.ts +4 -0
- package/dist/test-utils/utils/createFileList.js +27 -0
- package/dist/test-utils/utils/createFileList.js.map +1 -0
- package/dist/test-utils/utils/createResizeObserverEntry.d.ts +18 -0
- package/dist/test-utils/utils/createResizeObserverEntry.js +33 -0
- package/dist/test-utils/utils/createResizeObserverEntry.js.map +1 -0
- package/dist/test-utils/vitest/index.d.ts +4 -0
- package/dist/test-utils/vitest/index.js +6 -0
- package/dist/test-utils/vitest/index.js.map +1 -0
- package/dist/test-utils/vitest/match-media.d.ts +32 -0
- package/dist/test-utils/vitest/match-media.js +35 -0
- package/dist/test-utils/vitest/match-media.js.map +1 -0
- package/dist/test-utils/vitest/resize-observer.d.ts +5 -0
- package/dist/test-utils/vitest/resize-observer.js +10 -0
- package/dist/test-utils/vitest/resize-observer.js.map +1 -0
- package/dist/test-utils/vitest/setup.d.ts +1 -0
- package/dist/test-utils/vitest/setup.js +14 -0
- package/dist/test-utils/vitest/setup.js.map +1 -0
- package/dist/test-utils/vitest/timers.d.ts +42 -0
- package/dist/test-utils/vitest/timers.js +42 -0
- package/dist/test-utils/vitest/timers.js.map +1 -0
- package/dist/test-utils/vitest/uploadMenuItemFileInput.d.ts +32 -0
- package/dist/test-utils/vitest/uploadMenuItemFileInput.js +39 -0
- package/dist/test-utils/vitest/uploadMenuItemFileInput.js.map +1 -0
- package/dist/theme/LocalStorageColorSchemeProvider.d.ts +17 -17
- package/dist/theme/LocalStorageColorSchemeProvider.js +19 -19
- package/dist/theme/LocalStorageColorSchemeProvider.js.map +1 -1
- package/dist/theme/ThemeProvider.d.ts +2 -2
- package/dist/theme/ThemeProvider.js +4 -4
- package/dist/theme/ThemeProvider.js.map +1 -1
- package/dist/theme/_theme.scss +0 -4
- package/dist/theme/isColorScheme.d.ts +5 -5
- package/dist/theme/isColorScheme.js +5 -5
- package/dist/theme/isColorScheme.js.map +1 -1
- package/dist/theme/types.d.ts +10 -22
- package/dist/theme/types.js.map +1 -1
- package/dist/theme/useCSSVariables.d.ts +8 -15
- package/dist/theme/useCSSVariables.js.map +1 -1
- package/dist/theme/useColorScheme.d.ts +15 -13
- package/dist/theme/useColorScheme.js +17 -15
- package/dist/theme/useColorScheme.js.map +1 -1
- package/dist/theme/useColorSchemeMetaTag.d.ts +15 -2
- package/dist/theme/useColorSchemeMetaTag.js +13 -0
- package/dist/theme/useColorSchemeMetaTag.js.map +1 -1
- package/dist/theme/useColorSchemeProvider.d.ts +18 -20
- package/dist/theme/useColorSchemeProvider.js +13 -13
- package/dist/theme/useColorSchemeProvider.js.map +1 -1
- package/dist/theme/{usePrefersDarkScheme.js → usePrefersDarkTheme.js} +1 -1
- package/dist/theme/usePrefersDarkTheme.js.map +1 -0
- package/dist/tooltip/Tooltip.js.map +1 -1
- package/dist/tooltip/TooltipHoverModeProvider.js.map +1 -1
- package/dist/tooltip/tooltipStyles.js.map +1 -1
- package/dist/tooltip/useTooltip.d.ts +5 -2
- package/dist/tooltip/useTooltip.js.map +1 -1
- package/dist/tooltip/useTooltipPosition.js.map +1 -1
- package/dist/transition/CSSTransition.js.map +1 -1
- package/dist/transition/Collapse.js.map +1 -1
- package/dist/transition/CrossFade.d.ts +1 -1
- package/dist/transition/CrossFade.js +1 -1
- package/dist/transition/CrossFade.js.map +1 -1
- package/dist/transition/ScaleTransition.js.map +1 -1
- package/dist/transition/SkeletonPlaceholder.js.map +1 -1
- package/dist/transition/Slide.js.map +1 -1
- package/dist/transition/SlideContainer.js.map +1 -1
- package/dist/transition/collapseStyles.js.map +1 -1
- package/dist/transition/config.d.ts +4 -1
- package/dist/transition/config.js.map +1 -1
- package/dist/transition/maxWidthTransition.d.ts +6 -0
- package/dist/transition/maxWidthTransition.js +3 -1
- package/dist/transition/maxWidthTransition.js.map +1 -1
- package/dist/transition/skeletonPlaceholderUtils.js.map +1 -1
- package/dist/transition/types.d.ts +0 -1
- package/dist/transition/types.js.map +1 -1
- package/dist/transition/useCSSTransition.d.ts +8 -4
- package/dist/transition/useCSSTransition.js +8 -4
- package/dist/transition/useCSSTransition.js.map +1 -1
- package/dist/transition/useCarousel.js.map +1 -1
- package/dist/transition/useCollapseTransition.d.ts +13 -8
- package/dist/transition/useCollapseTransition.js +11 -6
- package/dist/transition/useCollapseTransition.js.map +1 -1
- package/dist/transition/useCrossFadeTransition.js.map +1 -1
- package/dist/transition/useMaxWidthTransition.d.ts +9 -0
- package/dist/transition/useMaxWidthTransition.js +9 -0
- package/dist/transition/useMaxWidthTransition.js.map +1 -1
- package/dist/transition/useScaleTransition.d.ts +27 -6
- package/dist/transition/useScaleTransition.js +4 -2
- package/dist/transition/useScaleTransition.js.map +1 -1
- package/dist/transition/useSkeletonPlaceholder.d.ts +16 -0
- package/dist/transition/useSkeletonPlaceholder.js +13 -1
- package/dist/transition/useSkeletonPlaceholder.js.map +1 -1
- package/dist/transition/useSlideTransition.d.ts +12 -16
- package/dist/transition/useSlideTransition.js +12 -16
- package/dist/transition/useSlideTransition.js.map +1 -1
- package/dist/transition/useTransition.js +1 -1
- package/dist/transition/useTransition.js.map +1 -1
- package/dist/tree/DefaultTreeItemRenderer.js.map +1 -1
- package/dist/tree/Tree.js.map +1 -1
- package/dist/tree/TreeGroup.js.map +1 -1
- package/dist/tree/TreeItem.js.map +1 -1
- package/dist/tree/TreeItemExpander.js +1 -1
- package/dist/tree/TreeItemExpander.js.map +1 -1
- package/dist/tree/TreeProvider.js.map +1 -1
- package/dist/tree/_tree.scss +0 -1
- package/dist/tree/styles.js.map +1 -1
- package/dist/tree/types.js.map +1 -1
- package/dist/tree/useTree.js.map +1 -1
- package/dist/tree/useTreeExpansion.js.map +1 -1
- package/dist/tree/useTreeItems.d.ts +1 -1
- package/dist/tree/useTreeItems.js.map +1 -1
- package/dist/tree/useTreeMovement.js.map +1 -1
- package/dist/tree/useTreeSelection.js.map +1 -1
- package/dist/typography/SrOnly.js.map +1 -1
- package/dist/typography/TextContainer.js.map +1 -1
- package/dist/typography/Typography.js.map +1 -1
- package/dist/typography/WritingDirectionProvider.js.map +1 -1
- package/dist/typography/textContainerStyles.js.map +1 -1
- package/dist/typography/typographyStyles.js.map +1 -1
- package/dist/useAsyncFunction.d.ts +20 -0
- package/dist/useAsyncFunction.js.map +1 -1
- package/dist/useDebouncedFunction.js.map +1 -1
- package/dist/useDropzone.d.ts +18 -11
- package/dist/useDropzone.js +27 -23
- package/dist/useDropzone.js.map +1 -1
- package/dist/useElementSize.d.ts +3 -3
- package/dist/useElementSize.js +1 -1
- package/dist/useElementSize.js.map +1 -1
- package/dist/useEnsuredId.d.ts +1 -1
- package/dist/useEnsuredId.js +1 -1
- package/dist/useEnsuredId.js.map +1 -1
- package/dist/useEnsuredRef.d.ts +1 -1
- package/dist/useEnsuredRef.js +1 -1
- package/dist/useEnsuredRef.js.map +1 -1
- package/dist/useEnsuredState.js.map +1 -1
- package/dist/useHtmlClassName.d.ts +11 -0
- package/dist/useHtmlClassName.js +11 -0
- package/dist/useHtmlClassName.js.map +1 -1
- package/dist/useIntersectionObserver.d.ts +3 -3
- package/dist/useIntersectionObserver.js +2 -2
- package/dist/useIntersectionObserver.js.map +1 -1
- package/dist/useIsomorphicLayoutEffect.js.map +1 -1
- package/dist/useMutationObserver.d.ts +3 -3
- package/dist/useMutationObserver.js +4 -4
- package/dist/useMutationObserver.js.map +1 -1
- package/dist/useOrientation.d.ts +0 -1
- package/dist/useOrientation.js +0 -1
- package/dist/useOrientation.js.map +1 -1
- package/dist/usePageInactive.d.ts +7 -2
- package/dist/usePageInactive.js +7 -2
- package/dist/usePageInactive.js.map +1 -1
- package/dist/useReadonlySet.d.ts +5 -4
- package/dist/useReadonlySet.js +4 -3
- package/dist/useReadonlySet.js.map +1 -1
- package/dist/useResizeListener.d.ts +6 -4
- package/dist/useResizeListener.js +6 -4
- package/dist/useResizeListener.js.map +1 -1
- package/dist/useResizeObserver.d.ts +1 -1
- package/dist/useResizeObserver.js +1 -1
- package/dist/useResizeObserver.js.map +1 -1
- package/dist/useThrottledFunction.js.map +1 -1
- package/dist/useToggle.d.ts +3 -3
- package/dist/useToggle.js +3 -3
- package/dist/useToggle.js.map +1 -1
- package/dist/useUnmounted.js.map +1 -1
- package/dist/useWindowSize.d.ts +1 -1
- package/dist/useWindowSize.js +1 -1
- package/dist/useWindowSize.js.map +1 -1
- package/dist/utils/RenderRecursively.d.ts +88 -32
- package/dist/utils/RenderRecursively.js +88 -32
- package/dist/utils/RenderRecursively.js.map +1 -1
- package/dist/utils/alphaNumericSort.d.ts +5 -0
- package/dist/utils/alphaNumericSort.js +5 -4
- package/dist/utils/alphaNumericSort.js.map +1 -1
- package/dist/utils/bem.d.ts +49 -6
- package/dist/utils/bem.js +5 -14
- package/dist/utils/bem.js.map +1 -1
- package/dist/utils/getRangeDefaultValue.js.map +1 -1
- package/dist/utils/isElementVisible.d.ts +1 -1
- package/dist/utils/isElementVisible.js +1 -1
- package/dist/utils/isElementVisible.js.map +1 -1
- package/dist/utils/loop.d.ts +2 -0
- package/dist/utils/loop.js.map +1 -1
- package/dist/utils/parseCssLengthUnit.d.ts +1 -1
- package/dist/utils/parseCssLengthUnit.js.map +1 -1
- package/dist/utils/wait.d.ts +4 -4
- package/dist/utils/wait.js +6 -4
- package/dist/utils/wait.js.map +1 -1
- package/dist/window-splitter/WindowSplitter.js.map +1 -1
- package/dist/window-splitter/styles.js.map +1 -1
- package/dist/window-splitter/useWindowSplitter.d.ts +4 -1
- package/dist/window-splitter/useWindowSplitter.js +4 -1
- package/dist/window-splitter/useWindowSplitter.js.map +1 -1
- package/package.json +26 -22
- package/src/CoreProviders.tsx +8 -6
- package/src/NoSsr.tsx +3 -1
- package/src/RootHtml.tsx +1 -0
- package/src/SsrProvider.tsx +3 -2
- package/src/app-bar/AppBar.tsx +3 -2
- package/src/app-bar/AppBarTitle.tsx +1 -0
- package/src/app-bar/styles.ts +1 -0
- package/src/autocomplete/Autocomplete.tsx +2 -0
- package/src/autocomplete/AutocompleteChip.tsx +2 -1
- package/src/autocomplete/AutocompleteCircularProgress.tsx +1 -0
- package/src/autocomplete/AutocompleteClearButton.tsx +3 -1
- package/src/autocomplete/AutocompleteDropdownButton.tsx +3 -1
- package/src/autocomplete/AutocompleteListboxChildren.tsx +2 -0
- package/src/autocomplete/autocompleteStyles.ts +1 -0
- package/src/autocomplete/types.ts +1 -0
- package/src/autocomplete/useAutocomplete.ts +4 -2
- package/src/autocomplete/utils.ts +1 -0
- package/src/avatar/Avatar.tsx +3 -2
- package/src/avatar/styles.ts +2 -1
- package/src/badge/Badge.tsx +3 -2
- package/src/badge/styles.ts +1 -0
- package/src/box/Box.tsx +5 -2
- package/src/box/styles.ts +17 -2
- package/src/button/AsyncButton.tsx +3 -1
- package/src/button/Button.tsx +4 -2
- package/src/button/ButtonUnstyled.tsx +2 -1
- package/src/button/FloatingActionButton.tsx +2 -1
- package/src/button/TooltippedButton.tsx +4 -2
- package/src/button/buttonStyles.ts +2 -1
- package/src/card/Card.tsx +10 -23
- package/src/card/CardContent.tsx +3 -2
- package/src/card/CardFooter.tsx +1 -0
- package/src/card/CardHeader.tsx +2 -1
- package/src/card/CardSubtitle.tsx +1 -0
- package/src/card/CardTitle.tsx +1 -0
- package/src/card/ClickableCard.tsx +3 -1
- package/src/card/styles.ts +1 -0
- package/src/chip/Chip.tsx +4 -2
- package/src/chip/styles.ts +1 -0
- package/src/dialog/Dialog.tsx +10 -6
- package/src/dialog/DialogContent.tsx +3 -2
- package/src/dialog/DialogFooter.tsx +3 -2
- package/src/dialog/DialogHeader.tsx +2 -1
- package/src/dialog/DialogTitle.tsx +2 -1
- package/src/dialog/FixedDialog.tsx +14 -9
- package/src/dialog/NestedDialogProvider.ts +1 -0
- package/src/dialog/styles.ts +5 -4
- package/src/divider/Divider.tsx +3 -2
- package/src/divider/styles.ts +1 -0
- package/src/draggable/useDraggable.ts +25 -12
- package/src/draggable/utils.ts +2 -1
- package/src/expansion-panel/ExpansionList.tsx +3 -1
- package/src/expansion-panel/ExpansionPanel.tsx +3 -1
- package/src/expansion-panel/ExpansionPanelHeader.tsx +3 -2
- package/src/expansion-panel/expansionPanelStyles.ts +1 -0
- package/src/expansion-panel/useExpansionList.ts +2 -0
- package/src/expansion-panel/useExpansionPanels.ts +1 -0
- package/src/files/FileInput.tsx +4 -2
- package/src/files/styles.ts +1 -0
- package/src/files/useFileUpload.ts +7 -5
- package/src/files/utils.ts +31 -1
- package/src/focus/useFocusContainer.ts +10 -10
- package/src/form/Checkbox.tsx +2 -1
- package/src/form/Fieldset.tsx +2 -1
- package/src/form/Form.tsx +2 -1
- package/src/form/FormMessage.tsx +1 -0
- package/src/form/FormMessageContainer.tsx +2 -1
- package/src/form/FormMessageCounter.tsx +1 -0
- package/src/form/InputToggle.tsx +3 -1
- package/src/form/InputToggleIcon.tsx +4 -3
- package/src/form/Label.tsx +1 -0
- package/src/form/Legend.tsx +1 -0
- package/src/form/Listbox.tsx +1 -0
- package/src/form/ListboxProvider.ts +2 -0
- package/src/form/MenuItemCheckbox.tsx +5 -3
- package/src/form/MenuItemFileInput.tsx +25 -13
- package/src/form/MenuItemInputToggle.tsx +3 -1
- package/src/form/MenuItemRadio.tsx +4 -2
- package/src/form/MenuItemSwitch.tsx +2 -0
- package/src/form/MenuItemTextField.tsx +3 -1
- package/src/form/NativeSelect.tsx +3 -2
- package/src/form/OptGroup.tsx +3 -1
- package/src/form/Option.tsx +6 -4
- package/src/form/Password.tsx +5 -3
- package/src/form/Radio.tsx +2 -0
- package/src/form/ResizingTextAreaWrapper.tsx +2 -1
- package/src/form/Select.tsx +6 -4
- package/src/form/SelectedOption.tsx +1 -0
- package/src/form/Slider.tsx +13 -71
- package/src/form/SliderContainer.tsx +2 -1
- package/src/form/SliderMark.tsx +1 -0
- package/src/form/SliderMarkLabel.tsx +2 -1
- package/src/form/SliderThumb.tsx +6 -3
- package/src/form/SliderTrack.tsx +4 -3
- package/src/form/SliderValueMarks.tsx +3 -2
- package/src/form/SliderValueTooltip.tsx +2 -0
- package/src/form/Switch.tsx +2 -1
- package/src/form/SwitchTrack.tsx +2 -1
- package/src/form/TextArea.tsx +4 -2
- package/src/form/TextField.tsx +2 -1
- package/src/form/TextFieldAddon.tsx +1 -0
- package/src/form/TextFieldContainer.tsx +3 -1
- package/src/form/formMessageContainerStyles.ts +1 -0
- package/src/form/formMessageStyles.ts +1 -0
- package/src/form/inputToggleStyles.ts +1 -0
- package/src/form/menuItemInputToggleStyles.ts +1 -0
- package/src/form/nativeSelectStyles.ts +1 -0
- package/src/form/optionStyles.ts +1 -0
- package/src/form/passwordStyles.ts +1 -0
- package/src/form/selectStyles.ts +1 -0
- package/src/form/selectUtils.ts +2 -1
- package/src/form/sliderUtils.ts +8 -7
- package/src/form/switchStyles.ts +1 -0
- package/src/form/textAreaStyles.ts +2 -1
- package/src/form/textFieldContainerStyles.ts +2 -1
- package/src/form/textFieldStyles.ts +1 -0
- package/src/form/types.ts +1 -0
- package/src/form/useCheckboxGroup.ts +4 -2
- package/src/form/useCombobox.ts +4 -2
- package/src/form/useEditableCombobox.ts +2 -0
- package/src/form/useFormReset.ts +4 -2
- package/src/form/useNumberField.ts +3 -1
- package/src/form/useRadioGroup.ts +5 -3
- package/src/form/useRangeSlider.ts +3 -0
- package/src/form/useResizingTextArea.ts +5 -3
- package/src/form/useSelectCombobox.ts +2 -1
- package/src/form/useSlider.ts +3 -3
- package/src/form/useSliderDraggable.ts +71 -0
- package/src/form/useTextField.ts +40 -26
- package/src/form/useTextFieldContainerAddons.ts +4 -2
- package/src/form/validation.ts +2 -0
- package/src/hoverMode/useHoverMode.ts +76 -4
- package/src/hoverMode/useHoverModeProvider.ts +24 -12
- package/src/icon/FontIcon.tsx +3 -2
- package/src/icon/IconRotator.tsx +5 -4
- package/src/icon/MaterialIcon.tsx +3 -2
- package/src/icon/MaterialSymbol.tsx +4 -3
- package/src/icon/SVGIcon.tsx +3 -2
- package/src/icon/TextIconSpacing.tsx +2 -2
- package/src/icon/{iconConfig.tsx → config.tsx} +1 -0
- package/src/icon/materialConfig.ts +1 -0
- package/src/icon/styles.ts +2 -1
- package/src/interaction/Ripple.tsx +2 -0
- package/src/interaction/RippleContainer.tsx +1 -0
- package/src/interaction/UserInteractionModeProvider.tsx +3 -2
- package/src/interaction/useElementInteraction.tsx +39 -36
- package/src/interaction/useHigherContrastChildren.tsx +11 -8
- package/src/interaction/utils.ts +1 -0
- package/src/layout/LayoutAppBar.tsx +2 -0
- package/src/layout/LayoutNav.tsx +4 -2
- package/src/layout/LayoutWindowSplitter.tsx +4 -2
- package/src/layout/Main.tsx +4 -2
- package/src/layout/layoutNavStyles.ts +1 -0
- package/src/layout/layoutWindowSplitterStyles.ts +1 -0
- package/src/layout/mainStyles.ts +1 -0
- package/src/layout/useExpandableLayout.ts +17 -17
- package/src/layout/useHorizontalLayoutTransition.ts +2 -0
- package/src/layout/useLayoutAppBarHeight.ts +3 -1
- package/src/layout/useLayoutTree.ts +6 -3
- package/src/layout/useLayoutWindowSplitter.ts +2 -1
- package/src/layout/useMainTabIndex.ts +1 -0
- package/src/layout/useResizableLayout.ts +14 -17
- package/src/layout/useTemporaryLayout.ts +18 -11
- package/src/link/Link.tsx +3 -2
- package/src/link/SkipToMainContent.tsx +4 -2
- package/src/link/styles.ts +1 -0
- package/src/list/List.tsx +2 -1
- package/src/list/ListItem.tsx +4 -2
- package/src/list/ListItemAddon.tsx +2 -1
- package/src/list/ListItemChildren.tsx +1 -0
- package/src/list/ListItemLink.tsx +4 -2
- package/src/list/ListItemText.tsx +2 -1
- package/src/list/ListSubheader.tsx +2 -1
- package/src/list/listItemStyles.ts +1 -0
- package/src/list/listStyles.ts +1 -0
- package/src/list/types.ts +1 -0
- package/src/media-queries/AppSizeProvider.tsx +7 -5
- package/src/media-queries/useMediaQuery.ts +5 -3
- package/src/menu/DropdownMenu.tsx +5 -3
- package/src/menu/Menu.tsx +8 -6
- package/src/menu/MenuBar.tsx +2 -0
- package/src/menu/MenuButton.tsx +3 -1
- package/src/menu/MenuConfigurationProvider.tsx +4 -2
- package/src/menu/MenuItem.tsx +2 -0
- package/src/menu/MenuItemButton.tsx +3 -1
- package/src/menu/MenuItemCircularProgress.tsx +2 -1
- package/src/menu/MenuItemGroup.tsx +3 -1
- package/src/menu/MenuItemSeparator.tsx +3 -1
- package/src/menu/MenuSheet.tsx +3 -1
- package/src/menu/MenuVisibilityProvider.tsx +4 -2
- package/src/menu/MenuWidget.tsx +3 -1
- package/src/menu/MenuWidgetKeyboardProvider.tsx +2 -0
- package/src/menu/useContextMenu.ts +2 -0
- package/src/menu/useMenuBarProvider.ts +2 -0
- package/src/movement/types.ts +1 -0
- package/src/movement/useKeyboardMovementProvider.ts +2 -0
- package/src/movement/utils.ts +1 -0
- package/src/navigation/CollapsibleNavGroup.tsx +3 -1
- package/src/navigation/DefaultNavigationRenderer.tsx +1 -0
- package/src/navigation/NavGroup.tsx +2 -1
- package/src/navigation/NavItem.tsx +2 -1
- package/src/navigation/NavItemButton.tsx +4 -2
- package/src/navigation/NavItemLink.tsx +4 -2
- package/src/navigation/NavSubheader.tsx +2 -1
- package/src/navigation/Navigation.tsx +3 -2
- package/src/navigation/navGroupStyles.ts +1 -0
- package/src/navigation/navItemStyles.ts +1 -0
- package/src/navigation/types.ts +1 -0
- package/src/navigation/useActiveHeadingId.ts +8 -6
- package/src/navigation/useNavigationExpansion.ts +2 -0
- package/src/navigation/useTableOfContentsHeadings.ts +150 -0
- package/src/objectFit.ts +1 -0
- package/src/overlay/Overlay.tsx +4 -2
- package/src/overlay/overlayStyles.ts +10 -10
- package/src/portal/Portal.tsx +1 -0
- package/src/portal/PortalContainerProvider.tsx +4 -3
- package/src/positioning/createHorizontalPosition.ts +1 -1
- package/src/positioning/createVerticalPosition.ts +1 -1
- package/src/positioning/useFixedPositioning.ts +17 -12
- package/src/progress/CircularProgress.tsx +3 -2
- package/src/progress/LinearProgress.tsx +3 -2
- package/src/responsive-item/ResponsiveItem.tsx +3 -2
- package/src/responsive-item/ResponsiveItemOverlay.tsx +3 -2
- package/src/responsive-item/responsiveItemOverlayStyles.ts +1 -0
- package/src/responsive-item/responsiveItemStyles.ts +1 -0
- package/src/scroll/ScrollLock.tsx +1 -0
- package/src/scroll/useScrollLock.ts +3 -1
- package/src/searching/fuzzy.ts +1 -1
- package/src/searching/useFuzzyMatch.ts +2 -0
- package/src/segmented-button/SegmentedButton.tsx +4 -2
- package/src/segmented-button/SegmentedButtonContainer.tsx +3 -2
- package/src/segmented-button/segmentedButtonContainerStyles.ts +1 -0
- package/src/segmented-button/segmentedButtonStyles.ts +1 -0
- package/src/sheet/Sheet.tsx +4 -2
- package/src/sheet/styles.ts +3 -3
- package/src/snackbar/DefaultToastRenderer.tsx +5 -3
- package/src/snackbar/Snackbar.tsx +4 -2
- package/src/snackbar/Toast.tsx +4 -2
- package/src/snackbar/ToastActionButton.tsx +2 -0
- package/src/snackbar/ToastCloseButton.tsx +3 -1
- package/src/snackbar/ToastContent.tsx +3 -1
- package/src/snackbar/ToastManager.tsx +1 -0
- package/src/snackbar/ToastManagerProvider.tsx +4 -3
- package/src/snackbar/snackbarStyles.ts +1 -0
- package/src/snackbar/toastContentStyles.ts +1 -0
- package/src/snackbar/toastStyles.ts +2 -1
- package/src/snackbar/useCurrentToastActions.ts +1 -0
- package/src/storage/internalUtils.ts +43 -0
- package/src/storage/types.ts +88 -0
- package/src/storage/useStorage.ts +277 -0
- package/src/storage/utils.ts +156 -0
- package/src/suspense/CircularProgressSuspense.tsx +2 -1
- package/src/suspense/NullSuspense.tsx +1 -1
- package/src/table/StickyTableSection.tsx +3 -1
- package/src/table/Table.tsx +3 -1
- package/src/table/TableBody.tsx +3 -1
- package/src/table/TableCell.tsx +4 -2
- package/src/table/TableCellContent.tsx +2 -1
- package/src/table/TableCheckbox.tsx +3 -1
- package/src/table/TableConfigurationProvider.tsx +2 -0
- package/src/table/TableContainer.tsx +4 -2
- package/src/table/TableContainerProvider.tsx +2 -1
- package/src/table/TableFooter.tsx +3 -1
- package/src/table/TableHeader.tsx +3 -1
- package/src/table/TableRadio.tsx +3 -1
- package/src/table/TableRow.tsx +3 -1
- package/src/table/tableCellStyles.ts +1 -0
- package/src/table/tableFooterStyles.ts +1 -0
- package/src/table/tableHeaderStyles.ts +1 -0
- package/src/table/tableRowStyles.ts +1 -0
- package/src/table/tableStyles.ts +1 -0
- package/src/table/useStickyTableSection.tsx +4 -2
- package/src/table/useTableSectionConfig.ts +2 -0
- package/src/tabs/SimpleTabPanel.tsx +35 -0
- package/src/tabs/SimpleTabPanels.tsx +28 -0
- package/src/tabs/Tab.tsx +4 -3
- package/src/tabs/TabList.tsx +38 -51
- package/src/tabs/TabListScrollButton.tsx +6 -3
- package/src/tabs/tabIndicatorStyles.ts +1 -0
- package/src/tabs/tabListScrollButtonStyles.ts +1 -0
- package/src/tabs/tabListStyles.ts +22 -2
- package/src/tabs/tabStyles.ts +8 -0
- package/src/tabs/types.ts +30 -0
- package/src/tabs/useMaxTabPanelHeight.ts +138 -0
- package/src/tabs/useTabList.ts +45 -8
- package/src/tabs/useTabs.ts +64 -79
- package/src/tabs/utils.ts +9 -0
- package/src/test-utils/drag.ts +10 -2
- package/src/test-utils/index.ts +6 -5
- package/src/test-utils/jest-globals/index.ts +4 -0
- package/src/test-utils/jest-globals/match-media.ts +41 -0
- package/src/test-utils/jest-globals/resize-observer.ts +11 -0
- package/src/test-utils/{jest-setup.ts → jest-globals/setup.ts} +4 -2
- package/src/test-utils/{timers.ts → jest-globals/timers.ts} +2 -2
- package/src/test-utils/jest-globals/uploadMenuItemFileInput.ts +52 -0
- package/src/test-utils/{ResizeObserver.ts → mocks/ResizeObserver.ts} +25 -59
- package/src/test-utils/mocks/match-media-implementation.ts +111 -0
- package/src/test-utils/mocks/match-media.ts +63 -0
- package/src/test-utils/polyfills/IntersectionObserver.ts +1 -1
- package/src/test-utils/polyfills/ResizeObserver.ts +1 -1
- package/src/test-utils/polyfills/matchMedia.ts +1 -1
- package/src/test-utils/queries/index.ts +2 -0
- package/src/test-utils/queries/select.ts +116 -0
- package/src/test-utils/queries/slider.ts +247 -0
- package/src/test-utils/queries/types.ts +13 -0
- package/src/test-utils/render.tsx +2 -1
- package/src/test-utils/utils/createFileList.ts +27 -0
- package/src/test-utils/utils/createResizeObserverEntry.ts +47 -0
- package/src/test-utils/vitest/index.ts +4 -0
- package/src/test-utils/vitest/match-media.ts +41 -0
- package/src/test-utils/vitest/resize-observer.ts +11 -0
- package/src/test-utils/vitest/setup.ts +15 -0
- package/src/test-utils/vitest/timers.ts +48 -0
- package/src/test-utils/vitest/uploadMenuItemFileInput.ts +52 -0
- package/src/theme/LocalStorageColorSchemeProvider.tsx +30 -30
- package/src/theme/ThemeProvider.tsx +9 -7
- package/src/theme/isColorScheme.ts +8 -6
- package/src/theme/types.ts +11 -23
- package/src/theme/useCSSVariables.ts +10 -15
- package/src/theme/useColorScheme.ts +19 -15
- package/src/theme/useColorSchemeMetaTag.ts +17 -2
- package/src/theme/useColorSchemeProvider.ts +36 -37
- package/src/theme/{usePrefersDarkScheme.ts → usePrefersDarkTheme.ts} +1 -0
- package/src/tooltip/Tooltip.tsx +3 -1
- package/src/tooltip/TooltipHoverModeProvider.tsx +6 -4
- package/src/tooltip/tooltipStyles.ts +2 -1
- package/src/tooltip/useTooltip.ts +15 -10
- package/src/tooltip/useTooltipPosition.ts +2 -0
- package/src/transition/CSSTransition.tsx +3 -1
- package/src/transition/Collapse.tsx +4 -2
- package/src/transition/CrossFade.tsx +5 -3
- package/src/transition/ScaleTransition.tsx +4 -2
- package/src/transition/SkeletonPlaceholder.tsx +4 -2
- package/src/transition/Slide.tsx +3 -1
- package/src/transition/SlideContainer.tsx +2 -1
- package/src/transition/collapseStyles.ts +1 -0
- package/src/transition/config.ts +4 -1
- package/src/transition/maxWidthTransition.ts +7 -0
- package/src/transition/skeletonPlaceholderUtils.ts +1 -0
- package/src/transition/types.ts +0 -2
- package/src/transition/useCSSTransition.ts +10 -4
- package/src/transition/useCarousel.ts +2 -0
- package/src/transition/useCollapseTransition.ts +20 -14
- package/src/transition/useCrossFadeTransition.ts +1 -0
- package/src/transition/useMaxWidthTransition.ts +11 -0
- package/src/transition/useScaleTransition.ts +12 -10
- package/src/transition/useSkeletonPlaceholder.ts +20 -2
- package/src/transition/useSlideTransition.ts +14 -16
- package/src/transition/useTransition.ts +3 -1
- package/src/tree/DefaultTreeItemRenderer.tsx +1 -0
- package/src/tree/Tree.tsx +3 -1
- package/src/tree/TreeGroup.tsx +3 -1
- package/src/tree/TreeItem.tsx +4 -2
- package/src/tree/TreeItemExpander.tsx +5 -3
- package/src/tree/TreeProvider.tsx +4 -2
- package/src/tree/styles.ts +1 -0
- package/src/tree/types.ts +1 -0
- package/src/tree/useTree.ts +3 -2
- package/src/tree/useTreeExpansion.ts +1 -0
- package/src/tree/useTreeItems.ts +4 -3
- package/src/tree/useTreeMovement.ts +2 -0
- package/src/tree/useTreeSelection.ts +1 -0
- package/src/typography/SrOnly.tsx +2 -1
- package/src/typography/TextContainer.tsx +3 -2
- package/src/typography/Typography.tsx +3 -2
- package/src/typography/WritingDirectionProvider.tsx +4 -2
- package/src/typography/textContainerStyles.ts +1 -0
- package/src/typography/typographyStyles.ts +2 -1
- package/src/useAsyncFunction.ts +23 -0
- package/src/useDebouncedFunction.ts +2 -0
- package/src/useDropzone.ts +50 -34
- package/src/useElementSize.ts +7 -5
- package/src/useEnsuredId.ts +1 -1
- package/src/useEnsuredRef.ts +3 -1
- package/src/useEnsuredState.ts +1 -0
- package/src/useHtmlClassName.ts +12 -0
- package/src/useIntersectionObserver.ts +5 -3
- package/src/useIsomorphicLayoutEffect.ts +1 -0
- package/src/useMutationObserver.ts +7 -6
- package/src/useOrientation.ts +1 -1
- package/src/usePageInactive.ts +8 -2
- package/src/useReadonlySet.ts +7 -4
- package/src/useResizeListener.ts +8 -4
- package/src/useResizeObserver.ts +4 -3
- package/src/useThrottledFunction.ts +2 -0
- package/src/useToggle.ts +5 -3
- package/src/useUnmounted.ts +2 -0
- package/src/useWindowSize.ts +4 -2
- package/src/utils/RenderRecursively.tsx +88 -32
- package/src/utils/alphaNumericSort.ts +10 -4
- package/src/utils/bem.ts +58 -26
- package/src/utils/getRangeDefaultValue.ts +1 -1
- package/src/utils/isElementVisible.ts +1 -1
- package/src/utils/loop.ts +2 -0
- package/src/utils/parseCssLengthUnit.ts +1 -1
- package/src/utils/wait.ts +6 -5
- package/src/window-splitter/WindowSplitter.tsx +2 -2
- package/src/window-splitter/styles.ts +1 -0
- package/src/window-splitter/useWindowSplitter.ts +7 -2
- package/dist/icon/iconConfig.js.map +0 -1
- package/dist/test-utils/IntersectionObserver.js.map +0 -1
- package/dist/test-utils/ResizeObserver.js.map +0 -1
- package/dist/test-utils/jest-setup.d.ts +0 -1
- package/dist/test-utils/jest-setup.js.map +0 -1
- package/dist/test-utils/matchMedia.d.ts +0 -97
- package/dist/test-utils/matchMedia.js +0 -112
- package/dist/test-utils/matchMedia.js.map +0 -1
- package/dist/test-utils/timers.js.map +0 -1
- package/dist/theme/usePrefersDarkScheme.js.map +0 -1
- package/dist/useLocalStorage.d.ts +0 -368
- package/dist/useLocalStorage.js +0 -377
- package/dist/useLocalStorage.js.map +0 -1
- package/src/test-utils/README.md +0 -150
- package/src/test-utils/matchMedia.ts +0 -194
- package/src/useLocalStorage.ts +0 -584
- /package/dist/icon/{iconConfig.d.ts → config.d.ts} +0 -0
- /package/dist/test-utils/{IntersectionObserver.d.ts → mocks/IntersectionObserver.d.ts} +0 -0
- /package/dist/test-utils/{IntersectionObserver.js → mocks/IntersectionObserver.js} +0 -0
- /package/dist/theme/{usePrefersDarkScheme.d.ts → usePrefersDarkTheme.d.ts} +0 -0
- /package/src/test-utils/{IntersectionObserver.ts → mocks/IntersectionObserver.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/typography/typographyStyles.ts"],"sourcesContent":["import { cnb } from \"cnbuilder\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/typography/typographyStyles.ts"],"sourcesContent":["import { cnb } from \"cnbuilder\";\n\nimport { type TextCssUtilsOptions, cssUtils } from \"../cssUtils.js\";\n\n/**\n * A union of all the material design provided typography styles. When used with\n * the Typography component, this will generate the correct typography className\n * to apply and determine what component to be rendered as if none was provided.\n *\n * @since 4.0.0\n */\nexport type TypographyType =\n | \"headline-1\"\n | \"headline-2\"\n | \"headline-3\"\n | \"headline-4\"\n | \"headline-5\"\n | \"headline-6\"\n | \"subtitle-1\"\n | \"subtitle-2\"\n | \"body-1\"\n | \"body-2\"\n | \"caption\"\n | \"overline\";\n\n/** @since 6.0.0 */\nexport interface TypographyClassNameOptions extends TextCssUtilsOptions {\n className?: string;\n\n /**\n * @see {@link TypographyType}\n * @defaultValue `\"body-1\"`\n */\n type?: TypographyType;\n}\n\n/** @since 6.0.0 */\nexport type NullableTypographyClassNameOptions = Omit<\n TypographyClassNameOptions,\n \"type\"\n> & {\n /**\n * When using the {@link typography} class name utility, the `type` can be set\n * to `null` to inherit font.\n *\n * @see {@link TypographyType}\n * @defaultValue `\"body-1\"`\n */\n type?: TypographyType | null;\n};\n\n/**\n * Get a typography class name based on different typography options. This is\n * only useful if you are unable to use the {@link Typography} component for\n * some reason.\n *\n * @example Simple Example\n * ```ts\n * import { typography } from \"@react-md/core\";\n *\n * function Example() {\n * return (\n * <>\n * <h1 className={typography({ type: \"headline-1\" })} />\n * <h2 className={typography({ type: \"headline-2\" })} />\n * <h3 className={typography({ type: \"headline-3\" })} />\n * <h4 className={typography({ type: \"headline-4\" })} />\n * <h5 className={typography({ type: \"headline-5\" })} />\n * <h6 className={typography({ type: \"headline-6\" })} />\n * <h5 className={typography({ type: \"subtitle-1\" })} />\n * <h6 className={typography({ type: \"subtitle-2\" })} />\n * <p className={typography()} />\n * <p className={typography({ type \"body-1\" })} />\n * <p className={typography({ type \"body-1\" })} />\n * <caption className={typography({ type: \"caption\" })} />\n * <span className={typography({ type: \"overline\" })} />\n * </>\n * );\n * }\n * ```\n *\n * @example Applying Additional Styles\n * ```ts\n * import { typography } from \"@react-md/core\";\n *\n * function Example() {\n * return (\n * <>\n * <h1\n * // only maintain the default margin-bottom\n * className={typography({\n * type: \"headline-1\",\n * margin: \"bottom\",\n * })}\n * />\n *\n * <h2\n * // remove all default margin\n * className={typography({\n * type: \"headline-2\",\n * margin: \"none\",\n * })}\n * />\n *\n * <h3\n * // only maintain the default margin-top\n * className={typography({\n * type: \"headline-3\",\n * margin: \"top\",\n * })}\n * />\n *\n * <p\n * // center the text, set to bold, and only maintain default margin-bottom\n * className={typography({\n * type \"subtitle-1\",\n * align: \"center\",\n * margin: \"bottom\",\n * })}\n * />\n * </>\n * );\n * }\n * ```\n *\n * @see {@link Typography}\n * @param options - An optional object of options used to create the typography\n * class name.\n * @returns a typography class name string\n * @since 6.0.0\n */\nexport function typography(\n options: NullableTypographyClassNameOptions = {}\n): string {\n const { type = \"body-1\" } = options;\n\n // using `&&` instead of `bem` since the latest version of typescript does not\n // support setting the same object key (empty string)\n return cnb(\n \"rmd-typography\",\n type && `rmd-typography--${type}`,\n cssUtils(options)\n );\n}\n"],"names":["cnb","cssUtils","typography","options","type"],"mappings":"AAAA,SAASA,GAAG,QAAQ,YAAY;AAEhC,SAAmCC,QAAQ,QAAQ,iBAAiB;AAiDpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+EC,GACD,OAAO,SAASC,WACdC,UAA8C,CAAC,CAAC;IAEhD,MAAM,EAAEC,OAAO,QAAQ,EAAE,GAAGD;IAE5B,8EAA8E;IAC9E,qDAAqD;IACrD,OAAOH,IACL,kBACAI,QAAQ,CAAC,gBAAgB,EAAEA,MAAM,EACjCH,SAASE;AAEb"}
|
|
@@ -19,6 +19,26 @@ export interface AsyncFunctionHookOptions {
|
|
|
19
19
|
*/
|
|
20
20
|
export interface AsyncFunctionHookImplementation {
|
|
21
21
|
pending: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* This ref can be used to prevent setting state on an unmounted component.
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* const { handleAsync, pending, unmounted } = useAsyncFunction();
|
|
27
|
+
*
|
|
28
|
+
* return (
|
|
29
|
+
* <Button
|
|
30
|
+
* onClick={async () => {
|
|
31
|
+
* await handleAsync(someAsyncTaskThatMightUnmountThisComponent);
|
|
32
|
+
* if (!unmounted.current) {
|
|
33
|
+
* // set some local state
|
|
34
|
+
* }
|
|
35
|
+
* }}
|
|
36
|
+
* >
|
|
37
|
+
* Button
|
|
38
|
+
* </Button>
|
|
39
|
+
* );
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
22
42
|
unmounted: NonNullRef<boolean>;
|
|
23
43
|
setPending: UseStateSetter<boolean>;
|
|
24
44
|
handleAsync: HandleAsyncFunction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useAsyncFunction.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useState } from \"react\";\nimport type { NonNullRef, UseStateSetter } from \"./types.js\";\nimport { useUnmounted } from \"./useUnmounted.js\";\n\n/**\n * @since 6.0.0\n */\nexport type AsyncFunction<Args extends unknown[]> = (\n ...args: Args\n) => Promise<void>;\n\n/**\n * @since 6.0.0\n */\nexport type HandleAsyncFunction = <Args extends unknown[]>(\n action: AsyncFunction<Args>\n) => AsyncFunction<Args>;\n\n/**\n * @since 6.0.0\n */\nexport interface AsyncFunctionHookOptions {\n /** @defaultValue `false` */\n disabled?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AsyncFunctionHookImplementation {\n pending: boolean;\n unmounted: NonNullRef<boolean>;\n setPending: UseStateSetter<boolean>;\n handleAsync: HandleAsyncFunction;\n}\n\n/**\n * A simple utility hook for triggering a pending state while an async function\n * is running. This is really only useful if you aren't using something like\n * `react-query`, `@reduxjs/toolkit/query`, `@apollo/client`, etc for API calls\n * which have a built-in pending state for mutations.\n *\n * @example Simple Example (Async Button)\n * ```tsx\n * import type { ButtonProps } from \"@react-md/core\";\n * import { box, Button, CircularProgress, useAsyncFunction } from \"@react-md/core\";\n * import { cnb } from \"cnbuilder\";\n * import type { MouseEvent, ReactElement } from \"react\";\n *\n * import styles from \"./AsyncButton.module.scss\";\n *\n * export interface AsyncButtonProps extends ButtonProps {\n * onClick(event: MouseEvent<HTMLButtonElement>): Promise<void>;\n * }\n *\n * export function AsyncButton(props: AsyncButtonProps): ReactElement {\n * const { onClick, children, theme, className, disabled, ...remaining } = props;\n * const { handleAsync, pending } = useAsyncFunction({ disabled });\n *\n * return (\n * <Button\n * {...remaining}\n * aria-disabled={pending || undefined}\n * disabled={disabled}\n * className={cnb(pending && styles.loading, className)}\n * theme={pending ? \"disabled\" : theme}\n * onClick={handleAsync(onClick)}\n * >\n * {children}\n * {pending && (\n * <span\n * className={box({\n * align: \"center\",\n * disablePadding: true,\n * className: styles.overlay,\n * })}\n * >\n * <CircularProgress />\n * </span>\n * )}\n * </Button>\n * );\n * }\n *\n * // `AsyncButton.module.scss`\n * // hide everything in the button except for the overlay containing the circular\n * // progress\n * .loading > *:not(.overlay) {\n * opacity: 0;\n * }\n *\n * .overlay {\n * border-radius: inherit;\n * box-shadow: inherit;\n * inset: 0;\n * position: absolute;\n * z-index: 1;\n * }\n * ```\n *\n * @example Confirmation Dialog with Overlay\n * ```tsx\n * import {\n * Button,\n * DialogHeader,\n * DialogContent,\n * DialogFooter,\n * Form,\n * useAsyncFunction,\n * } from \"@react-md/core\";\n * import CloseIcon from \"@react-md/material-icons/CloseIcon\";\n * import type { ReactElement } from \"react\";\n * import { useId } from \"react\";\n *\n * interface ExampleProps {\n * hide(); void;\n * submit(): Promise<void>\n * }\n *\n * function Example({ hide, submit }: ExampleProps): ReactElement {\n * const { handleAsync, pending } = useAsyncFunction();\n * const formId = useId();\n *\n * return (\n * <>\n * <DialogHeader>\n * <DialogTitle>Some Title</DialogTitle>\n * <Button aria-label=\"Close\" onClick={hide} disabled={pending}>\n * <CloseIcon />\n * </Button>\n * </DialogHeader>\n * <DialogContent>\n * <Form\n * id={formId}\n * onReset={hide}\n * onSubmit={handleAsync(submit)}\n * >\n * // pretend content\n * </Form>\n * </DialogContent>\n * <DialogFooter>\n * <Button\n * type=\"reset\"\n * form={formId}\n * disabled={pending}\n * >\n * Cancel\n * </Button>\n * <Button\n * type=\"submit\"\n * form={formId}\n * disabled={pending}\n * >\n * Confirm\n * </Button>\n * </DialogFooter>\n * </>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n */\nexport function useAsyncFunction(\n options: AsyncFunctionHookOptions = {}\n): AsyncFunctionHookImplementation {\n const { disabled } = options;\n\n const [pending, setPending] = useState(false);\n const unmounted = useUnmounted();\n\n const handleAsync = useCallback<HandleAsyncFunction>(\n (action) =>\n async (...args) => {\n if (pending || disabled) {\n return;\n }\n\n setPending(true);\n try {\n await action(...args);\n } finally {\n if (!unmounted.current) {\n setPending(false);\n }\n }\n },\n [disabled, pending, unmounted]\n );\n\n return {\n pending,\n unmounted,\n setPending,\n handleAsync,\n };\n}\n"],"names":["useCallback","useState","useUnmounted","useAsyncFunction","options","disabled","pending","setPending","unmounted","handleAsync","action","args","current"],"mappings":"AAAA;
|
|
1
|
+
{"version":3,"sources":["../src/useAsyncFunction.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useState } from \"react\";\n\nimport type { NonNullRef, UseStateSetter } from \"./types.js\";\nimport { useUnmounted } from \"./useUnmounted.js\";\n\n/**\n * @since 6.0.0\n */\nexport type AsyncFunction<Args extends unknown[]> = (\n ...args: Args\n) => Promise<void>;\n\n/**\n * @since 6.0.0\n */\nexport type HandleAsyncFunction = <Args extends unknown[]>(\n action: AsyncFunction<Args>\n) => AsyncFunction<Args>;\n\n/**\n * @since 6.0.0\n */\nexport interface AsyncFunctionHookOptions {\n /** @defaultValue `false` */\n disabled?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AsyncFunctionHookImplementation {\n pending: boolean;\n\n /**\n * This ref can be used to prevent setting state on an unmounted component.\n * @example\n * ```tsx\n * const { handleAsync, pending, unmounted } = useAsyncFunction();\n *\n * return (\n * <Button\n * onClick={async () => {\n * await handleAsync(someAsyncTaskThatMightUnmountThisComponent);\n * if (!unmounted.current) {\n * // set some local state\n * }\n * }}\n * >\n * Button\n * </Button>\n * );\n * ```\n */\n unmounted: NonNullRef<boolean>;\n setPending: UseStateSetter<boolean>;\n handleAsync: HandleAsyncFunction;\n}\n\n/**\n * A simple utility hook for triggering a pending state while an async function\n * is running. This is really only useful if you aren't using something like\n * `react-query`, `@reduxjs/toolkit/query`, `@apollo/client`, etc for API calls\n * which have a built-in pending state for mutations.\n *\n * @example Simple Example (Async Button)\n * ```tsx\n * import type { ButtonProps } from \"@react-md/core\";\n * import { box, Button, CircularProgress, useAsyncFunction } from \"@react-md/core\";\n * import { cnb } from \"cnbuilder\";\n * import type { MouseEvent, ReactElement } from \"react\";\n *\n * import styles from \"./AsyncButton.module.scss\";\n *\n * export interface AsyncButtonProps extends ButtonProps {\n * onClick(event: MouseEvent<HTMLButtonElement>): Promise<void>;\n * }\n *\n * export function AsyncButton(props: AsyncButtonProps): ReactElement {\n * const { onClick, children, theme, className, disabled, ...remaining } = props;\n * const { handleAsync, pending } = useAsyncFunction({ disabled });\n *\n * return (\n * <Button\n * {...remaining}\n * aria-disabled={pending || undefined}\n * disabled={disabled}\n * className={cnb(pending && styles.loading, className)}\n * theme={pending ? \"disabled\" : theme}\n * onClick={handleAsync(onClick)}\n * >\n * {children}\n * {pending && (\n * <span\n * className={box({\n * align: \"center\",\n * disablePadding: true,\n * className: styles.overlay,\n * })}\n * >\n * <CircularProgress />\n * </span>\n * )}\n * </Button>\n * );\n * }\n *\n * // `AsyncButton.module.scss`\n * // hide everything in the button except for the overlay containing the circular\n * // progress\n * .loading > *:not(.overlay) {\n * opacity: 0;\n * }\n *\n * .overlay {\n * border-radius: inherit;\n * box-shadow: inherit;\n * inset: 0;\n * position: absolute;\n * z-index: 1;\n * }\n * ```\n *\n * @example Confirmation Dialog with Overlay\n * ```tsx\n * import {\n * Button,\n * DialogHeader,\n * DialogContent,\n * DialogFooter,\n * Form,\n * useAsyncFunction,\n * } from \"@react-md/core\";\n * import CloseIcon from \"@react-md/material-icons/CloseIcon\";\n * import type { ReactElement } from \"react\";\n * import { useId } from \"react\";\n *\n * interface ExampleProps {\n * hide(); void;\n * submit(): Promise<void>\n * }\n *\n * function Example({ hide, submit }: ExampleProps): ReactElement {\n * const { handleAsync, pending } = useAsyncFunction();\n * const formId = useId();\n *\n * return (\n * <>\n * <DialogHeader>\n * <DialogTitle>Some Title</DialogTitle>\n * <Button aria-label=\"Close\" onClick={hide} disabled={pending}>\n * <CloseIcon />\n * </Button>\n * </DialogHeader>\n * <DialogContent>\n * <Form\n * id={formId}\n * onReset={hide}\n * onSubmit={handleAsync(submit)}\n * >\n * // pretend content\n * </Form>\n * </DialogContent>\n * <DialogFooter>\n * <Button\n * type=\"reset\"\n * form={formId}\n * disabled={pending}\n * >\n * Cancel\n * </Button>\n * <Button\n * type=\"submit\"\n * form={formId}\n * disabled={pending}\n * >\n * Confirm\n * </Button>\n * </DialogFooter>\n * </>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n */\nexport function useAsyncFunction(\n options: AsyncFunctionHookOptions = {}\n): AsyncFunctionHookImplementation {\n const { disabled } = options;\n\n const [pending, setPending] = useState(false);\n const unmounted = useUnmounted();\n\n const handleAsync = useCallback<HandleAsyncFunction>(\n (action) =>\n async (...args) => {\n if (pending || disabled) {\n return;\n }\n\n setPending(true);\n try {\n await action(...args);\n } finally {\n if (!unmounted.current) {\n setPending(false);\n }\n }\n },\n [disabled, pending, unmounted]\n );\n\n return {\n pending,\n unmounted,\n setPending,\n handleAsync,\n };\n}\n"],"names":["useCallback","useState","useUnmounted","useAsyncFunction","options","disabled","pending","setPending","unmounted","handleAsync","action","args","current"],"mappings":"AAAA;AAEA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AAG9C,SAASC,YAAY,QAAQ,oBAAoB;AAuDjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8HC,GACD,OAAO,SAASC,iBACdC,UAAoC,CAAC,CAAC;IAEtC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;IAErB,MAAM,CAACE,SAASC,WAAW,GAAGN,SAAS;IACvC,MAAMO,YAAYN;IAElB,MAAMO,cAAcT,YAClB,CAACU,SACC,OAAO,GAAGC;YACR,IAAIL,WAAWD,UAAU;gBACvB;YACF;YAEAE,WAAW;YACX,IAAI;gBACF,MAAMG,UAAUC;YAClB,SAAU;gBACR,IAAI,CAACH,UAAUI,OAAO,EAAE;oBACtBL,WAAW;gBACb;YACF;QACF,GACF;QAACF;QAAUC;QAASE;KAAU;IAGhC,OAAO;QACLF;QACAE;QACAD;QACAE;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useDebouncedFunction.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { type AnyFunction, type DebouncedFunction } from \"./types.js\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect.js\";\n\n/**\n * Creates a function that will only be called if it has not been called again\n * for X milliseconds.\n *\n * @example Debounced Search API Requests\n * ```tsx\n * import { TextField, useDebouncedFunction, useUnmounted } from \"@react-md/core\";\n * import { useState } from \"react\";\n * import type { ReactElement } from \"react\";\n *\n * interface State {\n * error?: unknown\n * loading: boolean;\n * results?: {\n * // pretend some search results\n * id: string;\n * name: string;\n * }[];\n * }\n *\n * function Example(): ReactElement {\n * const [state, setState] = useState<State>({\n * loading: false,\n * });\n * // this is only required for async actions\n * const unmounted = useUnmounted();\n *\n * // A new search request will be fired once every 500ms as the user types.\n * // can't use the event here since React uses synthetic events\n * const search = useDebouncedFunction(async (q: string) => {\n * setState({\n * loading: true,\n * error: undefined,\n * results: undefined,\n * });\n *\n * try {\n * const response = await fetch('/search', {\n * method: 'POST',\n * headers: {\n * 'Content-Type': 'application/json',\n * },\n * body: JSON.stringify({ q }),\n * });\n * const json = await response.json();\n *\n * if (!unmounted.current) {\n * setState({\n * loading: false,\n * results: json,\n * });\n * }\n * } catch (error) {\n * if (!unmounted.current) {\n * setState({\n * error,\n * loading: false,\n * });\n * }\n * }\n * }, 500);\n *\n * return (\n * <TextField\n * type=\"search\"\n * label=\"Search\"\n * onChange={(event) => search(event.currentTarget.value)}\n * />\n * );\n * }\n * ```\n *\n * @see `useThrottledFunction` for throttle behavior instead. (Call a\n * function at most once every X milliseconds).\n * @since 6.0.0\n */\nexport function useDebouncedFunction<F extends AnyFunction>(\n func: F,\n wait: number\n): DebouncedFunction<F> {\n const timeout = useRef<number | undefined>();\n const funcRef = useRef(func);\n useIsomorphicLayoutEffect(() => {\n funcRef.current = func;\n });\n\n useEffect(() => {\n return () => {\n window.clearTimeout(timeout.current);\n };\n }, []);\n\n return useMemo(() => {\n const debounced: DebouncedFunction<F> = (...args) => {\n window.clearTimeout(timeout.current);\n timeout.current = window.setTimeout(() => {\n funcRef.current(...args);\n }, wait);\n };\n debounced.cancel = () => {\n window.clearTimeout(timeout.current);\n };\n\n return debounced;\n }, [wait]);\n}\n"],"names":["useEffect","useMemo","useRef","useIsomorphicLayoutEffect","useDebouncedFunction","func","wait","timeout","funcRef","current","window","clearTimeout","debounced","args","setTimeout","cancel"],"mappings":"AAAA;
|
|
1
|
+
{"version":3,"sources":["../src/useDebouncedFunction.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useRef } from \"react\";\n\nimport { type AnyFunction, type DebouncedFunction } from \"./types.js\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect.js\";\n\n/**\n * Creates a function that will only be called if it has not been called again\n * for X milliseconds.\n *\n * @example Debounced Search API Requests\n * ```tsx\n * import { TextField, useDebouncedFunction, useUnmounted } from \"@react-md/core\";\n * import { useState } from \"react\";\n * import type { ReactElement } from \"react\";\n *\n * interface State {\n * error?: unknown\n * loading: boolean;\n * results?: {\n * // pretend some search results\n * id: string;\n * name: string;\n * }[];\n * }\n *\n * function Example(): ReactElement {\n * const [state, setState] = useState<State>({\n * loading: false,\n * });\n * // this is only required for async actions\n * const unmounted = useUnmounted();\n *\n * // A new search request will be fired once every 500ms as the user types.\n * // can't use the event here since React uses synthetic events\n * const search = useDebouncedFunction(async (q: string) => {\n * setState({\n * loading: true,\n * error: undefined,\n * results: undefined,\n * });\n *\n * try {\n * const response = await fetch('/search', {\n * method: 'POST',\n * headers: {\n * 'Content-Type': 'application/json',\n * },\n * body: JSON.stringify({ q }),\n * });\n * const json = await response.json();\n *\n * if (!unmounted.current) {\n * setState({\n * loading: false,\n * results: json,\n * });\n * }\n * } catch (error) {\n * if (!unmounted.current) {\n * setState({\n * error,\n * loading: false,\n * });\n * }\n * }\n * }, 500);\n *\n * return (\n * <TextField\n * type=\"search\"\n * label=\"Search\"\n * onChange={(event) => search(event.currentTarget.value)}\n * />\n * );\n * }\n * ```\n *\n * @see `useThrottledFunction` for throttle behavior instead. (Call a\n * function at most once every X milliseconds).\n * @since 6.0.0\n */\nexport function useDebouncedFunction<F extends AnyFunction>(\n func: F,\n wait: number\n): DebouncedFunction<F> {\n const timeout = useRef<number | undefined>();\n const funcRef = useRef(func);\n useIsomorphicLayoutEffect(() => {\n funcRef.current = func;\n });\n\n useEffect(() => {\n return () => {\n window.clearTimeout(timeout.current);\n };\n }, []);\n\n return useMemo(() => {\n const debounced: DebouncedFunction<F> = (...args) => {\n window.clearTimeout(timeout.current);\n timeout.current = window.setTimeout(() => {\n funcRef.current(...args);\n }, wait);\n };\n debounced.cancel = () => {\n window.clearTimeout(timeout.current);\n };\n\n return debounced;\n }, [wait]);\n}\n"],"names":["useEffect","useMemo","useRef","useIsomorphicLayoutEffect","useDebouncedFunction","func","wait","timeout","funcRef","current","window","clearTimeout","debounced","args","setTimeout","cancel"],"mappings":"AAAA;AAEA,SAASA,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AAGnD,SAASC,yBAAyB,QAAQ,iCAAiC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2EC,GACD,OAAO,SAASC,qBACdC,IAAO,EACPC,IAAY;IAEZ,MAAMC,UAAUL;IAChB,MAAMM,UAAUN,OAAOG;IACvBF,0BAA0B;QACxBK,QAAQC,OAAO,GAAGJ;IACpB;IAEAL,UAAU;QACR,OAAO;YACLU,OAAOC,YAAY,CAACJ,QAAQE,OAAO;QACrC;IACF,GAAG,EAAE;IAEL,OAAOR,QAAQ;QACb,MAAMW,YAAkC,CAAC,GAAGC;YAC1CH,OAAOC,YAAY,CAACJ,QAAQE,OAAO;YACnCF,QAAQE,OAAO,GAAGC,OAAOI,UAAU,CAAC;gBAClCN,QAAQC,OAAO,IAAII;YACrB,GAAGP;QACL;QACAM,UAAUG,MAAM,GAAG;YACjBL,OAAOC,YAAY,CAACJ,QAAQE,OAAO;QACrC;QAEA,OAAOG;IACT,GAAG;QAACN;KAAK;AACX"}
|
package/dist/useDropzone.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DragEvent } from "react";
|
|
2
2
|
/**
|
|
3
3
|
* @since 5.1.3
|
|
4
4
|
* @since 6.0.0 The element type is dynamically inferred on each handler
|
|
@@ -15,21 +15,27 @@ export interface DropzoneHandlers {
|
|
|
15
15
|
*/
|
|
16
16
|
export interface DropzoneOptions extends DropzoneHandlers {
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* By default, the `useDropzone` hook will listen to any `dragenter`/`dragover`
|
|
19
|
+
* events on the page and enabling the {@link DragHookReturnValue.isDragging}
|
|
20
|
+
* flag to show that the user is dragging _something_ and they might want to
|
|
21
|
+
* drag that something into the dropzone.
|
|
22
|
+
*
|
|
23
|
+
* So set this option to `true` if that behavior is not required and only
|
|
24
|
+
* drag events on the dropzone element need to be captured.
|
|
20
25
|
*
|
|
21
26
|
* @defaultValue `false`
|
|
22
|
-
* @see {@link
|
|
27
|
+
* @see {@link DropzoneImplementation.isDragging}
|
|
23
28
|
*/
|
|
24
29
|
disableDragging?: boolean;
|
|
25
30
|
}
|
|
26
31
|
/**
|
|
27
32
|
* @since 2.9.0
|
|
28
|
-
* @since 6.0.0
|
|
29
|
-
* `
|
|
30
|
-
* `
|
|
33
|
+
* @since 6.0.0 Renamed from `DropzoneHookReturnValue` to
|
|
34
|
+
* `DropzoneImplementation` to match other naming conventions. Returns an
|
|
35
|
+
* object instead of an ordered array of `[isOver: boolean, dropzoneHandlers:
|
|
36
|
+
* DropzoneHandlers]`. Also returns a new `isDragging` state.
|
|
31
37
|
*/
|
|
32
|
-
export interface
|
|
38
|
+
export interface DropzoneImplementation {
|
|
33
39
|
/**
|
|
34
40
|
* This will be `true` when the user is dragging something over the dropzone
|
|
35
41
|
* target.
|
|
@@ -52,8 +58,9 @@ export interface DropzoneHookReturnValue {
|
|
|
52
58
|
/**
|
|
53
59
|
* @example Simple Example
|
|
54
60
|
* ```tsx
|
|
55
|
-
* import {
|
|
56
|
-
* import
|
|
61
|
+
* import { useFileUpload } from "@react-md/core/files/useFileUpload";
|
|
62
|
+
* import { useDropzone } from "@react-md/core/useDropzone";
|
|
63
|
+
* import { type CSSProperties, type ReactElement } from "react";
|
|
57
64
|
*
|
|
58
65
|
* const style: CSSProperties = {
|
|
59
66
|
* border: '1px solid blue',
|
|
@@ -119,4 +126,4 @@ export interface DropzoneHookReturnValue {
|
|
|
119
126
|
* @since 2.9.0
|
|
120
127
|
* @since 6.0.0 Supports document-level dragging flag;
|
|
121
128
|
*/
|
|
122
|
-
export declare function useDropzone(options: DropzoneOptions):
|
|
129
|
+
export declare function useDropzone(options: DropzoneOptions): DropzoneImplementation;
|
package/dist/useDropzone.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useToggle } from "./useToggle.js";
|
|
3
4
|
const noop = ()=>{
|
|
4
5
|
// do nothing
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
7
8
|
* @example Simple Example
|
|
8
9
|
* ```tsx
|
|
9
|
-
* import {
|
|
10
|
-
* import
|
|
10
|
+
* import { useFileUpload } from "@react-md/core/files/useFileUpload";
|
|
11
|
+
* import { useDropzone } from "@react-md/core/useDropzone";
|
|
12
|
+
* import { type CSSProperties, type ReactElement } from "react";
|
|
11
13
|
*
|
|
12
14
|
* const style: CSSProperties = {
|
|
13
15
|
* border: '1px solid blue',
|
|
@@ -75,36 +77,35 @@ const noop = ()=>{
|
|
|
75
77
|
*/ export function useDropzone(options) {
|
|
76
78
|
const { onDrop, onDragOver = noop, onDragEnter = noop, onDragLeave = noop, disableDragging = false } = options;
|
|
77
79
|
const [isOver, setOver] = useState(false);
|
|
78
|
-
const
|
|
80
|
+
const { toggled: isDragging, enable: startDragging, disable: stopDragging } = useToggle();
|
|
79
81
|
const draggingTimeout = useRef();
|
|
82
|
+
// Browsers sometimes don't trigger a dragleave event for the entire
|
|
83
|
+
// document, so we have to work around that by using the `dragover` event
|
|
84
|
+
// instead. The `dragover` event will continually fire within the window
|
|
85
|
+
// until the user drops the file or moves the file outside of the window.
|
|
86
|
+
const delayedStopDragging = useCallback(()=>{
|
|
87
|
+
window.clearTimeout(draggingTimeout.current);
|
|
88
|
+
draggingTimeout.current = window.setTimeout(()=>{
|
|
89
|
+
stopDragging();
|
|
90
|
+
}, 100);
|
|
91
|
+
}, [
|
|
92
|
+
stopDragging
|
|
93
|
+
]);
|
|
80
94
|
useEffect(()=>{
|
|
81
95
|
if (disableDragging) {
|
|
82
96
|
return;
|
|
83
97
|
}
|
|
84
|
-
const startDragging = ()=>{
|
|
85
|
-
setDragging(true);
|
|
86
|
-
};
|
|
87
|
-
// Browsers sometimes don't trigger a dragleave event for the entire
|
|
88
|
-
// document, so we have to work around that by using the `dragover` event
|
|
89
|
-
// instead. The `dragover` event will continually fire within the window
|
|
90
|
-
// until the user drops the file or moves the file outside of the window.
|
|
91
|
-
//
|
|
92
|
-
// So we can consider the
|
|
93
|
-
const handler = ()=>{
|
|
94
|
-
window.clearTimeout(draggingTimeout.current);
|
|
95
|
-
draggingTimeout.current = window.setTimeout(()=>{
|
|
96
|
-
setDragging(false);
|
|
97
|
-
}, 100);
|
|
98
|
-
};
|
|
99
98
|
window.addEventListener("dragenter", startDragging);
|
|
100
|
-
window.addEventListener("dragover",
|
|
99
|
+
window.addEventListener("dragover", delayedStopDragging);
|
|
101
100
|
return ()=>{
|
|
102
101
|
window.clearTimeout(draggingTimeout.current);
|
|
103
102
|
window.removeEventListener("dragenter", startDragging);
|
|
104
|
-
window.removeEventListener("dragover",
|
|
103
|
+
window.removeEventListener("dragover", delayedStopDragging);
|
|
105
104
|
};
|
|
106
105
|
}, [
|
|
107
|
-
|
|
106
|
+
delayedStopDragging,
|
|
107
|
+
disableDragging,
|
|
108
|
+
startDragging
|
|
108
109
|
]);
|
|
109
110
|
return {
|
|
110
111
|
isOver,
|
|
@@ -123,7 +124,7 @@ const noop = ()=>{
|
|
|
123
124
|
window.clearTimeout(draggingTimeout.current);
|
|
124
125
|
onDrop(event);
|
|
125
126
|
setOver(false);
|
|
126
|
-
|
|
127
|
+
stopDragging();
|
|
127
128
|
},
|
|
128
129
|
onDragOver (event) {
|
|
129
130
|
event.preventDefault();
|
|
@@ -143,6 +144,9 @@ const noop = ()=>{
|
|
|
143
144
|
event.stopPropagation();
|
|
144
145
|
onDragLeave(event);
|
|
145
146
|
setOver(false);
|
|
147
|
+
// this stops dragging if the user's File Explorer is somewhat above the dropzone
|
|
148
|
+
// and drags out into the File Explorer
|
|
149
|
+
delayedStopDragging();
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
152
|
};
|
package/dist/useDropzone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useDropzone.ts"],"sourcesContent":["\"use client\";\nimport type
|
|
1
|
+
{"version":3,"sources":["../src/useDropzone.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type DragEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\n\nimport { useToggle } from \"./useToggle.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * @since 5.1.3\n * @since 6.0.0 The element type is dynamically inferred on each handler\n * instead of the `DropzoneHandlers` type.\n */\nexport interface DropzoneHandlers {\n onDrop: <E extends HTMLElement>(event: DragEvent<E>) => void;\n onDragEnter?: <E extends HTMLElement>(event: DragEvent<E>) => void;\n onDragOver?: <E extends HTMLElement>(event: DragEvent<E>) => void;\n onDragLeave?: <E extends HTMLElement>(event: DragEvent<E>) => void;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface DropzoneOptions extends DropzoneHandlers {\n /**\n * By default, the `useDropzone` hook will listen to any `dragenter`/`dragover`\n * events on the page and enabling the {@link DragHookReturnValue.isDragging}\n * flag to show that the user is dragging _something_ and they might want to\n * drag that something into the dropzone.\n *\n * So set this option to `true` if that behavior is not required and only\n * drag events on the dropzone element need to be captured.\n *\n * @defaultValue `false`\n * @see {@link DropzoneImplementation.isDragging}\n */\n disableDragging?: boolean;\n}\n\n/**\n * @since 2.9.0\n * @since 6.0.0 Renamed from `DropzoneHookReturnValue` to\n * `DropzoneImplementation` to match other naming conventions. Returns an\n * object instead of an ordered array of `[isOver: boolean, dropzoneHandlers:\n * DropzoneHandlers]`. Also returns a new `isDragging` state.\n */\nexport interface DropzoneImplementation {\n /**\n * This will be `true` when the user is dragging something over the dropzone\n * target.\n */\n isOver: boolean;\n\n /**\n * This will be `true` when the user is dragging anything within the document.\n * The main use case for this is detecting when a user is dragging a file into\n * the document so you can help highlight the dropzone area.\n *\n * This will always be `false` if {@link DropzoneOptions.disableDragging} is\n * `true`.\n */\n isDragging: boolean;\n\n /**\n * The event handlers that should be passed to the dropzone target.\n */\n dropzoneHandlers: Required<DropzoneHandlers>;\n}\n\n/**\n * @example Simple Example\n * ```tsx\n * import { useFileUpload } from \"@react-md/core/files/useFileUpload\";\n * import { useDropzone } from \"@react-md/core/useDropzone\";\n * import { type CSSProperties, type ReactElement } from \"react\";\n *\n * const style: CSSProperties = {\n * border: '1px solid blue',\n * };\n *\n * function Example(): ReactElement {\n * const { onDrop } = useFileUpload()\n * const { isOver, dropzoneHandlers } = useDropzone({\n * onDrop(event) {\n * // normally use the `onDrop` behavior from `useFileUpload` to upload\n * // files:\n * // onDrop(event);\n * },\n * disableDragging: true,\n * });\n *\n * return (\n * <div {...dropzoneHandlers} style={isOver ? style : {}}>\n * Drag and drop some files!\n * {isOver && <UploadSVGIcon />}\n * </div>\n * );\n * }\n * ```\n *\n * @example Dragging Example\n * ```tsx\n * import { useDropzone, useFileUpload } from \"@react-md/core\"\n * import type { CSSProperties, ReactElement } from \"react\";\n *\n * const draggingStyle: CSSProperties = {\n * backgroundColor: \"orange\",\n * };\n * const overStyle: CSSProperties = {\n * border: '1px solid blue',\n * };\n *\n * function Example(): ReactElement {\n * const { onDrop } = useFileUpload()\n * const { isOver, isDragging, dropzoneHandlers } = useDropzone({\n * onDrop(event) {\n * // normally use the `onDrop` behavior from `useFileUpload` to upload\n * // files:\n * // onDrop(event);\n * },\n * });\n *\n * return (\n * <div\n * {...dropzoneHandlers}\n * style={{\n * ...(isDragging && draggingStyle),\n * ...(isOver && overStyle),\n * }}\n * >\n * Drag and drop some files!\n * {isOver && <UploadSVGIcon />}\n * </div>\n * );\n * }\n * ```\n *\n * @since 2.9.0\n * @since 6.0.0 Supports document-level dragging flag;\n */\nexport function useDropzone(options: DropzoneOptions): DropzoneImplementation {\n const {\n onDrop,\n onDragOver = noop,\n onDragEnter = noop,\n onDragLeave = noop,\n disableDragging = false,\n } = options;\n\n const [isOver, setOver] = useState(false);\n const {\n toggled: isDragging,\n enable: startDragging,\n disable: stopDragging,\n } = useToggle();\n const draggingTimeout = useRef<number | undefined>();\n\n // Browsers sometimes don't trigger a dragleave event for the entire\n // document, so we have to work around that by using the `dragover` event\n // instead. The `dragover` event will continually fire within the window\n // until the user drops the file or moves the file outside of the window.\n const delayedStopDragging = useCallback(() => {\n window.clearTimeout(draggingTimeout.current);\n draggingTimeout.current = window.setTimeout(() => {\n stopDragging();\n }, 100);\n }, [stopDragging]);\n\n useEffect(() => {\n if (disableDragging) {\n return;\n }\n\n window.addEventListener(\"dragenter\", startDragging);\n window.addEventListener(\"dragover\", delayedStopDragging);\n return () => {\n window.clearTimeout(draggingTimeout.current);\n window.removeEventListener(\"dragenter\", startDragging);\n window.removeEventListener(\"dragover\", delayedStopDragging);\n };\n }, [delayedStopDragging, disableDragging, startDragging]);\n\n return {\n isOver,\n isDragging,\n dropzoneHandlers: {\n // Note: need to call `event.stopPropagation()` and\n // `event.preventDefault())` for each of these handlers to prevent the\n // default browser behavior when dropping. Only calling within `onDrop`\n // does not work.\n //\n // i.e. dropping an image would preview that image in the current\n // window/tab instead of triggering the drop event.\n onDrop(event) {\n event.preventDefault();\n event.stopPropagation();\n\n window.clearTimeout(draggingTimeout.current);\n onDrop(event);\n setOver(false);\n stopDragging();\n },\n onDragOver(event) {\n event.preventDefault();\n event.stopPropagation();\n\n window.clearTimeout(draggingTimeout.current);\n onDragOver(event);\n setOver(true);\n },\n onDragEnter(event) {\n event.preventDefault();\n event.stopPropagation();\n\n onDragEnter(event);\n setOver(true);\n },\n onDragLeave(event) {\n event.preventDefault();\n event.stopPropagation();\n\n onDragLeave(event);\n setOver(false);\n // this stops dragging if the user's File Explorer is somewhat above the dropzone\n // and drags out into the File Explorer\n delayedStopDragging();\n },\n },\n };\n}\n"],"names":["useCallback","useEffect","useRef","useState","useToggle","noop","useDropzone","options","onDrop","onDragOver","onDragEnter","onDragLeave","disableDragging","isOver","setOver","toggled","isDragging","enable","startDragging","disable","stopDragging","draggingTimeout","delayedStopDragging","window","clearTimeout","current","setTimeout","addEventListener","removeEventListener","dropzoneHandlers","event","preventDefault","stopPropagation"],"mappings":"AAAA;AAEA,SAEEA,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,QAAQ;AAEf,SAASC,SAAS,QAAQ,iBAAiB;AAE3C,MAAMC,OAAO;AACX,aAAa;AACf;AA+DA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsEC,GACD,OAAO,SAASC,YAAYC,OAAwB;IAClD,MAAM,EACJC,MAAM,EACNC,aAAaJ,IAAI,EACjBK,cAAcL,IAAI,EAClBM,cAAcN,IAAI,EAClBO,kBAAkB,KAAK,EACxB,GAAGL;IAEJ,MAAM,CAACM,QAAQC,QAAQ,GAAGX,SAAS;IACnC,MAAM,EACJY,SAASC,UAAU,EACnBC,QAAQC,aAAa,EACrBC,SAASC,YAAY,EACtB,GAAGhB;IACJ,MAAMiB,kBAAkBnB;IAExB,oEAAoE;IACpE,yEAAyE;IACzE,wEAAwE;IACxE,yEAAyE;IACzE,MAAMoB,sBAAsBtB,YAAY;QACtCuB,OAAOC,YAAY,CAACH,gBAAgBI,OAAO;QAC3CJ,gBAAgBI,OAAO,GAAGF,OAAOG,UAAU,CAAC;YAC1CN;QACF,GAAG;IACL,GAAG;QAACA;KAAa;IAEjBnB,UAAU;QACR,IAAIW,iBAAiB;YACnB;QACF;QAEAW,OAAOI,gBAAgB,CAAC,aAAaT;QACrCK,OAAOI,gBAAgB,CAAC,YAAYL;QACpC,OAAO;YACLC,OAAOC,YAAY,CAACH,gBAAgBI,OAAO;YAC3CF,OAAOK,mBAAmB,CAAC,aAAaV;YACxCK,OAAOK,mBAAmB,CAAC,YAAYN;QACzC;IACF,GAAG;QAACA;QAAqBV;QAAiBM;KAAc;IAExD,OAAO;QACLL;QACAG;QACAa,kBAAkB;YAChB,mDAAmD;YACnD,sEAAsE;YACtE,uEAAuE;YACvE,iBAAiB;YACjB,EAAE;YACF,iEAAiE;YACjE,mDAAmD;YACnDrB,QAAOsB,KAAK;gBACVA,MAAMC,cAAc;gBACpBD,MAAME,eAAe;gBAErBT,OAAOC,YAAY,CAACH,gBAAgBI,OAAO;gBAC3CjB,OAAOsB;gBACPhB,QAAQ;gBACRM;YACF;YACAX,YAAWqB,KAAK;gBACdA,MAAMC,cAAc;gBACpBD,MAAME,eAAe;gBAErBT,OAAOC,YAAY,CAACH,gBAAgBI,OAAO;gBAC3ChB,WAAWqB;gBACXhB,QAAQ;YACV;YACAJ,aAAYoB,KAAK;gBACfA,MAAMC,cAAc;gBACpBD,MAAME,eAAe;gBAErBtB,YAAYoB;gBACZhB,QAAQ;YACV;YACAH,aAAYmB,KAAK;gBACfA,MAAMC,cAAc;gBACpBD,MAAME,eAAe;gBAErBrB,YAAYmB;gBACZhB,QAAQ;gBACR,iFAAiF;gBACjF,uCAAuC;gBACvCQ;YACF;QACF;IACF;AACF"}
|
package/dist/useElementSize.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface ElementSizeImplementation<E extends HTMLElement> extends Elemen
|
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* ```tsx
|
|
26
|
-
* const { height, width, observedOnce }
|
|
26
|
+
* const { height, width, observedOnce } = useElementSize();
|
|
27
27
|
* useCSSVariables(useMemo(() => {
|
|
28
28
|
* if (!observedOnce) {
|
|
29
29
|
* return []
|
|
@@ -31,7 +31,7 @@ export interface ElementSizeImplementation<E extends HTMLElement> extends Elemen
|
|
|
31
31
|
*
|
|
32
32
|
* // something that uses the element's height, width, or both
|
|
33
33
|
* return [{ var: "--something", value: height / width * 0.5 }];
|
|
34
|
-
* }, [height, width, observedOnce]))
|
|
34
|
+
* }, [height, width, observedOnce]));
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
observedOnce: boolean;
|
|
@@ -42,7 +42,7 @@ export interface ElementSizeImplementation<E extends HTMLElement> extends Elemen
|
|
|
42
42
|
*
|
|
43
43
|
* @example Simple Example
|
|
44
44
|
* ```tsx
|
|
45
|
-
* import { useElementSize } from "@react-md/core";
|
|
45
|
+
* import { useElementSize } from "@react-md/core/useElementSize";
|
|
46
46
|
* import { type ReactElement } from "react";
|
|
47
47
|
*
|
|
48
48
|
* function Example(): ReactElement {
|
package/dist/useElementSize.js
CHANGED
|
@@ -7,7 +7,7 @@ import { useResizeObserver } from "./useResizeObserver.js";
|
|
|
7
7
|
*
|
|
8
8
|
* @example Simple Example
|
|
9
9
|
* ```tsx
|
|
10
|
-
* import { useElementSize } from "@react-md/core";
|
|
10
|
+
* import { useElementSize } from "@react-md/core/useElementSize";
|
|
11
11
|
* import { type ReactElement } from "react";
|
|
12
12
|
*
|
|
13
13
|
* function Example(): ReactElement {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useElementSize.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef, useState
|
|
1
|
+
{"version":3,"sources":["../src/useElementSize.ts"],"sourcesContent":["\"use client\";\n\nimport { type RefCallback, useCallback, useRef, useState } from \"react\";\n\nimport { type ElementSize, type UseStateInitializer } from \"./types.js\";\nimport {\n type ResizeObserverHookOptions,\n useResizeObserver,\n} from \"./useResizeObserver.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface ElementSizeOptions<E extends HTMLElement>\n extends Omit<ResizeObserverHookOptions<E>, \"onUpdate\"> {\n /** @defaultValue `{ height: 0, width: 0 }` */\n defaultValue?: UseStateInitializer<ElementSize>;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface ElementSizeImplementation<E extends HTMLElement>\n extends ElementSize {\n elementRef: RefCallback<E>;\n\n /**\n * This will be `true` once the resize observer's callback is triggered at\n * least once.\n *\n * This was added so that generating custom properties that have a reasonable\n * default value set in css don't cause major layout shifts when a default\n * value cannot be provided.\n *\n * @example\n * ```tsx\n * const { height, width, observedOnce } = useElementSize();\n * useCSSVariables(useMemo(() => {\n * if (!observedOnce) {\n * return []\n * }\n *\n * // something that uses the element's height, width, or both\n * return [{ var: \"--something\", value: height / width * 0.5 }];\n * }, [height, width, observedOnce]));\n * ```\n */\n observedOnce: boolean;\n}\n\n/**\n * A small wrapper around the {@link useResizeObserver} hook to calculate the\n * element's size.\n *\n * @example Simple Example\n * ```tsx\n * import { useElementSize } from \"@react-md/core/useElementSize\";\n * import { type ReactElement } from \"react\";\n *\n * function Example(): ReactElement {\n * const { height, width, elementRef } = useElementSize();\n *\n * return (\n * <div ref={elementRef}>\n * {`height: ${height}, width: ${width}`}\n * </div>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n */\nexport function useElementSize<E extends HTMLElement>(\n options: ElementSizeOptions<E> = {}\n): ElementSizeImplementation<E> {\n const { defaultValue } = options;\n\n const observedOnce = useRef(false);\n const [size, setSize] = useState<ElementSize>(() => {\n if (typeof defaultValue === \"function\") {\n return defaultValue();\n }\n\n return (\n defaultValue ?? {\n height: 0,\n width: 0,\n }\n );\n });\n\n const elementRef = useResizeObserver({\n ...options,\n onUpdate: useCallback((entry) => {\n observedOnce.current = true;\n const size = entry.borderBoxSize[0];\n\n setSize({\n height: size.blockSize,\n width: size.inlineSize,\n });\n }, []),\n });\n\n return {\n ...size,\n elementRef,\n observedOnce: observedOnce.current,\n };\n}\n"],"names":["useCallback","useRef","useState","useResizeObserver","useElementSize","options","defaultValue","observedOnce","size","setSize","height","width","elementRef","onUpdate","entry","current","borderBoxSize","blockSize","inlineSize"],"mappings":"AAAA;AAEA,SAA2BA,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAGxE,SAEEC,iBAAiB,QACZ,yBAAyB;AA0ChC;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,SAASC,eACdC,UAAiC,CAAC,CAAC;IAEnC,MAAM,EAAEC,YAAY,EAAE,GAAGD;IAEzB,MAAME,eAAeN,OAAO;IAC5B,MAAM,CAACO,MAAMC,QAAQ,GAAGP,SAAsB;QAC5C,IAAI,OAAOI,iBAAiB,YAAY;YACtC,OAAOA;QACT;QAEA,OACEA,gBAAgB;YACdI,QAAQ;YACRC,OAAO;QACT;IAEJ;IAEA,MAAMC,aAAaT,kBAAkB;QACnC,GAAGE,OAAO;QACVQ,UAAUb,YAAY,CAACc;YACrBP,aAAaQ,OAAO,GAAG;YACvB,MAAMP,OAAOM,MAAME,aAAa,CAAC,EAAE;YAEnCP,QAAQ;gBACNC,QAAQF,KAAKS,SAAS;gBACtBN,OAAOH,KAAKU,UAAU;YACxB;QACF,GAAG,EAAE;IACP;IAEA,OAAO;QACL,GAAGV,IAAI;QACPI;QACAL,cAAcA,aAAaQ,OAAO;IACpC;AACF"}
|
package/dist/useEnsuredId.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @example Simple Example
|
|
6
6
|
* ```tsx
|
|
7
7
|
* import type { HTMLAttributes, ReactElement } from "react";
|
|
8
|
-
* import { useEnsuredId } from "@react-md/core";
|
|
8
|
+
* import { useEnsuredId } from "@react-md/core/useEnsuredId";
|
|
9
9
|
*
|
|
10
10
|
* export function MaterialDesignComponent(props: HTMLAttributes<HTMLDivElement>): ReactElement {
|
|
11
11
|
* const id = useEnsuredId(props.id, "component-name");
|
package/dist/useEnsuredId.js
CHANGED
|
@@ -6,7 +6,7 @@ import { useId } from "react";
|
|
|
6
6
|
* @example Simple Example
|
|
7
7
|
* ```tsx
|
|
8
8
|
* import type { HTMLAttributes, ReactElement } from "react";
|
|
9
|
-
* import { useEnsuredId } from "@react-md/core";
|
|
9
|
+
* import { useEnsuredId } from "@react-md/core/useEnsuredId";
|
|
10
10
|
*
|
|
11
11
|
* export function MaterialDesignComponent(props: HTMLAttributes<HTMLDivElement>): ReactElement {
|
|
12
12
|
* const id = useEnsuredId(props.id, "component-name");
|
package/dist/useEnsuredId.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useEnsuredId.ts"],"sourcesContent":["import { useId } from \"react\";\n\n/**\n * This hook is used to ensure that an `id` has been provided to a component\n * either through props or use the `useId` hook.\n *\n * @example Simple Example\n * ```tsx\n * import type { HTMLAttributes, ReactElement } from \"react\";\n * import { useEnsuredId } from \"@react-md/core\";\n *\n * export function MaterialDesignComponent(props: HTMLAttributes<HTMLDivElement>): ReactElement {\n * const id = useEnsuredId(props.id, \"component-name\");\n *\n * return <div {...props} id={id} />;\n * }\n * ```\n *\n * @since 6.0.0\n * @internal\n */\nexport function useEnsuredId(\n propId: string | undefined,\n prefix: string\n): string {\n const id = useId();\n\n return propId ?? `${prefix}-${id}`;\n}\n"],"names":["useId","useEnsuredId","propId","prefix","id"],"mappings":"AAAA,SAASA,KAAK,QAAQ,QAAQ;AAE9B;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,aACdC,MAA0B,EAC1BC,MAAc;IAEd,MAAMC,KAAKJ;IAEX,OAAOE,UAAU,GAAGC,OAAO,CAAC,EAAEC,IAAI;AACpC"}
|
|
1
|
+
{"version":3,"sources":["../src/useEnsuredId.ts"],"sourcesContent":["import { useId } from \"react\";\n\n/**\n * This hook is used to ensure that an `id` has been provided to a component\n * either through props or use the `useId` hook.\n *\n * @example Simple Example\n * ```tsx\n * import type { HTMLAttributes, ReactElement } from \"react\";\n * import { useEnsuredId } from \"@react-md/core/useEnsuredId\";\n *\n * export function MaterialDesignComponent(props: HTMLAttributes<HTMLDivElement>): ReactElement {\n * const id = useEnsuredId(props.id, \"component-name\");\n *\n * return <div {...props} id={id} />;\n * }\n * ```\n *\n * @since 6.0.0\n * @internal\n */\nexport function useEnsuredId(\n propId: string | undefined,\n prefix: string\n): string {\n const id = useId();\n\n return propId ?? `${prefix}-${id}`;\n}\n"],"names":["useId","useEnsuredId","propId","prefix","id"],"mappings":"AAAA,SAASA,KAAK,QAAQ,QAAQ;AAE9B;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,aACdC,MAA0B,EAC1BC,MAAc;IAEd,MAAMC,KAAKJ;IAEX,OAAOE,UAAU,GAAGC,OAAO,CAAC,EAAEC,IAAI;AACpC"}
|
package/dist/useEnsuredRef.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ export type EnsuredRefs<E extends HTMLElement> = readonly [
|
|
|
16
16
|
*
|
|
17
17
|
* @example Simple Example
|
|
18
18
|
* ```tsx
|
|
19
|
+
* import { useEnsuredRef } from "@react-md/core/useEnsuredRef";
|
|
19
20
|
* import { HTMLAttributes, forwardRef } from "react";
|
|
20
|
-
* import { useEnsuredRef } from "@react-md/core";
|
|
21
21
|
*
|
|
22
22
|
* export type ExampleProps = HTMLAttributes<HTMLDivElement>;
|
|
23
23
|
*
|
package/dist/useEnsuredRef.js
CHANGED
|
@@ -10,8 +10,8 @@ import { applyRef } from "./utils/applyRef.js";
|
|
|
10
10
|
*
|
|
11
11
|
* @example Simple Example
|
|
12
12
|
* ```tsx
|
|
13
|
+
* import { useEnsuredRef } from "@react-md/core/useEnsuredRef";
|
|
13
14
|
* import { HTMLAttributes, forwardRef } from "react";
|
|
14
|
-
* import { useEnsuredRef } from "@react-md/core";
|
|
15
15
|
*
|
|
16
16
|
* export type ExampleProps = HTMLAttributes<HTMLDivElement>;
|
|
17
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useEnsuredRef.ts"],"sourcesContent":["\"use client\";\nimport type { MutableRefObject, Ref, RefCallback } from \"react\";\nimport { useCallback, useRef } from \"react\";\nimport { applyRef } from \"./utils/applyRef.js\";\n\n/**\n * @since 2.3.0\n * @internal\n */\nexport type EnsuredRefs<E extends HTMLElement> = readonly [\n MutableRefObject<E | null>,\n RefCallback<E | null>,\n];\n\n/**\n * This is mostly an internal hook that allows for an optional ref (normally\n * from props or hook options) to be merged with a hook's required `ref`. This\n * will return a MutableRefObject used for DOM manipulation in a custom hook\n * followed by a ref callback function that should be passed to the DOM node\n * that will ensure that both the optional `propRef` and hook ref are updated.\n *\n * @example Simple Example\n * ```tsx\n * import {
|
|
1
|
+
{"version":3,"sources":["../src/useEnsuredRef.ts"],"sourcesContent":["\"use client\";\n\nimport type { MutableRefObject, Ref, RefCallback } from \"react\";\nimport { useCallback, useRef } from \"react\";\n\nimport { applyRef } from \"./utils/applyRef.js\";\n\n/**\n * @since 2.3.0\n * @internal\n */\nexport type EnsuredRefs<E extends HTMLElement> = readonly [\n MutableRefObject<E | null>,\n RefCallback<E | null>,\n];\n\n/**\n * This is mostly an internal hook that allows for an optional ref (normally\n * from props or hook options) to be merged with a hook's required `ref`. This\n * will return a MutableRefObject used for DOM manipulation in a custom hook\n * followed by a ref callback function that should be passed to the DOM node\n * that will ensure that both the optional `propRef` and hook ref are updated.\n *\n * @example Simple Example\n * ```tsx\n * import { useEnsuredRef } from \"@react-md/core/useEnsuredRef\";\n * import { HTMLAttributes, forwardRef } from \"react\";\n *\n * export type ExampleProps = HTMLAttributes<HTMLDivElement>;\n *\n * export const Example = forwardRef<HTMLDivElement, ExampleProps>(function Example(props, ref) {\n * const [nodeRef, refHandler] = useEnsuredRef(ref);\n * useEffect(() => {\n * // do something with nodeRef.current\n * }, [nodeRef])\n *\n * return <div ref={refHandler} />;\n * });\n * ```\n *\n * @since 2.3.0\n * @internal\n */\nexport function useEnsuredRef<E extends HTMLElement>(\n propRef?: Ref<E | null>\n): EnsuredRefs<E> {\n const ref = useRef<E | null>(null);\n const refHandler = useCallback(\n (instance: E | null) => {\n applyRef(instance, propRef);\n ref.current = instance;\n },\n [propRef]\n );\n\n return [ref, refHandler];\n}\n"],"names":["useCallback","useRef","applyRef","useEnsuredRef","propRef","ref","refHandler","instance","current"],"mappings":"AAAA;AAGA,SAASA,WAAW,EAAEC,MAAM,QAAQ,QAAQ;AAE5C,SAASC,QAAQ,QAAQ,sBAAsB;AAW/C;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASC,cACdC,OAAuB;IAEvB,MAAMC,MAAMJ,OAAiB;IAC7B,MAAMK,aAAaN,YACjB,CAACO;QACCL,SAASK,UAAUH;QACnBC,IAAIG,OAAO,GAAGD;IAChB,GACA;QAACH;KAAQ;IAGX,OAAO;QAACC;QAAKC;KAAW;AAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useEnsuredState.ts"],"sourcesContent":["/* eslint-disable react-hooks/rules-of-hooks */\nimport type { Dispatch } from \"react\";\nimport { useState } from \"react\";\nimport type { UseStateInitializer, UseStateSetter } from \"./types.js\";\n\n/**\n * @internal\n * @since 6.0.0\n */\nexport interface EnsuredStateOptions<\n V,\n Setter extends Dispatch<V> | UseStateSetter<V> = UseStateSetter<V>,\n> {\n value?: V;\n setValue?: Setter;\n defaultValue?: UseStateInitializer<V>;\n}\n\n/**\n * This is used to dynamically allow controlling hooks by providing a `value` +\n * `setValue` or defaulting to uncontrolled behavior with local state.\n *\n * @internal\n * @since 6.0.0\n */\nexport function useEnsuredState<\n V,\n Setter extends Dispatch<V> | UseStateSetter<V>,\n>(\n options: EnsuredStateOptions<V, Setter>\n): readonly [value: V, setValue: Setter] {\n const { value, setValue, defaultValue } = options;\n if (typeof value !== \"undefined\" && typeof setValue !== \"undefined\") {\n return [value, setValue];\n }\n\n if (typeof value !== \"undefined\" || typeof setValue !== \"undefined\") {\n throw new Error(\n \"Both a `value` and `setValue` must be defined for controlled components.\"\n );\n }\n\n if (typeof defaultValue === \"undefined\") {\n throw new Error(\n \"A `defaultValue` must be defined for uncontrolled components.\"\n );\n }\n\n return useState(defaultValue) as [value: V, setValue: Setter];\n}\n"],"names":["useState","useEnsuredState","options","value","setValue","defaultValue","Error"],"mappings":"AAAA,6CAA6C,GAE7C,SAASA,QAAQ,QAAQ,QAAQ;
|
|
1
|
+
{"version":3,"sources":["../src/useEnsuredState.ts"],"sourcesContent":["/* eslint-disable react-hooks/rules-of-hooks */\nimport type { Dispatch } from \"react\";\nimport { useState } from \"react\";\n\nimport type { UseStateInitializer, UseStateSetter } from \"./types.js\";\n\n/**\n * @internal\n * @since 6.0.0\n */\nexport interface EnsuredStateOptions<\n V,\n Setter extends Dispatch<V> | UseStateSetter<V> = UseStateSetter<V>,\n> {\n value?: V;\n setValue?: Setter;\n defaultValue?: UseStateInitializer<V>;\n}\n\n/**\n * This is used to dynamically allow controlling hooks by providing a `value` +\n * `setValue` or defaulting to uncontrolled behavior with local state.\n *\n * @internal\n * @since 6.0.0\n */\nexport function useEnsuredState<\n V,\n Setter extends Dispatch<V> | UseStateSetter<V>,\n>(\n options: EnsuredStateOptions<V, Setter>\n): readonly [value: V, setValue: Setter] {\n const { value, setValue, defaultValue } = options;\n if (typeof value !== \"undefined\" && typeof setValue !== \"undefined\") {\n return [value, setValue];\n }\n\n if (typeof value !== \"undefined\" || typeof setValue !== \"undefined\") {\n throw new Error(\n \"Both a `value` and `setValue` must be defined for controlled components.\"\n );\n }\n\n if (typeof defaultValue === \"undefined\") {\n throw new Error(\n \"A `defaultValue` must be defined for uncontrolled components.\"\n );\n }\n\n return useState(defaultValue) as [value: V, setValue: Setter];\n}\n"],"names":["useState","useEnsuredState","options","value","setValue","defaultValue","Error"],"mappings":"AAAA,6CAA6C,GAE7C,SAASA,QAAQ,QAAQ,QAAQ;AAiBjC;;;;;;CAMC,GACD,OAAO,SAASC,gBAIdC,OAAuC;IAEvC,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,YAAY,EAAE,GAAGH;IAC1C,IAAI,OAAOC,UAAU,eAAe,OAAOC,aAAa,aAAa;QACnE,OAAO;YAACD;YAAOC;SAAS;IAC1B;IAEA,IAAI,OAAOD,UAAU,eAAe,OAAOC,aAAa,aAAa;QACnE,MAAM,IAAIE,MACR;IAEJ;IAEA,IAAI,OAAOD,iBAAiB,aAAa;QACvC,MAAM,IAAIC,MACR;IAEJ;IAEA,OAAON,SAASK;AAClB"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* This hook can be used to dynamically apply a single className to the
|
|
3
|
+
* `document.documentElement` (`<html>`) using the `classList` API.
|
|
4
|
+
*
|
|
5
|
+
* @example Main Usage
|
|
6
|
+
* ```tsx
|
|
7
|
+
* function Example() {
|
|
8
|
+
* useHtmlClassName("my-class-name");
|
|
9
|
+
* return null;
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
2
13
|
* @since 6.0.0
|
|
3
14
|
*/
|
|
4
15
|
export declare function useHtmlClassName(className: string): void;
|
package/dist/useHtmlClassName.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
/**
|
|
4
|
+
* This hook can be used to dynamically apply a single className to the
|
|
5
|
+
* `document.documentElement` (`<html>`) using the `classList` API.
|
|
6
|
+
*
|
|
7
|
+
* @example Main Usage
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function Example() {
|
|
10
|
+
* useHtmlClassName("my-class-name");
|
|
11
|
+
* return null;
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
4
15
|
* @since 6.0.0
|
|
5
16
|
*/ export function useHtmlClassName(className) {
|
|
6
17
|
useEffect(()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useHtmlClassName.ts"],"sourcesContent":["\"use client\";\nimport { useEffect } from \"react\";\n\n/**\n * @since 6.0.0\n */\nexport function useHtmlClassName(className: string): void {\n useEffect(() => {\n if (!className) {\n return;\n }\n\n const html = document.documentElement;\n html.classList.add(className);\n return () => {\n html.classList.remove(className);\n };\n }, [className]);\n}\n"],"names":["useEffect","useHtmlClassName","className","html","document","documentElement","classList","add","remove"],"mappings":"AAAA;
|
|
1
|
+
{"version":3,"sources":["../src/useHtmlClassName.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\n\n/**\n * This hook can be used to dynamically apply a single className to the\n * `document.documentElement` (`<html>`) using the `classList` API.\n *\n * @example Main Usage\n * ```tsx\n * function Example() {\n * useHtmlClassName(\"my-class-name\");\n * return null;\n * }\n * ```\n *\n * @since 6.0.0\n */\nexport function useHtmlClassName(className: string): void {\n useEffect(() => {\n if (!className) {\n return;\n }\n\n const html = document.documentElement;\n html.classList.add(className);\n return () => {\n html.classList.remove(className);\n };\n }, [className]);\n}\n"],"names":["useEffect","useHtmlClassName","className","html","document","documentElement","classList","add","remove"],"mappings":"AAAA;AAEA,SAASA,SAAS,QAAQ,QAAQ;AAElC;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,iBAAiBC,SAAiB;IAChDF,UAAU;QACR,IAAI,CAACE,WAAW;YACd;QACF;QAEA,MAAMC,OAAOC,SAASC,eAAe;QACrCF,KAAKG,SAAS,CAACC,GAAG,CAACL;QACnB,OAAO;YACLC,KAAKG,SAAS,CAACE,MAAM,CAACN;QACxB;IACF,GAAG;QAACA;KAAU;AAChB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Ref, type RefCallback, type RefObject } from "react";
|
|
2
2
|
/** @since 6.0.0 */
|
|
3
3
|
export type IntersectionObserverRoot = IntersectionObserverInit["root"];
|
|
4
4
|
/** @since 6.0.0 */
|
|
@@ -176,8 +176,8 @@ export interface IntersectionObserverHookOptions<E extends HTMLElement> extends
|
|
|
176
176
|
* ```tsx
|
|
177
177
|
* // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#a_simple_example
|
|
178
178
|
*
|
|
179
|
-
* import { useIntersectionObserver } from "@react-md/core";
|
|
180
|
-
* import type
|
|
179
|
+
* import { useIntersectionObserver } from "@react-md/core/useIntersectionObserver";
|
|
180
|
+
* import { type ReactElement } from "react";
|
|
181
181
|
* import { useState } from "react";
|
|
182
182
|
*
|
|
183
183
|
* import styles from "./Example.module.scss";
|
|
@@ -6,8 +6,8 @@ import { useEnsuredRef } from "./useEnsuredRef.js";
|
|
|
6
6
|
* ```tsx
|
|
7
7
|
* // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#a_simple_example
|
|
8
8
|
*
|
|
9
|
-
* import { useIntersectionObserver } from "@react-md/core";
|
|
10
|
-
* import type
|
|
9
|
+
* import { useIntersectionObserver } from "@react-md/core/useIntersectionObserver";
|
|
10
|
+
* import { type ReactElement } from "react";
|
|
11
11
|
* import { useState } from "react";
|
|
12
12
|
*
|
|
13
13
|
* import styles from "./Example.module.scss";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useIntersectionObserver.ts"],"sourcesContent":["\"use client\";\nimport type { Ref, RefCallback, RefObject } from \"react\";\nimport { useEffect } from \"react\";\nimport { useEnsuredRef } from \"./useEnsuredRef.js\";\n\n/** @since 6.0.0 */\nexport type IntersectionObserverRoot = IntersectionObserverInit[\"root\"];\n/** @since 6.0.0 */\nexport type IntersectionObserverThreshold =\n IntersectionObserverInit[\"threshold\"];\n/** @since 6.0.0 */\nexport type IntersectionObserverRootMargin =\n IntersectionObserverInit[\"rootMargin\"];\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#intersection_observer_options}\n * @since 6.0.0\n */\nexport interface BaseIntersectionObserverHookOptions {\n /**\n * This is the same as the normal `root` for an IntersectionObserverInit, but\n * also supports refs.\n */\n root?: RefObject<IntersectionObserverRoot> | IntersectionObserverRoot;\n\n /**\n * Set this to `true` if the intersection observer behavior should be\n * disabled.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n\n /**\n * **When using a list of thresholds, they must either be defined outside of\n * the component or wrapped in a `useMemo` to prevent the IntersectionObserver\n * from being re-created each render.**\n *\n * @example Moving Out of Render\n * ```tsx\n * const threshold = [0, 0.25, 0.5, 0.75, 1];\n *\n * function Example() {\n * const targetRef = useIntersectionObserver({\n * threshold,\n * onUpdate: useCallback(([entry]) => {\n * // do something\n * }, []),\n * })\n * }\n * ```\n *\n * @example Wrapping in useMemo\n * ```tsx\n * interface ExampleProps {\n * min: number;\n * max: number;\n * }\n *\n * function Example({ min, max }: ExampleProps): ReactElement {\n * const targetRef = useIntersectionObserver({\n * threshold: useMemo(() => [min, max], [min, max]),\n * onUpdate: useCallback(([entry]) => {\n * // do something\n * }, []),\n * });\n * }\n * ```\n *\n * @see {@link getThreshold}\n */\n threshold?: IntersectionObserverThreshold;\n\n /** @see {@link getRootMargin} */\n rootMargin?: IntersectionObserverRootMargin;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * This can be used to dynamically generate the {@link threshold} which is\n * generally useful if you need access to the DOM or do some expensive\n * computation.\n *\n * @example Simple Example\n * ```tsx\n * const targetRef = useIntersectionObserver({\n * getThreshold: useCallback(() => {\n * // pretend some expensive computation\n * return [0, 0.25, 0.5, 0.75, 1];\n * }, []),\n * onUpdate: useCallback(() => {\n * // do something\n * }, []),\n * });\n * ```\n *\n * If this option is provided, {@link threshold}'s value will be ignored.\n */\n getThreshold?: () => IntersectionObserverThreshold;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * This can be used to dynamically generate the {@link rootMargin} which is\n * generally useful if you need access to the DOM.\n *\n * @example Simple Example\n * ```tsx\n * const nodeRef = useRef<HTMLElement>();\n * const targetRef = useIntersectionObserver({\n * getRootMargin: useCallback(() => {\n * return `-${nodeRef.current.offsetHeight - 1}px 0px 0px`;\n * }, []),\n * onUpdate: useCallback(() => {\n * // do something\n * }, []),\n * });\n * ```\n *\n * Note: If this option is provided, {@link rootMargin} will be ignored.\n */\n getRootMargin?: () => IntersectionObserverRootMargin;\n}\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#intersection_observer_options}\n * @since 6.0.0\n */\nexport interface IntersectionObserverHookOptions<E extends HTMLElement>\n extends BaseIntersectionObserverHookOptions {\n /**\n * An optional ref to merge with the ref returned by this hook.\n */\n ref?: Ref<E>;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * @example Simple Example\n * ```tsx\n * const threshold = [0, 0.25, 0.5, 0.75, 1];\n *\n * function Example(): ReactElement {\n * const [intersecting, setIntersecting] = useState(false);\n * const targetRef = useIntersectionObserver({\n * threshold,\n * onUpdate: useCallback(([entry]) {\n * setIntersecting(entry.isIntersecting);\n * }, []),\n * });\n *\n * // implementation\n * }\n * ```\n */\n onUpdate: (entries: readonly IntersectionObserverEntry[]) => void;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * If this is defined, the {@link ref} will be ignored along with the returned\n * ref.\n *\n * @example Watching Queried Elements\n * ```tsx\n * function Example(): ReactElement {\n * useIntersectionObserver({\n * onUpdate: useCallback((entries) => {\n * entries.forEach((entry) => {\n * // do stuff\n * });\n *\n * setIntersectingIds(intersecting);\n * }, []),\n * getTargets: useCallback(() => {\n * return document.querySelectorAll('h1, h2, h3, h4, h5, h6');\n * }, []),\n * }),\n *\n * return <div {...props} />;\n * }\n * ```\n */\n getTargets?: () => readonly Element[];\n}\n\n/**\n * @example Simple Example\n * ```tsx\n * // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#a_simple_example\n *\n * import { useIntersectionObserver } from \"@react-md/core\";\n * import type { ReactElement } from \"react\";\n * import { useState } from \"react\";\n *\n * import styles from \"./Example.module.scss\";\n *\n * const numSteps = 20;\n * const thresholds = Array.from({ length: numSteps }, (_, i) => i / numSteps);\n * thresholds.push(0);\n *\n * const INCREASING = \"rgba(40, 40, 190, ratio)\";\n * const DECREASING = \"rgba(190, 40, 40, ratio)\";\n *\n * export default function Example(): ReactElement {\n * const [{ ratio, increasing }, setState] = useState({\n * ratio: 0.0,\n * increasing: true,\n * });\n *\n * const targetRef = useIntersectionObserver({\n * threshold: thresholds,\n * rootMargin: \"0px\",\n * onUpdate: useCallback(([entry]) => {\n * const { intersectionRatio } = entry;\n * setState((prevState) => {\n * return {\n * ratio: intersectionRatio,\n * increasing: intersectionRatio > prevState.ratio,\n * };\n * });\n * }, []),\n * });\n *\n * return (\n * <div\n * ref={targetRef}\n * className={styles.box}\n * style={{\n * backgroundColor: (increasing ? INCREASING : DECREASING).replace(\n * \"ratio\",\n * `${ratio}`\n * ),\n * }}\n * >\n * <div className={styles.vertical}>\n * Welcome to <strong>The Box!</strong>\n * </div>\n * </div>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API\n */\nexport function useIntersectionObserver<E extends HTMLElement>(\n options: IntersectionObserverHookOptions<E>\n): RefCallback<E> {\n const {\n ref,\n root,\n disabled = false,\n onUpdate,\n threshold,\n rootMargin,\n getTargets,\n getThreshold,\n getRootMargin,\n } = options;\n\n const [targetNodeRef, targetRef] = useEnsuredRef(ref);\n\n useEffect(() => {\n const element = targetNodeRef.current;\n let targets: readonly Element[] = [];\n if (getTargets) {\n targets = getTargets();\n } else if (element) {\n targets = [element];\n }\n\n if (disabled || !targets.length) {\n return;\n }\n\n let resolvedRoot: IntersectionObserverRoot;\n if (root && \"current\" in root) {\n resolvedRoot = root.current;\n } else {\n resolvedRoot = root;\n }\n\n const options: IntersectionObserverInit = {\n root: resolvedRoot,\n threshold: (getThreshold || (() => threshold))(),\n rootMargin: (getRootMargin || (() => rootMargin))(),\n };\n\n // Just like the ResizeObserver, you can see performance improvements by\n // sharing a single intersection observer but I don't think it's worth the\n // effort to implement here since I'd need to:\n // - check if there is an observer with the same options\n // - if there is, add the callback to that existing observer\n // - if there isn't, create a new observer\n // - when cleaning up, check if there are any other existing callbacks\n // - disconnect and remove the observer if there are none left\n const observer = new IntersectionObserver(onUpdate, options);\n targets.forEach((target) => {\n observer.observe(target);\n });\n\n return () => {\n observer.disconnect();\n };\n }, [\n disabled,\n getRootMargin,\n getTargets,\n getThreshold,\n onUpdate,\n root,\n rootMargin,\n targetNodeRef,\n threshold,\n ]);\n\n return targetRef;\n}\n"],"names":["useEffect","useEnsuredRef","useIntersectionObserver","options","ref","root","disabled","onUpdate","threshold","rootMargin","getTargets","getThreshold","getRootMargin","targetNodeRef","targetRef","element","current","targets","length","resolvedRoot","observer","IntersectionObserver","forEach","target","observe","disconnect"],"mappings":"AAAA;AAEA,SAASA,SAAS,QAAQ,QAAQ;AAClC,SAASC,aAAa,QAAQ,qBAAqB;AA2LnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2DC,GACD,OAAO,SAASC,wBACdC,OAA2C;IAE3C,MAAM,EACJC,GAAG,EACHC,IAAI,EACJC,WAAW,KAAK,EAChBC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,UAAU,EACVC,YAAY,EACZC,aAAa,EACd,GAAGT;IAEJ,MAAM,CAACU,eAAeC,UAAU,GAAGb,cAAcG;IAEjDJ,UAAU;QACR,MAAMe,UAAUF,cAAcG,OAAO;QACrC,IAAIC,UAA8B,EAAE;QACpC,IAAIP,YAAY;YACdO,UAAUP;QACZ,OAAO,IAAIK,SAAS;YAClBE,UAAU;gBAACF;aAAQ;QACrB;QAEA,IAAIT,YAAY,CAACW,QAAQC,MAAM,EAAE;YAC/B;QACF;QAEA,IAAIC;QACJ,IAAId,QAAQ,aAAaA,MAAM;YAC7Bc,eAAed,KAAKW,OAAO;QAC7B,OAAO;YACLG,eAAed;QACjB;QAEA,MAAMF,UAAoC;YACxCE,MAAMc;YACNX,WAAW,AAACG,CAAAA,gBAAiB,CAAA,IAAMH,SAAQ,CAAC;YAC5CC,YAAY,AAACG,CAAAA,iBAAkB,CAAA,IAAMH,UAAS,CAAC;QACjD;QAEA,wEAAwE;QACxE,0EAA0E;QAC1E,8CAA8C;QAC9C,wDAAwD;QACxD,8DAA8D;QAC9D,4CAA4C;QAC5C,sEAAsE;QACtE,gEAAgE;QAChE,MAAMW,WAAW,IAAIC,qBAAqBd,UAAUJ;QACpDc,QAAQK,OAAO,CAAC,CAACC;YACfH,SAASI,OAAO,CAACD;QACnB;QAEA,OAAO;YACLH,SAASK,UAAU;QACrB;IACF,GAAG;QACDnB;QACAM;QACAF;QACAC;QACAJ;QACAF;QACAI;QACAI;QACAL;KACD;IAED,OAAOM;AACT"}
|
|
1
|
+
{"version":3,"sources":["../src/useIntersectionObserver.ts"],"sourcesContent":["\"use client\";\n\nimport { type Ref, type RefCallback, type RefObject } from \"react\";\nimport { useEffect } from \"react\";\n\nimport { useEnsuredRef } from \"./useEnsuredRef.js\";\n\n/** @since 6.0.0 */\nexport type IntersectionObserverRoot = IntersectionObserverInit[\"root\"];\n/** @since 6.0.0 */\nexport type IntersectionObserverThreshold =\n IntersectionObserverInit[\"threshold\"];\n/** @since 6.0.0 */\nexport type IntersectionObserverRootMargin =\n IntersectionObserverInit[\"rootMargin\"];\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#intersection_observer_options}\n * @since 6.0.0\n */\nexport interface BaseIntersectionObserverHookOptions {\n /**\n * This is the same as the normal `root` for an IntersectionObserverInit, but\n * also supports refs.\n */\n root?: RefObject<IntersectionObserverRoot> | IntersectionObserverRoot;\n\n /**\n * Set this to `true` if the intersection observer behavior should be\n * disabled.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n\n /**\n * **When using a list of thresholds, they must either be defined outside of\n * the component or wrapped in a `useMemo` to prevent the IntersectionObserver\n * from being re-created each render.**\n *\n * @example Moving Out of Render\n * ```tsx\n * const threshold = [0, 0.25, 0.5, 0.75, 1];\n *\n * function Example() {\n * const targetRef = useIntersectionObserver({\n * threshold,\n * onUpdate: useCallback(([entry]) => {\n * // do something\n * }, []),\n * })\n * }\n * ```\n *\n * @example Wrapping in useMemo\n * ```tsx\n * interface ExampleProps {\n * min: number;\n * max: number;\n * }\n *\n * function Example({ min, max }: ExampleProps): ReactElement {\n * const targetRef = useIntersectionObserver({\n * threshold: useMemo(() => [min, max], [min, max]),\n * onUpdate: useCallback(([entry]) => {\n * // do something\n * }, []),\n * });\n * }\n * ```\n *\n * @see {@link getThreshold}\n */\n threshold?: IntersectionObserverThreshold;\n\n /** @see {@link getRootMargin} */\n rootMargin?: IntersectionObserverRootMargin;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * This can be used to dynamically generate the {@link threshold} which is\n * generally useful if you need access to the DOM or do some expensive\n * computation.\n *\n * @example Simple Example\n * ```tsx\n * const targetRef = useIntersectionObserver({\n * getThreshold: useCallback(() => {\n * // pretend some expensive computation\n * return [0, 0.25, 0.5, 0.75, 1];\n * }, []),\n * onUpdate: useCallback(() => {\n * // do something\n * }, []),\n * });\n * ```\n *\n * If this option is provided, {@link threshold}'s value will be ignored.\n */\n getThreshold?: () => IntersectionObserverThreshold;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * This can be used to dynamically generate the {@link rootMargin} which is\n * generally useful if you need access to the DOM.\n *\n * @example Simple Example\n * ```tsx\n * const nodeRef = useRef<HTMLElement>();\n * const targetRef = useIntersectionObserver({\n * getRootMargin: useCallback(() => {\n * return `-${nodeRef.current.offsetHeight - 1}px 0px 0px`;\n * }, []),\n * onUpdate: useCallback(() => {\n * // do something\n * }, []),\n * });\n * ```\n *\n * Note: If this option is provided, {@link rootMargin} will be ignored.\n */\n getRootMargin?: () => IntersectionObserverRootMargin;\n}\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#intersection_observer_options}\n * @since 6.0.0\n */\nexport interface IntersectionObserverHookOptions<E extends HTMLElement>\n extends BaseIntersectionObserverHookOptions {\n /**\n * An optional ref to merge with the ref returned by this hook.\n */\n ref?: Ref<E>;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * @example Simple Example\n * ```tsx\n * const threshold = [0, 0.25, 0.5, 0.75, 1];\n *\n * function Example(): ReactElement {\n * const [intersecting, setIntersecting] = useState(false);\n * const targetRef = useIntersectionObserver({\n * threshold,\n * onUpdate: useCallback(([entry]) {\n * setIntersecting(entry.isIntersecting);\n * }, []),\n * });\n *\n * // implementation\n * }\n * ```\n */\n onUpdate: (entries: readonly IntersectionObserverEntry[]) => void;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * If this is defined, the {@link ref} will be ignored along with the returned\n * ref.\n *\n * @example Watching Queried Elements\n * ```tsx\n * function Example(): ReactElement {\n * useIntersectionObserver({\n * onUpdate: useCallback((entries) => {\n * entries.forEach((entry) => {\n * // do stuff\n * });\n *\n * setIntersectingIds(intersecting);\n * }, []),\n * getTargets: useCallback(() => {\n * return document.querySelectorAll('h1, h2, h3, h4, h5, h6');\n * }, []),\n * }),\n *\n * return <div {...props} />;\n * }\n * ```\n */\n getTargets?: () => readonly Element[];\n}\n\n/**\n * @example Simple Example\n * ```tsx\n * // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#a_simple_example\n *\n * import { useIntersectionObserver } from \"@react-md/core/useIntersectionObserver\";\n * import { type ReactElement } from \"react\";\n * import { useState } from \"react\";\n *\n * import styles from \"./Example.module.scss\";\n *\n * const numSteps = 20;\n * const thresholds = Array.from({ length: numSteps }, (_, i) => i / numSteps);\n * thresholds.push(0);\n *\n * const INCREASING = \"rgba(40, 40, 190, ratio)\";\n * const DECREASING = \"rgba(190, 40, 40, ratio)\";\n *\n * export default function Example(): ReactElement {\n * const [{ ratio, increasing }, setState] = useState({\n * ratio: 0.0,\n * increasing: true,\n * });\n *\n * const targetRef = useIntersectionObserver({\n * threshold: thresholds,\n * rootMargin: \"0px\",\n * onUpdate: useCallback(([entry]) => {\n * const { intersectionRatio } = entry;\n * setState((prevState) => {\n * return {\n * ratio: intersectionRatio,\n * increasing: intersectionRatio > prevState.ratio,\n * };\n * });\n * }, []),\n * });\n *\n * return (\n * <div\n * ref={targetRef}\n * className={styles.box}\n * style={{\n * backgroundColor: (increasing ? INCREASING : DECREASING).replace(\n * \"ratio\",\n * `${ratio}`\n * ),\n * }}\n * >\n * <div className={styles.vertical}>\n * Welcome to <strong>The Box!</strong>\n * </div>\n * </div>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API\n */\nexport function useIntersectionObserver<E extends HTMLElement>(\n options: IntersectionObserverHookOptions<E>\n): RefCallback<E> {\n const {\n ref,\n root,\n disabled = false,\n onUpdate,\n threshold,\n rootMargin,\n getTargets,\n getThreshold,\n getRootMargin,\n } = options;\n\n const [targetNodeRef, targetRef] = useEnsuredRef(ref);\n\n useEffect(() => {\n const element = targetNodeRef.current;\n let targets: readonly Element[] = [];\n if (getTargets) {\n targets = getTargets();\n } else if (element) {\n targets = [element];\n }\n\n if (disabled || !targets.length) {\n return;\n }\n\n let resolvedRoot: IntersectionObserverRoot;\n if (root && \"current\" in root) {\n resolvedRoot = root.current;\n } else {\n resolvedRoot = root;\n }\n\n const options: IntersectionObserverInit = {\n root: resolvedRoot,\n threshold: (getThreshold || (() => threshold))(),\n rootMargin: (getRootMargin || (() => rootMargin))(),\n };\n\n // Just like the ResizeObserver, you can see performance improvements by\n // sharing a single intersection observer but I don't think it's worth the\n // effort to implement here since I'd need to:\n // - check if there is an observer with the same options\n // - if there is, add the callback to that existing observer\n // - if there isn't, create a new observer\n // - when cleaning up, check if there are any other existing callbacks\n // - disconnect and remove the observer if there are none left\n const observer = new IntersectionObserver(onUpdate, options);\n targets.forEach((target) => {\n observer.observe(target);\n });\n\n return () => {\n observer.disconnect();\n };\n }, [\n disabled,\n getRootMargin,\n getTargets,\n getThreshold,\n onUpdate,\n root,\n rootMargin,\n targetNodeRef,\n threshold,\n ]);\n\n return targetRef;\n}\n"],"names":["useEffect","useEnsuredRef","useIntersectionObserver","options","ref","root","disabled","onUpdate","threshold","rootMargin","getTargets","getThreshold","getRootMargin","targetNodeRef","targetRef","element","current","targets","length","resolvedRoot","observer","IntersectionObserver","forEach","target","observe","disconnect"],"mappings":"AAAA;AAGA,SAASA,SAAS,QAAQ,QAAQ;AAElC,SAASC,aAAa,QAAQ,qBAAqB;AA2LnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2DC,GACD,OAAO,SAASC,wBACdC,OAA2C;IAE3C,MAAM,EACJC,GAAG,EACHC,IAAI,EACJC,WAAW,KAAK,EAChBC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,UAAU,EACVC,YAAY,EACZC,aAAa,EACd,GAAGT;IAEJ,MAAM,CAACU,eAAeC,UAAU,GAAGb,cAAcG;IAEjDJ,UAAU;QACR,MAAMe,UAAUF,cAAcG,OAAO;QACrC,IAAIC,UAA8B,EAAE;QACpC,IAAIP,YAAY;YACdO,UAAUP;QACZ,OAAO,IAAIK,SAAS;YAClBE,UAAU;gBAACF;aAAQ;QACrB;QAEA,IAAIT,YAAY,CAACW,QAAQC,MAAM,EAAE;YAC/B;QACF;QAEA,IAAIC;QACJ,IAAId,QAAQ,aAAaA,MAAM;YAC7Bc,eAAed,KAAKW,OAAO;QAC7B,OAAO;YACLG,eAAed;QACjB;QAEA,MAAMF,UAAoC;YACxCE,MAAMc;YACNX,WAAW,AAACG,CAAAA,gBAAiB,CAAA,IAAMH,SAAQ,CAAC;YAC5CC,YAAY,AAACG,CAAAA,iBAAkB,CAAA,IAAMH,UAAS,CAAC;QACjD;QAEA,wEAAwE;QACxE,0EAA0E;QAC1E,8CAA8C;QAC9C,wDAAwD;QACxD,8DAA8D;QAC9D,4CAA4C;QAC5C,sEAAsE;QACtE,gEAAgE;QAChE,MAAMW,WAAW,IAAIC,qBAAqBd,UAAUJ;QACpDc,QAAQK,OAAO,CAAC,CAACC;YACfH,SAASI,OAAO,CAACD;QACnB;QAEA,OAAO;YACLH,SAASK,UAAU;QACrB;IACF,GAAG;QACDnB;QACAM;QACAF;QACAC;QACAJ;QACAF;QACAI;QACAI;QACAL;KACD;IAED,OAAOM;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useIsomorphicLayoutEffect.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useLayoutEffect } from \"react\";\n\n/**\n * This is copy/pasted from react-redux which has some more information about\n * this and how to fix \"invalid\" warnings while running tests.\n *\n * @see {@link https://github.com/reduxjs/react-redux/blob/4c907c0870c6b9a136dd69be294c17d1dc63c8f5/src/utils/useIsomorphicLayoutEffect.js}\n */\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" &&\n typeof window.document !== \"undefined\" &&\n typeof window.document.createElement !== \"undefined\"\n ? useLayoutEffect\n : useEffect;\n"],"names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","window","document","createElement"],"mappings":"AAAA;
|
|
1
|
+
{"version":3,"sources":["../src/useIsomorphicLayoutEffect.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useLayoutEffect } from \"react\";\n\n/**\n * This is copy/pasted from react-redux which has some more information about\n * this and how to fix \"invalid\" warnings while running tests.\n *\n * @see {@link https://github.com/reduxjs/react-redux/blob/4c907c0870c6b9a136dd69be294c17d1dc63c8f5/src/utils/useIsomorphicLayoutEffect.js}\n */\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" &&\n typeof window.document !== \"undefined\" &&\n typeof window.document.createElement !== \"undefined\"\n ? useLayoutEffect\n : useEffect;\n"],"names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","window","document","createElement"],"mappings":"AAAA;AAEA,SAASA,SAAS,EAAEC,eAAe,QAAQ,QAAQ;AAEnD;;;;;CAKC,GACD,OAAO,MAAMC,4BACX,OAAOC,WAAW,eAClB,OAAOA,OAAOC,QAAQ,KAAK,eAC3B,OAAOD,OAAOC,QAAQ,CAACC,aAAa,KAAK,cACrCJ,kBACAD,UAAU"}
|