@basic-ui/core 0.0.53 → 0.0.56
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/build/cjs/index.js +278 -505
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/Accordion.js +20 -29
- package/build/esm/Accordion/Accordion.js.map +1 -1
- package/build/esm/Accordion/AccordionBody.js +18 -32
- package/build/esm/Accordion/AccordionBody.js.map +1 -1
- package/build/esm/Accordion/AccordionHeader.js +37 -74
- package/build/esm/Accordion/AccordionHeader.js.map +1 -1
- package/build/esm/Accordion/AccordionItem.js +19 -22
- package/build/esm/Accordion/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/context.js +16 -13
- package/build/esm/Accordion/context.js.map +1 -1
- package/build/esm/Accordion/index.js.map +1 -1
- package/build/esm/Accordion/scopeQuery.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.js +15 -25
- package/build/esm/CheckBox/CheckBox.js.map +1 -1
- package/build/esm/CheckBox/index.js.map +1 -1
- package/build/esm/ComboBox/Combobox.d.ts +7 -7
- package/build/esm/ComboBox/Combobox.js +52 -59
- package/build/esm/ComboBox/Combobox.js.map +1 -1
- package/build/esm/ComboBox/ComboboxButton.js +23 -28
- package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
- package/build/esm/ComboBox/ComboboxInput.js +67 -70
- package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
- package/build/esm/ComboBox/ComboboxLabel.js +15 -17
- package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
- package/build/esm/ComboBox/ComboboxList.js +19 -20
- package/build/esm/ComboBox/ComboboxList.js.map +1 -1
- package/build/esm/ComboBox/ComboboxOption.js +41 -45
- package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
- package/build/esm/ComboBox/ComboboxPopover.js +22 -21
- package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
- package/build/esm/ComboBox/cities.js.map +1 -1
- package/build/esm/ComboBox/context.js +5 -6
- package/build/esm/ComboBox/context.js.map +1 -1
- package/build/esm/ComboBox/hooks.d.ts +2 -2
- package/build/esm/ComboBox/hooks.js +175 -148
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/ComboBox/index.js.map +1 -1
- package/build/esm/ComboBox/makeHash.js +3 -6
- package/build/esm/ComboBox/makeHash.js.map +1 -1
- package/build/esm/ComboBox/scopeQuery.js.map +1 -1
- package/build/esm/FocusLock/FocusLock.js +26 -32
- package/build/esm/FocusLock/FocusLock.js.map +1 -1
- package/build/esm/FocusLock/index.js.map +1 -1
- package/build/esm/FocusLock/tabUtils.js +5 -7
- package/build/esm/FocusLock/tabUtils.js.map +1 -1
- package/build/esm/FocusLock/useFocusLock.js +14 -19
- package/build/esm/FocusLock/useFocusLock.js.map +1 -1
- package/build/esm/List/List.js +9 -11
- package/build/esm/List/List.js.map +1 -1
- package/build/esm/List/ListItem.js +9 -11
- package/build/esm/List/ListItem.js.map +1 -1
- package/build/esm/List/context.js +6 -6
- package/build/esm/List/context.js.map +1 -1
- package/build/esm/List/index.js.map +1 -1
- package/build/esm/Menu/ContextMenuTrigger.d.ts +4 -4
- package/build/esm/Menu/ContextMenuTrigger.js +32 -37
- package/build/esm/Menu/ContextMenuTrigger.js.map +1 -1
- package/build/esm/Menu/Menu.js +33 -49
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuButton.d.ts +4 -4
- package/build/esm/Menu/MenuButton.js +28 -44
- package/build/esm/Menu/MenuButton.js.map +1 -1
- package/build/esm/Menu/MenuItem.js +29 -38
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.js +61 -116
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.js +16 -19
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +1 -1
- package/build/esm/Menu/context.js +14 -12
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Menu/fixtures/countryList.js +1 -1
- package/build/esm/Menu/fixtures/countryList.js.map +1 -1
- package/build/esm/Menu/index.js.map +1 -1
- package/build/esm/Menu/scope.js.map +1 -1
- package/build/esm/Modal/Modal.js +13 -18
- package/build/esm/Modal/Modal.js.map +1 -1
- package/build/esm/Modal/ModalBackdrop.js +24 -33
- package/build/esm/Modal/ModalBackdrop.js.map +1 -1
- package/build/esm/Modal/index.js.map +1 -1
- package/build/esm/Popper/Popper.d.ts +3 -3
- package/build/esm/Popper/Popper.js +44 -61
- package/build/esm/Popper/Popper.js.map +1 -1
- package/build/esm/Popper/PopperArrow.js +11 -16
- package/build/esm/Popper/PopperArrow.js.map +1 -1
- package/build/esm/Popper/context.js +3 -5
- package/build/esm/Popper/context.js.map +1 -1
- package/build/esm/Popper/index.js.map +1 -1
- package/build/esm/Portal/Portal.js +9 -11
- package/build/esm/Portal/Portal.js.map +1 -1
- package/build/esm/Portal/PortalSelectorProvider.d.ts +3 -3
- package/build/esm/Portal/PortalSelectorProvider.js +6 -4
- package/build/esm/Portal/PortalSelectorProvider.js.map +1 -1
- package/build/esm/Portal/index.js.map +1 -1
- package/build/esm/RadioButton/RadioButton.js +17 -23
- package/build/esm/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/RadioButton/RadioGroup.js +19 -28
- package/build/esm/RadioButton/RadioGroup.js.map +1 -1
- package/build/esm/RadioButton/context.d.ts +1 -1
- package/build/esm/RadioButton/context.js +8 -6
- package/build/esm/RadioButton/context.js.map +1 -1
- package/build/esm/RadioButton/index.js.map +1 -1
- package/build/esm/SkipNav/SkipNav.js +9 -11
- package/build/esm/SkipNav/SkipNav.js.map +1 -1
- package/build/esm/SkipNav/index.js.map +1 -1
- package/build/esm/Slider/Slider.d.ts +7 -7
- package/build/esm/Slider/Slider.js +340 -407
- package/build/esm/Slider/Slider.js.map +1 -1
- package/build/esm/Slider/index.js.map +1 -1
- package/build/esm/Spinner/Spinner.js +31 -59
- package/build/esm/Spinner/Spinner.js.map +1 -1
- package/build/esm/Spinner/SpinnerButton.js +14 -19
- package/build/esm/Spinner/SpinnerButton.js.map +1 -1
- package/build/esm/Spinner/context.js +8 -7
- package/build/esm/Spinner/context.js.map +1 -1
- package/build/esm/Spinner/index.js.map +1 -1
- package/build/esm/Tabs/Tab.js +32 -50
- package/build/esm/Tabs/Tab.js.map +1 -1
- package/build/esm/Tabs/TabList.js +24 -34
- package/build/esm/Tabs/TabList.js.map +1 -1
- package/build/esm/Tabs/TabPanel.js +16 -23
- package/build/esm/Tabs/TabPanel.js.map +1 -1
- package/build/esm/Tabs/TabPanels.js +15 -20
- package/build/esm/Tabs/TabPanels.js.map +1 -1
- package/build/esm/Tabs/Tabs.js +17 -33
- package/build/esm/Tabs/Tabs.js.map +1 -1
- package/build/esm/Tabs/context.js +16 -13
- package/build/esm/Tabs/context.js.map +1 -1
- package/build/esm/Tabs/index.js.map +1 -1
- package/build/esm/Tabs/scopeQuery.js.map +1 -1
- package/build/esm/Tooltip/Tooltip.d.ts +2 -2
- package/build/esm/Tooltip/Tooltip.js +20 -30
- package/build/esm/Tooltip/Tooltip.js.map +1 -1
- package/build/esm/Tooltip/index.js.map +1 -1
- package/build/esm/Tooltip/stateMachine.d.ts +2 -2
- package/build/esm/Tooltip/stateMachine.js +95 -81
- package/build/esm/Tooltip/stateMachine.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +2 -2
- package/build/esm/Tooltip/useTooltip.js +38 -50
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/index.js.map +1 -1
- package/build/esm/hooks/useAutoFocus.js +3 -3
- package/build/esm/hooks/useAutoFocus.js.map +1 -1
- package/build/esm/hooks/useChildrenCounter.js +6 -8
- package/build/esm/hooks/useChildrenCounter.js.map +1 -1
- package/build/esm/hooks/useControlledState.js +6 -16
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/hooks/useFocusReturn.js +8 -12
- package/build/esm/hooks/useFocusReturn.js.map +1 -1
- package/build/esm/hooks/useFocusState.d.ts +2 -2
- package/build/esm/hooks/useFocusState.js +9 -15
- package/build/esm/hooks/useFocusState.js.map +1 -1
- package/build/esm/hooks/useGestureHandlers.d.ts +1 -1
- package/build/esm/hooks/useGestureHandlers.js +80 -100
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/esm/hooks/useMeasure.js +7 -15
- package/build/esm/hooks/useMeasure.js.map +1 -1
- package/build/esm/hooks/useOnClickOutside.js +4 -6
- package/build/esm/hooks/useOnClickOutside.js.map +1 -1
- package/build/esm/hooks/useOnKeyDown.js +3 -4
- package/build/esm/hooks/useOnKeyDown.js.map +1 -1
- package/build/esm/hooks/useReducerMachine.d.ts +1 -1
- package/build/esm/hooks/useReducerMachine.js +15 -26
- package/build/esm/hooks/useReducerMachine.js.map +1 -1
- package/build/esm/hooks/useRemoveBodyScroll.js +9 -14
- package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
- package/build/esm/hooks/useScope.d.ts +2 -2
- package/build/esm/hooks/useScope.js +12 -14
- package/build/esm/hooks/useScope.js.map +1 -1
- package/build/esm/hooks/useThrottle.js +5 -10
- package/build/esm/hooks/useThrottle.js.map +1 -1
- package/build/esm/index.js +4 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/styles.d.js +2 -0
- package/build/esm/styles.d.js.map +1 -0
- package/build/esm/utils/assign-ref.js +3 -5
- package/build/esm/utils/assign-ref.js.map +1 -1
- package/build/esm/utils/can-use-dom.js.map +1 -1
- package/build/esm/utils/clamp.js.map +1 -1
- package/build/esm/utils/context.d.ts +1 -1
- package/build/esm/utils/context.js +13 -20
- package/build/esm/utils/context.js.map +1 -1
- package/build/esm/utils/create-subscription.js +5 -10
- package/build/esm/utils/create-subscription.js.map +1 -1
- package/build/esm/utils/get-circular-index.js +0 -1
- package/build/esm/utils/get-circular-index.js.map +1 -1
- package/build/esm/utils/index.js.map +1 -1
- package/build/esm/utils/is-right-click.js.map +1 -1
- package/build/esm/utils/owner-document.js +1 -1
- package/build/esm/utils/owner-document.js.map +1 -1
- package/build/esm/utils/polymorphic.d.ts +10 -10
- package/build/esm/utils/polymorphic.js.map +1 -1
- package/build/esm/utils/rubber-band-clamp.js +2 -5
- package/build/esm/utils/rubber-band-clamp.js.map +1 -1
- package/build/esm/utils/use-stable-callback.js +8 -10
- package/build/esm/utils/use-stable-callback.js.map +1 -1
- package/build/esm/utils/wrap-event.d.ts +1 -1
- package/build/esm/utils/wrap-event.js +2 -5
- package/build/esm/utils/wrap-event.js.map +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/Accordion/Accordion.tsx +1 -1
- package/src/Accordion/AccordionBody.tsx +1 -1
- package/src/Accordion/AccordionHeader.tsx +1 -2
- package/src/ComboBox/Combobox.tsx +2 -2
- package/src/ComboBox/ComboboxList.tsx +1 -1
- package/src/ComboBox/ComboboxOption.tsx +0 -1
- package/src/ComboBox/hooks.tsx +0 -3
- package/src/FocusLock/useFocusLock.ts +0 -1
- package/src/Menu/Menu.tsx +2 -3
- package/src/Menu/MenuItem.tsx +1 -2
- package/src/Menu/MenuList.tsx +4 -4
- package/src/Modal/Modal.story.tsx +11 -7
- package/src/Modal/ModalBackdrop.tsx +1 -1
- package/src/Modal/NavDrawer.story.tsx +9 -6
- package/src/Popper/Popper.story.tsx +23 -7
- package/src/Popper/Popper.tsx +2 -2
- package/src/RadioButton/RadioButton.story.tsx +2 -1
- package/src/Slider/Slider.tsx +6 -11
- package/src/Spinner/Spinner.tsx +1 -1
- package/src/Tabs/TabList.tsx +1 -1
- package/src/Tooltip/Tooltip.tsx +8 -5
- package/src/Tooltip/useTooltip.ts +1 -1
- package/src/hooks/useControlledState.ts +1 -6
- package/src/hooks/useGestureHandlers.ts +0 -4
- package/src/hooks/useRemoveBodyScroll.ts +0 -1
- package/src/hooks/useScope.ts +1 -1
- package/src/styles.d.ts +1 -0
- package/src/utils/polymorphic.ts +14 -10
- package/src/utils/use-stable-callback.ts +0 -1
- package/build/esm/Carousel/Carousel.d.ts +0 -9
- package/build/esm/Carousel/Carousel.js +0 -38
- package/build/esm/Carousel/Carousel.js.map +0 -1
- package/build/esm/Carousel/Fader.d.ts +0 -14
- package/build/esm/Carousel/Fader.js +0 -76
- package/build/esm/Carousel/Fader.js.map +0 -1
- package/build/esm/Carousel/FaderItem.d.ts +0 -5
- package/build/esm/Carousel/FaderItem.js +0 -16
- package/build/esm/Carousel/FaderItem.js.map +0 -1
- package/build/esm/Carousel/Preloader.d.ts +0 -7
- package/build/esm/Carousel/Preloader.js +0 -70
- package/build/esm/Carousel/Preloader.js.map +0 -1
- package/build/esm/Carousel/Slider.d.ts +0 -14
- package/build/esm/Carousel/Slider.js +0 -212
- package/build/esm/Carousel/Slider.js.map +0 -1
- package/build/esm/Carousel/SliderItem.d.ts +0 -12
- package/build/esm/Carousel/SliderItem.js +0 -41
- package/build/esm/Carousel/SliderItem.js.map +0 -1
- package/build/esm/Carousel/context.d.ts +0 -10
- package/build/esm/Carousel/context.js +0 -8
- package/build/esm/Carousel/context.js.map +0 -1
- package/build/esm/Carousel/getSliderParams.d.ts +0 -9
- package/build/esm/Carousel/getSliderParams.js +0 -85
- package/build/esm/Carousel/getSliderParams.js.map +0 -1
- package/build/esm/Carousel/index.d.ts +0 -7
- package/build/esm/Carousel/index.js +0 -8
- package/build/esm/Carousel/index.js.map +0 -1
- package/build/esm/Carousel/useCarouselGestures.d.ts +0 -30
- package/build/esm/Carousel/useCarouselGestures.js +0 -33
- package/build/esm/Carousel/useCarouselGestures.js.map +0 -1
- package/build/esm/DatePicker/DatePicker.d.ts +0 -24
- package/build/esm/DatePicker/DatePicker.js +0 -101
- package/build/esm/DatePicker/DatePicker.js.map +0 -1
- package/build/esm/DatePicker/DatePickerSelect.d.ts +0 -8
- package/build/esm/DatePicker/DatePickerSelect.js +0 -201
- package/build/esm/DatePicker/DatePickerSelect.js.map +0 -1
- package/build/esm/DatePicker/RangeDatePicker.d.ts +0 -28
- package/build/esm/DatePicker/RangeDatePicker.js +0 -94
- package/build/esm/DatePicker/RangeDatePicker.js.map +0 -1
- package/build/esm/DatePicker/adjustDates.d.ts +0 -4
- package/build/esm/DatePicker/adjustDates.js +0 -18
- package/build/esm/DatePicker/adjustDates.js.map +0 -1
- package/build/esm/DatePicker/contexts.d.ts +0 -31
- package/build/esm/DatePicker/contexts.js +0 -15
- package/build/esm/DatePicker/contexts.js.map +0 -1
- package/build/esm/DatePicker/dateTypes.d.ts +0 -2
- package/build/esm/DatePicker/dateTypes.js +0 -2
- package/build/esm/DatePicker/dateTypes.js.map +0 -1
- package/build/esm/DatePicker/hooks.d.ts +0 -36
- package/build/esm/DatePicker/hooks.js +0 -98
- package/build/esm/DatePicker/hooks.js.map +0 -1
- package/build/esm/DatePicker/index.d.ts +0 -5
- package/build/esm/DatePicker/index.js +0 -6
- package/build/esm/DatePicker/index.js.map +0 -1
- package/build/esm/hooks/useId.d.ts +0 -1
- package/build/esm/hooks/useId.js +0 -25
- package/build/esm/hooks/useId.js.map +0 -1
- package/build/esm/utils/assignRef.d.ts +0 -3
- package/build/esm/utils/assignRef.js +0 -25
- package/build/esm/utils/assignRef.js.map +0 -1
- package/build/esm/utils/getCircularIndex.d.ts +0 -1
- package/build/esm/utils/getCircularIndex.js +0 -8
- package/build/esm/utils/getCircularIndex.js.map +0 -1
- package/build/esm/utils/rubberBandClamp.d.ts +0 -2
- package/build/esm/utils/rubberBandClamp.js +0 -20
- package/build/esm/utils/rubberBandClamp.js.map +0 -1
- package/build/esm/utils/wrapEvent.d.ts +0 -3
- package/build/esm/utils/wrapEvent.js +0 -16
- package/build/esm/utils/wrapEvent.js.map +0 -1
- package/build/tsconfig.tsbuildinfo +0 -7270
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
2
|
+
const comboboxContext = /*#__PURE__*/createContext(null);
|
|
3
|
+
export const {
|
|
4
|
+
Provider: ComboBoxProvider
|
|
5
|
+
} = comboboxContext;
|
|
6
|
+
export const useComboBoxContext = () => useContext(comboboxContext);
|
|
8
7
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["createContext","useContext","comboboxContext","
|
|
1
|
+
{"version":3,"file":"context.js","names":["createContext","useContext","comboboxContext","Provider","ComboBoxProvider","useComboBoxContext"],"sources":["../../../src/ComboBox/context.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { createContext, useContext } from 'react';\n\nimport type { ActionTypes, StateTypes, ReducerState } from './hooks';\nimport type { SelectEventHandler } from './Combobox';\nimport type { Scope } from '../hooks';\n\nexport interface ComboBoxContextProps {\n data: Omit<ReducerState, 'state'>;\n inputRef: MutableRefObject<HTMLInputElement | null>;\n popoverRef: MutableRefObject<HTMLDivElement | null>;\n buttonRef: MutableRefObject<HTMLButtonElement | null>;\n onSelect?: SelectEventHandler;\n optionsRef: MutableRefObject<{\n [itemId: string]: {\n value: string | unknown;\n text: string;\n };\n }>;\n listScope: Scope<HTMLElement>;\n state: StateTypes;\n transition: (action: ActionTypes, payload?: any) => void;\n listboxIdRef: MutableRefObject<string | undefined>;\n labelIdRef: MutableRefObject<string | undefined>;\n autocompletePropRef: MutableRefObject<boolean>;\n persistSelectionRef: MutableRefObject<boolean>;\n clearOnEscapeRef: MutableRefObject<boolean>;\n isVisible: boolean;\n openOnFocus: boolean;\n selectOnBlur: boolean;\n}\n\nconst comboboxContext = createContext<ComboBoxContextProps>(null as any);\nexport const { Provider: ComboBoxProvider } = comboboxContext;\nexport const useComboBoxContext = () => useContext(comboboxContext);\n"],"mappings":"AACA,SAASA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AA+BjD,MAAMC,eAAe,gBAAGF,aAAa,CAAuB,IAAW,CAAC;AACxE,OAAO,MAAM;EAAEG,QAAQ,EAAEC;AAAiB,CAAC,GAAGF,eAAe;AAC7D,OAAO,MAAMG,kBAAkB,GAAGA,CAAA,KAAMJ,UAAU,CAACC,eAAe,CAAC","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@ import type { StateChart as GenericStateChart, StateMachineState } from '../hook
|
|
|
3
3
|
export declare const IDLE = "IDLE";
|
|
4
4
|
declare const SUGGESTING = "SUGGESTING";
|
|
5
5
|
export declare const NAVIGATING = "NAVIGATING";
|
|
6
|
-
export
|
|
6
|
+
export type StateTypes = typeof IDLE | typeof SUGGESTING | typeof NAVIGATING;
|
|
7
7
|
export declare const INIT = "INIT";
|
|
8
8
|
export declare const CLEAR = "CLEAR";
|
|
9
9
|
export declare const CLEAR_SELECTION = "CLEAR_SELECTION";
|
|
@@ -16,7 +16,7 @@ declare const BLUR = "BLUR";
|
|
|
16
16
|
export declare const FOCUS = "FOCUS";
|
|
17
17
|
export declare const OPEN_WITH_BUTTON = "OPEN_WITH_BUTTON";
|
|
18
18
|
export declare const CLOSE_WITH_BUTTON = "CLOSE_WITH_BUTTON";
|
|
19
|
-
export
|
|
19
|
+
export type ActionTypes = typeof CLEAR | typeof CLEAR_SELECTION | typeof CHANGE | typeof INIT | typeof NAVIGATE | typeof SELECT_WITH_KEYBOARD | typeof SELECT_WITH_CLICK | typeof ESCAPE | typeof BLUR | typeof FOCUS | typeof OPEN_WITH_BUTTON | typeof CLOSE_WITH_BUTTON;
|
|
20
20
|
export declare const stateChart: GenericStateChart<StateTypes, ActionTypes>;
|
|
21
21
|
export interface ReducerState extends StateMachineState<StateTypes, ActionTypes> {
|
|
22
22
|
item: string;
|
|
@@ -1,174 +1,206 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
|
|
4
|
-
var _on, _on2, _on3, _states;
|
|
5
|
-
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
7
|
-
|
|
8
|
-
/* eslint-disable default-case */
|
|
9
1
|
import { useEffect } from 'react';
|
|
10
2
|
import { getCircularIndex } from '../utils/get-circular-index';
|
|
11
3
|
import { useComboBoxContext } from './context';
|
|
12
|
-
import { scopeQuery } from './scopeQuery';
|
|
4
|
+
import { scopeQuery } from './scopeQuery';
|
|
5
|
+
|
|
6
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
13
7
|
// States
|
|
14
|
-
// Nothing going on, waiting for the user to type or use the arrow keys
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
// Nothing going on, waiting for the user to type or use the arrow keys
|
|
10
|
+
export const IDLE = 'IDLE';
|
|
17
11
|
|
|
18
|
-
|
|
12
|
+
// The component is suggesting options as the user types
|
|
13
|
+
const SUGGESTING = 'SUGGESTING';
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
// The user is using the keyboard to navigate the list, not typing
|
|
16
|
+
export const NAVIGATING = 'NAVIGATING';
|
|
21
17
|
////////////////////////////////////////////////////////////////////////////////
|
|
22
18
|
// Actions:
|
|
23
|
-
// Used to sync the state with controlled state, right after mounting
|
|
24
|
-
export var INIT = 'INIT'; // User cleared the value w/ backspace, but input still has focus
|
|
25
19
|
|
|
26
|
-
|
|
20
|
+
// Used to sync the state with controlled state, right after mounting
|
|
21
|
+
export const INIT = 'INIT';
|
|
27
22
|
|
|
28
|
-
|
|
23
|
+
// User cleared the value w/ backspace, but input still has focus
|
|
24
|
+
export const CLEAR = 'CLEAR';
|
|
29
25
|
|
|
30
|
-
|
|
26
|
+
// User cleared the value w/ backspace, but input still has focus
|
|
27
|
+
export const CLEAR_SELECTION = 'CLEAR_SELECTION';
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
// User is typing
|
|
30
|
+
export const CHANGE = 'CHANGE';
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
export
|
|
32
|
+
// User is navigating w/ the keyboard
|
|
33
|
+
export const NAVIGATE = 'NAVIGATE';
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export
|
|
42
|
-
|
|
35
|
+
// User can be navigating with keyboard and then click instead, we want the
|
|
36
|
+
// value from the click, not the current nav item
|
|
37
|
+
const SELECT_WITH_KEYBOARD = 'SELECT_WITH_KEYBOARD';
|
|
38
|
+
export const SELECT_WITH_CLICK = 'SELECT_WITH_CLICK';
|
|
39
|
+
|
|
40
|
+
// Pretty self-explanatory, user can hit escape or blur to close the popover
|
|
41
|
+
const ESCAPE = 'ESCAPE';
|
|
42
|
+
const BLUR = 'BLUR';
|
|
43
|
+
export const FOCUS = 'FOCUS';
|
|
44
|
+
export const OPEN_WITH_BUTTON = 'OPEN_WITH_BUTTON';
|
|
45
|
+
export const CLOSE_WITH_BUTTON = 'CLOSE_WITH_BUTTON';
|
|
43
46
|
////////////////////////////////////////////////////////////////////////////////
|
|
44
|
-
export
|
|
47
|
+
export const stateChart = {
|
|
45
48
|
initial: IDLE,
|
|
46
|
-
states:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
states: {
|
|
50
|
+
[IDLE]: {
|
|
51
|
+
on: {
|
|
52
|
+
[BLUR]: IDLE,
|
|
53
|
+
[CLEAR]: IDLE,
|
|
54
|
+
[INIT]: IDLE,
|
|
55
|
+
[CLEAR_SELECTION]: IDLE,
|
|
56
|
+
[CHANGE]: SUGGESTING,
|
|
57
|
+
[FOCUS]: SUGGESTING,
|
|
58
|
+
[NAVIGATE]: NAVIGATING,
|
|
59
|
+
[OPEN_WITH_BUTTON]: SUGGESTING
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
[SUGGESTING]: {
|
|
63
|
+
on: {
|
|
64
|
+
[CHANGE]: SUGGESTING,
|
|
65
|
+
[FOCUS]: SUGGESTING,
|
|
66
|
+
[INIT]: SUGGESTING,
|
|
67
|
+
[NAVIGATE]: NAVIGATING,
|
|
68
|
+
[CLEAR]: IDLE,
|
|
69
|
+
[CLEAR_SELECTION]: SUGGESTING,
|
|
70
|
+
[ESCAPE]: IDLE,
|
|
71
|
+
[BLUR]: IDLE,
|
|
72
|
+
[SELECT_WITH_CLICK]: IDLE,
|
|
73
|
+
[CLOSE_WITH_BUTTON]: IDLE
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
[NAVIGATING]: {
|
|
77
|
+
on: {
|
|
78
|
+
[CHANGE]: SUGGESTING,
|
|
79
|
+
[FOCUS]: SUGGESTING,
|
|
80
|
+
[INIT]: NAVIGATING,
|
|
81
|
+
[CLEAR]: IDLE,
|
|
82
|
+
[CLEAR_SELECTION]: NAVIGATING,
|
|
83
|
+
[BLUR]: IDLE,
|
|
84
|
+
[ESCAPE]: IDLE,
|
|
85
|
+
[NAVIGATE]: NAVIGATING,
|
|
86
|
+
[SELECT_WITH_KEYBOARD]: IDLE,
|
|
87
|
+
[SELECT_WITH_CLICK]: IDLE,
|
|
88
|
+
[CLOSE_WITH_BUTTON]: IDLE
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
53
92
|
};
|
|
54
93
|
export function comboboxReducer(data, action) {
|
|
55
|
-
|
|
94
|
+
const nextState = {
|
|
95
|
+
...data,
|
|
56
96
|
state: action.nextState,
|
|
57
97
|
lastActionType: action.type
|
|
58
|
-
}
|
|
59
|
-
|
|
98
|
+
};
|
|
60
99
|
switch (action.type) {
|
|
61
100
|
case INIT:
|
|
62
101
|
case CHANGE:
|
|
63
|
-
return
|
|
102
|
+
return {
|
|
103
|
+
...nextState,
|
|
64
104
|
text: action.text,
|
|
65
105
|
navigationItem: '',
|
|
66
106
|
item: ''
|
|
67
|
-
}
|
|
68
|
-
|
|
107
|
+
};
|
|
69
108
|
case NAVIGATE:
|
|
70
109
|
case OPEN_WITH_BUTTON:
|
|
71
110
|
if (action.persistSelection) {
|
|
72
|
-
return
|
|
111
|
+
return {
|
|
112
|
+
...nextState,
|
|
73
113
|
navigationItem: data.item
|
|
74
|
-
}
|
|
114
|
+
};
|
|
75
115
|
}
|
|
76
|
-
|
|
77
|
-
|
|
116
|
+
return {
|
|
117
|
+
...nextState,
|
|
78
118
|
navigationItem: action.item
|
|
79
|
-
}
|
|
80
|
-
|
|
119
|
+
};
|
|
81
120
|
case CLEAR_SELECTION:
|
|
82
|
-
return
|
|
121
|
+
return {
|
|
122
|
+
...nextState,
|
|
83
123
|
navigationItem: ''
|
|
84
|
-
}
|
|
85
|
-
|
|
124
|
+
};
|
|
86
125
|
case CLEAR:
|
|
87
|
-
return
|
|
126
|
+
return {
|
|
127
|
+
...nextState,
|
|
88
128
|
text: '',
|
|
89
129
|
navigationItem: '',
|
|
90
130
|
item: ''
|
|
91
|
-
}
|
|
92
|
-
|
|
131
|
+
};
|
|
93
132
|
case BLUR:
|
|
94
|
-
return
|
|
133
|
+
return {
|
|
134
|
+
...nextState,
|
|
95
135
|
text: action.text,
|
|
96
136
|
navigationItem: '',
|
|
97
137
|
item: action.item
|
|
98
|
-
}
|
|
99
|
-
|
|
138
|
+
};
|
|
100
139
|
case CLOSE_WITH_BUTTON:
|
|
101
140
|
case ESCAPE:
|
|
102
|
-
return
|
|
141
|
+
return {
|
|
142
|
+
...nextState,
|
|
103
143
|
navigationItem: '',
|
|
104
144
|
item: ''
|
|
105
|
-
}
|
|
106
|
-
|
|
145
|
+
};
|
|
107
146
|
case SELECT_WITH_CLICK:
|
|
108
147
|
case SELECT_WITH_KEYBOARD:
|
|
109
|
-
return
|
|
148
|
+
return {
|
|
149
|
+
...nextState,
|
|
110
150
|
text: action.text,
|
|
111
151
|
item: action.item,
|
|
112
152
|
navigationItem: ''
|
|
113
|
-
}
|
|
114
|
-
|
|
153
|
+
};
|
|
115
154
|
case FOCUS:
|
|
116
|
-
return
|
|
155
|
+
return {
|
|
156
|
+
...nextState,
|
|
117
157
|
navigationItem: action.item
|
|
118
|
-
}
|
|
119
|
-
|
|
158
|
+
};
|
|
120
159
|
default:
|
|
121
|
-
throw new Error(
|
|
160
|
+
throw new Error(`Unknown action ${action.type}`);
|
|
122
161
|
}
|
|
123
162
|
}
|
|
124
|
-
|
|
125
|
-
export
|
|
126
|
-
|
|
127
|
-
|
|
163
|
+
const visibleStates = [SUGGESTING, NAVIGATING];
|
|
164
|
+
export const isVisible = state => visibleStates.indexOf(state) >= 0;
|
|
165
|
+
|
|
166
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
128
167
|
// The rest is all implementation details
|
|
168
|
+
|
|
129
169
|
// Move focus back to the input if we start navigating w/ the
|
|
130
170
|
// keyboard after focus has moved to any focusable content in
|
|
131
171
|
// the popup.
|
|
132
|
-
|
|
133
172
|
export function useFocusManagement(lastActionType, inputRef) {
|
|
134
173
|
// useEffect so that the cursor goes to the end of the input instead
|
|
135
174
|
// of awkwardly at the beginning, unclear to me why ...
|
|
136
|
-
useEffect(
|
|
175
|
+
useEffect(() => {
|
|
137
176
|
if (lastActionType === NAVIGATE || lastActionType === ESCAPE || lastActionType === SELECT_WITH_CLICK || lastActionType === OPEN_WITH_BUTTON) {
|
|
138
177
|
inputRef.current && inputRef.current.focus();
|
|
139
178
|
}
|
|
140
179
|
});
|
|
141
180
|
}
|
|
142
|
-
|
|
143
181
|
function getNextItem(currentItem, key, optionsItems, autocomplete) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
182
|
+
const jumpToStartOrEnd = key === 'Home' || key === 'End';
|
|
183
|
+
let incr = 1;
|
|
147
184
|
switch (key) {
|
|
148
185
|
case 'PageUp':
|
|
149
186
|
incr = -10;
|
|
150
187
|
break;
|
|
151
|
-
|
|
152
188
|
case 'PageDown':
|
|
153
189
|
incr = 10;
|
|
154
190
|
break;
|
|
155
|
-
|
|
156
191
|
case 'End':
|
|
157
192
|
case 'ArrowUp':
|
|
158
193
|
incr = -1;
|
|
159
194
|
break;
|
|
160
|
-
|
|
161
195
|
case 'Home':
|
|
162
196
|
case 'ArrowDown':
|
|
163
197
|
incr = 1;
|
|
164
198
|
break;
|
|
165
199
|
}
|
|
200
|
+
const index = currentItem === '' ? -1 : optionsItems.findIndex(n => String(n.id) === currentItem);
|
|
201
|
+
const optionsLen = optionsItems.length;
|
|
166
202
|
|
|
167
|
-
|
|
168
|
-
return String(n.id) === currentItem;
|
|
169
|
-
});
|
|
170
|
-
var optionsLen = optionsItems.length; // Nothing selected, either go to start, or end
|
|
171
|
-
|
|
203
|
+
// Nothing selected, either go to start, or end
|
|
172
204
|
if (index < 0 || jumpToStartOrEnd) {
|
|
173
205
|
if (incr > 0) {
|
|
174
206
|
// Go to start
|
|
@@ -178,39 +210,37 @@ function getNextItem(currentItem, key, optionsItems, autocomplete) {
|
|
|
178
210
|
return optionsItems[optionsLen - 1];
|
|
179
211
|
}
|
|
180
212
|
} else if (autocomplete) {
|
|
181
|
-
|
|
182
|
-
|
|
213
|
+
const nextIndex = index + incr;
|
|
183
214
|
if (nextIndex < 0 || nextIndex >= optionsLen) {
|
|
184
215
|
// Next is outside the bounds of list, return nothing selected
|
|
185
216
|
return null;
|
|
186
217
|
}
|
|
187
|
-
}
|
|
188
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
189
|
-
|
|
218
|
+
}
|
|
190
219
|
|
|
220
|
+
// I'm sure it won't be null, we already check optionsLen above
|
|
191
221
|
return optionsItems[getCircularIndex(index + incr, optionsLen)];
|
|
192
|
-
}
|
|
193
|
-
// HOOKS BTW?) This is probably the hairiest piece but it's not bad.
|
|
194
|
-
|
|
222
|
+
}
|
|
195
223
|
|
|
224
|
+
// We want the same events when the input or the popup have focus (HOW COOL ARE
|
|
225
|
+
// HOOKS BTW?) This is probably the hairiest piece but it's not bad.
|
|
196
226
|
export function useKeyDown() {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
text
|
|
200
|
-
navigationItem
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
227
|
+
const {
|
|
228
|
+
data: {
|
|
229
|
+
text,
|
|
230
|
+
navigationItem
|
|
231
|
+
},
|
|
232
|
+
onSelect,
|
|
233
|
+
optionsRef,
|
|
234
|
+
inputRef,
|
|
235
|
+
state,
|
|
236
|
+
transition,
|
|
237
|
+
autocompletePropRef,
|
|
238
|
+
clearOnEscapeRef,
|
|
239
|
+
persistSelectionRef,
|
|
240
|
+
listScope
|
|
241
|
+
} = useComboBoxContext();
|
|
211
242
|
return function handleKeyDown(event) {
|
|
212
|
-
|
|
213
|
-
|
|
243
|
+
const optionNodes = listScope.current.queryAllNodes(scopeQuery);
|
|
214
244
|
switch (event.key) {
|
|
215
245
|
case 'Home':
|
|
216
246
|
case 'End':
|
|
@@ -221,14 +251,14 @@ export function useKeyDown() {
|
|
|
221
251
|
{
|
|
222
252
|
// Don't scroll the page
|
|
223
253
|
event.preventDefault();
|
|
224
|
-
|
|
254
|
+
const optionsLen = optionNodes.length;
|
|
255
|
+
|
|
256
|
+
// If the developer didn't render any options, there's no point in
|
|
225
257
|
// trying to navigate--but seriously what the heck? Give us some
|
|
226
258
|
// options fam.
|
|
227
|
-
|
|
228
259
|
if (optionsLen === 0) {
|
|
229
260
|
return;
|
|
230
261
|
}
|
|
231
|
-
|
|
232
262
|
if (state === IDLE) {
|
|
233
263
|
// Opening a closed list
|
|
234
264
|
transition(NAVIGATE, {
|
|
@@ -236,10 +266,10 @@ export function useKeyDown() {
|
|
|
236
266
|
});
|
|
237
267
|
} else {
|
|
238
268
|
// When autocompletting, we'll not cycle through the list directly
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
var nextItem = getNextItem(navigationItem, event.key, optionNodes, autocomplete);
|
|
269
|
+
const autocomplete = autocompletePropRef.current;
|
|
242
270
|
|
|
271
|
+
// Get next selected item
|
|
272
|
+
const nextItem = getNextItem(navigationItem, event.key, optionNodes, autocomplete);
|
|
243
273
|
if (nextItem !== null) {
|
|
244
274
|
nextItem.scrollIntoView({
|
|
245
275
|
behavior: 'auto',
|
|
@@ -256,10 +286,8 @@ export function useKeyDown() {
|
|
|
256
286
|
});
|
|
257
287
|
}
|
|
258
288
|
}
|
|
259
|
-
|
|
260
289
|
break;
|
|
261
290
|
}
|
|
262
|
-
|
|
263
291
|
case 'Escape':
|
|
264
292
|
{
|
|
265
293
|
if (state !== IDLE) {
|
|
@@ -267,34 +295,31 @@ export function useKeyDown() {
|
|
|
267
295
|
} else if (state === IDLE && text !== '') {
|
|
268
296
|
if (!inputRef.current || !clearOnEscapeRef.current) {
|
|
269
297
|
break;
|
|
270
|
-
}
|
|
271
|
-
|
|
298
|
+
}
|
|
272
299
|
|
|
273
|
-
|
|
300
|
+
// emulate a inputRef change event, might not work in future versions of React
|
|
301
|
+
const lastValue = inputRef.current.value;
|
|
274
302
|
inputRef.current.value = '';
|
|
275
|
-
|
|
276
|
-
|
|
303
|
+
const tracker = inputRef.current._valueTracker;
|
|
277
304
|
if (tracker) {
|
|
278
305
|
tracker.setValue(lastValue);
|
|
279
306
|
}
|
|
280
|
-
|
|
281
|
-
var _event = new Event('change', {
|
|
307
|
+
const event = new Event('change', {
|
|
282
308
|
bubbles: true
|
|
283
309
|
});
|
|
284
|
-
|
|
285
|
-
inputRef.current.dispatchEvent(_event);
|
|
310
|
+
inputRef.current.dispatchEvent(event);
|
|
286
311
|
}
|
|
287
|
-
|
|
288
312
|
break;
|
|
289
313
|
}
|
|
290
|
-
|
|
291
314
|
case 'Enter':
|
|
292
315
|
{
|
|
293
316
|
if (state === NAVIGATING && navigationItem !== '') {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
317
|
+
const {
|
|
318
|
+
value: navigationValue,
|
|
319
|
+
text: navigationText
|
|
320
|
+
} = optionsRef.current[navigationItem];
|
|
297
321
|
|
|
322
|
+
// don't want to submit forms
|
|
298
323
|
event.preventDefault();
|
|
299
324
|
onSelect && onSelect(navigationText, navigationItem, navigationValue);
|
|
300
325
|
transition(SELECT_WITH_KEYBOARD, {
|
|
@@ -302,30 +327,31 @@ export function useKeyDown() {
|
|
|
302
327
|
item: navigationItem
|
|
303
328
|
});
|
|
304
329
|
}
|
|
305
|
-
|
|
306
330
|
break;
|
|
307
331
|
}
|
|
308
332
|
}
|
|
309
333
|
};
|
|
310
334
|
}
|
|
311
335
|
export function useBlur() {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
navigationItem
|
|
315
|
-
stateText
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
336
|
+
const {
|
|
337
|
+
data: {
|
|
338
|
+
navigationItem,
|
|
339
|
+
text: stateText
|
|
340
|
+
},
|
|
341
|
+
transition,
|
|
342
|
+
optionsRef,
|
|
343
|
+
popoverRef,
|
|
344
|
+
inputRef,
|
|
345
|
+
buttonRef,
|
|
346
|
+
onSelect,
|
|
347
|
+
selectOnBlur // not implemented yet
|
|
348
|
+
} = useComboBoxContext();
|
|
324
349
|
return function handleBlur() {
|
|
325
|
-
requestAnimationFrame(
|
|
350
|
+
requestAnimationFrame(() => {
|
|
326
351
|
// we on want to close only if focus rests outside the combobox
|
|
327
352
|
if (document.activeElement !== inputRef.current && document.activeElement !== buttonRef.current && popoverRef.current) {
|
|
328
|
-
if (popoverRef.current.contains(document.activeElement)) {
|
|
353
|
+
if (popoverRef.current.contains(document.activeElement)) {
|
|
354
|
+
// focus landed inside the combobox, keep it open
|
|
329
355
|
// in the future, we can make it not close, select, or anything
|
|
330
356
|
// this way we can have like... checkboxes available in the
|
|
331
357
|
// menu item, etc.
|
|
@@ -339,9 +365,10 @@ export function useBlur() {
|
|
|
339
365
|
});
|
|
340
366
|
} else {
|
|
341
367
|
// select the currently selected item
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
368
|
+
const {
|
|
369
|
+
value: navigationValue,
|
|
370
|
+
text: navigationText
|
|
371
|
+
} = optionsRef.current[navigationItem];
|
|
345
372
|
onSelect && onSelect(navigationText, navigationItem, navigationValue);
|
|
346
373
|
transition(BLUR, {
|
|
347
374
|
text: navigationText,
|