@salt-ds/core 1.44.1 → 1.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/css/salt-core.css +449 -11
- package/dist-cjs/accordion/Accordion.js.map +1 -1
- package/dist-cjs/accordion/AccordionContext.js.map +1 -1
- package/dist-cjs/accordion/AccordionHeader.js.map +1 -1
- package/dist-cjs/accordion/AccordionPanel.js.map +1 -1
- package/dist-cjs/aria-announcer/AriaAnnouncerContext.js.map +1 -1
- package/dist-cjs/aria-announcer/AriaAnnouncerProvider.js.map +1 -1
- package/dist-cjs/aria-announcer/useAriaAnnouncer.js +1 -9
- package/dist-cjs/aria-announcer/useAriaAnnouncer.js.map +1 -1
- package/dist-cjs/avatar/Avatar.js.map +1 -1
- package/dist-cjs/button/Button.js.map +1 -1
- package/dist-cjs/button/useButton.js.map +1 -1
- package/dist-cjs/checkbox/Checkbox.js.map +1 -1
- package/dist-cjs/checkbox/CheckboxGroup.js.map +1 -1
- package/dist-cjs/checkbox/internal/CheckboxGroupContext.js.map +1 -1
- package/dist-cjs/combo-box/ComboBox.js.map +1 -1
- package/dist-cjs/combo-box/useComboBox.js.map +1 -1
- package/dist-cjs/dialog/Dialog.js.map +1 -1
- package/dist-cjs/dialog/DialogContent.js.map +1 -1
- package/dist-cjs/dialog/DialogContext.js.map +1 -1
- package/dist-cjs/drawer/Drawer.js.map +1 -1
- package/dist-cjs/dropdown/Dropdown.js.map +1 -1
- package/dist-cjs/file-drop-zone/FileDropZone.js.map +1 -1
- package/dist-cjs/file-drop-zone/FileDropZoneTrigger.js.map +1 -1
- package/dist-cjs/file-drop-zone/internal/utils.js.map +1 -1
- package/dist-cjs/flex-layout/parseSpacing.js.map +1 -1
- package/dist-cjs/form-field/FormField.js.map +1 -1
- package/dist-cjs/form-field/FormFieldHelperText.js.map +1 -1
- package/dist-cjs/form-field/FormFieldLabel.js.map +1 -1
- package/dist-cjs/grid-layout/GridLayout.js.map +1 -1
- package/dist-cjs/index.js +4 -0
- package/dist-cjs/index.js.map +1 -1
- package/dist-cjs/input/Input.js.map +1 -1
- package/dist-cjs/interactable-card/InteractableCard.js.map +1 -1
- package/dist-cjs/interactable-card/InteractableCardGroup.js.map +1 -1
- package/dist-cjs/interactable-card/InteractableCardGroupContext.js.map +1 -1
- package/dist-cjs/interactable-card/useInteractableCard.js.map +1 -1
- package/dist-cjs/link/Link.js.map +1 -1
- package/dist-cjs/list-box/ListBox.js.map +1 -1
- package/dist-cjs/list-control/ListControlContext.js.map +1 -1
- package/dist-cjs/list-control/ListControlState.js.map +1 -1
- package/dist-cjs/menu/MenuBase.js.map +1 -1
- package/dist-cjs/menu/MenuContext.js.map +1 -1
- package/dist-cjs/menu/MenuGroup.js.map +1 -1
- package/dist-cjs/menu/MenuItem.js.map +1 -1
- package/dist-cjs/menu/MenuPanel.js.map +1 -1
- package/dist-cjs/menu/MenuPanelContext.js.map +1 -1
- package/dist-cjs/menu/MenuTrigger.js.map +1 -1
- package/dist-cjs/multiline-input/MultilineInput.js.map +1 -1
- package/dist-cjs/navigation-item/ExpansionIcon.js +1 -1
- package/dist-cjs/navigation-item/ExpansionIcon.js.map +1 -1
- package/dist-cjs/navigation-item/NavigationItem.js.map +1 -1
- package/dist-cjs/option/Option.js.map +1 -1
- package/dist-cjs/overlay/Overlay.js.map +1 -1
- package/dist-cjs/pagination/PageButton.js.map +1 -1
- package/dist-cjs/pagination/Pagination.js.map +1 -1
- package/dist-cjs/pagination/PaginationContext.js.map +1 -1
- package/dist-cjs/pagination/usePagination.js.map +1 -1
- package/dist-cjs/parent-child-layout/ParentChildLayout.js.map +1 -1
- package/dist-cjs/pill-input/PillInput.js.map +1 -1
- package/dist-cjs/progress/CircularProgress/CircularProgress.js.map +1 -1
- package/dist-cjs/progress/LinearProgress/LinearProgress.js.map +1 -1
- package/dist-cjs/radio-button/RadioButton.js.map +1 -1
- package/dist-cjs/radio-button/RadioButtonGroup.js.map +1 -1
- package/dist-cjs/radio-button/internal/RadioGroupContext.js.map +1 -1
- package/dist-cjs/salt-provider/SaltProvider.js.map +1 -1
- package/dist-cjs/skip-link/internal/useManageFocusOnTarget.js.map +1 -1
- package/dist-cjs/slider/RangeSlider.js.map +1 -1
- package/dist-cjs/slider/Slider.js.map +1 -1
- package/dist-cjs/slider/internal/SliderThumb.js.map +1 -1
- package/dist-cjs/slider/internal/SliderTrack.js.map +1 -1
- package/dist-cjs/slider/internal/useRangeSliderThumb.js.map +1 -1
- package/dist-cjs/slider/internal/useSliderThumb.js.map +1 -1
- package/dist-cjs/stack-layout/StackLayout.js.map +1 -1
- package/dist-cjs/stepper/Step.css.js +6 -0
- package/dist-cjs/stepper/Step.css.js.map +1 -0
- package/dist-cjs/stepper/Step.js +167 -0
- package/dist-cjs/stepper/Step.js.map +1 -0
- package/dist-cjs/stepper/Stepper.css.js +6 -0
- package/dist-cjs/stepper/Stepper.css.js.map +1 -0
- package/dist-cjs/stepper/Stepper.js +40 -0
- package/dist-cjs/stepper/Stepper.js.map +1 -0
- package/dist-cjs/stepper/internal/StepConnector.css.js +6 -0
- package/dist-cjs/stepper/internal/StepConnector.css.js.map +1 -0
- package/dist-cjs/stepper/internal/StepConnector.js +27 -0
- package/dist-cjs/stepper/internal/StepConnector.js.map +1 -0
- package/dist-cjs/stepper/internal/StepExpandTrigger.css.js +6 -0
- package/dist-cjs/stepper/internal/StepExpandTrigger.css.js.map +1 -0
- package/dist-cjs/stepper/internal/StepExpandTrigger.js +45 -0
- package/dist-cjs/stepper/internal/StepExpandTrigger.js.map +1 -0
- package/dist-cjs/stepper/internal/StepIcon.css.js +6 -0
- package/dist-cjs/stepper/internal/StepIcon.css.js.map +1 -0
- package/dist-cjs/stepper/internal/StepIcon.js +62 -0
- package/dist-cjs/stepper/internal/StepIcon.js.map +1 -0
- package/dist-cjs/stepper/internal/StepScreenReaderOnly.js +13 -0
- package/dist-cjs/stepper/internal/StepScreenReaderOnly.js.map +1 -0
- package/dist-cjs/stepper/internal/StepText.css.js +6 -0
- package/dist-cjs/stepper/internal/StepText.css.js.map +1 -0
- package/dist-cjs/stepper/internal/StepText.js +50 -0
- package/dist-cjs/stepper/internal/StepText.js.map +1 -0
- package/dist-cjs/stepper/internal/StepperProvider.js +19 -0
- package/dist-cjs/stepper/internal/StepperProvider.js.map +1 -0
- package/dist-cjs/switch/Switch.js.map +1 -1
- package/dist-cjs/toggle-button/ToggleButton.css.js +1 -1
- package/dist-cjs/toggle-button/ToggleButton.js +34 -20
- package/dist-cjs/toggle-button/ToggleButton.js.map +1 -1
- package/dist-cjs/toggle-button-group/ToggleButtonGroup.css.js +1 -1
- package/dist-cjs/toggle-button-group/ToggleButtonGroup.js +30 -6
- package/dist-cjs/toggle-button-group/ToggleButtonGroup.js.map +1 -1
- package/dist-cjs/toggle-button-group/ToggleButtonGroupContext.js.map +1 -1
- package/dist-cjs/tooltip/Tooltip.js.map +1 -1
- package/dist-cjs/tooltip/TooltipBase.js.map +1 -1
- package/dist-cjs/tooltip/useAriaAnnounce.js.map +1 -1
- package/dist-cjs/tooltip/useTooltip.js.map +1 -1
- package/dist-cjs/utils/mergeProps.js.map +1 -1
- package/dist-cjs/utils/useControlled.js.map +1 -1
- package/dist-cjs/utils/useFloatingUI/useFloatingUI.js.map +1 -1
- package/dist-cjs/utils/useId.js.map +1 -1
- package/dist-cjs/utils/usePreventScroll.js.map +1 -1
- package/dist-cjs/utils/useResizeObserver.js.map +1 -1
- package/dist-cjs/utils/useResponsiveProp.js.map +1 -1
- package/dist-es/accordion/Accordion.js.map +1 -1
- package/dist-es/accordion/AccordionContext.js.map +1 -1
- package/dist-es/accordion/AccordionHeader.js.map +1 -1
- package/dist-es/accordion/AccordionPanel.js.map +1 -1
- package/dist-es/aria-announcer/AriaAnnouncerContext.js.map +1 -1
- package/dist-es/aria-announcer/AriaAnnouncerProvider.js.map +1 -1
- package/dist-es/aria-announcer/useAriaAnnouncer.js +1 -9
- package/dist-es/aria-announcer/useAriaAnnouncer.js.map +1 -1
- package/dist-es/avatar/Avatar.js.map +1 -1
- package/dist-es/breakpoints/BreakpointProvider.js +1 -1
- package/dist-es/button/Button.js.map +1 -1
- package/dist-es/button/useButton.js.map +1 -1
- package/dist-es/checkbox/Checkbox.js.map +1 -1
- package/dist-es/checkbox/CheckboxGroup.js.map +1 -1
- package/dist-es/checkbox/internal/CheckboxGroupContext.js.map +1 -1
- package/dist-es/combo-box/ComboBox.js.map +1 -1
- package/dist-es/combo-box/useComboBox.js.map +1 -1
- package/dist-es/dialog/Dialog.js.map +1 -1
- package/dist-es/dialog/DialogContent.js.map +1 -1
- package/dist-es/dialog/DialogContext.js.map +1 -1
- package/dist-es/drawer/Drawer.js.map +1 -1
- package/dist-es/dropdown/Dropdown.js.map +1 -1
- package/dist-es/file-drop-zone/FileDropZone.js +1 -1
- package/dist-es/file-drop-zone/FileDropZone.js.map +1 -1
- package/dist-es/file-drop-zone/FileDropZoneTrigger.js.map +1 -1
- package/dist-es/file-drop-zone/internal/utils.js.map +1 -1
- package/dist-es/flex-layout/parseSpacing.js.map +1 -1
- package/dist-es/form-field/FormField.js.map +1 -1
- package/dist-es/form-field/FormFieldHelperText.js.map +1 -1
- package/dist-es/form-field/FormFieldLabel.js.map +1 -1
- package/dist-es/grid-layout/GridLayout.js.map +1 -1
- package/dist-es/index.js +2 -0
- package/dist-es/index.js.map +1 -1
- package/dist-es/input/Input.js.map +1 -1
- package/dist-es/interactable-card/InteractableCard.js.map +1 -1
- package/dist-es/interactable-card/InteractableCardGroup.js.map +1 -1
- package/dist-es/interactable-card/InteractableCardGroupContext.js.map +1 -1
- package/dist-es/interactable-card/useInteractableCard.js.map +1 -1
- package/dist-es/link/Link.js.map +1 -1
- package/dist-es/list-box/ListBox.js.map +1 -1
- package/dist-es/list-control/ListControlContext.js.map +1 -1
- package/dist-es/list-control/ListControlState.js.map +1 -1
- package/dist-es/menu/MenuBase.js +1 -1
- package/dist-es/menu/MenuBase.js.map +1 -1
- package/dist-es/menu/MenuContext.js.map +1 -1
- package/dist-es/menu/MenuGroup.js.map +1 -1
- package/dist-es/menu/MenuItem.js.map +1 -1
- package/dist-es/menu/MenuPanel.js.map +1 -1
- package/dist-es/menu/MenuPanelContext.js.map +1 -1
- package/dist-es/menu/MenuTrigger.js.map +1 -1
- package/dist-es/multiline-input/MultilineInput.js.map +1 -1
- package/dist-es/navigation-item/ExpansionIcon.js +1 -1
- package/dist-es/navigation-item/ExpansionIcon.js.map +1 -1
- package/dist-es/navigation-item/NavigationItem.js.map +1 -1
- package/dist-es/option/Option.js.map +1 -1
- package/dist-es/overlay/Overlay.js +1 -1
- package/dist-es/overlay/Overlay.js.map +1 -1
- package/dist-es/pagination/PageButton.js.map +1 -1
- package/dist-es/pagination/Pagination.js.map +1 -1
- package/dist-es/pagination/PaginationContext.js.map +1 -1
- package/dist-es/pagination/usePagination.js.map +1 -1
- package/dist-es/parent-child-layout/ParentChildLayout.js.map +1 -1
- package/dist-es/pill-input/PillInput.js.map +1 -1
- package/dist-es/progress/CircularProgress/CircularProgress.js.map +1 -1
- package/dist-es/progress/LinearProgress/LinearProgress.js.map +1 -1
- package/dist-es/radio-button/RadioButton.js.map +1 -1
- package/dist-es/radio-button/RadioButtonGroup.js.map +1 -1
- package/dist-es/radio-button/internal/RadioGroupContext.js.map +1 -1
- package/dist-es/salt-provider/SaltProvider.js.map +1 -1
- package/dist-es/semantic-icon-provider/SemanticIconProvider.js +1 -1
- package/dist-es/skip-link/internal/useManageFocusOnTarget.js.map +1 -1
- package/dist-es/slider/RangeSlider.js.map +1 -1
- package/dist-es/slider/Slider.js.map +1 -1
- package/dist-es/slider/internal/SliderThumb.js.map +1 -1
- package/dist-es/slider/internal/SliderTrack.js.map +1 -1
- package/dist-es/slider/internal/useRangeSliderThumb.js.map +1 -1
- package/dist-es/slider/internal/useSliderThumb.js.map +1 -1
- package/dist-es/stack-layout/StackLayout.js.map +1 -1
- package/dist-es/stepper/Step.css.js +4 -0
- package/dist-es/stepper/Step.css.js.map +1 -0
- package/dist-es/stepper/Step.js +165 -0
- package/dist-es/stepper/Step.js.map +1 -0
- package/dist-es/stepper/Stepper.css.js +4 -0
- package/dist-es/stepper/Stepper.css.js.map +1 -0
- package/dist-es/stepper/Stepper.js +38 -0
- package/dist-es/stepper/Stepper.js.map +1 -0
- package/dist-es/stepper/internal/StepConnector.css.js +4 -0
- package/dist-es/stepper/internal/StepConnector.css.js.map +1 -0
- package/dist-es/stepper/internal/StepConnector.js +25 -0
- package/dist-es/stepper/internal/StepConnector.js.map +1 -0
- package/dist-es/stepper/internal/StepExpandTrigger.css.js +4 -0
- package/dist-es/stepper/internal/StepExpandTrigger.css.js.map +1 -0
- package/dist-es/stepper/internal/StepExpandTrigger.js +43 -0
- package/dist-es/stepper/internal/StepExpandTrigger.js.map +1 -0
- package/dist-es/stepper/internal/StepIcon.css.js +4 -0
- package/dist-es/stepper/internal/StepIcon.css.js.map +1 -0
- package/dist-es/stepper/internal/StepIcon.js +60 -0
- package/dist-es/stepper/internal/StepIcon.js.map +1 -0
- package/dist-es/stepper/internal/StepScreenReaderOnly.js +11 -0
- package/dist-es/stepper/internal/StepScreenReaderOnly.js.map +1 -0
- package/dist-es/stepper/internal/StepText.css.js +4 -0
- package/dist-es/stepper/internal/StepText.css.js.map +1 -0
- package/dist-es/stepper/internal/StepText.js +48 -0
- package/dist-es/stepper/internal/StepText.js.map +1 -0
- package/dist-es/stepper/internal/StepperProvider.js +15 -0
- package/dist-es/stepper/internal/StepperProvider.js.map +1 -0
- package/dist-es/switch/Switch.js.map +1 -1
- package/dist-es/toggle-button/ToggleButton.css.js +1 -1
- package/dist-es/toggle-button/ToggleButton.js +34 -20
- package/dist-es/toggle-button/ToggleButton.js.map +1 -1
- package/dist-es/toggle-button-group/ToggleButtonGroup.css.js +1 -1
- package/dist-es/toggle-button-group/ToggleButtonGroup.js +30 -6
- package/dist-es/toggle-button-group/ToggleButtonGroup.js.map +1 -1
- package/dist-es/toggle-button-group/ToggleButtonGroupContext.js.map +1 -1
- package/dist-es/tooltip/Tooltip.js.map +1 -1
- package/dist-es/tooltip/TooltipBase.js.map +1 -1
- package/dist-es/tooltip/useAriaAnnounce.js.map +1 -1
- package/dist-es/tooltip/useTooltip.js +1 -1
- package/dist-es/tooltip/useTooltip.js.map +1 -1
- package/dist-es/utils/mergeProps.js.map +1 -1
- package/dist-es/utils/useControlled.js.map +1 -1
- package/dist-es/utils/useFloatingUI/useFloatingUI.js +2 -2
- package/dist-es/utils/useFloatingUI/useFloatingUI.js.map +1 -1
- package/dist-es/utils/useId.js.map +1 -1
- package/dist-es/utils/usePreventScroll.js.map +1 -1
- package/dist-es/utils/useResizeObserver.js.map +1 -1
- package/dist-es/utils/useResponsiveProp.js.map +1 -1
- package/dist-types/combo-box/ComboBox.d.ts +2 -2
- package/dist-types/form-field/FormFieldHelperText.d.ts +3 -1
- package/dist-types/index.d.ts +1 -0
- package/dist-types/stepper/Step.d.ts +46 -0
- package/dist-types/stepper/Stepper.d.ts +9 -0
- package/dist-types/stepper/index.d.ts +2 -0
- package/dist-types/stepper/internal/StepConnector.d.ts +1 -0
- package/dist-types/stepper/internal/StepExpandTrigger.d.ts +5 -0
- package/dist-types/stepper/internal/StepIcon.d.ts +8 -0
- package/dist-types/stepper/internal/StepScreenReaderOnly.d.ts +5 -0
- package/dist-types/stepper/internal/StepText.d.ts +5 -0
- package/dist-types/stepper/internal/StepperProvider.d.ts +9 -0
- package/dist-types/toggle-button/ToggleButton.d.ts +30 -1
- package/dist-types/toggle-button-group/ToggleButtonGroup.d.ts +16 -2
- package/dist-types/toggle-button-group/ToggleButtonGroupContext.d.ts +6 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAriaAnnounce.js","sources":["../src/tooltip/useAriaAnnounce.ts"],"sourcesContent":["import type { ElementProps, FloatingContext } from \"@floating-ui/react\";\nimport { type PointerEvent, useEffect, useRef } from \"react\";\nimport { useAriaAnnouncer } from \"../aria-announcer\";\nimport { useIsomorphicLayoutEffect } from \"../utils\";\n\nfunction getDocument(floating: HTMLElement | null) {\n return floating?.ownerDocument ?? document;\n}\n\n// TODO: Check whether can be anything more restrictive than `any`\n// biome-ignore lint/suspicious/noExplicitAny: see comment above\nfunction getWindow(value: any) {\n return getDocument(value).defaultView ?? window;\n}\n\nfunction isElement(value: unknown): value is HTMLElement {\n return value ? value instanceof getWindow(value).Element : false;\n}\n\nfunction getDelay(\n value: Props[\"delay\"],\n prop: \"open\" | \"close\",\n pointerType?: PointerEvent[\"pointerType\"],\n) {\n if (pointerType && pointerType !== \"mouse\") {\n return 0;\n }\n\n if (typeof value === \"number\") {\n return value;\n }\n\n return value?.[prop];\n}\n\ntype Props = {\n delay?: number | Partial<{ open: number; close: number }>;\n};\n\nexport const useAriaAnnounce = (\n context: FloatingContext,\n { delay = 0 }: Props,\n): ElementProps => {\n const { open, dataRef, refs } = context;\n\n const pointerTypeRef = useRef<PointerEvent[\"pointerType\"]>();\n const timeoutRef = useRef<number>();\n const blockMouseMoveRef = useRef(true);\n const { announce } = useAriaAnnouncer();\n\n useIsomorphicLayoutEffect(() => {\n if (!open) {\n pointerTypeRef.current = undefined;\n }\n });\n\n useEffect(() => {\n const reference = refs.reference.current;\n function announceFloating() {\n const tooltipContent = refs.floating.current?.innerText;\n\n if (tooltipContent) {\n announce(tooltipContent);\n }\n }\n\n function onMouseEnter(event: MouseEvent) {\n clearTimeout(timeoutRef.current);\n\n if (open) {\n return;\n }\n\n blockMouseMoveRef.current = false;\n dataRef.current.openEvent = event;\n\n if (delay) {\n timeoutRef.current = window.setTimeout(\n () => {\n announceFloating();\n },\n getDelay(delay, \"open\", pointerTypeRef.current),\n );\n } else {\n announceFloating();\n }\n }\n\n if (isElement(reference)) {\n reference.addEventListener(\"mouseenter\", onMouseEnter);\n return () => {\n reference.removeEventListener(\"mouseenter\", onMouseEnter);\n };\n }\n }, [dataRef, delay, open, refs.reference, refs.floating, announce]);\n\n function setPointerRef(event: PointerEvent) {\n pointerTypeRef.current = event.pointerType;\n }\n\n return {\n reference: {\n onPointerDown: setPointerRef,\n onPointerEnter: setPointerRef,\n },\n floating: {\n onMouseEnter() {\n clearTimeout(timeoutRef.current);\n },\n },\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;AAKA,SAAS,YAAY,QAA8B,EAAA;AACjD,EAAA,OAAA,CAAO,qCAAU,aAAiB,KAAA,QAAA;AACpC;AAIA,SAAS,UAAU,KAAY,EAAA;AAC7B,EAAO,OAAA,WAAA,CAAY,KAAK,CAAA,CAAE,WAAe,IAAA,MAAA;AAC3C;AAEA,SAAS,UAAU,KAAsC,EAAA;AACvD,EAAA,OAAO,KAAQ,GAAA,KAAA,YAAiB,SAAU,CAAA,KAAK,EAAE,OAAU,GAAA,KAAA;AAC7D;AAEA,SAAS,QAAA,CACP,KACA,EAAA,IAAA,EACA,WACA,EAAA;AACA,EAAI,IAAA,WAAA,IAAe,gBAAgB,OAAS,EAAA;AAC1C,IAAO,OAAA,CAAA;AAAA;AAGT,EAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC7B,IAAO,OAAA,KAAA;AAAA;AAGT,EAAA,OAAO,KAAQ,IAAA,IAAA,GAAA,
|
|
1
|
+
{"version":3,"file":"useAriaAnnounce.js","sources":["../src/tooltip/useAriaAnnounce.ts"],"sourcesContent":["import type { ElementProps, FloatingContext } from \"@floating-ui/react\";\nimport { type PointerEvent, useEffect, useRef } from \"react\";\nimport { useAriaAnnouncer } from \"../aria-announcer\";\nimport { useIsomorphicLayoutEffect } from \"../utils\";\n\nfunction getDocument(floating: HTMLElement | null) {\n return floating?.ownerDocument ?? document;\n}\n\n// TODO: Check whether can be anything more restrictive than `any`\n// biome-ignore lint/suspicious/noExplicitAny: see comment above\nfunction getWindow(value: any) {\n return getDocument(value).defaultView ?? window;\n}\n\nfunction isElement(value: unknown): value is HTMLElement {\n return value ? value instanceof getWindow(value).Element : false;\n}\n\nfunction getDelay(\n value: Props[\"delay\"],\n prop: \"open\" | \"close\",\n pointerType?: PointerEvent[\"pointerType\"],\n) {\n if (pointerType && pointerType !== \"mouse\") {\n return 0;\n }\n\n if (typeof value === \"number\") {\n return value;\n }\n\n return value?.[prop];\n}\n\ntype Props = {\n delay?: number | Partial<{ open: number; close: number }>;\n};\n\nexport const useAriaAnnounce = (\n context: FloatingContext,\n { delay = 0 }: Props,\n): ElementProps => {\n const { open, dataRef, refs } = context;\n\n const pointerTypeRef = useRef<PointerEvent[\"pointerType\"]>();\n const timeoutRef = useRef<number>();\n const blockMouseMoveRef = useRef(true);\n const { announce } = useAriaAnnouncer();\n\n useIsomorphicLayoutEffect(() => {\n if (!open) {\n pointerTypeRef.current = undefined;\n }\n });\n\n useEffect(() => {\n const reference = refs.reference.current;\n function announceFloating() {\n const tooltipContent = refs.floating.current?.innerText;\n\n if (tooltipContent) {\n announce(tooltipContent);\n }\n }\n\n function onMouseEnter(event: MouseEvent) {\n clearTimeout(timeoutRef.current);\n\n if (open) {\n return;\n }\n\n blockMouseMoveRef.current = false;\n dataRef.current.openEvent = event;\n\n if (delay) {\n timeoutRef.current = window.setTimeout(\n () => {\n announceFloating();\n },\n getDelay(delay, \"open\", pointerTypeRef.current),\n );\n } else {\n announceFloating();\n }\n }\n\n if (isElement(reference)) {\n reference.addEventListener(\"mouseenter\", onMouseEnter);\n return () => {\n reference.removeEventListener(\"mouseenter\", onMouseEnter);\n };\n }\n }, [dataRef, delay, open, refs.reference, refs.floating, announce]);\n\n function setPointerRef(event: PointerEvent) {\n pointerTypeRef.current = event.pointerType;\n }\n\n return {\n reference: {\n onPointerDown: setPointerRef,\n onPointerEnter: setPointerRef,\n },\n floating: {\n onMouseEnter() {\n clearTimeout(timeoutRef.current);\n },\n },\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;AAKA,SAAS,YAAY,QAA8B,EAAA;AACjD,EAAA,OAAA,CAAO,qCAAU,aAAiB,KAAA,QAAA;AACpC;AAIA,SAAS,UAAU,KAAY,EAAA;AAC7B,EAAO,OAA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import { offset, shift,
|
|
1
|
+
import { offset, shift, flip, arrow, limitShift, useInteractions, useHover, useFocus, useRole, useDismiss, safePolygon } from '@floating-ui/react';
|
|
2
2
|
import { useRef } from 'react';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
import 'clsx';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTooltip.js","sources":["../src/tooltip/useTooltip.ts"],"sourcesContent":["import {\n arrow,\n flip,\n limitShift,\n offset,\n safePolygon,\n shift,\n useDismiss,\n useFocus,\n useHover,\n useInteractions,\n useRole,\n} from \"@floating-ui/react\";\nimport { type HTMLProps, useRef } from \"react\";\nimport {\n type UseFloatingUIProps,\n useControlled,\n useFloatingUI,\n} from \"../utils\";\nimport { useAriaAnnounce } from \"./useAriaAnnounce\";\n\nexport interface UseTooltipProps\n extends Partial<\n Pick<UseFloatingUIProps, \"onOpenChange\" | \"open\" | \"placement\">\n > {\n /**\n * When `true`, the tooltip will be disabled.\n */\n disabled?: boolean;\n /**\n * Do not respond to focus events.\n */\n disableFocusListener?: boolean;\n /**\n * Do not respond to hover events.\n */\n disableHoverListener?: boolean;\n /**\n * The number of milliseconds to wait before showing the tooltip.\n * This prop won't impact the enter touch delay (`enterTouchDelay`).\n */\n enterDelay?: number;\n /**\n * The number of milliseconds to wait before hiding the tooltip.\n * This prop won't impact the leave touch delay (`leaveTouchDelay`).\n */\n leaveDelay?: number;\n}\n\nexport function useTooltip(props?: UseTooltipProps) {\n const {\n enterDelay,\n disabled,\n leaveDelay,\n open: openProp,\n onOpenChange,\n placement: placementProp,\n disableHoverListener,\n disableFocusListener,\n } = props ?? {};\n\n const arrowRef = useRef<SVGSVGElement | null>(null);\n\n const [open, setOpen] = useControlled({\n controlled: openProp,\n default: false,\n name: \"Tooltip\",\n state: \"open\",\n });\n const handleOpenChange = (open: boolean) => {\n setOpen(open);\n onOpenChange?.(open);\n };\n\n const { floating, reference, x, y, strategy, placement, context, elements } =\n useFloatingUI({\n open: disabled ? false : open,\n onOpenChange: handleOpenChange,\n placement: placementProp,\n middleware: [\n offset(8),\n shift({ limiter: limitShift() }),\n flip({\n fallbackAxisSideDirection: \"end\",\n fallbackStrategy: \"initialPlacement\",\n }),\n arrow({ element: arrowRef }),\n ],\n });\n\n const { getReferenceProps, getFloatingProps } = useInteractions([\n useHover(context, {\n delay: {\n open: enterDelay,\n close: leaveDelay,\n },\n enabled: !(disableHoverListener || disabled),\n handleClose: safePolygon(),\n }),\n useFocus(context, { enabled: !(disableFocusListener || disabled) }),\n useRole(context, { role: \"tooltip\" }),\n useDismiss(context, { enabled: !disabled }),\n useAriaAnnounce(context, {\n delay: {\n open: enterDelay,\n close: leaveDelay,\n },\n }),\n ]);\n\n const arrowProps = {\n ref: arrowRef,\n context,\n };\n\n const getTooltipProps = (): HTMLProps<HTMLDivElement> => {\n // tabIndex raises false positives because it is set to \"-1\".\n const { tabIndex, ...tooltipProps } = getFloatingProps({\n // @ts-expect-error - `data-*` props need extra typing when not used on a DOM element.\n \"data-placement\": placement,\n ref: floating,\n });\n\n return tooltipProps;\n };\n\n const getTriggerProps = () =>\n getReferenceProps({\n ref: reference,\n });\n\n const getTooltipPosition = () => ({\n top: y ?? 0,\n left: x ?? 0,\n position: strategy,\n width: elements.floating?.offsetWidth,\n height: elements.floating?.offsetHeight,\n });\n\n return {\n arrowProps,\n open,\n floating,\n reference,\n getTooltipProps,\n getTriggerProps,\n getTooltipPosition,\n };\n}\n"],"names":["open"],"mappings":";;;;;;;;;;;AAiDO,SAAS,WAAW,KAAyB,EAAA;AAClD,EAAM,MAAA;AAAA,IACJ,UAAA;AAAA,IACA,QAAA;AAAA,IACA,UAAA;AAAA,IACA,IAAM,EAAA,QAAA;AAAA,IACN,YAAA;AAAA,IACA,SAAW,EAAA,aAAA;AAAA,IACX,oBAAA;AAAA,IACA;AAAA,GACF,GAAI,SAAS,EAAC;AAEd,EAAM,MAAA,QAAA,GAAW,OAA6B,IAAI,CAAA;AAElD,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAI,aAAc,CAAA;AAAA,IACpC,UAAY,EAAA,QAAA;AAAA,IACZ,OAAS,EAAA,KAAA;AAAA,IACT,IAAM,EAAA,SAAA;AAAA,IACN,KAAO,EAAA;AAAA,GACR,CAAA;AACD,EAAM,MAAA,gBAAA,GAAmB,CAACA,KAAkB,KAAA;AAC1C,IAAA,OAAA,CAAQA,KAAI,CAAA;AACZ,IAAeA,YAAAA,IAAAA,IAAAA,GAAAA,
|
|
1
|
+
{"version":3,"file":"useTooltip.js","sources":["../src/tooltip/useTooltip.ts"],"sourcesContent":["import {\n arrow,\n flip,\n limitShift,\n offset,\n safePolygon,\n shift,\n useDismiss,\n useFocus,\n useHover,\n useInteractions,\n useRole,\n} from \"@floating-ui/react\";\nimport { type HTMLProps, useRef } from \"react\";\nimport {\n type UseFloatingUIProps,\n useControlled,\n useFloatingUI,\n} from \"../utils\";\nimport { useAriaAnnounce } from \"./useAriaAnnounce\";\n\nexport interface UseTooltipProps\n extends Partial<\n Pick<UseFloatingUIProps, \"onOpenChange\" | \"open\" | \"placement\">\n > {\n /**\n * When `true`, the tooltip will be disabled.\n */\n disabled?: boolean;\n /**\n * Do not respond to focus events.\n */\n disableFocusListener?: boolean;\n /**\n * Do not respond to hover events.\n */\n disableHoverListener?: boolean;\n /**\n * The number of milliseconds to wait before showing the tooltip.\n * This prop won't impact the enter touch delay (`enterTouchDelay`).\n */\n enterDelay?: number;\n /**\n * The number of milliseconds to wait before hiding the tooltip.\n * This prop won't impact the leave touch delay (`leaveTouchDelay`).\n */\n leaveDelay?: number;\n}\n\nexport function useTooltip(props?: UseTooltipProps) {\n const {\n enterDelay,\n disabled,\n leaveDelay,\n open: openProp,\n onOpenChange,\n placement: placementProp,\n disableHoverListener,\n disableFocusListener,\n } = props ?? {};\n\n const arrowRef = useRef<SVGSVGElement | null>(null);\n\n const [open, setOpen] = useControlled({\n controlled: openProp,\n default: false,\n name: \"Tooltip\",\n state: \"open\",\n });\n const handleOpenChange = (open: boolean) => {\n setOpen(open);\n onOpenChange?.(open);\n };\n\n const { floating, reference, x, y, strategy, placement, context, elements } =\n useFloatingUI({\n open: disabled ? false : open,\n onOpenChange: handleOpenChange,\n placement: placementProp,\n middleware: [\n offset(8),\n shift({ limiter: limitShift() }),\n flip({\n fallbackAxisSideDirection: \"end\",\n fallbackStrategy: \"initialPlacement\",\n }),\n arrow({ element: arrowRef }),\n ],\n });\n\n const { getReferenceProps, getFloatingProps } = useInteractions([\n useHover(context, {\n delay: {\n open: enterDelay,\n close: leaveDelay,\n },\n enabled: !(disableHoverListener || disabled),\n handleClose: safePolygon(),\n }),\n useFocus(context, { enabled: !(disableFocusListener || disabled) }),\n useRole(context, { role: \"tooltip\" }),\n useDismiss(context, { enabled: !disabled }),\n useAriaAnnounce(context, {\n delay: {\n open: enterDelay,\n close: leaveDelay,\n },\n }),\n ]);\n\n const arrowProps = {\n ref: arrowRef,\n context,\n };\n\n const getTooltipProps = (): HTMLProps<HTMLDivElement> => {\n // tabIndex raises false positives because it is set to \"-1\".\n const { tabIndex, ...tooltipProps } = getFloatingProps({\n // @ts-expect-error - `data-*` props need extra typing when not used on a DOM element.\n \"data-placement\": placement,\n ref: floating,\n });\n\n return tooltipProps;\n };\n\n const getTriggerProps = () =>\n getReferenceProps({\n ref: reference,\n });\n\n const getTooltipPosition = () => ({\n top: y ?? 0,\n left: x ?? 0,\n position: strategy,\n width: elements.floating?.offsetWidth,\n height: elements.floating?.offsetHeight,\n });\n\n return {\n arrowProps,\n open,\n floating,\n reference,\n getTooltipProps,\n getTriggerProps,\n getTooltipPosition,\n };\n}\n"],"names":["open"],"mappings":";;;;;;;;;;;AAiDO,SAAS,WAAW,KAAyB,EAAA;AAClD,EAAM,MAAA;AAAA,IACJ,UAAA;AAAA,IACA,QAAA;AAAA,IACA,UAAA;AAAA,IACA,IAAM,EAAA,QAAA;AAAA,IACN,YAAA;AAAA,IACA,SAAW,EAAA,aAAA;AAAA,IACX,oBAAA;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EA,EAAO,OAAA;AAAA,IACL,UAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,eAAA;AAAA,IACA,eAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeProps.js","sources":["../src/utils/mergeProps.ts"],"sourcesContent":["import { clsx } from \"clsx\";\nimport { createChainedFunction } from \"./createChainedFunction\";\n\ninterface Props {\n [key: string]: unknown;\n}\n\n/**\n * This utility merges two prop objects according to the following rules:\n *\n * - If the prop is a function and begins with \"on\" then chain the functions together\n * - If the prop key is \"className\" then merge them using `clsx`\n * - If the prop is anything else, then use the value from the second parameter unless it's undefined then use the value from the first parameter\n */\nexport function mergeProps(\n propsA: Props,\n propsB: Props,\n): Record<string, unknown> {\n const props = { ...propsA };\n\n Object.keys(propsB).forEach((key) => {\n const a: any = props[key];\n const b: any = propsB[key];\n\n if (\n typeof a === \"function\" &&\n typeof b === \"function\" &&\n key.indexOf(\"on\") === 0\n ) {\n props[key] = createChainedFunction(a, b);\n } else if (\n typeof a === \"string\" &&\n typeof b === \"string\" &&\n key === \"className\"\n ) {\n props[key] = clsx(a, b);\n } else {\n props[key] = b !== undefined ? b : a;\n }\n });\n\n return props;\n}\n"],"names":[],"mappings":";;;AAcgB,SAAA,UAAA,CACd,QACA,MACyB,EAAA;AACzB,EAAM,MAAA,KAAA,GAAQ,EAAE,GAAG,MAAO,EAAA;AAE1B,EAAA,MAAA,CAAO,IAAK,CAAA,MAAM,CAAE,CAAA,OAAA,CAAQ,CAAC,GAAQ,KAAA;AACnC,IAAM,MAAA,CAAA,GAAS,MAAM,GAAG,CAAA;AACxB,IAAM,MAAA,CAAA,GAAS,OAAO,GAAG,CAAA;AAEzB,IACE,IAAA,OAAO,CAAM,KAAA,UAAA,IACb,OAAO,CAAA,KAAM,cACb,GAAI,CAAA,OAAA,CAAQ,IAAI,CAAA,KAAM,CACtB,EAAA;AACA,MAAA,KAAA,CAAM,GAAG,CAAA,GAAI,qBAAsB,CAAA,CAAA,EAAG,CAAC,CAAA;AAAA,KACzC,MAAA,IACE,OAAO,CAAM,KAAA,QAAA,IACb,OAAO,CAAM,KAAA,QAAA,IACb,QAAQ,WACR,EAAA;AACA,MAAA,KAAA,CAAM,GAAG,CAAA,GAAI,IAAK,CAAA,CAAA,EAAG,CAAC,CAAA;AAAA,KACjB,MAAA;AACL,MAAA,KAAA,CAAM,GAAG,CAAA,GAAI,CAAM,KAAA,
|
|
1
|
+
{"version":3,"file":"mergeProps.js","sources":["../src/utils/mergeProps.ts"],"sourcesContent":["import { clsx } from \"clsx\";\nimport { createChainedFunction } from \"./createChainedFunction\";\n\ninterface Props {\n [key: string]: unknown;\n}\n\n/**\n * This utility merges two prop objects according to the following rules:\n *\n * - If the prop is a function and begins with \"on\" then chain the functions together\n * - If the prop key is \"className\" then merge them using `clsx`\n * - If the prop is anything else, then use the value from the second parameter unless it's undefined then use the value from the first parameter\n */\nexport function mergeProps(\n propsA: Props,\n propsB: Props,\n): Record<string, unknown> {\n const props = { ...propsA };\n\n Object.keys(propsB).forEach((key) => {\n const a: any = props[key];\n const b: any = propsB[key];\n\n if (\n typeof a === \"function\" &&\n typeof b === \"function\" &&\n key.indexOf(\"on\") === 0\n ) {\n props[key] = createChainedFunction(a, b);\n } else if (\n typeof a === \"string\" &&\n typeof b === \"string\" &&\n key === \"className\"\n ) {\n props[key] = clsx(a, b);\n } else {\n props[key] = b !== undefined ? b : a;\n }\n });\n\n return props;\n}\n"],"names":[],"mappings":";;;AAcgB,SAAA,UAAA,CACd,QACA,MACyB,EAAA;AACzB,EAAM,MAAA,KAAA,GAAQ,EAAE,GAAG,MAAO,EAAA;AAE1B,EAAA,MAAA,CAAO,IAAK,CAAA,MAAM,CAAE,CAAA,OAAA,CAAQ,CAAC,GAAQ,KAAA;AACnC,IAAM,MAAA,CAAA,GAAS,MAAM,GAAG,CAAA;AACxB,IAAM,MAAA,CAAA,GAAS,OAAO,GAAG,CAAA;AAEzB,IACE,IAAA,OAAO,CAAM,KAAA,UAAA,IACb,OAAO,CAAA,KAAM,cACb,GAAI,CAAA,OAAA,CAAQ,IAAI,CAAA,KAAM,CACtB,EAAA;AACA,MAAA,KAAA,CAAM,GAAG,CAAA,GAAI,qBAAsB,CAAA,CAAA,EAAG,CAAC,CAAA;AAAA,KACzC,MAAA,IACE,OAAO,CAAM,KAAA,QAAA,IACb,OAAO,CAAM,KAAA,QAAA,IACb,QAAQ,WACR,EAAA;AACA,MAAA,KAAA,CAAM,GAAG,CAAA,GAAI,IAAK,CAAA,CAAA,EAAG,CAAC,CAAA;AAAA,KACjB,MAAA;AACL,MAAA,KAAA,CAAM,GAAG,CAAA,GAAI,CAAM,KAAA,MAAA,GAAY,CAAI,GAAA,CAAA;AAAA;AACrC,GACD,CAAA;AAED,EAAO,OAAA,KAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControlled.js","sources":["../src/utils/useControlled.ts"],"sourcesContent":["import {\n type Dispatch,\n type SetStateAction,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\n\nexport interface UseControlledProps<T> {\n /**\n * Holds the component value when it's controlled.\n */\n controlled?: T;\n /**\n * The default value when uncontrolled.\n */\n default: T;\n /**\n * The component name displayed in warnings.\n */\n name: string;\n /**\n * The name of the state variable displayed in warnings.\n */\n state?: string;\n}\n\n/**\n * Copied from MUI (v5) useControlled hook with one additional returned value\n * @see https://github.com/mui-org/material-ui/blob/0979e6a54ba47c278d1f535953c0520a86349811/packages/material-ui-utils/src/useControlled.js\n */\nexport function useControlled<S>({\n controlled,\n default: defaultProp,\n name,\n state = \"value\",\n}: UseControlledProps<S>): [S, Dispatch<SetStateAction<S>>, boolean] {\n const { current: isControlled } = useRef(controlled !== undefined);\n const [valueState, setValue] = useState<S>(defaultProp);\n const value = controlled !== undefined ? controlled : valueState;\n const { current: defaultValue } = useRef(defaultProp);\n\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\") {\n if (isControlled !== (controlled !== undefined)) {\n console.error(\n [\n `Salt: A component is changing the ${\n isControlled ? \"\" : \"un\"\n }controlled ${state} state of ${name} to be ${\n isControlled ? \"un\" : \"\"\n }controlled.`,\n \"Elements should not switch from uncontrolled to controlled (or vice versa).\",\n `Decide between using a controlled or uncontrolled ${name} element for the lifetime of the component.`,\n \"The nature of the state is determined during the first render, it's considered controlled if the value is not `undefined`.\",\n \"More info: https://reactjs.org/link/controlled-components\",\n ].join(\"\\n\"),\n );\n }\n }\n return undefined;\n }, [state, name, controlled]);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: uses JSON.stringify to compare defaultProp\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\") {\n if (!isControlled && defaultValue !== defaultProp) {\n console.error(\n [\n `Salt: A component is changing the default ${state} state of an uncontrolled ${name} after being initialized. ` +\n `To suppress this warning opt to use a controlled ${name}.`,\n ].join(\"\\n\"),\n );\n }\n }\n return undefined;\n }, [JSON.stringify(defaultProp, ignoreReactElements)]);\n\n const setValueIfUncontrolled: Dispatch<SetStateAction<S>> = useCallback(\n (newValue) => {\n if (!isControlled) {\n setValue(newValue);\n }\n },\n [],\n );\n\n return [value, setValueIfUncontrolled, isControlled];\n}\n\n// Ignore ReactElements in JSON, they contain circular refs\nfunction ignoreReactElements<T>(key: string, value: T): T | null {\n return isValidElement(value) ? null : value;\n}\n"],"names":[],"mappings":";;AAiCO,SAAS,aAAiB,CAAA;AAAA,EAC/B,UAAA;AAAA,EACA,OAAS,EAAA,WAAA;AAAA,EACT,IAAA;AAAA,EACA,KAAQ,GAAA;AACV,CAAqE,EAAA;AACnE,EAAA,MAAM,EAAE,OAAS,EAAA,YAAA,EAAiB,GAAA,MAAA,CAAO,eAAe,
|
|
1
|
+
{"version":3,"file":"useControlled.js","sources":["../src/utils/useControlled.ts"],"sourcesContent":["import {\n type Dispatch,\n type SetStateAction,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\n\nexport interface UseControlledProps<T> {\n /**\n * Holds the component value when it's controlled.\n */\n controlled?: T;\n /**\n * The default value when uncontrolled.\n */\n default: T;\n /**\n * The component name displayed in warnings.\n */\n name: string;\n /**\n * The name of the state variable displayed in warnings.\n */\n state?: string;\n}\n\n/**\n * Copied from MUI (v5) useControlled hook with one additional returned value\n * @see https://github.com/mui-org/material-ui/blob/0979e6a54ba47c278d1f535953c0520a86349811/packages/material-ui-utils/src/useControlled.js\n */\nexport function useControlled<S>({\n controlled,\n default: defaultProp,\n name,\n state = \"value\",\n}: UseControlledProps<S>): [S, Dispatch<SetStateAction<S>>, boolean] {\n const { current: isControlled } = useRef(controlled !== undefined);\n const [valueState, setValue] = useState<S>(defaultProp);\n const value = controlled !== undefined ? controlled : valueState;\n const { current: defaultValue } = useRef(defaultProp);\n\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\") {\n if (isControlled !== (controlled !== undefined)) {\n console.error(\n [\n `Salt: A component is changing the ${\n isControlled ? \"\" : \"un\"\n }controlled ${state} state of ${name} to be ${\n isControlled ? \"un\" : \"\"\n }controlled.`,\n \"Elements should not switch from uncontrolled to controlled (or vice versa).\",\n `Decide between using a controlled or uncontrolled ${name} element for the lifetime of the component.`,\n \"The nature of the state is determined during the first render, it's considered controlled if the value is not `undefined`.\",\n \"More info: https://reactjs.org/link/controlled-components\",\n ].join(\"\\n\"),\n );\n }\n }\n return undefined;\n }, [state, name, controlled]);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: uses JSON.stringify to compare defaultProp\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\") {\n if (!isControlled && defaultValue !== defaultProp) {\n console.error(\n [\n `Salt: A component is changing the default ${state} state of an uncontrolled ${name} after being initialized. ` +\n `To suppress this warning opt to use a controlled ${name}.`,\n ].join(\"\\n\"),\n );\n }\n }\n return undefined;\n }, [JSON.stringify(defaultProp, ignoreReactElements)]);\n\n const setValueIfUncontrolled: Dispatch<SetStateAction<S>> = useCallback(\n (newValue) => {\n if (!isControlled) {\n setValue(newValue);\n }\n },\n [],\n );\n\n return [value, setValueIfUncontrolled, isControlled];\n}\n\n// Ignore ReactElements in JSON, they contain circular refs\nfunction ignoreReactElements<T>(key: string, value: T): T | null {\n return isValidElement(value) ? null : value;\n}\n"],"names":[],"mappings":";;AAiCO,SAAS,aAAiB,CAAA;AAAA,EAC/B,UAAA;AAAA,EACA,OAAS,EAAA,WAAA;AAAA,EACT,IAAA;AAAA,EACA,KAAQ,GAAA;AACV,CAAqE,EAAA;AACnE,EAAA,MAAM,EAAE,OAAS,EAAA,YAAA,EAAiB,GAAA,MAAA,CAAO,eAAe,MAAS,CAAA;AACjE,EAAA,MAAM,CAAC,UAAA,EAAY,QAAQ,CAAA,GAAI,SAAY,WAAW,CAAA;AACtD,EAAM,MAAA,KAAA,GAAQ,UAAe,KAAA,MAAA,GAAY,UAAa,GAAA,UAAA;AACtD,EAAA,MAAM,EAAE,OAAA,EAAS,YAAa,EAAA,GAAI,OAAO,WAAW,CAAA;AAEpD,EAAA,SAAA,CAAU,MAAM;AACd,IAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AACzC,MAAI,IAAA,YAAA,MAAkB,eAAe,MAAY,CAAA,EAAA;AAC/C,QAAQ,OAAA,CAAA,KAAA;AAAA,UACN;AAAA,YACE,CAAA,kCAAA,EACE,YAAe,GAAA,EAAA,GAAK,IACtB,CAAA,WAAA,EAAc,KAAK,CAAA,UAAA,EAAa,IAAI,CAAA,OAAA,EAClC,YAAe,GAAA,IAAA,GAAO,EACxB,CAAA,WAAA,CAAA;AAAA,YACA,6EAAA;AAAA,YACA,qDAAqD,IAAI,CAAA,2CAAA,CAAA;AAAA,YACzD,4HAAA;AAAA,YACA;AAAA,WACF,CAAE,KAAK,IAAI;AAAA,SACb;AAAA;AACF;AAEF,IAAO,OAAA,MAAA;AAAA,GACN,EAAA,CAAC,KAAO,EAAA,IAAA,EAAM,UAAU,CAAC,CAAA;AAG5B,EAAA,SAAA,CAAU,MAAM;AACd,IAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AACzC,MAAI,IAAA,CAAC,YAAgB,IAAA,YAAA,KAAiB,WAAa,EAAA;AACjD,QAAQ,OAAA,CAAA,KAAA;AAAA,UACN;AAAA,YACE,CAA6C,0CAAA,EAAA,KAAK,CAA6B,0BAAA,EAAA,IAAI,8EAC7B,IAAI,CAAA,CAAA;AAAA,WAC5D,CAAE,KAAK,IAAI;AAAA,SACb;AAAA;AACF;AAEF,IAAO,OAAA,MAAA;AAAA,KACN,CAAC,IAAA,CAAK,UAAU,WAAa,EAAA,mBAAmB,CAAC,CAAC,CAAA;AAErD,EAAA,MAAM,sBAAsD,GAAA,WAAA;AAAA,IAC1D,CAAC,QAAa,KAAA;AACZ,MAAA,IAAI,CAAC,YAAc,EAAA;AACjB,QAAA,QAAA,CAAS,QAAQ,CAAA;AAAA;AACnB,KACF;AAAA,IACA;AAAC,GACH;AAEA,EAAO,OAAA,CAAC,KAAO,EAAA,sBAAA,EAAwB,YAAY,CAAA;AACrD;AAGA,SAAS,mBAAA,CAAuB,KAAa,KAAoB,EAAA;AAC/D,EAAO,OAAA,cAAA,CAAe,KAAK,CAAA,GAAI,IAAO,GAAA,KAAA;AACxC;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { FloatingPortal, FloatingFocusManager, flip, shift, limitShift,
|
|
3
|
-
import { forwardRef, createContext,
|
|
2
|
+
import { FloatingPortal, FloatingFocusManager, platform, flip, shift, limitShift, useFloating, autoUpdate } from '@floating-ui/react';
|
|
3
|
+
import { forwardRef, createContext, useContext, useMemo } from 'react';
|
|
4
4
|
import { useTheme, SaltProviderNext, SaltProvider } from '../../salt-provider/SaltProvider.js';
|
|
5
5
|
import { usePreventScroll } from '../usePreventScroll.js';
|
|
6
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFloatingUI.js","sources":["../src/utils/useFloatingUI/useFloatingUI.tsx"],"sourcesContent":["import {\n FloatingFocusManager,\n type FloatingFocusManagerProps,\n FloatingPortal,\n type Middleware,\n type Platform,\n type Strategy,\n type UseFloatingOptions,\n autoUpdate,\n flip,\n limitShift,\n platform,\n shift,\n useFloating,\n} from \"@floating-ui/react\";\nimport {\n type ComponentPropsWithoutRef,\n type ReactNode,\n createContext,\n forwardRef,\n useContext,\n useMemo,\n} from \"react\";\nimport { SaltProvider, SaltProviderNext, useTheme } from \"../../salt-provider\";\nimport { usePreventScroll } from \"../usePreventScroll\";\n\nexport interface FloatingComponentProps\n extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * Whether the floating component is open (used for determining whether to show the component)\n * We pass this as a prop rather than not rendering the component to allow more advanced use-cases e.g.\n * for caching windows and reusing them, rather than always spawning a new one\n */\n open: boolean;\n /**\n * Use this prop when `FloatingFocusManager` is needed for floating component\n */\n focusManagerProps?: Omit<FloatingFocusManagerProps, \"children\">;\n /**\n * Position and sizing optional props for the floating component. `top`, `left`, and `position` for floating elements where they aren't positioned with relative to the trigger.\n * `width` and `height` are used to define the size of the floating element.\n *\n */\n top?: number;\n left?: number;\n width?: number;\n height?: number;\n position?: Strategy;\n /**\n * Makes the page unscrollable when the floating component is open.\n */\n lockScroll?: boolean;\n}\n\nconst DefaultFloatingComponent = forwardRef<\n HTMLDivElement,\n FloatingComponentProps\n>(function DefaultFloatingComponent(props, ref) {\n const {\n open,\n top,\n left,\n position,\n width,\n height,\n focusManagerProps,\n lockScroll,\n ...rest\n } = props;\n const style = {\n top,\n left,\n position,\n };\n\n const { themeNext } = useTheme();\n usePreventScroll({ isDisabled: !lockScroll || !open });\n\n const ChosenSaltProvider = themeNext ? SaltProviderNext : SaltProvider;\n\n if (focusManagerProps && open) {\n return (\n <FloatingPortal>\n <ChosenSaltProvider applyClassesTo=\"scope\">\n <FloatingFocusManager {...focusManagerProps}>\n <div style={style} {...rest} ref={ref} />\n </FloatingFocusManager>\n </ChosenSaltProvider>\n </FloatingPortal>\n );\n }\n\n return open ? (\n <FloatingPortal>\n <ChosenSaltProvider applyClassesTo=\"scope\">\n <div style={style} {...rest} ref={ref} />\n </ChosenSaltProvider>\n </FloatingPortal>\n ) : null;\n});\n\nexport interface FloatingComponentContextType {\n Component: typeof DefaultFloatingComponent;\n}\n\nconst FloatingComponentContext = createContext<FloatingComponentContextType>({\n Component: DefaultFloatingComponent,\n});\n\nif (process.env.NODE_ENV !== \"production\") {\n FloatingComponentContext.displayName = \"FloatingComponentContext\";\n}\n\nexport interface FloatingComponentProviderProps\n extends FloatingComponentContextType {\n children: ReactNode;\n}\n\nexport function FloatingComponentProvider(\n props: FloatingComponentProviderProps,\n) {\n const { Component, children } = props;\n const value = useMemo(() => ({ Component }), [Component]);\n\n return (\n <FloatingComponentContext.Provider value={value}>\n {children}\n </FloatingComponentContext.Provider>\n );\n}\n\nexport function useFloatingComponent() {\n return useContext(FloatingComponentContext);\n}\n\nexport interface UseFloatingUIProps\n extends Pick<\n UseFloatingOptions,\n \"placement\" | \"strategy\" | \"open\" | \"onOpenChange\" | \"nodeId\"\n > {\n /**\n * Function to update the default middleware used to extend or replace it\n */\n middleware?: Middleware[];\n}\n\ntype GetMiddleware = (middleware: Middleware[]) => Middleware[];\n\nconst defaultGetMiddleware: GetMiddleware = (defaultMiddleware) =>\n defaultMiddleware;\n\ninterface FloatingPlatformContextType {\n platform: Platform;\n middleware: GetMiddleware;\n animationFrame: boolean;\n}\n\nconst defaultFloatingPlaform: FloatingPlatformContextType = {\n platform,\n middleware: defaultGetMiddleware,\n animationFrame: false,\n};\n\nconst FloatingPlatformContext = createContext<FloatingPlatformContextType>(\n defaultFloatingPlaform,\n);\n\nexport interface FloatingPlatformProviderProps {\n platform?: Platform;\n middleware?: GetMiddleware;\n children: ReactNode;\n animationFrame?: boolean;\n}\n\nexport function FloatingPlatformProvider(props: FloatingPlatformProviderProps) {\n const {\n platform: platformProp,\n middleware,\n animationFrame,\n children,\n } = props;\n\n const floatingPlatformContextValue = useMemo<FloatingPlatformContextType>(\n () => ({\n platform: platformProp ?? platform,\n middleware: middleware ?? defaultGetMiddleware,\n animationFrame: animationFrame || false,\n }),\n [platformProp, middleware, animationFrame],\n );\n\n return (\n <FloatingPlatformContext.Provider value={floatingPlatformContextValue}>\n {children}\n </FloatingPlatformContext.Provider>\n );\n}\n\nexport function useFloatingPlatform() {\n return useContext(FloatingPlatformContext);\n}\n\nexport const DEFAULT_FLOATING_UI_MIDDLEWARE = [\n flip(),\n shift({ limiter: limitShift() }),\n];\n\ntype UseFloatingRefs = ReturnType<typeof useFloating>[\"refs\"];\n\nexport interface UseFloatingUIReturn extends ReturnType<typeof useFloating> {\n reference: UseFloatingRefs[\"setReference\"];\n floating: UseFloatingRefs[\"setFloating\"];\n}\n\nexport function useFloatingUI(props: UseFloatingUIProps): UseFloatingUIReturn {\n const {\n middleware = DEFAULT_FLOATING_UI_MIDDLEWARE,\n open = false,\n onOpenChange,\n ...other\n } = props;\n\n const handleOpenChange: UseFloatingUIProps[\"onOpenChange\"] = (\n open,\n boolean,\n reason,\n ) => {\n update();\n onOpenChange?.(open, boolean, reason);\n };\n\n const {\n platform: contextPlatform,\n middleware: contextMiddleware,\n animationFrame,\n } = useFloatingPlatform();\n\n const { refs, update, ...rest } = useFloating({\n ...other,\n middleware: contextMiddleware(middleware),\n open,\n onOpenChange: handleOpenChange,\n whileElementsMounted: (...args) => {\n const cleanup = autoUpdate(...args, { animationFrame });\n\n return cleanup;\n },\n platform: contextPlatform,\n });\n\n return {\n reference: refs.setReference,\n floating: refs.setFloating,\n refs,\n update,\n ...rest,\n };\n}\n"],"names":["DefaultFloatingComponent","open"],"mappings":";;;;;;AAsDA,MAAM,wBAA2B,GAAA,UAAA,CAG/B,SAASA,yBAAAA,CAAyB,OAAO,GAAK,EAAA;AAC9C,EAAM,MAAA;AAAA,IACJ,IAAA;AAAA,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,UAAa,GAAA,8BAAA;AAAA,IACb,IAAO,GAAA,KAAA;AAAA,IACP,YAAA;AAAA,IACA,GAAG;AAAA,GACD,GAAA,KAAA;AAEJ,EAAA,MAAM,gBAAuD,GAAA,CAC3DC,KACA,EAAA,OAAA,EACA,MACG,KAAA;AACH,IAAO,MAAA,EAAA;AACP,IAAA,YAAA,IAAA,IAAA,GAAA,
|
|
1
|
+
{"version":3,"file":"useFloatingUI.js","sources":["../src/utils/useFloatingUI/useFloatingUI.tsx"],"sourcesContent":["import {\n FloatingFocusManager,\n type FloatingFocusManagerProps,\n FloatingPortal,\n type Middleware,\n type Platform,\n type Strategy,\n type UseFloatingOptions,\n autoUpdate,\n flip,\n limitShift,\n platform,\n shift,\n useFloating,\n} from \"@floating-ui/react\";\nimport {\n type ComponentPropsWithoutRef,\n type ReactNode,\n createContext,\n forwardRef,\n useContext,\n useMemo,\n} from \"react\";\nimport { SaltProvider, SaltProviderNext, useTheme } from \"../../salt-provider\";\nimport { usePreventScroll } from \"../usePreventScroll\";\n\nexport interface FloatingComponentProps\n extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * Whether the floating component is open (used for determining whether to show the component)\n * We pass this as a prop rather than not rendering the component to allow more advanced use-cases e.g.\n * for caching windows and reusing them, rather than always spawning a new one\n */\n open: boolean;\n /**\n * Use this prop when `FloatingFocusManager` is needed for floating component\n */\n focusManagerProps?: Omit<FloatingFocusManagerProps, \"children\">;\n /**\n * Position and sizing optional props for the floating component. `top`, `left`, and `position` for floating elements where they aren't positioned with relative to the trigger.\n * `width` and `height` are used to define the size of the floating element.\n *\n */\n top?: number;\n left?: number;\n width?: number;\n height?: number;\n position?: Strategy;\n /**\n * Makes the page unscrollable when the floating component is open.\n */\n lockScroll?: boolean;\n}\n\nconst DefaultFloatingComponent = forwardRef<\n HTMLDivElement,\n FloatingComponentProps\n>(function DefaultFloatingComponent(props, ref) {\n const {\n open,\n top,\n left,\n position,\n width,\n height,\n focusManagerProps,\n lockScroll,\n ...rest\n } = props;\n const style = {\n top,\n left,\n position,\n };\n\n const { themeNext } = useTheme();\n usePreventScroll({ isDisabled: !lockScroll || !open });\n\n const ChosenSaltProvider = themeNext ? SaltProviderNext : SaltProvider;\n\n if (focusManagerProps && open) {\n return (\n <FloatingPortal>\n <ChosenSaltProvider applyClassesTo=\"scope\">\n <FloatingFocusManager {...focusManagerProps}>\n <div style={style} {...rest} ref={ref} />\n </FloatingFocusManager>\n </ChosenSaltProvider>\n </FloatingPortal>\n );\n }\n\n return open ? (\n <FloatingPortal>\n <ChosenSaltProvider applyClassesTo=\"scope\">\n <div style={style} {...rest} ref={ref} />\n </ChosenSaltProvider>\n </FloatingPortal>\n ) : null;\n});\n\nexport interface FloatingComponentContextType {\n Component: typeof DefaultFloatingComponent;\n}\n\nconst FloatingComponentContext = createContext<FloatingComponentContextType>({\n Component: DefaultFloatingComponent,\n});\n\nif (process.env.NODE_ENV !== \"production\") {\n FloatingComponentContext.displayName = \"FloatingComponentContext\";\n}\n\nexport interface FloatingComponentProviderProps\n extends FloatingComponentContextType {\n children: ReactNode;\n}\n\nexport function FloatingComponentProvider(\n props: FloatingComponentProviderProps,\n) {\n const { Component, children } = props;\n const value = useMemo(() => ({ Component }), [Component]);\n\n return (\n <FloatingComponentContext.Provider value={value}>\n {children}\n </FloatingComponentContext.Provider>\n );\n}\n\nexport function useFloatingComponent() {\n return useContext(FloatingComponentContext);\n}\n\nexport interface UseFloatingUIProps\n extends Pick<\n UseFloatingOptions,\n \"placement\" | \"strategy\" | \"open\" | \"onOpenChange\" | \"nodeId\"\n > {\n /**\n * Function to update the default middleware used to extend or replace it\n */\n middleware?: Middleware[];\n}\n\ntype GetMiddleware = (middleware: Middleware[]) => Middleware[];\n\nconst defaultGetMiddleware: GetMiddleware = (defaultMiddleware) =>\n defaultMiddleware;\n\ninterface FloatingPlatformContextType {\n platform: Platform;\n middleware: GetMiddleware;\n animationFrame: boolean;\n}\n\nconst defaultFloatingPlaform: FloatingPlatformContextType = {\n platform,\n middleware: defaultGetMiddleware,\n animationFrame: false,\n};\n\nconst FloatingPlatformContext = createContext<FloatingPlatformContextType>(\n defaultFloatingPlaform,\n);\n\nexport interface FloatingPlatformProviderProps {\n platform?: Platform;\n middleware?: GetMiddleware;\n children: ReactNode;\n animationFrame?: boolean;\n}\n\nexport function FloatingPlatformProvider(props: FloatingPlatformProviderProps) {\n const {\n platform: platformProp,\n middleware,\n animationFrame,\n children,\n } = props;\n\n const floatingPlatformContextValue = useMemo<FloatingPlatformContextType>(\n () => ({\n platform: platformProp ?? platform,\n middleware: middleware ?? defaultGetMiddleware,\n animationFrame: animationFrame || false,\n }),\n [platformProp, middleware, animationFrame],\n );\n\n return (\n <FloatingPlatformContext.Provider value={floatingPlatformContextValue}>\n {children}\n </FloatingPlatformContext.Provider>\n );\n}\n\nexport function useFloatingPlatform() {\n return useContext(FloatingPlatformContext);\n}\n\nexport const DEFAULT_FLOATING_UI_MIDDLEWARE = [\n flip(),\n shift({ limiter: limitShift() }),\n];\n\ntype UseFloatingRefs = ReturnType<typeof useFloating>[\"refs\"];\n\nexport interface UseFloatingUIReturn extends ReturnType<typeof useFloating> {\n reference: UseFloatingRefs[\"setReference\"];\n floating: UseFloatingRefs[\"setFloating\"];\n}\n\nexport function useFloatingUI(props: UseFloatingUIProps): UseFloatingUIReturn {\n const {\n middleware = DEFAULT_FLOATING_UI_MIDDLEWARE,\n open = false,\n onOpenChange,\n ...other\n } = props;\n\n const handleOpenChange: UseFloatingUIProps[\"onOpenChange\"] = (\n open,\n boolean,\n reason,\n ) => {\n update();\n onOpenChange?.(open, boolean, reason);\n };\n\n const {\n platform: contextPlatform,\n middleware: contextMiddleware,\n animationFrame,\n } = useFloatingPlatform();\n\n const { refs, update, ...rest } = useFloating({\n ...other,\n middleware: contextMiddleware(middleware),\n open,\n onOpenChange: handleOpenChange,\n whileElementsMounted: (...args) => {\n const cleanup = autoUpdate(...args, { animationFrame });\n\n return cleanup;\n },\n platform: contextPlatform,\n });\n\n return {\n reference: refs.setReference,\n floating: refs.setFloating,\n refs,\n update,\n ...rest,\n };\n}\n"],"names":["DefaultFloatingComponent","open"],"mappings":";;;;;;AAsDA,MAAM,wBAA2B,GAAA,UAAA,CAG/B,SAASA,yBAAAA,CAAyB,OAAO,GAAK,EAAA;AAC9C,EAAM,MAAA;AAAA,IACJ,IAAA;AAAA,IACA,GAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA,iBAAA;AAAA,IACA,UAAA;AAAA,IACA,GAAG;AAAA,GACD,GAAA,KAAA;AACJ,EAAA,MAAM,KAAQ,GAAA;AAAA,IACZ,GAAA;AAAA,IACA,IAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAM,MAAA,EAAE,SAAU,EAAA,GAAI,QAAS,EAAA;AAC/B,EAAA,gBAAA,CAAiB,EAAE,UAAY,EAAA,CAAC,UAAc,IAAA,CAAC,MAAM,CAAA;AAErD,EAAM,MAAA,kBAAA,GAAqB,YAAY,gBAAmB,GAAA,YAAA;AAE1D,EAAA,IAAI,qBAAqB,IAAM,EAAA;AAC7B,IAAA,2BACG,cACC,EAAA,EAAA,QAAA,kBAAA,GAAA,CAAC,sBAAmB,cAAe,EAAA,OAAA,EACjC,8BAAC,oBAAsB,EAAA,EAAA,GAAG,iBACxB,EAAA,QAAA,kBAAA,GAAA,CAAC,SAAI,KAAe,EAAA,GAAG,MAAM,GAAU,EAAA,CAAA,EACzC,GACF,CACF,EAAA,CAAA;AAAA;AAIJ,EAAA,OAAO,IACL,mBAAA,GAAA,CAAC,cACC,EAAA,EAAA,QAAA,kBAAA,GAAA,CAAC,sBAAmB,cAAe,EAAA,OAAA,EACjC,QAAC,kBAAA,GAAA,CAAA,KAAA,EAAA,EAAI,OAAe,GAAG,IAAA,EAAM,GAAU,EAAA,CAAA,EACzC,GACF,CACE,GAAA,IAAA;AACN,CAAC,CAAA;AAMD,MAAM,2BAA2B,aAA4C,CAAA;AAAA,E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,"file":"useId.js","sources":["../src/utils/useId.ts"],"sourcesContent":["import * as React from \"react\";\n\n// Workaround for https://github.com/webpack/webpack/issues/14814#issuecomment-1536757985\n// Without `toString()`, downstream library using webpack to re-bundle will error\nconst maybeReactUseId: undefined | (() => string) = (React as any)[\n \"useId\".toString()\n];\n\nlet globalId = BigInt(0);\nfunction useIdLegacy(idOverride?: string): string | undefined {\n const [defaultId, setDefaultId] = React.useState(idOverride);\n const id = idOverride || defaultId;\n React.useEffect(() => {\n if (defaultId == null) {\n setDefaultId(`salt-${++globalId}`);\n }\n }, [defaultId]);\n return id;\n}\n\nexport function useId(idOverride?: string): string | undefined {\n if (maybeReactUseId !== undefined) {\n const reactId = maybeReactUseId();\n return idOverride ?? reactId;\n }\n // `React.useId` is invariant at runtime.\n return useIdLegacy(idOverride);\n}\n\n// Note: Some usages require that an id is returned on first call, not only post-first-render\n// (as with the useEffect solution). This can go away once we totally move to React 18\nexport function useIdMemo(idOverride?: string): string {\n return React.useMemo(() => {\n return idOverride ?? `salt-${++globalId}`;\n }, [idOverride]);\n}\n"],"names":[],"mappings":";;AAIA,MAAM,eAA+C,GAAA,KAAA,CACnD,OAAQ,CAAA,QAAA,EACV,CAAA;AAEA,IAAI,QAAA,GAAW,OAAO,CAAC,CAAA;AACvB,SAAS,YAAY,UAAyC,EAAA;AAC5D,EAAA,MAAM,CAAC,SAAW,EAAA,YAAY,CAAI,GAAA,KAAA,CAAM,SAAS,UAAU,CAAA;AAC3D,EAAA,MAAM,KAAK,UAAc,IAAA,SAAA;AACzB,EAAA,KAAA,CAAM,UAAU,MAAM;AACpB,IAAA,IAAI,aAAa,IAAM,EAAA;AACrB,MAAa,YAAA,CAAA,CAAA,KAAA,EAAQ,EAAE,QAAQ,CAAE,CAAA,CAAA;AAAA;AACnC,GACF,EAAG,CAAC,SAAS,CAAC,CAAA;AACd,EAAO,OAAA,EAAA;AACT;AAEO,SAAS,MAAM,UAAyC,EAAA;AAC7D,EAAA,IAAI,oBAAoB,
|
|
1
|
+
{"version":3,"file":"useId.js","sources":["../src/utils/useId.ts"],"sourcesContent":["import * as React from \"react\";\n\n// Workaround for https://github.com/webpack/webpack/issues/14814#issuecomment-1536757985\n// Without `toString()`, downstream library using webpack to re-bundle will error\nconst maybeReactUseId: undefined | (() => string) = (React as any)[\n \"useId\".toString()\n];\n\nlet globalId = BigInt(0);\nfunction useIdLegacy(idOverride?: string): string | undefined {\n const [defaultId, setDefaultId] = React.useState(idOverride);\n const id = idOverride || defaultId;\n React.useEffect(() => {\n if (defaultId == null) {\n setDefaultId(`salt-${++globalId}`);\n }\n }, [defaultId]);\n return id;\n}\n\nexport function useId(idOverride?: string): string | undefined {\n if (maybeReactUseId !== undefined) {\n const reactId = maybeReactUseId();\n return idOverride ?? reactId;\n }\n // `React.useId` is invariant at runtime.\n return useIdLegacy(idOverride);\n}\n\n// Note: Some usages require that an id is returned on first call, not only post-first-render\n// (as with the useEffect solution). This can go away once we totally move to React 18\nexport function useIdMemo(idOverride?: string): string {\n return React.useMemo(() => {\n return idOverride ?? `salt-${++globalId}`;\n }, [idOverride]);\n}\n"],"names":[],"mappings":";;AAIA,MAAM,eAA+C,GAAA,KAAA,CACnD,OAAQ,CAAA,QAAA,EACV,CAAA;AAEA,IAAI,QAAA,GAAW,OAAO,CAAC,CAAA;AACvB,SAAS,YAAY,UAAyC,EAAA;AAC5D,EAAA,MAAM,CAAC,SAAW,EAAA,YAAY,CAAI,GAAA,KAAA,CAAM,SAAS,UAAU,CAAA;AAC3D,EAAA,MAAM,KAAK,UAAc,IAAA,SAAA;AACzB,EAAA,KAAA,CAAM,UAAU,MAAM;AACpB,IAAA,IAAI,aAAa,IAAM,EAAA;AACrB,MAAa,YAAA,CAAA,CAAA,KAAA,EAAQ,EAAE,QAAQ,CAAE,CAAA,CAAA;AAAA;AACnC,GACF,EAAG,CAAC,SAAS,CAAC,CAAA;AACd,EAAO,OAAA,EAAA;AACT;AAEO,SAAS,MAAM,UAAyC,EAAA;AAC7D,EAAA,IAAI,oBAAoB,MAAW,EAAA;AACjC,IAAA,MAAM,UAAU,eAAgB,EAAA;AAChC,IAAA,OAAO,UAAc,IAAA,OAAA;AAAA;AAGvB,EAAA,OAAO,YAAY,UAAU,CAAA;AAC/B;AAIO,SAAS,UAAU,UAA6B,EAAA;AACrD,EAAO,OAAA,KAAA,CAAM,QAAQ,MAAM;AACzB,IAAO,OAAA,UAAA,IAAc,CAAQ,KAAA,EAAA,EAAE,QAAQ,CAAA,CAAA;AAAA,GACzC,EAAG,CAAC,UAAU,CAAC,CAAA;AACjB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePreventScroll.js","sources":["../src/utils/usePreventScroll.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/**\n * Taken from https://github.com/adobe/react-spectrum/blob/cc08a8dbc95d3648eee47bc9b8e0ed48448e0da2/packages/%40react-aria/overlays/src/usePreventScroll.ts#L44 but refactored.\n * This hook currently doesn't use `useWindow` because in a desktop environment the main window is only the window they typically want locked.\n * If we need to in the future we can add an option to specify which window should be affected.\n */\n\nimport { createChainedFunction } from \"./createChainedFunction\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean;\n}\n\nconst visualViewport = typeof document !== \"undefined\" && window.visualViewport;\n\n// HTML input types that do not cause the software keyboard to appear.\nconst nonTextInputTypes = new Set([\n \"checkbox\",\n \"radio\",\n \"range\",\n \"color\",\n \"file\",\n \"image\",\n \"button\",\n \"submit\",\n \"reset\",\n]);\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore: () => void;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function usePreventScroll(options: PreventScrollOptions = {}) {\n const { isDisabled } = options;\n\n useIsomorphicLayoutEffect(() => {\n if (isDisabled) {\n return;\n }\n\n preventScrollCount++;\n if (preventScrollCount === 1) {\n if (isIOS()) {\n restore = preventScrollMobileSafari();\n } else {\n restore = preventScrollStandard();\n }\n }\n\n return () => {\n preventScrollCount--;\n if (preventScrollCount === 0) {\n restore();\n }\n };\n }, [isDisabled]);\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard() {\n return createChainedFunction(\n setStyle(\n document.documentElement,\n \"paddingRight\",\n `${window.innerWidth - document.documentElement.clientWidth}px`,\n ),\n setStyle(document.documentElement, \"overflow\", \"hidden\"),\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at\n// the top or bottom. Work around a bug where this does not work when the element does not actually overflow\n// by preventing default in a `touchmove` event.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\n// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top\n// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element\n// into view ourselves, without scrolling the whole page.\n// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the\n// same visually, but makes the actual scroll position always zero. This is required to make all of the\n// above work or Safari will still try to scroll the page when focusing an input.\n// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting\n// to navigate to an input with the next/previous buttons that's outside a modal.\nfunction preventScrollMobileSafari() {\n let scrollable: Element;\n let restoreScrollableStyles: () => void;\n const onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n scrollable = getScrollParent(e.target as Element, true);\n if (\n scrollable === document.documentElement &&\n scrollable === document.body\n ) {\n return;\n }\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead.\n if (\n scrollable instanceof HTMLElement &&\n window.getComputedStyle(scrollable).overscrollBehavior === \"auto\"\n ) {\n restoreScrollableStyles = setStyle(\n scrollable,\n \"overscrollBehavior\",\n \"contain\",\n );\n }\n };\n\n const onTouchMove = (e: TouchEvent) => {\n // Prevent scrolling the window.\n if (\n !scrollable ||\n scrollable === document.documentElement ||\n scrollable === document.body\n ) {\n e.preventDefault();\n return;\n }\n\n // overscroll-behavior should prevent scroll chaining, but currently does not\n // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452\n // This checks that both the width and height do not overflow, otherwise we might\n // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to\n // the element will prevent vertical page scrolling. We can't add that automatically\n // because it must be set before the touchstart event.\n if (\n scrollable.scrollHeight === scrollable.clientHeight &&\n scrollable.scrollWidth === scrollable.clientWidth\n ) {\n e.preventDefault();\n }\n };\n\n const onTouchEnd = () => {\n if (restoreScrollableStyles) {\n restoreScrollableStyles();\n }\n };\n\n const onFocus = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n if (willOpenKeyboard(target)) {\n setupStyles();\n\n // Apply a transform to trick Safari into thinking the input is at the top of the page\n // so it doesn't try to scroll it into view.\n target.style.transform = \"translateY(-2000px)\";\n requestAnimationFrame(() => {\n target.style.transform = \"\";\n\n // This will have prevented the browser from scrolling the focused element into view,\n // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.\n if (visualViewport) {\n if (visualViewport.height < window.innerHeight) {\n // If the keyboard is already visible, do this after one additional frame\n // to wait for the transform to be removed.\n requestAnimationFrame(() => {\n scrollIntoView(target);\n });\n } else {\n // Otherwise, wait for the visual viewport to resize before scrolling so we can\n // measure the correct position to scroll to.\n visualViewport.addEventListener(\n \"resize\",\n () => scrollIntoView(target),\n { once: true },\n );\n }\n }\n });\n }\n };\n\n let restoreStyles: null | (() => void) = null;\n const setupStyles = () => {\n if (restoreStyles) {\n return;\n }\n\n const onWindowScroll = () => {\n // Last resort. If the window scrolled, scroll it back to the top.\n // It should always be at the top because the body will have a negative margin (see below).\n window.scrollTo(0, 0);\n };\n\n // Record the original scroll position so we can restore it.\n // Then apply a negative margin to the body to offset it by the scroll position. This will\n // enable us to scroll the window to the top, which is required for the rest of this to work.\n const scrollX = window.pageXOffset;\n const scrollY = window.pageYOffset;\n\n restoreStyles = createChainedFunction(\n addEvent(window, \"scroll\", onWindowScroll),\n setStyle(\n document.documentElement,\n \"paddingRight\",\n `${window.innerWidth - document.documentElement.clientWidth}px`,\n ),\n setStyle(document.documentElement, \"overflow\", \"hidden\"),\n setStyle(document.body, \"marginTop\", `-${scrollY}px`),\n () => {\n window.scrollTo(scrollX, scrollY);\n },\n );\n\n // Scroll to the top. The negative margin on the body will make this appear the same.\n window.scrollTo(0, 0);\n };\n\n const removeEvents = createChainedFunction(\n addEvent(document, \"touchstart\", onTouchStart, {\n passive: false,\n capture: true,\n }),\n addEvent(document, \"touchmove\", onTouchMove, {\n passive: false,\n capture: true,\n }),\n addEvent(document, \"touchend\", onTouchEnd, {\n passive: false,\n capture: true,\n }),\n addEvent(document, \"focus\", onFocus, true),\n );\n\n return () => {\n // Restore styles and scroll the page back to where it was.\n restoreScrollableStyles?.();\n restoreStyles?.();\n removeEvents();\n };\n}\n\n// Sets a CSS property on an element, and returns a function to revert it to the previous value.\nfunction setStyle(element: HTMLElement, style: string, value: string) {\n const cur = element.style[style as any];\n element.style[style as any] = value;\n\n return () => {\n element.style[style as any] = cur;\n };\n}\n\n// Adds an event listener to an element, and returns a function to remove it.\nfunction addEvent<K extends keyof GlobalEventHandlersEventMap>(\n target: Document | Window,\n event: K,\n handler: (this: Document | Window, ev: GlobalEventHandlersEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions,\n) {\n // internal function, so it's ok to ignore the difficult to fix type error\n // @ts-ignore\n target.addEventListener(event, handler, options);\n return () => {\n // @ts-ignore\n target.removeEventListener(event, handler, options);\n };\n}\n\nfunction scrollIntoView(target: Element) {\n const root = document.scrollingElement || document.documentElement;\n let nextTarget: Element | null = target;\n while (nextTarget && nextTarget !== root) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n const scrollable = getScrollParent(nextTarget);\n if (\n scrollable !== document.documentElement &&\n scrollable !== document.body &&\n scrollable !== nextTarget\n ) {\n const scrollableTop = scrollable.getBoundingClientRect().top;\n const targetTop = nextTarget.getBoundingClientRect().top;\n if (targetTop > scrollableTop + nextTarget.clientHeight) {\n scrollable.scrollTop += targetTop - scrollableTop;\n }\n }\n\n nextTarget = scrollable.parentElement;\n }\n}\n\nfunction willOpenKeyboard(target: Element) {\n return (\n (target instanceof HTMLInputElement &&\n !nonTextInputTypes.has(target.type)) ||\n target instanceof HTMLTextAreaElement ||\n (target instanceof HTMLElement && target.isContentEditable)\n );\n}\n\nfunction isScrollable(\n node: Element | null,\n checkForOverflow?: boolean,\n): boolean {\n if (!node) {\n return false;\n }\n const style = window.getComputedStyle(node);\n let isScrollable = /(auto|scroll)/.test(\n style.overflow + style.overflowX + style.overflowY,\n );\n\n if (isScrollable && checkForOverflow) {\n isScrollable =\n node.scrollHeight !== node.clientHeight ||\n node.scrollWidth !== node.clientWidth;\n }\n\n return isScrollable;\n}\n\nfunction getScrollParent(node: Element, checkForOverflow?: boolean): Element {\n let scrollableNode: Element | null = node;\n if (isScrollable(scrollableNode, checkForOverflow)) {\n scrollableNode = scrollableNode.parentElement;\n }\n\n while (scrollableNode && !isScrollable(scrollableNode, checkForOverflow)) {\n scrollableNode = scrollableNode.parentElement;\n }\n\n return (\n scrollableNode || document.scrollingElement || document.documentElement\n );\n}\n\nfunction testPlatform(re: RegExp) {\n return typeof window !== \"undefined\" && window.navigator != null\n ? re.test(\n // @ts-expect-error userAgentData is only supported in Chrome 90+\n window.navigator.userAgentData?.platform || window.navigator.platform,\n )\n : false;\n}\n\nfunction cached(fn: () => boolean) {\n if (process.env.NODE_ENV === \"test\") {\n return fn;\n }\n\n let res: boolean | null = null;\n return () => {\n if (res == null) {\n res = fn();\n }\n return res;\n };\n}\n\nconst isMac = cached(() => testPlatform(/^Mac/i));\n\nconst isIPhone = cached(() => testPlatform(/^iPhone/i));\n\nconst isIPad = cached(\n () =>\n testPlatform(/^iPad/i) ||\n // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.\n (isMac() && navigator.maxTouchPoints > 1),\n);\n\nconst isIOS = cached(() => isIPhone() || isIPad());\n"],"names":["isScrollable"],"mappings":";;;AA0BA,MAAM,cAAiB,GAAA,OAAO,QAAa,KAAA,WAAA,IAAe,MAAO,CAAA,cAAA;AAGjE,MAAM,iBAAA,uBAAwB,GAAI,CAAA;AAAA,EAChC,UAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC,CAAA;AAGD,IAAI,kBAAqB,GAAA,CAAA;AACzB,IAAI,OAAA;AAOY,SAAA,gBAAA,CAAiB,OAAgC,GAAA,EAAI,EAAA;AACnE,EAAM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* Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/**\n * Taken from https://github.com/adobe/react-spectrum/blob/cc08a8dbc95d3648eee47bc9b8e0ed48448e0da2/packages/%40react-aria/overlays/src/usePreventScroll.ts#L44 but refactored.\n * This hook currently doesn't use `useWindow` because in a desktop environment the main window is only the window they typically want locked.\n * If we need to in the future we can add an option to specify which window should be affected.\n */\n\nimport { createChainedFunction } from \"./createChainedFunction\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean;\n}\n\nconst visualViewport = typeof document !== \"undefined\" && window.visualViewport;\n\n// HTML input types that do not cause the software keyboard to appear.\nconst nonTextInputTypes = new Set([\n \"checkbox\",\n \"radio\",\n \"range\",\n \"color\",\n \"file\",\n \"image\",\n \"button\",\n \"submit\",\n \"reset\",\n]);\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore: () => void;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function usePreventScroll(options: PreventScrollOptions = {}) {\n const { isDisabled } = options;\n\n useIsomorphicLayoutEffect(() => {\n if (isDisabled) {\n return;\n }\n\n preventScrollCount++;\n if (preventScrollCount === 1) {\n if (isIOS()) {\n restore = preventScrollMobileSafari();\n } else {\n restore = preventScrollStandard();\n }\n }\n\n return () => {\n preventScrollCount--;\n if (preventScrollCount === 0) {\n restore();\n }\n };\n }, [isDisabled]);\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard() {\n return createChainedFunction(\n setStyle(\n document.documentElement,\n \"paddingRight\",\n `${window.innerWidth - document.documentElement.clientWidth}px`,\n ),\n setStyle(document.documentElement, \"overflow\", \"hidden\"),\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at\n// the top or bottom. Work around a bug where this does not work when the element does not actually overflow\n// by preventing default in a `touchmove` event.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\n// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top\n// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element\n// into view ourselves, without scrolling the whole page.\n// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the\n// same visually, but makes the actual scroll position always zero. This is required to make all of the\n// above work or Safari will still try to scroll the page when focusing an input.\n// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting\n// to navigate to an input with the next/previous buttons that's outside a modal.\nfunction preventScrollMobileSafari() {\n let scrollable: Element;\n let restoreScrollableStyles: () => void;\n const onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n scrollable = getScrollParent(e.target as Element, true);\n if (\n scrollable === document.documentElement &&\n scrollable === document.body\n ) {\n return;\n }\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead.\n if (\n scrollable instanceof HTMLElement &&\n window.getComputedStyle(scrollable).overscrollBehavior === \"auto\"\n ) {\n restoreScrollableStyles = setStyle(\n scrollable,\n \"overscrollBehavior\",\n \"contain\",\n );\n }\n };\n\n const onTouchMove = (e: TouchEvent) => {\n // Prevent scrolling the window.\n if (\n !scrollable ||\n scrollable === document.documentElement ||\n scrollable === document.body\n ) {\n e.preventDefault();\n return;\n }\n\n // overscroll-behavior should prevent scroll chaining, but currently does not\n // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452\n // This checks that both the width and height do not overflow, otherwise we might\n // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to\n // the element will prevent vertical page scrolling. We can't add that automatically\n // because it must be set before the touchstart event.\n if (\n scrollable.scrollHeight === scrollable.clientHeight &&\n scrollable.scrollWidth === scrollable.clientWidth\n ) {\n e.preventDefault();\n }\n };\n\n const onTouchEnd = () => {\n if (restoreScrollableStyles) {\n restoreScrollableStyles();\n }\n };\n\n const onFocus = (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n if (willOpenKeyboard(target)) {\n setupStyles();\n\n // Apply a transform to trick Safari into thinking the input is at the top of the page\n // so it doesn't try to scroll it into view.\n target.style.transform = \"translateY(-2000px)\";\n requestAnimationFrame(() => {\n target.style.transform = \"\";\n\n // This will have prevented the browser from scrolling the focused element into view,\n // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.\n if (visualViewport) {\n if (visualViewport.height < window.innerHeight) {\n // If the keyboard is already visible, do this after one additional frame\n // to wait for the transform to be removed.\n requestAnimationFrame(() => {\n scrollIntoView(target);\n });\n } else {\n // Otherwise, wait for the visual viewport to resize before scrolling so we can\n // measure the correct position to scroll to.\n visualViewport.addEventListener(\n \"resize\",\n () => scrollIntoView(target),\n { once: true },\n );\n }\n }\n });\n }\n };\n\n let restoreStyles: null | (() => void) = null;\n const setupStyles = () => {\n if (restoreStyles) {\n return;\n }\n\n const onWindowScroll = () => {\n // Last resort. If the window scrolled, scroll it back to the top.\n // It should always be at the top because the body will have a negative margin (see below).\n window.scrollTo(0, 0);\n };\n\n // Record the original scroll position so we can restore it.\n // Then apply a negative margin to the body to offset it by the scroll position. This will\n // enable us to scroll the window to the top, which is required for the rest of this to work.\n const scrollX = window.pageXOffset;\n const scrollY = window.pageYOffset;\n\n restoreStyles = createChainedFunction(\n addEvent(window, \"scroll\", onWindowScroll),\n setStyle(\n document.documentElement,\n \"paddingRight\",\n `${window.innerWidth - document.documentElement.clientWidth}px`,\n ),\n setStyle(document.documentElement, \"overflow\", \"hidden\"),\n setStyle(document.body, \"marginTop\", `-${scrollY}px`),\n () => {\n window.scrollTo(scrollX, scrollY);\n },\n );\n\n // Scroll to the top. The negative margin on the body will make this appear the same.\n window.scrollTo(0, 0);\n };\n\n const removeEvents = createChainedFunction(\n addEvent(document, \"touchstart\", onTouchStart, {\n passive: false,\n capture: true,\n }),\n addEvent(document, \"touchmove\", onTouchMove, {\n passive: false,\n capture: true,\n }),\n addEvent(document, \"touchend\", onTouchEnd, {\n passive: false,\n capture: true,\n }),\n addEvent(document, \"focus\", onFocus, true),\n );\n\n return () => {\n // Restore styles and scroll the page back to where it was.\n restoreScrollableStyles?.();\n restoreStyles?.();\n removeEvents();\n };\n}\n\n// Sets a CSS property on an element, and returns a function to revert it to the previous value.\nfunction setStyle(element: HTMLElement, style: string, value: string) {\n const cur = element.style[style as any];\n element.style[style as any] = value;\n\n return () => {\n element.style[style as any] = cur;\n };\n}\n\n// Adds an event listener to an element, and returns a function to remove it.\nfunction addEvent<K extends keyof GlobalEventHandlersEventMap>(\n target: Document | Window,\n event: K,\n handler: (this: Document | Window, ev: GlobalEventHandlersEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions,\n) {\n // internal function, so it's ok to ignore the difficult to fix type error\n // @ts-ignore\n target.addEventListener(event, handler, options);\n return () => {\n // @ts-ignore\n target.removeEventListener(event, handler, options);\n };\n}\n\nfunction scrollIntoView(target: Element) {\n const root = document.scrollingElement || document.documentElement;\n let nextTarget: Element | null = target;\n while (nextTarget && nextTarget !== root) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n const scrollable = getScrollParent(nextTarget);\n if (\n scrollable !== document.documentElement &&\n scrollable !== document.body &&\n scrollable !== nextTarget\n ) {\n const scrollableTop = scrollable.getBoundingClientRect().top;\n const targetTop = nextTarget.getBoundingClientRect().top;\n if (targetTop > scrollableTop + nextTarget.clientHeight) {\n scrollable.scrollTop += targetTop - scrollableTop;\n }\n }\n\n nextTarget = scrollable.parentElement;\n }\n}\n\nfunction willOpenKeyboard(target: Element) {\n return (\n (target instanceof HTMLInputElement &&\n !nonTextInputTypes.has(target.type)) ||\n target instanceof HTMLTextAreaElement ||\n (target instanceof HTMLElement && target.isContentEditable)\n );\n}\n\nfunction isScrollable(\n node: Element | null,\n checkForOverflow?: boolean,\n): boolean {\n if (!node) {\n return false;\n }\n const style = window.getComputedStyle(node);\n let isScrollable = /(auto|scroll)/.test(\n style.overflow + style.overflowX + style.overflowY,\n );\n\n if (isScrollable && checkForOverflow) {\n isScrollable =\n node.scrollHeight !== node.clientHeight ||\n node.scrollWidth !== node.clientWidth;\n }\n\n return isScrollable;\n}\n\nfunction getScrollParent(node: Element, checkForOverflow?: boolean): Element {\n let scrollableNode: Element | null = node;\n if (isScrollable(scrollableNode, checkForOverflow)) {\n scrollableNode = scrollableNode.parentElement;\n }\n\n while (scrollableNode && !isScrollable(scrollableNode, checkForOverflow)) {\n scrollableNode = scrollableNode.parentElement;\n }\n\n return (\n scrollableNode || document.scrollingElement || document.documentElement\n );\n}\n\nfunction testPlatform(re: RegExp) {\n return typeof window !== \"undefined\" && window.navigator != null\n ? re.test(\n // @ts-expect-error userAgentData is only supported in Chrome 90+\n window.navigator.userAgentData?.platform || window.navigator.platform,\n )\n : false;\n}\n\nfunction cached(fn: () => boolean) {\n if (process.env.NODE_ENV === \"test\") {\n return fn;\n }\n\n let res: boolean | null = null;\n return () => {\n if (res == null) {\n res = fn();\n }\n return res;\n };\n}\n\nconst isMac = cached(() => testPlatform(/^Mac/i));\n\nconst isIPhone = cached(() => testPlatform(/^iPhone/i));\n\nconst isIPad = cached(\n () =>\n testPlatform(/^iPad/i) ||\n // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.\n (isMac() && navigator.maxTouchPoints > 1),\n);\n\nconst isIOS = cached(() => isIPhone() || isIPad());\n"],"names":["isScrollable"],"mappings":";;;AA0BA,MAAM,cAAiB,GAAA,OAAO,QAAa,KAAA,WAAA,IAAe,MAAO,CAAA,cAAA;AAGjE,MAAM,iBAAA,uBAAwB,GAAI,CAAA;AAAA,EAChC,UAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC,CAAA;AAGD,IAAI,kBAAqB,GAAA,CAAA;AACzB,IAAI,OAAA;AAOY,SAAA,gBAAA,CAAiB,OAAgC,GAAA,EAAI,EAAA;AACnE,EAAM,MAAA,EAAE,YAAe,GAAA,OAAA;AAEvB,EAAA,yBAAA,CAA0B,MAAM;AAC9B,IAAA,IAAI,UAAY,EAAA;AACd,MAAA;AAAA;AAGF,IAAA,kBAAA,EAAA;AACA,IAAA,IAAI,uBAAuB,CAAG,EAAA;AAC5B,MAAA,IAAI,OAAS,EAAA;AACX,QAAA,OAAA,GAAU,yBAA0B,EAAA;AAAA,OAC/B,MAAA;AACL,QAAA,OAAA,GAAU,qBAAsB,EAAA;AAAA;AAClC;AAGF,IAAA,OAAO,MAAM;AACX,MAAA,kBAAA,EAAA;AACA,MAAA,IAAI,uBAAuB,CAAG,EAAA;AAC5B,QAAQ,OAAA,EAAA;AAAA;AACV,KACF;AAAA,GACF,EAAG,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,KAAA;AACN;AAEA,SAAS,OAAO,EAAmB,EAAA;AACjC,EAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,MAAQ,EAAA;AACnC,IAAO,OAAA,EAAA;AAAA;AAGT,EAAA,IAAI,GAAsB,GAAA,IAAA;AAC1B,EAAA,OAAO,MAAM;AACX,IAAA,IAAI,OAAO,IAAM,EAAA;AACf,MAAA,GAAA,GAAM,EAAG,EAAA;AAAA;AAEX,IAAO,OAAA,GAAA;AAAA,GACT;AACF;AAEA,MAAM,KAAQ,GAAA,MAAA,CAAO,MAAM,YAAA,CAAa,OAAO,CAAC,CAAA;AAEhD,MAAM,QAAW,GAAA,MAAA,CAAO,MAAM,YAAA,CAAa,UAAU,CAAC,CAAA;AAEtD,MAAM,MAAS,GAAA,MAAA;AAAA,EACb,MACE,aAAa,QAAQ,CAAA;AAAA,EAEpB,KAAA,EAAW,IAAA,SAAA,CAAU,cAAiB,GAAA;AAC3C,CAAA;AAEA,MAAM,QAAQ,MAAO,CAAA,MAAM,QAAS,EAAA,IAAK,QAAQ,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResizeObserver.js","sources":["../src/utils/useResizeObserver.ts"],"sourcesContent":["import { type RefObject, useEffect } from \"react\";\nimport { ownerWindow } from \"./ownerWindow\";\n\nexport interface UseResizeObserverProps {\n ref: RefObject<HTMLElement>;\n onResize: () => void;\n}\n\nexport function useResizeObserver({ ref, onResize }: UseResizeObserverProps) {\n useEffect(() => {\n const element = ref?.current;\n if (!element) return;\n\n const win = ownerWindow(element);\n\n const resizeObserver = new win.ResizeObserver((entries) => {\n requestAnimationFrame(() => {\n if (entries.length === 0) return;\n\n onResize();\n });\n });\n resizeObserver.observe(element);\n\n return () => {\n if (element) {\n resizeObserver.unobserve(element);\n }\n };\n }, [ref, onResize]);\n}\n"],"names":[],"mappings":";;;AAQO,SAAS,iBAAkB,CAAA,EAAE,GAAK,EAAA,QAAA,EAAoC,EAAA;AAC3E,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAM,UAAU,GAAK,IAAA,IAAA,GAAA,
|
|
1
|
+
{"version":3,"file":"useResizeObserver.js","sources":["../src/utils/useResizeObserver.ts"],"sourcesContent":["import { type RefObject, useEffect } from \"react\";\nimport { ownerWindow } from \"./ownerWindow\";\n\nexport interface UseResizeObserverProps {\n ref: RefObject<HTMLElement>;\n onResize: () => void;\n}\n\nexport function useResizeObserver({ ref, onResize }: UseResizeObserverProps) {\n useEffect(() => {\n const element = ref?.current;\n if (!element) return;\n\n const win = ownerWindow(element);\n\n const resizeObserver = new win.ResizeObserver((entries) => {\n requestAnimationFrame(() => {\n if (entries.length === 0) return;\n\n onResize();\n });\n });\n resizeObserver.observe(element);\n\n return () => {\n if (element) {\n resizeObserver.unobserve(element);\n }\n };\n }, [ref, onResize]);\n}\n"],"names":[],"mappings":";;;AAQO,SAAS,iBAAkB,CAAA,EAAE,GAAK,EAAA,QAAA,EAAoC,EAAA;AAC3E,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAM,UAAU,GAAK,IAAA,IAAA,GAAA,MAAA,GAAA,GAAA,CAAA,OAAA;AACrB,IAAA,IAAI,CAAC,OAAS,EAAA;AAEd,IAAM,MAAA,GAAA,GAAM,YAAY,OAAO,CAAA;AAE/B,IAAA,MAAM,cAAiB,GAAA,IAAI,GAAI,CAAA,cAAA,CAAe,CAAC,OAAY,KAAA;AACzD,MAAA,qBAAA,CAAsB,MAAM;AAC1B,QAAI,IAAA,OAAA,CAAQ,WAAW,CAAG,EAAA;AAE1B,QAAS,QAAA,EAAA;AAAA,OACV,CAAA;AAAA,KACF,CAAA;AACD,IAAA,cAAA,CAAe,QAAQ,OAAO,CAAA;AAE9B,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,OAAS,EAAA;AACX,QAAA,cAAA,CAAe,UAAU,OAAO,CAAA;AAAA;AAClC,KACF;AAAA,GACC,EAAA,CAAC,GAAK,EAAA,QAAQ,CAAC,CAAA;AACpB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResponsiveProp.js","sources":["../src/utils/useResponsiveProp.ts"],"sourcesContent":["import type { Breakpoints } from \"../breakpoints\";\nimport { useBreakpoints } from \"../salt-provider\";\nimport { useViewport } from \"../viewport\";\n\ntype BreakpointProp<T> = {\n [K in keyof Breakpoints]?: T;\n};\n\nexport type ResponsiveProp<T> = T | BreakpointProp<T>;\n\nexport const getCurrentBreakpoint = (\n breakpoints: Breakpoints,\n width: number,\n) => {\n const breakpointList = Object.entries(breakpoints).sort(\n ([, a], [, b]) => a - b,\n );\n const [currentBreakpoint] = (\n breakpointList as [keyof Breakpoints, number][]\n ).reduce(\n (acc, val) => {\n const [, accWidth] = acc;\n const [breakpoint, breakpointWidth] = val;\n if (breakpointWidth <= width && breakpointWidth > accWidth) {\n return [breakpoint, breakpointWidth];\n }\n return acc;\n },\n breakpointList[0] as [keyof Breakpoints, number],\n );\n\n return currentBreakpoint;\n};\n\nexport const useCurrentBreakpoint = () => {\n const viewport = useViewport();\n\n const breakpoints = useBreakpoints();\n\n return getCurrentBreakpoint(breakpoints, viewport);\n};\n\nexport const useOrderedBreakpoints = () => {\n const breakpoints = useBreakpoints();\n\n return Object.entries(breakpoints)\n .sort(([, a], [, b]) => a - b)\n .map(([key]) => key);\n};\n\nconst isObject = <T>(\n value: T,\n): value is Record<string | number | symbol, any> => {\n const type = typeof value;\n return value !== null && (type === \"object\" || type === \"function\");\n};\n\nconst hasBreakpointValues = <T>(\n value: ResponsiveProp<T>,\n breakpoints: Breakpoints,\n): value is BreakpointProp<T> => {\n return (\n isObject(value) && Object.keys(value).every((key) => key in breakpoints)\n );\n};\n\nconst getResponsiveValue = <T>(\n breakpointValues: BreakpointProp<T>,\n breakpoints: Breakpoints,\n viewport: keyof Breakpoints,\n defaultValue: T,\n) => {\n return Object.entries(breakpointValues).reduce<[number, T]>(\n (acc, val) => {\n const [accWidth] = acc;\n const [breakpoint, breakpointValue] = val;\n\n const breakpointWidth =\n breakpoints[breakpoint as keyof typeof breakpoints];\n\n if (\n breakpointWidth >= accWidth &&\n breakpointWidth <= breakpoints[viewport]\n ) {\n return [breakpointWidth, breakpointValue];\n }\n\n return acc;\n },\n [0, defaultValue],\n )[1];\n};\n\nexport const useResponsiveProp = <T>(\n value: ResponsiveProp<T>,\n defaultValue: T,\n) => {\n const breakpoints = useBreakpoints();\n const viewport = useViewport();\n // return early if the values are the same\n if (value === defaultValue) return defaultValue;\n\n const currentViewport = getCurrentBreakpoint(breakpoints, viewport);\n if (hasBreakpointValues(value, breakpoints)) {\n return getResponsiveValue(\n value,\n breakpoints,\n currentViewport,\n defaultValue,\n );\n }\n return value;\n};\n\nfunction isBreakpointProp<T>(\n value: ResponsiveProp<T>,\n): value is BreakpointProp<T> {\n return typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport function resolveResponsiveValue<Value>(\n value: ResponsiveProp<Value>,\n matchedBreakpoints: (keyof Breakpoints)[],\n) {\n if (value && isBreakpointProp(value)) {\n for (const breakpoint of matchedBreakpoints) {\n if (value[breakpoint] != null) {\n return value[breakpoint];\n }\n }\n return undefined;\n }\n return value;\n}\n"],"names":[],"mappings":";;;AAUa,MAAA,oBAAA,GAAuB,CAClC,WAAA,EACA,KACG,KAAA;AACH,EAAA,MAAM,cAAiB,GAAA,MAAA,CAAO,OAAQ,CAAA,WAAW,CAAE,CAAA,IAAA;AAAA,IACjD,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAA,KAAM,CAAI,GAAA;AAAA,GACxB;AACA,EAAM,MAAA,CAAC,iBAAiB,CAAA,GACtB,cACA,CAAA,MAAA;AAAA,IACA,CAAC,KAAK,GAAQ,KAAA;AACZ,MAAM,MAAA,GAAG,QAAQ,CAAI,GAAA,GAAA;AACrB,MAAM,MAAA,CAAC,UAAY,EAAA,eAAe,CAAI,GAAA,GAAA;AACtC,MAAI,IAAA,eAAA,IAAmB,KAAS,IAAA,eAAA,GAAkB,Q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sourcesContent":["import type { Breakpoints } from \"../breakpoints\";\nimport { useBreakpoints } from \"../salt-provider\";\nimport { useViewport } from \"../viewport\";\n\ntype BreakpointProp<T> = {\n [K in keyof Breakpoints]?: T;\n};\n\nexport type ResponsiveProp<T> = T | BreakpointProp<T>;\n\nexport const getCurrentBreakpoint = (\n breakpoints: Breakpoints,\n width: number,\n) => {\n const breakpointList = Object.entries(breakpoints).sort(\n ([, a], [, b]) => a - b,\n );\n const [currentBreakpoint] = (\n breakpointList as [keyof Breakpoints, number][]\n ).reduce(\n (acc, val) => {\n const [, accWidth] = acc;\n const [breakpoint, breakpointWidth] = val;\n if (breakpointWidth <= width && breakpointWidth > accWidth) {\n return [breakpoint, breakpointWidth];\n }\n return acc;\n },\n breakpointList[0] as [keyof Breakpoints, number],\n );\n\n return currentBreakpoint;\n};\n\nexport const useCurrentBreakpoint = () => {\n const viewport = useViewport();\n\n const breakpoints = useBreakpoints();\n\n return getCurrentBreakpoint(breakpoints, viewport);\n};\n\nexport const useOrderedBreakpoints = () => {\n const breakpoints = useBreakpoints();\n\n return Object.entries(breakpoints)\n .sort(([, a], [, b]) => a - b)\n .map(([key]) => key);\n};\n\nconst isObject = <T>(\n value: T,\n): value is Record<string | number | symbol, any> => {\n const type = typeof value;\n return value !== null && (type === \"object\" || type === \"function\");\n};\n\nconst hasBreakpointValues = <T>(\n value: ResponsiveProp<T>,\n breakpoints: Breakpoints,\n): value is BreakpointProp<T> => {\n return (\n isObject(value) && Object.keys(value).every((key) => key in breakpoints)\n );\n};\n\nconst getResponsiveValue = <T>(\n breakpointValues: BreakpointProp<T>,\n breakpoints: Breakpoints,\n viewport: keyof Breakpoints,\n defaultValue: T,\n) => {\n return Object.entries(breakpointValues).reduce<[number, T]>(\n (acc, val) => {\n const [accWidth] = acc;\n const [breakpoint, breakpointValue] = val;\n\n const breakpointWidth =\n breakpoints[breakpoint as keyof typeof breakpoints];\n\n if (\n breakpointWidth >= accWidth &&\n breakpointWidth <= breakpoints[viewport]\n ) {\n return [breakpointWidth, breakpointValue];\n }\n\n return acc;\n },\n [0, defaultValue],\n )[1];\n};\n\nexport const useResponsiveProp = <T>(\n value: ResponsiveProp<T>,\n defaultValue: T,\n) => {\n const breakpoints = useBreakpoints();\n const viewport = useViewport();\n // return early if the values are the same\n if (value === defaultValue) return defaultValue;\n\n const currentViewport = getCurrentBreakpoint(breakpoints, viewport);\n if (hasBreakpointValues(value, breakpoints)) {\n return getResponsiveValue(\n value,\n breakpoints,\n currentViewport,\n defaultValue,\n );\n }\n return value;\n};\n\nfunction isBreakpointProp<T>(\n value: ResponsiveProp<T>,\n): value is BreakpointProp<T> {\n return typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport function resolveResponsiveValue<Value>(\n value: ResponsiveProp<Value>,\n matchedBreakpoints: (keyof Breakpoints)[],\n) {\n if (value && isBreakpointProp(value)) {\n for (const breakpoint of matchedBreakpoints) {\n if (value[breakpoint] != null) {\n return value[breakpoint];\n }\n }\n return undefined;\n }\n return value;\n}\n"],"names":[],"mappings":";;;AAUa,MAAA,oBAAA,GAAuB,CAClC,WAAA,EACA,KACG,KAAA;AACH,EAAA,MAAM,cAAiB,GAAA,MAAA,CAAO,OAAQ,CAAA,WAAW,CAAE,CAAA,IAAA;AAAA,IACjD,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAA,KAAM,CAAI,GAAA;AAAA,GACxB;AACA,EAAM,MAAA,CAAC,iBAAiB,CAAA,GACtB,cACA,CAAA,MAAA;AAAA,IACA,CAAC,KAAK,GAAQ,KAAA;AACZ,MAAM,MAAA,GAAG,QAAQ,CAAI,GAAA,GAAA;AACrB,MAAM,MAAA,CAAC,UAAY,EAAA,eAAe,CAAI,GAAA,GAAA;AACtC,MAAI,IAAA,eAAA,IAAmB,KAAS,IAAA,eAAA,GAAkB,QAAU,EAAA;AAC1D,QAAO,OAAA,CAAC,YAAY,eAAe,CAAA;AAAA;AAErC,MAAO,OAAA,GAAA;AAAA,KACT;AAAA,IACA,eA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AA,QAAA,IACnB,eAAmB,IAAA,WAAA,CAAY,QAAQ,CACvC,EAAA;AACA,QAAO,OAAA,CAAC,iBAAiB,eAAe,CAAA;AAAA;AAG1C,MAAO,OAAA,GAAA;AAAA,KACT;AAAA,IACA,CAAC,GAAG,YAAY;AAAA,IAChB,CAAC,CAAA;AACL,CAAA;AAEa,MAAA,iBAAA,GAAoB,CAC/B,KAAA,EACA,YACG,KAAA;AACH,EAAA,MAAM,cAAc,cAAe,EAAA;AACnC,EAAA,MAAM,WAAW,WAAY,EAAA;AAE7B,EAAI,IAAA,KAAA,KAAU,cAAqB,OAAA,YAAA;AAEnC,EAAM,MAAA,eAAA,GAAkB,oBAAqB,CAAA,WAAA,EAAa,QAAQ,CAAA;AAClE,EAAI,IAAA,mBAAA,CAAoB,KAAO,EAAA,WAAW,CAAG,EAAA;AAC3C,IAAO,OAAA,kBAAA;AAAA,MACL,KAAA;AAAA,MACA,WAAA;AAAA,MACA,eAAA;AAAA,MACA;AAAA,KACF;AAAA;AAEF,EAAO,OAAA,KAAA;AACT;AAEA,SAAS,iBACP,KAC4B,EAAA;AAC5B,EAAA,OAAO,OAAO,KAAU,KAAA,QAAA,IAAY,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC1D;AAEgB,SAAA,sBAAA,CACd,OACA,kBACA,EAAA;AACA,EAAI,IAAA,KAAA,IAAS,gBAAiB,CAAA,KAAK,CAAG,EAAA;AACpC,IAAA,KAAA,MAAW,cAAc,kBAAoB,EAAA;AAC3C,MAAI,IAAA,KAAA,CAAM,UAAU,CAAA,IAAK,IAAM,EAAA;AAC7B,QAAA,OAAO,MAAM,UAAU,CAAA;AAAA;AACzB;AAEF,IAAO,OAAA,MAAA;AAAA;AAET,EAAO,OAAA,KAAA;AACT;;;;"}
|
|
@@ -10,7 +10,7 @@ export declare type ComboBoxProps<Item = string> = {
|
|
|
10
10
|
* If true, options will be selected on tab key press.
|
|
11
11
|
*/
|
|
12
12
|
selectOnTab?: boolean;
|
|
13
|
-
} & UseComboBoxProps<Item> & PillInputProps
|
|
13
|
+
} & UseComboBoxProps<Item> & Omit<PillInputProps, "onPillRemove">;
|
|
14
14
|
export declare const ComboBox: <Item = string>(props: {
|
|
15
15
|
/**
|
|
16
16
|
* The options to display in the combo box.
|
|
@@ -20,6 +20,6 @@ export declare const ComboBox: <Item = string>(props: {
|
|
|
20
20
|
* If true, options will be selected on tab key press.
|
|
21
21
|
*/
|
|
22
22
|
selectOnTab?: boolean | undefined;
|
|
23
|
-
} & import("../list-control/ListControlState").ListControlProps<Item> & Pick<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, "value" | "defaultValue"> & PillInputProps & {
|
|
23
|
+
} & import("../list-control/ListControlState").ListControlProps<Item> & Pick<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, "value" | "defaultValue"> & Omit<PillInputProps, "onPillRemove"> & {
|
|
24
24
|
ref?: Ref<HTMLDivElement> | undefined;
|
|
25
25
|
}) => JSX.Element;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { type TextProps } from "../text";
|
|
2
|
-
export
|
|
2
|
+
export interface FormFieldHelperTextProps extends Omit<TextProps<"label">, "variant" | "styleAs"> {
|
|
3
|
+
}
|
|
4
|
+
export declare const FormFieldHelperText: ({ className, children, ...restProps }: FormFieldHelperTextProps) => import("react/jsx-runtime").JSX.Element;
|
package/dist-types/index.d.ts
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactNode } from "react";
|
|
2
|
+
import type { ButtonProps } from "../button";
|
|
3
|
+
export interface StepProps extends Omit<ComponentPropsWithoutRef<"li">, "onToggle"> {
|
|
4
|
+
/**
|
|
5
|
+
* The label of the step
|
|
6
|
+
*/
|
|
7
|
+
label?: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Description text is displayed just below the label
|
|
10
|
+
**/
|
|
11
|
+
description?: ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Optional string to determine the status of the step.
|
|
14
|
+
*/
|
|
15
|
+
status?: StepStatus;
|
|
16
|
+
/**
|
|
17
|
+
* The stage of the step
|
|
18
|
+
*/
|
|
19
|
+
stage?: StepStage;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the step item is expanded.
|
|
22
|
+
*/
|
|
23
|
+
expanded?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Initial expanded state of the step.
|
|
26
|
+
*/
|
|
27
|
+
defaultExpanded?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Callback fired when the step is toggled.
|
|
30
|
+
*/
|
|
31
|
+
onToggle?: ButtonProps["onClick"];
|
|
32
|
+
}
|
|
33
|
+
export declare type StepId = string;
|
|
34
|
+
export declare type StepStatus = "warning" | "error";
|
|
35
|
+
export declare type StepStage = "pending" | "locked" | "completed" | "inprogress" | "active";
|
|
36
|
+
export declare type StepDepth = number;
|
|
37
|
+
export interface StepProps extends Omit<ComponentPropsWithoutRef<"li">, "onToggle"> {
|
|
38
|
+
label?: ReactNode;
|
|
39
|
+
description?: ReactNode;
|
|
40
|
+
status?: StepStatus;
|
|
41
|
+
stage?: StepStage;
|
|
42
|
+
expanded?: boolean;
|
|
43
|
+
defaultExpanded?: boolean;
|
|
44
|
+
onToggle?: ButtonProps["onClick"];
|
|
45
|
+
}
|
|
46
|
+
export declare const Step: import("react").ForwardRefExoticComponent<StepProps & import("react").RefAttributes<HTMLLIElement>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef } from "react";
|
|
2
|
+
export declare type StepperOrientation = "horizontal" | "vertical";
|
|
3
|
+
export interface StepperProps extends ComponentPropsWithoutRef<"ol"> {
|
|
4
|
+
/**
|
|
5
|
+
* The orientation of the stepper: defaults to horizontal.
|
|
6
|
+
*/
|
|
7
|
+
orientation?: StepperOrientation;
|
|
8
|
+
}
|
|
9
|
+
export declare const Stepper: import("react").ForwardRefExoticComponent<StepperProps & import("react").RefAttributes<HTMLOListElement>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function StepConnector(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ButtonProps } from "../../button";
|
|
2
|
+
export interface StepExpandTriggerProps extends ButtonProps {
|
|
3
|
+
expanded: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function StepExpandTrigger({ id, expanded, className, ...props }: StepExpandTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IconProps } from "@salt-ds/icons";
|
|
2
|
+
import type { StepStage, StepStatus } from "../Step";
|
|
3
|
+
export interface StepIconProps extends IconProps {
|
|
4
|
+
stage: StepStage;
|
|
5
|
+
status?: StepStatus;
|
|
6
|
+
sizeMultiplier?: IconProps["size"];
|
|
7
|
+
}
|
|
8
|
+
export declare function StepIcon({ status, stage, size, sizeMultiplier, className, ...props }: StepIconProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
export interface StepScreenReaderOnlyProps extends ComponentPropsWithoutRef<"div"> {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export declare function StepScreenReaderOnly({ children, ...props }: StepScreenReaderOnlyProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TextProps } from "../../text";
|
|
2
|
+
export interface StepTextProps extends TextProps<"div"> {
|
|
3
|
+
purpose: "label" | "description";
|
|
4
|
+
}
|
|
5
|
+
export declare function StepText({ id, purpose, className, styleAs, children, ...props }: StepTextProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { StepperOrientation } from "../Stepper";
|
|
3
|
+
export declare const StepperOrientationContext: import("react").Context<StepperOrientation>;
|
|
4
|
+
export declare const StepDepthContext: import("react").Context<number>;
|
|
5
|
+
export interface StepperProviderProps {
|
|
6
|
+
orientation: StepperOrientation;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function StepperProvider({ orientation: orientationProp, children, }: StepperProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,36 @@
|
|
|
1
1
|
import { type ComponentPropsWithoutRef, type MouseEvent } from "react";
|
|
2
|
+
import type { ButtonAppearance, ButtonSentiment } from "../button";
|
|
2
3
|
export interface ToggleButtonProps extends ComponentPropsWithoutRef<"button"> {
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The appearance of the toggle button when `selected` is true.
|
|
6
|
+
* @default solid
|
|
7
|
+
*/
|
|
8
|
+
appearance?: Extract<ButtonAppearance, "bordered" | "solid">;
|
|
9
|
+
/**
|
|
10
|
+
* Callback fired when the toggle button's selection state is changed.
|
|
11
|
+
*/
|
|
4
12
|
onChange?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
13
|
+
/**
|
|
14
|
+
* If `true`, the toggle button will be read-only.
|
|
15
|
+
*/
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The sentiment of the toggle button.
|
|
19
|
+
* @default neutral
|
|
20
|
+
*/
|
|
21
|
+
sentiment?: ButtonSentiment;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the toggle button is in a selected state.
|
|
24
|
+
*/
|
|
25
|
+
selected?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the toggle button is selected by default.
|
|
28
|
+
* This will be disregarded if `selected` is already set.
|
|
29
|
+
*/
|
|
30
|
+
defaultSelected?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Value of the toggle button, to be used when in a controlled state.
|
|
33
|
+
*/
|
|
5
34
|
value: string | ReadonlyArray<string> | number | undefined;
|
|
6
35
|
}
|
|
7
36
|
export declare const ToggleButton: import("react").ForwardRefExoticComponent<ToggleButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { type ComponentPropsWithoutRef, type SyntheticEvent } from "react";
|
|
2
|
+
import type { ButtonAppearance, ButtonSentiment } from "../button";
|
|
2
3
|
import { type Value } from "./ToggleButtonGroupContext";
|
|
3
4
|
export interface ToggleButtonGroupProps extends Omit<ComponentPropsWithoutRef<"div">, "onChange"> {
|
|
5
|
+
/**
|
|
6
|
+
* The appearance of all the toggle buttons within the group.
|
|
7
|
+
* @default solid
|
|
8
|
+
*/
|
|
9
|
+
appearance?: Extract<ButtonAppearance, "bordered" | "solid">;
|
|
4
10
|
/**
|
|
5
11
|
* The default value. Use when the component is not controlled.
|
|
6
12
|
*/
|
|
@@ -10,17 +16,25 @@ export interface ToggleButtonGroupProps extends Omit<ComponentPropsWithoutRef<"d
|
|
|
10
16
|
*/
|
|
11
17
|
disabled?: boolean;
|
|
12
18
|
/**
|
|
13
|
-
*
|
|
19
|
+
* Value of the toggle button group, to be used when the component is controlled.
|
|
14
20
|
*/
|
|
15
21
|
value?: Value;
|
|
16
22
|
/**
|
|
17
23
|
* Callback fired when the selection changes.
|
|
18
|
-
* @param event
|
|
19
24
|
*/
|
|
20
25
|
onChange?: (event: SyntheticEvent<HTMLButtonElement>) => void;
|
|
26
|
+
/**
|
|
27
|
+
* If `true`, the toggle button group will be read-only.
|
|
28
|
+
*/
|
|
29
|
+
readOnly?: boolean;
|
|
21
30
|
/**
|
|
22
31
|
* The orientation of the toggle buttons.
|
|
23
32
|
*/
|
|
24
33
|
orientation?: "horizontal" | "vertical";
|
|
34
|
+
/**
|
|
35
|
+
* The visual sentimenent of all the toggle buttons within the group.
|
|
36
|
+
* @default neutral
|
|
37
|
+
*/
|
|
38
|
+
sentiment?: ButtonSentiment;
|
|
25
39
|
}
|
|
26
40
|
export declare const ToggleButtonGroup: import("react").ForwardRefExoticComponent<ToggleButtonGroupProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { type SyntheticEvent } from "react";
|
|
2
|
+
import type { ButtonAppearance, ButtonSentiment } from "../button";
|
|
2
3
|
export declare type Value = string | readonly string[] | number | undefined;
|
|
3
4
|
export interface ToggleButtonGroupContextValue {
|
|
5
|
+
appearance?: Extract<ButtonAppearance, "bordered" | "solid">;
|
|
4
6
|
disabled?: boolean;
|
|
5
|
-
select: (event: SyntheticEvent<HTMLButtonElement>) => void;
|
|
6
|
-
isSelected: (id: Value) => boolean;
|
|
7
7
|
focus: (id: Value) => void;
|
|
8
8
|
isFocused: (id: Value) => boolean;
|
|
9
|
+
isSelected: (id: Value) => boolean;
|
|
9
10
|
orientation: "horizontal" | "vertical";
|
|
11
|
+
readOnly?: boolean;
|
|
12
|
+
select: (event: SyntheticEvent<HTMLButtonElement>) => void;
|
|
13
|
+
sentiment?: ButtonSentiment;
|
|
10
14
|
}
|
|
11
15
|
export declare const ToggleButtonGroupContext: import("react").Context<ToggleButtonGroupContextValue | undefined>;
|
|
12
16
|
export declare function useToggleButtonGroup(): ToggleButtonGroupContextValue | undefined;
|