@react-md/core 6.3.3 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CoreProviders.d.ts +1 -0
- package/dist/CoreProviders.js.map +1 -1
- package/dist/_base.scss +3 -0
- package/dist/_core.scss +1 -0
- package/dist/_utils.scss +15 -7
- package/dist/app-bar/AppBar.js.map +1 -1
- package/dist/app-bar/AppBarTitle.js.map +1 -1
- package/dist/autocomplete/AutocompleteListboxChildren.js.map +1 -1
- package/dist/autocomplete/types.js.map +1 -1
- package/dist/autocomplete/utils.js.map +1 -1
- package/dist/avatar/Avatar.js.map +1 -1
- package/dist/box/_box.scss +20 -1
- package/dist/box/styles.d.ts +39 -0
- package/dist/box/styles.js +39 -0
- package/dist/box/styles.js.map +1 -1
- package/dist/button/Button.js.map +1 -1
- package/dist/button/FloatingActionButton.js.map +1 -1
- package/dist/card/Card.js.map +1 -1
- package/dist/card/CardContent.js.map +1 -1
- package/dist/card/ClickableCard.js.map +1 -1
- package/dist/chip/Chip.js.map +1 -1
- package/dist/datetime/NativeDateField.js.map +1 -1
- package/dist/datetime/NativeTimeField.js.map +1 -1
- package/dist/datetime/useDateField.js.map +1 -1
- package/dist/datetime/useTimeField.js.map +1 -1
- package/dist/dialog/Dialog.js.map +1 -1
- package/dist/dialog/DialogContainer.js.map +1 -1
- package/dist/dialog/DialogContent.js.map +1 -1
- package/dist/dialog/DialogFooter.js.map +1 -1
- package/dist/divider/Divider.js.map +1 -1
- package/dist/draggable/useDraggable.js.map +1 -1
- package/dist/draggable/utils.js.map +1 -1
- package/dist/expansion-panel/ExpansionPanelHeader.js.map +1 -1
- package/dist/files/FileInput.js.map +1 -1
- package/dist/files/useFileUpload.js.map +1 -1
- package/dist/files/validation.js.map +1 -1
- package/dist/focus/useFocusContainer.js.map +1 -1
- package/dist/form/Fieldset.d.ts +19 -0
- package/dist/form/Fieldset.js +22 -2
- package/dist/form/Fieldset.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/Legend.d.ts +27 -5
- package/dist/form/Legend.js +39 -6
- 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/NativeSelect.js.map +1 -1
- package/dist/form/Password.js.map +1 -1
- package/dist/form/ResizingTextAreaWrapper.js.map +1 -1
- package/dist/form/Select.js.map +1 -1
- package/dist/form/Slider.js.map +1 -1
- package/dist/form/SliderContainer.js.map +1 -1
- 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/Switch.js.map +1 -1
- package/dist/form/TextArea.js.map +1 -1
- package/dist/form/TextField.js.map +1 -1
- package/dist/form/TextFieldContainer.js.map +1 -1
- package/dist/form/_fieldset.scss +7 -0
- package/dist/form/_legend.scss +68 -0
- package/dist/form/_text-field.scss +39 -4
- package/dist/form/fieldsetStyles.d.ts +6 -1
- package/dist/form/fieldsetStyles.js +3 -2
- package/dist/form/fieldsetStyles.js.map +1 -1
- package/dist/form/inputToggleStyles.js.map +1 -1
- package/dist/form/labelStyles.d.ts +1 -1
- package/dist/form/labelStyles.js +1 -1
- package/dist/form/labelStyles.js.map +1 -1
- package/dist/form/legendStyles.d.ts +83 -0
- package/dist/form/legendStyles.js +25 -0
- package/dist/form/legendStyles.js.map +1 -0
- package/dist/form/selectUtils.js.map +1 -1
- package/dist/form/textFieldContainerStyles.js.map +1 -1
- package/dist/form/types.d.ts +28 -6
- package/dist/form/types.js.map +1 -1
- package/dist/form/useCheckboxGroup.js.map +1 -1
- package/dist/form/useCombobox.js.map +1 -1
- package/dist/form/useNumberField.js +16 -19
- package/dist/form/useNumberField.js.map +1 -1
- package/dist/form/useRangeSlider.js.map +1 -1
- package/dist/form/useSlider.js.map +1 -1
- package/dist/form/useTextField.d.ts +1 -1
- package/dist/form/useTextField.js.map +1 -1
- package/dist/hoverMode/useHoverMode.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/config.d.ts +0 -1
- package/dist/icon/config.js +10 -7
- package/dist/icon/config.js.map +1 -1
- package/dist/icon/materialConfig.js.map +1 -1
- package/dist/icon/styles.js.map +1 -1
- package/dist/interaction/UserInteractionModeProvider.js +6 -4
- package/dist/interaction/UserInteractionModeProvider.js.map +1 -1
- package/dist/interaction/types.js.map +1 -1
- package/dist/interaction/useElementInteraction.js.map +1 -1
- package/dist/layout/LayoutAppBar.d.ts +6 -6
- package/dist/layout/LayoutAppBar.js +6 -6
- 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/useExpandableLayout.js +43 -0
- package/dist/layout/useExpandableLayout.js.map +1 -1
- package/dist/layout/useHorizontalLayoutTransition.js.map +1 -1
- package/dist/layout/useLayoutTree.js.map +1 -1
- package/dist/layout/useLayoutWindowSplitter.js.map +1 -1
- package/dist/layout/useResizableLayout.js.map +1 -1
- package/dist/link/Link.js.map +1 -1
- package/dist/link/SkipToMainContent.js +19 -21
- package/dist/link/SkipToMainContent.js.map +1 -1
- package/dist/list/List.js.map +1 -1
- package/dist/list/ListItem.js.map +1 -1
- package/dist/list/ListItemAddon.js.map +1 -1
- package/dist/list/ListItemLink.js.map +1 -1
- package/dist/list/ListSubheader.js.map +1 -1
- package/dist/list/getListItemHeight.js.map +1 -1
- package/dist/list/listItemStyles.js.map +1 -1
- package/dist/list/types.js.map +1 -1
- package/dist/media-queries/AppSizeProvider.d.ts +2 -0
- package/dist/media-queries/AppSizeProvider.js +3 -2
- package/dist/media-queries/AppSizeProvider.js.map +1 -1
- package/dist/media-queries/appSize.d.ts +3 -0
- package/dist/media-queries/appSize.js +3 -1
- package/dist/media-queries/appSize.js.map +1 -1
- package/dist/media-queries/config.d.ts +11 -0
- package/dist/media-queries/config.js +26 -0
- package/dist/media-queries/config.js.map +1 -0
- package/dist/menu/DropdownMenu.js.map +1 -1
- package/dist/menu/Menu.js.map +1 -1
- package/dist/menu/MenuItemButton.js.map +1 -1
- package/dist/menu/MenuItemFileInput.js.map +1 -1
- package/dist/menu/MenuItemInputToggle.js.map +1 -1
- package/dist/menu/MenuItemSeparator.js.map +1 -1
- package/dist/menu/MenuVisibilityProvider.js.map +1 -1
- package/dist/menu/MenuWidget.js.map +1 -1
- package/dist/menu/useContextMenu.js.map +1 -1
- package/dist/movement/types.d.ts +28 -3
- package/dist/movement/types.js.map +1 -1
- package/dist/movement/useKeyboardMovementProvider.js +96 -47
- package/dist/movement/useKeyboardMovementProvider.js.map +1 -1
- package/dist/navigation/CollapsibleNavGroup.js.map +1 -1
- package/dist/navigation/NavItem.js.map +1 -1
- package/dist/navigation/NavItemButton.js.map +1 -1
- package/dist/navigation/NavItemLink.js.map +1 -1
- package/dist/navigation/getTableOfContentsHeadings.js.map +1 -1
- package/dist/navigation/types.js.map +1 -1
- package/dist/overlay/Overlay.js.map +1 -1
- package/dist/positioning/createHorizontalPosition.js.map +1 -1
- package/dist/positioning/createVerticalPosition.js.map +1 -1
- 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/linearProgressStyles.js.map +1 -1
- package/dist/responsive-item/ResponsiveItem.js.map +1 -1
- package/dist/responsive-item/ResponsiveItemOverlay.js.map +1 -1
- package/dist/searching/caseInsensitive.js.map +1 -1
- package/dist/segmented-button/SegmentedButton.js.map +1 -1
- package/dist/segmented-button/SegmentedButtonContainer.js.map +1 -1
- package/dist/segmented-button/segmentedButtonStyles.js.map +1 -1
- package/dist/sheet/Sheet.js.map +1 -1
- package/dist/snackbar/Toast.js.map +1 -1
- package/dist/spinbutton/SpinButton.d.ts +16 -0
- package/dist/spinbutton/SpinButton.js +55 -0
- package/dist/spinbutton/SpinButton.js.map +1 -0
- package/dist/spinbutton/SpinButtonGroupProvider.d.ts +17 -0
- package/dist/spinbutton/SpinButtonGroupProvider.js +19 -0
- package/dist/spinbutton/SpinButtonGroupProvider.js.map +1 -0
- package/dist/spinbutton/defaults.d.ts +9 -0
- package/dist/spinbutton/defaults.js +25 -0
- package/dist/spinbutton/defaults.js.map +1 -0
- package/dist/spinbutton/types.d.ts +324 -0
- package/dist/spinbutton/types.js +5 -0
- package/dist/spinbutton/types.js.map +1 -0
- package/dist/spinbutton/useSpinButton.d.ts +5 -0
- package/dist/spinbutton/useSpinButton.js +260 -0
- package/dist/spinbutton/useSpinButton.js.map +1 -0
- package/dist/spinbutton/useSpinButtonGroupProvider.d.ts +27 -0
- package/dist/spinbutton/useSpinButtonGroupProvider.js +49 -0
- package/dist/spinbutton/useSpinButtonGroupProvider.js.map +1 -0
- package/dist/spinbutton/utils/deselectNode.d.ts +5 -0
- package/dist/spinbutton/utils/deselectNode.js +17 -0
- package/dist/spinbutton/utils/deselectNode.js.map +1 -0
- package/dist/spinbutton/utils/resolveInputEvent.d.ts +30 -0
- package/dist/spinbutton/utils/resolveInputEvent.js +53 -0
- package/dist/spinbutton/utils/resolveInputEvent.js.map +1 -0
- package/dist/spinbutton/utils/selectNode.d.ts +5 -0
- package/dist/spinbutton/utils/selectNode.js +15 -0
- package/dist/spinbutton/utils/selectNode.js.map +1 -0
- 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/TableCellContent.js.map +1 -1
- package/dist/table/TableCheckbox.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/useStickyTableSection.js.map +1 -1
- package/dist/tabs/SimpleTabPanel.js.map +1 -1
- package/dist/tabs/SimpleTabPanels.js.map +1 -1
- package/dist/tabs/Tab.js.map +1 -1
- package/dist/tabs/TabList.js.map +1 -1
- package/dist/tabs/TabListScrollButton.js.map +1 -1
- package/dist/tabs/useMaxTabPanelHeight.js.map +1 -1
- package/dist/test-utils/data-testid.js.map +1 -1
- package/dist/test-utils/mocks/match-media.js +5 -5
- package/dist/test-utils/mocks/match-media.js.map +1 -1
- package/dist/test-utils/vitest/timers.d.ts +1 -1
- package/dist/test-utils/vitest/timers.js +1 -1
- package/dist/test-utils/vitest/timers.js.map +1 -1
- package/dist/tooltip/Tooltip.js.map +1 -1
- package/dist/tooltip/TooltipHoverModeProvider.js.map +1 -1
- package/dist/tooltip/useTooltip.js.map +1 -1
- package/dist/transition/CSSTransition.js.map +1 -1
- package/dist/transition/Collapse.js.map +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/types.js.map +1 -1
- package/dist/transition/useCollapseTransition.js.map +1 -1
- package/dist/transition/useCrossFadeTransition.js.map +1 -1
- package/dist/transition/useMaxWidthTransition.js.map +1 -1
- package/dist/transition/useScaleTransition.js.map +1 -1
- package/dist/transition/useSkeletonPlaceholder.js.map +1 -1
- package/dist/tree/Tree.js.map +1 -1
- package/dist/tree/TreeItem.js.map +1 -1
- package/dist/tree/TreeProvider.js.map +1 -1
- package/dist/tree/styles.js.map +1 -1
- package/dist/tree/types.js.map +1 -1
- package/dist/tree/useTreeMovement.js.map +1 -1
- package/dist/typography/HighlightTextMark.js.map +1 -1
- package/dist/typography/Mark.js.map +1 -1
- package/dist/typography/TextContainer.js.map +1 -1
- package/dist/typography/Typography.js.map +1 -1
- package/dist/typography/_typography.scss +0 -1
- package/dist/useElementSize.js.map +1 -1
- package/dist/useIntersectionObserver.js.map +1 -1
- package/dist/useMutationObserver.js.map +1 -1
- package/dist/useWindowSize.js.map +1 -1
- package/dist/utils/getNumberOfDigits.d.ts +7 -0
- package/dist/utils/getNumberOfDigits.js +11 -0
- package/dist/utils/getNumberOfDigits.js.map +1 -0
- package/dist/utils/nearest.js +2 -1
- package/dist/utils/nearest.js.map +1 -1
- package/dist/utils/useDevEffect.d.ts +7 -0
- package/dist/utils/useDevEffect.js +8 -0
- package/dist/utils/useDevEffect.js.map +1 -0
- package/dist/window-splitter/WindowSplitter.js +3 -2
- package/dist/window-splitter/WindowSplitter.js.map +1 -1
- package/dist/window-splitter/_window-splitter.scss +60 -12
- package/dist/window-splitter/styles.d.ts +9 -0
- package/dist/window-splitter/styles.js +3 -2
- package/dist/window-splitter/styles.js.map +1 -1
- package/dist/window-splitter/useWindowSplitter.js.map +1 -1
- package/package.json +38 -30
- package/src/CoreProviders.tsx +1 -0
- package/src/app-bar/AppBar.tsx +1 -2
- package/src/app-bar/AppBarTitle.tsx +1 -2
- package/src/autocomplete/AutocompleteListboxChildren.tsx +3 -1
- package/src/autocomplete/types.ts +24 -19
- package/src/autocomplete/utils.ts +9 -6
- package/src/avatar/Avatar.tsx +2 -1
- package/src/box/styles.ts +39 -0
- package/src/button/Button.tsx +2 -1
- package/src/button/FloatingActionButton.tsx +2 -1
- package/src/card/Card.tsx +2 -1
- package/src/card/CardContent.tsx +1 -2
- package/src/card/ClickableCard.tsx +1 -2
- package/src/chip/Chip.tsx +2 -1
- package/src/datetime/NativeDateField.tsx +2 -1
- package/src/datetime/NativeTimeField.tsx +2 -1
- package/src/datetime/useDateField.ts +13 -8
- package/src/datetime/useTimeField.ts +13 -8
- package/src/dialog/Dialog.tsx +2 -1
- package/src/dialog/DialogContainer.tsx +1 -2
- package/src/dialog/DialogContent.tsx +1 -2
- package/src/dialog/DialogFooter.tsx +1 -2
- package/src/divider/Divider.tsx +1 -2
- package/src/draggable/useDraggable.ts +4 -4
- package/src/draggable/utils.ts +4 -2
- package/src/expansion-panel/ExpansionPanelHeader.tsx +1 -2
- package/src/files/FileInput.tsx +2 -1
- package/src/files/useFileUpload.ts +6 -6
- package/src/files/validation.ts +1 -2
- package/src/focus/useFocusContainer.ts +4 -4
- package/src/form/Fieldset.tsx +25 -3
- package/src/form/FormMessageContainer.tsx +1 -2
- package/src/form/FormMessageCounter.tsx +1 -2
- package/src/form/InputToggle.tsx +3 -3
- package/src/form/Legend.tsx +55 -10
- package/src/form/Listbox.tsx +1 -2
- package/src/form/ListboxProvider.ts +3 -2
- package/src/form/NativeSelect.tsx +2 -1
- package/src/form/Password.tsx +4 -2
- package/src/form/ResizingTextAreaWrapper.tsx +1 -2
- package/src/form/Select.tsx +2 -1
- package/src/form/Slider.tsx +2 -1
- package/src/form/SliderContainer.tsx +1 -2
- package/src/form/SliderThumb.tsx +6 -3
- package/src/form/SliderTrack.tsx +2 -1
- package/src/form/SliderValueMarks.tsx +1 -2
- package/src/form/Switch.tsx +2 -1
- package/src/form/TextArea.tsx +1 -2
- package/src/form/TextField.tsx +2 -1
- package/src/form/TextFieldContainer.tsx +1 -2
- package/src/form/fieldsetStyles.ts +18 -3
- package/src/form/inputToggleStyles.ts +4 -2
- package/src/form/labelStyles.ts +1 -1
- package/src/form/legendStyles.ts +132 -0
- package/src/form/selectUtils.ts +3 -2
- package/src/form/textFieldContainerStyles.ts +1 -2
- package/src/form/types.ts +35 -17
- package/src/form/useCheckboxGroup.ts +3 -2
- package/src/form/useCombobox.ts +8 -3
- package/src/form/useNumberField.ts +36 -35
- package/src/form/useRangeSlider.ts +1 -2
- package/src/form/useSlider.ts +1 -2
- package/src/form/useTextField.ts +9 -4
- package/src/hoverMode/useHoverMode.ts +4 -8
- package/src/icon/FontIcon.tsx +1 -2
- package/src/icon/IconRotator.tsx +1 -2
- package/src/icon/MaterialIcon.tsx +2 -1
- package/src/icon/MaterialSymbol.tsx +2 -1
- package/src/icon/SVGIcon.tsx +1 -2
- package/src/icon/config.tsx +10 -7
- package/src/icon/materialConfig.ts +1 -2
- package/src/icon/styles.ts +1 -2
- package/src/interaction/UserInteractionModeProvider.tsx +9 -4
- package/src/interaction/types.ts +1 -2
- package/src/interaction/useElementInteraction.tsx +3 -2
- package/src/layout/LayoutAppBar.tsx +6 -6
- package/src/layout/LayoutNav.tsx +2 -1
- package/src/layout/LayoutWindowSplitter.tsx +2 -1
- package/src/layout/Main.tsx +1 -2
- package/src/layout/useExpandableLayout.ts +63 -5
- package/src/layout/useHorizontalLayoutTransition.ts +1 -2
- package/src/layout/useLayoutTree.ts +2 -2
- package/src/layout/useLayoutWindowSplitter.ts +6 -6
- package/src/layout/useResizableLayout.ts +3 -6
- package/src/link/Link.tsx +1 -2
- package/src/link/SkipToMainContent.tsx +20 -23
- package/src/list/List.tsx +1 -2
- package/src/list/ListItem.tsx +2 -1
- package/src/list/ListItemAddon.tsx +2 -1
- package/src/list/ListItemLink.tsx +2 -1
- package/src/list/ListSubheader.tsx +1 -2
- package/src/list/getListItemHeight.ts +8 -9
- package/src/list/listItemStyles.ts +1 -2
- package/src/list/types.ts +1 -2
- package/src/media-queries/AppSizeProvider.tsx +8 -10
- package/src/media-queries/appSize.ts +3 -0
- package/src/media-queries/config.ts +41 -0
- package/src/menu/DropdownMenu.tsx +4 -5
- package/src/menu/Menu.tsx +2 -1
- package/src/menu/MenuItemButton.tsx +1 -2
- package/src/menu/MenuItemFileInput.tsx +2 -1
- package/src/menu/MenuItemInputToggle.tsx +3 -3
- package/src/menu/MenuItemSeparator.tsx +2 -1
- package/src/menu/MenuVisibilityProvider.tsx +4 -2
- package/src/menu/MenuWidget.tsx +1 -2
- package/src/menu/useContextMenu.ts +4 -2
- package/src/movement/types.ts +52 -13
- package/src/movement/useKeyboardMovementProvider.ts +77 -38
- package/src/navigation/CollapsibleNavGroup.tsx +1 -2
- package/src/navigation/NavItem.tsx +1 -2
- package/src/navigation/NavItemButton.tsx +2 -1
- package/src/navigation/NavItemLink.tsx +2 -1
- package/src/navigation/getTableOfContentsHeadings.ts +1 -2
- package/src/navigation/types.ts +1 -2
- package/src/overlay/Overlay.tsx +2 -1
- package/src/positioning/createHorizontalPosition.ts +10 -12
- package/src/positioning/createVerticalPosition.ts +10 -11
- package/src/positioning/useFixedPositioning.ts +6 -3
- package/src/progress/CircularProgress.tsx +2 -1
- package/src/progress/LinearProgress.tsx +2 -1
- package/src/progress/linearProgressStyles.ts +1 -2
- package/src/responsive-item/ResponsiveItem.tsx +1 -2
- package/src/responsive-item/ResponsiveItemOverlay.tsx +2 -1
- package/src/searching/caseInsensitive.ts +2 -4
- package/src/segmented-button/SegmentedButton.tsx +2 -1
- package/src/segmented-button/SegmentedButtonContainer.tsx +2 -1
- package/src/segmented-button/segmentedButtonStyles.ts +1 -2
- package/src/sheet/Sheet.tsx +1 -2
- package/src/snackbar/Toast.tsx +2 -1
- package/src/spinbutton/SpinButton.tsx +98 -0
- package/src/spinbutton/SpinButtonGroupProvider.tsx +32 -0
- package/src/spinbutton/defaults.ts +45 -0
- package/src/spinbutton/types.ts +413 -0
- package/src/spinbutton/useSpinButton.ts +311 -0
- package/src/spinbutton/useSpinButtonGroupProvider.ts +104 -0
- package/src/spinbutton/utils/deselectNode.ts +17 -0
- package/src/spinbutton/utils/resolveInputEvent.ts +112 -0
- package/src/spinbutton/utils/selectNode.ts +15 -0
- package/src/table/StickyTableSection.tsx +2 -1
- package/src/table/Table.tsx +1 -2
- package/src/table/TableBody.tsx +2 -1
- package/src/table/TableCellContent.tsx +1 -2
- package/src/table/TableCheckbox.tsx +1 -2
- package/src/table/TableFooter.tsx +1 -2
- package/src/table/TableHeader.tsx +1 -2
- package/src/table/TableRadio.tsx +1 -2
- package/src/table/TableRow.tsx +1 -2
- package/src/table/useStickyTableSection.tsx +1 -2
- package/src/tabs/SimpleTabPanel.tsx +2 -1
- package/src/tabs/SimpleTabPanels.tsx +2 -1
- package/src/tabs/Tab.tsx +3 -6
- package/src/tabs/TabList.tsx +2 -1
- package/src/tabs/TabListScrollButton.tsx +1 -2
- package/src/tabs/useMaxTabPanelHeight.ts +7 -4
- package/src/test-utils/data-testid.ts +1 -2
- package/src/test-utils/mocks/match-media.ts +5 -10
- package/src/test-utils/vitest/timers.ts +1 -1
- package/src/tooltip/Tooltip.tsx +2 -1
- package/src/tooltip/TooltipHoverModeProvider.tsx +1 -2
- package/src/tooltip/useTooltip.ts +9 -5
- package/src/transition/CSSTransition.tsx +2 -1
- package/src/transition/Collapse.tsx +4 -2
- package/src/transition/CrossFade.tsx +2 -1
- package/src/transition/ScaleTransition.tsx +2 -1
- package/src/transition/SkeletonPlaceholder.tsx +1 -2
- package/src/transition/Slide.tsx +2 -1
- package/src/transition/SlideContainer.tsx +1 -2
- package/src/transition/types.ts +15 -16
- package/src/transition/useCollapseTransition.ts +6 -5
- package/src/transition/useCrossFadeTransition.ts +3 -2
- package/src/transition/useMaxWidthTransition.ts +1 -2
- package/src/transition/useScaleTransition.ts +3 -2
- package/src/transition/useSkeletonPlaceholder.ts +1 -2
- package/src/tree/Tree.tsx +2 -1
- package/src/tree/TreeItem.tsx +2 -1
- package/src/tree/TreeProvider.tsx +4 -4
- package/src/tree/styles.ts +1 -2
- package/src/tree/types.ts +1 -2
- package/src/tree/useTreeMovement.ts +1 -2
- package/src/typography/HighlightTextMark.tsx +1 -2
- package/src/typography/Mark.tsx +1 -2
- package/src/typography/TextContainer.tsx +1 -2
- package/src/typography/Typography.tsx +1 -2
- package/src/useElementSize.ts +7 -4
- package/src/useIntersectionObserver.ts +3 -2
- package/src/useMutationObserver.ts +3 -2
- package/src/useWindowSize.ts +4 -2
- package/src/utils/getNumberOfDigits.ts +18 -0
- package/src/utils/nearest.ts +2 -1
- package/src/utils/useDevEffect.ts +9 -0
- package/src/window-splitter/WindowSplitter.tsx +5 -2
- package/src/window-splitter/styles.ts +13 -2
- package/src/window-splitter/useWindowSplitter.ts +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transition/types.ts"],"sourcesContent":["// This is pretty much `react-transition-group` since I liked the API wanted a\n// hook implementation. I also had to redo most of the types for v4.0.0 due to\n// the new `nodeRef` stuff, so it made it easier to create the types and hooks\n// here.\nimport type { ReactElement, Ref, RefCallback } from \"react\";\n\n/**\n * @since 4.0.0\n */\nexport interface TransitionActions {\n /**\n * Boolean if the transition should occur immediately once the component\n * mounts if the {@link TransitionOptions.transitionIn} is `true`\n *\n * @defaultValue `false`\n */\n appear?: boolean;\n\n /**\n * Boolean if the transition should occur whenever the\n * {@link TransitionOptions.transitionIn} is switch to `true` after the\n * component has been rendered in the DOM.\n *\n * @defaultValue `true`\n */\n enter?: boolean;\n\n /**\n * Boolean if the transition should occur whenever the\n * {@link TransitionOptions.transitionIn} is switch to `false` after the\n * component has been rendered in the DOM.\n *\n * @defaultValue `true`\n */\n exit?: boolean;\n}\n\n/**\n * An object timeout values that would be used for each\n * {@link TransitionActions}. If a value is set to `0` or `undefined`, the\n * transition will not occur.\n *\n * @since 4.0.0\n */\nexport type TransitionTimeoutObject = {\n [action in keyof TransitionActions]?: number;\n};\n\n/**\n * Either a single timeout duration in milliseconds to use for each of the\n * {@link TransitionActions} stages, or an object of transition durations.\n *\n * @since 4.0.0\n */\nexport type TransitionTimeout = number | Readonly<TransitionTimeoutObject>;\n\n/**\n * @since 6.0.0\n */\nexport type TransitionEnterStage = \"enter\" | \"entering\" | \"entered\";\n\n/**\n * @since 6.0.0\n */\nexport type TransitionExitStage = \"exit\" | \"exiting\" | \"exited\";\n\n/**\n * The way the transition works is by flowing through the different stages and\n * assigning waiting for a timeout to occur. Setting the `stage` to `enter` will\n * begin the enter transition going from `enter -> entering -> entered` while\n * setting the stage to `exit` will transition from `exit -> exiting -> exited`.\n *\n * @since 4.0.0\n * @since 6.0.0 Type union between `TransitionEnterStage` and `TransitionExitStage`\n */\nexport type TransitionStage = TransitionEnterStage | TransitionExitStage;\n\n/**\n * This function is called at each `\"enter\"` {@link TransitionStage}. If a\n * {@link TransitionOptions.nodeRef} was provided, the DOM node should be\n * available in `nodeRef.current` by this point if the transition requires DOM\n * calculations.\n *\n * @param appearing - Boolean if this is the initial `appear` flow.\n * @since 4.0.0\n */\nexport type TransitionEnterHandler = (appearing: boolean) => void;\n\n/**\n * This function is called at each `\"exit\"` {@link TransitionStage}. If a\n * {@link TransitionOptions.nodeRef} was provided, the DOM node should be\n * available in `nodeRef.current` by this point if the transition requires DOM\n * calculations.\n *\n * @since 4.0.0\n */\nexport type TransitionExitHandler = () => void;\n\n/**\n * @since 4.0.0\n */\nexport interface TransitionCallbacks {\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"enter\"`.\n *\n * NOTE: This callback will be skipped when transitions are disabled. Use the\n * `getTransitionCallbacks` helper if something should only be called once\n * while entering.\n *\n * @see {@link TransitionEnterHandler}\n */\n onEnter?: TransitionEnterHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"enter\"`.\n *\n * NOTE: This callback will be skipped when transitions are disabled. Use the\n * `getTransitionCallbacks` helper if something should only be called once\n * while entering.\n *\n * @see {@link TransitionEnterHandler}\n */\n onEntering?: TransitionEnterHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"entering\"`.\n *\n * @see {@link TransitionEnterHandler}\n */\n onEntered?: TransitionEnterHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"entered\"`.\n *\n * NOTE: This callback will be skipped when transitions are disabled. Use the\n * `getTransitionCallbacks` helper if something should only be called once\n * while exiting.\n *\n * @see {@link TransitionEnterHandler}\n */\n onExit?: TransitionExitHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"exiting\"`.\n *\n * NOTE: This callback will be skipped when transitions are disabled. Use the\n * `getTransitionCallbacks` helper if something should only be called once\n * while exiting.\n *\n * @see {@link TransitionExitHandler}\n */\n onExiting?: TransitionExitHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"exited\"`.\n *\n * @see {@link TransitionExitHandler}\n */\n onExited?: TransitionExitHandler;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface PreconfiguredTransitionInDefaultedOptions<\n E extends HTMLElement,\n> extends TransitionActions,\n TransitionCallbacks {\n /**\n * An optional ref that will be merged with the\n * {@link TransitionHookReturnValue.ref}\n */\n nodeRef?: Ref<E>;\n\n /**\n * Boolean if the element should mount and unmount based on the\n * {@link PreconfiguredTransitionInDefaultedOptions.transitionIn} value.\n *\n * @defaultValue `false`\n */\n temporary?: boolean;\n\n /**\n * This boolean controls the transition by activating flowing through the\n * {@link TransitionStage}.\n *\n * @see {@link TransitionActions} for a description around the transitions.\n */\n transitionIn?: boolean;\n\n /** {@inheritDoc TransitionTimeout} */\n timeout?: TransitionTimeout;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface PreconfiguredTransitionOptions<E extends HTMLElement>\n extends PreconfiguredTransitionInDefaultedOptions<E> {\n /** {@inheritDoc PreconfiguredTransitionInDefaultedOptions.transitionIn} */\n transitionIn: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface TransitionOptions<E extends HTMLElement>\n extends PreconfiguredTransitionOptions<E> {\n /** {@inheritDoc TransitionTimeout} */\n timeout: TransitionTimeout;\n}\n\n/**\n * An object of classnames that will be applied based on the\n * {@link TransitionStage} where all the classes in the previous stages will\n * also be applied.\n *\n * @example Explaining className application\n * ```ts\n * const { ref, className, stage, appearing } = useCSSTransition({\n * appear: true,\n * enter: true,\n * exit: true,\n * timeout: 300,\n * classNames: {\n * appear: \"appear\",\n * appearEnter: \"appear--enter\",\n * appearDone: \"appear--done appear--complete\",\n * enter: \"enter\",\n * enterEnter: \"\",\n * enterDone: \"enter--done enter--complete\",\n * exit: \"\",\n * exitEnter: \"\",\n * exitDone: \"exit--done exit--complete\",\n * }\n * });\n *\n * // stage === \"enter\" && appearing\n * // className === \"appear\"\n * //\n * // stage === \"entering\" && appearing\n * // className === \"appear appear--enter\"\n * //\n * // stage === \"entered\" && appearing\n * // className === \"appear--done appear--complete\"\n * //\n * //\n * // stage === \"enter\" && !appearing\n * // className === \"enter\"\n * //\n * // stage === \"entering\" && !appearing\n * // className === \"enter\"\n * //\n * // stage === \"entered\" && !appearing\n * // className === \"enter--done enter--complete\"\n * //\n * //\n * // stage === \"exit\"\n * // className === \"\"\n * //\n * // stage === \"exiting\"\n * // className === \"\"\n * //\n * // stage === \"exited\"\n * // className === \"exit--done exit--complete\"\n * ```\n *\n * @since 4.0.0\n */\nexport interface CSSTransitionClassNamesObject {\n /**\n * The class name to apply starting at the `\"enter\"` {@link TransitionStage}\n * while {@link TransitionState.appearing}.\n *\n * @defaultValue `\"\"`\n */\n appear?: string;\n\n /**\n * The class name to apply starting at the `\"entering\"` {@link TransitionStage}\n * while {@link TransitionState.appearing}.\n *\n * @defaultValue `\"\"`\n */\n appearActive?: string;\n\n /**\n * The class name to apply starting at the `\"entered\"` {@link TransitionStage}\n * while {@link TransitionState.appearing}.\n *\n * @defaultValue `\"\"`\n */\n appearDone?: string;\n\n /**\n * The class name to apply starting at the `\"enter\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n enter?: string;\n\n /**\n * The class name to apply starting at the `\"entering\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n enterActive?: string;\n\n /**\n * The class name to apply starting at the `\"entered\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n enterDone?: string;\n\n /**\n * The class name to apply starting at the `\"exit\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n exit?: string;\n\n /**\n * The class name to apply starting at the `\"exiting\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n exitActive?: string;\n\n /**\n * The class name to apply starting at the `\"exited\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n exitDone?: string;\n}\n\n/**\n * @since 4.0.0\n */\nexport type CSSTransitionClassNames =\n | string\n | Readonly<CSSTransitionClassNamesObject>;\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface PreconfiguredCSSTransitionInDefaultedOptions<\n E extends HTMLElement,\n> extends PreconfiguredTransitionInDefaultedOptions<E> {\n /**\n * An optional className to be merged with the transition classes.\n */\n className?: string;\n\n /**\n * When this is `true` and the {@link temporary} option is `false`, the\n * element will gain a class name to hide it with `display: none` instead of\n * conditionally rendering the element.\n *\n * @defaultValue `false`\n * @since 6.0.0\n */\n exitedHidden?: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface PreconfiguredCSSTransitionOptions<E extends HTMLElement>\n extends PreconfiguredCSSTransitionInDefaultedOptions<E> {\n /** {@inheritDoc PreconfiguredTransitionInDefaultedOptions.transitionIn} */\n transitionIn: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface SSRTransitionOptions {\n /**\n * This is mostly used internally to make it so that you can render portalled\n * elements inline with content if SSR is enabled in your app. To enable this\n * feature, the {@link CoreProvidersProps.ssr} must be set to `true`.\n *\n * This value will be `true` if a portalled element was rendered by default\n * from the server and remain true until it unmounts from the DOM.\n *\n * @defaultValue `false`\n */\n disablePortal?: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface TransitionHookOptions<E extends HTMLElement>\n extends TransitionOptions<E>,\n SSRTransitionOptions {\n /**\n * Boolean if the DOM should forcefully be reflow each time a transition\n * change occurs. This is generally required for any CSS transition and is\n * set to `true` for the {@link useCSSTransition} hook.\n *\n * @defaultValue `false`\n */\n reflow?: boolean;\n}\n\n/**\n * @since 4.0.0\n */\nexport interface TransitionState {\n /** {@inheritDoc TransitionStage} */\n stage: TransitionStage;\n\n /**\n * Boolean if the element should be rendered or not. This will always be\n * `true` if the {@link TransitionOptions.temporary} is `false`. Otherwise, it\n * will be `true` when not the `\"exited\"` {@link TransitionStage}.\n */\n rendered: boolean;\n\n /**\n * Boolean if this is the first {@link TransitionActions.appear} transition.\n * This will be `true` during the first transition if\n * {@link TransitionActions.appear} was also `true`. Otherwise it will be\n * `false`.\n */\n appearing: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface TransitionHookReturnValue<E extends HTMLElement>\n extends TransitionState,\n Required<SSRTransitionOptions> {\n /**\n * A ref that is required for the transition to occur and should be passed to\n * the element affected by the transition.\n */\n ref: RefCallback<E>;\n\n /**\n * A function that can be used to specifically set the transition to a\n * specific stage. This shouldn't really be used too much and is really just\n * useful for \"appear only transitions\" that do not unmount the child\n * elements.\n *\n * @example Simple Example\n * ```tsx\n * import { ReactElement, useEffect, useRef } from \"react\";\n * import { useCSSTransition } from \"@react-md/transition\";\n * import { useRouter } from \"react-router-dom\";\n *\n * function Example(): ReactElement {\n * const { pathname } = useRouter();\n * const { elementProps, transitionTo } = useCSSTransition({\n * transitionIn: true,\n * timeout: 1000,\n * classNames: \"some-enter-transition\",\n * });\n *\n * useEffect(() => {\n * // Do not trigger transition on first load.\n * if (prevPathname.current === pathname) {\n * return;\n * }\n *\n * prevPathname.current = pathname;\n * transitionTo(\"enter\");\n * }, [pathname, transitionTo]);\n *\n * return <div {...elementProps}>{content}</div>;\n * }\n * ```\n *\n * @param stage - The {@link TransitionStage} to set to\n */\n transitionTo: (stage: TransitionStage) => void;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CSSTransitionHookOptions<E extends HTMLElement>\n extends PreconfiguredCSSTransitionOptions<E>,\n SSRTransitionOptions {\n /** {@inheritDoc TransitionTimeout} */\n timeout: TransitionTimeout;\n /** {@inheritDoc CSSTransitionClassNames} */\n classNames: CSSTransitionClassNames;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CSSTransitionElementProps<E extends HTMLElement> {\n /** @see {@link TransitionHookReturnValue.ref} */\n ref: RefCallback<E>;\n\n /**\n * The current transition class name or `undefined`.\n */\n className: string | undefined;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CSSTransitionHookReturnValue<E extends HTMLElement>\n extends TransitionHookReturnValue<E>,\n CSSTransitionElementProps<E> {\n /**\n * This can be used so that you don't need to destructure multiple props from\n * the hook return value to pass to the transitioning component.\n *\n * @example Simple Example\n * ```tsx\n * import type { ReactElement } from \"react\";\n * import { useCSSTransition } from \"@react-md/transition\";\n *\n * interface ExampleProps {\n * transitionIn: boolean;\n * children: ReactNode;\n * }\n *\n * function Example({ transitionIn, children }: ExampleProps): ReactElement | null {\n * const { elementProps, rendered } = useCSSTransition({\n * timeout: 150,\n * classNames: \"example\",\n * transitionIn,\n * });\n *\n * if (!rendered) {\n * return null;\n * }\n *\n * return <div {...elementProps}>{children}</div>\n * }\n * ```\n *\n * @example Verbose Version\n * ```tsx\n * import type { ReactElement } from \"react\";\n * import { useCSSTransition } from \"@react-md/transition\";\n *\n * interface ExampleProps {\n * transitionIn: boolean;\n * children: ReactNode;\n * }\n *\n * function Example({ transitionIn, children }: ExampleProps): ReactElement | null {\n * const { ref, className, rendered } = useCSSTransition({\n * timeout: 150,\n * classNames: \"example\",\n * transitionIn,\n * });\n *\n * if (!rendered) {\n * return null;\n * }\n *\n * return <div ref={ref} className={className}>{children}</div>\n * }\n * ```\n */\n elementProps: CSSTransitionElementProps<E>;\n}\n\n/**\n * This is mostly an internal type that can be used to help with transitionable\n * components.\n *\n * @since 4.0.0\n */\nexport interface CSSTransitionComponentProps extends TransitionCallbacks {\n /** @see {@link CSSTransitionHookOptions.temporary} */\n temporary?: boolean;\n /** @see {@link TransitionTimeout} */\n timeout?: TransitionTimeout;\n /** @see {@link CSSTransitionClassNames} */\n classNames?: CSSTransitionClassNames;\n /** @see {@link CSSTransitionHookOptions.exitedHidden} */\n exitedHidden?: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CSSTransitionComponentImplementation<E extends HTMLElement> {\n /**\n * The child element that should have a `ref` and `className` cloned into\n * using the `cloneElement` API. If the child is a custom component, you\n * **must** use `React.forwardRef` and pass both of these to a DOM element for\n * the transition to work.\n */\n children: ReactElement<{ ref: Ref<E>; className: string | undefined }>;\n}\n"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,QAAQ;AAkmBR;;;;CAIC,GACD,WAQC"}
|
|
1
|
+
{"version":3,"sources":["../../src/transition/types.ts"],"sourcesContent":["// This is pretty much `react-transition-group` since I liked the API wanted a\n// hook implementation. I also had to redo most of the types for v4.0.0 due to\n// the new `nodeRef` stuff, so it made it easier to create the types and hooks\n// here.\nimport type { ReactElement, Ref, RefCallback } from \"react\";\n\n/**\n * @since 4.0.0\n */\nexport interface TransitionActions {\n /**\n * Boolean if the transition should occur immediately once the component\n * mounts if the {@link TransitionOptions.transitionIn} is `true`\n *\n * @defaultValue `false`\n */\n appear?: boolean;\n\n /**\n * Boolean if the transition should occur whenever the\n * {@link TransitionOptions.transitionIn} is switch to `true` after the\n * component has been rendered in the DOM.\n *\n * @defaultValue `true`\n */\n enter?: boolean;\n\n /**\n * Boolean if the transition should occur whenever the\n * {@link TransitionOptions.transitionIn} is switch to `false` after the\n * component has been rendered in the DOM.\n *\n * @defaultValue `true`\n */\n exit?: boolean;\n}\n\n/**\n * An object timeout values that would be used for each\n * {@link TransitionActions}. If a value is set to `0` or `undefined`, the\n * transition will not occur.\n *\n * @since 4.0.0\n */\nexport type TransitionTimeoutObject = {\n [action in keyof TransitionActions]?: number;\n};\n\n/**\n * Either a single timeout duration in milliseconds to use for each of the\n * {@link TransitionActions} stages, or an object of transition durations.\n *\n * @since 4.0.0\n */\nexport type TransitionTimeout = number | Readonly<TransitionTimeoutObject>;\n\n/**\n * @since 6.0.0\n */\nexport type TransitionEnterStage = \"enter\" | \"entering\" | \"entered\";\n\n/**\n * @since 6.0.0\n */\nexport type TransitionExitStage = \"exit\" | \"exiting\" | \"exited\";\n\n/**\n * The way the transition works is by flowing through the different stages and\n * assigning waiting for a timeout to occur. Setting the `stage` to `enter` will\n * begin the enter transition going from `enter -> entering -> entered` while\n * setting the stage to `exit` will transition from `exit -> exiting -> exited`.\n *\n * @since 4.0.0\n * @since 6.0.0 Type union between `TransitionEnterStage` and `TransitionExitStage`\n */\nexport type TransitionStage = TransitionEnterStage | TransitionExitStage;\n\n/**\n * This function is called at each `\"enter\"` {@link TransitionStage}. If a\n * {@link TransitionOptions.nodeRef} was provided, the DOM node should be\n * available in `nodeRef.current` by this point if the transition requires DOM\n * calculations.\n *\n * @param appearing - Boolean if this is the initial `appear` flow.\n * @since 4.0.0\n */\nexport type TransitionEnterHandler = (appearing: boolean) => void;\n\n/**\n * This function is called at each `\"exit\"` {@link TransitionStage}. If a\n * {@link TransitionOptions.nodeRef} was provided, the DOM node should be\n * available in `nodeRef.current` by this point if the transition requires DOM\n * calculations.\n *\n * @since 4.0.0\n */\nexport type TransitionExitHandler = () => void;\n\n/**\n * @since 4.0.0\n */\nexport interface TransitionCallbacks {\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"enter\"`.\n *\n * NOTE: This callback will be skipped when transitions are disabled. Use the\n * `getTransitionCallbacks` helper if something should only be called once\n * while entering.\n *\n * @see {@link TransitionEnterHandler}\n */\n onEnter?: TransitionEnterHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"enter\"`.\n *\n * NOTE: This callback will be skipped when transitions are disabled. Use the\n * `getTransitionCallbacks` helper if something should only be called once\n * while entering.\n *\n * @see {@link TransitionEnterHandler}\n */\n onEntering?: TransitionEnterHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"entering\"`.\n *\n * @see {@link TransitionEnterHandler}\n */\n onEntered?: TransitionEnterHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"entered\"`.\n *\n * NOTE: This callback will be skipped when transitions are disabled. Use the\n * `getTransitionCallbacks` helper if something should only be called once\n * while exiting.\n *\n * @see {@link TransitionEnterHandler}\n */\n onExit?: TransitionExitHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"exiting\"`.\n *\n * NOTE: This callback will be skipped when transitions are disabled. Use the\n * `getTransitionCallbacks` helper if something should only be called once\n * while exiting.\n *\n * @see {@link TransitionExitHandler}\n */\n onExiting?: TransitionExitHandler;\n\n /**\n * This function will be called once the {@link TransitionStage} has been set\n * to `\"exited\"`.\n *\n * @see {@link TransitionExitHandler}\n */\n onExited?: TransitionExitHandler;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface PreconfiguredTransitionInDefaultedOptions<\n E extends HTMLElement,\n>\n extends TransitionActions, TransitionCallbacks {\n /**\n * An optional ref that will be merged with the\n * {@link TransitionHookReturnValue.ref}\n */\n nodeRef?: Ref<E>;\n\n /**\n * Boolean if the element should mount and unmount based on the\n * {@link PreconfiguredTransitionInDefaultedOptions.transitionIn} value.\n *\n * @defaultValue `false`\n */\n temporary?: boolean;\n\n /**\n * This boolean controls the transition by activating flowing through the\n * {@link TransitionStage}.\n *\n * @see {@link TransitionActions} for a description around the transitions.\n */\n transitionIn?: boolean;\n\n /** {@inheritDoc TransitionTimeout} */\n timeout?: TransitionTimeout;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface PreconfiguredTransitionOptions<\n E extends HTMLElement,\n> extends PreconfiguredTransitionInDefaultedOptions<E> {\n /** {@inheritDoc PreconfiguredTransitionInDefaultedOptions.transitionIn} */\n transitionIn: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface TransitionOptions<\n E extends HTMLElement,\n> extends PreconfiguredTransitionOptions<E> {\n /** {@inheritDoc TransitionTimeout} */\n timeout: TransitionTimeout;\n}\n\n/**\n * An object of classnames that will be applied based on the\n * {@link TransitionStage} where all the classes in the previous stages will\n * also be applied.\n *\n * @example Explaining className application\n * ```ts\n * const { ref, className, stage, appearing } = useCSSTransition({\n * appear: true,\n * enter: true,\n * exit: true,\n * timeout: 300,\n * classNames: {\n * appear: \"appear\",\n * appearEnter: \"appear--enter\",\n * appearDone: \"appear--done appear--complete\",\n * enter: \"enter\",\n * enterEnter: \"\",\n * enterDone: \"enter--done enter--complete\",\n * exit: \"\",\n * exitEnter: \"\",\n * exitDone: \"exit--done exit--complete\",\n * }\n * });\n *\n * // stage === \"enter\" && appearing\n * // className === \"appear\"\n * //\n * // stage === \"entering\" && appearing\n * // className === \"appear appear--enter\"\n * //\n * // stage === \"entered\" && appearing\n * // className === \"appear--done appear--complete\"\n * //\n * //\n * // stage === \"enter\" && !appearing\n * // className === \"enter\"\n * //\n * // stage === \"entering\" && !appearing\n * // className === \"enter\"\n * //\n * // stage === \"entered\" && !appearing\n * // className === \"enter--done enter--complete\"\n * //\n * //\n * // stage === \"exit\"\n * // className === \"\"\n * //\n * // stage === \"exiting\"\n * // className === \"\"\n * //\n * // stage === \"exited\"\n * // className === \"exit--done exit--complete\"\n * ```\n *\n * @since 4.0.0\n */\nexport interface CSSTransitionClassNamesObject {\n /**\n * The class name to apply starting at the `\"enter\"` {@link TransitionStage}\n * while {@link TransitionState.appearing}.\n *\n * @defaultValue `\"\"`\n */\n appear?: string;\n\n /**\n * The class name to apply starting at the `\"entering\"` {@link TransitionStage}\n * while {@link TransitionState.appearing}.\n *\n * @defaultValue `\"\"`\n */\n appearActive?: string;\n\n /**\n * The class name to apply starting at the `\"entered\"` {@link TransitionStage}\n * while {@link TransitionState.appearing}.\n *\n * @defaultValue `\"\"`\n */\n appearDone?: string;\n\n /**\n * The class name to apply starting at the `\"enter\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n enter?: string;\n\n /**\n * The class name to apply starting at the `\"entering\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n enterActive?: string;\n\n /**\n * The class name to apply starting at the `\"entered\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n enterDone?: string;\n\n /**\n * The class name to apply starting at the `\"exit\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n exit?: string;\n\n /**\n * The class name to apply starting at the `\"exiting\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n exitActive?: string;\n\n /**\n * The class name to apply starting at the `\"exited\"` {@link TransitionStage}\n *\n * @defaultValue `\"\"`\n */\n exitDone?: string;\n}\n\n/**\n * @since 4.0.0\n */\nexport type CSSTransitionClassNames =\n | string\n | Readonly<CSSTransitionClassNamesObject>;\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface PreconfiguredCSSTransitionInDefaultedOptions<\n E extends HTMLElement,\n> extends PreconfiguredTransitionInDefaultedOptions<E> {\n /**\n * An optional className to be merged with the transition classes.\n */\n className?: string;\n\n /**\n * When this is `true` and the {@link temporary} option is `false`, the\n * element will gain a class name to hide it with `display: none` instead of\n * conditionally rendering the element.\n *\n * @defaultValue `false`\n * @since 6.0.0\n */\n exitedHidden?: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface PreconfiguredCSSTransitionOptions<\n E extends HTMLElement,\n> extends PreconfiguredCSSTransitionInDefaultedOptions<E> {\n /** {@inheritDoc PreconfiguredTransitionInDefaultedOptions.transitionIn} */\n transitionIn: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface SSRTransitionOptions {\n /**\n * This is mostly used internally to make it so that you can render portalled\n * elements inline with content if SSR is enabled in your app. To enable this\n * feature, the {@link CoreProvidersProps.ssr} must be set to `true`.\n *\n * This value will be `true` if a portalled element was rendered by default\n * from the server and remain true until it unmounts from the DOM.\n *\n * @defaultValue `false`\n */\n disablePortal?: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface TransitionHookOptions<E extends HTMLElement>\n extends TransitionOptions<E>, SSRTransitionOptions {\n /**\n * Boolean if the DOM should forcefully be reflow each time a transition\n * change occurs. This is generally required for any CSS transition and is\n * set to `true` for the {@link useCSSTransition} hook.\n *\n * @defaultValue `false`\n */\n reflow?: boolean;\n}\n\n/**\n * @since 4.0.0\n */\nexport interface TransitionState {\n /** {@inheritDoc TransitionStage} */\n stage: TransitionStage;\n\n /**\n * Boolean if the element should be rendered or not. This will always be\n * `true` if the {@link TransitionOptions.temporary} is `false`. Otherwise, it\n * will be `true` when not the `\"exited\"` {@link TransitionStage}.\n */\n rendered: boolean;\n\n /**\n * Boolean if this is the first {@link TransitionActions.appear} transition.\n * This will be `true` during the first transition if\n * {@link TransitionActions.appear} was also `true`. Otherwise it will be\n * `false`.\n */\n appearing: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface TransitionHookReturnValue<E extends HTMLElement>\n extends TransitionState, Required<SSRTransitionOptions> {\n /**\n * A ref that is required for the transition to occur and should be passed to\n * the element affected by the transition.\n */\n ref: RefCallback<E>;\n\n /**\n * A function that can be used to specifically set the transition to a\n * specific stage. This shouldn't really be used too much and is really just\n * useful for \"appear only transitions\" that do not unmount the child\n * elements.\n *\n * @example Simple Example\n * ```tsx\n * import { ReactElement, useEffect, useRef } from \"react\";\n * import { useCSSTransition } from \"@react-md/transition\";\n * import { useRouter } from \"react-router-dom\";\n *\n * function Example(): ReactElement {\n * const { pathname } = useRouter();\n * const { elementProps, transitionTo } = useCSSTransition({\n * transitionIn: true,\n * timeout: 1000,\n * classNames: \"some-enter-transition\",\n * });\n *\n * useEffect(() => {\n * // Do not trigger transition on first load.\n * if (prevPathname.current === pathname) {\n * return;\n * }\n *\n * prevPathname.current = pathname;\n * transitionTo(\"enter\");\n * }, [pathname, transitionTo]);\n *\n * return <div {...elementProps}>{content}</div>;\n * }\n * ```\n *\n * @param stage - The {@link TransitionStage} to set to\n */\n transitionTo: (stage: TransitionStage) => void;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CSSTransitionHookOptions<E extends HTMLElement>\n extends PreconfiguredCSSTransitionOptions<E>, SSRTransitionOptions {\n /** {@inheritDoc TransitionTimeout} */\n timeout: TransitionTimeout;\n /** {@inheritDoc CSSTransitionClassNames} */\n classNames: CSSTransitionClassNames;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CSSTransitionElementProps<E extends HTMLElement> {\n /** @see {@link TransitionHookReturnValue.ref} */\n ref: RefCallback<E>;\n\n /**\n * The current transition class name or `undefined`.\n */\n className: string | undefined;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CSSTransitionHookReturnValue<E extends HTMLElement>\n extends TransitionHookReturnValue<E>, CSSTransitionElementProps<E> {\n /**\n * This can be used so that you don't need to destructure multiple props from\n * the hook return value to pass to the transitioning component.\n *\n * @example Simple Example\n * ```tsx\n * import type { ReactElement } from \"react\";\n * import { useCSSTransition } from \"@react-md/transition\";\n *\n * interface ExampleProps {\n * transitionIn: boolean;\n * children: ReactNode;\n * }\n *\n * function Example({ transitionIn, children }: ExampleProps): ReactElement | null {\n * const { elementProps, rendered } = useCSSTransition({\n * timeout: 150,\n * classNames: \"example\",\n * transitionIn,\n * });\n *\n * if (!rendered) {\n * return null;\n * }\n *\n * return <div {...elementProps}>{children}</div>\n * }\n * ```\n *\n * @example Verbose Version\n * ```tsx\n * import type { ReactElement } from \"react\";\n * import { useCSSTransition } from \"@react-md/transition\";\n *\n * interface ExampleProps {\n * transitionIn: boolean;\n * children: ReactNode;\n * }\n *\n * function Example({ transitionIn, children }: ExampleProps): ReactElement | null {\n * const { ref, className, rendered } = useCSSTransition({\n * timeout: 150,\n * classNames: \"example\",\n * transitionIn,\n * });\n *\n * if (!rendered) {\n * return null;\n * }\n *\n * return <div ref={ref} className={className}>{children}</div>\n * }\n * ```\n */\n elementProps: CSSTransitionElementProps<E>;\n}\n\n/**\n * This is mostly an internal type that can be used to help with transitionable\n * components.\n *\n * @since 4.0.0\n */\nexport interface CSSTransitionComponentProps extends TransitionCallbacks {\n /** @see {@link CSSTransitionHookOptions.temporary} */\n temporary?: boolean;\n /** @see {@link TransitionTimeout} */\n timeout?: TransitionTimeout;\n /** @see {@link CSSTransitionClassNames} */\n classNames?: CSSTransitionClassNames;\n /** @see {@link CSSTransitionHookOptions.exitedHidden} */\n exitedHidden?: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CSSTransitionComponentImplementation<E extends HTMLElement> {\n /**\n * The child element that should have a `ref` and `className` cloned into\n * using the `cloneElement` API. If the child is a custom component, you\n * **must** use `React.forwardRef` and pass both of these to a DOM element for\n * the transition to work.\n */\n children: ReactElement<{ ref: Ref<E>; className: string | undefined }>;\n}\n"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,QAAQ;AAimBR;;;;CAIC,GACD,WAQC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transition/useCollapseTransition.ts"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport { type CSSProperties, useState } from \"react\";\n\nimport { useEnsuredRef } from \"../useEnsuredRef.js\";\nimport { DISPLAY_NONE_CLASS } from \"../utils/isElementVisible.js\";\nimport { collapse } from \"./collapseStyles.js\";\nimport {\n type CSSTransitionElementProps,\n type CSSTransitionHookReturnValue,\n type PreconfiguredCSSTransitionOptions,\n type TransitionTimeout,\n} from \"./types.js\";\nimport { useTransition } from \"./useTransition.js\";\nimport { getElementSizing, getTransitionTimeout } from \"./utils.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * @since 2.0.0\n */\nexport const DEFAULT_COLLAPSE_TIMEOUT = {\n enter: 250,\n exit: 200,\n} as const satisfies TransitionTimeout;\n\n/**\n * @since 4.0.0\n */\nexport interface CollapseConfigurationStyle {\n /**\n * The minimum height that the collapsed element can be which defaults to `0`.\n * This can either be a number of pixels or a string CSS height value.\n *\n * Setting this value to any non-zero value will allow for the element to\n * shrink to the defined min-height, and then expand to the full height once\n * no longer collapsed.\n *\n * Note: If the `minHeight`, `minPaddingTop`, and `minPaddingBottom` options\n * are all set to `0` (default), the child will be removed from the DOM while\n * collapsed.\n *\n * @defaultValue `0`\n */\n minHeight?: number | string;\n\n /**\n * The minimum padding-top that the collapsed element can be which defaults to\n * `0`. This can either be a number of pixels or a string CSS `padding-top`\n * value.\n *\n * Note: If the `minHeight`, `minPaddingTop`, and `minPaddingBottom` options\n * are all set to `0` (default), the child will be removed from the DOM while\n * collapsed.\n *\n * @defaultValue `0`\n */\n minPaddingTop?: number | string;\n\n /**\n * The minimum padding-bottom that the collapsed element can be which defaults\n * to `0`. This can either be a number of pixels or a string CSS\n * `padding-bottom` value.\n *\n * Note: If the `minHeight`, `minPaddingTop`, and `minPaddingBottom` options\n * are all set to `0` (default), the child will be removed from the DOM while\n * collapsed.\n *\n * @defaultValue `0`\n */\n minPaddingBottom?: number | string;\n}\n\n/**\n * @since 4.0.0\n */\nexport interface CollapseStyle extends CollapseConfigurationStyle {\n /**\n * This will only be set when the {@link TransitionStage} is `\"entering\"` or\n * `\"exiting\"` as `\"${timeout}ms\"`.\n */\n transitionDuration?: string;\n}\n\n/**\n * These props (and `ref`) **must** be passed to a DOM element for the collapse\n * transition to work.\n *\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CollapseElementProps<E extends HTMLElement>\n extends CSSTransitionElementProps<E> {\n /**\n * A merged styled object required for the collapse transition to work.\n *\n * @see {@link CollapseStyle}\n * @see {@link CollapseTransitionHookOptions.style}\n */\n style: CSSProperties;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CollapseTransitionHookOptions<E extends HTMLElement>\n extends Omit<PreconfiguredCSSTransitionOptions<E>, \"exitedHidden\">,\n CollapseConfigurationStyle {\n /**\n * An optional style to merge with the required collapse transition styles.\n *\n * If any keys from the {@link CollapseStyle} are included in this object,\n * these styles will override and possibly break the collapse transition.\n */\n style?: CSSProperties;\n\n /**\n *\n * @see {@link DEFAULT_COLLAPSE_TIMEOUT}\n * @defaultValue `DEFAULT_COLLAPSE_TIMEOUT`\n */\n timeout?: TransitionTimeout;\n\n /**\n *\n * @defaultValue `minHeight === 0 && minPaddingTop === 0 && minPaddingBottom === 0`\n */\n temporary?: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CollapseTransitionHookReturnValue<E extends HTMLElement>\n extends CSSTransitionHookReturnValue<E>,\n CollapseElementProps<E> {\n /**\n * This is just a convenience object so that you don't need to destructure as\n * many variables to pass to an element.\n *\n * @example Simple Usage\n * ```tsx\n * const { elementProps, rendered } = useCollapseTransition({\n * // ...options\n * transitionIn,\n * });\n *\n * if (!rendered) {\n * return null\n * }\n *\n * return <div {...elementProps}>{children}</div>;\n *\n * // This is the long-hand version\n * const { ref, style, className, hidden, rendered } = useCollapseTransition({\n * // ...options\n * transitionIn,\n * });\n *\n * if (!rendered) {\n * return null\n * }\n *\n * return (\n * <div\n * ref={ref}\n * style={style}\n * className={className}\n * hidden={hidden}\n * >\n * {children}\n * </div>\n * );\n * ```\n */\n elementProps: Readonly<CollapseElementProps<E>>;\n}\n\n/**\n * This hook is used to create a transition to collapse and expand an element\n * **inline** with other content like an accordion by animating the\n * `max-height`, `padding-top`, and `padding-bottom` CSS properties. The default\n * behavior is to hide the element completely while collapsed, but providing the\n * `minHeight`, `minPaddingTop`, and `minPaddingBottom` options can make this\n * work like a \"See More\"/\"Preview\" type of element\n *\n * @example Simple Example\n * ```tsx\n * import { Button } from \"@react-md/core/button/Button\";\n * import { useCollapseTransition } from \"@react-md/core/transition/useCollapseTransition\";\n * import { Typography } from \"@react-md/core/typography/Typography\";\n * import { type ReactElement, useState } from \"react\";\n *\n * function Example(): ReactElement {\n * const [collapsed, setCollapsed] = useState(true);\n * const { elementProps, rendered } =\n * useCollapseTransition({\n * transitionIn: !collapsed,\n * // If the collapsible element should maintain state by not unmounting\n * // while collapsed, uncomment this next line\n * // temporary: false,\n * });\n *\n * return (\n * <>\n * <Button onClick={() => setCollapsed(!collapsed)}>\n * Toggle\n * </Button>\n * {rendered && (\n * <div {...elementProps}>\n * <Typography>Stuff that should be collapsed</Typography>\n * <div>Whatever content...</div>\n * </div>\n * )}\n * </>\n * );\n * }\n * ```\n *\n * @example See More Example\n * ```tsx\n * import { Button } from \"@react-md/core/button/Button\";\n * import { IconRotator } from \"@react-md/core/icon/IconRotator\";\n * import KeyboardArrowDownIcon from \"@react-md/material-icons/KeyboardArrowDownIcon\"\n * import { useCollapseTransition } from \"@react-md/core/transition/useCollapseTransition\";\n * import { Typography } from \"@react-md/core/typography/Typography\";\n * import { type ReactElement, useState } from \"react\";\n *\n * import styles from \"./Example.module.scss\";\n * // pretend styles:\n * //\n * // .container {\n * // padding: 1rem;\n * // position: relative;\n * // }\n * //\n * // .button {\n * // position: absolute;\n * // right: 0;\n * // top: 0;\n * // }\n *\n *\n * function Example(): ReactElement {\n * const [collapsed, setCollapsed] = useState(true);\n * const { elementProps } =\n * useCollapseTransition({\n * transitionIn: !collapsed,\n * minHeight: 120,\n * minPaddingTop: 16,\n * className: styles.container,\n * });\n *\n * return (\n * <div {...elementProps}>\n * <Button\n * aria-expanded={!collapsed}\n * aria-label=\"Expand\"\n * onClick={() => setCollapsed(!collapsed)}\n * buttonType=\"icon\"\n * className={styles.button}\n * >\n * <IconRotator rotated={!collapsed}>\n * <KeyboardArrowDownIcon />\n * </IconRotator>\n * </Button>\n * <SomeComponentWithALotOfContent />\n * </div>\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/hooks/use-collapse-transition | useCollapseTransition Demos}\n * @see {@link https://react-md.dev/components/collapse | Collapse Demos}\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport function useCollapseTransition<E extends HTMLElement>(\n options: CollapseTransitionHookOptions<E>\n): CollapseTransitionHookReturnValue<E> {\n const {\n nodeRef: propNodeRef,\n style: propStyle,\n className,\n transitionIn,\n timeout = DEFAULT_COLLAPSE_TIMEOUT,\n minHeight = 0,\n minPaddingTop = 0,\n minPaddingBottom = 0,\n temporary = minHeight === 0 &&\n minPaddingTop === 0 &&\n minPaddingBottom === 0,\n appear = false,\n enter = true,\n exit = true,\n onEnter = noop,\n onEntering = noop,\n onEntered = noop,\n onExit = noop,\n onExiting = noop,\n onExited = noop,\n } = options;\n\n const [nodeRef, refCallback] = useEnsuredRef(propNodeRef);\n const [style, setStyle] = useState<CSSProperties | undefined>(() => {\n if (transitionIn) {\n return undefined;\n }\n\n return {\n maxHeight: minHeight,\n paddingTop: minPaddingTop,\n paddingBottom: minPaddingBottom,\n };\n });\n\n const transitionTimeout = getTransitionTimeout({\n timeout,\n appear,\n enter,\n exit,\n });\n\n const { appearing, rendered, ref, stage, transitionTo, disablePortal } =\n useTransition({\n nodeRef: refCallback,\n timeout,\n transitionIn,\n reflow: true,\n appear,\n enter,\n exit,\n temporary,\n onEnter(appearing) {\n onEnter(appearing);\n setStyle({\n maxHeight: minHeight,\n paddingTop: minPaddingTop,\n paddingBottom: minPaddingBottom,\n });\n },\n onEntering(appearing) {\n onEntering(appearing);\n const { maxHeight, paddingTop, paddingBottom } = getElementSizing(\n nodeRef.current\n );\n\n const duration = appearing\n ? transitionTimeout.appear\n : transitionTimeout.enter;\n\n setStyle({\n maxHeight,\n paddingTop,\n paddingBottom,\n transitionDuration: `${duration}ms`,\n });\n },\n onEntered(appearing) {\n onEntered(appearing);\n setStyle(undefined);\n },\n onExit() {\n onExit();\n const { maxHeight, paddingTop, paddingBottom } = getElementSizing(\n nodeRef.current\n );\n\n setStyle({\n maxHeight,\n paddingTop,\n paddingBottom,\n transitionDuration: `${transitionTimeout.exit}ms`,\n });\n },\n onExiting() {\n onExiting();\n setStyle({\n maxHeight: minHeight,\n paddingTop: minPaddingTop,\n paddingBottom: minPaddingBottom,\n transitionDuration: `${transitionTimeout.exit}ms`,\n });\n },\n onExited() {\n onExited();\n setStyle({\n maxHeight: minHeight,\n paddingTop: minPaddingTop,\n paddingBottom: minPaddingBottom,\n });\n },\n });\n const entering = stage === \"enter\" || stage === \"entering\";\n const exiting = stage === \"exit\" || stage === \"exiting\";\n const collapsible =\n transitionTimeout.enter !== 0 || transitionTimeout.exit !== 0;\n\n const elementProps: CollapseElementProps<E> = {\n ref,\n style: { ...style, ...propStyle },\n className:\n cnb(\n className,\n collapsible &&\n collapse({\n enter: entering,\n leave: exiting,\n disableOverflow: !transitionIn || !!style,\n }),\n stage === \"exited\" &&\n minHeight === 0 &&\n minPaddingTop === 0 &&\n minPaddingBottom === 0 &&\n DISPLAY_NONE_CLASS\n ) || undefined,\n };\n\n return {\n ...elementProps,\n stage,\n rendered,\n appearing,\n elementProps,\n transitionTo,\n disablePortal,\n };\n}\n"],"names":["cnb","useState","useEnsuredRef","DISPLAY_NONE_CLASS","collapse","useTransition","getElementSizing","getTransitionTimeout","noop","DEFAULT_COLLAPSE_TIMEOUT","enter","exit","useCollapseTransition","options","nodeRef","propNodeRef","style","propStyle","className","transitionIn","timeout","minHeight","minPaddingTop","minPaddingBottom","temporary","appear","onEnter","onEntering","onEntered","onExit","onExiting","onExited","refCallback","setStyle","undefined","maxHeight","paddingTop","paddingBottom","transitionTimeout","appearing","rendered","ref","stage","transitionTo","disablePortal","reflow","current","duration","transitionDuration","entering","exiting","collapsible","elementProps","leave","disableOverflow"],"mappings":"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"}
|
|
1
|
+
{"version":3,"sources":["../../src/transition/useCollapseTransition.ts"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport { type CSSProperties, useState } from \"react\";\n\nimport { useEnsuredRef } from \"../useEnsuredRef.js\";\nimport { DISPLAY_NONE_CLASS } from \"../utils/isElementVisible.js\";\nimport { collapse } from \"./collapseStyles.js\";\nimport {\n type CSSTransitionElementProps,\n type CSSTransitionHookReturnValue,\n type PreconfiguredCSSTransitionOptions,\n type TransitionTimeout,\n} from \"./types.js\";\nimport { useTransition } from \"./useTransition.js\";\nimport { getElementSizing, getTransitionTimeout } from \"./utils.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * @since 2.0.0\n */\nexport const DEFAULT_COLLAPSE_TIMEOUT = {\n enter: 250,\n exit: 200,\n} as const satisfies TransitionTimeout;\n\n/**\n * @since 4.0.0\n */\nexport interface CollapseConfigurationStyle {\n /**\n * The minimum height that the collapsed element can be which defaults to `0`.\n * This can either be a number of pixels or a string CSS height value.\n *\n * Setting this value to any non-zero value will allow for the element to\n * shrink to the defined min-height, and then expand to the full height once\n * no longer collapsed.\n *\n * Note: If the `minHeight`, `minPaddingTop`, and `minPaddingBottom` options\n * are all set to `0` (default), the child will be removed from the DOM while\n * collapsed.\n *\n * @defaultValue `0`\n */\n minHeight?: number | string;\n\n /**\n * The minimum padding-top that the collapsed element can be which defaults to\n * `0`. This can either be a number of pixels or a string CSS `padding-top`\n * value.\n *\n * Note: If the `minHeight`, `minPaddingTop`, and `minPaddingBottom` options\n * are all set to `0` (default), the child will be removed from the DOM while\n * collapsed.\n *\n * @defaultValue `0`\n */\n minPaddingTop?: number | string;\n\n /**\n * The minimum padding-bottom that the collapsed element can be which defaults\n * to `0`. This can either be a number of pixels or a string CSS\n * `padding-bottom` value.\n *\n * Note: If the `minHeight`, `minPaddingTop`, and `minPaddingBottom` options\n * are all set to `0` (default), the child will be removed from the DOM while\n * collapsed.\n *\n * @defaultValue `0`\n */\n minPaddingBottom?: number | string;\n}\n\n/**\n * @since 4.0.0\n */\nexport interface CollapseStyle extends CollapseConfigurationStyle {\n /**\n * This will only be set when the {@link TransitionStage} is `\"entering\"` or\n * `\"exiting\"` as `\"${timeout}ms\"`.\n */\n transitionDuration?: string;\n}\n\n/**\n * These props (and `ref`) **must** be passed to a DOM element for the collapse\n * transition to work.\n *\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CollapseElementProps<\n E extends HTMLElement,\n> extends CSSTransitionElementProps<E> {\n /**\n * A merged styled object required for the collapse transition to work.\n *\n * @see {@link CollapseStyle}\n * @see {@link CollapseTransitionHookOptions.style}\n */\n style: CSSProperties;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CollapseTransitionHookOptions<E extends HTMLElement>\n extends\n Omit<PreconfiguredCSSTransitionOptions<E>, \"exitedHidden\">,\n CollapseConfigurationStyle {\n /**\n * An optional style to merge with the required collapse transition styles.\n *\n * If any keys from the {@link CollapseStyle} are included in this object,\n * these styles will override and possibly break the collapse transition.\n */\n style?: CSSProperties;\n\n /**\n *\n * @see {@link DEFAULT_COLLAPSE_TIMEOUT}\n * @defaultValue `DEFAULT_COLLAPSE_TIMEOUT`\n */\n timeout?: TransitionTimeout;\n\n /**\n *\n * @defaultValue `minHeight === 0 && minPaddingTop === 0 && minPaddingBottom === 0`\n */\n temporary?: boolean;\n}\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CollapseTransitionHookReturnValue<E extends HTMLElement>\n extends CSSTransitionHookReturnValue<E>, CollapseElementProps<E> {\n /**\n * This is just a convenience object so that you don't need to destructure as\n * many variables to pass to an element.\n *\n * @example Simple Usage\n * ```tsx\n * const { elementProps, rendered } = useCollapseTransition({\n * // ...options\n * transitionIn,\n * });\n *\n * if (!rendered) {\n * return null\n * }\n *\n * return <div {...elementProps}>{children}</div>;\n *\n * // This is the long-hand version\n * const { ref, style, className, hidden, rendered } = useCollapseTransition({\n * // ...options\n * transitionIn,\n * });\n *\n * if (!rendered) {\n * return null\n * }\n *\n * return (\n * <div\n * ref={ref}\n * style={style}\n * className={className}\n * hidden={hidden}\n * >\n * {children}\n * </div>\n * );\n * ```\n */\n elementProps: Readonly<CollapseElementProps<E>>;\n}\n\n/**\n * This hook is used to create a transition to collapse and expand an element\n * **inline** with other content like an accordion by animating the\n * `max-height`, `padding-top`, and `padding-bottom` CSS properties. The default\n * behavior is to hide the element completely while collapsed, but providing the\n * `minHeight`, `minPaddingTop`, and `minPaddingBottom` options can make this\n * work like a \"See More\"/\"Preview\" type of element\n *\n * @example Simple Example\n * ```tsx\n * import { Button } from \"@react-md/core/button/Button\";\n * import { useCollapseTransition } from \"@react-md/core/transition/useCollapseTransition\";\n * import { Typography } from \"@react-md/core/typography/Typography\";\n * import { type ReactElement, useState } from \"react\";\n *\n * function Example(): ReactElement {\n * const [collapsed, setCollapsed] = useState(true);\n * const { elementProps, rendered } =\n * useCollapseTransition({\n * transitionIn: !collapsed,\n * // If the collapsible element should maintain state by not unmounting\n * // while collapsed, uncomment this next line\n * // temporary: false,\n * });\n *\n * return (\n * <>\n * <Button onClick={() => setCollapsed(!collapsed)}>\n * Toggle\n * </Button>\n * {rendered && (\n * <div {...elementProps}>\n * <Typography>Stuff that should be collapsed</Typography>\n * <div>Whatever content...</div>\n * </div>\n * )}\n * </>\n * );\n * }\n * ```\n *\n * @example See More Example\n * ```tsx\n * import { Button } from \"@react-md/core/button/Button\";\n * import { IconRotator } from \"@react-md/core/icon/IconRotator\";\n * import KeyboardArrowDownIcon from \"@react-md/material-icons/KeyboardArrowDownIcon\"\n * import { useCollapseTransition } from \"@react-md/core/transition/useCollapseTransition\";\n * import { Typography } from \"@react-md/core/typography/Typography\";\n * import { type ReactElement, useState } from \"react\";\n *\n * import styles from \"./Example.module.scss\";\n * // pretend styles:\n * //\n * // .container {\n * // padding: 1rem;\n * // position: relative;\n * // }\n * //\n * // .button {\n * // position: absolute;\n * // right: 0;\n * // top: 0;\n * // }\n *\n *\n * function Example(): ReactElement {\n * const [collapsed, setCollapsed] = useState(true);\n * const { elementProps } =\n * useCollapseTransition({\n * transitionIn: !collapsed,\n * minHeight: 120,\n * minPaddingTop: 16,\n * className: styles.container,\n * });\n *\n * return (\n * <div {...elementProps}>\n * <Button\n * aria-expanded={!collapsed}\n * aria-label=\"Expand\"\n * onClick={() => setCollapsed(!collapsed)}\n * buttonType=\"icon\"\n * className={styles.button}\n * >\n * <IconRotator rotated={!collapsed}>\n * <KeyboardArrowDownIcon />\n * </IconRotator>\n * </Button>\n * <SomeComponentWithALotOfContent />\n * </div>\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/hooks/use-collapse-transition | useCollapseTransition Demos}\n * @see {@link https://react-md.dev/components/collapse | Collapse Demos}\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport function useCollapseTransition<E extends HTMLElement>(\n options: CollapseTransitionHookOptions<E>\n): CollapseTransitionHookReturnValue<E> {\n const {\n nodeRef: propNodeRef,\n style: propStyle,\n className,\n transitionIn,\n timeout = DEFAULT_COLLAPSE_TIMEOUT,\n minHeight = 0,\n minPaddingTop = 0,\n minPaddingBottom = 0,\n temporary = minHeight === 0 &&\n minPaddingTop === 0 &&\n minPaddingBottom === 0,\n appear = false,\n enter = true,\n exit = true,\n onEnter = noop,\n onEntering = noop,\n onEntered = noop,\n onExit = noop,\n onExiting = noop,\n onExited = noop,\n } = options;\n\n const [nodeRef, refCallback] = useEnsuredRef(propNodeRef);\n const [style, setStyle] = useState<CSSProperties | undefined>(() => {\n if (transitionIn) {\n return undefined;\n }\n\n return {\n maxHeight: minHeight,\n paddingTop: minPaddingTop,\n paddingBottom: minPaddingBottom,\n };\n });\n\n const transitionTimeout = getTransitionTimeout({\n timeout,\n appear,\n enter,\n exit,\n });\n\n const { appearing, rendered, ref, stage, transitionTo, disablePortal } =\n useTransition({\n nodeRef: refCallback,\n timeout,\n transitionIn,\n reflow: true,\n appear,\n enter,\n exit,\n temporary,\n onEnter(appearing) {\n onEnter(appearing);\n setStyle({\n maxHeight: minHeight,\n paddingTop: minPaddingTop,\n paddingBottom: minPaddingBottom,\n });\n },\n onEntering(appearing) {\n onEntering(appearing);\n const { maxHeight, paddingTop, paddingBottom } = getElementSizing(\n nodeRef.current\n );\n\n const duration = appearing\n ? transitionTimeout.appear\n : transitionTimeout.enter;\n\n setStyle({\n maxHeight,\n paddingTop,\n paddingBottom,\n transitionDuration: `${duration}ms`,\n });\n },\n onEntered(appearing) {\n onEntered(appearing);\n setStyle(undefined);\n },\n onExit() {\n onExit();\n const { maxHeight, paddingTop, paddingBottom } = getElementSizing(\n nodeRef.current\n );\n\n setStyle({\n maxHeight,\n paddingTop,\n paddingBottom,\n transitionDuration: `${transitionTimeout.exit}ms`,\n });\n },\n onExiting() {\n onExiting();\n setStyle({\n maxHeight: minHeight,\n paddingTop: minPaddingTop,\n paddingBottom: minPaddingBottom,\n transitionDuration: `${transitionTimeout.exit}ms`,\n });\n },\n onExited() {\n onExited();\n setStyle({\n maxHeight: minHeight,\n paddingTop: minPaddingTop,\n paddingBottom: minPaddingBottom,\n });\n },\n });\n const entering = stage === \"enter\" || stage === \"entering\";\n const exiting = stage === \"exit\" || stage === \"exiting\";\n const collapsible =\n transitionTimeout.enter !== 0 || transitionTimeout.exit !== 0;\n\n const elementProps: CollapseElementProps<E> = {\n ref,\n style: { ...style, ...propStyle },\n className:\n cnb(\n className,\n collapsible &&\n collapse({\n enter: entering,\n leave: exiting,\n disableOverflow: !transitionIn || !!style,\n }),\n stage === \"exited\" &&\n minHeight === 0 &&\n minPaddingTop === 0 &&\n minPaddingBottom === 0 &&\n DISPLAY_NONE_CLASS\n ) || undefined,\n };\n\n return {\n ...elementProps,\n stage,\n rendered,\n appearing,\n elementProps,\n transitionTo,\n disablePortal,\n };\n}\n"],"names":["cnb","useState","useEnsuredRef","DISPLAY_NONE_CLASS","collapse","useTransition","getElementSizing","getTransitionTimeout","noop","DEFAULT_COLLAPSE_TIMEOUT","enter","exit","useCollapseTransition","options","nodeRef","propNodeRef","style","propStyle","className","transitionIn","timeout","minHeight","minPaddingTop","minPaddingBottom","temporary","appear","onEnter","onEntering","onEntered","onExit","onExiting","onExited","refCallback","setStyle","undefined","maxHeight","paddingTop","paddingBottom","transitionTimeout","appearing","rendered","ref","stage","transitionTo","disablePortal","reflow","current","duration","transitionDuration","entering","exiting","collapsible","elementProps","leave","disableOverflow"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transition/useCrossFadeTransition.ts"],"sourcesContent":["\"use client\";\n\nimport type {\n CSSTransitionClassNames,\n CSSTransitionHookReturnValue,\n PreconfiguredCSSTransitionInDefaultedOptions,\n TransitionTimeout,\n} from \"./types.js\";\nimport { useCSSTransition } from \"./useCSSTransition.js\";\n\n/**\n * The default cross fade transition timeout.\n *\n * @since 2.0.0\n * @since 6.0.0 Renamed from `CROSS_FADE_TIMEOUT` to\n * `DEFAULT_CROSS_FADE_TIMEOUT`\n */\nexport const DEFAULT_CROSS_FADE_TIMEOUT = {\n appear: 300,\n enter: 300,\n exit: 0,\n} as const satisfies TransitionTimeout;\n\n/**\n * The default cross fade transition classes to use.\n *\n * @since 2.0.0\n * @since 6.0.0 Renamed from `CROSS_FADE_CLASSNAMES` to\n * `DEFAULT_CROSS_FADE_CLASSNAMES`.\n */\nexport const DEFAULT_CROSS_FADE_CLASSNAMES = {\n appear: \"rmd-cross-fade\",\n appearActive: \"rmd-cross-fade--active\",\n enter: \"rmd-cross-fade\",\n enterActive: \"rmd-cross-fade--active\",\n} as const satisfies CSSTransitionClassNames;\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CrossFadeTransitionHookOptions
|
|
1
|
+
{"version":3,"sources":["../../src/transition/useCrossFadeTransition.ts"],"sourcesContent":["\"use client\";\n\nimport type {\n CSSTransitionClassNames,\n CSSTransitionHookReturnValue,\n PreconfiguredCSSTransitionInDefaultedOptions,\n TransitionTimeout,\n} from \"./types.js\";\nimport { useCSSTransition } from \"./useCSSTransition.js\";\n\n/**\n * The default cross fade transition timeout.\n *\n * @since 2.0.0\n * @since 6.0.0 Renamed from `CROSS_FADE_TIMEOUT` to\n * `DEFAULT_CROSS_FADE_TIMEOUT`\n */\nexport const DEFAULT_CROSS_FADE_TIMEOUT = {\n appear: 300,\n enter: 300,\n exit: 0,\n} as const satisfies TransitionTimeout;\n\n/**\n * The default cross fade transition classes to use.\n *\n * @since 2.0.0\n * @since 6.0.0 Renamed from `CROSS_FADE_CLASSNAMES` to\n * `DEFAULT_CROSS_FADE_CLASSNAMES`.\n */\nexport const DEFAULT_CROSS_FADE_CLASSNAMES = {\n appear: \"rmd-cross-fade\",\n appearActive: \"rmd-cross-fade--active\",\n enter: \"rmd-cross-fade\",\n enterActive: \"rmd-cross-fade--active\",\n} as const satisfies CSSTransitionClassNames;\n\n/**\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface CrossFadeTransitionHookOptions<\n E extends HTMLElement,\n> extends PreconfiguredCSSTransitionInDefaultedOptions<E> {\n /**\n * @see {@link TransitionTimeout}\n * @see {@link DEFAULT_CROSS_FADE_TIMEOUT}\n * @defaultValue `CROSS_FADE_TIMEOUT`\n */\n timeout?: TransitionTimeout;\n\n /**\n * @see {@link CSSTransitionClassNames}\n * @see {@link DEFAULT_CROSS_FADE_CLASSNAMES}\n * @defaultValue `CROSS_FADE_CLASSNAMES`\n */\n classNames?: CSSTransitionClassNames;\n\n /**\n * @see {@link PreconfiguredCSSTransitionInDefaultedOptions.transitionIn}\n * @defaultValue `true`\n */\n transitionIn?: boolean;\n}\n\n/**\n * This hook is used to create a \"cross fade\" transition -- a transition that\n * gradually increases the opacity and transforms the element vertically a short\n * distance. This is generally used for full page transitions when a route\n * changes.\n *\n * @see {@link https://react-md.dev/hooks/use-cross-fade-transition | useCrossFadeTransition Demos}\n * @see {@link https://react-md.dev/components/cross-fade | CrossFade Demos}\n * @typeParam E - An HTMLElement type used for the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport function useCrossFadeTransition<E extends HTMLElement>(\n options: CrossFadeTransitionHookOptions<E> = {}\n): CSSTransitionHookReturnValue<E> {\n const {\n appear = false,\n transitionIn = true,\n timeout = DEFAULT_CROSS_FADE_TIMEOUT,\n classNames = DEFAULT_CROSS_FADE_CLASSNAMES,\n ...cssOptions\n } = options;\n\n return useCSSTransition({\n ...cssOptions,\n appear,\n timeout,\n classNames,\n transitionIn,\n });\n}\n"],"names":["useCSSTransition","DEFAULT_CROSS_FADE_TIMEOUT","appear","enter","exit","DEFAULT_CROSS_FADE_CLASSNAMES","appearActive","enterActive","useCrossFadeTransition","options","transitionIn","timeout","classNames","cssOptions"],"mappings":"AAAA;AAQA,SAASA,gBAAgB,QAAQ,wBAAwB;AAEzD;;;;;;CAMC,GACD,OAAO,MAAMC,6BAA6B;IACxCC,QAAQ;IACRC,OAAO;IACPC,MAAM;AACR,EAAuC;AAEvC;;;;;;CAMC,GACD,OAAO,MAAMC,gCAAgC;IAC3CH,QAAQ;IACRI,cAAc;IACdH,OAAO;IACPI,aAAa;AACf,EAA6C;AA+B7C;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,uBACdC,UAA6C,CAAC,CAAC;IAE/C,MAAM,EACJP,SAAS,KAAK,EACdQ,eAAe,IAAI,EACnBC,UAAUV,0BAA0B,EACpCW,aAAaP,6BAA6B,EAC1C,GAAGQ,YACJ,GAAGJ;IAEJ,OAAOT,iBAAiB;QACtB,GAAGa,UAAU;QACbX;QACAS;QACAC;QACAF;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transition/useMaxWidthTransition.ts"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport type { ReactNode } from \"react\";\nimport { Children, cloneElement, isValidElement } from \"react\";\n\nimport { maxWidthTransition } from \"./maxWidthTransition.js\";\n\ndeclare module \"react\" {\n interface CSSProperites {\n \"--rmd-max-width\"?: string | number;\n \"--rmd-max-width-gap\"?: string | number;\n }\n}\n\n/**\n * @since 6.3.1\n */\nexport interface BaseMaxWidthTransitionOptions {\n className?: string;\n}\n\n/**\n * @since 6.0.0\n * @since 6.3.1 Extends BaseMaxWidthTransitionOptions\n */\nexport interface MaxWidthTransitionOptions
|
|
1
|
+
{"version":3,"sources":["../../src/transition/useMaxWidthTransition.ts"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport type { ReactNode } from \"react\";\nimport { Children, cloneElement, isValidElement } from \"react\";\n\nimport { maxWidthTransition } from \"./maxWidthTransition.js\";\n\ndeclare module \"react\" {\n interface CSSProperites {\n \"--rmd-max-width\"?: string | number;\n \"--rmd-max-width-gap\"?: string | number;\n }\n}\n\n/**\n * @since 6.3.1\n */\nexport interface BaseMaxWidthTransitionOptions {\n className?: string;\n}\n\n/**\n * @since 6.0.0\n * @since 6.3.1 Extends BaseMaxWidthTransitionOptions\n */\nexport interface MaxWidthTransitionOptions extends BaseMaxWidthTransitionOptions {\n element: ReactNode;\n transitionIn: boolean;\n\n disabled?: boolean;\n disableTransition?: boolean;\n}\n\n/**\n * The `useMaxWidthTransition` hook is used to animate the `max-width` using\n * the {@link maxWidthTransition} utility classes.\n *\n * NOTE: This hook clones the className into the child element using the\n * `cloneElement` API. The child **must** accept and pass the `className` forward\n * to work correctly.\n *\n * @see {@link maxWidthTransition}\n *\n * @since 6.0.0\n */\nexport function useMaxWidthTransition(\n options: MaxWidthTransitionOptions\n): ReactNode {\n const { element, disabled, disableTransition, transitionIn, className } =\n options;\n\n if (disabled || !isValidElement<{ className?: string }>(element)) {\n return element;\n }\n\n const child = Children.only(element);\n return cloneElement(element, {\n className: maxWidthTransition({\n className: cnb(child.props.className, className),\n disabled: disableTransition,\n transitionIn,\n }),\n });\n}\n"],"names":["cnb","Children","cloneElement","isValidElement","maxWidthTransition","useMaxWidthTransition","options","element","disabled","disableTransition","transitionIn","className","child","only","props"],"mappings":"AAAA;AAEA,SAASA,GAAG,QAAQ,YAAY;AAEhC,SAASC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,QAAQ,QAAQ;AAE/D,SAASC,kBAAkB,QAAQ,0BAA0B;AA4B7D;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,sBACdC,OAAkC;IAElC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,iBAAiB,EAAEC,YAAY,EAAEC,SAAS,EAAE,GACrEL;IAEF,IAAIE,YAAY,CAACL,eAAuCI,UAAU;QAChE,OAAOA;IACT;IAEA,MAAMK,QAAQX,SAASY,IAAI,CAACN;IAC5B,OAAOL,aAAaK,SAAS;QAC3BI,WAAWP,mBAAmB;YAC5BO,WAAWX,IAAIY,MAAME,KAAK,CAACH,SAAS,EAAEA;YACtCH,UAAUC;YACVC;QACF;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transition/useScaleTransition.ts"],"sourcesContent":["\"use client\";\n\nimport type {\n CSSTransitionClassNames,\n CSSTransitionHookReturnValue,\n PreconfiguredCSSTransitionOptions,\n TransitionTimeout,\n} from \"./types.js\";\nimport { useCSSTransition } from \"./useCSSTransition.js\";\n\n/**\n * The default {@link TransitionTimeout} to use for horizontal and vertical\n * scale transitions.\n *\n * @since 2.0.0\n * @since 6.0.0 Renamed from `SCALE_TIMEOUT` to `DEFAULT_SCALE_TIMEOUT`.\n */\nexport const DEFAULT_SCALE_TIMEOUT = {\n enter: 200,\n exit: 150,\n} as const satisfies TransitionTimeout;\n\n/**\n * The default {@link CSSTransitionClassNames} for a horizontal scale\n * transition.\n *\n * @since 2.0.0\n * @since 6.0.0 The class names were updated to be prefixed with\n * `rmd-scale-transition` and renamed from `SCALE_CLASSNAMES` to\n * `DEFAULT_SCALE_CLASSNAMES`.\n */\nexport const DEFAULT_SCALE_CLASSNAMES = {\n appear: \"rmd-scale-transition--enter\",\n appearActive: \"rmd-scale-transition--enter-active\",\n enter: \"rmd-scale-transition--enter\",\n enterActive: \"rmd-scale-transition--enter-active\",\n enterDone: \"\",\n exit: \"rmd-scale-transition--exit\",\n exitActive: \"rmd-scale-transition--exit-active\",\n} as const satisfies CSSTransitionClassNames;\n\n/**\n * The default {@link CSSTransitionClassNames} for a vertical scale transition.\n *\n * @since 2.0.0\n * @since 6.0.0 The class names were updated to be prefixed with\n * `rmd-scale-y-transition` and merged with the {@link DEFAULT_SCALE_CLASSNAMES}.\n * It was also renamed from `SCALE_Y_CLASSNAMES` to\n * `DEFAULT_SCALE_Y_CLASSNAMES`.\n */\nexport const DEFAULT_SCALE_Y_CLASSNAMES = {\n appear: \"rmd-scale-transition--enter rmd-scale-transition--y-enter\",\n appearActive:\n \"rmd-scale-transition--enter-active rmd-scale-transition--y-enter-active\",\n enter: \"rmd-scale-transition--enter rmd-scale-transition--y-enter\",\n enterActive:\n \"rmd-scale-transition--enter-active rmd-scale-transition--y-enter-active\",\n enterDone: \"\",\n exit: \"rmd-scale-transition--exit rmd-scale-transition--y-exit\",\n exitActive:\n \"rmd-scale-transition--exit-active rmd-scale-transition--y-exit-active\",\n} as const satisfies CSSTransitionClassNames;\n\n/**\n * @typeParam E - The HTMLElement type used or the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface ScaleTransitionHookOptions
|
|
1
|
+
{"version":3,"sources":["../../src/transition/useScaleTransition.ts"],"sourcesContent":["\"use client\";\n\nimport type {\n CSSTransitionClassNames,\n CSSTransitionHookReturnValue,\n PreconfiguredCSSTransitionOptions,\n TransitionTimeout,\n} from \"./types.js\";\nimport { useCSSTransition } from \"./useCSSTransition.js\";\n\n/**\n * The default {@link TransitionTimeout} to use for horizontal and vertical\n * scale transitions.\n *\n * @since 2.0.0\n * @since 6.0.0 Renamed from `SCALE_TIMEOUT` to `DEFAULT_SCALE_TIMEOUT`.\n */\nexport const DEFAULT_SCALE_TIMEOUT = {\n enter: 200,\n exit: 150,\n} as const satisfies TransitionTimeout;\n\n/**\n * The default {@link CSSTransitionClassNames} for a horizontal scale\n * transition.\n *\n * @since 2.0.0\n * @since 6.0.0 The class names were updated to be prefixed with\n * `rmd-scale-transition` and renamed from `SCALE_CLASSNAMES` to\n * `DEFAULT_SCALE_CLASSNAMES`.\n */\nexport const DEFAULT_SCALE_CLASSNAMES = {\n appear: \"rmd-scale-transition--enter\",\n appearActive: \"rmd-scale-transition--enter-active\",\n enter: \"rmd-scale-transition--enter\",\n enterActive: \"rmd-scale-transition--enter-active\",\n enterDone: \"\",\n exit: \"rmd-scale-transition--exit\",\n exitActive: \"rmd-scale-transition--exit-active\",\n} as const satisfies CSSTransitionClassNames;\n\n/**\n * The default {@link CSSTransitionClassNames} for a vertical scale transition.\n *\n * @since 2.0.0\n * @since 6.0.0 The class names were updated to be prefixed with\n * `rmd-scale-y-transition` and merged with the {@link DEFAULT_SCALE_CLASSNAMES}.\n * It was also renamed from `SCALE_Y_CLASSNAMES` to\n * `DEFAULT_SCALE_Y_CLASSNAMES`.\n */\nexport const DEFAULT_SCALE_Y_CLASSNAMES = {\n appear: \"rmd-scale-transition--enter rmd-scale-transition--y-enter\",\n appearActive:\n \"rmd-scale-transition--enter-active rmd-scale-transition--y-enter-active\",\n enter: \"rmd-scale-transition--enter rmd-scale-transition--y-enter\",\n enterActive:\n \"rmd-scale-transition--enter-active rmd-scale-transition--y-enter-active\",\n enterDone: \"\",\n exit: \"rmd-scale-transition--exit rmd-scale-transition--y-exit\",\n exitActive:\n \"rmd-scale-transition--exit-active rmd-scale-transition--y-exit-active\",\n} as const satisfies CSSTransitionClassNames;\n\n/**\n * @typeParam E - The HTMLElement type used or the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport interface ScaleTransitionHookOptions<\n E extends HTMLElement,\n> extends PreconfiguredCSSTransitionOptions<E> {\n /**\n * Boolean if the scale transition should be vertical instead of horizontal.\n * This really only changes the default value for the {@link classNames}.\n *\n * @defaultValue `false`\n */\n vertical?: boolean;\n\n /**\n * @see {@link PreconfiguredCSSTransitionOptions.temporary}\n * @defaultValue `true`\n */\n temporary?: boolean;\n\n /**\n * @see {@link vertical}\n * @see {@link DEFAULT_SCALE_CLASSNAMES}\n * @see {@link DEFAULT_SCALE_Y_CLASSNAMES}\n * @defaultValue `vertical ? SCALE_Y_CLASSNAMES : SCALE_CLASSNAMES`\n */\n classNames?: CSSTransitionClassNames;\n}\n\n/**\n * Implements a scale transition that should generally be used for temporary\n * elements that are positioned via `position: absolute` or `position: fixed`.\n *\n * @example Dropdown Menu Example\n * ```tsx\n * import { Button } from \"@react-md/core/button/Button\";\n * import { useFixedPositioning } from \"@react-md/core/positioning/useFixedPositioning\";\n * import { useScaleTransition } from \"@react-md/core/transition/useScaleTransition\";\n * import { type ReactElement, useRef, useState } from \"react\";\n *\n * function Example(): ReactElement {\n * const buttonRef = useRef<HTMLButtonElement>(null);\n * const [transitionIn, setTransitionIn] = useState(false);\n * const { style, transitionOptions } = useFixedPositioning({\n * fixedTo: buttonRef,\n * });\n * const { elementProps, rendered } = useScaleTransition({\n * ...transitionOptions,\n * transitionIn,\n * vertical: true,\n * });\n *\n * return (\n * <>\n * <Button ref={buttonRef} onClick={() => setTransitionIn(!transitionIn)}>\n * Toggle\n * </Button>\n * {rendered && (\n * <div {...elementProps} style={style}>\n * Some content within a menu\n * </div>\n * )}\n * </>\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/hooks/use-scale-transition | useScaleTransition Demos}\n * @see {@link https://react-md.dev/components/scale | Scale Demos}\n * @typeParam E - The HTMLElement type used or the ref required for the\n * transition.\n * @since 4.0.0\n */\nexport function useScaleTransition<E extends HTMLElement>(\n options: ScaleTransitionHookOptions<E>\n): CSSTransitionHookReturnValue<E> {\n const {\n timeout = DEFAULT_SCALE_TIMEOUT,\n vertical = false,\n temporary = true,\n exitedHidden = true,\n classNames = vertical\n ? DEFAULT_SCALE_Y_CLASSNAMES\n : DEFAULT_SCALE_CLASSNAMES,\n ...transitionOptions\n } = options;\n\n return useCSSTransition({\n ...transitionOptions,\n timeout,\n temporary,\n exitedHidden,\n classNames,\n });\n}\n"],"names":["useCSSTransition","DEFAULT_SCALE_TIMEOUT","enter","exit","DEFAULT_SCALE_CLASSNAMES","appear","appearActive","enterActive","enterDone","exitActive","DEFAULT_SCALE_Y_CLASSNAMES","useScaleTransition","options","timeout","vertical","temporary","exitedHidden","classNames","transitionOptions"],"mappings":"AAAA;AAQA,SAASA,gBAAgB,QAAQ,wBAAwB;AAEzD;;;;;;CAMC,GACD,OAAO,MAAMC,wBAAwB;IACnCC,OAAO;IACPC,MAAM;AACR,EAAuC;AAEvC;;;;;;;;CAQC,GACD,OAAO,MAAMC,2BAA2B;IACtCC,QAAQ;IACRC,cAAc;IACdJ,OAAO;IACPK,aAAa;IACbC,WAAW;IACXL,MAAM;IACNM,YAAY;AACd,EAA6C;AAE7C;;;;;;;;CAQC,GACD,OAAO,MAAMC,6BAA6B;IACxCL,QAAQ;IACRC,cACE;IACFJ,OAAO;IACPK,aACE;IACFC,WAAW;IACXL,MAAM;IACNM,YACE;AACJ,EAA6C;AAiC7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CC,GACD,OAAO,SAASE,mBACdC,OAAsC;IAEtC,MAAM,EACJC,UAAUZ,qBAAqB,EAC/Ba,WAAW,KAAK,EAChBC,YAAY,IAAI,EAChBC,eAAe,IAAI,EACnBC,aAAaH,WACTJ,6BACAN,wBAAwB,EAC5B,GAAGc,mBACJ,GAAGN;IAEJ,OAAOZ,iBAAiB;QACtB,GAAGkB,iBAAiB;QACpBL;QACAE;QACAC;QACAC;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transition/useSkeletonPlaceholder.ts"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport { type CSSProperties, useEffect, useState } from \"react\";\n\nimport { useSsr } from \"../SsrProvider.js\";\nimport {\n type SkeletonPlaceholderRandomOptions,\n randomSkeletonPlaceholder,\n skeletonPlaceholder,\n} from \"./skeletonPlaceholderUtils.js\";\n\n/** @since 6.0.0 */\nexport interface SkeletonPlaceholderOptions\n extends SkeletonPlaceholderRandomOptions {\n style?: CSSProperties;\n className?: string;\n\n /**\n * Set this to a custom `animation-delay` value (should be in milliseconds).\n *\n * @example\n * ```ts\n * delay=\"200ms\"\n * ```\n */\n delay?: string;\n\n /**\n * Set this value to a number or length unit string to set the height with\n * inline styles.\n *\n * If this is `undefined`, it will use the skeleton placeholder CSS variable\n * value instead which defaults to `1.125em`\n *\n * @defaultValue `undefined`\n */\n height?: string | number;\n\n /**\n * A custom width to apply to the skeleton placeholder.\n *\n * Set this value to an empty string if you want to control the width through\n * SCSS.\n *\n * @example No Inline Width CSS\n * ```scss\n * @use \"@react-md/core\";\n *\n * .customStyles {\n * // You could use these mixins on a parent element instead which would\n * // set the height and width to all skeleton placeholders that appear as a\n * // child instead\n * // @include core.transition-set-var(skeleton-placeholder-height, 1.5rem);\n * // @include core.transition-set-var(skeleton-placeholder-width, 40%);\n *\n * height: 1,5rem;\n * width: 40%;\n * }\n * ```\n *\n * @example No Inline Width\n * ```ts\n * import type { ReactElement } from \"@react\";\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * import styles from \"./MyComponent.module.scss\";\n *\n * export function Example(): ReactElement {\n * const skeletonProps = useSkeletonPlaceholder({\n * width: null,\n * className: styles.customStyles,\n * });\n *\n * return <div {...skeletonProps} />;\n * }\n * ```\n *\n *\n * Set this value to a number or length unit string to set the width with\n * inline styles.\n *\n * @example Custom Inline Width\n * ```ts\n * import type { ReactElement } from \"@react\";\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * export function Example(): ReactElement {\n * const skeletonProps = useSkeletonPlaceholder({\n * // any of these are valid\n * // width: 40,\n * // width: \"1rem\",\n * // width: \"1vh\",\n * // width: \"40%\",\n * width: \"1rem\",\n * });\n *\n * return <div {...skeletonProps} />;\n * }\n * ```\n *\n * If this value is `undefined`, a random percentage will be generated instead\n * using the {@link minPercentage} and {@link maxPercentage} options.\n *\n * Set this value to `null` if the size should be derived from the provided\n * `className` instead.\n *\n * @defaultValue `randomInt({ min: minPercentage, max: maxPercentage })%`\n */\n width?: number | string | null;\n\n /**\n * Settings this to `true` will prevent any of the skeleton placeholder styles\n * to be applied. This is really only useful if you can prerender parts of\n * your layout while waiting for the data to load.\n *\n * @example Pre-rendered Layout\n * ```tsx\n * import type { ReactElement } from \"@react\";\n * import { SkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * interface Data {\n * id: string;\n * name: string;\n * createdBy: string\n * createdOn: string;\n * modifiedBy: string;\n * modifiedOn: string;\n * }\n *\n * function ShowData({\n * id,\n * name,\n * createdBy,\n * createdOn,\n * modifiedBy,\n * modifiedOn,\n * }: Partial<Data>:: ReactElement {\n * const loading =\n * !name &&\n * !createdBy &&\n * !createdOn &&\n * !modifiedBy &&\n * !modifiedOn;\n *\n * return (\n * <Box grid gridClassName=\"custom-class-name\">\n * <SkeletonPlaceholder disabled={!loading}>\n * {id}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {name}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {createdOn}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {createdBy}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {modifiedOn}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {modifiedBy}\n * </SkeletonPlaceholder>\n * </Box>\n * );\n * }\n *\n * export function Example(): ReactElement {\n * const { data } = useLoadSomeDataQuery();\n *\n * const items = useMemo(() => {\n * // if the data has been fetched, just return the data\n * if (data) {\n * return data;\n * }\n *\n * // if the data does not exist, set up a skeleton of your layout by\n * // rendering a random number of items.\n * //\n * // NOTE: This is memoized so you don't create a random length each\n * // render\n * const length = randomInt({ min: 3, max: 10 })\n * return Array.from({ length }, (_, i) => ({ id: `placeholder-${i}` }));\n * }, [data])\n *\n * return (\n * <List>\n * {items.map((item) => <ShowData {...item} />)}\n * </List>\n * );\n * }\n * ```\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface SkeletonPlaceholderStylingProps {\n style?: CSSProperties;\n className: string;\n}\n\n/**\n * @example Simple Example\n * ```tsx\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n * import { type ReactElement } from \"react\";\n *\n * export default function UsingTheHookExample(): ReactElement {\n * const { style, className } = useSkeletonPlaceholder();\n * return <div style={style} className={className} />;\n * }\n * ```\n *\n * @see {@link https://react-md.dev/hooks/use-skeleton-placeholder-transition | useSkeletonPlaceholder Demos}\n * @see {@link https://react-md.dev/components/skeleton-placeholder | SkeletonPlaceholder Demos}\n * @since 6.0.0\n */\nexport function useSkeletonPlaceholder(\n options: SkeletonPlaceholderOptions = {}\n): SkeletonPlaceholderStylingProps {\n const {\n style: propStyle,\n className,\n height,\n width: propWidth,\n disabled = false,\n delay: propDelay,\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n } = options;\n const ssr = useSsr();\n\n const isDefinedWidth = typeof propWidth !== \"undefined\";\n const isDefinedDelay = typeof propDelay !== \"undefined\";\n const [randomStyles, setRandomStyles] = useState<CSSProperties>(() => {\n if (typeof window === \"undefined\" || ssr || disabled) {\n return {};\n }\n\n return randomSkeletonPlaceholder({\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n });\n });\n\n useEffect(() => {\n if (!ssr || disabled || (isDefinedDelay && isDefinedWidth)) {\n return;\n }\n\n setRandomStyles(\n randomSkeletonPlaceholder({\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n })\n );\n }, [\n disabled,\n isDefinedDelay,\n isDefinedWidth,\n maxDelay,\n maxPercentage,\n minDelay,\n minPercentage,\n ssr,\n ]);\n\n let width = propWidth;\n let animationDelay = propDelay;\n if (!disabled) {\n if (!isDefinedDelay) {\n ({ animationDelay } = randomStyles);\n }\n if (!isDefinedWidth) {\n ({ width } = randomStyles);\n }\n }\n\n let style: CSSProperties | undefined = propStyle;\n if (!!width || !!animationDelay || typeof height !== \"undefined\") {\n style = {\n ...style,\n height: height ?? style?.height,\n width: width ?? style?.width,\n // Note: not including MozAnimationDelay and WebkitAnimationDelay since\n // they weren't applied when they were set. Probably no longer required?\n animationDelay: animationDelay ?? style?.animationDelay,\n };\n }\n\n return {\n style,\n className: cnb(className, !disabled && skeletonPlaceholder()),\n };\n}\n"],"names":["cnb","useEffect","useState","useSsr","randomSkeletonPlaceholder","skeletonPlaceholder","useSkeletonPlaceholder","options","style","propStyle","className","height","width","propWidth","disabled","delay","propDelay","minDelay","maxDelay","minPercentage","maxPercentage","ssr","isDefinedWidth","isDefinedDelay","randomStyles","setRandomStyles","window","animationDelay"],"mappings":"AAAA;AAEA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAA6BC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAEhE,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAEEC,yBAAyB,EACzBC,mBAAmB,QACd,gCAAgC;AAsMvC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASC,uBACdC,UAAsC,CAAC,CAAC;IAExC,MAAM,EACJC,OAAOC,SAAS,EAChBC,SAAS,EACTC,MAAM,EACNC,OAAOC,SAAS,EAChBC,WAAW,KAAK,EAChBC,OAAOC,SAAS,EAChBC,QAAQ,EACRC,QAAQ,EACRC,aAAa,EACbC,aAAa,EACd,GAAGb;IACJ,MAAMc,MAAMlB;IAEZ,MAAMmB,iBAAiB,OAAOT,cAAc;IAC5C,MAAMU,iBAAiB,OAAOP,cAAc;IAC5C,MAAM,CAACQ,cAAcC,gBAAgB,GAAGvB,SAAwB;QAC9D,IAAI,OAAOwB,WAAW,eAAeL,OAAOP,UAAU;YACpD,OAAO,CAAC;QACV;QAEA,OAAOV,0BAA0B;YAC/Ba;YACAC;YACAC;YACAC;QACF;IACF;IAEAnB,UAAU;QACR,IAAI,CAACoB,OAAOP,YAAaS,kBAAkBD,gBAAiB;YAC1D;QACF;QAEAG,gBACErB,0BAA0B;YACxBa;YACAC;YACAC;YACAC;QACF;IAEJ,GAAG;QACDN;QACAS;QACAD;QACAJ;QACAE;QACAH;QACAE;QACAE;KACD;IAED,IAAIT,QAAQC;IACZ,IAAIc,iBAAiBX;IACrB,IAAI,CAACF,UAAU;QACb,IAAI,CAACS,gBAAgB;YAClB,CAAA,EAAEI,cAAc,EAAE,GAAGH,YAAW;QACnC;QACA,IAAI,CAACF,gBAAgB;YAClB,CAAA,EAAEV,KAAK,EAAE,GAAGY,YAAW;QAC1B;IACF;IAEA,IAAIhB,QAAmCC;IACvC,IAAI,CAAC,CAACG,SAAS,CAAC,CAACe,kBAAkB,OAAOhB,WAAW,aAAa;QAChEH,QAAQ;YACN,GAAGA,KAAK;YACRG,QAAQA,UAAUH,OAAOG;YACzBC,OAAOA,SAASJ,OAAOI;YACvB,uEAAuE;YACvE,wEAAwE;YACxEe,gBAAgBA,kBAAkBnB,OAAOmB;QAC3C;IACF;IAEA,OAAO;QACLnB;QACAE,WAAWV,IAAIU,WAAW,CAACI,YAAYT;IACzC;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/transition/useSkeletonPlaceholder.ts"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport { type CSSProperties, useEffect, useState } from \"react\";\n\nimport { useSsr } from \"../SsrProvider.js\";\nimport {\n type SkeletonPlaceholderRandomOptions,\n randomSkeletonPlaceholder,\n skeletonPlaceholder,\n} from \"./skeletonPlaceholderUtils.js\";\n\n/** @since 6.0.0 */\nexport interface SkeletonPlaceholderOptions extends SkeletonPlaceholderRandomOptions {\n style?: CSSProperties;\n className?: string;\n\n /**\n * Set this to a custom `animation-delay` value (should be in milliseconds).\n *\n * @example\n * ```ts\n * delay=\"200ms\"\n * ```\n */\n delay?: string;\n\n /**\n * Set this value to a number or length unit string to set the height with\n * inline styles.\n *\n * If this is `undefined`, it will use the skeleton placeholder CSS variable\n * value instead which defaults to `1.125em`\n *\n * @defaultValue `undefined`\n */\n height?: string | number;\n\n /**\n * A custom width to apply to the skeleton placeholder.\n *\n * Set this value to an empty string if you want to control the width through\n * SCSS.\n *\n * @example No Inline Width CSS\n * ```scss\n * @use \"@react-md/core\";\n *\n * .customStyles {\n * // You could use these mixins on a parent element instead which would\n * // set the height and width to all skeleton placeholders that appear as a\n * // child instead\n * // @include core.transition-set-var(skeleton-placeholder-height, 1.5rem);\n * // @include core.transition-set-var(skeleton-placeholder-width, 40%);\n *\n * height: 1,5rem;\n * width: 40%;\n * }\n * ```\n *\n * @example No Inline Width\n * ```ts\n * import type { ReactElement } from \"@react\";\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * import styles from \"./MyComponent.module.scss\";\n *\n * export function Example(): ReactElement {\n * const skeletonProps = useSkeletonPlaceholder({\n * width: null,\n * className: styles.customStyles,\n * });\n *\n * return <div {...skeletonProps} />;\n * }\n * ```\n *\n *\n * Set this value to a number or length unit string to set the width with\n * inline styles.\n *\n * @example Custom Inline Width\n * ```ts\n * import type { ReactElement } from \"@react\";\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * export function Example(): ReactElement {\n * const skeletonProps = useSkeletonPlaceholder({\n * // any of these are valid\n * // width: 40,\n * // width: \"1rem\",\n * // width: \"1vh\",\n * // width: \"40%\",\n * width: \"1rem\",\n * });\n *\n * return <div {...skeletonProps} />;\n * }\n * ```\n *\n * If this value is `undefined`, a random percentage will be generated instead\n * using the {@link minPercentage} and {@link maxPercentage} options.\n *\n * Set this value to `null` if the size should be derived from the provided\n * `className` instead.\n *\n * @defaultValue `randomInt({ min: minPercentage, max: maxPercentage })%`\n */\n width?: number | string | null;\n\n /**\n * Settings this to `true` will prevent any of the skeleton placeholder styles\n * to be applied. This is really only useful if you can prerender parts of\n * your layout while waiting for the data to load.\n *\n * @example Pre-rendered Layout\n * ```tsx\n * import type { ReactElement } from \"@react\";\n * import { SkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * interface Data {\n * id: string;\n * name: string;\n * createdBy: string\n * createdOn: string;\n * modifiedBy: string;\n * modifiedOn: string;\n * }\n *\n * function ShowData({\n * id,\n * name,\n * createdBy,\n * createdOn,\n * modifiedBy,\n * modifiedOn,\n * }: Partial<Data>:: ReactElement {\n * const loading =\n * !name &&\n * !createdBy &&\n * !createdOn &&\n * !modifiedBy &&\n * !modifiedOn;\n *\n * return (\n * <Box grid gridClassName=\"custom-class-name\">\n * <SkeletonPlaceholder disabled={!loading}>\n * {id}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {name}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {createdOn}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {createdBy}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {modifiedOn}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {modifiedBy}\n * </SkeletonPlaceholder>\n * </Box>\n * );\n * }\n *\n * export function Example(): ReactElement {\n * const { data } = useLoadSomeDataQuery();\n *\n * const items = useMemo(() => {\n * // if the data has been fetched, just return the data\n * if (data) {\n * return data;\n * }\n *\n * // if the data does not exist, set up a skeleton of your layout by\n * // rendering a random number of items.\n * //\n * // NOTE: This is memoized so you don't create a random length each\n * // render\n * const length = randomInt({ min: 3, max: 10 })\n * return Array.from({ length }, (_, i) => ({ id: `placeholder-${i}` }));\n * }, [data])\n *\n * return (\n * <List>\n * {items.map((item) => <ShowData {...item} />)}\n * </List>\n * );\n * }\n * ```\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface SkeletonPlaceholderStylingProps {\n style?: CSSProperties;\n className: string;\n}\n\n/**\n * @example Simple Example\n * ```tsx\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n * import { type ReactElement } from \"react\";\n *\n * export default function UsingTheHookExample(): ReactElement {\n * const { style, className } = useSkeletonPlaceholder();\n * return <div style={style} className={className} />;\n * }\n * ```\n *\n * @see {@link https://react-md.dev/hooks/use-skeleton-placeholder-transition | useSkeletonPlaceholder Demos}\n * @see {@link https://react-md.dev/components/skeleton-placeholder | SkeletonPlaceholder Demos}\n * @since 6.0.0\n */\nexport function useSkeletonPlaceholder(\n options: SkeletonPlaceholderOptions = {}\n): SkeletonPlaceholderStylingProps {\n const {\n style: propStyle,\n className,\n height,\n width: propWidth,\n disabled = false,\n delay: propDelay,\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n } = options;\n const ssr = useSsr();\n\n const isDefinedWidth = typeof propWidth !== \"undefined\";\n const isDefinedDelay = typeof propDelay !== \"undefined\";\n const [randomStyles, setRandomStyles] = useState<CSSProperties>(() => {\n if (typeof window === \"undefined\" || ssr || disabled) {\n return {};\n }\n\n return randomSkeletonPlaceholder({\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n });\n });\n\n useEffect(() => {\n if (!ssr || disabled || (isDefinedDelay && isDefinedWidth)) {\n return;\n }\n\n setRandomStyles(\n randomSkeletonPlaceholder({\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n })\n );\n }, [\n disabled,\n isDefinedDelay,\n isDefinedWidth,\n maxDelay,\n maxPercentage,\n minDelay,\n minPercentage,\n ssr,\n ]);\n\n let width = propWidth;\n let animationDelay = propDelay;\n if (!disabled) {\n if (!isDefinedDelay) {\n ({ animationDelay } = randomStyles);\n }\n if (!isDefinedWidth) {\n ({ width } = randomStyles);\n }\n }\n\n let style: CSSProperties | undefined = propStyle;\n if (!!width || !!animationDelay || typeof height !== \"undefined\") {\n style = {\n ...style,\n height: height ?? style?.height,\n width: width ?? style?.width,\n // Note: not including MozAnimationDelay and WebkitAnimationDelay since\n // they weren't applied when they were set. Probably no longer required?\n animationDelay: animationDelay ?? style?.animationDelay,\n };\n }\n\n return {\n style,\n className: cnb(className, !disabled && skeletonPlaceholder()),\n };\n}\n"],"names":["cnb","useEffect","useState","useSsr","randomSkeletonPlaceholder","skeletonPlaceholder","useSkeletonPlaceholder","options","style","propStyle","className","height","width","propWidth","disabled","delay","propDelay","minDelay","maxDelay","minPercentage","maxPercentage","ssr","isDefinedWidth","isDefinedDelay","randomStyles","setRandomStyles","window","animationDelay"],"mappings":"AAAA;AAEA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAA6BC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAEhE,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAEEC,yBAAyB,EACzBC,mBAAmB,QACd,gCAAgC;AAqMvC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASC,uBACdC,UAAsC,CAAC,CAAC;IAExC,MAAM,EACJC,OAAOC,SAAS,EAChBC,SAAS,EACTC,MAAM,EACNC,OAAOC,SAAS,EAChBC,WAAW,KAAK,EAChBC,OAAOC,SAAS,EAChBC,QAAQ,EACRC,QAAQ,EACRC,aAAa,EACbC,aAAa,EACd,GAAGb;IACJ,MAAMc,MAAMlB;IAEZ,MAAMmB,iBAAiB,OAAOT,cAAc;IAC5C,MAAMU,iBAAiB,OAAOP,cAAc;IAC5C,MAAM,CAACQ,cAAcC,gBAAgB,GAAGvB,SAAwB;QAC9D,IAAI,OAAOwB,WAAW,eAAeL,OAAOP,UAAU;YACpD,OAAO,CAAC;QACV;QAEA,OAAOV,0BAA0B;YAC/Ba;YACAC;YACAC;YACAC;QACF;IACF;IAEAnB,UAAU;QACR,IAAI,CAACoB,OAAOP,YAAaS,kBAAkBD,gBAAiB;YAC1D;QACF;QAEAG,gBACErB,0BAA0B;YACxBa;YACAC;YACAC;YACAC;QACF;IAEJ,GAAG;QACDN;QACAS;QACAD;QACAJ;QACAE;QACAH;QACAE;QACAE;KACD;IAED,IAAIT,QAAQC;IACZ,IAAIc,iBAAiBX;IACrB,IAAI,CAACF,UAAU;QACb,IAAI,CAACS,gBAAgB;YAClB,CAAA,EAAEI,cAAc,EAAE,GAAGH,YAAW;QACnC;QACA,IAAI,CAACF,gBAAgB;YAClB,CAAA,EAAEV,KAAK,EAAE,GAAGY,YAAW;QAC1B;IACF;IAEA,IAAIhB,QAAmCC;IACvC,IAAI,CAAC,CAACG,SAAS,CAAC,CAACe,kBAAkB,OAAOhB,WAAW,aAAa;QAChEH,QAAQ;YACN,GAAGA,KAAK;YACRG,QAAQA,UAAUH,OAAOG;YACzBC,OAAOA,SAASJ,OAAOI;YACvB,uEAAuE;YACvE,wEAAwE;YACxEe,gBAAgBA,kBAAkBnB,OAAOmB;QAC3C;IACF;IAEA,OAAO;QACLnB;QACAE,WAAWV,IAAIU,WAAW,CAACI,YAAYT;IACzC;AACF"}
|
package/dist/tree/Tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/Tree.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from \"react\";\n\nimport { type CustomLinkComponent } from \"../link/Link.js\";\nimport { List } from \"../list/List.js\";\nimport { KeyboardMovementProvider } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type LabelRequiredForA11y } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { RenderRecursively } from \"../utils/RenderRecursively.js\";\nimport { identity } from \"../utils/identity.js\";\nimport { DefaultTreeItemRenderer } from \"./DefaultTreeItemRenderer.js\";\nimport { type TreeExpansionMode, TreeProvider } from \"./TreeProvider.js\";\nimport { type TreeClassNameOptions, tree } from \"./styles.js\";\nimport {\n type TreeData,\n type TreeItemNode,\n type TreeItemRendererProps,\n type TreeItemSorter,\n} from \"./types.js\";\nimport { type TreeExpansion } from \"./useTreeExpansion.js\";\nimport { useTreeItems } from \"./useTreeItems.js\";\nimport { useTreeMovement } from \"./useTreeMovement.js\";\nimport { type TreeSelection } from \"./useTreeSelection.js\";\n\n/**\n * @since 6.0.0\n */\nexport type TreeHTMLAttributes = Omit<\n HTMLAttributes<HTMLUListElement>,\n \"role\" | \"tabIndex\" | \"children\"\n>;\n\n/**\n * @since 6.0.0 There was a major API change and the `id` is now `optional`.\n * In addition, the following props were removed:\n * - `itemRenderer`\n * - `labelKey`\n * - `valueKey`\n * - `getItemLabel`\n * - `getItemValue`\n * - `getItemProps`\n *\n * @since 6.3.1 Extends TreeClassNameOptions for CSSProperties module\n * augmentation.\n */\nexport interface TreeProps<T extends TreeItemNode>\n extends TreeHTMLAttributes,\n TreeClassNameOptions,\n TreeExpansion,\n TreeSelection {\n /** @see {@link TreeData} */\n data: TreeData<T>;\n\n /**\n * An optional ref to pass to the tree element.\n *\n * @since 6.0.0\n */\n treeRef?: Ref<HTMLUListElement>;\n\n /** @defaultValue `identity` */\n sort?: TreeItemSorter<T>;\n\n /**\n * Any nodes in the {@link data} that have a `parentId` set to this value will\n * appear at the root of the tree.\n *\n * @defaultValue `null`\n */\n rootId?: string | null;\n\n /**\n * @defaultValue `\"auto\"`\n * @see {@link TreeExpansionMode}\n */\n expansionMode?: TreeExpansionMode;\n\n /**\n * Set this to `true` to display the expander icon to the left instead of the\n * right. This will also update the styles slightly so you can still provide a\n * `leftAddon`.\n *\n * @defaultValue `false`\n */\n expanderLeft?: boolean;\n\n /**\n * @defaultValue `getIcon(\"expander\")`\n */\n expanderIcon?: ReactNode;\n\n /**\n * Set this to `true` to disable the collapse transition for all tree items.\n *\n * @defaultValue `false`\n */\n disableTransition?: boolean;\n\n /**\n * Set this to `true` if the collapsed tree items should be removed from the\n * DOM instead of hidden using `display: none`. This _might_ improve\n * performance for large trees.\n *\n * @defaultValue `false`\n */\n temporaryChildItems?: boolean;\n\n /**\n * @example Custom Tree Item Renderer\n * ```tsx\n * import { useTreeContext } from \"@react-md/core/movement/TreeProvider\"\n * import { useKeyboardMovementContext } from \"@react-md/core/movement/useKeyboardMovementProvider\"\n * import { TreeItem } from \"@react-md/core/tree/TreeItem\";\n * import { type TreeItemRendererProps } from \"@react-md/core/tree/types\";\n * import FolderIcon from \"@react-md/material-icons/FolderIcon\";\n * import FolderOpenIcon from \"@react-md/material-icons/FolderOpenIcon\";\n * import { type ReactElement } from \"react\";\n *\n * export function CustomTreeItem(props: TreeItemRendererProps): ReactElement {\n * const { item, ...remaining } = props;\n * const id = useId();\n * const { itemId } = item;\n * const {\n * data,\n * expandedIds,\n * selectedIds,\n * toggleTreeItemExpansion,\n * toggleTreeItemSelection,\n * } = useTreeContext()\n * const { activeDescendantId } = useKeyboardMovementContext();\n *\n * const focused = id === activeDescendantId;\n * const expanded = expandedIds.has(itemId);\n * const selected = selectedIds.has(itemId);\n * const children = ...; // do whatever\n *\n * return (\n * <TreeItem\n * {...remaining}\n * id={id}\n * itemId={itemId}\n * leftAddon={expanded ? <FolderOpenIcon /> : <FolderIcon />}\n * >\n * {children}\n * </TreeItem>\n * );\n * }\n * ```\n *\n * @see {@link DefaultTreeItemRenderer}\n * @defaultValue `DefaultTreeItemRenderer`\n */\n renderer?: ComponentType<TreeItemRendererProps<T>>;\n\n /**\n * The link component to use for any tree item nodes that have a `to` or\n * `href`.\n *\n * @see {@link CustomLinkComponent}\n * @defaultValue `Link`\n */\n linkComponent?: CustomLinkComponent;\n}\n\n/**\n * **Client Component**\n *\n * @example Simple Tree\n * ```tsx\n * import { Tree } from \"@react-md/core/tree/Tree\";\n * import { type TreeData } from \"@react-md/core/tree/types\";\n * import { useTree } from \"@react-md/core/tree/useTree\";\n * import type { ReactElement } from \"react\";\n *\n * const data: TreeData = {\n * \"item-1\": {\n * itemId: \"item-1\",\n * parentId: null,\n * name: \"Root Level Item 1\",\n * },\n * \"item-2\": {\n * itemId: \"item-2\",\n * parentId: \"item-1\",\n * name: \"A child for the first item\",\n * },\n * \"item-3\": {\n * itemId: \"item-3\",\n * parentId: \"item-1\",\n * children: \"Another child for the first item\",\n * },\n * };\n *\n * function Example(): ReactElement {\n * const tree = useTree({\n * // can enable multiple selected items\n * // multiSelect: true,\n *\n * // can set default expanded and selected items\n * // defaultSelectedIds: [\"item-1\"],\n * // defaultExpandedIds: [\"item-1\"],\n * });\n *\n * return (\n * <Tree\n * {...tree}\n * aria-label=\"Tree\"\n * data={data}\n * />\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/tree | Tree Demos}\n * @see {@link TreeProps.renderer} for a custom tree item example.\n * @since 6.0.0 There was a major API change and the `id` is now `optional`.\n * In addition, the following props were removed:\n * - `itemRenderer`\n * - `labelKey`\n * - `valueKey`\n * - `getItemLabel`\n * - `getItemValue`\n * - `getItemProps`\n */\nexport function Tree<T extends TreeItemNode>(\n props: LabelRequiredForA11y<TreeProps<T>>\n): ReactElement {\n const {\n id,\n data,\n sort = identity,\n rootId = null,\n treeRef,\n className,\n expandedIds,\n selectedIds,\n toggleTreeItemSelection,\n selectMultipleTreeItems,\n toggleTreeItemExpansion,\n expandMultipleTreeItems,\n onClick,\n onFocus,\n onKeyDown,\n renderer: TreeItemRenderer = DefaultTreeItemRenderer,\n multiSelect = false,\n expansionMode = \"auto\",\n expanderIcon,\n expanderLeft = false,\n linkComponent = \"a\",\n disableTransition = false,\n temporaryChildItems = false,\n ...remaining\n } = props;\n const treeId = useEnsuredId(id, \"tree\");\n const { items, treeItemChildIds } = useTreeItems({\n data,\n sort,\n rootId,\n });\n\n const { metadataLookup, movementContext, movementProps } = useTreeMovement({\n ref: treeRef,\n onClick,\n onFocus,\n onKeyDown,\n data,\n expandedIds,\n selectedIds,\n treeItemChildIds,\n toggleTreeItemExpansion,\n expandMultipleTreeItems,\n });\n\n return (\n <TreeProvider\n data={data}\n rootId={rootId}\n multiSelect={multiSelect}\n linkComponent={linkComponent}\n selectedIds={selectedIds}\n expandedIds={expandedIds}\n expanderIcon={expanderIcon}\n expanderLeft={expanderLeft}\n expansionMode={expansionMode}\n metadataLookup={metadataLookup}\n disableTransition={disableTransition}\n temporaryChildItems={temporaryChildItems}\n toggleTreeItemSelection={toggleTreeItemSelection}\n toggleTreeItemExpansion={toggleTreeItemExpansion}\n selectMultipleTreeItems={selectMultipleTreeItems}\n expandMultipleTreeItems={expandMultipleTreeItems}\n >\n <KeyboardMovementProvider value={movementContext}>\n <List\n {...remaining}\n {...movementProps}\n id={treeId}\n role=\"tree\"\n tabIndex={0}\n className={tree({ className })}\n >\n <RenderRecursively\n items={items}\n render={TreeItemRenderer}\n getItemKey={(options) => options.item.itemId}\n />\n </List>\n </KeyboardMovementProvider>\n </TreeProvider>\n );\n}\n"],"names":["List","KeyboardMovementProvider","useEnsuredId","RenderRecursively","identity","DefaultTreeItemRenderer","TreeProvider","tree","useTreeItems","useTreeMovement","Tree","props","id","data","sort","rootId","treeRef","className","expandedIds","selectedIds","toggleTreeItemSelection","selectMultipleTreeItems","toggleTreeItemExpansion","expandMultipleTreeItems","onClick","onFocus","onKeyDown","renderer","TreeItemRenderer","multiSelect","expansionMode","expanderIcon","expanderLeft","linkComponent","disableTransition","temporaryChildItems","remaining","treeId","items","treeItemChildIds","metadataLookup","movementContext","movementProps","ref","value","role","tabIndex","render","getItemKey","options","item","itemId"],"mappings":"AAAA;;AAWA,SAASA,IAAI,QAAQ,kBAAkB;AACvC,SAASC,wBAAwB,QAAQ,6CAA6C;AAEtF,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAAiCC,YAAY,QAAQ,oBAAoB;AACzE,SAAoCC,IAAI,QAAQ,cAAc;AAQ9D,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,eAAe,QAAQ,uBAAuB;AA+IvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DC,GACD,OAAO,SAASC,KACdC,KAAyC;IAEzC,MAAM,EACJC,EAAE,EACFC,IAAI,EACJC,OAAOV,QAAQ,EACfW,SAAS,IAAI,EACbC,OAAO,EACPC,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACvBC,OAAO,EACPC,OAAO,EACPC,SAAS,EACTC,UAAUC,mBAAmBvB,uBAAuB,EACpDwB,cAAc,KAAK,EACnBC,gBAAgB,MAAM,EACtBC,YAAY,EACZC,eAAe,KAAK,EACpBC,gBAAgB,GAAG,EACnBC,oBAAoB,KAAK,EACzBC,sBAAsB,KAAK,EAC3B,GAAGC,WACJ,GAAGzB;IACJ,MAAM0B,SAASnC,aAAaU,IAAI;IAChC,MAAM,EAAE0B,KAAK,EAAEC,gBAAgB,EAAE,GAAG/B,aAAa;QAC/CK;QACAC;QACAC;IACF;IAEA,MAAM,EAAEyB,cAAc,EAAEC,eAAe,EAAEC,aAAa,EAAE,GAAGjC,gBAAgB;QACzEkC,KAAK3B;QACLQ;QACAC;QACAC;QACAb;QACAK;QACAC;QACAoB;QACAjB;QACAC;IACF;IAEA,qBACE,KAACjB;QACCO,MAAMA;QACNE,QAAQA;QACRc,aAAaA;QACbI,eAAeA;QACfd,aAAaA;QACbD,aAAaA;QACba,cAAcA;QACdC,cAAcA;QACdF,eAAeA;QACfU,gBAAgBA;QAChBN,mBAAmBA;QACnBC,qBAAqBA;QACrBf,yBAAyBA;QACzBE,yBAAyBA;QACzBD,yBAAyBA;QACzBE,yBAAyBA;kBAEzB,cAAA,KAACtB;YAAyB2C,OAAOH;sBAC/B,cAAA,KAACzC;gBACE,GAAGoC,SAAS;gBACZ,GAAGM,aAAa;gBACjB9B,IAAIyB;gBACJQ,MAAK;gBACLC,UAAU;gBACV7B,WAAWV,KAAK;oBAAEU;gBAAU;0BAE5B,cAAA,KAACd;oBACCmC,OAAOA;oBACPS,QAAQnB;oBACRoB,YAAY,CAACC,UAAYA,QAAQC,IAAI,CAACC,MAAM;;;;;AAMxD"}
|
|
1
|
+
{"version":3,"sources":["../../src/tree/Tree.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from \"react\";\n\nimport { type CustomLinkComponent } from \"../link/Link.js\";\nimport { List } from \"../list/List.js\";\nimport { KeyboardMovementProvider } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type LabelRequiredForA11y } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { RenderRecursively } from \"../utils/RenderRecursively.js\";\nimport { identity } from \"../utils/identity.js\";\nimport { DefaultTreeItemRenderer } from \"./DefaultTreeItemRenderer.js\";\nimport { type TreeExpansionMode, TreeProvider } from \"./TreeProvider.js\";\nimport { type TreeClassNameOptions, tree } from \"./styles.js\";\nimport {\n type TreeData,\n type TreeItemNode,\n type TreeItemRendererProps,\n type TreeItemSorter,\n} from \"./types.js\";\nimport { type TreeExpansion } from \"./useTreeExpansion.js\";\nimport { useTreeItems } from \"./useTreeItems.js\";\nimport { useTreeMovement } from \"./useTreeMovement.js\";\nimport { type TreeSelection } from \"./useTreeSelection.js\";\n\n/**\n * @since 6.0.0\n */\nexport type TreeHTMLAttributes = Omit<\n HTMLAttributes<HTMLUListElement>,\n \"role\" | \"tabIndex\" | \"children\"\n>;\n\n/**\n * @since 6.0.0 There was a major API change and the `id` is now `optional`.\n * In addition, the following props were removed:\n * - `itemRenderer`\n * - `labelKey`\n * - `valueKey`\n * - `getItemLabel`\n * - `getItemValue`\n * - `getItemProps`\n *\n * @since 6.3.1 Extends TreeClassNameOptions for CSSProperties module\n * augmentation.\n */\nexport interface TreeProps<T extends TreeItemNode>\n extends\n TreeHTMLAttributes,\n TreeClassNameOptions,\n TreeExpansion,\n TreeSelection {\n /** @see {@link TreeData} */\n data: TreeData<T>;\n\n /**\n * An optional ref to pass to the tree element.\n *\n * @since 6.0.0\n */\n treeRef?: Ref<HTMLUListElement>;\n\n /** @defaultValue `identity` */\n sort?: TreeItemSorter<T>;\n\n /**\n * Any nodes in the {@link data} that have a `parentId` set to this value will\n * appear at the root of the tree.\n *\n * @defaultValue `null`\n */\n rootId?: string | null;\n\n /**\n * @defaultValue `\"auto\"`\n * @see {@link TreeExpansionMode}\n */\n expansionMode?: TreeExpansionMode;\n\n /**\n * Set this to `true` to display the expander icon to the left instead of the\n * right. This will also update the styles slightly so you can still provide a\n * `leftAddon`.\n *\n * @defaultValue `false`\n */\n expanderLeft?: boolean;\n\n /**\n * @defaultValue `getIcon(\"expander\")`\n */\n expanderIcon?: ReactNode;\n\n /**\n * Set this to `true` to disable the collapse transition for all tree items.\n *\n * @defaultValue `false`\n */\n disableTransition?: boolean;\n\n /**\n * Set this to `true` if the collapsed tree items should be removed from the\n * DOM instead of hidden using `display: none`. This _might_ improve\n * performance for large trees.\n *\n * @defaultValue `false`\n */\n temporaryChildItems?: boolean;\n\n /**\n * @example Custom Tree Item Renderer\n * ```tsx\n * import { useTreeContext } from \"@react-md/core/movement/TreeProvider\"\n * import { useKeyboardMovementContext } from \"@react-md/core/movement/useKeyboardMovementProvider\"\n * import { TreeItem } from \"@react-md/core/tree/TreeItem\";\n * import { type TreeItemRendererProps } from \"@react-md/core/tree/types\";\n * import FolderIcon from \"@react-md/material-icons/FolderIcon\";\n * import FolderOpenIcon from \"@react-md/material-icons/FolderOpenIcon\";\n * import { type ReactElement } from \"react\";\n *\n * export function CustomTreeItem(props: TreeItemRendererProps): ReactElement {\n * const { item, ...remaining } = props;\n * const id = useId();\n * const { itemId } = item;\n * const {\n * data,\n * expandedIds,\n * selectedIds,\n * toggleTreeItemExpansion,\n * toggleTreeItemSelection,\n * } = useTreeContext()\n * const { activeDescendantId } = useKeyboardMovementContext();\n *\n * const focused = id === activeDescendantId;\n * const expanded = expandedIds.has(itemId);\n * const selected = selectedIds.has(itemId);\n * const children = ...; // do whatever\n *\n * return (\n * <TreeItem\n * {...remaining}\n * id={id}\n * itemId={itemId}\n * leftAddon={expanded ? <FolderOpenIcon /> : <FolderIcon />}\n * >\n * {children}\n * </TreeItem>\n * );\n * }\n * ```\n *\n * @see {@link DefaultTreeItemRenderer}\n * @defaultValue `DefaultTreeItemRenderer`\n */\n renderer?: ComponentType<TreeItemRendererProps<T>>;\n\n /**\n * The link component to use for any tree item nodes that have a `to` or\n * `href`.\n *\n * @see {@link CustomLinkComponent}\n * @defaultValue `Link`\n */\n linkComponent?: CustomLinkComponent;\n}\n\n/**\n * **Client Component**\n *\n * @example Simple Tree\n * ```tsx\n * import { Tree } from \"@react-md/core/tree/Tree\";\n * import { type TreeData } from \"@react-md/core/tree/types\";\n * import { useTree } from \"@react-md/core/tree/useTree\";\n * import type { ReactElement } from \"react\";\n *\n * const data: TreeData = {\n * \"item-1\": {\n * itemId: \"item-1\",\n * parentId: null,\n * name: \"Root Level Item 1\",\n * },\n * \"item-2\": {\n * itemId: \"item-2\",\n * parentId: \"item-1\",\n * name: \"A child for the first item\",\n * },\n * \"item-3\": {\n * itemId: \"item-3\",\n * parentId: \"item-1\",\n * children: \"Another child for the first item\",\n * },\n * };\n *\n * function Example(): ReactElement {\n * const tree = useTree({\n * // can enable multiple selected items\n * // multiSelect: true,\n *\n * // can set default expanded and selected items\n * // defaultSelectedIds: [\"item-1\"],\n * // defaultExpandedIds: [\"item-1\"],\n * });\n *\n * return (\n * <Tree\n * {...tree}\n * aria-label=\"Tree\"\n * data={data}\n * />\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/tree | Tree Demos}\n * @see {@link TreeProps.renderer} for a custom tree item example.\n * @since 6.0.0 There was a major API change and the `id` is now `optional`.\n * In addition, the following props were removed:\n * - `itemRenderer`\n * - `labelKey`\n * - `valueKey`\n * - `getItemLabel`\n * - `getItemValue`\n * - `getItemProps`\n */\nexport function Tree<T extends TreeItemNode>(\n props: LabelRequiredForA11y<TreeProps<T>>\n): ReactElement {\n const {\n id,\n data,\n sort = identity,\n rootId = null,\n treeRef,\n className,\n expandedIds,\n selectedIds,\n toggleTreeItemSelection,\n selectMultipleTreeItems,\n toggleTreeItemExpansion,\n expandMultipleTreeItems,\n onClick,\n onFocus,\n onKeyDown,\n renderer: TreeItemRenderer = DefaultTreeItemRenderer,\n multiSelect = false,\n expansionMode = \"auto\",\n expanderIcon,\n expanderLeft = false,\n linkComponent = \"a\",\n disableTransition = false,\n temporaryChildItems = false,\n ...remaining\n } = props;\n const treeId = useEnsuredId(id, \"tree\");\n const { items, treeItemChildIds } = useTreeItems({\n data,\n sort,\n rootId,\n });\n\n const { metadataLookup, movementContext, movementProps } = useTreeMovement({\n ref: treeRef,\n onClick,\n onFocus,\n onKeyDown,\n data,\n expandedIds,\n selectedIds,\n treeItemChildIds,\n toggleTreeItemExpansion,\n expandMultipleTreeItems,\n });\n\n return (\n <TreeProvider\n data={data}\n rootId={rootId}\n multiSelect={multiSelect}\n linkComponent={linkComponent}\n selectedIds={selectedIds}\n expandedIds={expandedIds}\n expanderIcon={expanderIcon}\n expanderLeft={expanderLeft}\n expansionMode={expansionMode}\n metadataLookup={metadataLookup}\n disableTransition={disableTransition}\n temporaryChildItems={temporaryChildItems}\n toggleTreeItemSelection={toggleTreeItemSelection}\n toggleTreeItemExpansion={toggleTreeItemExpansion}\n selectMultipleTreeItems={selectMultipleTreeItems}\n expandMultipleTreeItems={expandMultipleTreeItems}\n >\n <KeyboardMovementProvider value={movementContext}>\n <List\n {...remaining}\n {...movementProps}\n id={treeId}\n role=\"tree\"\n tabIndex={0}\n className={tree({ className })}\n >\n <RenderRecursively\n items={items}\n render={TreeItemRenderer}\n getItemKey={(options) => options.item.itemId}\n />\n </List>\n </KeyboardMovementProvider>\n </TreeProvider>\n );\n}\n"],"names":["List","KeyboardMovementProvider","useEnsuredId","RenderRecursively","identity","DefaultTreeItemRenderer","TreeProvider","tree","useTreeItems","useTreeMovement","Tree","props","id","data","sort","rootId","treeRef","className","expandedIds","selectedIds","toggleTreeItemSelection","selectMultipleTreeItems","toggleTreeItemExpansion","expandMultipleTreeItems","onClick","onFocus","onKeyDown","renderer","TreeItemRenderer","multiSelect","expansionMode","expanderIcon","expanderLeft","linkComponent","disableTransition","temporaryChildItems","remaining","treeId","items","treeItemChildIds","metadataLookup","movementContext","movementProps","ref","value","role","tabIndex","render","getItemKey","options","item","itemId"],"mappings":"AAAA;;AAWA,SAASA,IAAI,QAAQ,kBAAkB;AACvC,SAASC,wBAAwB,QAAQ,6CAA6C;AAEtF,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAAiCC,YAAY,QAAQ,oBAAoB;AACzE,SAAoCC,IAAI,QAAQ,cAAc;AAQ9D,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,eAAe,QAAQ,uBAAuB;AAgJvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DC,GACD,OAAO,SAASC,KACdC,KAAyC;IAEzC,MAAM,EACJC,EAAE,EACFC,IAAI,EACJC,OAAOV,QAAQ,EACfW,SAAS,IAAI,EACbC,OAAO,EACPC,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACvBC,OAAO,EACPC,OAAO,EACPC,SAAS,EACTC,UAAUC,mBAAmBvB,uBAAuB,EACpDwB,cAAc,KAAK,EACnBC,gBAAgB,MAAM,EACtBC,YAAY,EACZC,eAAe,KAAK,EACpBC,gBAAgB,GAAG,EACnBC,oBAAoB,KAAK,EACzBC,sBAAsB,KAAK,EAC3B,GAAGC,WACJ,GAAGzB;IACJ,MAAM0B,SAASnC,aAAaU,IAAI;IAChC,MAAM,EAAE0B,KAAK,EAAEC,gBAAgB,EAAE,GAAG/B,aAAa;QAC/CK;QACAC;QACAC;IACF;IAEA,MAAM,EAAEyB,cAAc,EAAEC,eAAe,EAAEC,aAAa,EAAE,GAAGjC,gBAAgB;QACzEkC,KAAK3B;QACLQ;QACAC;QACAC;QACAb;QACAK;QACAC;QACAoB;QACAjB;QACAC;IACF;IAEA,qBACE,KAACjB;QACCO,MAAMA;QACNE,QAAQA;QACRc,aAAaA;QACbI,eAAeA;QACfd,aAAaA;QACbD,aAAaA;QACba,cAAcA;QACdC,cAAcA;QACdF,eAAeA;QACfU,gBAAgBA;QAChBN,mBAAmBA;QACnBC,qBAAqBA;QACrBf,yBAAyBA;QACzBE,yBAAyBA;QACzBD,yBAAyBA;QACzBE,yBAAyBA;kBAEzB,cAAA,KAACtB;YAAyB2C,OAAOH;sBAC/B,cAAA,KAACzC;gBACE,GAAGoC,SAAS;gBACZ,GAAGM,aAAa;gBACjB9B,IAAIyB;gBACJQ,MAAK;gBACLC,UAAU;gBACV7B,WAAWV,KAAK;oBAAEU;gBAAU;0BAE5B,cAAA,KAACd;oBACCmC,OAAOA;oBACPS,QAAQnB;oBACRoB,YAAY,CAACC,UAAYA,QAAQC,IAAI,CAACC,MAAM;;;;;AAMxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/TreeItem.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n useEffect,\n} from \"react\";\n\nimport { type ComponentWithRippleProps } from \"../interaction/types.js\";\nimport { useElementInteraction } from \"../interaction/useElementInteraction.js\";\nimport { useHigherContrastChildren } from \"../interaction/useHigherContrastChildren.js\";\nimport { ListItemChildren } from \"../list/ListItemChildren.js\";\nimport { useKeyboardMovementContext } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type PropsWithRef } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { type OverridableTreeGroupProps, TreeGroup } from \"./TreeGroup.js\";\nimport { TreeItemExpander } from \"./TreeItemExpander.js\";\nimport { useTreeContext } from \"./TreeProvider.js\";\nimport { treeItem, treeItemContent, treeItemMedia } from \"./styles.js\";\nimport { type DefaultTreeItemNode } from \"./types.js\";\n\n/**\n * @since 6.0.0 Added `liProps` and `groupProps`.\n * @since 6.0.0 The `liRef`, `liStyle`, and `liClassName` props were removed in\n * favor of `liProps={{ ref, style, className }}`.\n * @since 6.0.0 The `itemIndex`, `listSize`, `renderChildItems`, `isLink`,\n * `contentComponent`, and `readOnly` props were removed.\n */\nexport interface TreeItemProps\n extends Omit<DefaultTreeItemNode, \"parentId\">,\n HTMLAttributes<HTMLLIElement>,\n ComponentWithRippleProps {\n /**\n * @defaultValue `\"tree-item-\" + useId()`\n */\n id?: string;\n\n /**\n * This is used to set the `--rmd-tree-depth` CSS variable which allows the\n * padding to increase for each nested tree.\n */\n depth: number;\n\n /**\n * Any additional props that should be passed to the surrounding `<li>`\n * element. The top-level props are passed to the `<span>` or `<a>` element\n * instead.\n */\n liProps?: PropsWithRef<HTMLAttributes<HTMLLIElement>>;\n\n /**\n * Any additional props to pass to the `TreeGroup` component.\n */\n groupProps?: PropsWithRef<OverridableTreeGroupProps>;\n\n /**\n * This should normally be the text/content to display within the tree item\n * and should **not** include nested trees.\n */\n children?: ReactNode;\n\n /**\n * The nested tree items to render within a `TreeGroup`.\n */\n childItems?: ReactNode;\n\n /** @defaultValue `false` */\n disableTransition?: boolean;\n\n /**\n * This ref is applied to the `<span>` or `<a>` element and can be used to\n * implement drag and drop behavior.\n */\n contentRef?: Ref<HTMLElement>;\n\n /**\n * Set this to `true` if the {@link childItems} should not be rendered while\n * collapsed.\n *\n * @defaultValue `false`\n */\n temporaryChildItems?: boolean;\n}\n\n/**\n * **Client Component**\n *\n * @see {@link https://react-md.dev/components/tree | Tree Demos}\n * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/treeview/}\n * @since 6.0.0 No longer forwards refs. The ref must be provided using\n * `contentRef` instead.\n * @since 6.0.0 The `liRef` was removed in favor of `liProps={{ ref }}`.\n * @since 6.0.0 The wrapping `<li>` element will always be `role=\"none\"` and the\n * `<span>` or `<a>` will gain the `role=\"treeitem\"` instead. This makes it\n * easier to pass event handlers because of the nested behavior of tree items.\n * @since 6.0.0 No longer provides the `aria-level`, `aria-setsize` and\n * `aria-posinset` attributes and allows the browser to compute them instead.\n */\nexport function TreeItem(props: TreeItemProps): ReactElement {\n const {\n id: propId,\n depth,\n liProps,\n disabled = false,\n disabledOpacity = false,\n groupProps,\n children: propChildren,\n className,\n itemId,\n leftAddon,\n leftAddonType: propLeftAddonType,\n leftAddonPosition,\n leftAddonClassName,\n leftAddonForceWrap,\n rightAddon,\n rightAddonType,\n rightAddonPosition,\n rightAddonClassName,\n rightAddonForceWrap,\n disableTextChildren,\n disableLeftAddonCenteredMedia: propDisableLeftAddonCenteredMedia,\n disableRightAddonCenteredMedia,\n textProps,\n textClassName,\n primaryText,\n secondaryText,\n secondaryTextProps,\n secondaryTextClassName,\n multiline,\n childItems,\n contentClassName,\n temporaryChildItems,\n disableTransition: propDisableTransition,\n onBlur,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDragStart,\n onTouchStart,\n onTouchEnd,\n onTouchMove,\n contentRef,\n disableRipple,\n ...remaining\n } = props;\n\n const id = useEnsuredId(propId, \"tree-item\");\n const children = useHigherContrastChildren(propChildren);\n if (disabled) {\n // you can't really disable a link other than removing the href, so\n // unset these props\n remaining.to = undefined;\n remaining.href = undefined;\n }\n\n const {\n expandedIds,\n selectedIds,\n expanderLeft,\n expansionMode,\n metadataLookup,\n linkComponent: Link,\n toggleTreeItemSelection,\n toggleTreeItemExpansion,\n disableTransition: contextDisableTransition,\n } = useTreeContext();\n const { activeDescendantId } = useKeyboardMovementContext();\n\n const isLeafNode = !childItems;\n const focused = activeDescendantId === id;\n const expanded = expandedIds.has(itemId);\n const selected = selectedIds.has(itemId);\n const disableTransition = propDisableTransition ?? contextDisableTransition;\n\n useEffect(() => {\n const lookup = metadataLookup.current;\n lookup.expandable[itemId] = !isLeafNode;\n lookup.disabledItems[itemId] = disabled;\n lookup.elementToItem[id] = itemId;\n lookup.itemToElement[itemId] = id;\n\n return () => {\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete lookup.disabledItems[itemId];\n delete lookup.expandable[itemId];\n delete lookup.elementToItem[id];\n delete lookup.itemToElement[itemId];\n /* eslint-enable @typescript-eslint/no-dynamic-delete */\n };\n }, [id, metadataLookup, itemId, isLeafNode, disabled, depth]);\n\n const { pressedClassName, ripples, handlers } =\n useElementInteraction<HTMLLIElement>({\n mode: disableRipple ? \"none\" : undefined,\n onBlur,\n onClick(event) {\n onClick?.(event);\n toggleTreeItemSelection(itemId);\n if (!isLeafNode && expansionMode !== \"manual\") {\n toggleTreeItemExpansion(itemId);\n }\n },\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDragStart,\n onTouchStart,\n onTouchEnd,\n onTouchMove,\n disabled,\n });\n\n const isLink = !!(remaining.to || remaining.href);\n\n // cheating a bit so there are type errors around the event handlers\n const ContentComponent = (isLink ? Link : \"span\") as \"span\";\n const leftAddonType =\n (propLeftAddonType ?? (expanderLeft && leftAddon)) ? \"media\" : undefined;\n const isMediaLeftAddon =\n typeof propLeftAddonType === \"undefined\" && leftAddonType === \"media\";\n const disableLeftAddonCenteredMedia =\n propDisableLeftAddonCenteredMedia ?? isMediaLeftAddon;\n\n return (\n <li\n {...liProps}\n role=\"none\"\n className={treeItem({\n className,\n expander: !!childItems,\n expanderLeft,\n })}\n >\n <ContentComponent\n {...remaining}\n // nodes with children should always apply the `aria-expanded` to show\n // that it is expandable while leaf nodes should remain omitted\n aria-expanded={isLeafNode ? undefined : expanded}\n aria-selected={selected}\n aria-disabled={disabled || undefined}\n id={id}\n ref={contentRef}\n role=\"treeitem\"\n tabIndex={-1}\n {...handlers}\n className={treeItemContent({\n link: isLink,\n focused,\n selected,\n disabled,\n disabledOpacity,\n className: contentClassName,\n pressedClassName,\n })}\n >\n <ListItemChildren\n multiline={multiline}\n textClassName={textClassName}\n secondaryTextClassName={secondaryTextClassName}\n disableTextChildren={disableTextChildren}\n primaryText={primaryText}\n textProps={textProps}\n secondaryText={secondaryText}\n secondaryTextProps={secondaryTextProps}\n leftAddon={\n <TreeItemExpander\n isLeft\n itemId={itemId}\n addon={leftAddon}\n expanded={expanded}\n disabled={disabled}\n isLeafNode={isLeafNode}\n />\n }\n leftAddonType={leftAddonType}\n leftAddonPosition={leftAddonPosition}\n leftAddonClassName={treeItemMedia({\n isLeafNode,\n isMediaLeftAddon,\n className: leftAddonClassName,\n })}\n leftAddonForceWrap={leftAddonForceWrap}\n rightAddon={\n <TreeItemExpander\n itemId={itemId}\n addon={rightAddon}\n expanded={expanded}\n disabled={disabled}\n isLeafNode={isLeafNode}\n />\n }\n rightAddonType={rightAddonType}\n rightAddonPosition={rightAddonPosition}\n rightAddonClassName={rightAddonClassName}\n rightAddonForceWrap={rightAddonForceWrap}\n disableLeftAddonCenteredMedia={disableLeftAddonCenteredMedia}\n disableRightAddonCenteredMedia={disableRightAddonCenteredMedia}\n >\n {children}\n </ListItemChildren>\n {ripples}\n </ContentComponent>\n <TreeGroup\n id={`${id}-group`}\n temporary={temporaryChildItems}\n disableTransition={disableTransition}\n {...groupProps}\n depth={depth + 1}\n collapsed={isLeafNode || !expanded}\n >\n {childItems}\n </TreeGroup>\n </li>\n );\n}\n"],"names":["useEffect","useElementInteraction","useHigherContrastChildren","ListItemChildren","useKeyboardMovementContext","useEnsuredId","TreeGroup","TreeItemExpander","useTreeContext","treeItem","treeItemContent","treeItemMedia","TreeItem","props","id","propId","depth","liProps","disabled","disabledOpacity","groupProps","children","propChildren","className","itemId","leftAddon","leftAddonType","propLeftAddonType","leftAddonPosition","leftAddonClassName","leftAddonForceWrap","rightAddon","rightAddonType","rightAddonPosition","rightAddonClassName","rightAddonForceWrap","disableTextChildren","disableLeftAddonCenteredMedia","propDisableLeftAddonCenteredMedia","disableRightAddonCenteredMedia","textProps","textClassName","primaryText","secondaryText","secondaryTextProps","secondaryTextClassName","multiline","childItems","contentClassName","temporaryChildItems","disableTransition","propDisableTransition","onBlur","onClick","onKeyDown","onKeyUp","onMouseDown","onMouseUp","onMouseLeave","onDragStart","onTouchStart","onTouchEnd","onTouchMove","contentRef","disableRipple","remaining","to","undefined","href","expandedIds","selectedIds","expanderLeft","expansionMode","metadataLookup","linkComponent","Link","toggleTreeItemSelection","toggleTreeItemExpansion","contextDisableTransition","activeDescendantId","isLeafNode","focused","expanded","has","selected","lookup","current","expandable","disabledItems","elementToItem","itemToElement","pressedClassName","ripples","handlers","mode","event","isLink","ContentComponent","isMediaLeftAddon","li","role","expander","aria-expanded","aria-selected","aria-disabled","ref","tabIndex","link","isLeft","addon","temporary","collapsed"],"mappings":"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"}
|
|
1
|
+
{"version":3,"sources":["../../src/tree/TreeItem.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n useEffect,\n} from \"react\";\n\nimport { type ComponentWithRippleProps } from \"../interaction/types.js\";\nimport { useElementInteraction } from \"../interaction/useElementInteraction.js\";\nimport { useHigherContrastChildren } from \"../interaction/useHigherContrastChildren.js\";\nimport { ListItemChildren } from \"../list/ListItemChildren.js\";\nimport { useKeyboardMovementContext } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type PropsWithRef } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { type OverridableTreeGroupProps, TreeGroup } from \"./TreeGroup.js\";\nimport { TreeItemExpander } from \"./TreeItemExpander.js\";\nimport { useTreeContext } from \"./TreeProvider.js\";\nimport { treeItem, treeItemContent, treeItemMedia } from \"./styles.js\";\nimport { type DefaultTreeItemNode } from \"./types.js\";\n\n/**\n * @since 6.0.0 Added `liProps` and `groupProps`.\n * @since 6.0.0 The `liRef`, `liStyle`, and `liClassName` props were removed in\n * favor of `liProps={{ ref, style, className }}`.\n * @since 6.0.0 The `itemIndex`, `listSize`, `renderChildItems`, `isLink`,\n * `contentComponent`, and `readOnly` props were removed.\n */\nexport interface TreeItemProps\n extends\n Omit<DefaultTreeItemNode, \"parentId\">,\n HTMLAttributes<HTMLLIElement>,\n ComponentWithRippleProps {\n /**\n * @defaultValue `\"tree-item-\" + useId()`\n */\n id?: string;\n\n /**\n * This is used to set the `--rmd-tree-depth` CSS variable which allows the\n * padding to increase for each nested tree.\n */\n depth: number;\n\n /**\n * Any additional props that should be passed to the surrounding `<li>`\n * element. The top-level props are passed to the `<span>` or `<a>` element\n * instead.\n */\n liProps?: PropsWithRef<HTMLAttributes<HTMLLIElement>>;\n\n /**\n * Any additional props to pass to the `TreeGroup` component.\n */\n groupProps?: PropsWithRef<OverridableTreeGroupProps>;\n\n /**\n * This should normally be the text/content to display within the tree item\n * and should **not** include nested trees.\n */\n children?: ReactNode;\n\n /**\n * The nested tree items to render within a `TreeGroup`.\n */\n childItems?: ReactNode;\n\n /** @defaultValue `false` */\n disableTransition?: boolean;\n\n /**\n * This ref is applied to the `<span>` or `<a>` element and can be used to\n * implement drag and drop behavior.\n */\n contentRef?: Ref<HTMLElement>;\n\n /**\n * Set this to `true` if the {@link childItems} should not be rendered while\n * collapsed.\n *\n * @defaultValue `false`\n */\n temporaryChildItems?: boolean;\n}\n\n/**\n * **Client Component**\n *\n * @see {@link https://react-md.dev/components/tree | Tree Demos}\n * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/treeview/}\n * @since 6.0.0 No longer forwards refs. The ref must be provided using\n * `contentRef` instead.\n * @since 6.0.0 The `liRef` was removed in favor of `liProps={{ ref }}`.\n * @since 6.0.0 The wrapping `<li>` element will always be `role=\"none\"` and the\n * `<span>` or `<a>` will gain the `role=\"treeitem\"` instead. This makes it\n * easier to pass event handlers because of the nested behavior of tree items.\n * @since 6.0.0 No longer provides the `aria-level`, `aria-setsize` and\n * `aria-posinset` attributes and allows the browser to compute them instead.\n */\nexport function TreeItem(props: TreeItemProps): ReactElement {\n const {\n id: propId,\n depth,\n liProps,\n disabled = false,\n disabledOpacity = false,\n groupProps,\n children: propChildren,\n className,\n itemId,\n leftAddon,\n leftAddonType: propLeftAddonType,\n leftAddonPosition,\n leftAddonClassName,\n leftAddonForceWrap,\n rightAddon,\n rightAddonType,\n rightAddonPosition,\n rightAddonClassName,\n rightAddonForceWrap,\n disableTextChildren,\n disableLeftAddonCenteredMedia: propDisableLeftAddonCenteredMedia,\n disableRightAddonCenteredMedia,\n textProps,\n textClassName,\n primaryText,\n secondaryText,\n secondaryTextProps,\n secondaryTextClassName,\n multiline,\n childItems,\n contentClassName,\n temporaryChildItems,\n disableTransition: propDisableTransition,\n onBlur,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDragStart,\n onTouchStart,\n onTouchEnd,\n onTouchMove,\n contentRef,\n disableRipple,\n ...remaining\n } = props;\n\n const id = useEnsuredId(propId, \"tree-item\");\n const children = useHigherContrastChildren(propChildren);\n if (disabled) {\n // you can't really disable a link other than removing the href, so\n // unset these props\n remaining.to = undefined;\n remaining.href = undefined;\n }\n\n const {\n expandedIds,\n selectedIds,\n expanderLeft,\n expansionMode,\n metadataLookup,\n linkComponent: Link,\n toggleTreeItemSelection,\n toggleTreeItemExpansion,\n disableTransition: contextDisableTransition,\n } = useTreeContext();\n const { activeDescendantId } = useKeyboardMovementContext();\n\n const isLeafNode = !childItems;\n const focused = activeDescendantId === id;\n const expanded = expandedIds.has(itemId);\n const selected = selectedIds.has(itemId);\n const disableTransition = propDisableTransition ?? contextDisableTransition;\n\n useEffect(() => {\n const lookup = metadataLookup.current;\n lookup.expandable[itemId] = !isLeafNode;\n lookup.disabledItems[itemId] = disabled;\n lookup.elementToItem[id] = itemId;\n lookup.itemToElement[itemId] = id;\n\n return () => {\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete lookup.disabledItems[itemId];\n delete lookup.expandable[itemId];\n delete lookup.elementToItem[id];\n delete lookup.itemToElement[itemId];\n /* eslint-enable @typescript-eslint/no-dynamic-delete */\n };\n }, [id, metadataLookup, itemId, isLeafNode, disabled, depth]);\n\n const { pressedClassName, ripples, handlers } =\n useElementInteraction<HTMLLIElement>({\n mode: disableRipple ? \"none\" : undefined,\n onBlur,\n onClick(event) {\n onClick?.(event);\n toggleTreeItemSelection(itemId);\n if (!isLeafNode && expansionMode !== \"manual\") {\n toggleTreeItemExpansion(itemId);\n }\n },\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDragStart,\n onTouchStart,\n onTouchEnd,\n onTouchMove,\n disabled,\n });\n\n const isLink = !!(remaining.to || remaining.href);\n\n // cheating a bit so there are type errors around the event handlers\n const ContentComponent = (isLink ? Link : \"span\") as \"span\";\n const leftAddonType =\n (propLeftAddonType ?? (expanderLeft && leftAddon)) ? \"media\" : undefined;\n const isMediaLeftAddon =\n typeof propLeftAddonType === \"undefined\" && leftAddonType === \"media\";\n const disableLeftAddonCenteredMedia =\n propDisableLeftAddonCenteredMedia ?? isMediaLeftAddon;\n\n return (\n <li\n {...liProps}\n role=\"none\"\n className={treeItem({\n className,\n expander: !!childItems,\n expanderLeft,\n })}\n >\n <ContentComponent\n {...remaining}\n // nodes with children should always apply the `aria-expanded` to show\n // that it is expandable while leaf nodes should remain omitted\n aria-expanded={isLeafNode ? undefined : expanded}\n aria-selected={selected}\n aria-disabled={disabled || undefined}\n id={id}\n ref={contentRef}\n role=\"treeitem\"\n tabIndex={-1}\n {...handlers}\n className={treeItemContent({\n link: isLink,\n focused,\n selected,\n disabled,\n disabledOpacity,\n className: contentClassName,\n pressedClassName,\n })}\n >\n <ListItemChildren\n multiline={multiline}\n textClassName={textClassName}\n secondaryTextClassName={secondaryTextClassName}\n disableTextChildren={disableTextChildren}\n primaryText={primaryText}\n textProps={textProps}\n secondaryText={secondaryText}\n secondaryTextProps={secondaryTextProps}\n leftAddon={\n <TreeItemExpander\n isLeft\n itemId={itemId}\n addon={leftAddon}\n expanded={expanded}\n disabled={disabled}\n isLeafNode={isLeafNode}\n />\n }\n leftAddonType={leftAddonType}\n leftAddonPosition={leftAddonPosition}\n leftAddonClassName={treeItemMedia({\n isLeafNode,\n isMediaLeftAddon,\n className: leftAddonClassName,\n })}\n leftAddonForceWrap={leftAddonForceWrap}\n rightAddon={\n <TreeItemExpander\n itemId={itemId}\n addon={rightAddon}\n expanded={expanded}\n disabled={disabled}\n isLeafNode={isLeafNode}\n />\n }\n rightAddonType={rightAddonType}\n rightAddonPosition={rightAddonPosition}\n rightAddonClassName={rightAddonClassName}\n rightAddonForceWrap={rightAddonForceWrap}\n disableLeftAddonCenteredMedia={disableLeftAddonCenteredMedia}\n disableRightAddonCenteredMedia={disableRightAddonCenteredMedia}\n >\n {children}\n </ListItemChildren>\n {ripples}\n </ContentComponent>\n <TreeGroup\n id={`${id}-group`}\n temporary={temporaryChildItems}\n disableTransition={disableTransition}\n {...groupProps}\n depth={depth + 1}\n collapsed={isLeafNode || !expanded}\n >\n {childItems}\n </TreeGroup>\n </li>\n );\n}\n"],"names":["useEffect","useElementInteraction","useHigherContrastChildren","ListItemChildren","useKeyboardMovementContext","useEnsuredId","TreeGroup","TreeItemExpander","useTreeContext","treeItem","treeItemContent","treeItemMedia","TreeItem","props","id","propId","depth","liProps","disabled","disabledOpacity","groupProps","children","propChildren","className","itemId","leftAddon","leftAddonType","propLeftAddonType","leftAddonPosition","leftAddonClassName","leftAddonForceWrap","rightAddon","rightAddonType","rightAddonPosition","rightAddonClassName","rightAddonForceWrap","disableTextChildren","disableLeftAddonCenteredMedia","propDisableLeftAddonCenteredMedia","disableRightAddonCenteredMedia","textProps","textClassName","primaryText","secondaryText","secondaryTextProps","secondaryTextClassName","multiline","childItems","contentClassName","temporaryChildItems","disableTransition","propDisableTransition","onBlur","onClick","onKeyDown","onKeyUp","onMouseDown","onMouseUp","onMouseLeave","onDragStart","onTouchStart","onTouchEnd","onTouchMove","contentRef","disableRipple","remaining","to","undefined","href","expandedIds","selectedIds","expanderLeft","expansionMode","metadataLookup","linkComponent","Link","toggleTreeItemSelection","toggleTreeItemExpansion","contextDisableTransition","activeDescendantId","isLeafNode","focused","expanded","has","selected","lookup","current","expandable","disabledItems","elementToItem","itemToElement","pressedClassName","ripples","handlers","mode","event","isLink","ContentComponent","isMediaLeftAddon","li","role","expander","aria-expanded","aria-selected","aria-disabled","ref","tabIndex","link","isLeft","addon","temporary","collapsed"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/TreeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactElement,\n type ReactNode,\n createContext,\n useContext,\n useMemo,\n} from \"react\";\n\nimport { type CustomLinkComponent } from \"../link/Link.js\";\nimport { type NonNullRef } from \"../types.js\";\nimport {\n type DefaultTreeItemNode,\n type TreeData,\n type TreeItemNode,\n} from \"./types.js\";\nimport { type TreeExpansion } from \"./useTreeExpansion.js\";\nimport { type TreeSelection } from \"./useTreeSelection.js\";\n\n/**\n * When this is set to `\"auto\"`, clicking on a tree item with a mouse or with\n * the Enter/Space keys will select and expand/collapse the tree item. The user\n * can still use the ArrowLeft and ArrowRight keys to expand/collapse nested\n * tree items.\n *\n * When this is set to `\"manual\"`, clicking on a tree item with a mouse or with\n * the Enter/Space keys will only select that tree item. The user must use the\n * ArrowLeft and ArrowRight keys to expand/collapse nested tree items.\n *\n * The main use-case for the `\"manual\"` setting is creating a navigation tree\n * that requires the user to click on an icon or a button to expand the child\n * items.\n *\n * @since 6.0.0\n */\nexport type TreeExpansionMode = \"auto\" | \"manual\";\n\n/**\n * @internal\n * @since 6.0.0\n */\nexport interface TreeItemMetadataLookup {\n /**\n * This is used for the keyboard movement behavior for trees that allow the\n * `ArrowRight` key for tree items that have children.\n */\n expandable: Record<string, boolean>;\n\n /**\n * This is a quick lookup if a tree item is disabled since it's possible the\n * custom `renderer` sets the `disabled` state and not the `TreeData`.\n */\n disabledItems: Record<string, boolean>;\n\n /**\n * A lookup of element `id` (DOM id) for each tree item to the `itemId`. This\n * is a quick way to figure out which item is being interacted with from a\n * keyboard event without needed to add `data-*` attributes.\n */\n elementToItem: Record<string, string>;\n\n /**\n * A lookup of tree item `itemId` to the element `id` (DOM id). This is used\n * to be able to find a parent tree item when the `ArrowLeft` key is pressed\n * to focus that parent item.\n */\n itemToElement: Record<string, string>;\n}\n\n/**\n * The tree context is mostly a convenience API for implementing a custom tree\n * item that requires the {@link TreeExpansion}, {@link TreeSelection} and\n * {@link TreeData} to work.\n *\n * The other properties on the context are most likely for internal use only.\n *\n * @since 6.0.0\n */\nexport interface TreeContext<T extends TreeItemNode = DefaultTreeItemNode>\n extends TreeExpansion
|
|
1
|
+
{"version":3,"sources":["../../src/tree/TreeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactElement,\n type ReactNode,\n createContext,\n useContext,\n useMemo,\n} from \"react\";\n\nimport { type CustomLinkComponent } from \"../link/Link.js\";\nimport { type NonNullRef } from \"../types.js\";\nimport {\n type DefaultTreeItemNode,\n type TreeData,\n type TreeItemNode,\n} from \"./types.js\";\nimport { type TreeExpansion } from \"./useTreeExpansion.js\";\nimport { type TreeSelection } from \"./useTreeSelection.js\";\n\n/**\n * When this is set to `\"auto\"`, clicking on a tree item with a mouse or with\n * the Enter/Space keys will select and expand/collapse the tree item. The user\n * can still use the ArrowLeft and ArrowRight keys to expand/collapse nested\n * tree items.\n *\n * When this is set to `\"manual\"`, clicking on a tree item with a mouse or with\n * the Enter/Space keys will only select that tree item. The user must use the\n * ArrowLeft and ArrowRight keys to expand/collapse nested tree items.\n *\n * The main use-case for the `\"manual\"` setting is creating a navigation tree\n * that requires the user to click on an icon or a button to expand the child\n * items.\n *\n * @since 6.0.0\n */\nexport type TreeExpansionMode = \"auto\" | \"manual\";\n\n/**\n * @internal\n * @since 6.0.0\n */\nexport interface TreeItemMetadataLookup {\n /**\n * This is used for the keyboard movement behavior for trees that allow the\n * `ArrowRight` key for tree items that have children.\n */\n expandable: Record<string, boolean>;\n\n /**\n * This is a quick lookup if a tree item is disabled since it's possible the\n * custom `renderer` sets the `disabled` state and not the `TreeData`.\n */\n disabledItems: Record<string, boolean>;\n\n /**\n * A lookup of element `id` (DOM id) for each tree item to the `itemId`. This\n * is a quick way to figure out which item is being interacted with from a\n * keyboard event without needed to add `data-*` attributes.\n */\n elementToItem: Record<string, string>;\n\n /**\n * A lookup of tree item `itemId` to the element `id` (DOM id). This is used\n * to be able to find a parent tree item when the `ArrowLeft` key is pressed\n * to focus that parent item.\n */\n itemToElement: Record<string, string>;\n}\n\n/**\n * The tree context is mostly a convenience API for implementing a custom tree\n * item that requires the {@link TreeExpansion}, {@link TreeSelection} and\n * {@link TreeData} to work.\n *\n * The other properties on the context are most likely for internal use only.\n *\n * @since 6.0.0\n */\nexport interface TreeContext<T extends TreeItemNode = DefaultTreeItemNode>\n extends TreeExpansion, TreeSelection {\n data: TreeData<T>;\n rootId: string | null;\n disableTransition: boolean;\n temporaryChildItems: boolean;\n\n linkComponent: CustomLinkComponent;\n\n /** @internal */\n expanderLeft: boolean;\n /** @internal */\n expanderIcon: ReactNode;\n /** @internal */\n expansionMode: TreeExpansionMode;\n /** @internal */\n metadataLookup: NonNullRef<TreeItemMetadataLookup>;\n}\n\n// Allow the hook to correct typecast this instead\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst context = createContext<TreeContext<any> | undefined>(undefined);\ncontext.displayName = \"Tree\";\nconst { Provider } = context;\n\n/**\n * This can be used for a custom tree item renderer.\n *\n * @see The `Tree` component for an example.\n * @since 6.0.0\n */\nexport function useTreeContext<\n T extends TreeItemNode = DefaultTreeItemNode,\n>(): TreeContext<T> {\n const value = useContext(context);\n if (!value) {\n throw new Error(\"Cannot find a parent Tree component\");\n }\n\n return value;\n}\n\n/**\n * @internal\n * @since 6.0.0\n */\nexport interface TreeProviderProps<\n T extends TreeItemNode = DefaultTreeItemNode,\n> extends TreeContext<T> {\n children: ReactNode;\n}\n\n/**\n * **Client Component**\n *\n * @internal\n * @since 6.0.0\n */\nexport function TreeProvider<T extends TreeItemNode = DefaultTreeItemNode>(\n props: TreeProviderProps<T>\n): ReactElement {\n const {\n children,\n data,\n rootId,\n multiSelect,\n expanderIcon,\n expanderLeft,\n expansionMode,\n metadataLookup,\n disableTransition,\n temporaryChildItems,\n linkComponent,\n expandedIds,\n selectedIds,\n expandMultipleTreeItems,\n toggleTreeItemExpansion,\n selectMultipleTreeItems,\n toggleTreeItemSelection,\n } = props;\n const value = useMemo<TreeContext<T>>(\n () => ({\n data,\n rootId,\n multiSelect,\n expanderIcon,\n expanderLeft,\n expansionMode,\n metadataLookup,\n disableTransition,\n temporaryChildItems,\n linkComponent,\n expandedIds,\n selectedIds,\n expandMultipleTreeItems,\n toggleTreeItemExpansion,\n selectMultipleTreeItems,\n toggleTreeItemSelection,\n }),\n [\n data,\n disableTransition,\n expandMultipleTreeItems,\n expandedIds,\n expanderIcon,\n expanderLeft,\n expansionMode,\n linkComponent,\n metadataLookup,\n multiSelect,\n rootId,\n selectMultipleTreeItems,\n selectedIds,\n temporaryChildItems,\n toggleTreeItemExpansion,\n toggleTreeItemSelection,\n ]\n );\n\n return <Provider value={value}>{children}</Provider>;\n}\n"],"names":["createContext","useContext","useMemo","context","undefined","displayName","Provider","useTreeContext","value","Error","TreeProvider","props","children","data","rootId","multiSelect","expanderIcon","expanderLeft","expansionMode","metadataLookup","disableTransition","temporaryChildItems","linkComponent","expandedIds","selectedIds","expandMultipleTreeItems","toggleTreeItemExpansion","selectMultipleTreeItems","toggleTreeItemSelection"],"mappings":"AAAA;;AAEA,SAGEA,aAAa,EACbC,UAAU,EACVC,OAAO,QACF,QAAQ;AA0Ff,kDAAkD;AAClD,8DAA8D;AAC9D,MAAMC,wBAAUH,cAA4CI;AAC5DD,QAAQE,WAAW,GAAG;AACtB,MAAM,EAAEC,QAAQ,EAAE,GAAGH;AAErB;;;;;CAKC,GACD,OAAO,SAASI;IAGd,MAAMC,QAAQP,WAAWE;IACzB,IAAI,CAACK,OAAO;QACV,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAOD;AACT;AAYA;;;;;CAKC,GACD,OAAO,SAASE,aACdC,KAA2B;IAE3B,MAAM,EACJC,QAAQ,EACRC,IAAI,EACJC,MAAM,EACNC,WAAW,EACXC,YAAY,EACZC,YAAY,EACZC,aAAa,EACbC,cAAc,EACdC,iBAAiB,EACjBC,mBAAmB,EACnBC,aAAa,EACbC,WAAW,EACXC,WAAW,EACXC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACxB,GAAGjB;IACJ,MAAMH,QAAQN,QACZ,IAAO,CAAA;YACLW;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;QACF,CAAA,GACA;QACEf;QACAO;QACAK;QACAF;QACAP;QACAC;QACAC;QACAI;QACAH;QACAJ;QACAD;QACAa;QACAH;QACAH;QACAK;QACAE;KACD;IAGH,qBAAO,KAACtB;QAASE,OAAOA;kBAAQI;;AAClC"}
|
package/dist/tree/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/styles.ts"],"sourcesContent":["import { cnb } from \"cnbuilder\";\n\nimport { type InternalListItemClassNameOptions } from \"../list/listItemStyles.js\";\nimport { listItem } from \"../list/listItemStyles.js\";\nimport { bem } from \"../utils/bem.js\";\n\nconst treeStyles = bem(\"rmd-tree\");\nconst treeItemStyles = bem(\"rmd-tree-item\");\nconst treeGroupStyles = bem(\"rmd-tree-group\");\n\ndeclare module \"react\" {\n interface CSSProperties {\n \"--rmd-tree-depth\"?: number;\n \"--rmd-tree-item-padding\"?: string | number;\n \"--rmd-tree-item-padding-base\"?: string | number;\n \"--rmd-tree-item-padding-incrementor\"?: string | number;\n }\n}\n\n/** @since 6.0.0 */\nexport interface TreeClassNameOptions {\n className?: string;\n}\n\n/**\n * Apply the `className`s for a tree component. This will be type-safe if using\n * typescript.\n *\n * @since 6.0.0\n */\nexport function tree(options: TreeClassNameOptions = {}): string {\n const { className } = options;\n\n return cnb(treeStyles(), className);\n}\n\n/** @since 6.0.0 */\nexport interface TreeItemClassNameOptions {\n className?: string;\n expander?: boolean;\n\n /**\n * Settings this to `true` will update the styles for the expander icon within\n * the tree item to rotate `down -> right` instead of `down -> left`.\n *\n * @defaultValue `false`\n */\n expanderLeft?: boolean;\n}\n\n/**\n * Apply the `className`s for a tree item component. This will be type-safe if\n * using typescript.\n *\n * @since 6.0.0\n */\nexport function treeItem(options: TreeItemClassNameOptions = {}): string {\n const { className, expander = false, expanderLeft = false } = options;\n\n return cnb(\n treeItemStyles({\n \"expander-left\": expander && expanderLeft,\n \"expander-right\": expander && !expanderLeft,\n }),\n className\n );\n}\n\n/** @since 6.0.0 */\nexport interface TreeItemContentClassNameOptions
|
|
1
|
+
{"version":3,"sources":["../../src/tree/styles.ts"],"sourcesContent":["import { cnb } from \"cnbuilder\";\n\nimport { type InternalListItemClassNameOptions } from \"../list/listItemStyles.js\";\nimport { listItem } from \"../list/listItemStyles.js\";\nimport { bem } from \"../utils/bem.js\";\n\nconst treeStyles = bem(\"rmd-tree\");\nconst treeItemStyles = bem(\"rmd-tree-item\");\nconst treeGroupStyles = bem(\"rmd-tree-group\");\n\ndeclare module \"react\" {\n interface CSSProperties {\n \"--rmd-tree-depth\"?: number;\n \"--rmd-tree-item-padding\"?: string | number;\n \"--rmd-tree-item-padding-base\"?: string | number;\n \"--rmd-tree-item-padding-incrementor\"?: string | number;\n }\n}\n\n/** @since 6.0.0 */\nexport interface TreeClassNameOptions {\n className?: string;\n}\n\n/**\n * Apply the `className`s for a tree component. This will be type-safe if using\n * typescript.\n *\n * @since 6.0.0\n */\nexport function tree(options: TreeClassNameOptions = {}): string {\n const { className } = options;\n\n return cnb(treeStyles(), className);\n}\n\n/** @since 6.0.0 */\nexport interface TreeItemClassNameOptions {\n className?: string;\n expander?: boolean;\n\n /**\n * Settings this to `true` will update the styles for the expander icon within\n * the tree item to rotate `down -> right` instead of `down -> left`.\n *\n * @defaultValue `false`\n */\n expanderLeft?: boolean;\n}\n\n/**\n * Apply the `className`s for a tree item component. This will be type-safe if\n * using typescript.\n *\n * @since 6.0.0\n */\nexport function treeItem(options: TreeItemClassNameOptions = {}): string {\n const { className, expander = false, expanderLeft = false } = options;\n\n return cnb(\n treeItemStyles({\n \"expander-left\": expander && expanderLeft,\n \"expander-right\": expander && !expanderLeft,\n }),\n className\n );\n}\n\n/** @since 6.0.0 */\nexport interface TreeItemContentClassNameOptions extends InternalListItemClassNameOptions {\n /**\n * Set this\n *\n * @defaultValue `false`\n */\n link?: boolean;\n\n /**\n * Set this to `true` when the tree item is the current keyboard focus with\n * `aria-activedescendant`. This will apply the focus styles only while the\n * parent tree component is focused and the user is in keyboard mode.\n *\n *\n * @defaultValue `false`\n */\n focused?: boolean;\n\n /**\n * Set this to `true` hen the tree item has been selected by the user. The\n * default styles just\n *\n * @defaultValue `false`\n */\n selected?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport function treeItemContent(\n options: TreeItemContentClassNameOptions = {}\n): string {\n const {\n className,\n link = false,\n focused,\n selected,\n disabled = false,\n ...remaining\n } = options;\n\n return cnb(\n treeItemStyles(\"content\", {\n link,\n focused,\n selected,\n disabled,\n }),\n listItem({\n className,\n disabled,\n ...remaining,\n })\n );\n}\n\n/**\n * @since 6.0.0\n */\nexport interface TreeItemMediaClassNameOptions {\n className?: string;\n isLeafNode: boolean;\n isMediaLeftAddon: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport function treeItemMedia(options: TreeItemMediaClassNameOptions): string {\n const { isLeafNode, isMediaLeftAddon, className } = options;\n\n return cnb(\n isMediaLeftAddon && treeItemStyles(\"media\", { single: isLeafNode }),\n className\n );\n}\n\n/** @since 6.0.0 */\nexport interface TreeGroupClassNameOptions {\n className?: string;\n}\n\n/**\n * @since 6.0.0\n */\nexport function treeGroup(options: TreeGroupClassNameOptions = {}): string {\n const { className } = options;\n\n return cnb(treeGroupStyles(), className);\n}\n"],"names":["cnb","listItem","bem","treeStyles","treeItemStyles","treeGroupStyles","tree","options","className","treeItem","expander","expanderLeft","treeItemContent","link","focused","selected","disabled","remaining","treeItemMedia","isLeafNode","isMediaLeftAddon","single","treeGroup"],"mappings":"AAAA,SAASA,GAAG,QAAQ,YAAY;AAGhC,SAASC,QAAQ,QAAQ,4BAA4B;AACrD,SAASC,GAAG,QAAQ,kBAAkB;AAEtC,MAAMC,aAAaD,IAAI;AACvB,MAAME,iBAAiBF,IAAI;AAC3B,MAAMG,kBAAkBH,IAAI;AAgB5B;;;;;CAKC,GACD,OAAO,SAASI,KAAKC,UAAgC,CAAC,CAAC;IACrD,MAAM,EAAEC,SAAS,EAAE,GAAGD;IAEtB,OAAOP,IAAIG,cAAcK;AAC3B;AAgBA;;;;;CAKC,GACD,OAAO,SAASC,SAASF,UAAoC,CAAC,CAAC;IAC7D,MAAM,EAAEC,SAAS,EAAEE,WAAW,KAAK,EAAEC,eAAe,KAAK,EAAE,GAAGJ;IAE9D,OAAOP,IACLI,eAAe;QACb,iBAAiBM,YAAYC;QAC7B,kBAAkBD,YAAY,CAACC;IACjC,IACAH;AAEJ;AA8BA;;CAEC,GACD,OAAO,SAASI,gBACdL,UAA2C,CAAC,CAAC;IAE7C,MAAM,EACJC,SAAS,EACTK,OAAO,KAAK,EACZC,OAAO,EACPC,QAAQ,EACRC,WAAW,KAAK,EAChB,GAAGC,WACJ,GAAGV;IAEJ,OAAOP,IACLI,eAAe,WAAW;QACxBS;QACAC;QACAC;QACAC;IACF,IACAf,SAAS;QACPO;QACAQ;QACA,GAAGC,SAAS;IACd;AAEJ;AAWA;;CAEC,GACD,OAAO,SAASC,cAAcX,OAAsC;IAClE,MAAM,EAAEY,UAAU,EAAEC,gBAAgB,EAAEZ,SAAS,EAAE,GAAGD;IAEpD,OAAOP,IACLoB,oBAAoBhB,eAAe,SAAS;QAAEiB,QAAQF;IAAW,IACjEX;AAEJ;AAOA;;CAEC,GACD,OAAO,SAASc,UAAUf,UAAqC,CAAC,CAAC;IAC/D,MAAM,EAAEC,SAAS,EAAE,GAAGD;IAEtB,OAAOP,IAAIK,mBAAmBG;AAChC"}
|
package/dist/tree/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/types.ts"],"sourcesContent":["import { type ReactNode } from \"react\";\n\nimport { type ListItemChildrenProps } from \"../list/types.js\";\nimport { type UseStateInitializer } from \"../types.js\";\nimport { type RenderRecursiveItemsProps } from \"../utils/RenderRecursively.js\";\n\n/**\n * @since 6.0.0 This was renamed from `TreeItemIds`\n */\nexport interface TreeItemNode {\n itemId: string;\n parentId: string | null;\n}\n\n/**\n * The default tree item node allows for any props for rendering children within\n * list items and rendering links.\n *\n * @since 6.0.0\n */\nexport interface DefaultTreeItemNode\n extends TreeItemNode
|
|
1
|
+
{"version":3,"sources":["../../src/tree/types.ts"],"sourcesContent":["import { type ReactNode } from \"react\";\n\nimport { type ListItemChildrenProps } from \"../list/types.js\";\nimport { type UseStateInitializer } from \"../types.js\";\nimport { type RenderRecursiveItemsProps } from \"../utils/RenderRecursively.js\";\n\n/**\n * @since 6.0.0 This was renamed from `TreeItemIds`\n */\nexport interface TreeItemNode {\n itemId: string;\n parentId: string | null;\n}\n\n/**\n * The default tree item node allows for any props for rendering children within\n * list items and rendering links.\n *\n * @since 6.0.0\n */\nexport interface DefaultTreeItemNode\n extends TreeItemNode, ListItemChildrenProps {\n /**\n * If this is defined, the `TreeItem` will render the content within a `Link`\n * instead of a `<span>`.\n */\n to?: string;\n\n /**\n * If this is defined, the `TreeItem` will render the content within a `Link`\n * instead of a `<span>`.\n */\n href?: string;\n\n /**\n * This should only be provided if {@link to} or {@link href} exist on the\n * node.\n */\n rel?: string;\n\n /**\n * This should only be provided if {@link to} or {@link href} exist on the\n * node.\n */\n target?: string;\n\n /**\n * An alias for the {@link children} within a tree item. This will be used\n * over the {@link children} if both exist.\n */\n name?: ReactNode;\n\n /**\n * The children to display in the tree item.\n *\n * @see {@link name}\n */\n children?: ReactNode;\n\n /** @see {@link ListItemProps.disabled} */\n disabled?: boolean;\n\n /** @see {@link ListItemProps.disabledOpacity} */\n disabledOpacity?: boolean;\n\n className?: string;\n contentClassName?: string;\n}\n\n/**\n * @example Default Structure\n * ```tsx\n * import { type TreeData } from \"@react-md/core/tree/types\";\n * import FolderIcon from \"@react-md/material-icons/FolderIcon\";\n *\n * export const MY_DATA: TreeData = {\n * \"item-1\": {\n * itemId: \"item-1\",\n * parentId: null,\n * name: \"Root Level Item 1\",\n * },\n * \"item-2\": {\n * itemId: \"item-2\",\n * parentId: \"item-1\",\n * name: \"A child for the first item\",\n * leftAddon: <FolderIcon />,\n * },\n * \"item-3\": {\n * itemId: \"item-3\",\n * parentId: \"item-1\",\n * children: \"Another child for the first item\",\n * leftAddon: <FolderIcon />,\n * rightAddon: <span>Something custom</span>,\n * },\n * };\n * ```\n *\n * @since 6.0.0 Updated the default types\n * @see {@link DefaultTreeItemNode}\n */\nexport type TreeData<T extends TreeItemNode = DefaultTreeItemNode> = Record<\n string,\n T\n>;\n\n/**\n * @since 6.0.0 This used to be `ExpandedIds`/`SelectedIds` but was converted to\n * a `Set` to increase performance for large trees.\n */\nexport type TreeItemIdSet = ReadonlySet<string>;\n\n/**\n * @since 6.0.0\n */\nexport type TreeDefaultIds = UseStateInitializer<\n readonly string[] | ReadonlySet<string>\n>;\n\n/**\n * A function to call that will sort the items within the tree for each unique\n * `parentId`. If you have a tree like:\n *\n * ```\n * a\n * ├── a1\n * b\n * ├── b1\n * ├── b2\n * │ └── b2.1\n * c\n * ├── c1\n * ├── c2\n * └── c3\n * ```\n *\n * This function will be called with:\n *\n * - `[a1]`\n * - `[b2.1]`\n * - `[b1, b2]`\n * - `[c1, c2, c3]`\n * - `[a, b, c]`\n *\n * Note: This **should be memoized** to prevent rerendering the entire tree each\n * render.\n */\nexport type TreeItemSorter<T extends TreeItemNode = DefaultTreeItemNode> = (\n items: readonly T[]\n) => readonly T[];\n\n/**\n * @since 6.0.0\n */\nexport type TreeItemRendererProps<\n T extends TreeItemNode = DefaultTreeItemNode,\n> = RenderRecursiveItemsProps<T, TreeData<T>>;\n"],"names":[],"mappings":"AAsJA;;CAEC,GACD,WAE8C"}
|