@basic-ui/core 0.0.40 → 0.0.43
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 +1312 -464
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/Accordion.d.ts +7 -7
- package/build/esm/Accordion/Accordion.js +4 -4
- package/build/esm/Accordion/Accordion.js.map +1 -1
- package/build/esm/Accordion/AccordionBody.d.ts +5 -5
- package/build/esm/Accordion/AccordionBody.js +4 -4
- package/build/esm/Accordion/AccordionBody.js.map +1 -1
- package/build/esm/Accordion/AccordionHeader.d.ts +6 -6
- package/build/esm/Accordion/AccordionHeader.js +4 -4
- package/build/esm/Accordion/AccordionHeader.js.map +1 -1
- package/build/esm/Accordion/AccordionItem.d.ts +7 -7
- package/build/esm/Accordion/AccordionItem.js +2 -2
- package/build/esm/Accordion/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/context.d.ts +3 -3
- package/build/esm/Accordion/context.js.map +1 -1
- package/build/esm/Accordion/index.d.ts +0 -0
- package/build/esm/Accordion/index.js.map +1 -1
- package/build/esm/Accordion/scopeQuery.d.ts +0 -0
- package/build/esm/Accordion/scopeQuery.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.d.ts +6 -6
- package/build/esm/CheckBox/CheckBox.js +2 -2
- package/build/esm/CheckBox/CheckBox.js.map +1 -1
- package/build/esm/CheckBox/index.d.ts +0 -0
- package/build/esm/CheckBox/index.js.map +1 -1
- package/build/esm/ComboBox/Combobox.d.ts +10 -10
- package/build/esm/ComboBox/Combobox.js +3 -3
- package/build/esm/ComboBox/Combobox.js.map +1 -1
- package/build/esm/ComboBox/ComboboxButton.d.ts +8 -8
- package/build/esm/ComboBox/ComboboxButton.js +4 -4
- package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
- package/build/esm/ComboBox/ComboboxInput.d.ts +10 -10
- package/build/esm/ComboBox/ComboboxInput.js +3 -3
- package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
- package/build/esm/ComboBox/ComboboxLabel.d.ts +5 -5
- package/build/esm/ComboBox/ComboboxLabel.js +2 -2
- package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
- package/build/esm/ComboBox/ComboboxList.d.ts +6 -6
- package/build/esm/ComboBox/ComboboxList.js +3 -3
- package/build/esm/ComboBox/ComboboxList.js.map +1 -1
- package/build/esm/ComboBox/ComboboxOption.d.ts +7 -7
- package/build/esm/ComboBox/ComboboxOption.js +4 -4
- package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
- package/build/esm/ComboBox/ComboboxPopover.d.ts +8 -8
- package/build/esm/ComboBox/ComboboxPopover.js +5 -5
- package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
- package/build/esm/ComboBox/cities.d.ts +0 -0
- package/build/esm/ComboBox/cities.js.map +1 -1
- package/build/esm/ComboBox/context.d.ts +10 -10
- package/build/esm/ComboBox/context.js.map +1 -1
- package/build/esm/ComboBox/hooks.d.ts +3 -3
- package/build/esm/ComboBox/hooks.js +11 -11
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/ComboBox/index.d.ts +0 -0
- package/build/esm/ComboBox/index.js.map +1 -1
- package/build/esm/ComboBox/makeHash.d.ts +0 -0
- package/build/esm/ComboBox/makeHash.js.map +1 -1
- package/build/esm/ComboBox/scopeQuery.d.ts +0 -0
- package/build/esm/ComboBox/scopeQuery.js.map +1 -1
- package/build/esm/FocusLock/FocusLock.d.ts +7 -7
- package/build/esm/FocusLock/FocusLock.js +2 -2
- package/build/esm/FocusLock/FocusLock.js.map +1 -1
- package/build/esm/FocusLock/index.d.ts +0 -0
- package/build/esm/FocusLock/index.js.map +1 -1
- package/build/esm/FocusLock/tabUtils.d.ts +0 -0
- package/build/esm/FocusLock/tabUtils.js.map +1 -1
- package/build/esm/FocusLock/useFocusLock.d.ts +4 -4
- package/build/esm/FocusLock/useFocusLock.js.map +1 -1
- package/build/esm/List/List.d.ts +6 -6
- package/build/esm/List/List.js +2 -2
- package/build/esm/List/List.js.map +1 -1
- package/build/esm/List/ListItem.d.ts +6 -6
- package/build/esm/List/ListItem.js +2 -2
- package/build/esm/List/ListItem.js.map +1 -1
- package/build/esm/List/context.d.ts +0 -0
- package/build/esm/List/context.js.map +1 -1
- package/build/esm/List/index.d.ts +0 -0
- package/build/esm/List/index.js.map +1 -1
- package/build/esm/Menu/Menu.d.ts +6 -6
- package/build/esm/Menu/Menu.js +2 -2
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuButton.d.ts +10 -10
- package/build/esm/Menu/MenuButton.js +3 -3
- package/build/esm/Menu/MenuButton.js.map +1 -1
- package/build/esm/Menu/MenuItem.d.ts +6 -6
- package/build/esm/Menu/MenuItem.js +4 -4
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.d.ts +5 -5
- package/build/esm/Menu/MenuList.js +6 -6
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.d.ts +5 -5
- package/build/esm/Menu/MenuPopover.js +2 -2
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +2 -2
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Menu/index.d.ts +0 -0
- package/build/esm/Menu/index.js.map +1 -1
- package/build/esm/Menu/scope.d.ts +0 -0
- package/build/esm/Menu/scope.js.map +1 -1
- package/build/esm/Modal/Modal.d.ts +6 -7
- package/build/esm/Modal/Modal.js +5 -5
- package/build/esm/Modal/Modal.js.map +1 -1
- package/build/esm/Modal/ModalBackdrop.d.ts +6 -6
- package/build/esm/Modal/ModalBackdrop.js +6 -6
- package/build/esm/Modal/ModalBackdrop.js.map +1 -1
- package/build/esm/Modal/index.d.ts +0 -0
- package/build/esm/Modal/index.js.map +1 -1
- package/build/esm/Popper/Popper.d.ts +7 -7
- package/build/esm/Popper/Popper.js +6 -6
- package/build/esm/Popper/Popper.js.map +1 -1
- package/build/esm/Popper/PopperArrow.d.ts +5 -5
- package/build/esm/Popper/PopperArrow.js +5 -6
- package/build/esm/Popper/PopperArrow.js.map +1 -1
- package/build/esm/Popper/context.d.ts +0 -0
- package/build/esm/Popper/context.js.map +1 -1
- package/build/esm/Popper/index.d.ts +0 -0
- package/build/esm/Popper/index.js.map +1 -1
- package/build/esm/Portal/Portal.d.ts +0 -0
- package/build/esm/Portal/Portal.js.map +1 -1
- package/build/esm/Portal/index.d.ts +0 -0
- package/build/esm/Portal/index.js.map +1 -1
- package/build/esm/RadioButton/RadioButton.d.ts +6 -6
- package/build/esm/RadioButton/RadioButton.js +5 -3
- package/build/esm/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/RadioButton/RadioGroup.d.ts +7 -7
- package/build/esm/RadioButton/RadioGroup.js +2 -2
- package/build/esm/RadioButton/RadioGroup.js.map +1 -1
- package/build/esm/RadioButton/context.d.ts +2 -2
- package/build/esm/RadioButton/context.js.map +1 -1
- package/build/esm/RadioButton/index.d.ts +0 -0
- package/build/esm/RadioButton/index.js.map +1 -1
- package/build/esm/SkipNav/SkipNav.d.ts +6 -6
- package/build/esm/SkipNav/SkipNav.js +2 -2
- package/build/esm/SkipNav/SkipNav.js.map +1 -1
- package/build/esm/SkipNav/index.d.ts +0 -0
- package/build/esm/SkipNav/index.js.map +1 -1
- package/build/esm/Slider/Slider.d.ts +218 -0
- package/build/esm/Slider/Slider.js +842 -0
- package/build/esm/Slider/Slider.js.map +1 -0
- package/build/esm/Slider/index.d.ts +1 -0
- package/build/esm/Slider/index.js +2 -0
- package/build/esm/Slider/index.js.map +1 -0
- package/build/esm/Spinner/Spinner.d.ts +7 -7
- package/build/esm/Spinner/Spinner.js +2 -2
- package/build/esm/Spinner/Spinner.js.map +1 -1
- package/build/esm/Spinner/SpinnerButton.d.ts +6 -6
- package/build/esm/Spinner/SpinnerButton.js +3 -3
- package/build/esm/Spinner/SpinnerButton.js.map +1 -1
- package/build/esm/Spinner/context.d.ts +2 -2
- package/build/esm/Spinner/context.js.map +1 -1
- package/build/esm/Spinner/index.d.ts +0 -0
- package/build/esm/Spinner/index.js.map +1 -1
- package/build/esm/Tabs/Tab.d.ts +6 -6
- package/build/esm/Tabs/Tab.js +3 -3
- package/build/esm/Tabs/Tab.js.map +1 -1
- package/build/esm/Tabs/TabList.d.ts +6 -6
- package/build/esm/Tabs/TabList.js +4 -4
- package/build/esm/Tabs/TabList.js.map +1 -1
- package/build/esm/Tabs/TabPanel.d.ts +6 -6
- package/build/esm/Tabs/TabPanel.js +4 -4
- package/build/esm/Tabs/TabPanel.js.map +1 -1
- package/build/esm/Tabs/TabPanels.d.ts +5 -5
- package/build/esm/Tabs/TabPanels.js +4 -4
- package/build/esm/Tabs/TabPanels.js.map +1 -1
- package/build/esm/Tabs/Tabs.d.ts +6 -6
- package/build/esm/Tabs/Tabs.js +2 -2
- package/build/esm/Tabs/Tabs.js.map +1 -1
- package/build/esm/Tabs/context.d.ts +2 -2
- package/build/esm/Tabs/context.js.map +1 -1
- package/build/esm/Tabs/index.d.ts +0 -0
- package/build/esm/Tabs/index.js.map +1 -1
- package/build/esm/Tabs/scopeQuery.d.ts +0 -0
- package/build/esm/Tabs/scopeQuery.js.map +1 -1
- package/build/esm/Tooltip/Tooltip.d.ts +7 -8
- package/build/esm/Tooltip/Tooltip.js +5 -3
- package/build/esm/Tooltip/Tooltip.js.map +1 -1
- package/build/esm/Tooltip/index.d.ts +0 -0
- package/build/esm/Tooltip/index.js.map +1 -1
- package/build/esm/Tooltip/stateMachine.d.ts +0 -0
- package/build/esm/Tooltip/stateMachine.js +9 -9
- package/build/esm/Tooltip/stateMachine.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +7 -7
- package/build/esm/Tooltip/useTooltip.js +6 -5
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/index.d.ts +0 -0
- package/build/esm/hooks/index.js.map +1 -1
- package/build/esm/hooks/useAutoFocus.d.ts +2 -2
- package/build/esm/hooks/useAutoFocus.js.map +1 -1
- package/build/esm/hooks/useChildrenCounter.d.ts +0 -0
- package/build/esm/hooks/useChildrenCounter.js.map +1 -1
- package/build/esm/hooks/useControlledState.d.ts +2 -6
- package/build/esm/hooks/useControlledState.js +8 -7
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/hooks/useFocusReturn.d.ts +0 -0
- package/build/esm/hooks/useFocusReturn.js +2 -2
- package/build/esm/hooks/useFocusReturn.js.map +1 -1
- package/build/esm/hooks/useFocusState.d.ts +5 -5
- package/build/esm/hooks/useFocusState.js +1 -1
- package/build/esm/hooks/useFocusState.js.map +1 -1
- package/build/esm/hooks/useGestureHandlers.d.ts +5 -5
- package/build/esm/hooks/useGestureHandlers.js +23 -15
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/esm/hooks/useMeasure.d.ts +2 -2
- package/build/esm/hooks/useMeasure.js +0 -1
- package/build/esm/hooks/useMeasure.js.map +1 -1
- package/build/esm/hooks/useOnClickOutside.d.ts +2 -2
- package/build/esm/hooks/useOnClickOutside.js.map +1 -1
- package/build/esm/hooks/useOnKeyDown.d.ts +1 -1
- package/build/esm/hooks/useOnKeyDown.js +5 -5
- package/build/esm/hooks/useOnKeyDown.js.map +1 -1
- package/build/esm/hooks/useReducerMachine.d.ts +0 -0
- package/build/esm/hooks/useReducerMachine.js +2 -1
- package/build/esm/hooks/useReducerMachine.js.map +1 -1
- package/build/esm/hooks/useRemoveBodyScroll.d.ts +2 -1
- package/build/esm/hooks/useRemoveBodyScroll.js +12 -8
- package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
- package/build/esm/hooks/useScope.d.ts +0 -0
- package/build/esm/hooks/useScope.js.map +1 -1
- package/build/esm/hooks/useThrottle.d.ts +0 -0
- package/build/esm/hooks/useThrottle.js.map +1 -1
- package/build/esm/index.d.ts +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/utils/assign-ref.d.ts +3 -0
- package/build/esm/utils/{assignRef.js → assign-ref.js} +1 -1
- package/build/esm/utils/assign-ref.js.map +1 -0
- package/build/esm/utils/can-use-dom.d.ts +1 -0
- package/build/esm/utils/can-use-dom.js +4 -0
- package/build/esm/utils/can-use-dom.js.map +1 -0
- package/build/esm/utils/clamp.d.ts +0 -0
- package/build/esm/utils/clamp.js.map +1 -1
- package/build/esm/utils/context.d.ts +7 -0
- package/build/esm/utils/context.js +41 -0
- package/build/esm/utils/context.js.map +1 -0
- package/build/esm/utils/{createSubscription.d.ts → create-subscription.d.ts} +0 -0
- package/build/esm/utils/{createSubscription.js → create-subscription.js} +1 -1
- package/build/esm/utils/create-subscription.js.map +1 -0
- package/build/esm/utils/{getCircularIndex.d.ts → get-circular-index.d.ts} +0 -0
- package/build/esm/utils/{getCircularIndex.js → get-circular-index.js} +1 -1
- package/build/esm/utils/get-circular-index.js.map +1 -0
- package/build/esm/utils/index.d.ts +10 -4
- package/build/esm/utils/index.js +10 -4
- package/build/esm/utils/index.js.map +1 -1
- package/build/esm/utils/is-right-click.d.ts +6 -0
- package/build/esm/utils/is-right-click.js +9 -0
- package/build/esm/utils/is-right-click.js.map +1 -0
- package/build/esm/utils/owner-document.d.ts +7 -0
- package/build/esm/utils/owner-document.js +12 -0
- package/build/esm/utils/owner-document.js.map +1 -0
- package/build/esm/utils/polymorphic.d.ts +32 -0
- package/build/esm/utils/polymorphic.js +2 -0
- package/build/esm/utils/polymorphic.js.map +1 -0
- package/build/esm/utils/{rubberBandClamp.d.ts → rubber-band-clamp.d.ts} +0 -0
- package/build/esm/utils/{rubberBandClamp.js → rubber-band-clamp.js} +1 -1
- package/build/esm/utils/rubber-band-clamp.js.map +1 -0
- package/build/esm/utils/use-stable-callback.d.ts +16 -0
- package/build/esm/utils/use-stable-callback.js +43 -0
- package/build/esm/utils/use-stable-callback.js.map +1 -0
- package/build/esm/utils/wrap-event.d.ts +3 -0
- package/build/esm/utils/{wrapEvent.js → wrap-event.js} +1 -1
- package/build/esm/utils/wrap-event.js.map +1 -0
- package/build/tsconfig-build.tsbuildinfo +1 -0
- package/package.json +5 -6
- package/src/Accordion/Accordion.tsx +12 -6
- package/src/Accordion/AccordionBody.tsx +4 -5
- package/src/Accordion/AccordionHeader.tsx +30 -27
- package/src/Accordion/AccordionItem.tsx +12 -6
- package/src/Accordion/context.ts +3 -2
- package/src/CheckBox/CheckBox.tsx +5 -6
- package/src/ComboBox/ComboBox.story.tsx +3 -3
- package/src/ComboBox/Combobox.tsx +5 -8
- package/src/ComboBox/ComboboxButton.tsx +15 -9
- package/src/ComboBox/ComboboxInput.tsx +18 -10
- package/src/ComboBox/ComboboxLabel.tsx +4 -4
- package/src/ComboBox/ComboboxList.tsx +5 -6
- package/src/ComboBox/ComboboxOption.tsx +12 -8
- package/src/ComboBox/ComboboxPopover.tsx +15 -10
- package/src/ComboBox/context.ts +10 -9
- package/src/ComboBox/hooks.tsx +4 -3
- package/src/FocusLock/FocusLock.tsx +13 -7
- package/src/FocusLock/useFocusLock.ts +4 -3
- package/src/List/List.tsx +5 -5
- package/src/List/ListItem.tsx +5 -5
- package/src/Menu/Menu.story.tsx +2 -2
- package/src/Menu/Menu.tsx +13 -7
- package/src/Menu/MenuButton.tsx +13 -10
- package/src/Menu/MenuItem.tsx +15 -11
- package/src/Menu/MenuList.tsx +6 -6
- package/src/Menu/MenuPopover.tsx +4 -4
- package/src/Menu/context.ts +9 -4
- package/src/Modal/Modal.tsx +11 -7
- package/src/Modal/ModalBackdrop.tsx +16 -11
- package/src/Popper/Popper.tsx +7 -7
- package/src/Popper/PopperArrow.tsx +6 -8
- package/src/RadioButton/RadioButton.tsx +11 -6
- package/src/RadioButton/RadioGroup.tsx +11 -9
- package/src/RadioButton/context.ts +2 -4
- package/src/SkipNav/SkipNav.tsx +5 -5
- package/src/Slider/Slider.story.tsx +45 -0
- package/src/Slider/Slider.tsx +1106 -0
- package/src/Slider/index.ts +1 -0
- package/src/Slider/styles.css +131 -0
- package/src/Spinner/Spinner.tsx +13 -9
- package/src/Spinner/SpinnerButton.tsx +11 -6
- package/src/Spinner/context.ts +2 -3
- package/src/Tabs/Tab.tsx +13 -8
- package/src/Tabs/TabList.tsx +5 -5
- package/src/Tabs/TabPanel.tsx +5 -5
- package/src/Tabs/TabPanels.tsx +4 -4
- package/src/Tabs/Tabs.tsx +5 -7
- package/src/Tabs/context.ts +2 -3
- package/src/Tooltip/Tooltip.story.tsx +3 -3
- package/src/Tooltip/Tooltip.tsx +13 -7
- package/src/Tooltip/stateMachine.ts +9 -13
- package/src/Tooltip/useTooltip.ts +17 -11
- package/src/hooks/useAutoFocus.ts +2 -1
- package/src/hooks/useControlledState.ts +14 -14
- package/src/hooks/useFocusState.ts +4 -3
- package/src/hooks/useGestureHandlers.ts +33 -19
- package/src/hooks/useMeasure.ts +2 -2
- package/src/hooks/useOnClickOutside.ts +2 -2
- package/src/hooks/useOnKeyDown.ts +4 -3
- package/src/hooks/useRemoveBodyScroll.ts +18 -8
- package/src/index.ts +1 -0
- package/src/utils/{assignRef.ts → assign-ref.ts} +4 -4
- package/src/utils/can-use-dom.ts +7 -0
- package/src/utils/context.tsx +48 -0
- package/src/utils/{createSubscription.ts → create-subscription.ts} +0 -0
- package/src/utils/{getCircularIndex.ts → get-circular-index.ts} +0 -0
- package/src/utils/index.ts +10 -4
- package/src/utils/is-right-click.ts +14 -0
- package/src/utils/owner-document.ts +13 -0
- package/src/utils/polymorphic.ts +72 -0
- package/src/utils/{rubberBandClamp.ts → rubber-band-clamp.ts} +0 -0
- package/src/utils/use-stable-callback.ts +58 -0
- package/src/utils/wrap-event.ts +22 -0
- package/build/esm/hooks/useId.d.ts +0 -3
- package/build/esm/hooks/useId.js +0 -16
- package/build/esm/hooks/useId.js.map +0 -1
- package/build/esm/utils/assignRef.d.ts +0 -3
- package/build/esm/utils/assignRef.js.map +0 -1
- package/build/esm/utils/createSubscription.js.map +0 -1
- package/build/esm/utils/getCircularIndex.js.map +0 -1
- package/build/esm/utils/rubberBandClamp.js.map +0 -1
- package/build/esm/utils/wrapEvent.d.ts +0 -3
- package/build/esm/utils/wrapEvent.js.map +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
- package/src/utils/wrapEvent.ts +0 -20
|
@@ -0,0 +1,842 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
5
|
+
var _excluded = ["children"],
|
|
6
|
+
_excluded2 = ["aria-label", "aria-labelledby", "aria-valuetext", "as", "defaultValue", "disabled", "value", "getAriaLabel", "getAriaValueText", "handleAlignment", "max", "min", "name", "onChange", "onKeyDown", "onMouseDown", "onMouseMove", "onMouseUp", "onPointerDown", "onPointerUp", "onTouchEnd", "onTouchMove", "onTouchStart", "orientation", "step", "children"],
|
|
7
|
+
_excluded3 = ["ref"],
|
|
8
|
+
_excluded4 = ["as", "children", "style"],
|
|
9
|
+
_excluded5 = ["as", "children", "style"],
|
|
10
|
+
_excluded6 = ["as", "onBlur", "onFocus", "style", "onKeyDown"],
|
|
11
|
+
_excluded7 = ["as", "children", "style", "value"];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Welcome to @reach/slider!
|
|
15
|
+
*
|
|
16
|
+
* A UI input component where the user selects a value from within a given
|
|
17
|
+
* range. A Slider has a handle that can be moved along a track to change its
|
|
18
|
+
* value. When the user's mouse or focus is on the Slider's handle, the value
|
|
19
|
+
* can be incremented with keyboard controls.
|
|
20
|
+
*
|
|
21
|
+
* Random thoughts/notes:
|
|
22
|
+
* - Currently testing this against the behavior of the native input range
|
|
23
|
+
* element to get our slider on par. We'll explore animated and multi-handle
|
|
24
|
+
* sliders next.
|
|
25
|
+
* - We may want to research some use cases for reversed sliders in RTL
|
|
26
|
+
* languages if that's a thing
|
|
27
|
+
*
|
|
28
|
+
* @see Docs https://reach.tech/slider
|
|
29
|
+
* @see Source https://github.com/reach/reach-ui/tree/main/packages/slider
|
|
30
|
+
* @see WAI-ARIA https://www.w3.org/TR/wai-aria-practices-1.2/#slider
|
|
31
|
+
* @see Example https://github.com/Stanko/aria-progress-range-slider
|
|
32
|
+
* @see Example http://www.oaa-accessibility.org/examplep/slider1/
|
|
33
|
+
*/
|
|
34
|
+
import { forwardRef, memo, useRef, useState, useCallback, useEffect, useLayoutEffect, useId } from 'react';
|
|
35
|
+
import { createContext } from '../utils/context';
|
|
36
|
+
import { isRightClick } from '../utils/is-right-click';
|
|
37
|
+
import { getOwnerDocument } from '../utils/owner-document';
|
|
38
|
+
import { useStableLayoutCallback } from '../utils/use-stable-callback';
|
|
39
|
+
import { assignMultipleRefs, wrapEvent } from '../utils';
|
|
40
|
+
import { useControlledState } from '../hooks';
|
|
41
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
42
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
43
|
+
|
|
44
|
+
var noop = function noop() {
|
|
45
|
+
/* noop */
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
var _createContext = createContext('Slider'),
|
|
49
|
+
_createContext2 = _slicedToArray(_createContext, 2),
|
|
50
|
+
SliderProvider = _createContext2[0],
|
|
51
|
+
useSliderContext = _createContext2[1]; ////////////////////////////////////////////////////////////////////////////////
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Slider
|
|
55
|
+
*
|
|
56
|
+
* @see Docs https://reach.tech/slider#slider
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
var Slider = /*#__PURE__*/forwardRef(function Slider(_ref, forwardedRef) {
|
|
61
|
+
var children = _ref.children,
|
|
62
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
63
|
+
|
|
64
|
+
return /*#__PURE__*/_jsx(SliderInput, _extends(_extends({}, props), {}, {
|
|
65
|
+
ref: forwardedRef,
|
|
66
|
+
"data-reach-slider": "",
|
|
67
|
+
children: /*#__PURE__*/_jsxs(SliderTrack, {
|
|
68
|
+
children: [/*#__PURE__*/_jsx(SliderRange, {}), /*#__PURE__*/_jsx(SliderHandle, {}), children]
|
|
69
|
+
})
|
|
70
|
+
}));
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* @see Docs https://reach.tech/slider#slider-props
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* SliderInput
|
|
80
|
+
*
|
|
81
|
+
* The parent component of the slider interface. This is a lower level component
|
|
82
|
+
* if you need more control over styles or rendering the slider's inner
|
|
83
|
+
* components.
|
|
84
|
+
*
|
|
85
|
+
* @see Docs https://reach.tech/slider#sliderinput
|
|
86
|
+
*/
|
|
87
|
+
var SliderInput = /*#__PURE__*/forwardRef(function SliderInput(_ref2, forwardedRef) {
|
|
88
|
+
var ariaLabel = _ref2['aria-label'],
|
|
89
|
+
ariaLabelledBy = _ref2['aria-labelledby'],
|
|
90
|
+
ariaValueTextProp = _ref2['aria-valuetext'],
|
|
91
|
+
_ref2$as = _ref2.as,
|
|
92
|
+
Comp = _ref2$as === void 0 ? 'div' : _ref2$as,
|
|
93
|
+
defaultValue = _ref2.defaultValue,
|
|
94
|
+
_ref2$disabled = _ref2.disabled,
|
|
95
|
+
disabled = _ref2$disabled === void 0 ? false : _ref2$disabled,
|
|
96
|
+
controlledValue = _ref2.value,
|
|
97
|
+
getAriaLabel = _ref2.getAriaLabel,
|
|
98
|
+
getAriaValueText = _ref2.getAriaValueText,
|
|
99
|
+
_ref2$handleAlignment = _ref2.handleAlignment,
|
|
100
|
+
handleAlignment = _ref2$handleAlignment === void 0 ? 'center' : _ref2$handleAlignment,
|
|
101
|
+
_ref2$max = _ref2.max,
|
|
102
|
+
max = _ref2$max === void 0 ? 100 : _ref2$max,
|
|
103
|
+
_ref2$min = _ref2.min,
|
|
104
|
+
min = _ref2$min === void 0 ? 0 : _ref2$min,
|
|
105
|
+
name = _ref2.name,
|
|
106
|
+
onChangeProp = _ref2.onChange,
|
|
107
|
+
onKeyDown = _ref2.onKeyDown,
|
|
108
|
+
onMouseDown = _ref2.onMouseDown,
|
|
109
|
+
onMouseMove = _ref2.onMouseMove,
|
|
110
|
+
onMouseUp = _ref2.onMouseUp,
|
|
111
|
+
onPointerDown = _ref2.onPointerDown,
|
|
112
|
+
onPointerUp = _ref2.onPointerUp,
|
|
113
|
+
onTouchEnd = _ref2.onTouchEnd,
|
|
114
|
+
onTouchMove = _ref2.onTouchMove,
|
|
115
|
+
onTouchStart = _ref2.onTouchStart,
|
|
116
|
+
_ref2$orientation = _ref2.orientation,
|
|
117
|
+
orientation = _ref2$orientation === void 0 ? 'horizontal' : _ref2$orientation,
|
|
118
|
+
_ref2$step = _ref2.step,
|
|
119
|
+
step = _ref2$step === void 0 ? 1 : _ref2$step,
|
|
120
|
+
children = _ref2.children,
|
|
121
|
+
rest = _objectWithoutProperties(_ref2, _excluded2);
|
|
122
|
+
|
|
123
|
+
var touchId = useRef();
|
|
124
|
+
var fallbackId = useId();
|
|
125
|
+
var id = rest.id || fallbackId; // Track whether or not the pointer is down without updating the component
|
|
126
|
+
|
|
127
|
+
var pointerDownRef = useRef(false);
|
|
128
|
+
var trackRef = useRef(null);
|
|
129
|
+
var handleRef = useRef(null);
|
|
130
|
+
var sliderRef = useRef(null);
|
|
131
|
+
|
|
132
|
+
var _useState = useState(false),
|
|
133
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
134
|
+
hasFocus = _useState2[0],
|
|
135
|
+
setHasFocus = _useState2[1];
|
|
136
|
+
|
|
137
|
+
var _useDimensions = useDimensions(handleRef),
|
|
138
|
+
x = _useDimensions.ref,
|
|
139
|
+
handleDimensions = _objectWithoutProperties(_useDimensions, _excluded3);
|
|
140
|
+
|
|
141
|
+
var _useControlledState = useControlledState(controlledValue, onChangeProp, defaultValue || min, function (setValue) {
|
|
142
|
+
return function (e, v) {
|
|
143
|
+
return setValue(v);
|
|
144
|
+
};
|
|
145
|
+
}),
|
|
146
|
+
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
147
|
+
_value = _useControlledState2[0],
|
|
148
|
+
onChange = _useControlledState2[1];
|
|
149
|
+
|
|
150
|
+
var value = clamp(_value, min, max);
|
|
151
|
+
var trackPercent = valueToPercent(value, min, max);
|
|
152
|
+
var isVertical = orientation === 'vertical';
|
|
153
|
+
var handleSize = isVertical ? handleDimensions.height : handleDimensions.width; // TODO: Consider removing the `handleAlignment` prop
|
|
154
|
+
// We may want to use accept a `handlePosition` prop instead and let apps
|
|
155
|
+
// define their own positioning logic, similar to how we do for popovers.
|
|
156
|
+
|
|
157
|
+
var handlePosition = "calc(".concat(trackPercent, "% - ").concat(handleAlignment === 'center' ? "".concat(handleSize, "px / 2") : "".concat(handleSize, "px * ").concat(trackPercent * 0.01), ")");
|
|
158
|
+
var handlePositionRef = useRef(handlePosition);
|
|
159
|
+
useLayoutEffect(function () {
|
|
160
|
+
handlePositionRef.current = handlePosition;
|
|
161
|
+
}, [handlePosition]);
|
|
162
|
+
var getNewValueFromEvent = useCallback(function (event) {
|
|
163
|
+
return getNewValue(getPointerPosition(event, touchId), trackRef.current, {
|
|
164
|
+
step: step,
|
|
165
|
+
orientation: orientation,
|
|
166
|
+
min: min,
|
|
167
|
+
max: max
|
|
168
|
+
});
|
|
169
|
+
}, [max, min, orientation, step]); // https://www.w3.org/TR/wai-aria-practices-1.2/#slider_kbd_interaction
|
|
170
|
+
|
|
171
|
+
var handleKeyDown = useStableLayoutCallback(function (event) {
|
|
172
|
+
if (disabled) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
var newValue;
|
|
177
|
+
var tenSteps = (max - min) / 10;
|
|
178
|
+
var keyStep = step || (max - min) / 100;
|
|
179
|
+
|
|
180
|
+
switch (event.key) {
|
|
181
|
+
// Decrease the value of the slider by one step.
|
|
182
|
+
case 'ArrowLeft':
|
|
183
|
+
case 'ArrowDown':
|
|
184
|
+
newValue = value - keyStep;
|
|
185
|
+
break;
|
|
186
|
+
// Increase the value of the slider by one step
|
|
187
|
+
|
|
188
|
+
case 'ArrowRight':
|
|
189
|
+
case 'ArrowUp':
|
|
190
|
+
newValue = value + keyStep;
|
|
191
|
+
break;
|
|
192
|
+
// Decrement the slider by an amount larger than the step change made by
|
|
193
|
+
// `ArrowDown`.
|
|
194
|
+
|
|
195
|
+
case 'PageDown':
|
|
196
|
+
newValue = value - tenSteps;
|
|
197
|
+
break;
|
|
198
|
+
// Increment the slider by an amount larger than the step change made by
|
|
199
|
+
// `ArrowUp`.
|
|
200
|
+
|
|
201
|
+
case 'PageUp':
|
|
202
|
+
newValue = value + tenSteps;
|
|
203
|
+
break;
|
|
204
|
+
// Set the slider to the first allowed value in its range.
|
|
205
|
+
|
|
206
|
+
case 'Home':
|
|
207
|
+
newValue = min;
|
|
208
|
+
break;
|
|
209
|
+
// Set the slider to the last allowed value in its range.
|
|
210
|
+
|
|
211
|
+
case 'End':
|
|
212
|
+
newValue = max;
|
|
213
|
+
break;
|
|
214
|
+
|
|
215
|
+
default:
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
newValue = clamp(step ? roundValueToStep(newValue, step, min) : newValue, min, max);
|
|
220
|
+
onChange(event, newValue);
|
|
221
|
+
});
|
|
222
|
+
var ariaValueText = getAriaValueText ? getAriaValueText(value) : ariaValueTextProp;
|
|
223
|
+
|
|
224
|
+
var rangeStyle = _defineProperty({}, isVertical ? 'height' : 'width', "".concat(trackPercent, "%")); // Slide events!
|
|
225
|
+
// We will try to use pointer events if they are supported to leverage
|
|
226
|
+
// setPointerCapture and releasePointerCapture. We'll fall back to separate
|
|
227
|
+
// mouse and touch events.
|
|
228
|
+
// TODO: This could be more concise
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
var removeMoveEvents = useRef(noop);
|
|
232
|
+
var removeStartEvents = useRef(noop);
|
|
233
|
+
var removeEndEvents = useRef(noop); // Store our event handlers in refs so we aren't attaching/detaching events
|
|
234
|
+
// on every render if the user doesn't useCallback
|
|
235
|
+
|
|
236
|
+
var appEvents = useRef({
|
|
237
|
+
onMouseMove: onMouseMove,
|
|
238
|
+
onMouseDown: onMouseDown,
|
|
239
|
+
onMouseUp: onMouseUp,
|
|
240
|
+
onTouchStart: onTouchStart,
|
|
241
|
+
onTouchEnd: onTouchEnd,
|
|
242
|
+
onTouchMove: onTouchMove,
|
|
243
|
+
onPointerDown: onPointerDown,
|
|
244
|
+
onPointerUp: onPointerUp
|
|
245
|
+
});
|
|
246
|
+
useLayoutEffect(function () {
|
|
247
|
+
appEvents.current.onMouseMove = onMouseMove;
|
|
248
|
+
appEvents.current.onMouseDown = onMouseDown;
|
|
249
|
+
appEvents.current.onMouseUp = onMouseUp;
|
|
250
|
+
appEvents.current.onTouchStart = onTouchStart;
|
|
251
|
+
appEvents.current.onTouchEnd = onTouchEnd;
|
|
252
|
+
appEvents.current.onTouchMove = onTouchMove;
|
|
253
|
+
appEvents.current.onPointerDown = onPointerDown;
|
|
254
|
+
appEvents.current.onPointerUp = onPointerUp;
|
|
255
|
+
}, [onMouseMove, onMouseDown, onMouseUp, onTouchStart, onTouchEnd, onTouchMove, onPointerDown, onPointerUp]);
|
|
256
|
+
var handleSlideStart = useStableLayoutCallback(function (event) {
|
|
257
|
+
if (isRightClick(event)) return;
|
|
258
|
+
|
|
259
|
+
if (disabled) {
|
|
260
|
+
pointerDownRef.current = false;
|
|
261
|
+
return;
|
|
262
|
+
} // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
var ownerDocument = getOwnerDocument(sliderRef.current);
|
|
266
|
+
var ownerWindow = ownerDocument.defaultView || window;
|
|
267
|
+
pointerDownRef.current = true;
|
|
268
|
+
|
|
269
|
+
if (event.changedTouches) {
|
|
270
|
+
var _changedTouches;
|
|
271
|
+
|
|
272
|
+
// Prevent scrolling for touch events
|
|
273
|
+
event.preventDefault();
|
|
274
|
+
var touch = (_changedTouches = event.changedTouches) === null || _changedTouches === void 0 ? void 0 : _changedTouches[0];
|
|
275
|
+
|
|
276
|
+
if (touch != null) {
|
|
277
|
+
touchId.current = touch.identifier;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
var newValue = getNewValueFromEvent(event);
|
|
282
|
+
|
|
283
|
+
if (newValue == null) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
ownerWindow.requestAnimationFrame(function () {
|
|
288
|
+
var _handleRef$current;
|
|
289
|
+
|
|
290
|
+
return (_handleRef$current = handleRef.current) === null || _handleRef$current === void 0 ? void 0 : _handleRef$current.focus();
|
|
291
|
+
});
|
|
292
|
+
onChange(event, newValue);
|
|
293
|
+
removeMoveEvents.current = addMoveListener();
|
|
294
|
+
removeEndEvents.current = addEndListener();
|
|
295
|
+
});
|
|
296
|
+
var setPointerCapture = useStableLayoutCallback(function (event) {
|
|
297
|
+
var _sliderRef$current;
|
|
298
|
+
|
|
299
|
+
if (isRightClick(event)) return;
|
|
300
|
+
|
|
301
|
+
if (disabled) {
|
|
302
|
+
pointerDownRef.current = false;
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
pointerDownRef.current = true;
|
|
307
|
+
(_sliderRef$current = sliderRef.current) === null || _sliderRef$current === void 0 ? void 0 : _sliderRef$current.setPointerCapture(event.pointerId);
|
|
308
|
+
});
|
|
309
|
+
var releasePointerCapture = useStableLayoutCallback(function (event) {
|
|
310
|
+
var _sliderRef$current2;
|
|
311
|
+
|
|
312
|
+
if (isRightClick(event)) return;
|
|
313
|
+
(_sliderRef$current2 = sliderRef.current) === null || _sliderRef$current2 === void 0 ? void 0 : _sliderRef$current2.releasePointerCapture(event.pointerId);
|
|
314
|
+
pointerDownRef.current = false;
|
|
315
|
+
});
|
|
316
|
+
var handlePointerMove = useStableLayoutCallback(function (event) {
|
|
317
|
+
if (disabled || !pointerDownRef.current) {
|
|
318
|
+
pointerDownRef.current = false;
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
var newValue = getNewValueFromEvent(event);
|
|
323
|
+
|
|
324
|
+
if (newValue == null) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(event, newValue);
|
|
329
|
+
});
|
|
330
|
+
var handleSlideStop = useStableLayoutCallback(function (event) {
|
|
331
|
+
if (isRightClick(event)) return;
|
|
332
|
+
pointerDownRef.current = false;
|
|
333
|
+
var newValue = getNewValueFromEvent(event);
|
|
334
|
+
|
|
335
|
+
if (newValue == null) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
touchId.current = undefined;
|
|
340
|
+
removeMoveEvents.current();
|
|
341
|
+
removeEndEvents.current();
|
|
342
|
+
});
|
|
343
|
+
var addMoveListener = useCallback(function () {
|
|
344
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
345
|
+
var ownerDocument = getOwnerDocument(sliderRef.current);
|
|
346
|
+
var touchListener = wrapEvent(appEvents.current.onTouchMove, handlePointerMove);
|
|
347
|
+
var mouseListener = wrapEvent(appEvents.current.onMouseMove, handlePointerMove);
|
|
348
|
+
ownerDocument.addEventListener('touchmove', touchListener);
|
|
349
|
+
ownerDocument.addEventListener('mousemove', mouseListener);
|
|
350
|
+
return function () {
|
|
351
|
+
ownerDocument.removeEventListener('touchmove', touchListener);
|
|
352
|
+
ownerDocument.removeEventListener('mousemove', mouseListener);
|
|
353
|
+
};
|
|
354
|
+
}, [handlePointerMove]);
|
|
355
|
+
var addEndListener = useCallback(function () {
|
|
356
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
357
|
+
var ownerDocument = getOwnerDocument(sliderRef.current);
|
|
358
|
+
var ownerWindow = ownerDocument.defaultView || window;
|
|
359
|
+
var pointerListener = wrapEvent(appEvents.current.onPointerUp, releasePointerCapture);
|
|
360
|
+
var touchListener = wrapEvent(appEvents.current.onTouchEnd, handleSlideStop);
|
|
361
|
+
var mouseListener = wrapEvent(appEvents.current.onMouseUp, handleSlideStop);
|
|
362
|
+
|
|
363
|
+
if ('PointerEvent' in ownerWindow) {
|
|
364
|
+
ownerDocument.addEventListener('pointerup', pointerListener);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
ownerDocument.addEventListener('touchend', touchListener);
|
|
368
|
+
ownerDocument.addEventListener('mouseup', mouseListener);
|
|
369
|
+
return function () {
|
|
370
|
+
if ('PointerEvent' in ownerWindow) {
|
|
371
|
+
ownerDocument.removeEventListener('pointerup', pointerListener);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
ownerDocument.removeEventListener('touchend', touchListener);
|
|
375
|
+
ownerDocument.removeEventListener('mouseup', mouseListener);
|
|
376
|
+
};
|
|
377
|
+
}, [handleSlideStop, releasePointerCapture]);
|
|
378
|
+
var addStartListener = useCallback(function () {
|
|
379
|
+
// e.preventDefault is ignored by React's synthetic touchStart event, so
|
|
380
|
+
// we attach the listener directly to the DOM node
|
|
381
|
+
// https://github.com/facebook/react/issues/9809#issuecomment-413978405
|
|
382
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
383
|
+
var sliderElement = sliderRef.current;
|
|
384
|
+
|
|
385
|
+
if (!sliderElement) {
|
|
386
|
+
return noop;
|
|
387
|
+
} // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
var ownerDocument = getOwnerDocument(sliderElement);
|
|
391
|
+
var ownerWindow = ownerDocument.defaultView || window;
|
|
392
|
+
var touchListener = wrapEvent(appEvents.current.onTouchStart, handleSlideStart);
|
|
393
|
+
var mouseListener = wrapEvent(appEvents.current.onMouseDown, handleSlideStart);
|
|
394
|
+
var pointerListener = wrapEvent(appEvents.current.onPointerDown, setPointerCapture);
|
|
395
|
+
sliderElement.addEventListener('touchstart', touchListener);
|
|
396
|
+
sliderElement.addEventListener('mousedown', mouseListener);
|
|
397
|
+
|
|
398
|
+
if ('PointerEvent' in ownerWindow) {
|
|
399
|
+
sliderElement.addEventListener('pointerdown', pointerListener);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return function () {
|
|
403
|
+
sliderElement.removeEventListener('touchstart', touchListener);
|
|
404
|
+
sliderElement.removeEventListener('mousedown', mouseListener);
|
|
405
|
+
|
|
406
|
+
if ('PointerEvent' in ownerWindow) {
|
|
407
|
+
sliderElement.removeEventListener('pointerdown', pointerListener);
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
}, [setPointerCapture, handleSlideStart]);
|
|
411
|
+
useEffect(function () {
|
|
412
|
+
removeStartEvents.current = addStartListener();
|
|
413
|
+
return function () {
|
|
414
|
+
removeStartEvents.current();
|
|
415
|
+
removeEndEvents.current();
|
|
416
|
+
removeMoveEvents.current();
|
|
417
|
+
};
|
|
418
|
+
}, [addStartListener]);
|
|
419
|
+
var inputFallbackId = useId();
|
|
420
|
+
var inputId = id || inputFallbackId;
|
|
421
|
+
return /*#__PURE__*/_jsx(SliderProvider, {
|
|
422
|
+
ariaLabel: getAriaLabel ? getAriaLabel(value) : ariaLabel,
|
|
423
|
+
ariaLabelledBy: ariaLabelledBy,
|
|
424
|
+
ariaValueText: ariaValueText,
|
|
425
|
+
handleDimensions: handleDimensions,
|
|
426
|
+
handleKeyDown: handleKeyDown,
|
|
427
|
+
handlePosition: handlePosition,
|
|
428
|
+
handleRef: handleRef,
|
|
429
|
+
hasFocus: hasFocus,
|
|
430
|
+
onKeyDown: onKeyDown,
|
|
431
|
+
setHasFocus: setHasFocus,
|
|
432
|
+
sliderId: id,
|
|
433
|
+
sliderMax: max,
|
|
434
|
+
sliderMin: min,
|
|
435
|
+
value: value,
|
|
436
|
+
disabled: !!disabled,
|
|
437
|
+
isVertical: isVertical,
|
|
438
|
+
orientation: orientation,
|
|
439
|
+
trackPercent: trackPercent,
|
|
440
|
+
trackRef: trackRef,
|
|
441
|
+
rangeStyle: rangeStyle,
|
|
442
|
+
updateValue: onChange,
|
|
443
|
+
children: /*#__PURE__*/_jsxs(Comp, _extends(_extends({}, rest), {}, {
|
|
444
|
+
ref: assignMultipleRefs(sliderRef, forwardedRef),
|
|
445
|
+
"data-reach-slider-input": "",
|
|
446
|
+
"data-disabled": disabled ? '' : undefined,
|
|
447
|
+
"data-orientation": orientation,
|
|
448
|
+
tabIndex: -1,
|
|
449
|
+
children: [typeof children === 'function' ? children({
|
|
450
|
+
hasFocus: hasFocus,
|
|
451
|
+
id: id,
|
|
452
|
+
max: max,
|
|
453
|
+
min: min,
|
|
454
|
+
value: value,
|
|
455
|
+
ariaValueText: ariaValueText
|
|
456
|
+
}) : children, name &&
|
|
457
|
+
/*#__PURE__*/
|
|
458
|
+
// If the slider is used in a form we'll need an input field to
|
|
459
|
+
// capture the value. We'll assume this when the component is given a
|
|
460
|
+
// form field name (A `name` prop doesn't really make sense in any
|
|
461
|
+
// other context).
|
|
462
|
+
_jsx("input", {
|
|
463
|
+
type: "hidden",
|
|
464
|
+
value: value,
|
|
465
|
+
name: name,
|
|
466
|
+
id: inputId
|
|
467
|
+
})]
|
|
468
|
+
}))
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
/**
|
|
472
|
+
* @see Docs https://reach.tech/slider#sliderinput-props
|
|
473
|
+
*/
|
|
474
|
+
|
|
475
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* SliderTrack
|
|
479
|
+
*
|
|
480
|
+
* @see Docs https://reach.tech/slider#slidertrack
|
|
481
|
+
*/
|
|
482
|
+
var SliderTrackImpl = /*#__PURE__*/forwardRef(function SliderTrack(_ref3, forwardedRef) {
|
|
483
|
+
var _ref3$as = _ref3.as,
|
|
484
|
+
Comp = _ref3$as === void 0 ? 'div' : _ref3$as,
|
|
485
|
+
children = _ref3.children,
|
|
486
|
+
_ref3$style = _ref3.style,
|
|
487
|
+
style = _ref3$style === void 0 ? {} : _ref3$style,
|
|
488
|
+
props = _objectWithoutProperties(_ref3, _excluded4);
|
|
489
|
+
|
|
490
|
+
var _useSliderContext = useSliderContext('SliderTrack'),
|
|
491
|
+
disabled = _useSliderContext.disabled,
|
|
492
|
+
orientation = _useSliderContext.orientation,
|
|
493
|
+
trackRef = _useSliderContext.trackRef;
|
|
494
|
+
|
|
495
|
+
return /*#__PURE__*/_jsx(Comp, _extends(_extends({
|
|
496
|
+
ref: assignMultipleRefs(trackRef, forwardedRef),
|
|
497
|
+
style: _extends(_extends({}, style), {}, {
|
|
498
|
+
position: 'relative'
|
|
499
|
+
})
|
|
500
|
+
}, props), {}, {
|
|
501
|
+
"data-reach-slider-track": "",
|
|
502
|
+
"data-disabled": disabled ? '' : undefined,
|
|
503
|
+
"data-orientation": orientation,
|
|
504
|
+
children: children
|
|
505
|
+
}));
|
|
506
|
+
});
|
|
507
|
+
var SliderTrack = /*#__PURE__*/memo(SliderTrackImpl);
|
|
508
|
+
/**
|
|
509
|
+
* @see Docs https://reach.tech/slider#slidertrack-props
|
|
510
|
+
*/
|
|
511
|
+
|
|
512
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* SliderRange
|
|
516
|
+
*
|
|
517
|
+
* The (typically) highlighted portion of the track that represents the space
|
|
518
|
+
* between the slider's `min` value and its current value.
|
|
519
|
+
*
|
|
520
|
+
* @see Docs https://reach.tech/slider#sliderrange
|
|
521
|
+
*/
|
|
522
|
+
var SliderRangeImpl = /*#__PURE__*/forwardRef(function SliderRange(_ref4, forwardedRef) {
|
|
523
|
+
var _ref4$as = _ref4.as,
|
|
524
|
+
Comp = _ref4$as === void 0 ? 'div' : _ref4$as,
|
|
525
|
+
children = _ref4.children,
|
|
526
|
+
_ref4$style = _ref4.style,
|
|
527
|
+
style = _ref4$style === void 0 ? {} : _ref4$style,
|
|
528
|
+
props = _objectWithoutProperties(_ref4, _excluded5);
|
|
529
|
+
|
|
530
|
+
var _useSliderContext2 = useSliderContext('SliderRange'),
|
|
531
|
+
disabled = _useSliderContext2.disabled,
|
|
532
|
+
orientation = _useSliderContext2.orientation,
|
|
533
|
+
rangeStyle = _useSliderContext2.rangeStyle;
|
|
534
|
+
|
|
535
|
+
return /*#__PURE__*/_jsx(Comp, _extends(_extends({
|
|
536
|
+
ref: forwardedRef,
|
|
537
|
+
style: _extends(_extends({
|
|
538
|
+
position: 'absolute'
|
|
539
|
+
}, rangeStyle), style)
|
|
540
|
+
}, props), {}, {
|
|
541
|
+
"data-reach-slider-range": "",
|
|
542
|
+
"data-disabled": disabled ? '' : undefined,
|
|
543
|
+
"data-orientation": orientation
|
|
544
|
+
}));
|
|
545
|
+
});
|
|
546
|
+
var SliderRange = /*#__PURE__*/memo(SliderRangeImpl);
|
|
547
|
+
/**
|
|
548
|
+
* `SliderRange` accepts any props that a HTML div component accepts.
|
|
549
|
+
* `SliderRange` will not accept or render any children.
|
|
550
|
+
*
|
|
551
|
+
* @see Docs https://reach.tech/slider#sliderrange-props
|
|
552
|
+
*/
|
|
553
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
554
|
+
|
|
555
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* SliderHandle
|
|
559
|
+
*
|
|
560
|
+
* The handle that the user drags along the track to set the slider value.
|
|
561
|
+
*
|
|
562
|
+
* @see Docs https://reach.tech/slider#sliderhandle
|
|
563
|
+
*/
|
|
564
|
+
var SliderHandleImpl = /*#__PURE__*/forwardRef(function SliderHandle(_ref5, forwardedRef) {
|
|
565
|
+
var _ref5$as = _ref5.as,
|
|
566
|
+
Comp = _ref5$as === void 0 ? 'div' : _ref5$as,
|
|
567
|
+
onBlur = _ref5.onBlur,
|
|
568
|
+
onFocus = _ref5.onFocus,
|
|
569
|
+
_ref5$style = _ref5.style,
|
|
570
|
+
style = _ref5$style === void 0 ? {} : _ref5$style,
|
|
571
|
+
onKeyDown = _ref5.onKeyDown,
|
|
572
|
+
props = _objectWithoutProperties(_ref5, _excluded6);
|
|
573
|
+
|
|
574
|
+
var _useSliderContext3 = useSliderContext('SliderHandle'),
|
|
575
|
+
ariaLabel = _useSliderContext3.ariaLabel,
|
|
576
|
+
ariaLabelledBy = _useSliderContext3.ariaLabelledBy,
|
|
577
|
+
ariaValueText = _useSliderContext3.ariaValueText,
|
|
578
|
+
disabled = _useSliderContext3.disabled,
|
|
579
|
+
handlePosition = _useSliderContext3.handlePosition,
|
|
580
|
+
handleRef = _useSliderContext3.handleRef,
|
|
581
|
+
isVertical = _useSliderContext3.isVertical,
|
|
582
|
+
handleKeyDown = _useSliderContext3.handleKeyDown,
|
|
583
|
+
orientation = _useSliderContext3.orientation,
|
|
584
|
+
setHasFocus = _useSliderContext3.setHasFocus,
|
|
585
|
+
sliderMin = _useSliderContext3.sliderMin,
|
|
586
|
+
sliderMax = _useSliderContext3.sliderMax,
|
|
587
|
+
value = _useSliderContext3.value;
|
|
588
|
+
|
|
589
|
+
return /*#__PURE__*/_jsx(Comp, _extends(_extends({
|
|
590
|
+
"aria-disabled": disabled || undefined // If the slider has a visible label, it is referenced by
|
|
591
|
+
// `aria-labelledby` on the slider element. Otherwise, the slider
|
|
592
|
+
// element has a label provided by `aria-label`.
|
|
593
|
+
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
594
|
+
,
|
|
595
|
+
"aria-label": ariaLabel,
|
|
596
|
+
"aria-labelledby": ariaLabel ? undefined : ariaLabelledBy // If the slider is vertically oriented, it has `aria-orientation` set
|
|
597
|
+
// to vertical. The default value of `aria-orientation` for a slider is
|
|
598
|
+
// horizontal.
|
|
599
|
+
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
600
|
+
,
|
|
601
|
+
"aria-orientation": orientation // The slider element has the `aria-valuemax` property set to a decimal
|
|
602
|
+
// value representing the maximum allowed value of the slider.
|
|
603
|
+
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
604
|
+
,
|
|
605
|
+
"aria-valuemax": sliderMax // The slider element has the `aria-valuemin` property set to a decimal
|
|
606
|
+
// value representing the minimum allowed value of the slider.
|
|
607
|
+
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
608
|
+
,
|
|
609
|
+
"aria-valuemin": sliderMin // The slider element has the `aria-valuenow` property set to a decimal
|
|
610
|
+
// value representing the current value of the slider.
|
|
611
|
+
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
612
|
+
,
|
|
613
|
+
"aria-valuenow": value // If the value of `aria-valuenow` is not user-friendly, e.g., the day
|
|
614
|
+
// of the week is represented by a number, the `aria-valuetext` property
|
|
615
|
+
// is set to a string that makes the slider value understandable, e.g.,
|
|
616
|
+
// "Monday".
|
|
617
|
+
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
618
|
+
,
|
|
619
|
+
"aria-valuetext": ariaValueText // The element serving as the focusable slider control has role
|
|
620
|
+
// `slider`.
|
|
621
|
+
// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_roles_states_props
|
|
622
|
+
,
|
|
623
|
+
role: "slider",
|
|
624
|
+
tabIndex: disabled ? -1 : 0
|
|
625
|
+
}, props), {}, {
|
|
626
|
+
"data-reach-slider-handle": "",
|
|
627
|
+
ref: assignMultipleRefs(handleRef, forwardedRef),
|
|
628
|
+
onBlur: wrapEvent(onBlur, function () {
|
|
629
|
+
setHasFocus(false);
|
|
630
|
+
}),
|
|
631
|
+
onFocus: wrapEvent(onFocus, function () {
|
|
632
|
+
setHasFocus(true);
|
|
633
|
+
}),
|
|
634
|
+
onKeyDown: wrapEvent(onKeyDown, handleKeyDown),
|
|
635
|
+
style: _extends(_extends({
|
|
636
|
+
position: 'absolute'
|
|
637
|
+
}, isVertical ? {
|
|
638
|
+
bottom: handlePosition
|
|
639
|
+
} : {
|
|
640
|
+
left: handlePosition
|
|
641
|
+
}), style)
|
|
642
|
+
}));
|
|
643
|
+
});
|
|
644
|
+
var SliderHandle = /*#__PURE__*/memo(SliderHandleImpl);
|
|
645
|
+
/**
|
|
646
|
+
* `SliderRange` accepts any props that a HTML div component accepts.
|
|
647
|
+
*
|
|
648
|
+
* @see Docs https://reach.tech/slider#sliderhandle-props
|
|
649
|
+
*/
|
|
650
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
651
|
+
|
|
652
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* SliderMarker
|
|
656
|
+
*
|
|
657
|
+
* A fixed value marker. These can be used to illustrate a range of steps or
|
|
658
|
+
* highlight important points along the slider track.
|
|
659
|
+
*
|
|
660
|
+
* @see Docs https://reach.tech/slider#slidermarker
|
|
661
|
+
*/
|
|
662
|
+
var SliderMarkerImpl = /*#__PURE__*/forwardRef(function SliderMarker(_ref6, forwardedRef) {
|
|
663
|
+
var _ref6$as = _ref6.as,
|
|
664
|
+
Comp = _ref6$as === void 0 ? 'div' : _ref6$as,
|
|
665
|
+
children = _ref6.children,
|
|
666
|
+
_ref6$style = _ref6.style,
|
|
667
|
+
style = _ref6$style === void 0 ? {} : _ref6$style,
|
|
668
|
+
value = _ref6.value,
|
|
669
|
+
props = _objectWithoutProperties(_ref6, _excluded7);
|
|
670
|
+
|
|
671
|
+
var _useSliderContext4 = useSliderContext('SliderMarker'),
|
|
672
|
+
disabled = _useSliderContext4.disabled,
|
|
673
|
+
isVertical = _useSliderContext4.isVertical,
|
|
674
|
+
orientation = _useSliderContext4.orientation,
|
|
675
|
+
sliderMin = _useSliderContext4.sliderMin,
|
|
676
|
+
sliderMax = _useSliderContext4.sliderMax,
|
|
677
|
+
sliderValue = _useSliderContext4.value;
|
|
678
|
+
|
|
679
|
+
var inRange = !(value < sliderMin || value > sliderMax);
|
|
680
|
+
var absoluteStartPosition = "".concat(valueToPercent(value, sliderMin, sliderMax), "%");
|
|
681
|
+
var state = value < sliderValue ? 'under-value' : value === sliderValue ? 'at-value' : 'over-value';
|
|
682
|
+
return inRange ? /*#__PURE__*/_jsx(Comp, _extends(_extends({
|
|
683
|
+
ref: forwardedRef,
|
|
684
|
+
style: _extends(_extends({
|
|
685
|
+
position: 'absolute'
|
|
686
|
+
}, isVertical ? {
|
|
687
|
+
bottom: absoluteStartPosition
|
|
688
|
+
} : {
|
|
689
|
+
left: absoluteStartPosition
|
|
690
|
+
}), style)
|
|
691
|
+
}, props), {}, {
|
|
692
|
+
"data-reach-slider-marker": "",
|
|
693
|
+
"data-disabled": disabled ? '' : undefined,
|
|
694
|
+
"data-orientation": orientation,
|
|
695
|
+
"data-state": state,
|
|
696
|
+
"data-value": value,
|
|
697
|
+
children: children
|
|
698
|
+
})) : null;
|
|
699
|
+
});
|
|
700
|
+
var SliderMarker = /*#__PURE__*/memo(SliderMarkerImpl);
|
|
701
|
+
/**
|
|
702
|
+
* @see Docs https://reach.tech/slider#slidermarker-props
|
|
703
|
+
*/
|
|
704
|
+
|
|
705
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
706
|
+
function clamp(val, min, max) {
|
|
707
|
+
return val > max ? max : val < min ? min : val;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* This handles the case when num is very small (0.00000001), js will turn
|
|
711
|
+
* this into 1e-8. When num is bigger than 1 or less than -1 it won't get
|
|
712
|
+
* converted to this notation so it's fine.
|
|
713
|
+
*
|
|
714
|
+
* @param num
|
|
715
|
+
* @see https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/Slider/Slider.js#L69
|
|
716
|
+
*/
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
function getDecimalPrecision(num) {
|
|
720
|
+
if (Math.abs(num) < 1) {
|
|
721
|
+
var parts = num.toExponential().split('e-');
|
|
722
|
+
var matissaDecimalPart = parts[0].split('.')[1];
|
|
723
|
+
return (matissaDecimalPart ? matissaDecimalPart.length : 0) + parseInt(parts[1], 10);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
var decimalPart = num.toString().split('.')[1];
|
|
727
|
+
return decimalPart ? decimalPart.length : 0;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function percentToValue(percent, min, max) {
|
|
731
|
+
return (max - min) * percent + min;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
function roundValueToStep(value, step, min) {
|
|
735
|
+
var nearest = Math.round((value - min) / step) * step + min;
|
|
736
|
+
return Number(nearest.toFixed(getDecimalPrecision(step)));
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function getPointerPosition(event, touchId) {
|
|
740
|
+
if (touchId.current !== undefined && event.changedTouches) {
|
|
741
|
+
for (var i = 0; i < event.changedTouches.length; i += 1) {
|
|
742
|
+
var touch = event.changedTouches[i];
|
|
743
|
+
|
|
744
|
+
if (touch.identifier === touchId.current) {
|
|
745
|
+
return {
|
|
746
|
+
x: touch.clientX,
|
|
747
|
+
y: touch.clientY
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
return {
|
|
756
|
+
x: event.clientX,
|
|
757
|
+
y: event.clientY
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function getNewValue(handlePosition, track, props) {
|
|
762
|
+
var orientation = props.orientation,
|
|
763
|
+
min = props.min,
|
|
764
|
+
max = props.max,
|
|
765
|
+
step = props.step;
|
|
766
|
+
|
|
767
|
+
if (!track || !handlePosition) {
|
|
768
|
+
return null;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
var _track$getBoundingCli = track.getBoundingClientRect(),
|
|
772
|
+
left = _track$getBoundingCli.left,
|
|
773
|
+
width = _track$getBoundingCli.width,
|
|
774
|
+
bottom = _track$getBoundingCli.bottom,
|
|
775
|
+
height = _track$getBoundingCli.height;
|
|
776
|
+
|
|
777
|
+
var isVertical = orientation === 'vertical';
|
|
778
|
+
var diff = isVertical ? bottom - handlePosition.y : handlePosition.x - left;
|
|
779
|
+
var percent = diff / (isVertical ? height : width);
|
|
780
|
+
var newValue = percentToValue(percent, min, max);
|
|
781
|
+
return clamp(step ? roundValueToStep(newValue, step, min) : newValue, min, max);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function useDimensions(ref) {
|
|
785
|
+
var _useState3 = useState({
|
|
786
|
+
width: 0,
|
|
787
|
+
height: 0
|
|
788
|
+
}),
|
|
789
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
790
|
+
_useState4$ = _useState4[0],
|
|
791
|
+
width = _useState4$.width,
|
|
792
|
+
height = _useState4$.height,
|
|
793
|
+
setDimensions = _useState4[1]; // Many existing `useDimensions` type hooks will use `getBoundingClientRect`
|
|
794
|
+
// getBoundingClientRect does not work here when borders are applied.
|
|
795
|
+
// getComputedStyle is not as performant so we may want to create a utility to
|
|
796
|
+
// check for any conflicts with box sizing first and only use
|
|
797
|
+
// `getComputedStyle` if neccessary.
|
|
798
|
+
|
|
799
|
+
/* const { width, height } = ref.current
|
|
800
|
+
? ref.current.getBoundingClientRect()
|
|
801
|
+
: 0; */
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
useLayoutEffect(function () {
|
|
805
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
806
|
+
var ownerDocument = getOwnerDocument(ref.current);
|
|
807
|
+
var ownerWindow = ownerDocument.defaultView || window;
|
|
808
|
+
|
|
809
|
+
if (ref.current) {
|
|
810
|
+
var _ownerWindow$getCompu = ownerWindow.getComputedStyle(ref.current),
|
|
811
|
+
_newHeight = _ownerWindow$getCompu.height,
|
|
812
|
+
_newWidth = _ownerWindow$getCompu.width;
|
|
813
|
+
|
|
814
|
+
var newHeight = parseFloat(_newHeight);
|
|
815
|
+
var newWidth = parseFloat(_newWidth);
|
|
816
|
+
|
|
817
|
+
if (newHeight !== height || newWidth !== width) {
|
|
818
|
+
setDimensions({
|
|
819
|
+
height: newHeight,
|
|
820
|
+
width: newWidth
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}, [ref, width, height]);
|
|
825
|
+
return {
|
|
826
|
+
ref: ref,
|
|
827
|
+
width: width,
|
|
828
|
+
height: height
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
function valueToPercent(value, min, max) {
|
|
833
|
+
return (value - min) * 100 / (max - min);
|
|
834
|
+
} ////////////////////////////////////////////////////////////////////////////////
|
|
835
|
+
// Types
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
839
|
+
// Exports
|
|
840
|
+
export default Slider;
|
|
841
|
+
export { Slider, SliderHandle, SliderInput, SliderMarker, SliderTrack, SliderRange };
|
|
842
|
+
//# sourceMappingURL=Slider.js.map
|