@soroush.tech/design-system 2.0.0-rc.1 → 2.0.0-rc.3
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/README.md +30 -10
- package/dist/AppBar.d.cts +1 -3
- package/dist/AppBar.d.mts +1 -3
- package/dist/Avatar.cjs +1 -1
- package/dist/Avatar.d.cts +1 -3
- package/dist/Avatar.d.mts +1 -3
- package/dist/Avatar.mjs +1 -1
- package/dist/Backdrop.d.cts +1 -1
- package/dist/Backdrop.d.mts +1 -1
- package/dist/Breadcrumbs.cjs +132 -0
- package/dist/Breadcrumbs.d.cts +40 -0
- package/dist/Breadcrumbs.d.mts +40 -0
- package/dist/Breadcrumbs.mjs +131 -0
- package/dist/Button.cjs +1 -1
- package/dist/Button.d.cts +1 -1
- package/dist/Button.d.mts +1 -1
- package/dist/Button.mjs +1 -1
- package/dist/ButtonGroup.d.cts +1 -1
- package/dist/ButtonGroup.d.mts +1 -1
- package/dist/Card.cjs +3 -3
- package/dist/Card.d.cts +4 -3
- package/dist/Card.d.mts +4 -3
- package/dist/Card.mjs +3 -3
- package/dist/Checkbox.d.cts +1 -2
- package/dist/Checkbox.d.mts +1 -2
- package/dist/CircularProgress.d.cts +2 -3
- package/dist/CircularProgress.d.mts +2 -3
- package/dist/Drawer.d.cts +3 -2
- package/dist/Drawer.d.mts +3 -2
- package/dist/Flex.d.cts +1 -1
- package/dist/Flex.d.mts +1 -1
- package/dist/Form.d.cts +1 -1
- package/dist/Form.d.mts +1 -1
- package/dist/FormControl.cjs +10 -2
- package/dist/FormControl.d.cts +9 -2
- package/dist/FormControl.d.mts +9 -2
- package/dist/FormControl.mjs +10 -2
- package/dist/FormHelperText.d.cts +1 -1
- package/dist/FormHelperText.d.mts +1 -1
- package/dist/FormLabel.cjs +9 -1
- package/dist/FormLabel.d.cts +2 -2
- package/dist/FormLabel.d.mts +2 -2
- package/dist/FormLabel.mjs +10 -2
- package/dist/Grid.d.cts +1 -3
- package/dist/Grid.d.mts +1 -3
- package/dist/{Icon-CH3asUJu.mjs → Icon-BihOAP4u.mjs} +52 -2
- package/dist/{Icon-CI6q2Eyi.cjs → Icon-D-EWsBVg.cjs} +52 -2
- package/dist/Icon.cjs +1 -1
- package/dist/Icon.d.cts +1 -1
- package/dist/Icon.d.mts +1 -1
- package/dist/Icon.mjs +1 -1
- package/dist/Image.d.cts +1 -2
- package/dist/Image.d.mts +1 -2
- package/dist/InputRange.cjs +675 -0
- package/dist/InputRange.d.cts +79 -0
- package/dist/InputRange.d.mts +79 -0
- package/dist/InputRange.mjs +673 -0
- package/dist/LinearProgress.d.cts +2 -3
- package/dist/LinearProgress.d.mts +2 -3
- package/dist/Link.cjs +1 -1
- package/dist/Link.d.cts +1 -1
- package/dist/Link.d.mts +1 -1
- package/dist/Link.mjs +1 -1
- package/dist/Menu/ContextMenu.cjs +146 -0
- package/dist/Menu/ContextMenu.d.cts +52 -0
- package/dist/Menu/ContextMenu.d.mts +52 -0
- package/dist/Menu/ContextMenu.mjs +145 -0
- package/dist/Menu/Menu.cjs +3 -0
- package/dist/Menu/Menu.d.cts +2 -0
- package/dist/Menu/Menu.d.mts +2 -0
- package/dist/Menu/Menu.mjs +2 -0
- package/dist/Menu/MenuDivider.cjs +29 -0
- package/dist/Menu/MenuDivider.d.cts +12 -0
- package/dist/Menu/MenuDivider.d.mts +12 -0
- package/dist/Menu/MenuDivider.mjs +28 -0
- package/dist/Menu/MenuItems.cjs +29 -0
- package/dist/Menu/MenuItems.d.cts +2 -0
- package/dist/Menu/MenuItems.d.mts +2 -0
- package/dist/Menu/MenuItems.mjs +28 -0
- package/dist/Menu/MenuList.cjs +3 -0
- package/dist/Menu/MenuList.d.cts +38 -0
- package/dist/Menu/MenuList.d.mts +38 -0
- package/dist/Menu/MenuList.mjs +2 -0
- package/dist/Menu-Cgg-sX4W.cjs +173 -0
- package/dist/Menu-CrzHc_cn.mjs +168 -0
- package/dist/Menu.cjs +13 -0
- package/dist/Menu.d.cts +7 -0
- package/dist/Menu.d.mts +7 -0
- package/dist/Menu.mjs +6 -0
- package/dist/MenuItem-BTP7Ijwi.cjs +673 -0
- package/dist/MenuItem-DUn4IZKK.mjs +649 -0
- package/dist/MenuItem.cjs +2 -148
- package/dist/MenuItem.d.cts +2 -52
- package/dist/MenuItem.d.mts +2 -52
- package/dist/MenuItem.mjs +1 -147
- package/dist/MenuList-B7msJ1IG.mjs +187 -0
- package/dist/MenuList-D4imLXAa.cjs +223 -0
- package/dist/MenuListContext-DKUOhNyw.d.cts +21 -0
- package/dist/MenuListContext-x-7lH4CH.d.mts +21 -0
- package/dist/Modal.d.cts +1 -1
- package/dist/Modal.d.mts +1 -1
- package/dist/NativeSelect.cjs +9 -8
- package/dist/NativeSelect.d.cts +3 -4
- package/dist/NativeSelect.d.mts +3 -4
- package/dist/NativeSelect.mjs +9 -8
- package/dist/NumberField.cjs +476 -0
- package/dist/NumberField.d.cts +74 -0
- package/dist/NumberField.d.mts +74 -0
- package/dist/NumberField.mjs +474 -0
- package/dist/Pagination/PaginationItem.cjs +1 -1
- package/dist/Pagination/PaginationItem.d.cts +1 -1
- package/dist/Pagination/PaginationItem.d.mts +1 -1
- package/dist/Pagination/PaginationItem.mjs +1 -1
- package/dist/Pagination.d.cts +2 -2
- package/dist/Pagination.d.mts +2 -2
- package/dist/Paper.cjs +1 -1
- package/dist/Paper.d.cts +2 -1
- package/dist/Paper.d.mts +2 -1
- package/dist/Paper.mjs +1 -1
- package/dist/{Popover-TpwRSORC.cjs → Popover-CiZfgiKE.cjs} +5 -125
- package/dist/Popover-QjM5Z1CR.mjs +133 -0
- package/dist/Popover.cjs +1 -1
- package/dist/Popover.d.cts +6 -7
- package/dist/Popover.d.mts +6 -7
- package/dist/Popover.mjs +1 -1
- package/dist/Pressable.cjs +1 -1
- package/dist/Pressable.d.cts +1 -1
- package/dist/Pressable.d.mts +1 -1
- package/dist/Pressable.mjs +1 -1
- package/dist/Quote.d.cts +2 -3
- package/dist/Quote.d.mts +2 -3
- package/dist/Radio.d.cts +1 -2
- package/dist/Radio.d.mts +1 -2
- package/dist/Rating.cjs +373 -0
- package/dist/Rating.d.cts +57 -0
- package/dist/Rating.d.mts +57 -0
- package/dist/Rating.mjs +371 -0
- package/dist/Select.cjs +5 -4
- package/dist/Select.d.cts +3 -4
- package/dist/Select.d.mts +3 -4
- package/dist/Select.mjs +7 -6
- package/dist/Sidebar/Sidebar.d.cts +1 -1
- package/dist/Sidebar/Sidebar.d.mts +1 -1
- package/dist/Sidebar/SidebarItem.cjs +1 -1
- package/dist/Sidebar/SidebarItem.d.cts +3 -4
- package/dist/Sidebar/SidebarItem.d.mts +3 -4
- package/dist/Sidebar/SidebarItem.mjs +3 -3
- package/dist/Skeleton.d.cts +1 -2
- package/dist/Skeleton.d.mts +1 -2
- package/dist/Switch.cjs +23 -16
- package/dist/Switch.d.cts +2 -3
- package/dist/Switch.d.mts +2 -3
- package/dist/Switch.mjs +25 -18
- package/dist/Table/Table.d.cts +2 -3
- package/dist/Table/Table.d.mts +2 -3
- package/dist/Table/TableBody.d.cts +1 -2
- package/dist/Table/TableBody.d.mts +1 -2
- package/dist/Table/TableCell.d.cts +1 -1
- package/dist/Table/TableCell.d.mts +1 -1
- package/dist/Table/TableContainer.d.cts +1 -3
- package/dist/Table/TableContainer.d.mts +1 -3
- package/dist/Table/TableControl.d.cts +1 -1
- package/dist/Table/TableControl.d.mts +1 -1
- package/dist/Table/TableControl.mjs +2 -2
- package/dist/Table/TableFooter.d.cts +1 -2
- package/dist/Table/TableFooter.d.mts +1 -2
- package/dist/Table/TableHead.d.cts +1 -2
- package/dist/Table/TableHead.d.mts +1 -2
- package/dist/Table/TablePagination.d.cts +2 -2
- package/dist/Table/TablePagination.d.mts +2 -2
- package/dist/Table/TablePaginationActions.cjs +1 -1
- package/dist/Table/TablePaginationActions.d.cts +1 -1
- package/dist/Table/TablePaginationActions.d.mts +1 -1
- package/dist/Table/TablePaginationActions.mjs +1 -1
- package/dist/Table/TableRow.d.cts +1 -2
- package/dist/Table/TableRow.d.mts +1 -2
- package/dist/Table/TableSortLabel.cjs +1 -1
- package/dist/Table/TableSortLabel.d.cts +1 -1
- package/dist/Table/TableSortLabel.d.mts +1 -1
- package/dist/Table/TableSortLabel.mjs +1 -1
- package/dist/Table/hooks.d.cts +1 -1
- package/dist/Table/hooks.d.mts +1 -1
- package/dist/Table.d.cts +5 -5
- package/dist/Table.d.mts +5 -5
- package/dist/{TableContext-BeCxbtHH.d.cts → TableContext-DhuRf6Wy.d.mts} +1 -1
- package/dist/{TableContext-BiRiYkVZ.d.mts → TableContext-Duj1nVG7.d.cts} +1 -1
- package/dist/Tabs/Tab.cjs +306 -0
- package/dist/Tabs/Tab.d.cts +62 -0
- package/dist/Tabs/Tab.d.mts +62 -0
- package/dist/Tabs/Tab.mjs +305 -0
- package/dist/Tabs/TabContext.cjs +34 -0
- package/dist/Tabs/TabContext.d.cts +20 -0
- package/dist/Tabs/TabContext.d.mts +20 -0
- package/dist/Tabs/TabContext.mjs +33 -0
- package/dist/Tabs/TabList.cjs +31 -0
- package/dist/Tabs/TabList.d.cts +11 -0
- package/dist/Tabs/TabList.d.mts +11 -0
- package/dist/Tabs/TabList.mjs +30 -0
- package/dist/Tabs/TabPanel.cjs +40 -0
- package/dist/Tabs/TabPanel.d.cts +27 -0
- package/dist/Tabs/TabPanel.d.mts +27 -0
- package/dist/Tabs/TabPanel.mjs +38 -0
- package/dist/Tabs/TabScrollButton.cjs +93 -0
- package/dist/Tabs/TabScrollButton.d.cts +2 -0
- package/dist/Tabs/TabScrollButton.d.mts +2 -0
- package/dist/Tabs/TabScrollButton.mjs +91 -0
- package/dist/Tabs/Tabs.cjs +3 -0
- package/dist/Tabs/Tabs.d.cts +3 -0
- package/dist/Tabs/Tabs.d.mts +3 -0
- package/dist/Tabs/Tabs.mjs +2 -0
- package/dist/Tabs-BTNOJx5v.mjs +634 -0
- package/dist/Tabs-D4tWCq78.cjs +646 -0
- package/dist/Tabs.cjs +13 -0
- package/dist/Tabs.d.cts +8 -0
- package/dist/Tabs.d.mts +8 -0
- package/dist/Tabs.mjs +7 -0
- package/dist/TabsContext-B_XHbjcS.d.cts +6 -0
- package/dist/TabsContext-Dn2kqUwr.d.mts +6 -0
- package/dist/TabsValueContext-D40zGCpE.cjs +19 -0
- package/dist/TabsValueContext-DvL3inf7.mjs +8 -0
- package/dist/TextInput.cjs +4 -4
- package/dist/TextInput.d.cts +2 -3
- package/dist/TextInput.d.mts +2 -3
- package/dist/TextInput.mjs +4 -4
- package/dist/ToggleButton/ToggleButton.cjs +1 -1
- package/dist/ToggleButton/ToggleButton.d.cts +1 -1
- package/dist/ToggleButton/ToggleButton.d.mts +1 -1
- package/dist/ToggleButton/ToggleButton.mjs +1 -1
- package/dist/ToggleButton/ToggleButtonGroup.cjs +1 -1
- package/dist/ToggleButton/ToggleButtonGroup.d.cts +1 -1
- package/dist/ToggleButton/ToggleButtonGroup.d.mts +1 -1
- package/dist/ToggleButton/ToggleButtonGroup.mjs +1 -1
- package/dist/TransferList.cjs +356 -0
- package/dist/TransferList.d.cts +67 -0
- package/dist/TransferList.d.mts +67 -0
- package/dist/TransferList.mjs +354 -0
- package/dist/Typography.cjs +1 -1
- package/dist/Typography.d.cts +2 -2
- package/dist/Typography.d.mts +2 -2
- package/dist/Typography.mjs +1 -1
- package/dist/View.d.cts +1 -1
- package/dist/View.d.mts +1 -1
- package/dist/catalog.cjs +4568 -0
- package/dist/catalog.d.cts +90 -0
- package/dist/catalog.d.mts +90 -0
- package/dist/catalog.mjs +4567 -0
- package/dist/computePopoverPosition-BIprs_xo.mjs +123 -0
- package/dist/computePopoverPosition-DiyEOHnU.cjs +128 -0
- package/dist/dividerLine-BNljcGlv.cjs +66 -0
- package/dist/dividerLine-FahY-M6_.mjs +31 -0
- package/dist/engine.d.cts +1 -1
- package/dist/engine.d.mts +1 -1
- package/dist/index-B1RFybA_.d.mts +72 -0
- package/dist/index-B4TeaB7b.d.cts +72 -0
- package/dist/{index-BUoVTCqX.d.mts → index-BGbTuHP9.d.mts} +1 -2
- package/dist/{index-Celm-8iN.d.cts → index-BHKgEOZJ.d.cts} +2 -3
- package/dist/{index-Chg6pSrr.d.mts → index-BQWjh4rK.d.mts} +2 -3
- package/dist/{index-B78VkB0-.d.cts → index-BelFIizY.d.cts} +2 -3
- package/dist/index-BkzZxHVj.d.mts +35 -0
- package/dist/{index-DbEnSf2m.d.cts → index-BrgwkY6z.d.mts} +3 -4
- package/dist/{index-Wnv6jCR3.d.mts → index-Bx0-6yeX.d.mts} +1 -2
- package/dist/index-BxVTIMnB.d.cts +1 -0
- package/dist/{index-BfZuh9c2.d.mts → index-ByYxVl9O.d.mts} +2 -3
- package/dist/index-CE5JG1us.d.mts +34 -0
- package/dist/{index-BhibLnZ0.d.cts → index-CG_1uPrD.d.mts} +2 -3
- package/dist/{themes-RX2UX5gD.d.mts → index-CJhK7JND.d.mts} +265 -8
- package/dist/{index-BB-dLv5V.d.mts → index-CQfJZADG.d.cts} +3 -4
- package/dist/{index-CxUsrlg1.d.cts → index-CUz2h5xY.d.mts} +2 -3
- package/dist/{index-Bid71KeF.d.cts → index-CbFaWtjK.d.mts} +2 -2
- package/dist/{index-DdqdSOct.d.cts → index-ChXeKJCk.d.cts} +1 -2
- package/dist/index-CknoXDLQ.d.cts +35 -0
- package/dist/{index-BSqet8aO.d.cts → index-ClZyaZrR.d.mts} +2 -3
- package/dist/{index-DXvQ-JVZ.d.mts → index-DAwcmIjN.d.cts} +2 -3
- package/dist/index-DGnXJwLj.d.mts +72 -0
- package/dist/{themes-Kbk9h5cN.d.cts → index-DJ0f69wh.d.cts} +262 -5
- package/dist/index-DWjz5ZzG.d.cts +72 -0
- package/dist/{index-DNwF3DUX.d.cts → index-DYF8sRE-.d.cts} +2 -3
- package/dist/index-DaIIo5QU.d.mts +1 -0
- package/dist/{index-CrN4MSUF.d.cts → index-DchHf5cF.d.cts} +1 -1
- package/dist/{index-S-ClM6WM.d.mts → index-DtYjdBvO.d.cts} +2 -2
- package/dist/{index-Ctqajtac.d.cts → index-Dv_fk1_F.d.cts} +27 -3
- package/dist/{index-smqjMLAZ.d.mts → index-K5exjvnX.d.cts} +2 -3
- package/dist/index-KnXhlKMr.d.cts +34 -0
- package/dist/index-WHFhjfgy.d.cts +98 -0
- package/dist/{index-GpnmW6vu.d.mts → index-YKrfFC_I.d.cts} +2 -3
- package/dist/index-bpnLB_4K.d.mts +98 -0
- package/dist/{index-VOsBSWEu.d.mts → index-h4dYtVrp.d.mts} +1 -1
- package/dist/{index-DO9J-Fla.d.mts → index-ha1WjSZ5.d.mts} +27 -3
- package/dist/{index-Belxmt1X.d.cts → index-nqUA_6J_.d.cts} +1 -2
- package/dist/{index-nc4Sxiy9.d.mts → index-pTNq3iQn.d.mts} +2 -3
- package/dist/index.d.cts +1 -2
- package/dist/index.d.mts +1 -2
- package/dist/isRtl-BJDtm86G.mjs +7 -0
- package/dist/isRtl-DTkYHRPo.cjs +12 -0
- package/dist/precision-B1lhxnnO.mjs +25 -0
- package/dist/precision-B58cTPB2.cjs +48 -0
- package/dist/style.cjs +1 -1
- package/dist/style.d.cts +2 -2
- package/dist/style.d.mts +2 -2
- package/dist/style.mjs +1 -1
- package/dist/surfaceSystem-BGQBoXv_.cjs +38 -0
- package/dist/surfaceSystem-D8TbmKy3.mjs +21 -0
- package/dist/theme-BxXuXRgQ.cjs +137 -0
- package/dist/theme-Z9_QludW.mjs +102 -0
- package/dist/theme.cjs +25 -24
- package/dist/theme.d.cts +3 -3
- package/dist/theme.d.mts +3 -3
- package/dist/theme.mjs +2 -1
- package/dist/{theme-CDVxig_g.mjs → themes-L-dE7_ck.mjs} +10 -110
- package/dist/{theme-BXlAP3xf.cjs → themes-gd6tcmqS.cjs} +0 -136
- package/dist/useControlled-C666KpQ0.cjs +18 -0
- package/dist/useControlled-CBRLsO-H.mjs +13 -0
- package/dist/{useTablePagination-COTiNH_8.d.mts → useTablePagination-C-u3ru4N.d.cts} +1 -1
- package/dist/{useTablePagination-WFkaUZu8.d.cts → useTablePagination-D-39ZmQh.d.mts} +1 -1
- package/package.json +83 -2
- package/dist/Popover-DwnSLpp1.mjs +0 -253
- package/dist/index-B_dKjEDR.d.mts +0 -23
- package/dist/index-C1WqEDtQ.d.mts +0 -69
- package/dist/index-CA7HnbtH.d.cts +0 -21
- package/dist/index-CKZaErxJ.d.mts +0 -21
- package/dist/index-DBUwu65Z.d.cts +0 -69
- package/dist/index-DzQJSYIh.d.cts +0 -23
- package/dist/index-cuv3o-L7.d.mts +0 -34
- package/dist/index-nB94D7UM.d.cts +0 -34
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_src = require("./src-DU81aGy9.cjs");
|
|
3
|
+
const require_themeDefault = require("./themeDefault-Cebi08Cv.cjs");
|
|
4
|
+
const require_utils = require("./utils.cjs");
|
|
5
|
+
const require_theme = require("./theme-BxXuXRgQ.cjs");
|
|
6
|
+
const require_Icon = require("./Icon-D-EWsBVg.cjs");
|
|
7
|
+
const require_FormControlContext = require("./FormControlContext-74gvPGFk.cjs");
|
|
8
|
+
const require_FormControl = require("./FormControl.cjs");
|
|
9
|
+
const require_useControlled = require("./useControlled-C666KpQ0.cjs");
|
|
10
|
+
const require_precision = require("./precision-B58cTPB2.cjs");
|
|
11
|
+
const require_inputVariantStyles = require("./inputVariantStyles-BBkkYQtE.cjs");
|
|
12
|
+
let react = require("react");
|
|
13
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
14
|
+
let _soroush_tech_styled_system_should_forward_prop = require("@soroush.tech/styled-system/should-forward-prop");
|
|
15
|
+
//#region src/NumberField/hooks/useHoldRepeat.ts
|
|
16
|
+
/**
|
|
17
|
+
* Runs `action` at once on a press, then again and again while it is held - after a pause, so a
|
|
18
|
+
* tap is one step. `start` begins it, `stop` ends it, and it ends by itself when the component
|
|
19
|
+
* goes.
|
|
20
|
+
*/
|
|
21
|
+
function useHoldRepeat(action, { delay = 400, interval = 60 } = {}) {
|
|
22
|
+
const actionRef = (0, react.useRef)(action);
|
|
23
|
+
(0, react.useEffect)(() => {
|
|
24
|
+
actionRef.current = action;
|
|
25
|
+
});
|
|
26
|
+
const timers = (0, react.useRef)({});
|
|
27
|
+
const stop = (0, react.useCallback)(() => {
|
|
28
|
+
window.clearTimeout(timers.current.pause);
|
|
29
|
+
window.clearInterval(timers.current.repeat);
|
|
30
|
+
timers.current = {};
|
|
31
|
+
}, []);
|
|
32
|
+
const start = (0, react.useCallback)(() => {
|
|
33
|
+
stop();
|
|
34
|
+
actionRef.current();
|
|
35
|
+
timers.current.pause = window.setTimeout(() => {
|
|
36
|
+
timers.current.repeat = window.setInterval(() => actionRef.current(), interval);
|
|
37
|
+
}, delay);
|
|
38
|
+
}, [
|
|
39
|
+
stop,
|
|
40
|
+
delay,
|
|
41
|
+
interval
|
|
42
|
+
]);
|
|
43
|
+
(0, react.useEffect)(() => stop, [stop]);
|
|
44
|
+
return {
|
|
45
|
+
start,
|
|
46
|
+
stop
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/NumberField/utils/number.ts
|
|
51
|
+
/** What a number is shown as unless told otherwise: all its digits, ungrouped, so typing round-trips. */
|
|
52
|
+
const DEFAULT_FORMAT = {
|
|
53
|
+
useGrouping: false,
|
|
54
|
+
maximumFractionDigits: 20
|
|
55
|
+
};
|
|
56
|
+
/** The syntax a locale and format write a number in. */
|
|
57
|
+
function getNumberSyntax(locale, format) {
|
|
58
|
+
const probe = new Intl.NumberFormat(locale, {
|
|
59
|
+
useGrouping: false,
|
|
60
|
+
minimumFractionDigits: 1,
|
|
61
|
+
maximumFractionDigits: 1
|
|
62
|
+
});
|
|
63
|
+
const digitFormat = new Intl.NumberFormat(locale, { useGrouping: false });
|
|
64
|
+
return {
|
|
65
|
+
decimal: probe.formatToParts(1.1).find((part) => part.type === "decimal").value,
|
|
66
|
+
digits: Array.from({ length: 10 }, (_, digit) => digitFormat.format(digit)),
|
|
67
|
+
isPercent: format?.style === "percent"
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** The number as its locale and format write it. */
|
|
71
|
+
function formatNumber(value, locale, format) {
|
|
72
|
+
return new Intl.NumberFormat(locale, {
|
|
73
|
+
...DEFAULT_FORMAT,
|
|
74
|
+
...format
|
|
75
|
+
}).format(value);
|
|
76
|
+
}
|
|
77
|
+
const MINUS = new RegExp(`[${[
|
|
78
|
+
8722,
|
|
79
|
+
8210,
|
|
80
|
+
8211,
|
|
81
|
+
8212
|
|
82
|
+
].map((code) => String.fromCodePoint(code)).join("")}]`, "g");
|
|
83
|
+
/**
|
|
84
|
+
* The number a text stands for - `null` when it stands for none: its locale's digits and decimal
|
|
85
|
+
* mark, a leading minus, a percent's `%` (so `50%` is `0.5`). Group marks, spaces and symbols
|
|
86
|
+
* round it are ignored.
|
|
87
|
+
*/
|
|
88
|
+
function parseNumber(text, syntax) {
|
|
89
|
+
let normalized = text.replace(MINUS, "-");
|
|
90
|
+
syntax.digits.forEach((digit, index) => {
|
|
91
|
+
normalized = normalized.split(digit).join(String(index));
|
|
92
|
+
});
|
|
93
|
+
const isNegative = normalized.includes("-");
|
|
94
|
+
const [whole = "", ...fraction] = normalized.split(syntax.decimal);
|
|
95
|
+
const digits = (text) => text.replaceAll(/\D/g, "");
|
|
96
|
+
const wholeDigits = digits(whole);
|
|
97
|
+
const fractionDigits = fraction.map(digits).join("");
|
|
98
|
+
if (wholeDigits === "" && fractionDigits === "") return null;
|
|
99
|
+
const parsed = Number(`${wholeDigits || "0"}.${fractionDigits || "0"}`);
|
|
100
|
+
const signed = isNegative ? -parsed : parsed;
|
|
101
|
+
return syntax.isPercent ? Number((signed / 100).toFixed(require_precision.getDecimalPrecision(parsed) + 2)) : signed;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/NumberField/hooks/useNumberField.ts
|
|
105
|
+
const clampTo = (value, min, max) => require_utils.clamp(value, min ?? Number.NEGATIVE_INFINITY, max ?? Number.POSITIVE_INFINITY);
|
|
106
|
+
/**
|
|
107
|
+
* A number field's state: the number (controlled or not), the text the user is typing - which
|
|
108
|
+
* is theirs until it is committed on blur or Enter - and the steps by key and by button. A
|
|
109
|
+
* number typed is told at once; one outside the range is clamped when it is committed.
|
|
110
|
+
*/
|
|
111
|
+
function useNumberField({ value: valueProp, defaultValue, onChange, onChangeCommitted, min, max, step, smallStep, largeStep, format, locale, shouldSnapOnStep, isFrozen }) {
|
|
112
|
+
const [value, setValue] = require_useControlled.useControlled({
|
|
113
|
+
controlled: valueProp,
|
|
114
|
+
default: defaultValue ?? null
|
|
115
|
+
});
|
|
116
|
+
const [draft, setDraft] = (0, react.useState)(null);
|
|
117
|
+
const syntax = (0, react.useMemo)(() => getNumberSyntax(locale, format), [locale, format]);
|
|
118
|
+
const text = draft ?? (value === null ? "" : formatNumber(value, locale, format));
|
|
119
|
+
const update = (next) => {
|
|
120
|
+
if (next === value) return;
|
|
121
|
+
setValue(next);
|
|
122
|
+
onChange?.(next);
|
|
123
|
+
};
|
|
124
|
+
const handleChange = (event) => {
|
|
125
|
+
const typed = event.currentTarget.value;
|
|
126
|
+
setDraft(typed);
|
|
127
|
+
if (typed.trim() === "") return update(null);
|
|
128
|
+
const parsed = parseNumber(typed, syntax);
|
|
129
|
+
if (parsed !== null) update(parsed);
|
|
130
|
+
};
|
|
131
|
+
const settle = () => {
|
|
132
|
+
if (draft === null) return value;
|
|
133
|
+
if (draft.trim() === "") return null;
|
|
134
|
+
const parsed = parseNumber(draft, syntax);
|
|
135
|
+
return parsed === null ? value : clampTo(parsed, min, max);
|
|
136
|
+
};
|
|
137
|
+
const commit = (next) => {
|
|
138
|
+
setDraft(null);
|
|
139
|
+
update(next);
|
|
140
|
+
onChangeCommitted?.(next);
|
|
141
|
+
};
|
|
142
|
+
const handleBlur = () => {
|
|
143
|
+
if (draft !== null) commit(settle());
|
|
144
|
+
};
|
|
145
|
+
const stepBy = (direction, size = step) => {
|
|
146
|
+
if (isFrozen) return;
|
|
147
|
+
const base = settle() ?? 0;
|
|
148
|
+
let next = require_precision.addExact(base, direction * size);
|
|
149
|
+
if (shouldSnapOnStep) next = require_precision.snapToStep(next, step, min ?? 0);
|
|
150
|
+
commit(clampTo(next, min, max));
|
|
151
|
+
};
|
|
152
|
+
const handleKeyDown = (event) => {
|
|
153
|
+
if (isFrozen) return;
|
|
154
|
+
const { key, altKey, shiftKey } = event;
|
|
155
|
+
if (key === "Enter") return commit(settle());
|
|
156
|
+
if (key === "ArrowUp" || key === "ArrowDown") {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
let size = step;
|
|
159
|
+
if (altKey) size = smallStep;
|
|
160
|
+
if (shiftKey) size = largeStep;
|
|
161
|
+
return stepBy(key === "ArrowUp" ? 1 : -1, size);
|
|
162
|
+
}
|
|
163
|
+
const edge = key === "Home" ? min : max;
|
|
164
|
+
if ((key === "Home" || key === "End") && edge !== void 0) {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
commit(edge);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
text,
|
|
171
|
+
value,
|
|
172
|
+
canIncrement: !isFrozen && (max === void 0 || (value ?? Number.NEGATIVE_INFINITY) < max),
|
|
173
|
+
canDecrement: !isFrozen && (min === void 0 || (value ?? Number.POSITIVE_INFINITY) > min),
|
|
174
|
+
handleChange,
|
|
175
|
+
handleBlur,
|
|
176
|
+
handleKeyDown,
|
|
177
|
+
stepBy
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/NumberField/hooks/useWheelStep.ts
|
|
182
|
+
/**
|
|
183
|
+
* Steps a focused field by the mouse wheel - up for a wheel up. A native listener, since the
|
|
184
|
+
* page must not scroll as it turns, and a React one can't prevent that.
|
|
185
|
+
*/
|
|
186
|
+
function useWheelStep(ref, isEnabled, onStep) {
|
|
187
|
+
const stepRef = (0, react.useRef)(onStep);
|
|
188
|
+
(0, react.useEffect)(() => {
|
|
189
|
+
stepRef.current = onStep;
|
|
190
|
+
});
|
|
191
|
+
(0, react.useEffect)(() => {
|
|
192
|
+
const element = ref.current;
|
|
193
|
+
if (!isEnabled || !element) return void 0;
|
|
194
|
+
const handleWheel = (event) => {
|
|
195
|
+
if (element.ownerDocument.activeElement !== element) return;
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
stepRef.current(event.deltaY < 0 ? 1 : -1);
|
|
198
|
+
};
|
|
199
|
+
element.addEventListener("wheel", handleWheel, { passive: false });
|
|
200
|
+
return () => element.removeEventListener("wheel", handleWheel);
|
|
201
|
+
}, [ref, isEnabled]);
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/NumberField/NumberField.tsx
|
|
205
|
+
const widthStyles = (0, require_src.src_exports.system)({
|
|
206
|
+
width: true,
|
|
207
|
+
minWidth: true,
|
|
208
|
+
maxWidth: true
|
|
209
|
+
});
|
|
210
|
+
const frameStyle = ({ theme, color, textColor, isError, isDisabled, isFullWidth, isInField }) => {
|
|
211
|
+
const main = (0, require_src.src_exports.get)(theme, `palette.${color}.main`);
|
|
212
|
+
const border = isError ? (0, require_src.src_exports.get)(theme, "palette.error.main") : (0, require_src.src_exports.get)(theme, `palette.${color}.light`);
|
|
213
|
+
const focusBorder = isError ? (0, require_src.src_exports.get)(theme, "palette.error.main") : main;
|
|
214
|
+
return {
|
|
215
|
+
display: isFullWidth || isInField ? "flex" : "inline-flex",
|
|
216
|
+
...isFullWidth && { width: "100%" },
|
|
217
|
+
...isInField && !isFullWidth && { width: "fit-content" },
|
|
218
|
+
alignItems: "stretch",
|
|
219
|
+
transition: "border-color 0.15s ease",
|
|
220
|
+
backgroundColor: (0, require_src.src_exports.get)(theme, `background.${require_themeDefault.themeDefault(theme, "inputBg", "terminal")}`),
|
|
221
|
+
color: textColor ? (0, require_src.src_exports.get)(theme, `text.${textColor}`) : (0, require_src.src_exports.get)(theme, `palette.${color}.main`),
|
|
222
|
+
fontFamily: (0, require_src.src_exports.get)(theme, "fonts.body"),
|
|
223
|
+
lineHeight: (0, require_src.src_exports.get)(theme, "lineHeights.base"),
|
|
224
|
+
borderColor: border,
|
|
225
|
+
"&:focus-within": { borderColor: focusBorder },
|
|
226
|
+
"&:has(input:focus-visible)": {
|
|
227
|
+
outline: `2px solid ${main}`,
|
|
228
|
+
outlineOffset: "2px"
|
|
229
|
+
},
|
|
230
|
+
...isDisabled && {
|
|
231
|
+
opacity: .5,
|
|
232
|
+
cursor: "not-allowed",
|
|
233
|
+
pointerEvents: "none"
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
const NumberFieldRoot = require_src.styled("div", {
|
|
238
|
+
name: "NumberField",
|
|
239
|
+
label: "NumberField",
|
|
240
|
+
shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([
|
|
241
|
+
..._soroush_tech_styled_system_should_forward_prop.props,
|
|
242
|
+
"color",
|
|
243
|
+
"textColor",
|
|
244
|
+
"variant",
|
|
245
|
+
"isError",
|
|
246
|
+
"isDisabled",
|
|
247
|
+
"isFullWidth",
|
|
248
|
+
"isInField"
|
|
249
|
+
]),
|
|
250
|
+
systemProps: [require_src.src_exports.space, widthStyles]
|
|
251
|
+
})(require_inputVariantStyles.inputVariantStyles, frameStyle);
|
|
252
|
+
const NumberFieldInput = require_src.styled("input", {
|
|
253
|
+
name: "NumberField",
|
|
254
|
+
slot: "input",
|
|
255
|
+
label: "NumberFieldInput",
|
|
256
|
+
shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)(["sizeToken", "isCentered"])
|
|
257
|
+
})(({ theme, sizeToken, isCentered }) => {
|
|
258
|
+
const s = theme.sizes[sizeToken];
|
|
259
|
+
return {
|
|
260
|
+
flex: 1,
|
|
261
|
+
minWidth: 0,
|
|
262
|
+
width: "100%",
|
|
263
|
+
border: "none",
|
|
264
|
+
outline: "none",
|
|
265
|
+
background: "transparent",
|
|
266
|
+
color: "inherit",
|
|
267
|
+
fontFamily: "inherit",
|
|
268
|
+
lineHeight: "inherit",
|
|
269
|
+
textAlign: isCentered ? "center" : "start",
|
|
270
|
+
paddingTop: theme.space[s.paddingTop],
|
|
271
|
+
paddingBottom: theme.space[s.paddingBottom],
|
|
272
|
+
paddingLeft: theme.space[s.paddingLeft],
|
|
273
|
+
paddingRight: theme.space[s.paddingRight],
|
|
274
|
+
fontSize: theme.fontSizes[s.fontSize],
|
|
275
|
+
"&::placeholder": {
|
|
276
|
+
color: "inherit",
|
|
277
|
+
opacity: .5
|
|
278
|
+
},
|
|
279
|
+
"&:disabled": { cursor: "not-allowed" }
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
const NumberFieldSpinButtons = require_src.styled("span", {
|
|
283
|
+
name: "NumberField",
|
|
284
|
+
slot: "spinButtons",
|
|
285
|
+
label: "NumberFieldSpinButtons"
|
|
286
|
+
})(({ theme }) => ({
|
|
287
|
+
display: "flex",
|
|
288
|
+
flexDirection: "column",
|
|
289
|
+
borderInlineStart: `${theme.borderWidths.thin} solid`,
|
|
290
|
+
borderColor: "inherit"
|
|
291
|
+
}));
|
|
292
|
+
const spinStyle = ({ theme, color, isSide }) => {
|
|
293
|
+
const main = (0, require_src.src_exports.get)(theme, `palette.${color}.main`);
|
|
294
|
+
return {
|
|
295
|
+
appearance: "none",
|
|
296
|
+
display: "grid",
|
|
297
|
+
placeItems: "center",
|
|
298
|
+
flex: isSide ? "0 0 auto" : 1,
|
|
299
|
+
minWidth: isSide ? theme.space[5] : theme.icon.lg,
|
|
300
|
+
padding: 0,
|
|
301
|
+
border: "none",
|
|
302
|
+
background: "transparent",
|
|
303
|
+
color: "inherit",
|
|
304
|
+
cursor: "pointer",
|
|
305
|
+
"&:hover:not(:disabled)": { backgroundColor: `${main}1F` },
|
|
306
|
+
"&:disabled": {
|
|
307
|
+
opacity: .4,
|
|
308
|
+
cursor: "default"
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
const spinProps = (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)(["color", "isSide"]);
|
|
313
|
+
const sideDivider = (edge) => {
|
|
314
|
+
return ({ theme, isSide }) => isSide ? {
|
|
315
|
+
[edge]: `${theme.borderWidths.thin} solid`,
|
|
316
|
+
borderColor: "inherit"
|
|
317
|
+
} : {};
|
|
318
|
+
};
|
|
319
|
+
const NumberFieldIncrement = require_src.styled("button", {
|
|
320
|
+
name: "NumberField",
|
|
321
|
+
slot: "increment",
|
|
322
|
+
label: "NumberFieldIncrement",
|
|
323
|
+
shouldForwardProp: spinProps
|
|
324
|
+
})(spinStyle, sideDivider("borderInlineStart"));
|
|
325
|
+
const NumberFieldDecrement = require_src.styled("button", {
|
|
326
|
+
name: "NumberField",
|
|
327
|
+
slot: "decrement",
|
|
328
|
+
label: "NumberFieldDecrement",
|
|
329
|
+
shouldForwardProp: spinProps
|
|
330
|
+
})(spinStyle, sideDivider("borderInlineEnd"));
|
|
331
|
+
const getSpinIcon = (direction, isSide) => {
|
|
332
|
+
if (isSide) return direction === 1 ? "add" : "remove";
|
|
333
|
+
return direction === 1 ? "expand_less" : "expand_more";
|
|
334
|
+
};
|
|
335
|
+
function SpinButton({ direction, label, isSide, isDisabled, color, onStep }) {
|
|
336
|
+
const hold = useHoldRepeat(() => onStep(direction));
|
|
337
|
+
const { stop } = hold;
|
|
338
|
+
(0, react.useEffect)(() => {
|
|
339
|
+
if (isDisabled) stop();
|
|
340
|
+
}, [isDisabled, stop]);
|
|
341
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(direction === 1 ? NumberFieldIncrement : NumberFieldDecrement, {
|
|
342
|
+
type: "button",
|
|
343
|
+
tabIndex: -1,
|
|
344
|
+
"aria-label": label,
|
|
345
|
+
disabled: isDisabled,
|
|
346
|
+
color,
|
|
347
|
+
isSide,
|
|
348
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
349
|
+
onPointerDown: (event) => event.button === 0 && hold.start(),
|
|
350
|
+
onPointerUp: hold.stop,
|
|
351
|
+
onPointerLeave: hold.stop,
|
|
352
|
+
onPointerCancel: hold.stop,
|
|
353
|
+
onClick: (event) => event.detail === 0 && onStep(direction),
|
|
354
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Icon.Icon, {
|
|
355
|
+
name: getSpinIcon(direction, isSide),
|
|
356
|
+
size: "sm",
|
|
357
|
+
color: "inherit"
|
|
358
|
+
})
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* @description A field for a number: a text input - so what is typed is the user's until it is
|
|
363
|
+
* settled - that reads and writes the number in its locale, clamps it to `min`/`max`, and steps
|
|
364
|
+
* by the arrow keys, Home/End, the wheel and buttons that repeat while held. A
|
|
365
|
+
* `role="spinbutton"`, so the number and its range are announced; a hidden input carries the raw
|
|
366
|
+
* number to a form. In a `FormControl` it takes the field's size, color, error, disabled and
|
|
367
|
+
* required state, and its `FormLabel` targets the field.
|
|
368
|
+
*/
|
|
369
|
+
function NumberField({ value, defaultValue, onChange, onChangeCommitted, min, max, step: stepProp, smallStep: smallStepProp, largeStep: largeStepProp, format, locale, shouldSnapOnStep: shouldSnapProp, shouldScrubOnWheel: shouldScrubProp, spinButtons: spinButtonsProp, incrementLabel: incrementLabelProp, decrementLabel: decrementLabelProp, variant: variantProp, size: sizeProp, color: colorProp, textColor: textColorProp, error: errorProp, disabled: disabledProp, readOnly = false, required: requiredProp, fullWidth: fullWidthProp, name, id: idProp, placeholder, autoFocus, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, "aria-describedby": ariaDescribedby, "data-testid": dataTestid, ...rest }) {
|
|
370
|
+
const theme = require_theme.useTheme();
|
|
371
|
+
const dp = require_theme.useDefaultProps("NumberField");
|
|
372
|
+
const isInField = (0, react.useContext)(require_FormControlContext.FormControlContext) !== null;
|
|
373
|
+
const fc = require_FormControl.useFormControl({
|
|
374
|
+
id: idProp,
|
|
375
|
+
error: errorProp,
|
|
376
|
+
disabled: disabledProp,
|
|
377
|
+
required: requiredProp,
|
|
378
|
+
size: sizeProp ?? dp.size,
|
|
379
|
+
fullWidth: fullWidthProp,
|
|
380
|
+
color: colorProp ?? dp.color,
|
|
381
|
+
textColor: textColorProp
|
|
382
|
+
});
|
|
383
|
+
const color = fc.color ?? require_themeDefault.themeDefault(theme, "color", "primary");
|
|
384
|
+
const textColor = fc.textColor;
|
|
385
|
+
const variant = variantProp ?? dp.variant ?? require_themeDefault.themeDefault(theme, "inputVariant", "default");
|
|
386
|
+
const spinButtons = spinButtonsProp ?? dp.spinButtons ?? "stacked";
|
|
387
|
+
const step = stepProp ?? dp.step ?? 1;
|
|
388
|
+
const isFrozen = fc.disabled || readOnly;
|
|
389
|
+
const field = useNumberField({
|
|
390
|
+
value,
|
|
391
|
+
defaultValue,
|
|
392
|
+
onChange,
|
|
393
|
+
onChangeCommitted,
|
|
394
|
+
min,
|
|
395
|
+
max,
|
|
396
|
+
step,
|
|
397
|
+
smallStep: smallStepProp ?? dp.smallStep ?? .1,
|
|
398
|
+
largeStep: largeStepProp ?? dp.largeStep ?? 10,
|
|
399
|
+
format,
|
|
400
|
+
locale,
|
|
401
|
+
shouldSnapOnStep: shouldSnapProp ?? dp.shouldSnapOnStep ?? false,
|
|
402
|
+
isFrozen
|
|
403
|
+
});
|
|
404
|
+
const inputRef = (0, react.useRef)(null);
|
|
405
|
+
useWheelStep(inputRef, shouldScrubProp ?? dp.shouldScrubOnWheel ?? false, field.stepBy);
|
|
406
|
+
const isSide = spinButtons === "sides";
|
|
407
|
+
const buttonProps = {
|
|
408
|
+
isSide,
|
|
409
|
+
color,
|
|
410
|
+
onStep: field.stepBy
|
|
411
|
+
};
|
|
412
|
+
const decrement = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SpinButton, {
|
|
413
|
+
direction: -1,
|
|
414
|
+
label: decrementLabelProp ?? dp.decrementLabel,
|
|
415
|
+
isDisabled: !field.canDecrement,
|
|
416
|
+
...buttonProps
|
|
417
|
+
});
|
|
418
|
+
const increment = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SpinButton, {
|
|
419
|
+
direction: 1,
|
|
420
|
+
label: incrementLabelProp ?? dp.incrementLabel,
|
|
421
|
+
isDisabled: !field.canIncrement,
|
|
422
|
+
...buttonProps
|
|
423
|
+
});
|
|
424
|
+
const inputMode = (min ?? -1) >= 0 && Number.isInteger(step) ? "numeric" : "decimal";
|
|
425
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(NumberFieldRoot, {
|
|
426
|
+
color,
|
|
427
|
+
textColor,
|
|
428
|
+
variant,
|
|
429
|
+
isError: fc.error,
|
|
430
|
+
isDisabled: fc.disabled,
|
|
431
|
+
isFullWidth: fc.fullWidth,
|
|
432
|
+
isInField,
|
|
433
|
+
className,
|
|
434
|
+
"data-testid": dataTestid,
|
|
435
|
+
...rest,
|
|
436
|
+
children: [
|
|
437
|
+
isSide && decrement,
|
|
438
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(NumberFieldInput, {
|
|
439
|
+
ref: inputRef,
|
|
440
|
+
type: "text",
|
|
441
|
+
role: "spinbutton",
|
|
442
|
+
inputMode,
|
|
443
|
+
autoComplete: "off",
|
|
444
|
+
id: fc.id,
|
|
445
|
+
value: field.text,
|
|
446
|
+
placeholder,
|
|
447
|
+
autoFocus,
|
|
448
|
+
disabled: fc.disabled,
|
|
449
|
+
readOnly,
|
|
450
|
+
required: fc.required,
|
|
451
|
+
sizeToken: fc.size,
|
|
452
|
+
isCentered: isSide,
|
|
453
|
+
"aria-valuenow": field.value ?? void 0,
|
|
454
|
+
"aria-valuemin": min,
|
|
455
|
+
"aria-valuemax": max,
|
|
456
|
+
"aria-label": ariaLabel,
|
|
457
|
+
"aria-labelledby": ariaLabelledby,
|
|
458
|
+
"aria-describedby": ariaDescribedby ?? fc["aria-describedby"],
|
|
459
|
+
"aria-invalid": fc.error || void 0,
|
|
460
|
+
onChange: field.handleChange,
|
|
461
|
+
onBlur: field.handleBlur,
|
|
462
|
+
onKeyDown: field.handleKeyDown
|
|
463
|
+
}),
|
|
464
|
+
name !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
465
|
+
type: "hidden",
|
|
466
|
+
name,
|
|
467
|
+
value: field.value ?? "",
|
|
468
|
+
disabled: fc.disabled
|
|
469
|
+
}),
|
|
470
|
+
spinButtons === "stacked" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(NumberFieldSpinButtons, { children: [increment, decrement] }),
|
|
471
|
+
isSide && increment
|
|
472
|
+
]
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
//#endregion
|
|
476
|
+
exports.NumberField = NumberField;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { W as Theme } from "./index-DJ0f69wh.cjs";
|
|
2
|
+
import { LayoutProps, SpaceProps } from "@soroush.tech/styled-system";
|
|
3
|
+
//#region src/NumberField/NumberField.d.ts
|
|
4
|
+
type NumberFieldVariant = 'default' | 'outlined' | 'text' | 'underline';
|
|
5
|
+
type NumberFieldSpinButtons = 'stacked' | 'sides' | 'none';
|
|
6
|
+
interface NumberFieldProps extends SpaceProps<Theme>, Pick<LayoutProps<Theme>, 'width' | 'minWidth' | 'maxWidth'> {
|
|
7
|
+
/** The number - `null` for none. Controlled with `onChange`. */
|
|
8
|
+
value?: number | null;
|
|
9
|
+
/** The number at first, when uncontrolled. */
|
|
10
|
+
defaultValue?: number | null;
|
|
11
|
+
/** Fired as the number changes - as it is typed, stepped or cleared. */
|
|
12
|
+
onChange?: (value: number | null) => void;
|
|
13
|
+
/** Fired when the number is settled: on blur, Enter, a step or Home/End. */
|
|
14
|
+
onChangeCommitted?: (value: number | null) => void;
|
|
15
|
+
/** The least number - what is typed or stepped is clamped to it. */
|
|
16
|
+
min?: number;
|
|
17
|
+
/** The greatest number. */
|
|
18
|
+
max?: number;
|
|
19
|
+
/** What the arrow keys and the buttons step by. Default: `1`. */
|
|
20
|
+
step?: number;
|
|
21
|
+
/** The step with Alt held. Default: `0.1`. */
|
|
22
|
+
smallStep?: number;
|
|
23
|
+
/** The step with Shift held. Default: `10`. */
|
|
24
|
+
largeStep?: number;
|
|
25
|
+
/** How the number is shown - `Intl.NumberFormat` options. Default: every digit, ungrouped. */
|
|
26
|
+
format?: Intl.NumberFormatOptions;
|
|
27
|
+
/** How the number is written and read. Default: the document's. */
|
|
28
|
+
locale?: string;
|
|
29
|
+
/** A step lands on the grid of `step`, counted from `min` (or 0). Default: `false`. */
|
|
30
|
+
shouldSnapOnStep?: boolean;
|
|
31
|
+
/** The mouse wheel steps the number while the field is focused. Default: `false`. */
|
|
32
|
+
shouldScrubOnWheel?: boolean;
|
|
33
|
+
/** Where the step buttons are: stacked at the end, either side of the field, or none. Default: `'stacked'`. */
|
|
34
|
+
spinButtons?: NumberFieldSpinButtons;
|
|
35
|
+
/** Names the increase button - no built-in text; a theme gives it through `defaultProps`. */
|
|
36
|
+
incrementLabel?: string;
|
|
37
|
+
/** Names the decrease button. */
|
|
38
|
+
decrementLabel?: string;
|
|
39
|
+
/** The frame: a box, an outline, an underline or none. Default: `theme.defaults.inputVariant`. */
|
|
40
|
+
variant?: NumberFieldVariant;
|
|
41
|
+
/** Resolves against `theme.sizes`. Default: its `FormControl`'s, else `'md'`. */
|
|
42
|
+
size?: keyof Theme['sizes'];
|
|
43
|
+
/** The focus border color - resolves to `theme.palette`. Default: `'primary'`. */
|
|
44
|
+
color?: keyof Theme['palette'];
|
|
45
|
+
/** The number's color - resolves against `theme.text`. Default: `'primary'`. */
|
|
46
|
+
textColor?: keyof Theme['text'];
|
|
47
|
+
error?: boolean;
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
readOnly?: boolean;
|
|
50
|
+
required?: boolean;
|
|
51
|
+
fullWidth?: boolean;
|
|
52
|
+
/** What a form submits the number as. */
|
|
53
|
+
name?: string;
|
|
54
|
+
/** On the field, which a `FormLabel` targets. Default: its `FormControl`'s. */
|
|
55
|
+
id?: string;
|
|
56
|
+
placeholder?: string;
|
|
57
|
+
autoFocus?: boolean;
|
|
58
|
+
className?: string;
|
|
59
|
+
'aria-label'?: string;
|
|
60
|
+
'aria-labelledby'?: string;
|
|
61
|
+
'aria-describedby'?: string;
|
|
62
|
+
'data-testid'?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @description A field for a number: a text input - so what is typed is the user's until it is
|
|
66
|
+
* settled - that reads and writes the number in its locale, clamps it to `min`/`max`, and steps
|
|
67
|
+
* by the arrow keys, Home/End, the wheel and buttons that repeat while held. A
|
|
68
|
+
* `role="spinbutton"`, so the number and its range are announced; a hidden input carries the raw
|
|
69
|
+
* number to a form. In a `FormControl` it takes the field's size, color, error, disabled and
|
|
70
|
+
* required state, and its `FormLabel` targets the field.
|
|
71
|
+
*/
|
|
72
|
+
declare function NumberField({ value, defaultValue, onChange, onChangeCommitted, min, max, step: stepProp, smallStep: smallStepProp, largeStep: largeStepProp, format, locale, shouldSnapOnStep: shouldSnapProp, shouldScrubOnWheel: shouldScrubProp, spinButtons: spinButtonsProp, incrementLabel: incrementLabelProp, decrementLabel: decrementLabelProp, variant: variantProp, size: sizeProp, color: colorProp, textColor: textColorProp, error: errorProp, disabled: disabledProp, readOnly, required: requiredProp, fullWidth: fullWidthProp, name, id: idProp, placeholder, autoFocus, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, 'data-testid': dataTestid, ...rest }: Readonly<NumberFieldProps>): import("react").JSX.Element;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { NumberField, NumberFieldProps, NumberFieldSpinButtons, NumberFieldVariant };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { W as Theme } from "./index-CJhK7JND.mjs";
|
|
2
|
+
import { LayoutProps, SpaceProps } from "@soroush.tech/styled-system";
|
|
3
|
+
//#region src/NumberField/NumberField.d.ts
|
|
4
|
+
type NumberFieldVariant = 'default' | 'outlined' | 'text' | 'underline';
|
|
5
|
+
type NumberFieldSpinButtons = 'stacked' | 'sides' | 'none';
|
|
6
|
+
interface NumberFieldProps extends SpaceProps<Theme>, Pick<LayoutProps<Theme>, 'width' | 'minWidth' | 'maxWidth'> {
|
|
7
|
+
/** The number - `null` for none. Controlled with `onChange`. */
|
|
8
|
+
value?: number | null;
|
|
9
|
+
/** The number at first, when uncontrolled. */
|
|
10
|
+
defaultValue?: number | null;
|
|
11
|
+
/** Fired as the number changes - as it is typed, stepped or cleared. */
|
|
12
|
+
onChange?: (value: number | null) => void;
|
|
13
|
+
/** Fired when the number is settled: on blur, Enter, a step or Home/End. */
|
|
14
|
+
onChangeCommitted?: (value: number | null) => void;
|
|
15
|
+
/** The least number - what is typed or stepped is clamped to it. */
|
|
16
|
+
min?: number;
|
|
17
|
+
/** The greatest number. */
|
|
18
|
+
max?: number;
|
|
19
|
+
/** What the arrow keys and the buttons step by. Default: `1`. */
|
|
20
|
+
step?: number;
|
|
21
|
+
/** The step with Alt held. Default: `0.1`. */
|
|
22
|
+
smallStep?: number;
|
|
23
|
+
/** The step with Shift held. Default: `10`. */
|
|
24
|
+
largeStep?: number;
|
|
25
|
+
/** How the number is shown - `Intl.NumberFormat` options. Default: every digit, ungrouped. */
|
|
26
|
+
format?: Intl.NumberFormatOptions;
|
|
27
|
+
/** How the number is written and read. Default: the document's. */
|
|
28
|
+
locale?: string;
|
|
29
|
+
/** A step lands on the grid of `step`, counted from `min` (or 0). Default: `false`. */
|
|
30
|
+
shouldSnapOnStep?: boolean;
|
|
31
|
+
/** The mouse wheel steps the number while the field is focused. Default: `false`. */
|
|
32
|
+
shouldScrubOnWheel?: boolean;
|
|
33
|
+
/** Where the step buttons are: stacked at the end, either side of the field, or none. Default: `'stacked'`. */
|
|
34
|
+
spinButtons?: NumberFieldSpinButtons;
|
|
35
|
+
/** Names the increase button - no built-in text; a theme gives it through `defaultProps`. */
|
|
36
|
+
incrementLabel?: string;
|
|
37
|
+
/** Names the decrease button. */
|
|
38
|
+
decrementLabel?: string;
|
|
39
|
+
/** The frame: a box, an outline, an underline or none. Default: `theme.defaults.inputVariant`. */
|
|
40
|
+
variant?: NumberFieldVariant;
|
|
41
|
+
/** Resolves against `theme.sizes`. Default: its `FormControl`'s, else `'md'`. */
|
|
42
|
+
size?: keyof Theme['sizes'];
|
|
43
|
+
/** The focus border color - resolves to `theme.palette`. Default: `'primary'`. */
|
|
44
|
+
color?: keyof Theme['palette'];
|
|
45
|
+
/** The number's color - resolves against `theme.text`. Default: `'primary'`. */
|
|
46
|
+
textColor?: keyof Theme['text'];
|
|
47
|
+
error?: boolean;
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
readOnly?: boolean;
|
|
50
|
+
required?: boolean;
|
|
51
|
+
fullWidth?: boolean;
|
|
52
|
+
/** What a form submits the number as. */
|
|
53
|
+
name?: string;
|
|
54
|
+
/** On the field, which a `FormLabel` targets. Default: its `FormControl`'s. */
|
|
55
|
+
id?: string;
|
|
56
|
+
placeholder?: string;
|
|
57
|
+
autoFocus?: boolean;
|
|
58
|
+
className?: string;
|
|
59
|
+
'aria-label'?: string;
|
|
60
|
+
'aria-labelledby'?: string;
|
|
61
|
+
'aria-describedby'?: string;
|
|
62
|
+
'data-testid'?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @description A field for a number: a text input - so what is typed is the user's until it is
|
|
66
|
+
* settled - that reads and writes the number in its locale, clamps it to `min`/`max`, and steps
|
|
67
|
+
* by the arrow keys, Home/End, the wheel and buttons that repeat while held. A
|
|
68
|
+
* `role="spinbutton"`, so the number and its range are announced; a hidden input carries the raw
|
|
69
|
+
* number to a form. In a `FormControl` it takes the field's size, color, error, disabled and
|
|
70
|
+
* required state, and its `FormLabel` targets the field.
|
|
71
|
+
*/
|
|
72
|
+
declare function NumberField({ value, defaultValue, onChange, onChangeCommitted, min, max, step: stepProp, smallStep: smallStepProp, largeStep: largeStepProp, format, locale, shouldSnapOnStep: shouldSnapProp, shouldScrubOnWheel: shouldScrubProp, spinButtons: spinButtonsProp, incrementLabel: incrementLabelProp, decrementLabel: decrementLabelProp, variant: variantProp, size: sizeProp, color: colorProp, textColor: textColorProp, error: errorProp, disabled: disabledProp, readOnly, required: requiredProp, fullWidth: fullWidthProp, name, id: idProp, placeholder, autoFocus, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, 'data-testid': dataTestid, ...rest }: Readonly<NumberFieldProps>): import("react").JSX.Element;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { NumberField, NumberFieldProps, NumberFieldSpinButtons, NumberFieldVariant };
|