@gild-ui/react 0.0.0 → 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +399 -1
- package/dist/Accordion.cjs +338 -0
- package/dist/Accordion.d.cts +110 -0
- package/dist/Accordion.d.mts +110 -0
- package/dist/Accordion.mjs +334 -0
- package/dist/Accordion.types-DxvwAfZc.d.mts +1299 -0
- package/dist/Alert.cjs +187 -0
- package/dist/Alert.d.cts +51 -0
- package/dist/Alert.d.mts +51 -0
- package/dist/Alert.mjs +186 -0
- package/dist/AppBar.cjs +76 -0
- package/dist/AppBar.d.cts +22 -0
- package/dist/AppBar.d.mts +22 -0
- package/dist/AppBar.mjs +76 -0
- package/dist/Autocomplete.cjs +685 -0
- package/dist/Autocomplete.d.cts +97 -0
- package/dist/Autocomplete.d.mts +97 -0
- package/dist/Autocomplete.mjs +685 -0
- package/dist/Avatar.cjs +113 -0
- package/dist/Avatar.d.cts +27 -0
- package/dist/Avatar.d.mts +27 -0
- package/dist/Avatar.mjs +113 -0
- package/dist/Backdrop.cjs +30 -0
- package/dist/Backdrop.d.cts +11 -0
- package/dist/Backdrop.d.mts +11 -0
- package/dist/Backdrop.mjs +29 -0
- package/dist/Badge.cjs +136 -0
- package/dist/Badge.d.cts +47 -0
- package/dist/Badge.d.mts +47 -0
- package/dist/Badge.mjs +136 -0
- package/dist/Breadcrumbs.cjs +150 -0
- package/dist/Breadcrumbs.d.cts +33 -0
- package/dist/Breadcrumbs.d.mts +33 -0
- package/dist/Breadcrumbs.mjs +149 -0
- package/dist/Button.cjs +194 -0
- package/dist/Button.d.cts +3 -0
- package/dist/Button.d.mts +3 -0
- package/dist/Button.mjs +194 -0
- package/dist/ButtonGroup.cjs +116 -0
- package/dist/ButtonGroup.d.cts +43 -0
- package/dist/ButtonGroup.d.mts +3 -0
- package/dist/ButtonGroup.mjs +115 -0
- package/dist/ButtonGroupContext-D5Fg5Slq.mjs +5 -0
- package/dist/ButtonGroupContext-W4VkHwoR.cjs +9 -0
- package/dist/CacheProvider.cjs +9 -0
- package/dist/CacheProvider.d.cts +4 -0
- package/dist/CacheProvider.d.mts +4 -0
- package/dist/CacheProvider.mjs +9 -0
- package/dist/Card.cjs +105 -0
- package/dist/Card.d.cts +19 -0
- package/dist/Card.d.mts +19 -0
- package/dist/Card.mjs +105 -0
- package/dist/Checkbox.cjs +210 -0
- package/dist/Checkbox.d.cts +48 -0
- package/dist/Checkbox.d.mts +48 -0
- package/dist/Checkbox.mjs +210 -0
- package/dist/Chip.cjs +210 -0
- package/dist/Chip.d.cts +51 -0
- package/dist/Chip.d.mts +51 -0
- package/dist/Chip.mjs +210 -0
- package/dist/CircularProgress.cjs +151 -0
- package/dist/CircularProgress.d.cts +37 -0
- package/dist/CircularProgress.d.mts +37 -0
- package/dist/CircularProgress.mjs +151 -0
- package/dist/Collapse.cjs +133 -0
- package/dist/Collapse.d.cts +38 -0
- package/dist/Collapse.d.mts +3 -0
- package/dist/Collapse.mjs +133 -0
- package/dist/Drawer.cjs +168 -0
- package/dist/Drawer.d.cts +60 -0
- package/dist/Drawer.d.mts +60 -0
- package/dist/Drawer.mjs +166 -0
- package/dist/Fab.cjs +123 -0
- package/dist/Fab.d.cts +33 -0
- package/dist/Fab.d.mts +3 -0
- package/dist/Fab.mjs +122 -0
- package/dist/FabMenu.cjs +312 -0
- package/dist/FabMenu.d.cts +70 -0
- package/dist/FabMenu.d.mts +70 -0
- package/dist/FabMenu.mjs +311 -0
- package/dist/Fade.cjs +17 -0
- package/dist/Fade.d.cts +8 -0
- package/dist/Fade.d.mts +8 -0
- package/dist/Fade.mjs +16 -0
- package/dist/Flex.cjs +18 -0
- package/dist/Flex.d.cts +2 -0
- package/dist/Flex.d.mts +2 -0
- package/dist/Flex.mjs +17 -0
- package/dist/FocusTrap.cjs +87 -0
- package/dist/FocusTrap.d.cts +28 -0
- package/dist/FocusTrap.d.mts +28 -0
- package/dist/FocusTrap.mjs +86 -0
- package/dist/Form.cjs +47 -0
- package/dist/Form.d.cts +41 -0
- package/dist/Form.d.mts +41 -0
- package/dist/Form.mjs +46 -0
- package/dist/FormContext-DfpxiqRO.cjs +9 -0
- package/dist/FormContext-fZHQHKUU.mjs +6 -0
- package/dist/FormControl.cjs +98 -0
- package/dist/FormControl.d.cts +81 -0
- package/dist/FormControl.d.mts +81 -0
- package/dist/FormControl.mjs +96 -0
- package/dist/FormControlContext-Btvm04Sj.cjs +9 -0
- package/dist/FormControlContext-CaQLS_sK.mjs +6 -0
- package/dist/FormHelperText.cjs +40 -0
- package/dist/FormHelperText.d.cts +15 -0
- package/dist/FormHelperText.d.mts +15 -0
- package/dist/FormHelperText.mjs +39 -0
- package/dist/FormLabel.cjs +45 -0
- package/dist/FormLabel.d.cts +17 -0
- package/dist/FormLabel.d.mts +17 -0
- package/dist/FormLabel.mjs +44 -0
- package/dist/Global.cjs +8 -0
- package/dist/Global.d.cts +2 -0
- package/dist/Global.d.mts +2 -0
- package/dist/Global.mjs +1 -0
- package/dist/Grid.cjs +20 -0
- package/dist/Grid.d.cts +25 -0
- package/dist/Grid.d.mts +25 -0
- package/dist/Grid.mjs +20 -0
- package/dist/Grow.cjs +21 -0
- package/dist/Grow.d.cts +8 -0
- package/dist/Grow.d.mts +8 -0
- package/dist/Grow.mjs +20 -0
- package/dist/Icon-DBgqmUb3.mjs +916 -0
- package/dist/Icon-DPIqGixm.cjs +927 -0
- package/dist/Icon.cjs +4 -0
- package/dist/Icon.d.cts +3 -0
- package/dist/Icon.d.mts +3 -0
- package/dist/Icon.mjs +1 -0
- package/dist/Image.cjs +89 -0
- package/dist/Image.d.cts +19 -0
- package/dist/Image.d.mts +19 -0
- package/dist/Image.mjs +89 -0
- package/dist/LayoutProvider-DFwC1-h0.d.cts +19 -0
- package/dist/LayoutProvider-DFwC1-h0.d.mts +19 -0
- package/dist/LayoutProvider-Eb5Vp2BZ.mjs +36 -0
- package/dist/LayoutProvider-nB0hiaCR.cjs +41 -0
- package/dist/LayoutProvider.cjs +3 -0
- package/dist/LayoutProvider.d.cts +2 -0
- package/dist/LayoutProvider.d.mts +2 -0
- package/dist/LayoutProvider.mjs +1 -0
- package/dist/LinearProgress.cjs +232 -0
- package/dist/LinearProgress.d.cts +39 -0
- package/dist/LinearProgress.d.mts +39 -0
- package/dist/LinearProgress.mjs +232 -0
- package/dist/Link.cjs +59 -0
- package/dist/Link.d.cts +9 -0
- package/dist/Link.d.mts +9 -0
- package/dist/Link.mjs +59 -0
- package/dist/Menu-Ca7aUnLg.mjs +229 -0
- package/dist/Menu-DlPDdIAu.cjs +245 -0
- package/dist/Menu.cjs +174 -0
- package/dist/Menu.d.cts +209 -0
- package/dist/Menu.d.mts +209 -0
- package/dist/Menu.mjs +168 -0
- package/dist/MenuItem-2UwOFsM6.cjs +859 -0
- package/dist/MenuItem-w7D1-AYW.mjs +807 -0
- package/dist/MenuItem.cjs +4 -0
- package/dist/MenuItem.d.cts +3 -0
- package/dist/MenuItem.d.mts +3 -0
- package/dist/MenuItem.mjs +2 -0
- package/dist/Modal-B6_1ugIW.cjs +328 -0
- package/dist/Modal-Ouz9KdOG.mjs +300 -0
- package/dist/Modal.cjs +8 -0
- package/dist/Modal.d.cts +57 -0
- package/dist/Modal.d.mts +3 -0
- package/dist/Modal.mjs +2 -0
- package/dist/NativeSelect.cjs +197 -0
- package/dist/NativeSelect.d.cts +65 -0
- package/dist/NativeSelect.d.mts +65 -0
- package/dist/NativeSelect.mjs +197 -0
- package/dist/NavTree.cjs +225 -0
- package/dist/NavTree.d.cts +65 -0
- package/dist/NavTree.d.mts +65 -0
- package/dist/NavTree.mjs +223 -0
- package/dist/NumberInput.cjs +513 -0
- package/dist/NumberInput.d.cts +96 -0
- package/dist/NumberInput.d.mts +96 -0
- package/dist/NumberInput.mjs +512 -0
- package/dist/Pagination.cjs +258 -0
- package/dist/Pagination.d.cts +90 -0
- package/dist/Pagination.d.mts +3 -0
- package/dist/Pagination.mjs +256 -0
- package/dist/Paper.cjs +54 -0
- package/dist/Paper.d.cts +2 -0
- package/dist/Paper.d.mts +3 -0
- package/dist/Paper.mjs +54 -0
- package/dist/Popover-ZsN1txGi.mjs +139 -0
- package/dist/Popover-d5fip8Fi.cjs +143 -0
- package/dist/Popover.cjs +4 -0
- package/dist/Popover.d.cts +67 -0
- package/dist/Popover.d.mts +67 -0
- package/dist/Popover.mjs +2 -0
- package/dist/Portal.cjs +22 -0
- package/dist/Portal.d.cts +15 -0
- package/dist/Portal.d.mts +2 -0
- package/dist/Portal.mjs +21 -0
- package/dist/Pressable.cjs +134 -0
- package/dist/Pressable.d.cts +52 -0
- package/dist/Pressable.d.mts +3 -0
- package/dist/Pressable.mjs +134 -0
- package/dist/Quote.cjs +11 -0
- package/dist/Quote.d.cts +15 -0
- package/dist/Quote.d.mts +15 -0
- package/dist/Quote.mjs +10 -0
- package/dist/Radio.cjs +161 -0
- package/dist/Radio.d.cts +43 -0
- package/dist/Radio.d.mts +43 -0
- package/dist/Radio.mjs +161 -0
- package/dist/RangeInput.cjs +705 -0
- package/dist/RangeInput.d.cts +77 -0
- package/dist/RangeInput.d.mts +77 -0
- package/dist/RangeInput.mjs +705 -0
- package/dist/Rating.cjs +390 -0
- package/dist/Rating.d.cts +59 -0
- package/dist/Rating.d.mts +59 -0
- package/dist/Rating.mjs +390 -0
- package/dist/ScrollArea.cjs +282 -0
- package/dist/ScrollArea.d.cts +40 -0
- package/dist/ScrollArea.d.mts +40 -0
- package/dist/ScrollArea.mjs +281 -0
- package/dist/Select.cjs +528 -0
- package/dist/Select.d.cts +69 -0
- package/dist/Select.d.mts +69 -0
- package/dist/Select.mjs +528 -0
- package/dist/Sidebar.cjs +332 -0
- package/dist/Sidebar.d.cts +156 -0
- package/dist/Sidebar.d.mts +156 -0
- package/dist/Sidebar.mjs +330 -0
- package/dist/Skeleton.cjs +90 -0
- package/dist/Skeleton.d.cts +24 -0
- package/dist/Skeleton.d.mts +24 -0
- package/dist/Skeleton.mjs +90 -0
- package/dist/Slide.cjs +57 -0
- package/dist/Slide.d.cts +14 -0
- package/dist/Slide.d.mts +14 -0
- package/dist/Slide.mjs +56 -0
- package/dist/Snackbar.cjs +216 -0
- package/dist/Snackbar.d.cts +81 -0
- package/dist/Snackbar.d.mts +81 -0
- package/dist/Snackbar.mjs +215 -0
- package/dist/StyleSheet.cjs +8 -0
- package/dist/StyleSheet.d.cts +2 -0
- package/dist/StyleSheet.d.mts +2 -0
- package/dist/StyleSheet.mjs +1 -0
- package/dist/Switch.cjs +355 -0
- package/dist/Switch.d.cts +45 -0
- package/dist/Switch.d.mts +45 -0
- package/dist/Switch.mjs +355 -0
- package/dist/Table.cjs +722 -0
- package/dist/Table.d.cts +404 -0
- package/dist/Table.d.mts +404 -0
- package/dist/Table.mjs +707 -0
- package/dist/Tabs.cjs +1227 -0
- package/dist/Tabs.d.cts +245 -0
- package/dist/Tabs.d.mts +245 -0
- package/dist/Tabs.mjs +1222 -0
- package/dist/TextInput.cjs +236 -0
- package/dist/TextInput.d.cts +3 -0
- package/dist/TextInput.d.mts +3 -0
- package/dist/TextInput.mjs +236 -0
- package/dist/ThemeProvider-DS6pBgE-.cjs +68 -0
- package/dist/ThemeProvider-DuhfCo2F.mjs +63 -0
- package/dist/ThemeProvider.cjs +4 -0
- package/dist/ThemeProvider.d.cts +2 -0
- package/dist/ThemeProvider.d.mts +2 -0
- package/dist/ThemeProvider.mjs +2 -0
- package/dist/ToggleButton.cjs +115 -0
- package/dist/ToggleButton.d.cts +51 -0
- package/dist/ToggleButton.d.mts +51 -0
- package/dist/ToggleButton.mjs +113 -0
- package/dist/Tooltip-Bt5lr52c.mjs +485 -0
- package/dist/Tooltip-CUpZpoC9.cjs +495 -0
- package/dist/Tooltip.cjs +5 -0
- package/dist/Tooltip.d.cts +122 -0
- package/dist/Tooltip.d.mts +122 -0
- package/dist/Tooltip.mjs +2 -0
- package/dist/TransferList.cjs +394 -0
- package/dist/TransferList.d.cts +69 -0
- package/dist/TransferList.d.mts +69 -0
- package/dist/TransferList.mjs +394 -0
- package/dist/Typography.cjs +69 -0
- package/dist/Typography.d.cts +3 -0
- package/dist/Typography.d.mts +3 -0
- package/dist/Typography.mjs +69 -0
- package/dist/View-DFnZ41Xe.cjs +77 -0
- package/dist/View-zuvgW6DP.mjs +66 -0
- package/dist/View.cjs +3 -0
- package/dist/View.d.cts +2 -0
- package/dist/View.d.mts +2 -0
- package/dist/View.mjs +1 -0
- package/dist/Zoom.cjs +16 -0
- package/dist/Zoom.d.cts +7 -0
- package/dist/Zoom.d.mts +7 -0
- package/dist/Zoom.mjs +15 -0
- package/dist/catalog.cjs +22 -0
- package/dist/catalog.d.cts +28 -0
- package/dist/catalog.d.mts +28 -0
- package/dist/catalog.mjs +21 -0
- package/dist/computePopoverPosition-C6qSQ1QD.cjs +126 -0
- package/dist/computePopoverPosition-DHV1wQgJ.mjs +121 -0
- package/dist/computePopoverPosition-JgOwCM7k.d.cts +12 -0
- package/dist/computePopoverPosition-JgOwCM7k.d.mts +12 -0
- package/dist/css.cjs +20 -0
- package/dist/css.d.cts +2 -0
- package/dist/css.d.mts +2 -0
- package/dist/css.mjs +1 -0
- package/dist/derivedTheme-B0cxTzAq.cjs +29 -0
- package/dist/derivedTheme-BB9VVZ08.mjs +24 -0
- package/dist/engine.cjs +146 -0
- package/dist/engine.d.cts +59 -0
- package/dist/engine.d.mts +59 -0
- package/dist/engine.mjs +101 -0
- package/dist/getElementRef-4m6-x2FS.cjs +18 -0
- package/dist/getElementRef-SBx9_7pp.mjs +13 -0
- package/dist/index-B3jHcw5h.d.cts +175 -0
- package/dist/index-Bf-ZHQLG.d.mts +33 -0
- package/dist/index-CAMwJg71.d.mts +92 -0
- package/dist/index-CLQt_mOa.d.mts +3 -0
- package/dist/index-Cqse4F32.d.mts +38 -0
- package/dist/index-CsYK-ukA.d.mts +3 -0
- package/dist/index-D9Gg2NWm.d.mts +90 -0
- package/dist/index-DPQxIeZF.d.cts +1299 -0
- package/dist/index-Dc7XiT_v.d.cts +92 -0
- package/dist/index-Djum1XiO.d.mts +52 -0
- package/dist/index-DtfH-dhY.d.mts +43 -0
- package/dist/index-IB1nBqEO.d.mts +175 -0
- package/dist/index-UloRwym_.d.mts +16 -0
- package/dist/index-phuw9VpI.d.mts +57 -0
- package/dist/index-yCzwpbBP.d.mts +1 -0
- package/dist/index.cjs +93 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +17 -0
- package/dist/inputVariantStyles-B-4lHxUZ.mjs +41 -0
- package/dist/inputVariantStyles-CqCQatKb.cjs +58 -0
- package/dist/isRtl-DN-EdUlg.mjs +6 -0
- package/dist/isRtl-Dl6QQWib.cjs +11 -0
- package/dist/keyframes.cjs +8 -0
- package/dist/keyframes.d.cts +2 -0
- package/dist/keyframes.d.mts +2 -0
- package/dist/keyframes.mjs +1 -0
- package/dist/next.cjs +8 -0
- package/dist/next.d.cts +2 -0
- package/dist/next.d.mts +2 -0
- package/dist/next.mjs +1 -0
- package/dist/overrides-DeXScOFK.cjs +21 -0
- package/dist/overrides-Ds6QZL5Q.mjs +16 -0
- package/dist/server.cjs +19 -0
- package/dist/server.d.cts +10 -0
- package/dist/server.d.mts +10 -0
- package/dist/server.mjs +18 -0
- package/dist/styleEngine-CLid4cmR.mjs +1 -0
- package/dist/styled-Dr3_OY1-.cjs +48 -0
- package/dist/styled-tLHNvicL.mjs +43 -0
- package/dist/styled.cjs +3 -0
- package/dist/styled.d.cts +2 -0
- package/dist/styled.d.mts +2 -0
- package/dist/styled.mjs +1 -0
- package/dist/testing.cjs +60 -0
- package/dist/testing.d.cts +6 -0
- package/dist/testing.d.mts +6 -0
- package/dist/testing.mjs +59 -0
- package/dist/themes-BtfQPcbo.mjs +8 -0
- package/dist/themes-k-PEE5O9.cjs +12 -0
- package/dist/useAnchoredPlacement-CSotv28V.cjs +116 -0
- package/dist/useAnchoredPlacement-VwHtXnAx.mjs +111 -0
- package/dist/useDefaultProps-BTQGhvfY.mjs +13 -0
- package/dist/useDefaultProps-DratGGIL.cjs +18 -0
- package/dist/useDefaultProps.cjs +3 -0
- package/dist/useDefaultProps.d.cts +2 -0
- package/dist/useDefaultProps.d.mts +2 -0
- package/dist/useDefaultProps.mjs +1 -0
- package/dist/useLiveValue-CN2SUG2B.cjs +20 -0
- package/dist/useLiveValue-CqiwCr56.mjs +15 -0
- package/dist/useMediaQuery-acJak9M3.mjs +2 -0
- package/dist/useMediaQuery.cjs +9 -0
- package/dist/useMediaQuery.d.cts +2 -0
- package/dist/useMediaQuery.d.mts +2 -0
- package/dist/useMediaQuery.mjs +2 -0
- package/dist/useStyle.cjs +14 -0
- package/dist/useStyle.d.cts +2 -0
- package/dist/useStyle.d.mts +2 -0
- package/dist/useStyle.mjs +1 -0
- package/dist/useTheme.cjs +8 -0
- package/dist/useTheme.d.cts +2 -0
- package/dist/useTheme.d.mts +2 -0
- package/dist/useTheme.mjs +1 -0
- package/dist/useTransition-BKBtk0Mb.mjs +78 -0
- package/dist/useTransition-BzwifRXe.d.mts +40 -0
- package/dist/useTransition-gHFCJwqF.cjs +83 -0
- package/dist/useTransition-lt8_WKk-.d.cts +40 -0
- package/dist/useTransitionChild-C18w474Q.mjs +52 -0
- package/dist/useTransitionChild-DD3f44AQ.cjs +57 -0
- package/dist/utils-ChXrUitU.mjs +1 -0
- package/dist/withStyle.cjs +8 -0
- package/dist/withStyle.d.cts +2 -0
- package/dist/withStyle.d.mts +2 -0
- package/dist/withStyle.mjs +1 -0
- package/dist/withTheme.cjs +8 -0
- package/dist/withTheme.d.cts +2 -0
- package/dist/withTheme.d.mts +2 -0
- package/dist/withTheme.mjs +1 -0
- package/package.json +911 -3
|
@@ -0,0 +1,705 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { i as alpha } from "./styleEngine-CLid4cmR.mjs";
|
|
3
|
+
import { t as styled } from "./styled-tLHNvicL.mjs";
|
|
4
|
+
import { t as useLiveValue } from "./useLiveValue-CqiwCr56.mjs";
|
|
5
|
+
import "./themes-BtfQPcbo.mjs";
|
|
6
|
+
import { t as useDefaultProps } from "./useDefaultProps-BTQGhvfY.mjs";
|
|
7
|
+
import { useFormControl } from "./FormControl.mjs";
|
|
8
|
+
import { t as isRtl } from "./isRtl-DN-EdUlg.mjs";
|
|
9
|
+
import { t as mergeOverrides } from "./overrides-Ds6QZL5Q.mjs";
|
|
10
|
+
import { Fragment, useId, useRef, useState } from "react";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { addExact, clamp, snapToStep } from "@gild-ui/core/utils";
|
|
13
|
+
import { createShouldForwardProp, props } from "@soroush.tech/styled-system/should-forward-prop";
|
|
14
|
+
import { get, space, system } from "@soroush.tech/styled-system";
|
|
15
|
+
import { useControlled } from "@gild-ui/hooks/useControlled";
|
|
16
|
+
// src/RangeInput/utils/range.ts
|
|
17
|
+
/** How far along the range a value is, as a percent. */
|
|
18
|
+
function valueToPercent(value, min, max) {
|
|
19
|
+
return max === min ? 0 : (value - min) * 100 / (max - min);
|
|
20
|
+
}
|
|
21
|
+
/** The value a fraction of the way along the range is. */
|
|
22
|
+
function fractionToValue(fraction, min, max) {
|
|
23
|
+
return (max - min) * fraction + min;
|
|
24
|
+
}
|
|
25
|
+
const ascending = (a, b) => a - b;
|
|
26
|
+
/**
|
|
27
|
+
* The thumbs' values, sorted and clamped to the range - one for a number, each for an array. An
|
|
28
|
+
* empty array has no thumb to draw or move, so it is one thumb at `min`, as no value is.
|
|
29
|
+
*/
|
|
30
|
+
function normalizeValues(value, min, max) {
|
|
31
|
+
const list = typeof value === "number" ? [value] : [...value].sort(ascending);
|
|
32
|
+
return (list.length === 0 ? [min] : list).map((entry) => clamp(entry, min, max));
|
|
33
|
+
}
|
|
34
|
+
/** The marks: one at every step for `true`, the ones given, or none. */
|
|
35
|
+
function getMarks(marks, step, min, max) {
|
|
36
|
+
if (marks === true && step !== null) {
|
|
37
|
+
const steps = Math.floor(Number(((max - min) / step).toPrecision(12)));
|
|
38
|
+
return Array.from({ length: steps + 1 }, (_, index) => ({ value: snapToStep(min + step * index, step, min) }));
|
|
39
|
+
}
|
|
40
|
+
return Array.isArray(marks) ? marks : [];
|
|
41
|
+
}
|
|
42
|
+
/** The index of the value nearest `target` - the preferred one when it is as near as the nearest. */
|
|
43
|
+
function findClosest(values, target, preferredIndex = -1) {
|
|
44
|
+
let closest = 0;
|
|
45
|
+
values.forEach((value, index) => {
|
|
46
|
+
if (Math.abs(target - value) <= Math.abs(target - values[closest])) closest = index;
|
|
47
|
+
});
|
|
48
|
+
return preferredIndex >= 0 && values[preferredIndex] === values[closest] ? preferredIndex : closest;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Moves one thumb to a value. Passing a neighbour swaps their places, the values staying sorted;
|
|
52
|
+
* without `shouldSwap` the thumb stops at its neighbour instead.
|
|
53
|
+
*/
|
|
54
|
+
function moveThumb(values, index, target, shouldSwap) {
|
|
55
|
+
const bounded = shouldSwap ? target : clamp(target, values[index - 1] ?? Number.NEGATIVE_INFINITY, values[index + 1] ?? Number.POSITIVE_INFINITY);
|
|
56
|
+
const moved = values.map((value, place) => place === index ? bounded : value).sort(ascending);
|
|
57
|
+
return {
|
|
58
|
+
values: moved,
|
|
59
|
+
index: shouldSwap ? moved.indexOf(bounded) : index
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function areValuesEqual(a, b) {
|
|
63
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
64
|
+
}
|
|
65
|
+
const KEYS = /* @__PURE__ */ new Set([
|
|
66
|
+
"ArrowUp",
|
|
67
|
+
"ArrowDown",
|
|
68
|
+
"ArrowLeft",
|
|
69
|
+
"ArrowRight",
|
|
70
|
+
"PageUp",
|
|
71
|
+
"PageDown",
|
|
72
|
+
"Home",
|
|
73
|
+
"End"
|
|
74
|
+
]);
|
|
75
|
+
/** Whether the slider takes the key. */
|
|
76
|
+
const isRangeKey = (key) => KEYS.has(key);
|
|
77
|
+
const upKeys = (isRtl) => [
|
|
78
|
+
"ArrowUp",
|
|
79
|
+
isRtl ? "ArrowLeft" : "ArrowRight",
|
|
80
|
+
"PageUp",
|
|
81
|
+
"End"
|
|
82
|
+
];
|
|
83
|
+
const downKeys = (isRtl) => [
|
|
84
|
+
"ArrowDown",
|
|
85
|
+
isRtl ? "ArrowRight" : "ArrowLeft",
|
|
86
|
+
"PageDown",
|
|
87
|
+
"Home"
|
|
88
|
+
];
|
|
89
|
+
function getMarkValue({ key, value, isRtl, marks }) {
|
|
90
|
+
const values = marks.map((mark) => mark.value);
|
|
91
|
+
if (values.length === 0) return null;
|
|
92
|
+
if (key === "Home") return values[0];
|
|
93
|
+
if (key === "End") return values.at(-1);
|
|
94
|
+
if (downKeys(isRtl).includes(key)) return [...values].reverse().find((mark) => mark < value) ?? values[0];
|
|
95
|
+
return values.find((mark) => mark > value) ?? values.at(-1);
|
|
96
|
+
}
|
|
97
|
+
/** The value a key moves a thumb to - `null` when the key moves nothing. */
|
|
98
|
+
function getKeyValue(params) {
|
|
99
|
+
const { key, shiftKey, value, step, shiftStep, min, max, isRtl } = params;
|
|
100
|
+
if (!isRangeKey(key)) return null;
|
|
101
|
+
if (step === null) return getMarkValue(params);
|
|
102
|
+
if (key === "Home") return min;
|
|
103
|
+
if (key === "End") return max;
|
|
104
|
+
const size = key === "PageUp" || key === "PageDown" || shiftKey ? shiftStep : step;
|
|
105
|
+
const direction = upKeys(isRtl).includes(key) ? 1 : -1;
|
|
106
|
+
return clamp(addExact(value, direction * size), min, max);
|
|
107
|
+
}
|
|
108
|
+
/** The value under a point - along the box, snapped to the step or the nearest mark. */
|
|
109
|
+
function getValueAtPoint({ x, y, rect, orientation, isRtl, min, max, step, marks }) {
|
|
110
|
+
const length = orientation === "vertical" ? rect.height : rect.width;
|
|
111
|
+
if (length === 0) return null;
|
|
112
|
+
let fraction = orientation === "vertical" ? (rect.bottom - y) / length : (x - rect.left) / length;
|
|
113
|
+
if (orientation === "horizontal" && isRtl) fraction = 1 - fraction;
|
|
114
|
+
const raw = fractionToValue(fraction, min, max);
|
|
115
|
+
if (step !== null) return clamp(snapToStep(raw, step, min), min, max);
|
|
116
|
+
const markValues = marks.map((mark) => mark.value);
|
|
117
|
+
if (markValues.length === 0) return clamp(raw, min, max);
|
|
118
|
+
return clamp(markValues[findClosest(markValues, raw)], min, max);
|
|
119
|
+
}
|
|
120
|
+
// src/RangeInput/hooks/useRangeInput.ts
|
|
121
|
+
const NONE = -1;
|
|
122
|
+
function withTarget(event, target) {
|
|
123
|
+
const native = event.nativeEvent;
|
|
124
|
+
const clone = new native.constructor(native.type, native);
|
|
125
|
+
Object.defineProperty(clone, "target", {
|
|
126
|
+
writable: true,
|
|
127
|
+
value: target
|
|
128
|
+
});
|
|
129
|
+
return clone;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* A slider's state: its value (controlled or not) as the thumbs' sorted values, which thumb is
|
|
133
|
+
* pressed, hovered or focused, and the handlers - the pointer's on the root, which keeps the
|
|
134
|
+
* pointer while it drags, and the keys' and the native input's on each thumb's own input.
|
|
135
|
+
*/
|
|
136
|
+
function useRangeInput({ value: valueProp, defaultValue, min, max, step, shiftStep, marks, orientation, shouldSwapThumbs, isDisabled, name, rootRef, onChange, onChangeCommitted }) {
|
|
137
|
+
const [value, setValue] = useControlled({
|
|
138
|
+
controlled: valueProp,
|
|
139
|
+
default: defaultValue ?? min
|
|
140
|
+
});
|
|
141
|
+
const isRange = typeof value !== "number";
|
|
142
|
+
const values = normalizeValues(value, min, max);
|
|
143
|
+
const [active, setActive] = useState(NONE);
|
|
144
|
+
const [hovered, setHovered] = useState(NONE);
|
|
145
|
+
const [focused, setFocused] = useState(NONE);
|
|
146
|
+
const [lastUsed, setLastUsed] = useState(NONE);
|
|
147
|
+
const dragIndex = useRef(NONE);
|
|
148
|
+
const pointerId = useRef(NONE);
|
|
149
|
+
const lastChanged = useRef(0);
|
|
150
|
+
const toOutput = (list) => isRange ? [...list] : list[0];
|
|
151
|
+
const emit = (event, list, index) => {
|
|
152
|
+
const next = toOutput(list);
|
|
153
|
+
setValue(next);
|
|
154
|
+
if (areValuesEqual(list, values)) return;
|
|
155
|
+
lastChanged.current = next;
|
|
156
|
+
onChange?.(withTarget(event, {
|
|
157
|
+
value: next,
|
|
158
|
+
name
|
|
159
|
+
}), next, index);
|
|
160
|
+
};
|
|
161
|
+
const focusThumb = (index) => {
|
|
162
|
+
(rootRef.current?.querySelector(`input[data-index="${index}"]`))?.focus({ preventScroll: true });
|
|
163
|
+
};
|
|
164
|
+
const resolveAt = (event, held) => {
|
|
165
|
+
const target = getValueAtPoint({
|
|
166
|
+
x: event.clientX,
|
|
167
|
+
y: event.clientY,
|
|
168
|
+
rect: rootRef.current.getBoundingClientRect(),
|
|
169
|
+
orientation,
|
|
170
|
+
isRtl: isRtl(rootRef.current),
|
|
171
|
+
min,
|
|
172
|
+
max,
|
|
173
|
+
step,
|
|
174
|
+
marks
|
|
175
|
+
});
|
|
176
|
+
if (target === null) return null;
|
|
177
|
+
const index = held === NONE ? findClosest(values, target, lastUsed) : held;
|
|
178
|
+
return moveThumb(values, index, target, shouldSwapThumbs);
|
|
179
|
+
};
|
|
180
|
+
const hold = (event, moved) => {
|
|
181
|
+
dragIndex.current = moved.index;
|
|
182
|
+
setActive(moved.index);
|
|
183
|
+
setLastUsed(moved.index);
|
|
184
|
+
focusThumb(moved.index);
|
|
185
|
+
emit(event, moved.values, moved.index);
|
|
186
|
+
};
|
|
187
|
+
const handlePointerDown = (event) => {
|
|
188
|
+
if (isDisabled || event.defaultPrevented || event.button !== 0) return;
|
|
189
|
+
const moved = resolveAt(event, NONE);
|
|
190
|
+
if (moved === null) return;
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
pointerId.current = event.pointerId;
|
|
193
|
+
lastChanged.current = toOutput(values);
|
|
194
|
+
hold(event, moved);
|
|
195
|
+
try {
|
|
196
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
197
|
+
} catch {}
|
|
198
|
+
};
|
|
199
|
+
const release = (event) => {
|
|
200
|
+
setActive(NONE);
|
|
201
|
+
pointerId.current = NONE;
|
|
202
|
+
dragIndex.current = NONE;
|
|
203
|
+
if (event.currentTarget.hasPointerCapture?.(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
|
|
204
|
+
onChangeCommitted?.(event, lastChanged.current);
|
|
205
|
+
};
|
|
206
|
+
const handlePointerMove = (event) => {
|
|
207
|
+
if (event.pointerId !== pointerId.current) return;
|
|
208
|
+
if (event.buttons === 0) return release(event);
|
|
209
|
+
const moved = resolveAt(event, dragIndex.current);
|
|
210
|
+
if (moved !== null) hold(event, moved);
|
|
211
|
+
};
|
|
212
|
+
const handlePointerEnd = (event) => {
|
|
213
|
+
if (event.pointerId === pointerId.current) release(event);
|
|
214
|
+
};
|
|
215
|
+
const change = (event, index, target) => {
|
|
216
|
+
const moved = moveThumb(values, index, clamp(target, min, max), shouldSwapThumbs);
|
|
217
|
+
if (moved.index !== index) focusThumb(moved.index);
|
|
218
|
+
setFocused(moved.index);
|
|
219
|
+
emit(event, moved.values, moved.index);
|
|
220
|
+
onChangeCommitted?.(event, toOutput(moved.values));
|
|
221
|
+
};
|
|
222
|
+
const getInputProps = (index) => ({
|
|
223
|
+
onKeyDown: (event) => {
|
|
224
|
+
if (!isRangeKey(event.key)) return;
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
const next = getKeyValue({
|
|
227
|
+
key: event.key,
|
|
228
|
+
shiftKey: event.shiftKey,
|
|
229
|
+
value: values[index],
|
|
230
|
+
step,
|
|
231
|
+
shiftStep,
|
|
232
|
+
min,
|
|
233
|
+
max,
|
|
234
|
+
isRtl: isRtl(event.currentTarget),
|
|
235
|
+
marks
|
|
236
|
+
});
|
|
237
|
+
if (next !== null) change(event, index, next);
|
|
238
|
+
},
|
|
239
|
+
onChange: (event) => {
|
|
240
|
+
const typed = event.currentTarget.valueAsNumber;
|
|
241
|
+
const markValues = marks.map((mark) => mark.value);
|
|
242
|
+
const target = step === null && markValues.length > 0 ? markValues[findClosest(markValues, typed)] : typed;
|
|
243
|
+
change(event, index, target);
|
|
244
|
+
},
|
|
245
|
+
onFocus: () => setFocused(index),
|
|
246
|
+
onBlur: () => setFocused(NONE)
|
|
247
|
+
});
|
|
248
|
+
const getThumbProps = (index) => ({
|
|
249
|
+
onMouseEnter: () => setHovered(index),
|
|
250
|
+
onMouseLeave: () => setHovered(NONE)
|
|
251
|
+
});
|
|
252
|
+
return {
|
|
253
|
+
values,
|
|
254
|
+
isRange,
|
|
255
|
+
active: isDisabled ? NONE : active,
|
|
256
|
+
hovered,
|
|
257
|
+
focused,
|
|
258
|
+
lastUsed,
|
|
259
|
+
rootProps: {
|
|
260
|
+
onPointerDown: handlePointerDown,
|
|
261
|
+
onPointerMove: handlePointerMove,
|
|
262
|
+
onPointerUp: handlePointerEnd,
|
|
263
|
+
onPointerCancel: handlePointerEnd,
|
|
264
|
+
onLostPointerCapture: handlePointerEnd
|
|
265
|
+
},
|
|
266
|
+
getInputProps,
|
|
267
|
+
getThumbProps
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
// src/RangeInput/RangeInput.tsx
|
|
271
|
+
const RAIL = {
|
|
272
|
+
sm: .25,
|
|
273
|
+
md: .5,
|
|
274
|
+
lg: .75
|
|
275
|
+
};
|
|
276
|
+
const railThickness = (theme, size) => theme.space[RAIL[size] ?? .5];
|
|
277
|
+
const layoutStyles = system({
|
|
278
|
+
width: true,
|
|
279
|
+
height: true,
|
|
280
|
+
minWidth: true,
|
|
281
|
+
maxWidth: true,
|
|
282
|
+
minHeight: true,
|
|
283
|
+
maxHeight: true
|
|
284
|
+
});
|
|
285
|
+
const RangeInputRoot = styled("span", {
|
|
286
|
+
name: "RangeInput",
|
|
287
|
+
label: "RangeInput",
|
|
288
|
+
shouldForwardProp: createShouldForwardProp([
|
|
289
|
+
...props,
|
|
290
|
+
"size",
|
|
291
|
+
"orientation",
|
|
292
|
+
"isDisabled"
|
|
293
|
+
]),
|
|
294
|
+
systemProps: [space, layoutStyles]
|
|
295
|
+
})(({ theme, size, orientation, isDisabled }) => {
|
|
296
|
+
const thumb = theme.icon[size];
|
|
297
|
+
const isVertical = orientation === "vertical";
|
|
298
|
+
return {
|
|
299
|
+
position: "relative",
|
|
300
|
+
display: "block",
|
|
301
|
+
boxSizing: "border-box",
|
|
302
|
+
...!isVertical && { alignSelf: "stretch" },
|
|
303
|
+
...isVertical ? {
|
|
304
|
+
width: thumb,
|
|
305
|
+
height: "12rem",
|
|
306
|
+
marginBlock: `calc(${thumb} / 2)`
|
|
307
|
+
} : {
|
|
308
|
+
height: thumb,
|
|
309
|
+
marginInline: `calc(${thumb} / 2)`
|
|
310
|
+
},
|
|
311
|
+
touchAction: "none",
|
|
312
|
+
userSelect: "none",
|
|
313
|
+
cursor: "pointer",
|
|
314
|
+
...isDisabled && {
|
|
315
|
+
opacity: .5,
|
|
316
|
+
cursor: "not-allowed",
|
|
317
|
+
pointerEvents: "none"
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
});
|
|
321
|
+
const RangeInputRail = styled("span", {
|
|
322
|
+
name: "RangeInput",
|
|
323
|
+
slot: "rail",
|
|
324
|
+
label: "RangeInputRail",
|
|
325
|
+
shouldForwardProp: createShouldForwardProp([
|
|
326
|
+
"size",
|
|
327
|
+
"orientation",
|
|
328
|
+
"color",
|
|
329
|
+
"isInverted"
|
|
330
|
+
])
|
|
331
|
+
})(({ theme, size, orientation, color, isInverted }) => {
|
|
332
|
+
const thickness = railThickness(theme, size);
|
|
333
|
+
const fill = isInverted ? get(theme, `palette.${color}.main`) : get(theme, "border.light");
|
|
334
|
+
return {
|
|
335
|
+
position: "absolute",
|
|
336
|
+
borderRadius: theme.radii.sm,
|
|
337
|
+
backgroundColor: fill,
|
|
338
|
+
...orientation === "vertical" ? {
|
|
339
|
+
top: 0,
|
|
340
|
+
bottom: 0,
|
|
341
|
+
insetInlineStart: "50%",
|
|
342
|
+
width: thickness,
|
|
343
|
+
marginInlineStart: `calc(${thickness} / -2)`
|
|
344
|
+
} : {
|
|
345
|
+
insetInlineStart: 0,
|
|
346
|
+
insetInlineEnd: 0,
|
|
347
|
+
top: "50%",
|
|
348
|
+
height: thickness,
|
|
349
|
+
marginTop: `calc(${thickness} / -2)`
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
});
|
|
353
|
+
const RangeInputTrack = styled("span", {
|
|
354
|
+
name: "RangeInput",
|
|
355
|
+
slot: "track",
|
|
356
|
+
label: "RangeInputTrack",
|
|
357
|
+
shouldForwardProp: createShouldForwardProp([
|
|
358
|
+
"size",
|
|
359
|
+
"orientation",
|
|
360
|
+
"color",
|
|
361
|
+
"isInverted",
|
|
362
|
+
"isDragging",
|
|
363
|
+
"from",
|
|
364
|
+
"span"
|
|
365
|
+
])
|
|
366
|
+
})(({ theme, size, orientation, color, isInverted, isDragging, from, span }) => {
|
|
367
|
+
const thickness = railThickness(theme, size);
|
|
368
|
+
const fill = isInverted ? get(theme, "border.light") : get(theme, `palette.${color}.main`);
|
|
369
|
+
return {
|
|
370
|
+
position: "absolute",
|
|
371
|
+
borderRadius: theme.radii.sm,
|
|
372
|
+
backgroundColor: fill,
|
|
373
|
+
transition: isDragging ? "none" : "inset 0.1s ease, width 0.1s ease, height 0.1s ease",
|
|
374
|
+
"@media (prefers-reduced-motion: reduce)": { transition: "none" },
|
|
375
|
+
...orientation === "vertical" ? {
|
|
376
|
+
bottom: `${from}`,
|
|
377
|
+
height: `${span}`,
|
|
378
|
+
insetInlineStart: "50%",
|
|
379
|
+
width: thickness,
|
|
380
|
+
marginInlineStart: `calc(${thickness} / -2)`
|
|
381
|
+
} : {
|
|
382
|
+
insetInlineStart: `${from}`,
|
|
383
|
+
width: `${span}`,
|
|
384
|
+
top: "50%",
|
|
385
|
+
height: thickness,
|
|
386
|
+
marginTop: `calc(${thickness} / -2)`
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
});
|
|
390
|
+
const place = (orientation, percent) => orientation === "vertical" ? { bottom: `${percent}%` } : { insetInlineStart: `${percent}%` };
|
|
391
|
+
const RangeInputMark = styled("span", {
|
|
392
|
+
name: "RangeInput",
|
|
393
|
+
slot: "mark",
|
|
394
|
+
label: "RangeInputMark",
|
|
395
|
+
shouldForwardProp: createShouldForwardProp([
|
|
396
|
+
"size",
|
|
397
|
+
"orientation",
|
|
398
|
+
"color",
|
|
399
|
+
"isActive",
|
|
400
|
+
"percent"
|
|
401
|
+
])
|
|
402
|
+
})(({ theme, size, orientation, color, isActive, percent }) => {
|
|
403
|
+
const thickness = railThickness(theme, size);
|
|
404
|
+
return {
|
|
405
|
+
position: "absolute",
|
|
406
|
+
...place(orientation, percent),
|
|
407
|
+
pointerEvents: "none",
|
|
408
|
+
opacity: isActive ? .5 : 1,
|
|
409
|
+
backgroundColor: isActive ? get(theme, `palette.${color}.contrastText`) : get(theme, "text.disabled"),
|
|
410
|
+
...orientation === "vertical" ? {
|
|
411
|
+
insetInlineStart: "50%",
|
|
412
|
+
width: thickness,
|
|
413
|
+
height: 2,
|
|
414
|
+
marginInlineStart: `calc(${thickness} / -2)`,
|
|
415
|
+
marginBottom: -1
|
|
416
|
+
} : {
|
|
417
|
+
top: "50%",
|
|
418
|
+
width: 2,
|
|
419
|
+
height: thickness,
|
|
420
|
+
marginTop: `calc(${thickness} / -2)`,
|
|
421
|
+
marginInlineStart: -1
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
});
|
|
425
|
+
const RangeInputMarkLabel = styled("span", {
|
|
426
|
+
name: "RangeInput",
|
|
427
|
+
slot: "markLabel",
|
|
428
|
+
label: "RangeInputMarkLabel",
|
|
429
|
+
shouldForwardProp: createShouldForwardProp([
|
|
430
|
+
"size",
|
|
431
|
+
"orientation",
|
|
432
|
+
"percent"
|
|
433
|
+
])
|
|
434
|
+
})(({ theme, size, orientation, percent }) => {
|
|
435
|
+
const thumb = theme.icon[size];
|
|
436
|
+
return {
|
|
437
|
+
position: "absolute",
|
|
438
|
+
...place(orientation, percent),
|
|
439
|
+
pointerEvents: "none",
|
|
440
|
+
whiteSpace: "nowrap",
|
|
441
|
+
fontSize: theme.fontSizes[0],
|
|
442
|
+
color: get(theme, "text.secondary"),
|
|
443
|
+
...orientation === "vertical" ? {
|
|
444
|
+
insetInlineStart: `calc(50% + ${thumb})`,
|
|
445
|
+
transform: "translateY(50%)"
|
|
446
|
+
} : {
|
|
447
|
+
top: `calc(50% + ${thumb})`,
|
|
448
|
+
transform: "translateX(-50%)",
|
|
449
|
+
"[dir=\"rtl\"] &": { transform: "translateX(50%)" }
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
});
|
|
453
|
+
const RangeInputThumb = styled("span", {
|
|
454
|
+
name: "RangeInput",
|
|
455
|
+
slot: "thumb",
|
|
456
|
+
label: "RangeInputThumb",
|
|
457
|
+
shouldForwardProp: createShouldForwardProp([
|
|
458
|
+
"size",
|
|
459
|
+
"orientation",
|
|
460
|
+
"color",
|
|
461
|
+
"isActive",
|
|
462
|
+
"isPassive",
|
|
463
|
+
"place",
|
|
464
|
+
"isLastUsed"
|
|
465
|
+
])
|
|
466
|
+
})(({ theme, size, orientation, color, isActive, isPassive, place, isLastUsed }) => {
|
|
467
|
+
const thumb = theme.icon[size];
|
|
468
|
+
const main = get(theme, `palette.${color}.main`);
|
|
469
|
+
return {
|
|
470
|
+
position: "absolute",
|
|
471
|
+
boxSizing: "border-box",
|
|
472
|
+
width: thumb,
|
|
473
|
+
height: thumb,
|
|
474
|
+
borderRadius: "50%",
|
|
475
|
+
backgroundColor: main,
|
|
476
|
+
...isPassive && { pointerEvents: "none" },
|
|
477
|
+
...isLastUsed && { zIndex: 1 },
|
|
478
|
+
boxShadow: isActive ? `0 0 0 ${theme.space[1]} ${alpha(main, .2)}` : "none",
|
|
479
|
+
transition: "box-shadow 0.15s ease",
|
|
480
|
+
"&:hover": { boxShadow: `0 0 0 ${theme.space[1]} ${alpha(main, .16)}` },
|
|
481
|
+
"&:has(input:focus-visible)": {
|
|
482
|
+
outline: `${theme.borderWidths.base} solid ${main}`,
|
|
483
|
+
outlineOffset: theme.space[.5]
|
|
484
|
+
},
|
|
485
|
+
"@media (prefers-reduced-motion: reduce)": { transition: "none" },
|
|
486
|
+
...orientation === "vertical" ? {
|
|
487
|
+
bottom: `${place}`,
|
|
488
|
+
insetInlineStart: "50%",
|
|
489
|
+
marginInlineStart: `calc(${thumb} / -2)`,
|
|
490
|
+
marginBottom: `calc(${thumb} / -2)`
|
|
491
|
+
} : {
|
|
492
|
+
insetInlineStart: `${place}`,
|
|
493
|
+
top: "50%",
|
|
494
|
+
marginTop: `calc(${thumb} / -2)`,
|
|
495
|
+
marginInlineStart: `calc(${thumb} / -2)`
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
});
|
|
499
|
+
function PlacedThumb({ percent, ...rest }) {
|
|
500
|
+
return /* @__PURE__ */ jsx(RangeInputThumb, {
|
|
501
|
+
place: useLiveValue(percent, "%"),
|
|
502
|
+
...rest
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
const RangeInputInput = styled("input", {
|
|
506
|
+
name: "RangeInput",
|
|
507
|
+
slot: "input",
|
|
508
|
+
label: "RangeInputInput",
|
|
509
|
+
shouldForwardProp: createShouldForwardProp(["orientation"])
|
|
510
|
+
})(({ orientation }) => ({
|
|
511
|
+
position: "absolute",
|
|
512
|
+
inset: 0,
|
|
513
|
+
width: "100%",
|
|
514
|
+
height: "100%",
|
|
515
|
+
margin: 0,
|
|
516
|
+
padding: 0,
|
|
517
|
+
opacity: 0,
|
|
518
|
+
pointerEvents: "none",
|
|
519
|
+
...orientation === "vertical" && { writingMode: "vertical-lr" }
|
|
520
|
+
}));
|
|
521
|
+
const RangeInputValueLabel = styled("span", {
|
|
522
|
+
name: "RangeInput",
|
|
523
|
+
slot: "valueLabel",
|
|
524
|
+
label: "RangeInputValueLabel",
|
|
525
|
+
shouldForwardProp: createShouldForwardProp([
|
|
526
|
+
"color",
|
|
527
|
+
"orientation",
|
|
528
|
+
"isOpen"
|
|
529
|
+
])
|
|
530
|
+
})(({ theme, color, orientation, isOpen }) => ({
|
|
531
|
+
position: "absolute",
|
|
532
|
+
pointerEvents: "none",
|
|
533
|
+
whiteSpace: "nowrap",
|
|
534
|
+
padding: `${theme.space[.25]} ${theme.space[1]}`,
|
|
535
|
+
borderRadius: theme.radii.sm,
|
|
536
|
+
fontSize: theme.fontSizes[0],
|
|
537
|
+
lineHeight: 1.4,
|
|
538
|
+
color: get(theme, `palette.${color}.contrastText`),
|
|
539
|
+
backgroundColor: get(theme, `palette.${color}.main`),
|
|
540
|
+
visibility: isOpen ? "visible" : "hidden",
|
|
541
|
+
...orientation === "vertical" ? {
|
|
542
|
+
insetInlineStart: "100%",
|
|
543
|
+
top: "50%",
|
|
544
|
+
marginInlineStart: theme.space[1],
|
|
545
|
+
transform: "translateY(-50%)"
|
|
546
|
+
} : {
|
|
547
|
+
bottom: "100%",
|
|
548
|
+
insetInlineStart: "50%",
|
|
549
|
+
marginBottom: theme.space[1],
|
|
550
|
+
transform: "translateX(-50%)",
|
|
551
|
+
"[dir=\"rtl\"] &": { transform: "translateX(50%)" }
|
|
552
|
+
}
|
|
553
|
+
}));
|
|
554
|
+
/**
|
|
555
|
+
* @description A slider: one value on a range, or two or more thumbs for a range of values.
|
|
556
|
+
* Each thumb is a visually hidden native `<input type="range">`, so the keys (the arrows, Page,
|
|
557
|
+
* Home and End), assistive technology and forms work as the platform's; the pointer drags a thumb,
|
|
558
|
+
* touch included. Marks, a value label, a vertical layout and a track drawn or not or inverted.
|
|
559
|
+
* In a `FormControl` it takes the field's size, color, error, and disabled state, and its
|
|
560
|
+
* `FormLabel` targets the first thumb.
|
|
561
|
+
*/
|
|
562
|
+
function RangeInput({ value, defaultValue, onChange, onChangeCommitted, min = 0, max = 100, step: stepProp, shiftStep: shiftStepProp, marks: marksProp, orientation: orientationProp, track: trackProp, scale = (entry) => entry, valueLabel: valueLabelProp, formatValueLabel, getAriaLabel, getAriaValueText, shouldSwapThumbs: shouldSwapProp, size: sizeProp, color: colorProp, disabled: disabledProp, error: errorProp, name, id: idProp, className, style, slotProps, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, "aria-describedby": ariaDescribedby, "data-testid": dataTestid, ...rest }) {
|
|
563
|
+
const dp = useDefaultProps("RangeInput");
|
|
564
|
+
const fc = useFormControl({
|
|
565
|
+
id: idProp,
|
|
566
|
+
error: errorProp,
|
|
567
|
+
disabled: disabledProp,
|
|
568
|
+
size: sizeProp ?? dp.size,
|
|
569
|
+
color: colorProp ?? dp.color
|
|
570
|
+
});
|
|
571
|
+
const color = fc.error ? "error" : fc.color ?? "primary";
|
|
572
|
+
const step = stepProp === void 0 ? dp.step ?? 1 : stepProp;
|
|
573
|
+
const orientation = orientationProp ?? dp.orientation ?? "horizontal";
|
|
574
|
+
const track = trackProp ?? dp.track ?? "normal";
|
|
575
|
+
const valueLabel = valueLabelProp ?? dp.valueLabel ?? "off";
|
|
576
|
+
const marks = getMarks(marksProp ?? false, step, min, max);
|
|
577
|
+
const rootRef = useRef(null);
|
|
578
|
+
const baseId = useId();
|
|
579
|
+
const range = useRangeInput({
|
|
580
|
+
value,
|
|
581
|
+
defaultValue,
|
|
582
|
+
min,
|
|
583
|
+
max,
|
|
584
|
+
step,
|
|
585
|
+
shiftStep: shiftStepProp ?? dp.shiftStep ?? 10,
|
|
586
|
+
marks,
|
|
587
|
+
orientation,
|
|
588
|
+
shouldSwapThumbs: shouldSwapProp ?? dp.shouldSwapThumbs ?? true,
|
|
589
|
+
isDisabled: fc.disabled,
|
|
590
|
+
name,
|
|
591
|
+
rootRef,
|
|
592
|
+
onChange,
|
|
593
|
+
onChangeCommitted
|
|
594
|
+
});
|
|
595
|
+
const { values } = range;
|
|
596
|
+
const thumbKeys = values.map((_, position) => `${baseId}-${position}`);
|
|
597
|
+
const trackStart = valueToPercent(range.isRange ? values[0] : min, min, max);
|
|
598
|
+
const trackEnd = valueToPercent(values.at(-1), min, max);
|
|
599
|
+
const isInverted = track === "inverted";
|
|
600
|
+
const axis = {
|
|
601
|
+
size: fc.size,
|
|
602
|
+
orientation
|
|
603
|
+
};
|
|
604
|
+
const isDragging = range.active !== -1;
|
|
605
|
+
const isMarkActive = (mark) => {
|
|
606
|
+
if (track === false) return false;
|
|
607
|
+
const covered = mark >= values[0] && mark <= values.at(-1);
|
|
608
|
+
return range.isRange || isInverted ? covered !== isInverted : mark <= values[0];
|
|
609
|
+
};
|
|
610
|
+
const trackFrom = useLiveValue(trackStart, "%");
|
|
611
|
+
const trackSpan = useLiveValue(trackEnd - trackStart, "%");
|
|
612
|
+
return /* @__PURE__ */ jsxs(RangeInputRoot, {
|
|
613
|
+
ref: rootRef,
|
|
614
|
+
isDisabled: fc.disabled,
|
|
615
|
+
...mergeOverrides(slotProps?.root, {
|
|
616
|
+
style,
|
|
617
|
+
className
|
|
618
|
+
}),
|
|
619
|
+
"data-testid": dataTestid,
|
|
620
|
+
...axis,
|
|
621
|
+
...range.rootProps,
|
|
622
|
+
...rest,
|
|
623
|
+
children: [
|
|
624
|
+
/* @__PURE__ */ jsx(RangeInputRail, {
|
|
625
|
+
color,
|
|
626
|
+
isInverted,
|
|
627
|
+
...axis,
|
|
628
|
+
...slotProps?.rail
|
|
629
|
+
}),
|
|
630
|
+
track !== false && /* @__PURE__ */ jsx(RangeInputTrack, {
|
|
631
|
+
color,
|
|
632
|
+
isInverted,
|
|
633
|
+
isDragging,
|
|
634
|
+
from: trackFrom,
|
|
635
|
+
span: trackSpan,
|
|
636
|
+
...axis,
|
|
637
|
+
...slotProps?.track
|
|
638
|
+
}),
|
|
639
|
+
marks.filter((mark) => mark.value >= min && mark.value <= max).map((mark) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(RangeInputMark, {
|
|
640
|
+
"data-mark": mark.value,
|
|
641
|
+
color,
|
|
642
|
+
isActive: isMarkActive(mark.value),
|
|
643
|
+
percent: valueToPercent(mark.value, min, max),
|
|
644
|
+
...axis,
|
|
645
|
+
...slotProps?.mark
|
|
646
|
+
}), mark.label != null && /* @__PURE__ */ jsx(RangeInputMarkLabel, {
|
|
647
|
+
"aria-hidden": true,
|
|
648
|
+
percent: valueToPercent(mark.value, min, max),
|
|
649
|
+
...axis,
|
|
650
|
+
...slotProps?.markLabel,
|
|
651
|
+
children: mark.label
|
|
652
|
+
})] }, mark.value)),
|
|
653
|
+
values.map((thumbValue, index) => {
|
|
654
|
+
const isShown = valueLabel === "on" || valueLabel === "auto" && [
|
|
655
|
+
range.active,
|
|
656
|
+
range.hovered,
|
|
657
|
+
range.focused
|
|
658
|
+
].includes(index);
|
|
659
|
+
const input = range.getInputProps(index);
|
|
660
|
+
return /* @__PURE__ */ jsxs(PlacedThumb, {
|
|
661
|
+
"data-index": index,
|
|
662
|
+
color,
|
|
663
|
+
isActive: range.active === index,
|
|
664
|
+
isPassive: range.active !== -1 && range.active !== index,
|
|
665
|
+
percent: valueToPercent(thumbValue, min, max),
|
|
666
|
+
isLastUsed: range.lastUsed === index,
|
|
667
|
+
...axis,
|
|
668
|
+
...slotProps?.thumb,
|
|
669
|
+
...range.getThumbProps(index),
|
|
670
|
+
children: [valueLabel !== "off" && /* @__PURE__ */ jsx(RangeInputValueLabel, {
|
|
671
|
+
"aria-hidden": true,
|
|
672
|
+
color,
|
|
673
|
+
orientation,
|
|
674
|
+
isOpen: isShown,
|
|
675
|
+
...slotProps?.valueLabel,
|
|
676
|
+
children: formatValueLabel ? formatValueLabel(scale(thumbValue), index) : scale(thumbValue)
|
|
677
|
+
}), /* @__PURE__ */ jsx(RangeInputInput, {
|
|
678
|
+
...slotProps?.input,
|
|
679
|
+
type: "range",
|
|
680
|
+
orientation,
|
|
681
|
+
"data-index": index,
|
|
682
|
+
id: index === 0 ? fc.id : void 0,
|
|
683
|
+
name,
|
|
684
|
+
min,
|
|
685
|
+
max,
|
|
686
|
+
step: step ?? "any",
|
|
687
|
+
value: thumbValue,
|
|
688
|
+
disabled: fc.disabled,
|
|
689
|
+
"aria-label": getAriaLabel?.(index) ?? ariaLabel,
|
|
690
|
+
"aria-labelledby": ariaLabelledby ?? fc.labelId,
|
|
691
|
+
"aria-describedby": ariaDescribedby ?? fc["aria-describedby"],
|
|
692
|
+
"aria-invalid": fc.error || void 0,
|
|
693
|
+
"aria-orientation": orientation,
|
|
694
|
+
"aria-valuemin": scale(min),
|
|
695
|
+
"aria-valuemax": scale(max),
|
|
696
|
+
"aria-valuenow": scale(thumbValue),
|
|
697
|
+
"aria-valuetext": getAriaValueText?.(scale(thumbValue), index),
|
|
698
|
+
...input
|
|
699
|
+
})]
|
|
700
|
+
}, thumbKeys[index]);
|
|
701
|
+
})
|
|
702
|
+
]
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
export { RangeInput };
|