@react-md/core 1.0.0-next.16 → 1.0.0-next.18
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/_box-shadows.scss +76 -0
- package/dist/_colors.scss +279 -277
- package/dist/_core.scss +107 -16
- package/dist/_object-fit.scss +86 -0
- package/dist/_utils.scss +246 -72
- package/dist/app-bar/AppBar.d.ts +1 -90
- package/dist/app-bar/AppBar.js +1 -40
- package/dist/app-bar/AppBar.js.map +1 -1
- package/dist/app-bar/AppBarTitle.d.ts +1 -27
- package/dist/app-bar/AppBarTitle.js +1 -15
- package/dist/app-bar/AppBarTitle.js.map +1 -1
- package/dist/app-bar/_app-bar.scss +156 -25
- package/dist/app-bar/styles.d.ts +117 -0
- package/dist/app-bar/styles.js +55 -0
- package/dist/app-bar/styles.js.map +1 -0
- package/dist/autocomplete/Autocomplete.d.ts +8 -79
- package/dist/autocomplete/Autocomplete.js +112 -83
- package/dist/autocomplete/Autocomplete.js.map +1 -1
- package/dist/autocomplete/AutocompleteChip.d.ts +8 -0
- package/dist/autocomplete/AutocompleteChip.js +34 -0
- package/dist/autocomplete/AutocompleteChip.js.map +1 -0
- package/dist/autocomplete/AutocompleteCircularProgress.d.ts +5 -11
- package/dist/autocomplete/AutocompleteCircularProgress.js +4 -0
- package/dist/autocomplete/AutocompleteCircularProgress.js.map +1 -1
- package/dist/autocomplete/AutocompleteClearButton.d.ts +9 -0
- package/dist/autocomplete/AutocompleteClearButton.js +29 -0
- package/dist/autocomplete/AutocompleteClearButton.js.map +1 -0
- package/dist/autocomplete/AutocompleteDropdownButton.d.ts +4 -26
- package/dist/autocomplete/AutocompleteDropdownButton.js +5 -1
- package/dist/autocomplete/AutocompleteDropdownButton.js.map +1 -1
- package/dist/autocomplete/AutocompleteListboxChildren.d.ts +22 -0
- package/dist/autocomplete/AutocompleteListboxChildren.js +37 -0
- package/dist/autocomplete/AutocompleteListboxChildren.js.map +1 -0
- package/dist/autocomplete/_autocomplete.scss +362 -34
- package/dist/autocomplete/autocompleteStyles.d.ts +22 -0
- package/dist/autocomplete/autocompleteStyles.js +17 -8
- package/dist/autocomplete/autocompleteStyles.js.map +1 -1
- package/dist/autocomplete/defaults.d.ts +9 -9
- package/dist/autocomplete/defaults.js +13 -13
- package/dist/autocomplete/defaults.js.map +1 -1
- package/dist/autocomplete/types.d.ts +554 -56
- package/dist/autocomplete/types.js.map +1 -1
- package/dist/autocomplete/useAutocomplete.d.ts +22 -0
- package/dist/autocomplete/useAutocomplete.js +281 -0
- package/dist/autocomplete/useAutocomplete.js.map +1 -0
- package/dist/autocomplete/utils.d.ts +81 -0
- package/dist/autocomplete/utils.js +108 -0
- package/dist/autocomplete/utils.js.map +1 -0
- package/dist/avatar/_avatar.scss +93 -2
- package/dist/badge/Badge.d.ts +1 -20
- package/dist/badge/Badge.js +1 -14
- package/dist/badge/Badge.js.map +1 -1
- package/dist/badge/_badge.scss +90 -3
- package/dist/badge/styles.d.ts +26 -0
- package/dist/badge/styles.js +18 -0
- package/dist/badge/styles.js.map +1 -0
- package/dist/box/Box.js +2 -1
- package/dist/box/Box.js.map +1 -1
- package/dist/box/_box.scss +130 -17
- package/dist/box/styles.d.ts +6 -0
- package/dist/box/styles.js +2 -1
- package/dist/box/styles.js.map +1 -1
- package/dist/button/AsyncButton.d.ts +1 -1
- package/dist/button/AsyncButton.js.map +1 -1
- package/dist/button/Button.d.ts +2 -1
- package/dist/button/Button.js +2 -1
- package/dist/button/Button.js.map +1 -1
- package/dist/button/_button.scss +157 -25
- package/dist/card/Card.d.ts +16 -0
- package/dist/card/Card.js +11 -3
- package/dist/card/Card.js.map +1 -1
- package/dist/card/ClickableCard.d.ts +2 -1
- package/dist/card/ClickableCard.js +5 -2
- package/dist/card/ClickableCard.js.map +1 -1
- package/dist/card/_card.scss +90 -19
- package/dist/card/styles.d.ts +0 -7
- package/dist/card/styles.js +2 -3
- package/dist/card/styles.js.map +1 -1
- package/dist/chip/Chip.d.ts +2 -1
- package/dist/chip/Chip.js +2 -1
- package/dist/chip/Chip.js.map +1 -1
- package/dist/chip/_chip.scss +45 -22
- package/dist/chip/styles.d.ts +12 -10
- package/dist/chip/styles.js.map +1 -1
- package/dist/cssUtils.js.map +1 -1
- package/dist/delegateEvent.d.ts +2 -2
- package/dist/delegateEvent.js.map +1 -1
- package/dist/dialog/Dialog.d.ts +8 -21
- package/dist/dialog/Dialog.js +27 -27
- package/dist/dialog/Dialog.js.map +1 -1
- package/dist/dialog/FixedDialog.d.ts +1 -3
- package/dist/dialog/FixedDialog.js +0 -8
- package/dist/dialog/FixedDialog.js.map +1 -1
- package/dist/dialog/_dialog.scss +67 -13
- package/dist/dialog/styles.d.ts +56 -0
- package/dist/dialog/styles.js +29 -2
- package/dist/dialog/styles.js.map +1 -1
- package/dist/divider/Divider.d.ts +0 -11
- package/dist/divider/Divider.js.map +1 -1
- package/dist/divider/_divider.scss +7 -1
- package/dist/divider/styles.d.ts +11 -0
- package/dist/divider/styles.js.map +1 -1
- package/dist/draggable/useDraggable.d.ts +6 -6
- package/dist/draggable/useDraggable.js.map +1 -1
- package/dist/draggable/utils.d.ts +3 -3
- package/dist/draggable/utils.js.map +1 -1
- package/dist/expansion-panel/ExpansionPanel.d.ts +1 -1
- package/dist/expansion-panel/ExpansionPanel.js.map +1 -1
- package/dist/expansion-panel/_expansion-panel.scss +5 -1
- package/dist/expansion-panel/useExpansionPanels.js +12 -24
- package/dist/expansion-panel/useExpansionPanels.js.map +1 -1
- package/dist/{form → files}/FileInput.d.ts +3 -6
- package/dist/{form → files}/FileInput.js +3 -6
- package/dist/files/FileInput.js.map +1 -0
- package/dist/files/_files.scss +22 -0
- package/dist/files/styles.d.ts +5 -0
- package/dist/files/styles.js +7 -0
- package/dist/files/styles.js.map +1 -0
- package/dist/{form → files}/useFileUpload.d.ts +7 -9
- package/dist/{form → files}/useFileUpload.js +5 -7
- package/dist/files/useFileUpload.js.map +1 -0
- package/dist/files/utils.d.ts +169 -0
- package/dist/files/utils.js +114 -0
- package/dist/files/utils.js.map +1 -0
- package/dist/{form/fileUtils.d.ts → files/validation.d.ts} +11 -176
- package/dist/{form/fileUtils.js → files/validation.js} +10 -135
- package/dist/files/validation.js.map +1 -0
- package/dist/focus/useFocusContainer.d.ts +2 -2
- package/dist/focus/useFocusContainer.js.map +1 -1
- package/dist/focus/utils.js.map +1 -1
- package/dist/form/FormMessage.js.map +1 -1
- package/dist/form/FormMessageContainer.js +4 -2
- package/dist/form/FormMessageContainer.js.map +1 -1
- package/dist/form/InputToggle.d.ts +2 -1
- package/dist/form/InputToggle.js +2 -1
- package/dist/form/InputToggle.js.map +1 -1
- package/dist/form/InputToggleIcon.js.map +1 -1
- package/dist/form/Label.js +2 -2
- package/dist/form/Label.js.map +1 -1
- package/dist/form/Listbox.d.ts +24 -0
- package/dist/form/Listbox.js +46 -0
- package/dist/form/Listbox.js.map +1 -0
- package/dist/form/ListboxProvider.d.ts +21 -0
- package/dist/form/{useListboxProvider.js → ListboxProvider.js} +1 -1
- package/dist/form/ListboxProvider.js.map +1 -0
- package/dist/form/MenuItemTextField.js +1 -2
- package/dist/form/MenuItemTextField.js.map +1 -1
- package/dist/form/NativeSelect.js +7 -4
- package/dist/form/NativeSelect.js.map +1 -1
- package/dist/form/Option.d.ts +49 -10
- package/dist/form/Option.js +11 -9
- package/dist/form/Option.js.map +1 -1
- package/dist/form/Password.js.map +1 -1
- package/dist/form/Select.d.ts +2 -2
- package/dist/form/Select.js +81 -85
- package/dist/form/Select.js.map +1 -1
- package/dist/form/SelectedOption.js +2 -1
- package/dist/form/SelectedOption.js.map +1 -1
- package/dist/form/Slider.d.ts +4 -4
- package/dist/form/Slider.js +6 -2
- package/dist/form/Slider.js.map +1 -1
- package/dist/form/SliderThumb.d.ts +3 -3
- package/dist/form/SliderThumb.js.map +1 -1
- package/dist/form/SliderValueMarks.d.ts +2 -2
- package/dist/form/SliderValueMarks.js.map +1 -1
- package/dist/form/SliderValueTooltip.js.map +1 -1
- package/dist/form/TextArea.js +1 -2
- package/dist/form/TextArea.js.map +1 -1
- package/dist/form/TextField.js +1 -2
- package/dist/form/TextField.js.map +1 -1
- package/dist/form/TextFieldContainer.js +1 -2
- package/dist/form/TextFieldContainer.js.map +1 -1
- package/dist/form/_form.scss +193 -124
- package/dist/form/formMessageContainerStyles.d.ts +10 -0
- package/dist/form/formMessageContainerStyles.js +11 -0
- package/dist/form/formMessageContainerStyles.js.map +1 -0
- package/dist/form/inputToggleStyles.js.map +1 -1
- package/dist/form/optionStyles.d.ts +1 -0
- package/dist/form/optionStyles.js +2 -2
- package/dist/form/optionStyles.js.map +1 -1
- package/dist/form/selectUtils.js.map +1 -1
- package/dist/form/sliderUtils.d.ts +1 -1
- package/dist/form/sliderUtils.js.map +1 -1
- package/dist/form/textFieldContainerStyles.d.ts +0 -2
- package/dist/form/textFieldContainerStyles.js +1 -2
- package/dist/form/textFieldContainerStyles.js.map +1 -1
- package/dist/form/types.d.ts +3 -10
- package/dist/form/types.js.map +1 -1
- package/dist/form/useCheckboxGroup.d.ts +17 -17
- package/dist/form/useCheckboxGroup.js +9 -17
- package/dist/form/useCheckboxGroup.js.map +1 -1
- package/dist/form/useCombobox.d.ts +56 -21
- package/dist/form/useCombobox.js +19 -4
- package/dist/form/useCombobox.js.map +1 -1
- package/dist/form/useEditableCombobox.d.ts +24 -4
- package/dist/form/useEditableCombobox.js +5 -0
- package/dist/form/useEditableCombobox.js.map +1 -1
- package/dist/form/useNumberField.js.map +1 -1
- package/dist/form/useRadioGroup.d.ts +6 -6
- package/dist/form/useRadioGroup.js.map +1 -1
- package/dist/form/useResizingTextArea.js.map +1 -1
- package/dist/form/useSelectCombobox.d.ts +3 -4
- package/dist/form/useSelectCombobox.js.map +1 -1
- package/dist/form/useTextField.d.ts +1 -1
- package/dist/form/useTextField.js.map +1 -1
- package/dist/form/useTextFieldContainerAddons.js.map +1 -1
- package/dist/hoverMode/useHoverMode.d.ts +3 -3
- package/dist/hoverMode/useHoverMode.js.map +1 -1
- package/dist/hoverMode/useHoverModeProvider.d.ts +4 -4
- package/dist/hoverMode/useHoverModeProvider.js.map +1 -1
- package/dist/icon/FontIcon.d.ts +4 -2
- package/dist/icon/FontIcon.js.map +1 -1
- package/dist/icon/TextIconSpacing.d.ts +3 -1
- package/dist/icon/TextIconSpacing.js.map +1 -1
- package/dist/icon/_icon.scss +151 -2
- package/dist/icon/iconConfig.d.ts +10 -0
- package/dist/icon/iconConfig.js +7 -0
- package/dist/icon/iconConfig.js.map +1 -1
- package/dist/icon/materialConfig.js.map +1 -1
- package/dist/icon/styles.js.map +1 -1
- package/dist/interaction/UserInteractionModeProvider.d.ts +5 -5
- package/dist/interaction/UserInteractionModeProvider.js +12 -8
- package/dist/interaction/UserInteractionModeProvider.js.map +1 -1
- package/dist/interaction/types.d.ts +20 -2
- package/dist/interaction/types.js.map +1 -1
- package/dist/interaction/useElementInteraction.d.ts +7 -1
- package/dist/interaction/useElementInteraction.js +1 -2
- package/dist/interaction/useElementInteraction.js.map +1 -1
- package/dist/interaction/utils.d.ts +2 -2
- package/dist/interaction/utils.js +2 -2
- package/dist/interaction/utils.js.map +1 -1
- package/dist/layout/LayoutWindowSplitter.js.map +1 -1
- package/dist/layout/_layout.scss +23 -10
- package/dist/layout/useExpandableLayout.d.ts +3 -3
- package/dist/layout/useExpandableLayout.js.map +1 -1
- package/dist/layout/useLayoutAppBarHeight.d.ts +2 -3
- package/dist/layout/useLayoutAppBarHeight.js.map +1 -1
- package/dist/layout/useTemporaryLayout.d.ts +2 -2
- package/dist/layout/useTemporaryLayout.js.map +1 -1
- package/dist/link/SkipToMainContent.js.map +1 -1
- package/dist/list/ListItem.d.ts +2 -1
- package/dist/list/ListItem.js +2 -1
- package/dist/list/ListItem.js.map +1 -1
- package/dist/list/ListItemChildren.js.map +1 -1
- package/dist/list/ListItemLink.d.ts +2 -1
- package/dist/list/ListItemLink.js +2 -1
- package/dist/list/ListItemLink.js.map +1 -1
- package/dist/list/_list.scss +6 -5
- package/dist/media-queries/_media-queries.scss +12 -0
- package/dist/media-queries/appSize.js.map +1 -1
- package/dist/media-queries/useMediaQuery.js +3 -1
- package/dist/media-queries/useMediaQuery.js.map +1 -1
- package/dist/menu/DropdownMenu.js.map +1 -1
- package/dist/menu/Menu.d.ts +8 -3
- package/dist/menu/Menu.js +2 -1
- package/dist/menu/Menu.js.map +1 -1
- package/dist/menu/MenuItemButton.js +6 -2
- package/dist/menu/MenuItemButton.js.map +1 -1
- package/dist/menu/useContextMenu.d.ts +3 -3
- package/dist/menu/useContextMenu.js.map +1 -1
- package/dist/movement/types.d.ts +5 -5
- package/dist/movement/types.js.map +1 -1
- package/dist/navigation/CollapsibleNavGroup.d.ts +5 -3
- package/dist/navigation/CollapsibleNavGroup.js +3 -4
- package/dist/navigation/CollapsibleNavGroup.js.map +1 -1
- package/dist/navigation/DefaultNavigationRenderer.d.ts +1 -2
- package/dist/navigation/DefaultNavigationRenderer.js +6 -2
- package/dist/navigation/DefaultNavigationRenderer.js.map +1 -1
- package/dist/navigation/NavItemButton.d.ts +1 -1
- package/dist/navigation/NavItemButton.js +1 -0
- package/dist/navigation/NavItemButton.js.map +1 -1
- package/dist/navigation/NavItemLink.d.ts +3 -2
- package/dist/navigation/NavItemLink.js +6 -2
- package/dist/navigation/NavItemLink.js.map +1 -1
- package/dist/navigation/NavSubheader.d.ts +2 -3
- package/dist/navigation/NavSubheader.js.map +1 -1
- package/dist/navigation/Navigation.d.ts +1 -1
- package/dist/navigation/Navigation.js.map +1 -1
- package/dist/navigation/_navigation.scss +6 -5
- package/dist/navigation/types.d.ts +54 -6
- package/dist/navigation/types.js.map +1 -1
- package/dist/navigation/useActiveHeadingId.d.ts +1 -1
- package/dist/navigation/useActiveHeadingId.js.map +1 -1
- package/dist/navigation/useNavigationExpansion.d.ts +104 -0
- package/dist/navigation/useNavigationExpansion.js +77 -0
- package/dist/navigation/useNavigationExpansion.js.map +1 -0
- package/dist/navigation/utils.d.ts +13 -0
- package/dist/navigation/utils.js +36 -0
- package/dist/navigation/utils.js.map +1 -0
- package/dist/objectFit.d.ts +69 -0
- package/dist/objectFit.js +52 -0
- package/dist/objectFit.js.map +1 -0
- package/dist/overlay/_overlay.scss +2 -1
- package/dist/positioning/useFixedPositioning.d.ts +17 -4
- package/dist/positioning/useFixedPositioning.js +10 -5
- package/dist/positioning/useFixedPositioning.js.map +1 -1
- package/dist/positioning/utils.js.map +1 -1
- package/dist/progress/LinearProgress.js.map +1 -1
- package/dist/progress/_progress.scss +20 -14
- package/dist/responsive-item/ResponsiveItem.d.ts +64 -0
- package/dist/responsive-item/ResponsiveItem.js +68 -0
- package/dist/responsive-item/ResponsiveItem.js.map +1 -0
- package/dist/responsive-item/ResponsiveItemOverlay.d.ts +1 -19
- package/dist/responsive-item/ResponsiveItemOverlay.js +1 -12
- package/dist/responsive-item/ResponsiveItemOverlay.js.map +1 -1
- package/dist/responsive-item/_responsive-item.scss +110 -133
- package/dist/responsive-item/responsiveItemOverlayStyles.d.ts +19 -0
- package/dist/responsive-item/responsiveItemOverlayStyles.js +14 -0
- package/dist/responsive-item/responsiveItemOverlayStyles.js.map +1 -0
- package/dist/responsive-item/responsiveItemStyles.d.ts +52 -0
- package/dist/responsive-item/responsiveItemStyles.js +15 -0
- package/dist/responsive-item/responsiveItemStyles.js.map +1 -0
- package/dist/scroll/useScrollLock.d.ts +5 -0
- package/dist/scroll/useScrollLock.js.map +1 -1
- package/dist/searching/utils.d.ts +2 -2
- package/dist/searching/utils.js.map +1 -1
- package/dist/segmented-button/SegmentedButton.d.ts +2 -1
- package/dist/segmented-button/SegmentedButton.js +2 -1
- package/dist/segmented-button/SegmentedButton.js.map +1 -1
- package/dist/segmented-button/_segmented-button.scss +6 -6
- package/dist/sheet/_sheet.scss +18 -6
- package/dist/snackbar/ToastManager.js +15 -5
- package/dist/snackbar/ToastManager.js.map +1 -1
- package/dist/snackbar/_snackbar.scss +30 -17
- package/dist/snackbar/useCurrentToastActions.d.ts +5 -5
- package/dist/snackbar/useCurrentToastActions.js.map +1 -1
- package/dist/table/_table.scss +15 -3
- package/dist/table/tableCellStyles.d.ts +7 -3
- package/dist/table/tableCellStyles.js +2 -2
- package/dist/table/tableCellStyles.js.map +1 -1
- package/dist/tabs/Tab.d.ts +2 -1
- package/dist/tabs/Tab.js +2 -1
- package/dist/tabs/Tab.js.map +1 -1
- package/dist/tabs/TabList.d.ts +2 -2
- package/dist/tabs/TabList.js.map +1 -1
- package/dist/tabs/TabListScrollButton.d.ts +1 -1
- package/dist/tabs/TabListScrollButton.js +1 -1
- package/dist/tabs/TabListScrollButton.js.map +1 -1
- package/dist/tabs/_tabs.scss +30 -9
- package/dist/tabs/getTabListScrollToOptions.d.ts +18 -0
- package/dist/tabs/getTabListScrollToOptions.js +19 -0
- package/dist/tabs/getTabListScrollToOptions.js.map +1 -0
- package/dist/tabs/tabStyles.d.ts +3 -0
- package/dist/tabs/tabStyles.js.map +1 -1
- package/dist/tabs/useTabList.d.ts +1 -8
- package/dist/tabs/useTabList.js +1 -0
- package/dist/tabs/useTabList.js.map +1 -1
- package/dist/tabs/useTabs.d.ts +6 -6
- package/dist/tabs/useTabs.js.map +1 -1
- package/dist/tabs/utils.d.ts +0 -18
- package/dist/tabs/utils.js +0 -15
- package/dist/tabs/utils.js.map +1 -1
- package/dist/test-utils/ResizeObserver.d.ts +11 -12
- package/dist/test-utils/ResizeObserver.js +11 -12
- package/dist/test-utils/ResizeObserver.js.map +1 -1
- package/dist/test-utils/matchMedia.d.ts +3 -3
- package/dist/test-utils/matchMedia.js +6 -6
- package/dist/test-utils/matchMedia.js.map +1 -1
- package/dist/test-utils/polyfills/TextDecoder.js +0 -1
- package/dist/test-utils/polyfills/TextDecoder.js.map +1 -1
- package/dist/test-utils/timers.d.ts +9 -5
- package/dist/test-utils/timers.js +5 -5
- package/dist/test-utils/timers.js.map +1 -1
- package/dist/theme/LocalStorageColorSchemeProvider.d.ts +1 -1
- package/dist/theme/LocalStorageColorSchemeProvider.js +2 -1
- package/dist/theme/LocalStorageColorSchemeProvider.js.map +1 -1
- package/dist/theme/ThemeProvider.js +3 -1
- package/dist/theme/ThemeProvider.js.map +1 -1
- package/dist/theme/_a11y.scss +86 -13
- package/dist/theme/_colors.scss +279 -277
- package/dist/theme/_theme.scss +308 -37
- package/dist/theme/isColorScheme.d.ts +16 -0
- package/dist/theme/isColorScheme.js +19 -0
- package/dist/theme/isColorScheme.js.map +1 -0
- package/dist/theme/types.d.ts +53 -1
- package/dist/theme/types.js +1 -23
- package/dist/theme/types.js.map +1 -1
- package/dist/theme/useCSSVariables.d.ts +2 -19
- package/dist/theme/useCSSVariables.js.map +1 -1
- package/dist/theme/useColorScheme.d.ts +1 -35
- package/dist/theme/useColorScheme.js.map +1 -1
- package/dist/theme/useColorSchemeMetaTag.d.ts +1 -1
- package/dist/theme/useColorSchemeMetaTag.js.map +1 -1
- package/dist/theme/useColorSchemeProvider.d.ts +1 -1
- package/dist/theme/useColorSchemeProvider.js +1 -1
- package/dist/theme/useColorSchemeProvider.js.map +1 -1
- package/dist/theme/{usePrefersColorScheme.js → usePrefersDarkScheme.js} +1 -1
- package/dist/theme/usePrefersDarkScheme.js.map +1 -0
- package/dist/theme/utils.js.map +1 -1
- package/dist/tooltip/useTooltip.d.ts +14 -9
- package/dist/tooltip/useTooltip.js +2 -1
- package/dist/tooltip/useTooltip.js.map +1 -1
- package/dist/transition/_transition.scss +16 -9
- package/dist/transition/skeletonPlaceholderUtils.js.map +1 -1
- package/dist/transition/types.d.ts +1 -1
- package/dist/transition/types.js.map +1 -1
- package/dist/transition/useCarousel.d.ts +3 -3
- package/dist/transition/useCarousel.js.map +1 -1
- package/dist/transition/useCollapseTransition.js.map +1 -1
- package/dist/transition/useTransition.js +1 -0
- package/dist/transition/useTransition.js.map +1 -1
- package/dist/transition/utils.js.map +1 -1
- package/dist/tree/TreeItem.d.ts +2 -1
- package/dist/tree/TreeItem.js +4 -3
- package/dist/tree/TreeItem.js.map +1 -1
- package/dist/tree/TreeItemExpander.js.map +1 -1
- package/dist/tree/_tree.scss +8 -6
- package/dist/tree/useTreeExpansion.d.ts +1 -1
- package/dist/tree/useTreeExpansion.js +6 -18
- package/dist/tree/useTreeExpansion.js.map +1 -1
- package/dist/tree/useTreeSelection.d.ts +1 -1
- package/dist/tree/useTreeSelection.js +7 -25
- package/dist/tree/useTreeSelection.js.map +1 -1
- package/dist/tree/utils.d.ts +1 -1
- package/dist/tree/utils.js.map +1 -1
- package/dist/types.d.ts +12 -4
- package/dist/types.js.map +1 -1
- package/dist/typography/WritingDirectionProvider.d.ts +1 -1
- package/dist/typography/WritingDirectionProvider.js.map +1 -1
- package/dist/typography/_typography.scss +94 -37
- package/dist/typography/typographyStyles.js.map +1 -1
- package/dist/useDebouncedFunction.d.ts +1 -5
- package/dist/useDebouncedFunction.js +3 -1
- package/dist/useDebouncedFunction.js.map +1 -1
- package/dist/useDropzone.d.ts +4 -4
- package/dist/useDropzone.js.map +1 -1
- package/dist/useEnsuredId.js.map +1 -1
- package/dist/useIntersectionObserver.d.ts +5 -5
- package/dist/useIntersectionObserver.js.map +1 -1
- package/dist/useLocalStorage.d.ts +3 -3
- package/dist/useLocalStorage.js +1 -1
- package/dist/useLocalStorage.js.map +1 -1
- package/dist/useMutationObserver.d.ts +1 -1
- package/dist/useMutationObserver.js.map +1 -1
- package/dist/useOrientation.js +3 -1
- package/dist/useOrientation.js.map +1 -1
- package/dist/usePageInactive.d.ts +2 -2
- package/dist/usePageInactive.js.map +1 -1
- package/dist/useReadonlySet.d.ts +76 -0
- package/dist/useReadonlySet.js +72 -0
- package/dist/useReadonlySet.js.map +1 -0
- package/dist/useResizeListener.d.ts +1 -1
- package/dist/useResizeListener.js.map +1 -1
- package/dist/useResizeObserver.d.ts +19 -0
- package/dist/useResizeObserver.js +19 -0
- package/dist/useResizeObserver.js.map +1 -1
- package/dist/useThrottledFunction.d.ts +1 -5
- package/dist/useThrottledFunction.js +3 -1
- package/dist/useThrottledFunction.js.map +1 -1
- package/dist/useToggle.d.ts +3 -3
- package/dist/useToggle.js.map +1 -1
- package/dist/utils/RenderRecursively.d.ts +2 -2
- package/dist/utils/RenderRecursively.js.map +1 -1
- package/dist/utils/alphaNumericSort.d.ts +5 -5
- package/dist/utils/alphaNumericSort.js.map +1 -1
- package/dist/utils/bem.d.ts +1 -1
- package/dist/utils/bem.js +1 -1
- package/dist/utils/bem.js.map +1 -1
- package/dist/utils/debounce.d.ts +5 -0
- package/dist/utils/debounce.js +17 -0
- package/dist/utils/debounce.js.map +1 -0
- package/dist/utils/nearest.js.map +1 -1
- package/dist/utils/parseCssLengthUnit.js.map +1 -1
- package/dist/utils/throttle.d.ts +5 -0
- package/dist/utils/throttle.js +30 -0
- package/dist/utils/throttle.js.map +1 -0
- package/dist/utils/wait.js +3 -1
- package/dist/utils/wait.js.map +1 -1
- package/dist/window-splitter/WindowSplitter.d.ts +37 -15
- package/dist/window-splitter/WindowSplitter.js +38 -17
- package/dist/window-splitter/WindowSplitter.js.map +1 -1
- package/dist/window-splitter/_window-splitter.scss +32 -14
- package/dist/window-splitter/styles.d.ts +14 -0
- package/dist/window-splitter/styles.js +18 -0
- package/dist/window-splitter/styles.js.map +1 -0
- package/package.json +25 -24
- package/src/app-bar/AppBar.tsx +1 -170
- package/src/app-bar/AppBarTitle.tsx +1 -44
- package/src/app-bar/styles.ts +206 -0
- package/src/autocomplete/Autocomplete.tsx +194 -211
- package/src/autocomplete/AutocompleteChip.tsx +48 -0
- package/src/autocomplete/AutocompleteCircularProgress.tsx +6 -17
- package/src/autocomplete/AutocompleteClearButton.tsx +44 -0
- package/src/autocomplete/AutocompleteDropdownButton.tsx +16 -37
- package/src/autocomplete/AutocompleteListboxChildren.tsx +68 -0
- package/src/autocomplete/autocompleteStyles.ts +48 -9
- package/src/autocomplete/defaults.ts +26 -17
- package/src/autocomplete/types.ts +744 -61
- package/src/autocomplete/useAutocomplete.ts +428 -0
- package/src/autocomplete/utils.ts +211 -0
- package/src/badge/Badge.tsx +1 -39
- package/src/badge/styles.ts +45 -0
- package/src/box/Box.tsx +11 -9
- package/src/box/styles.ts +14 -5
- package/src/button/AsyncButton.tsx +1 -1
- package/src/button/Button.tsx +5 -1
- package/src/card/Card.tsx +35 -4
- package/src/card/ClickableCard.tsx +9 -2
- package/src/card/styles.ts +1 -10
- package/src/chip/Chip.tsx +6 -1
- package/src/chip/styles.ts +12 -10
- package/src/delegateEvent.ts +5 -5
- package/src/dialog/Dialog.tsx +48 -61
- package/src/dialog/FixedDialog.tsx +1 -11
- package/src/dialog/styles.ts +97 -0
- package/src/divider/Divider.tsx +0 -12
- package/src/divider/styles.ts +12 -0
- package/src/draggable/useDraggable.ts +17 -10
- package/src/draggable/utils.ts +3 -3
- package/src/expansion-panel/ExpansionPanel.tsx +1 -1
- package/src/expansion-panel/useExpansionPanels.ts +18 -27
- package/src/{form → files}/FileInput.tsx +7 -15
- package/src/files/styles.ts +10 -0
- package/src/{form → files}/useFileUpload.ts +30 -34
- package/src/files/utils.ts +234 -0
- package/src/{form/fileUtils.ts → files/validation.ts} +15 -244
- package/src/focus/useFocusContainer.ts +16 -8
- package/src/form/FormMessageContainer.tsx +2 -2
- package/src/form/InputToggle.tsx +5 -1
- package/src/form/Label.tsx +18 -18
- package/src/form/Listbox.tsx +87 -0
- package/src/form/ListboxProvider.ts +37 -0
- package/src/form/MenuItemTextField.tsx +1 -2
- package/src/form/NativeSelect.tsx +14 -10
- package/src/form/Option.tsx +74 -22
- package/src/form/Select.tsx +89 -85
- package/src/form/SelectedOption.tsx +2 -0
- package/src/form/Slider.tsx +14 -11
- package/src/form/SliderThumb.tsx +4 -4
- package/src/form/SliderValueMarks.tsx +4 -4
- package/src/form/TextArea.tsx +6 -8
- package/src/form/TextField.tsx +0 -2
- package/src/form/TextFieldContainer.tsx +9 -11
- package/src/form/formMessageContainerStyles.ts +22 -0
- package/src/form/optionStyles.ts +7 -2
- package/src/form/sliderUtils.ts +1 -1
- package/src/form/textFieldContainerStyles.ts +9 -14
- package/src/form/types.ts +3 -11
- package/src/form/useCheckboxGroup.ts +28 -36
- package/src/form/useCombobox.ts +86 -38
- package/src/form/useEditableCombobox.ts +43 -8
- package/src/form/useRadioGroup.ts +6 -6
- package/src/form/useSelectCombobox.ts +4 -4
- package/src/form/useTextField.ts +1 -1
- package/src/hoverMode/useHoverMode.ts +3 -3
- package/src/hoverMode/useHoverModeProvider.ts +4 -4
- package/src/icon/FontIcon.tsx +4 -2
- package/src/icon/TextIconSpacing.tsx +1 -1
- package/src/icon/iconConfig.tsx +12 -0
- package/src/interaction/UserInteractionModeProvider.tsx +12 -8
- package/src/interaction/types.ts +21 -2
- package/src/interaction/useElementInteraction.tsx +9 -2
- package/src/interaction/utils.ts +7 -7
- package/src/layout/useExpandableLayout.ts +3 -3
- package/src/layout/useLayoutAppBarHeight.ts +3 -4
- package/src/layout/useTemporaryLayout.ts +2 -2
- package/src/list/ListItem.tsx +5 -1
- package/src/list/ListItemLink.tsx +5 -1
- package/src/media-queries/useMediaQuery.ts +2 -1
- package/src/menu/Menu.tsx +11 -3
- package/src/menu/MenuItemButton.tsx +7 -1
- package/src/menu/useContextMenu.ts +3 -3
- package/src/movement/types.ts +5 -5
- package/src/navigation/CollapsibleNavGroup.tsx +16 -8
- package/src/navigation/DefaultNavigationRenderer.tsx +8 -6
- package/src/navigation/NavItemButton.tsx +2 -1
- package/src/navigation/NavItemLink.tsx +11 -3
- package/src/navigation/NavSubheader.tsx +1 -1
- package/src/navigation/Navigation.tsx +1 -1
- package/src/navigation/types.ts +60 -10
- package/src/navigation/useActiveHeadingId.ts +1 -1
- package/src/navigation/useNavigationExpansion.ts +170 -0
- package/src/navigation/utils.ts +47 -0
- package/src/objectFit.ts +88 -0
- package/src/positioning/useFixedPositioning.ts +34 -11
- package/src/responsive-item/ResponsiveItem.tsx +96 -0
- package/src/responsive-item/ResponsiveItemOverlay.tsx +6 -46
- package/src/responsive-item/responsiveItemOverlayStyles.ts +46 -0
- package/src/responsive-item/responsiveItemStyles.ts +81 -0
- package/src/scroll/useScrollLock.ts +6 -0
- package/src/searching/utils.ts +3 -3
- package/src/segmented-button/SegmentedButton.tsx +5 -1
- package/src/snackbar/ToastManager.tsx +16 -5
- package/src/snackbar/useCurrentToastActions.ts +5 -5
- package/src/table/tableCellStyles.ts +10 -6
- package/src/tabs/Tab.tsx +4 -1
- package/src/tabs/TabList.tsx +2 -2
- package/src/tabs/TabListScrollButton.tsx +4 -4
- package/src/tabs/getTabListScrollToOptions.ts +37 -0
- package/src/tabs/tabStyles.ts +4 -0
- package/src/tabs/useTabList.ts +2 -9
- package/src/tabs/useTabs.ts +6 -6
- package/src/tabs/utils.ts +0 -38
- package/src/test-utils/ResizeObserver.ts +11 -12
- package/src/test-utils/matchMedia.ts +7 -7
- package/src/test-utils/polyfills/TextDecoder.ts +0 -1
- package/src/test-utils/timers.ts +10 -7
- package/src/theme/LocalStorageColorSchemeProvider.tsx +4 -4
- package/src/theme/ThemeProvider.tsx +3 -3
- package/src/theme/isColorScheme.ts +22 -0
- package/src/theme/types.ts +67 -1
- package/src/theme/useCSSVariables.ts +7 -30
- package/src/theme/useColorScheme.ts +1 -40
- package/src/theme/useColorSchemeMetaTag.ts +1 -1
- package/src/theme/useColorSchemeProvider.ts +2 -2
- package/src/tooltip/useTooltip.ts +17 -9
- package/src/transition/types.ts +1 -1
- package/src/transition/useCarousel.ts +3 -3
- package/src/transition/useTransition.ts +1 -0
- package/src/tree/TreeItem.tsx +7 -1
- package/src/tree/TreeItemExpander.tsx +1 -1
- package/src/tree/useTreeExpansion.ts +7 -25
- package/src/tree/useTreeSelection.ts +8 -32
- package/src/tree/utils.ts +6 -2
- package/src/types.ts +20 -4
- package/src/typography/WritingDirectionProvider.tsx +1 -1
- package/src/useDebouncedFunction.ts +4 -9
- package/src/useDropzone.ts +4 -4
- package/src/useIntersectionObserver.ts +5 -5
- package/src/useLocalStorage.ts +6 -6
- package/src/useMutationObserver.ts +1 -1
- package/src/useOrientation.ts +3 -1
- package/src/usePageInactive.ts +2 -2
- package/src/useReadonlySet.ts +122 -0
- package/src/useResizeListener.ts +1 -1
- package/src/useResizeObserver.ts +19 -0
- package/src/useThrottledFunction.ts +6 -9
- package/src/useToggle.ts +3 -3
- package/src/utils/RenderRecursively.tsx +2 -2
- package/src/utils/alphaNumericSort.ts +5 -5
- package/src/utils/bem.ts +1 -1
- package/src/utils/debounce.ts +22 -0
- package/src/utils/throttle.ts +38 -0
- package/src/utils/wait.ts +5 -1
- package/src/window-splitter/WindowSplitter.tsx +38 -43
- package/src/window-splitter/styles.ts +42 -0
- package/dist/autocomplete/FilterAutocompleteOptions.d.ts +0 -8
- package/dist/autocomplete/FilterAutocompleteOptions.js +0 -57
- package/dist/autocomplete/FilterAutocompleteOptions.js.map +0 -1
- package/dist/dialog/DialogContainer.d.ts +0 -14
- package/dist/dialog/DialogContainer.js +0 -20
- package/dist/dialog/DialogContainer.js.map +0 -1
- package/dist/form/FileInput.js.map +0 -1
- package/dist/form/fileUtils.js.map +0 -1
- package/dist/form/useFileUpload.js.map +0 -1
- package/dist/form/useListboxProvider.d.ts +0 -31
- package/dist/form/useListboxProvider.js.map +0 -1
- package/dist/navigation/getHrefFromParents.d.ts +0 -5
- package/dist/navigation/getHrefFromParents.js +0 -13
- package/dist/navigation/getHrefFromParents.js.map +0 -1
- package/dist/responsive-item/ResponsiveItemContainer.d.ts +0 -115
- package/dist/responsive-item/ResponsiveItemContainer.js +0 -80
- package/dist/responsive-item/ResponsiveItemContainer.js.map +0 -1
- package/dist/responsive-item/styles.d.ts +0 -34
- package/dist/responsive-item/styles.js +0 -17
- package/dist/responsive-item/styles.js.map +0 -1
- package/dist/theme/usePrefersColorScheme.js.map +0 -1
- package/src/autocomplete/FilterAutocompleteOptions.tsx +0 -86
- package/src/dialog/DialogContainer.tsx +0 -28
- package/src/form/useListboxProvider.ts +0 -45
- package/src/navigation/getHrefFromParents.ts +0 -15
- package/src/responsive-item/ResponsiveItemContainer.tsx +0 -174
- package/src/responsive-item/styles.ts +0 -58
- /package/dist/theme/{usePrefersColorScheme.d.ts → usePrefersDarkScheme.d.ts} +0 -0
- /package/src/theme/{usePrefersColorScheme.ts → usePrefersDarkScheme.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/autocomplete/types.ts"],"sourcesContent":["import { type ReactNode } from \"react\";\nimport { type MenuItemProps } from \"../menu/MenuItem.jsx\";\nimport {\n type BaseSearchOptions,\n type WhitespaceFilter,\n} from \"../searching/types.js\";\nimport { type RequireAtLeastOne, type TextExtractor } from \"../types.js\";\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteMenuLabel<\n T extends { menuLabel?: string; menuLabelledBy?: string },\n> = RequireAtLeastOne<T, \"menuLabel\" | \"menuLabelledBy\">;\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteFilterOptions<T> = Pick<\n Required<BaseSearchOptions<T>>,\n \"list\" | \"query\" | \"extractor\" | \"whitespace\"\n>;\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteGetOptionPropsOptions<T> {\n index: number;\n option: T;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteOptionsProps<T> {\n /**\n * This list of options to display and will be filtered based on the current\n * value in the text box unless {@link disableFilter} is `true`.\n *\n * When this is not a list of strings or a list of objects with a\n * `{ label: string }`, the {@link extractor} is required to pull a searchable\n * string from each option.\n */\n options: readonly T[];\n\n /**\n * This controls how the {@link options} are filtered based on the current\n * value in the text box.\n *\n * @example Fuzzy Search\n * ```tsx\n * import { fuzzySearch } from \"@react-md/core/searching/fuzzy\";\n *\n * <Autocomplete\n * {...props}\n * filter={fuzzySearch}\n * />\n * ```\n *\n * @defaultValue `caseInsensitiveSearch`\n */\n filter?(options: AutocompleteFilterOptions<T>): readonly T[];\n\n /**\n * @example\n * ```tsx\n * <Autocomplete\n * options={[{ children: \"Apple\" }, { children = \"Banana\" }]}\n * extractor={(option) => option.children}\n * {...props}\n * />\n * ```\n */\n extractor?: TextExtractor<T>;\n\n /**\n * This can be used to add additional props to each option.\n *\n * @example Simple Example\n * ```tsx\n * getOptionProps={({ option }) => {\n * return {\n * disabled: option === \"\",\n * className: cnb(option === \"a\" && styles.blue),\n * leftAddon: option === value && <CheckIcon />,\n * };\n * }}\n * ```\n */\n getOptionProps?(\n options: AutocompleteGetOptionPropsOptions<T>\n ): Partial<MenuItemProps> | undefined;\n\n /**\n * The children to display when there are no {@link options} due to the\n * current text box value.\n *\n * @defaultValue `<ListSubheader>No options</ListSubheader`\n */\n noOptionsChildren?: ReactNode;\n\n /**\n * This will be called whenever one of the options are selected or reset.\n */\n onAutocomplete?(option: T | null): void;\n\n /**\n * @defaultValue `false`\n */\n clearOnAutocomplete?: boolean;\n\n /**\n * Set this to `true` to disable the built-in filtering of the\n * {@link options}. This will always be `true` if `aria-autocomplete=\"none\"`.\n *\n * @defaultValue `false`\n */\n disableFilter?: boolean;\n\n /** @defaultValue `\"keep\"` */\n whitespace?: WhitespaceFilter;\n}\n"],"names":[],"mappings":"AA+BA;;CAEC,GACD,WAuFC"}
|
|
1
|
+
{"version":3,"sources":["../../src/autocomplete/types.ts"],"sourcesContent":["import {\n type AriaAttributes,\n type ChangeEventHandler,\n type Dispatch,\n type FocusEventHandler,\n type MouseEventHandler,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { type ButtonProps } from \"../button/Button.js\";\nimport { type ChipProps } from \"../chip/Chip.js\";\nimport {\n type OptionProps,\n type OptionSelectedIconProps,\n} from \"../form/Option.js\";\nimport { type TextFieldProps } from \"../form/TextField.js\";\nimport {\n type ComboboxMenuProps,\n type ComboboxVisibilityOptions,\n type ConfigurableComboboxMenuProps,\n} from \"../form/useCombobox.js\";\nimport {\n type EditableComboboxImplementation,\n type EditableComboboxOptions,\n type EditableComboboxWidgetProps,\n} from \"../form/useEditableCombobox.js\";\nimport { type EditableHTMLElement } from \"../form/utils.js\";\nimport { type IconRotatorProps } from \"../icon/IconRotator.js\";\nimport { type CircularProgressProps } from \"../progress/CircularProgress.js\";\nimport { type ProgressTheme } from \"../progress/types.js\";\nimport { type BaseSearchOptions } from \"../searching/types.js\";\nimport {\n type PropsWithRef,\n type TextExtractor,\n type UseStateInitializer,\n} from \"../types.js\";\n\n/**\n * If a autocomplete value is one of these types, no additional code is required\n * to display a label in the input/chip for the autocomplete once the value has\n * been selected.\n *\n * - `\"some value\"` -> `\"some value\"`\n * - `{ label: \"Hello, world\", value: 300 }` -> `\"Hello, world!\"`\n *\n * @since 6.0.0\n */\nexport type AutocompleteLabeledOption = string | { label: string };\n\n/**\n * @since 6.0.0\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type AutocompleteOption = AutocompleteLabeledOption | {};\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteFilterOptions<Option extends AutocompleteOption> = Pick<\n Required<BaseSearchOptions<Option>>,\n \"list\" | \"query\" | \"extractor\"\n>;\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteFilterFunction<Option extends AutocompleteOption> = (\n options: AutocompleteFilterOptions<Option>\n) => readonly Option[];\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteGetOptionPropsOptions<\n Option extends AutocompleteOption,\n> {\n index: number;\n query: string;\n option: Option;\n selected: boolean;\n extractor: TextExtractor<Option>;\n}\n\n/**\n * This can be used to add additional props to each option.\n *\n * @example Simple Example\n * ```tsx\n * getOptionProps={({ option }) => {\n * return {\n * disabled: option === \"\",\n * className: cnb(option === \"a\" && styles.blue),\n * leftAddon: option === value && <CheckIcon />,\n * };\n * }}\n * ```\n * @since 6.0.0\n */\nexport type AutocompleteGetOptionProps<Option extends AutocompleteOption> = (\n options: AutocompleteGetOptionPropsOptions<Option>\n) => ConfigurableAutocompleteOptionProps | undefined;\n\n/**\n * This can be used to add additional props to each inline chip for multiselect\n * autocompletes.\n *\n * @example Simple Example\n * ```tsx\n * getChipProps={({ option, index }) => {\n * return {\n * disabled: index < 3,\n * className: cnb(option === \"a\" && styles.blue)<\n * };\n * }}\n * ```\n * @since 6.0.0\n */\nexport type AutocompleteGetChipProps<Option extends AutocompleteOption> = (\n options: Omit<AutocompleteGetOptionPropsOptions<Option>, \"selected\">\n) => Partial<AutocompleteChipProps> | undefined;\n\n/**\n * If the list of options contain an object that doesn't have a\n * `label: string`, this prop must be provided to extract a string to display\n * in the text field once selected.\n *\n * @example No Getter Required\n * ```tsx\n * const options1 = ['a', 'b', 'c', 'd'];\n * const options2 = [{ label: 'a' }, { label: 'b' }, { label: 'c' }, { label: 'd' }];\n *\n * <Autocomplete options={options1} />\n * <Autocomplete options={options2} />\n * ```\n *\n * @example Getter Required\n * ```tsx\n * const options = [\n * {\n * name: \"Alaska\",\n * abbr: \"AK\",\n * },\n * {\n * name: \"Arizona\",\n * abbr: \"AZ\",\n * }\n * ];\n *\n * <Autocomplete options={options} getOptionLabel={(state) => state.name} />\n * ```\n *\n * @defaultValue `defaultAutocompleteExtractor`\n * @since 6.0.0\n */\nexport type AutocompleteGetOptionLabel<Option extends AutocompleteOption> = (\n option: Option\n) => string;\n\n/**\n * @since 6.0.0\n */\nexport type ConfigurableAutocompleteOptionProps = Partial<\n Omit<OptionProps, \"role\" | \"value\">\n>;\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteControlledValue<T> {\n value: T;\n setValue: Dispatch<T>;\n defaultValue?: never;\n onValueChange?: never;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteUncontrolledValue<T> {\n value?: never;\n setValue?: never;\n defaultValue?: UseStateInitializer<T>;\n\n /**\n * This prop should be used when some action should occur whenever the value\n * changes, but is not required to be stored in state. For all other cases, it\n * is recommended to control the `value` instead of using this prop.\n *\n * @defaultValue `() => {}`\n */\n onValueChange?: (value: T) => void;\n}\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteValue<T> =\n | AutocompleteControlledValue<T>\n | AutocompleteUncontrolledValue<T>;\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteControlledQuery {\n query: string;\n setQuery: Dispatch<string>;\n defaultQuery?: never;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteUncontrolledQuery {\n query?: never;\n setQuery?: never;\n defaultQuery?: UseStateInitializer<string>;\n}\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteQuery =\n | AutocompleteControlledQuery\n | AutocompleteUncontrolledQuery;\n\n/**\n * This allows the `query` to be updated whenever a new value has been selected.\n *\n * - `\"clear\"` - clears the `query`\n * - `\"selected\"` - sets the \tquery\t to the selected value's label\n * - `\"as-is\"` - doesn't change the `query`\n *\n * @defaultValue `(multiselect || Array.isArray(value ?? defaultValue)) ? \"clear\" : \"as-is\"`\n * @since 6.0.0\n */\nexport type AutocompleteUpdateQueryOnSelect = \"clear\" | \"selected\" | \"as-is\";\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteUnknownQueryAndValueOptions<\n Option extends AutocompleteOption,\n> {\n query?: string;\n setQuery?: Dispatch<string>;\n defaultQuery?: UseStateInitializer<string>;\n value?: Option | null | readonly Option[];\n setValue?: Dispatch<Option | null | readonly Option[]>;\n defaultValue?: UseStateInitializer<Option | null | readonly Option[]>;\n onValueChange?: (value: Option | null | readonly Option[]) => void;\n}\n\n/**\n * A utility type that makes the `getOptionLabel` required when an option is not\n * a {@link AutocompleteLabeledOption}.\n *\n * @since 6.0.0\n */\nexport type AutocompleteOptionLabelExtractor<\n Option extends AutocompleteOption,\n> = Option extends AutocompleteLabeledOption\n ? { getOptionLabel?: AutocompleteGetOptionLabel<Option> }\n : { getOptionLabel: AutocompleteGetOptionLabel<Option> };\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteFilteringOptions<\n Option extends AutocompleteOption,\n> {\n /**\n * The list of options that can be shown within the autocomplete and filtered\n * based on the current query.\n */\n options: readonly Option[];\n\n /** @see {@link AutocompleteGetOptionLabel} */\n getOptionLabel?: AutocompleteGetOptionLabel<Option>;\n\n /**\n * The function that filters the {@link options} based on the current query\n * and defaults to a case insensitive search that starts with the query.\n *\n * @example Case Insensitive Anywhere\n * ```tsx\n * import { caseInsensitiveSearch } from \"@react-md/core/searching/caseInsensitive\";\n *\n * <Autocomplete {...props} filter={caseInsensitiveSearch} />\n * ```\n *\n * @example Fuzzy Filtering\n * ```tsx\n * import { fuzzySearch } from \"@react-md/core/searching/fuzzy\";\n *\n * <Autocomplete {...props} filter={fuzzySearch} />\n * ```\n *\n * @example Async Searching\n * ```tsx\n * import { useDebouncedFunction } from \"@react-md/core/useDebouncedFunction\";\n * import { useState } from \"react\";\n *\n * interface State {\n * loading: boolean;\n * options: readonly string[];\n * }\n *\n * function Example() {\n * const [state, setState] = useState<State>({\n * loading: false,\n * options: [],\n * });\n *\n * const search = useDebouncedFunction(async (query: string) => {\n * setState(prev => ({ ...prev, loading: true }));\n *\n * const options = await someAsyncTask(query);\n * setState({ loading: false, options })\n * });\n *\n * return (\n * <Autocomplete\n * {...props}\n * // Setting `type=\"search\"` automatically updates the `filter` prop to\n * // be `noopAutocompleteFilter`\n * type=\"search\"\n * options={options}\n * onChange={(event) => search(event.currentTarget.value)}\n * />\n * );\n * }\n * ```\n *\n * @defaultValue `defaultAutocompleteFilter`\n */\n filter?: AutocompleteFilterFunction<Option>;\n\n /**\n * Set this to `true` to update the filtering behavior to also remove the\n * selected value from the available options. This is mostly for the\n * multiselect behavior.\n *\n * @defaultValue `false`\n */\n filterSelected?: boolean;\n\n /**\n * Set this to `true` to allow any value to be typed into the autocomplete\n * instead of enforcing an empty string or one of the option labels.\n *\n * @defaultValue `filter === noopAutocompleteFilter`\n */\n allowAnyValue?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteFilterAndListboxOptions<\n Option extends AutocompleteOption,\n> extends AutocompleteFilteringOptions<Option>,\n OptionSelectedIconProps {\n /**\n * Set this to `true` when using a multiselect autocomplete to update each\n * option to use checkboxes to show the selection state.\n *\n * @defaultValue `false`\n */\n checkboxes?: boolean;\n\n /**\n * @see {@link OptionSelectedIconProps.disableSelectedIcon}\n * @defaultValue `!checkboxes`\n */\n disableSelectedIcon?: boolean;\n\n /**\n * @see {@link AutocompleteUpdateQueryOnSelect}\n * @defaultValue `multiselect ? \"clear\" : \"as-is\"`\n */\n updateQueryOnSelect?: AutocompleteUpdateQueryOnSelect;\n\n /**\n * Set this to `true` to prevent the listbox from closing when an option is\n * selected.\n *\n * @defaultValue `checkboxes`\n */\n disableCloseOnSelect?: boolean;\n\n /** @see {@link AutocompleteGetOptionProps} */\n getOptionProps?: AutocompleteGetOptionProps<Option>;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteEditableComboboxOptions<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n> extends EditableComboboxOptions<ComboboxEl, PopupEl>,\n AutocompleteFilterAndListboxOptions<Option> {\n onBlur?: FocusEventHandler<ComboboxEl>;\n onChange?: ChangeEventHandler<ComboboxEl>;\n\n /**\n * This is a convenience prop for the `onEntering`/`onEntered` transition\n * callbacks that will ensure it is only called once even if the transitions\n * are disabled. A great use-case for this function is to fetch data once the\n * menu is opened.\n */\n onOpen?: () => void;\n}\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteQueryAndExtractorOptions<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n> = AutocompleteEditableComboboxOptions<Option, ComboboxEl, PopupEl> &\n AutocompleteOptionLabelExtractor<Option> &\n AutocompleteQuery;\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteSingleSelectOptions<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n> = AutocompleteQueryAndExtractorOptions<Option, ComboboxEl, PopupEl> &\n AutocompleteValue<Option | null>;\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteMultiSelectOptions<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n> = AutocompleteQueryAndExtractorOptions<Option, ComboboxEl, PopupEl> &\n AutocompleteValue<readonly Option[]>;\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteOptions<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n> extends AutocompleteEditableComboboxOptions<Option, ComboboxEl, PopupEl>,\n AutocompleteUnknownQueryAndValueOptions<Option> {}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteComboboxProps<\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n> extends EditableComboboxWidgetProps<ComboboxEl> {\n \"aria-autocomplete\": NonNullable<AriaAttributes[\"aria-autocomplete\"]>;\n value: string;\n onBlur: FocusEventHandler<ComboboxEl>;\n onChange: ChangeEventHandler<ComboboxEl>;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteListboxProps<\n T extends AutocompleteOption = AutocompleteOption,\n PopupEl extends HTMLElement = HTMLElement,\n> extends Omit<ComboboxMenuProps<PopupEl>, \"ref\">,\n OptionSelectedIconProps {\n value: T | null | readonly T[];\n setValue: Dispatch<T>;\n onEnter: (appearing: boolean) => void;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface ConfigurableAutocompleteListboxProps\n extends ConfigurableComboboxMenuProps,\n OptionSelectedIconProps {\n id?: string;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface ConfigurableAutocompleteClearButtonProps extends ButtonProps {\n /** @defaultValue `\"Clear\"` */\n \"aria-label\"?: string;\n\n /** @defaultValue `\"autocomplete-clear-\" + useId()` */\n id?: string;\n}\n\n/**\n * @internal\n * @since 6.0.0\n */\nexport interface AutocompleteClearButtonProps\n extends ConfigurableAutocompleteClearButtonProps {\n onClick: MouseEventHandler<HTMLButtonElement>;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface ConfigurableAutocompleteDropdownButtonProps\n extends ButtonProps {\n /** @defaultValue `AutocompleteProps.listboxLabel` */\n \"aria-label\"?: string;\n /** @defaultValue `AutocompleteProps.listboxLabelledby` */\n \"aria-labelledby\"?: string;\n\n /** @defaultValue `\"autocomplete-dropdown-\" + useId()` */\n id?: string;\n\n /** @defaultValue `getIcon(\"dropdown\")` */\n icon?: ReactNode;\n iconRotatorProps?: Omit<IconRotatorProps, \"rotated\">;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteDropdownButtonProps\n extends ConfigurableAutocompleteDropdownButtonProps {\n \"aria-controls\": string;\n onClick: MouseEventHandler<HTMLButtonElement>;\n visible: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteCircularProgressProps\n extends CircularProgressProps {\n /** @defaultValue `\"Loading\"` */\n \"aria-label\"?: string;\n\n /** @defaultValue `\"current-color\"` */\n theme?: ProgressTheme;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteChipProps extends ChipProps {\n /**\n * @defaultValue `typeof children === \"string\" && \\`Remove \"${children}\"\\`\n */\n \"aria-description\"?: string;\n\n /** @defaultValue `getIcon(\"remove\")` */\n removeIcon?: ReactNode;\n children: ReactNode;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteWithQueryImplementation<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n> extends EditableComboboxImplementation<ComboboxEl, PopupEl> {\n query: string;\n setQuery: Dispatch<string>;\n comboboxProps: AutocompleteComboboxProps<ComboboxEl>;\n\n /**\n * This is a convenience prop to determine if the autocomplete supports\n * multiselect.\n */\n multiselect: boolean;\n\n /**\n * This is the current list of options that will be filtered based on the\n * current `query`. This should normally be rendered in the\n * `AutocompleteListboxChildren` component\n */\n availableOptions: readonly Option[];\n\n /**\n * Generates the props required for the `Listbox` component and should\n * normally be provided any menu props that might override the default display\n * settings.\n */\n getListboxProps: (\n overrides?: ConfigurableAutocompleteListboxProps\n ) => AutocompleteListboxProps<Option, PopupEl>;\n\n /**\n * Generates the props required for the `AutocompleteClearButton`.\n */\n getClearButtonProps: (\n overrides?: ConfigurableAutocompleteClearButtonProps\n ) => AutocompleteClearButtonProps;\n\n /**\n * Generates the props required for the `AutocompleteDropdownButton`.\n */\n getDropdownButtonProps: (\n overrides?: ConfigurableAutocompleteDropdownButtonProps\n ) => AutocompleteDropdownButtonProps;\n\n /** @see {@link AutocompleteGetOptionLabel} */\n getOptionLabel: AutocompleteGetOptionLabel<Option>;\n /** @see {@link AutocompleteGetOptionProps} */\n getOptionProps: AutocompleteGetOptionProps<Option>;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteSingleSelectImplementation<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n> extends AutocompleteWithQueryImplementation<Option, ComboboxEl, PopupEl> {\n value: Option | null;\n setValue: Dispatch<Option | null>;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteMultiSelectImplementation<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n> extends AutocompleteWithQueryImplementation<Option, ComboboxEl, PopupEl> {\n value: readonly Option[];\n setValue: Dispatch<readonly Option[]>;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteImplementation<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n> extends AutocompleteWithQueryImplementation<Option, ComboboxEl, PopupEl> {\n value: Option | null | readonly Option[];\n setValue: Dispatch<Option | null | readonly Option[]>;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface AutocompleteBaseProps<Option extends AutocompleteOption>\n extends Omit<TextFieldProps, \"value\" | \"defaultValue\">,\n AutocompleteFilterAndListboxOptions<Option>,\n ComboboxVisibilityOptions {\n inputRef?: Ref<HTMLInputElement>;\n\n /**\n * An `aria-label` to pass to the `Listbox` component that describes the list\n * of {@link options}. Either this or the {@link listboxLabelledBy} are\n * required for accessibility.\n */\n listboxLabel?: string;\n\n /**\n * An `aria-labelledby` to pass to the `Listbox` component that describes the\n * list of {@link options}. Either this or the {@link listboxLabel} are\n * required for accessibility.\n */\n listboxLabelledBy?: string;\n\n /**\n * Any additional props that should be passed to the `Listbox` component.\n */\n listboxProps?: PropsWithRef<\n ConfigurableAutocompleteListboxProps,\n HTMLDivElement\n >;\n\n /** @see {@link AutocompleteGetOptionProps} */\n getOptionProps?: AutocompleteGetOptionProps<Option>;\n\n /**\n * This can be used to add any custom styling, change the icon, change the\n * label, etc for the dropdown button.\n *\n * @example Simple Example\n * ```tsx\n * dropdownButtonProps={{\n * \"aria-label\": \"Open\",\n * className: styles.dropdownButton,\n * icon: <MyCustomDropdownIcon />,\n * }}\n * ```\n */\n dropdownButtonProps?: ConfigurableAutocompleteDropdownButtonProps;\n\n /**\n * Set this to `true` to remove the {@link DropdownButton} from being rendered\n * after the input element.\n *\n * @defaultValue `false`\n */\n disableDropdownButton?: boolean;\n\n /**\n * Set this to `true` to disable a `<CircularProgress />` after the input and\n * before the `<DropdownButton />`.\n *\n * @defaultValue `false`\n */\n loading?: boolean;\n\n /**\n * @defaultValue `{ \"aria-label\": \"Loading\", ...loadingProps }`\n */\n loadingProps?: AutocompleteCircularProgressProps;\n\n clearButtonProps?: PropsWithRef<\n ConfigurableAutocompleteClearButtonProps,\n HTMLButtonElement\n >;\n\n /**\n * @defaultValue `false`\n */\n disableClearButton?: boolean;\n\n /**\n * This is a convenience prop for the `onEntering`/`onEntered` transition\n * callbacks that will ensure it is only called once even if the transitions\n * are disabled. A great use-case for this function is to fetch data once the\n * menu is opened.\n */\n onOpen?: () => void;\n\n /**\n * The children to display when there are no {@link options} due to the\n * current text box value.\n *\n * @defaultValue `<ListSubheader>No options</ListSubheader`\n */\n noOptionsChildren?: ReactNode;\n\n /**\n * Set this to `true` when using a multiselect autocomplete to prevent the\n * selected values from being rendered inline with the input. This is useful\n * when the selected values should be shown in a different part of the UI\n * instead.\n *\n * @defaultValue `false`\n */\n disableInlineChips?: boolean;\n\n /** @see {@link AutocompleteGetChipProps} */\n getChipProps?: AutocompleteGetChipProps<Option>;\n}\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteListboxLabelProps =\n | { listboxLabel: string }\n | { listboxLabelledBy: string };\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteQueryAndExtractorProps<\n Option extends AutocompleteOption,\n> = AutocompleteBaseProps<Option> &\n AutocompleteOptionLabelExtractor<Option> &\n AutocompleteQuery &\n AutocompleteListboxLabelProps;\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteSingleSelectProps<Option extends AutocompleteOption> =\n AutocompleteQueryAndExtractorProps<Option> &\n AutocompleteValue<Option | null> & {\n checkboxes?: never;\n getChipProps?: never;\n disableInlineChips?: never;\n };\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteMultiSelectProps<Option extends AutocompleteOption> =\n AutocompleteQueryAndExtractorProps<Option> &\n AutocompleteValue<readonly Option[]>;\n\n/**\n * @since 6.0.0\n */\nexport type AutocompleteProps<Option extends AutocompleteOption> =\n AutocompleteBaseProps<Option> &\n AutocompleteUnknownQueryAndValueOptions<Option>;\n"],"names":[],"mappings":"AA+xBA;;CAEC,GACD,WAEoD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type EditableHTMLElement } from "../form/utils.js";
|
|
2
|
+
import { type AutocompleteImplementation, type AutocompleteMultiSelectImplementation, type AutocompleteMultiSelectOptions, type AutocompleteOption, type AutocompleteOptions, type AutocompleteSingleSelectImplementation, type AutocompleteSingleSelectOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* This is the single select autocomplete implementation.
|
|
5
|
+
*
|
|
6
|
+
* @since 6.0.0
|
|
7
|
+
*/
|
|
8
|
+
export declare function useAutocomplete<Option extends AutocompleteOption, ComboboxEl extends EditableHTMLElement = HTMLInputElement, PopupEl extends HTMLElement = HTMLElement>(options: AutocompleteSingleSelectOptions<Option, ComboboxEl, PopupEl>): AutocompleteSingleSelectImplementation<Option, ComboboxEl, PopupEl>;
|
|
9
|
+
/**
|
|
10
|
+
* This is the multiselect autocomplete implementation.
|
|
11
|
+
*
|
|
12
|
+
* @since 6.0.0
|
|
13
|
+
*/
|
|
14
|
+
export declare function useAutocomplete<Option extends AutocompleteOption, ComboboxEl extends EditableHTMLElement = HTMLInputElement, PopupEl extends HTMLElement = HTMLElement>(options: AutocompleteMultiSelectOptions<Option, ComboboxEl, PopupEl>): AutocompleteMultiSelectImplementation<Option, ComboboxEl, PopupEl>;
|
|
15
|
+
/**
|
|
16
|
+
* This is an internal override implementation where the types are less strict
|
|
17
|
+
* so it can be used with the `Autocomplete` component.
|
|
18
|
+
*
|
|
19
|
+
* @since 6.0.0
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare function useAutocomplete<Option extends AutocompleteOption, ComboboxEl extends EditableHTMLElement = HTMLInputElement, PopupEl extends HTMLElement = HTMLElement>(options: AutocompleteOptions<Option, ComboboxEl, PopupEl>): AutocompleteImplementation<Option, ComboboxEl, PopupEl>;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
3
|
+
import { useEditableCombobox } from "../form/useEditableCombobox.js";
|
|
4
|
+
import { triggerManualChangeEvent } from "../form/utils.js";
|
|
5
|
+
import { getIcon } from "../icon/iconConfig.js";
|
|
6
|
+
import { useUserInteractionMode } from "../interaction/UserInteractionModeProvider.js";
|
|
7
|
+
import { TRANSITION_CONFIG } from "../transition/config.js";
|
|
8
|
+
import { useEnsuredState } from "../useEnsuredState.js";
|
|
9
|
+
import { defaultAutocompleteExtractor, defaultAutocompleteFilter, defaultAutocompleteGetOptionProps, noopAutocompleteFilter } from "./defaults.js";
|
|
10
|
+
import { enforceSelectedValue, getDefaultQuery, getDefaultValue, isMultipleValues } from "./utils.js";
|
|
11
|
+
const noop = ()=>{
|
|
12
|
+
// do nothing
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @since 6.0.0
|
|
16
|
+
* @internal
|
|
17
|
+
*/ export function useAutocomplete(options) {
|
|
18
|
+
const { value: propValue, setValue: propSetValue, defaultValue, onValueChange = noop, query: propQuery, setQuery: propSetQuery, defaultQuery, options: values, getOptionLabel = defaultAutocompleteExtractor, getOptionProps = defaultAutocompleteGetOptionProps, onBlur = noop, onChange = noop, onOpen = noop, filter = defaultAutocompleteFilter, filterSelected, allowAnyValue = filter === noopAutocompleteFilter, multiselect: propMultiselect, checkboxes, selectedIcon: propSelectedIcon, unselectedIcon: propUnselectedIcon, selectedIconAfter, disableSelectedIcon: propDisableSelectedIcon, updateQueryOnSelect: propUpdateQueryOnSelect, disableCloseOnSelect: propDisableCloseOnSelect, ...comboboxOptions } = options;
|
|
19
|
+
const mode = useUserInteractionMode();
|
|
20
|
+
const [value, setValueState] = useEnsuredState({
|
|
21
|
+
value: propValue,
|
|
22
|
+
setValue: propSetValue,
|
|
23
|
+
defaultValue: getDefaultValue({
|
|
24
|
+
query: propQuery,
|
|
25
|
+
filter,
|
|
26
|
+
multiselect: propMultiselect,
|
|
27
|
+
defaultQuery,
|
|
28
|
+
defaultValue,
|
|
29
|
+
options: values,
|
|
30
|
+
getOptionLabel
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
const multiselect = propMultiselect ?? (!!value && typeof value === "object" && "length" in value);
|
|
34
|
+
let updateQueryOnSelect = propUpdateQueryOnSelect;
|
|
35
|
+
if (typeof propUpdateQueryOnSelect === "undefined") {
|
|
36
|
+
updateQueryOnSelect = multiselect ? "clear" : "selected";
|
|
37
|
+
}
|
|
38
|
+
const disableCloseOnSelect = propDisableCloseOnSelect ?? (multiselect && checkboxes);
|
|
39
|
+
const [query, setQuery] = useEnsuredState({
|
|
40
|
+
value: propQuery,
|
|
41
|
+
setValue: propSetQuery,
|
|
42
|
+
defaultValue: getDefaultQuery({
|
|
43
|
+
value,
|
|
44
|
+
getOptionLabel,
|
|
45
|
+
defaultQuery
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
const setValue = useCallback((value)=>{
|
|
49
|
+
onValueChange(value);
|
|
50
|
+
setValueState(value);
|
|
51
|
+
}, [
|
|
52
|
+
onValueChange,
|
|
53
|
+
setValueState
|
|
54
|
+
]);
|
|
55
|
+
const combobox = useEditableCombobox({
|
|
56
|
+
...comboboxOptions,
|
|
57
|
+
multiselect
|
|
58
|
+
});
|
|
59
|
+
const { visible, setVisible, popupRef, comboboxRef, comboboxProps, getMenuProps } = combobox;
|
|
60
|
+
// These refs are used to make it so that the options are not filtered until
|
|
61
|
+
// the user types a new query while the listbox is visible. The filtered
|
|
62
|
+
// options will be "cached" while:
|
|
63
|
+
// - the listbox is closing
|
|
64
|
+
// - the listbox is opening and:
|
|
65
|
+
// - the user has not typed at least one letter
|
|
66
|
+
// - the options have not changed
|
|
67
|
+
const entered = useRef(visible);
|
|
68
|
+
const initialQuery = useRef("");
|
|
69
|
+
const prevAvailableOptions = useRef(null);
|
|
70
|
+
const isQueryChange = query && query !== initialQuery.current && entered.current;
|
|
71
|
+
let availableOptions = prevAvailableOptions.current || values;
|
|
72
|
+
if (isQueryChange && filter !== noopAutocompleteFilter && !prevAvailableOptions.current) {
|
|
73
|
+
initialQuery.current = "";
|
|
74
|
+
availableOptions = filter({
|
|
75
|
+
list: values,
|
|
76
|
+
query,
|
|
77
|
+
extractor: getOptionLabel
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// This is probably overkill, but `filterSelected` will create a quick-lookup
|
|
81
|
+
// for all the selected values in a `Set` since it is much faster than
|
|
82
|
+
// `Array.includes()`. The lookup will only be re-created whenever the `value`
|
|
83
|
+
// changes or is uninitialized to prevent it being created each render as
|
|
84
|
+
// well.
|
|
85
|
+
//
|
|
86
|
+
// These optimizations only start mattering when there are around 5000 items
|
|
87
|
+
// selected...
|
|
88
|
+
const selectedOptions = useMemo(()=>{
|
|
89
|
+
if (!filterSelected) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
let optionList = [];
|
|
93
|
+
if (isMultipleValues(value)) {
|
|
94
|
+
optionList = value;
|
|
95
|
+
} else if (value) {
|
|
96
|
+
optionList = [
|
|
97
|
+
value
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
return new Set(optionList);
|
|
101
|
+
}, [
|
|
102
|
+
filterSelected,
|
|
103
|
+
value
|
|
104
|
+
]);
|
|
105
|
+
if (filterSelected && selectedOptions?.size) {
|
|
106
|
+
availableOptions = availableOptions.filter((option)=>!selectedOptions.has(option));
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...combobox,
|
|
110
|
+
value,
|
|
111
|
+
setValue,
|
|
112
|
+
query,
|
|
113
|
+
setQuery,
|
|
114
|
+
availableOptions,
|
|
115
|
+
multiselect,
|
|
116
|
+
comboboxProps: {
|
|
117
|
+
...comboboxProps,
|
|
118
|
+
"aria-autocomplete": "list",
|
|
119
|
+
value: query,
|
|
120
|
+
onKeyDown (event) {
|
|
121
|
+
comboboxProps.onKeyDown(event);
|
|
122
|
+
if (!visible && event.key === "Escape") {
|
|
123
|
+
setQuery("");
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
onBlur (event) {
|
|
127
|
+
onBlur(event);
|
|
128
|
+
if (allowAnyValue) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
enforceSelectedValue({
|
|
132
|
+
value,
|
|
133
|
+
visible,
|
|
134
|
+
popupRef,
|
|
135
|
+
container: event.currentTarget.parentElement,
|
|
136
|
+
comboboxRef,
|
|
137
|
+
getOptionLabel,
|
|
138
|
+
availableOptions,
|
|
139
|
+
prevAvailableOptions
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
onFocus (event) {
|
|
143
|
+
comboboxProps.onFocus(event);
|
|
144
|
+
event.currentTarget.select();
|
|
145
|
+
},
|
|
146
|
+
onChange (event) {
|
|
147
|
+
onChange(event);
|
|
148
|
+
const { value } = event.currentTarget;
|
|
149
|
+
setQuery(value);
|
|
150
|
+
if (!value && !multiselect) {
|
|
151
|
+
setValue(null);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
getListboxProps (overrides) {
|
|
156
|
+
const { ref, onEnter, onEntered, onExited, disableTransition, ...listboxProps } = getMenuProps(overrides);
|
|
157
|
+
const isTransitionCompleteSkipped = !disableTransition && !TRANSITION_CONFIG.disabled;
|
|
158
|
+
const handleEntering = (callback = noop, skipped)=>(appearing)=>{
|
|
159
|
+
callback(appearing);
|
|
160
|
+
if (skipped) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
onOpen();
|
|
164
|
+
// when the listbox is opened, need to flag the entered state to show
|
|
165
|
+
// that new `query` values should be accepted. Also store the initial
|
|
166
|
+
// query.
|
|
167
|
+
entered.current = true;
|
|
168
|
+
initialQuery.current = query;
|
|
169
|
+
};
|
|
170
|
+
let selectedIcon = propSelectedIcon;
|
|
171
|
+
let unselectedIcon = propUnselectedIcon;
|
|
172
|
+
let disableSelectedIcon = propDisableSelectedIcon;
|
|
173
|
+
if (multiselect && checkboxes) {
|
|
174
|
+
if (typeof selectedIcon === "undefined") {
|
|
175
|
+
selectedIcon = getIcon("checkboxChecked");
|
|
176
|
+
}
|
|
177
|
+
if (typeof unselectedIcon === "undefined") {
|
|
178
|
+
unselectedIcon = getIcon("checkbox");
|
|
179
|
+
}
|
|
180
|
+
} else if (typeof disableSelectedIcon === "undefined") {
|
|
181
|
+
disableSelectedIcon = true;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
selectedIcon,
|
|
185
|
+
unselectedIcon,
|
|
186
|
+
selectedIconAfter,
|
|
187
|
+
disableSelectedIcon,
|
|
188
|
+
...listboxProps,
|
|
189
|
+
disableTransition,
|
|
190
|
+
onRequestClose () {
|
|
191
|
+
// Make it so clicking on the text field, clear button, dropdown
|
|
192
|
+
// button, etc does not close the listbox
|
|
193
|
+
if (mode !== "keyboard" && comboboxRef.current?.parentElement?.contains(document.activeElement)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
listboxProps.onRequestClose();
|
|
197
|
+
},
|
|
198
|
+
nodeRef: ref,
|
|
199
|
+
value,
|
|
200
|
+
setValue (option) {
|
|
201
|
+
if (!disableCloseOnSelect) {
|
|
202
|
+
// this makes it so that the options are not filtered again while the
|
|
203
|
+
// listbox is closing after selecting a value
|
|
204
|
+
prevAvailableOptions.current = availableOptions;
|
|
205
|
+
}
|
|
206
|
+
if (value && typeof value === "object" && "length" in value) {
|
|
207
|
+
const nextValue = [
|
|
208
|
+
...value
|
|
209
|
+
];
|
|
210
|
+
const i = value.indexOf(option);
|
|
211
|
+
if (i === -1) {
|
|
212
|
+
nextValue.push(option);
|
|
213
|
+
} else {
|
|
214
|
+
nextValue.splice(i, 1);
|
|
215
|
+
}
|
|
216
|
+
setValue(nextValue);
|
|
217
|
+
} else {
|
|
218
|
+
setValue(option);
|
|
219
|
+
}
|
|
220
|
+
if (updateQueryOnSelect === "as-is") {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const nextQuery = updateQueryOnSelect === "clear" ? "" : getOptionLabel(option);
|
|
224
|
+
triggerManualChangeEvent(comboboxRef.current, nextQuery);
|
|
225
|
+
},
|
|
226
|
+
onEnter: handleEntering(onEnter, false),
|
|
227
|
+
onEntered: handleEntering(onEntered, isTransitionCompleteSkipped),
|
|
228
|
+
onExited () {
|
|
229
|
+
onExited();
|
|
230
|
+
// once the listbox has exited, reset any cached states so the next
|
|
231
|
+
// time the listbox is opened the filtering behaves the same
|
|
232
|
+
entered.current = false;
|
|
233
|
+
prevAvailableOptions.current = null;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
getOptionLabel,
|
|
238
|
+
getOptionProps (options) {
|
|
239
|
+
const overrides = getOptionProps(options);
|
|
240
|
+
return {
|
|
241
|
+
...overrides,
|
|
242
|
+
onClick: (event)=>{
|
|
243
|
+
overrides?.onClick?.(event);
|
|
244
|
+
if (disableCloseOnSelect) {
|
|
245
|
+
event.stopPropagation();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
getClearButtonProps (overrides) {
|
|
251
|
+
return {
|
|
252
|
+
...overrides,
|
|
253
|
+
onClick (event) {
|
|
254
|
+
overrides?.onClick?.(event);
|
|
255
|
+
comboboxRef.current?.focus();
|
|
256
|
+
if (!multiselect) {
|
|
257
|
+
setValue(null);
|
|
258
|
+
}
|
|
259
|
+
triggerManualChangeEvent(comboboxRef.current, "");
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
getDropdownButtonProps (overrides) {
|
|
264
|
+
return {
|
|
265
|
+
"aria-controls": comboboxProps.id,
|
|
266
|
+
visible,
|
|
267
|
+
...overrides,
|
|
268
|
+
onClick (event) {
|
|
269
|
+
overrides?.onClick?.(event);
|
|
270
|
+
comboboxRef.current?.focus();
|
|
271
|
+
if (visible) {
|
|
272
|
+
prevAvailableOptions.current = availableOptions;
|
|
273
|
+
}
|
|
274
|
+
setVisible((prev)=>!prev);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
//# sourceMappingURL=useAutocomplete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/autocomplete/useAutocomplete.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useMemo, useRef } from \"react\";\nimport { useEditableCombobox } from \"../form/useEditableCombobox.js\";\nimport {\n triggerManualChangeEvent,\n type EditableHTMLElement,\n} from \"../form/utils.js\";\nimport { getIcon } from \"../icon/iconConfig.js\";\nimport { useUserInteractionMode } from \"../interaction/UserInteractionModeProvider.js\";\nimport { TRANSITION_CONFIG } from \"../transition/config.js\";\nimport { type TransitionEnterHandler } from \"../transition/types.js\";\nimport { useEnsuredState } from \"../useEnsuredState.js\";\nimport {\n defaultAutocompleteExtractor,\n defaultAutocompleteFilter,\n defaultAutocompleteGetOptionProps,\n noopAutocompleteFilter,\n} from \"./defaults.js\";\nimport {\n type AutocompleteImplementation,\n type AutocompleteMultiSelectImplementation,\n type AutocompleteMultiSelectOptions,\n type AutocompleteOption,\n type AutocompleteOptions,\n type AutocompleteSingleSelectImplementation,\n type AutocompleteSingleSelectOptions,\n} from \"./types.js\";\nimport {\n enforceSelectedValue,\n getDefaultQuery,\n getDefaultValue,\n isMultipleValues,\n} from \"./utils.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * This is the single select autocomplete implementation.\n *\n * @since 6.0.0\n */\nexport function useAutocomplete<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n>(\n options: AutocompleteSingleSelectOptions<Option, ComboboxEl, PopupEl>\n): AutocompleteSingleSelectImplementation<Option, ComboboxEl, PopupEl>;\n/**\n * This is the multiselect autocomplete implementation.\n *\n * @since 6.0.0\n */\nexport function useAutocomplete<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n>(\n options: AutocompleteMultiSelectOptions<Option, ComboboxEl, PopupEl>\n): AutocompleteMultiSelectImplementation<Option, ComboboxEl, PopupEl>;\n/**\n * This is an internal override implementation where the types are less strict\n * so it can be used with the `Autocomplete` component.\n *\n * @since 6.0.0\n * @internal\n */\nexport function useAutocomplete<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n>(\n options: AutocompleteOptions<Option, ComboboxEl, PopupEl>\n): AutocompleteImplementation<Option, ComboboxEl, PopupEl>;\n/**\n * @since 6.0.0\n * @internal\n */\nexport function useAutocomplete<\n Option extends AutocompleteOption,\n ComboboxEl extends EditableHTMLElement = HTMLInputElement,\n PopupEl extends HTMLElement = HTMLElement,\n>(\n options: AutocompleteOptions<Option, ComboboxEl, PopupEl>\n): AutocompleteImplementation<Option, ComboboxEl, PopupEl> {\n const {\n value: propValue,\n setValue: propSetValue,\n defaultValue,\n onValueChange = noop,\n query: propQuery,\n setQuery: propSetQuery,\n defaultQuery,\n options: values,\n getOptionLabel = defaultAutocompleteExtractor,\n getOptionProps = defaultAutocompleteGetOptionProps,\n onBlur = noop,\n onChange = noop,\n onOpen = noop,\n filter = defaultAutocompleteFilter,\n filterSelected,\n allowAnyValue = filter === noopAutocompleteFilter,\n multiselect: propMultiselect,\n checkboxes,\n selectedIcon: propSelectedIcon,\n unselectedIcon: propUnselectedIcon,\n selectedIconAfter,\n disableSelectedIcon: propDisableSelectedIcon,\n updateQueryOnSelect: propUpdateQueryOnSelect,\n disableCloseOnSelect: propDisableCloseOnSelect,\n ...comboboxOptions\n } = options;\n\n const mode = useUserInteractionMode();\n const [value, setValueState] = useEnsuredState({\n value: propValue,\n setValue: propSetValue,\n defaultValue: getDefaultValue({\n query: propQuery,\n filter,\n multiselect: propMultiselect,\n defaultQuery,\n defaultValue,\n options: values,\n getOptionLabel,\n }),\n });\n const multiselect =\n propMultiselect ??\n (!!value && typeof value === \"object\" && \"length\" in value);\n let updateQueryOnSelect = propUpdateQueryOnSelect;\n if (typeof propUpdateQueryOnSelect === \"undefined\") {\n updateQueryOnSelect = multiselect ? \"clear\" : \"selected\";\n }\n\n const disableCloseOnSelect =\n propDisableCloseOnSelect ?? (multiselect && checkboxes);\n\n const [query, setQuery] = useEnsuredState({\n value: propQuery,\n setValue: propSetQuery,\n defaultValue: getDefaultQuery({\n value,\n getOptionLabel,\n defaultQuery,\n }),\n });\n const setValue = useCallback(\n (value: Option | null | readonly Option[]) => {\n onValueChange(value);\n setValueState(value);\n },\n [onValueChange, setValueState]\n );\n\n const combobox = useEditableCombobox<ComboboxEl, PopupEl>({\n ...comboboxOptions,\n multiselect,\n });\n const {\n visible,\n setVisible,\n popupRef,\n comboboxRef,\n comboboxProps,\n getMenuProps,\n } = combobox;\n\n // These refs are used to make it so that the options are not filtered until\n // the user types a new query while the listbox is visible. The filtered\n // options will be \"cached\" while:\n // - the listbox is closing\n // - the listbox is opening and:\n // - the user has not typed at least one letter\n // - the options have not changed\n const entered = useRef(visible);\n const initialQuery = useRef(\"\");\n const prevAvailableOptions = useRef<readonly Option[] | null>(null);\n const isQueryChange =\n query && query !== initialQuery.current && entered.current;\n\n let availableOptions = prevAvailableOptions.current || values;\n if (\n isQueryChange &&\n filter !== noopAutocompleteFilter &&\n !prevAvailableOptions.current\n ) {\n initialQuery.current = \"\";\n availableOptions = filter({\n list: values,\n query,\n extractor: getOptionLabel,\n });\n }\n\n // This is probably overkill, but `filterSelected` will create a quick-lookup\n // for all the selected values in a `Set` since it is much faster than\n // `Array.includes()`. The lookup will only be re-created whenever the `value`\n // changes or is uninitialized to prevent it being created each render as\n // well.\n //\n // These optimizations only start mattering when there are around 5000 items\n // selected...\n const selectedOptions = useMemo(() => {\n if (!filterSelected) {\n return null;\n }\n\n let optionList: readonly Option[] = [];\n if (isMultipleValues(value)) {\n optionList = value;\n } else if (value) {\n optionList = [value];\n }\n\n return new Set(optionList);\n }, [filterSelected, value]);\n\n if (filterSelected && selectedOptions?.size) {\n availableOptions = availableOptions.filter(\n (option) => !selectedOptions.has(option)\n );\n }\n\n return {\n ...combobox,\n value,\n setValue,\n query,\n setQuery,\n availableOptions,\n multiselect,\n comboboxProps: {\n ...comboboxProps,\n \"aria-autocomplete\": \"list\",\n value: query,\n onKeyDown(event) {\n comboboxProps.onKeyDown(event);\n if (!visible && event.key === \"Escape\") {\n setQuery(\"\");\n }\n },\n onBlur(event) {\n onBlur(event);\n\n if (allowAnyValue) {\n return;\n }\n\n enforceSelectedValue({\n value,\n visible,\n popupRef,\n container: event.currentTarget.parentElement,\n comboboxRef,\n getOptionLabel,\n availableOptions,\n prevAvailableOptions,\n });\n },\n onFocus(event) {\n comboboxProps.onFocus(event);\n event.currentTarget.select();\n },\n onChange(event) {\n onChange(event);\n\n const { value } = event.currentTarget;\n setQuery(value);\n if (!value && !multiselect) {\n setValue(null);\n }\n },\n },\n getListboxProps(overrides) {\n const {\n ref,\n onEnter,\n onEntered,\n onExited,\n disableTransition,\n ...listboxProps\n } = getMenuProps(overrides);\n\n const isTransitionCompleteSkipped =\n !disableTransition && !TRANSITION_CONFIG.disabled;\n\n const handleEntering =\n (callback: TransitionEnterHandler = noop, skipped: boolean) =>\n (appearing: boolean) => {\n callback(appearing);\n\n if (skipped) {\n return;\n }\n\n onOpen();\n\n // when the listbox is opened, need to flag the entered state to show\n // that new `query` values should be accepted. Also store the initial\n // query.\n entered.current = true;\n initialQuery.current = query;\n };\n\n let selectedIcon = propSelectedIcon;\n let unselectedIcon = propUnselectedIcon;\n let disableSelectedIcon = propDisableSelectedIcon;\n if (multiselect && checkboxes) {\n if (typeof selectedIcon === \"undefined\") {\n selectedIcon = getIcon(\"checkboxChecked\");\n }\n if (typeof unselectedIcon === \"undefined\") {\n unselectedIcon = getIcon(\"checkbox\");\n }\n } else if (typeof disableSelectedIcon === \"undefined\") {\n disableSelectedIcon = true;\n }\n\n return {\n selectedIcon,\n unselectedIcon,\n selectedIconAfter,\n disableSelectedIcon,\n ...listboxProps,\n disableTransition,\n onRequestClose() {\n // Make it so clicking on the text field, clear button, dropdown\n // button, etc does not close the listbox\n if (\n mode !== \"keyboard\" &&\n comboboxRef.current?.parentElement?.contains(document.activeElement)\n ) {\n return;\n }\n\n listboxProps.onRequestClose();\n },\n nodeRef: ref,\n value,\n setValue(option) {\n if (!disableCloseOnSelect) {\n // this makes it so that the options are not filtered again while the\n // listbox is closing after selecting a value\n prevAvailableOptions.current = availableOptions;\n }\n\n if (value && typeof value === \"object\" && \"length\" in value) {\n const nextValue = [...value];\n const i = value.indexOf(option);\n if (i === -1) {\n nextValue.push(option);\n } else {\n nextValue.splice(i, 1);\n }\n\n setValue(nextValue);\n } else {\n setValue(option);\n }\n\n if (updateQueryOnSelect === \"as-is\") {\n return;\n }\n\n const nextQuery =\n updateQueryOnSelect === \"clear\" ? \"\" : getOptionLabel(option);\n triggerManualChangeEvent(comboboxRef.current, nextQuery);\n },\n onEnter: handleEntering(onEnter, false),\n onEntered: handleEntering(onEntered, isTransitionCompleteSkipped),\n onExited() {\n onExited();\n\n // once the listbox has exited, reset any cached states so the next\n // time the listbox is opened the filtering behaves the same\n entered.current = false;\n prevAvailableOptions.current = null;\n },\n };\n },\n getOptionLabel,\n getOptionProps(options) {\n const overrides = getOptionProps(options);\n\n return {\n ...overrides,\n onClick: (event) => {\n overrides?.onClick?.(event);\n if (disableCloseOnSelect) {\n event.stopPropagation();\n }\n },\n };\n },\n getClearButtonProps(overrides) {\n return {\n ...overrides,\n onClick(event) {\n overrides?.onClick?.(event);\n comboboxRef.current?.focus();\n\n if (!multiselect) {\n setValue(null);\n }\n triggerManualChangeEvent(comboboxRef.current, \"\");\n },\n };\n },\n getDropdownButtonProps(overrides) {\n return {\n \"aria-controls\": comboboxProps.id,\n visible,\n ...overrides,\n onClick(event) {\n overrides?.onClick?.(event);\n comboboxRef.current?.focus();\n if (visible) {\n prevAvailableOptions.current = availableOptions;\n }\n setVisible((prev) => !prev);\n },\n };\n },\n };\n}\n"],"names":["useCallback","useMemo","useRef","useEditableCombobox","triggerManualChangeEvent","getIcon","useUserInteractionMode","TRANSITION_CONFIG","useEnsuredState","defaultAutocompleteExtractor","defaultAutocompleteFilter","defaultAutocompleteGetOptionProps","noopAutocompleteFilter","enforceSelectedValue","getDefaultQuery","getDefaultValue","isMultipleValues","noop","useAutocomplete","options","value","propValue","setValue","propSetValue","defaultValue","onValueChange","query","propQuery","setQuery","propSetQuery","defaultQuery","values","getOptionLabel","getOptionProps","onBlur","onChange","onOpen","filter","filterSelected","allowAnyValue","multiselect","propMultiselect","checkboxes","selectedIcon","propSelectedIcon","unselectedIcon","propUnselectedIcon","selectedIconAfter","disableSelectedIcon","propDisableSelectedIcon","updateQueryOnSelect","propUpdateQueryOnSelect","disableCloseOnSelect","propDisableCloseOnSelect","comboboxOptions","mode","setValueState","combobox","visible","setVisible","popupRef","comboboxRef","comboboxProps","getMenuProps","entered","initialQuery","prevAvailableOptions","isQueryChange","current","availableOptions","list","extractor","selectedOptions","optionList","Set","size","option","has","onKeyDown","event","key","container","currentTarget","parentElement","onFocus","select","getListboxProps","overrides","ref","onEnter","onEntered","onExited","disableTransition","listboxProps","isTransitionCompleteSkipped","disabled","handleEntering","callback","skipped","appearing","onRequestClose","contains","document","activeElement","nodeRef","nextValue","i","indexOf","push","splice","nextQuery","onClick","stopPropagation","getClearButtonProps","focus","getDropdownButtonProps","id","prev"],"mappings":"AAAA;AACA,SAASA,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AACrD,SAASC,mBAAmB,QAAQ,iCAAiC;AACrE,SACEC,wBAAwB,QAEnB,mBAAmB;AAC1B,SAASC,OAAO,QAAQ,wBAAwB;AAChD,SAASC,sBAAsB,QAAQ,gDAAgD;AACvF,SAASC,iBAAiB,QAAQ,0BAA0B;AAE5D,SAASC,eAAe,QAAQ,wBAAwB;AACxD,SACEC,4BAA4B,EAC5BC,yBAAyB,EACzBC,iCAAiC,EACjCC,sBAAsB,QACjB,gBAAgB;AAUvB,SACEC,oBAAoB,EACpBC,eAAe,EACfC,eAAe,EACfC,gBAAgB,QACX,aAAa;AAEpB,MAAMC,OAAO;AACX,aAAa;AACf;AAwCA;;;CAGC,GACD,OAAO,SAASC,gBAKdC,OAAyD;IAEzD,MAAM,EACJC,OAAOC,SAAS,EAChBC,UAAUC,YAAY,EACtBC,YAAY,EACZC,gBAAgBR,IAAI,EACpBS,OAAOC,SAAS,EAChBC,UAAUC,YAAY,EACtBC,YAAY,EACZX,SAASY,MAAM,EACfC,iBAAiBvB,4BAA4B,EAC7CwB,iBAAiBtB,iCAAiC,EAClDuB,SAASjB,IAAI,EACbkB,WAAWlB,IAAI,EACfmB,SAASnB,IAAI,EACboB,SAAS3B,yBAAyB,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OAAO,EAAE;gBAChD;YACF;QACF;QACA+C,wBAAuB5B,SAAS;YAC9B,OAAO;gBACL,iBAAiBzB,cAAcsD,EAAE;gBACjC1D;gBACA,GAAG6B,SAAS;gBACZwB,SAAQhC,KAAK;oBACXQ,WAAWwB,UAAUhC;oBACrBlB,YAAYO,OAAO,EAAE8C;oBACrB,IAAIxD,SAAS;wBACXQ,qBAAqBE,OAAO,GAAGC;oBACjC;oBACAV,WAAW,CAAC0D,OAAS,CAACA;gBACxB;YACF;QACF;IACF;AACF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import { type EditableHTMLElement } from "../form/utils.js";
|
|
3
|
+
import { type NonNullMutableRef, type UseStateInitializer } from "../types.js";
|
|
4
|
+
import { type AutocompleteFilterOptions, type AutocompleteGetOptionLabel, type AutocompleteOption } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* @since 6.0.0
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface GetDefaultValueOptions<Option extends AutocompleteOption> {
|
|
10
|
+
query: string | undefined;
|
|
11
|
+
multiselect?: boolean;
|
|
12
|
+
defaultQuery: UseStateInitializer<string> | undefined;
|
|
13
|
+
defaultValue: UseStateInitializer<Option | null | readonly Option[]> | undefined;
|
|
14
|
+
options: readonly Option[];
|
|
15
|
+
getOptionLabel: AutocompleteGetOptionLabel<Option>;
|
|
16
|
+
filter: (options: AutocompleteFilterOptions<Option>) => readonly Option[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @since 6.0.0
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare function getDefaultValue<Option extends AutocompleteOption>(options: GetDefaultValueOptions<Option>): UseStateInitializer<Option | null | readonly Option[]>;
|
|
23
|
+
/**
|
|
24
|
+
* @since 6.0.0
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
interface GetDefaultQueryOptions<Option extends AutocompleteOption> {
|
|
28
|
+
value: Option | null | readonly Option[];
|
|
29
|
+
getOptionLabel: AutocompleteGetOptionLabel<Option>;
|
|
30
|
+
defaultQuery?: UseStateInitializer<string>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @since 6.0.0
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export declare function getDefaultQuery<Option extends AutocompleteOption>(options: GetDefaultQueryOptions<Option>): UseStateInitializer<string>;
|
|
37
|
+
/**
|
|
38
|
+
* @since 6.0.0
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export interface EnforceSelectedValueOptions<Option extends AutocompleteOption> {
|
|
42
|
+
value: Option | readonly Option[] | null;
|
|
43
|
+
visible: boolean;
|
|
44
|
+
container: HTMLElement | null;
|
|
45
|
+
popupRef: RefObject<HTMLElement>;
|
|
46
|
+
comboboxRef: RefObject<EditableHTMLElement>;
|
|
47
|
+
getOptionLabel: AutocompleteGetOptionLabel<Option>;
|
|
48
|
+
availableOptions: readonly Option[];
|
|
49
|
+
prevAvailableOptions: NonNullMutableRef<readonly Option[] | null>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* This enforces that if the user clicks away, touches somewhere else on the
|
|
53
|
+
* page, tabs to the next element, or focuses another element programmatically
|
|
54
|
+
* the autocomplete will set the `value` back to the previous selected value if
|
|
55
|
+
* there was one. i.e.
|
|
56
|
+
*
|
|
57
|
+
* Case 1:
|
|
58
|
+
* - User selects "Apple"
|
|
59
|
+
* - User hits backspace twice. Input displays "App"
|
|
60
|
+
* - User clicks somewhere else on the page
|
|
61
|
+
* - Input now displays "Apple" again
|
|
62
|
+
*
|
|
63
|
+
* Case 2:
|
|
64
|
+
* - User selects "Apple"
|
|
65
|
+
* - User clears the input
|
|
66
|
+
* - User types "app"
|
|
67
|
+
* - User clicks somewhere else on the page
|
|
68
|
+
* - Input now displays "" and the value is set to `null`
|
|
69
|
+
*
|
|
70
|
+
* NOTE: This mutates the {@link EnforceSelectedValueOptions.prevAvailableOptions}
|
|
71
|
+
*
|
|
72
|
+
* @since 6.0.0
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export declare function enforceSelectedValue<Option extends AutocompleteOption>(options: EnforceSelectedValueOptions<Option>): void;
|
|
76
|
+
/**
|
|
77
|
+
* @since 6.0.0
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export declare function isMultipleValues<Option extends AutocompleteOption>(value: Option | null | readonly Option[]): value is readonly Option[];
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { triggerManualChangeEvent } from "../form/utils.js";
|
|
2
|
+
import { noopAutocompleteFilter } from "./defaults.js";
|
|
3
|
+
/**
|
|
4
|
+
* @since 6.0.0
|
|
5
|
+
* @internal
|
|
6
|
+
*/ export function getDefaultValue(options) {
|
|
7
|
+
const { query, filter, multiselect, defaultQuery, defaultValue, options: values, getOptionLabel } = options;
|
|
8
|
+
if (typeof defaultValue !== "undefined") {
|
|
9
|
+
return defaultValue;
|
|
10
|
+
}
|
|
11
|
+
// do not support determining the default value for a multiselect
|
|
12
|
+
// autocomplete if only a query was provided.
|
|
13
|
+
if (multiselect) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
// do not support a default value out of the box for this case
|
|
17
|
+
if (filter === noopAutocompleteFilter) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return ()=>{
|
|
21
|
+
let q = "";
|
|
22
|
+
if (query) {
|
|
23
|
+
q = query;
|
|
24
|
+
} else if (defaultQuery) {
|
|
25
|
+
q = defaultQuery instanceof Function ? defaultQuery() : defaultQuery;
|
|
26
|
+
}
|
|
27
|
+
if (!q) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const filtered = filter({
|
|
31
|
+
list: values,
|
|
32
|
+
query: q,
|
|
33
|
+
extractor: getOptionLabel
|
|
34
|
+
});
|
|
35
|
+
return filtered[0] ?? null;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @since 6.0.0
|
|
40
|
+
* @internal
|
|
41
|
+
*/ export function getDefaultQuery(options) {
|
|
42
|
+
const { value, getOptionLabel, defaultQuery } = options;
|
|
43
|
+
if (defaultQuery) {
|
|
44
|
+
return defaultQuery;
|
|
45
|
+
}
|
|
46
|
+
return ()=>{
|
|
47
|
+
if (typeof value === "string") {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (value && typeof value === "object" && !("length" in value)) {
|
|
51
|
+
return getOptionLabel(value);
|
|
52
|
+
}
|
|
53
|
+
return "";
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* This enforces that if the user clicks away, touches somewhere else on the
|
|
58
|
+
* page, tabs to the next element, or focuses another element programmatically
|
|
59
|
+
* the autocomplete will set the `value` back to the previous selected value if
|
|
60
|
+
* there was one. i.e.
|
|
61
|
+
*
|
|
62
|
+
* Case 1:
|
|
63
|
+
* - User selects "Apple"
|
|
64
|
+
* - User hits backspace twice. Input displays "App"
|
|
65
|
+
* - User clicks somewhere else on the page
|
|
66
|
+
* - Input now displays "Apple" again
|
|
67
|
+
*
|
|
68
|
+
* Case 2:
|
|
69
|
+
* - User selects "Apple"
|
|
70
|
+
* - User clears the input
|
|
71
|
+
* - User types "app"
|
|
72
|
+
* - User clicks somewhere else on the page
|
|
73
|
+
* - Input now displays "" and the value is set to `null`
|
|
74
|
+
*
|
|
75
|
+
* NOTE: This mutates the {@link EnforceSelectedValueOptions.prevAvailableOptions}
|
|
76
|
+
*
|
|
77
|
+
* @since 6.0.0
|
|
78
|
+
* @internal
|
|
79
|
+
*/ export function enforceSelectedValue(options) {
|
|
80
|
+
const { value, visible, container, popupRef, comboboxRef, getOptionLabel, availableOptions, prevAvailableOptions } = options;
|
|
81
|
+
if (!container) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
window.requestAnimationFrame(()=>{
|
|
85
|
+
if (container.contains(document.activeElement) || popupRef.current?.contains(document.activeElement)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (visible) {
|
|
89
|
+
// this makes it so that the options are not filtered again while closing
|
|
90
|
+
prevAvailableOptions.current = availableOptions;
|
|
91
|
+
}
|
|
92
|
+
let label = "";
|
|
93
|
+
if (typeof value === "string") {
|
|
94
|
+
label = value;
|
|
95
|
+
} else if (typeof value === "object" && value && !("length" in value)) {
|
|
96
|
+
label = getOptionLabel(value);
|
|
97
|
+
}
|
|
98
|
+
triggerManualChangeEvent(comboboxRef.current, label);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @since 6.0.0
|
|
103
|
+
* @internal
|
|
104
|
+
*/ export function isMultipleValues(value) {
|
|
105
|
+
return !!value && typeof value === "object" && "length" in value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/autocomplete/utils.ts"],"sourcesContent":["import { type RefObject } from \"react\";\nimport {\n type EditableHTMLElement,\n triggerManualChangeEvent,\n} from \"../form/utils.js\";\nimport { type NonNullMutableRef, type UseStateInitializer } from \"../types.js\";\nimport { noopAutocompleteFilter } from \"./defaults.js\";\nimport {\n type AutocompleteFilterOptions,\n type AutocompleteGetOptionLabel,\n type AutocompleteOption,\n} from \"./types.js\";\n\n/**\n * @since 6.0.0\n * @internal\n */\nexport interface GetDefaultValueOptions<Option extends AutocompleteOption> {\n query: string | undefined;\n multiselect?: boolean;\n defaultQuery: UseStateInitializer<string> | undefined;\n defaultValue:\n | UseStateInitializer<Option | null | readonly Option[]>\n | undefined;\n options: readonly Option[];\n getOptionLabel: AutocompleteGetOptionLabel<Option>;\n filter: (options: AutocompleteFilterOptions<Option>) => readonly Option[];\n}\n\n/**\n * @since 6.0.0\n * @internal\n */\nexport function getDefaultValue<Option extends AutocompleteOption>(\n options: GetDefaultValueOptions<Option>\n): UseStateInitializer<Option | null | readonly Option[]> {\n const {\n query,\n filter,\n multiselect,\n defaultQuery,\n defaultValue,\n options: values,\n getOptionLabel,\n } = options;\n\n if (typeof defaultValue !== \"undefined\") {\n return defaultValue;\n }\n\n // do not support determining the default value for a multiselect\n // autocomplete if only a query was provided.\n if (multiselect) {\n return [];\n }\n\n // do not support a default value out of the box for this case\n if (filter === noopAutocompleteFilter) {\n return null;\n }\n\n return () => {\n let q = \"\";\n if (query) {\n q = query;\n } else if (defaultQuery) {\n q = defaultQuery instanceof Function ? defaultQuery() : defaultQuery;\n }\n\n if (!q) {\n return null;\n }\n\n const filtered = filter({\n list: values,\n query: q,\n extractor: getOptionLabel,\n });\n\n return filtered[0] ?? null;\n };\n}\n\n/**\n * @since 6.0.0\n * @internal\n */\ninterface GetDefaultQueryOptions<Option extends AutocompleteOption> {\n value: Option | null | readonly Option[];\n getOptionLabel: AutocompleteGetOptionLabel<Option>;\n defaultQuery?: UseStateInitializer<string>;\n}\n\n/**\n * @since 6.0.0\n * @internal\n */\nexport function getDefaultQuery<Option extends AutocompleteOption>(\n options: GetDefaultQueryOptions<Option>\n): UseStateInitializer<string> {\n const { value, getOptionLabel, defaultQuery } = options;\n\n if (defaultQuery) {\n return defaultQuery;\n }\n\n return () => {\n if (typeof value === \"string\") {\n return value;\n }\n\n if (value && typeof value === \"object\" && !(\"length\" in value)) {\n return getOptionLabel(value);\n }\n\n return \"\";\n };\n}\n\n/**\n * @since 6.0.0\n * @internal\n */\nexport interface EnforceSelectedValueOptions<\n Option extends AutocompleteOption,\n> {\n value: Option | readonly Option[] | null;\n visible: boolean;\n container: HTMLElement | null;\n popupRef: RefObject<HTMLElement>;\n comboboxRef: RefObject<EditableHTMLElement>;\n getOptionLabel: AutocompleteGetOptionLabel<Option>;\n availableOptions: readonly Option[];\n prevAvailableOptions: NonNullMutableRef<readonly Option[] | null>;\n}\n\n/**\n * This enforces that if the user clicks away, touches somewhere else on the\n * page, tabs to the next element, or focuses another element programmatically\n * the autocomplete will set the `value` back to the previous selected value if\n * there was one. i.e.\n *\n * Case 1:\n * - User selects \"Apple\"\n * - User hits backspace twice. Input displays \"App\"\n * - User clicks somewhere else on the page\n * - Input now displays \"Apple\" again\n *\n * Case 2:\n * - User selects \"Apple\"\n * - User clears the input\n * - User types \"app\"\n * - User clicks somewhere else on the page\n * - Input now displays \"\" and the value is set to `null`\n *\n * NOTE: This mutates the {@link EnforceSelectedValueOptions.prevAvailableOptions}\n *\n * @since 6.0.0\n * @internal\n */\nexport function enforceSelectedValue<Option extends AutocompleteOption>(\n options: EnforceSelectedValueOptions<Option>\n): void {\n const {\n value,\n visible,\n container,\n popupRef,\n comboboxRef,\n getOptionLabel,\n availableOptions,\n prevAvailableOptions,\n } = options;\n\n if (!container) {\n return;\n }\n\n window.requestAnimationFrame(() => {\n if (\n container.contains(document.activeElement) ||\n popupRef.current?.contains(document.activeElement)\n ) {\n return;\n }\n\n if (visible) {\n // this makes it so that the options are not filtered again while closing\n prevAvailableOptions.current = availableOptions;\n }\n\n let label = \"\";\n if (typeof value === \"string\") {\n label = value;\n } else if (typeof value === \"object\" && value && !(\"length\" in value)) {\n label = getOptionLabel(value);\n }\n\n triggerManualChangeEvent(comboboxRef.current, label);\n });\n}\n\n/**\n * @since 6.0.0\n * @internal\n */\nexport function isMultipleValues<Option extends AutocompleteOption>(\n value: Option | null | readonly Option[]\n): value is readonly Option[] {\n return !!value && typeof value === \"object\" && \"length\" in value;\n}\n"],"names":["triggerManualChangeEvent","noopAutocompleteFilter","getDefaultValue","options","query","filter","multiselect","defaultQuery","defaultValue","values","getOptionLabel","q","Function","filtered","list","extractor","getDefaultQuery","value","enforceSelectedValue","visible","container","popupRef","comboboxRef","availableOptions","prevAvailableOptions","window","requestAnimationFrame","contains","document","activeElement","current","label","isMultipleValues"],"mappings":"AACA,SAEEA,wBAAwB,QACnB,mBAAmB;AAE1B,SAASC,sBAAsB,QAAQ,gBAAgB;AAuBvD;;;CAGC,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