@fluentui/react-spinbutton 0.0.0-nightly-20230317-1454.1 → 0.0.0-nightly-20230321-0440.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/CHANGELOG.json +17 -17
- package/CHANGELOG.md +11 -11
- package/lib/SpinButton.js +1 -1
- package/lib/SpinButton.js.map +1 -1
- package/lib/SpinButtonField.js +1 -1
- package/lib/SpinButtonField.js.map +1 -1
- package/lib/components/SpinButton/SpinButton.js +6 -6
- package/lib/components/SpinButton/SpinButton.js.map +1 -1
- package/lib/components/SpinButton/SpinButton.types.js +1 -1
- package/lib/components/SpinButton/SpinButton.types.js.map +1 -1
- package/lib/components/SpinButton/index.js +5 -5
- package/lib/components/SpinButton/index.js.map +1 -1
- package/lib/components/SpinButton/renderSpinButton.js +11 -3
- package/lib/components/SpinButton/renderSpinButton.js.map +1 -1
- package/lib/components/SpinButton/useSpinButton.js +57 -56
- package/lib/components/SpinButton/useSpinButton.js.map +1 -1
- package/lib/components/SpinButton/useSpinButtonStyles.js +14 -14
- package/lib/components/SpinButton/useSpinButtonStyles.js.map +1 -1
- package/lib/components/SpinButtonField/SpinButtonField.js +3 -2
- package/lib/components/SpinButtonField/SpinButtonField.js.map +1 -1
- package/lib/components/SpinButtonField/index.js +1 -1
- package/lib/components/SpinButtonField/index.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/utils/clamp.js +1 -1
- package/lib/utils/clamp.js.map +1 -1
- package/lib/utils/getBound.js +4 -4
- package/lib/utils/getBound.js.map +1 -1
- package/lib/utils/index.js +3 -3
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/precision.js +7 -6
- package/lib/utils/precision.js.map +1 -1
- package/lib-commonjs/SpinButton.js +4 -5
- package/lib-commonjs/SpinButton.js.map +1 -1
- package/lib-commonjs/SpinButtonField.js +4 -5
- package/lib-commonjs/SpinButtonField.js.map +1 -1
- package/lib-commonjs/components/SpinButton/SpinButton.js +20 -19
- package/lib-commonjs/components/SpinButton/SpinButton.js.map +1 -1
- package/lib-commonjs/components/SpinButton/SpinButton.types.js +2 -5
- package/lib-commonjs/components/SpinButton/SpinButton.types.js.map +1 -1
- package/lib-commonjs/components/SpinButton/index.js +8 -9
- package/lib-commonjs/components/SpinButton/index.js.map +1 -1
- package/lib-commonjs/components/SpinButton/renderSpinButton.js +24 -13
- package/lib-commonjs/components/SpinButton/renderSpinButton.js.map +1 -1
- package/lib-commonjs/components/SpinButton/useSpinButton.js +259 -246
- package/lib-commonjs/components/SpinButton/useSpinButton.js.map +1 -1
- package/lib-commonjs/components/SpinButton/useSpinButtonStyles.js +246 -506
- package/lib-commonjs/components/SpinButton/useSpinButtonStyles.js.map +1 -1
- package/lib-commonjs/components/SpinButtonField/SpinButtonField.js +11 -17
- package/lib-commonjs/components/SpinButtonField/SpinButtonField.js.map +1 -1
- package/lib-commonjs/components/SpinButtonField/index.js +4 -5
- package/lib-commonjs/components/SpinButtonField/index.js.map +1 -1
- package/lib-commonjs/index.js +49 -21
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/clamp.js +21 -28
- package/lib-commonjs/utils/clamp.js.map +1 -1
- package/lib-commonjs/utils/getBound.js +14 -16
- package/lib-commonjs/utils/getBound.js.map +1 -1
- package/lib-commonjs/utils/index.js +6 -7
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/precision.js +33 -33
- package/lib-commonjs/utils/precision.js.map +1 -1
- package/package.json +12 -11
- package/.swcrc +0 -39
package/CHANGELOG.json
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
"name": "@fluentui/react-spinbutton",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
6
|
-
"tag": "@fluentui/react-spinbutton_v0.0.0-nightly-
|
7
|
-
"version": "0.0.0-nightly-
|
5
|
+
"date": "Tue, 21 Mar 2023 04:49:43 GMT",
|
6
|
+
"tag": "@fluentui/react-spinbutton_v0.0.0-nightly-20230321-0440.1",
|
7
|
+
"version": "0.0.0-nightly-20230321-0440.1",
|
8
8
|
"comments": {
|
9
9
|
"prerelease": [
|
10
10
|
{
|
@@ -16,44 +16,44 @@
|
|
16
16
|
{
|
17
17
|
"author": "beachball",
|
18
18
|
"package": "@fluentui/react-spinbutton",
|
19
|
-
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly-
|
20
|
-
"commit": "
|
19
|
+
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly-20230321-0440.1",
|
20
|
+
"commit": "e913db5700c77cb74564f4422c775d52ef302e91"
|
21
21
|
},
|
22
22
|
{
|
23
23
|
"author": "beachball",
|
24
24
|
"package": "@fluentui/react-spinbutton",
|
25
|
-
"comment": "Bump @fluentui/react-field to v0.0.0-nightly-
|
26
|
-
"commit": "
|
25
|
+
"comment": "Bump @fluentui/react-field to v0.0.0-nightly-20230321-0440.1",
|
26
|
+
"commit": "e913db5700c77cb74564f4422c775d52ef302e91"
|
27
27
|
},
|
28
28
|
{
|
29
29
|
"author": "beachball",
|
30
30
|
"package": "@fluentui/react-spinbutton",
|
31
|
-
"comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-
|
32
|
-
"commit": "
|
31
|
+
"comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230321-0440.1",
|
32
|
+
"commit": "e913db5700c77cb74564f4422c775d52ef302e91"
|
33
33
|
},
|
34
34
|
{
|
35
35
|
"author": "beachball",
|
36
36
|
"package": "@fluentui/react-spinbutton",
|
37
|
-
"comment": "Bump @fluentui/react-theme to v0.0.0-nightly-
|
38
|
-
"commit": "
|
37
|
+
"comment": "Bump @fluentui/react-theme to v0.0.0-nightly-20230321-0440.1",
|
38
|
+
"commit": "e913db5700c77cb74564f4422c775d52ef302e91"
|
39
39
|
},
|
40
40
|
{
|
41
41
|
"author": "beachball",
|
42
42
|
"package": "@fluentui/react-spinbutton",
|
43
|
-
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-
|
44
|
-
"commit": "
|
43
|
+
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230321-0440.1",
|
44
|
+
"commit": "e913db5700c77cb74564f4422c775d52ef302e91"
|
45
45
|
},
|
46
46
|
{
|
47
47
|
"author": "beachball",
|
48
48
|
"package": "@fluentui/react-spinbutton",
|
49
|
-
"comment": "Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-
|
50
|
-
"commit": "
|
49
|
+
"comment": "Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230321-0440.1",
|
50
|
+
"commit": "e913db5700c77cb74564f4422c775d52ef302e91"
|
51
51
|
},
|
52
52
|
{
|
53
53
|
"author": "beachball",
|
54
54
|
"package": "@fluentui/react-spinbutton",
|
55
|
-
"comment": "Bump @fluentui/react-label to v0.0.0-nightly-
|
56
|
-
"commit": "
|
55
|
+
"comment": "Bump @fluentui/react-label to v0.0.0-nightly-20230321-0440.1",
|
56
|
+
"commit": "e913db5700c77cb74564f4422c775d52ef302e91"
|
57
57
|
}
|
58
58
|
]
|
59
59
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# Change Log - @fluentui/react-spinbutton
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Tue, 21 Mar 2023 04:49:43 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
-
## [0.0.0-nightly-
|
7
|
+
## [0.0.0-nightly-20230321-0440.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-spinbutton_v0.0.0-nightly-20230321-0440.1)
|
8
8
|
|
9
|
-
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-spinbutton_v9.2.4..@fluentui/react-spinbutton_v0.0.0-nightly-
|
9
|
+
Tue, 21 Mar 2023 04:49:43 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-spinbutton_v9.2.4..@fluentui/react-spinbutton_v0.0.0-nightly-20230321-0440.1)
|
11
11
|
|
12
12
|
### Changes
|
13
13
|
|
14
14
|
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
|
15
|
-
- Bump @fluentui/keyboard-keys to v0.0.0-nightly-
|
16
|
-
- Bump @fluentui/react-field to v0.0.0-nightly-
|
17
|
-
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-
|
18
|
-
- Bump @fluentui/react-theme to v0.0.0-nightly-
|
19
|
-
- Bump @fluentui/react-utilities to v0.0.0-nightly-
|
20
|
-
- Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-
|
21
|
-
- Bump @fluentui/react-label to v0.0.0-nightly-
|
15
|
+
- Bump @fluentui/keyboard-keys to v0.0.0-nightly-20230321-0440.1 ([commit](https://github.com/microsoft/fluentui/commit/e913db5700c77cb74564f4422c775d52ef302e91) by beachball)
|
16
|
+
- Bump @fluentui/react-field to v0.0.0-nightly-20230321-0440.1 ([commit](https://github.com/microsoft/fluentui/commit/e913db5700c77cb74564f4422c775d52ef302e91) by beachball)
|
17
|
+
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230321-0440.1 ([commit](https://github.com/microsoft/fluentui/commit/e913db5700c77cb74564f4422c775d52ef302e91) by beachball)
|
18
|
+
- Bump @fluentui/react-theme to v0.0.0-nightly-20230321-0440.1 ([commit](https://github.com/microsoft/fluentui/commit/e913db5700c77cb74564f4422c775d52ef302e91) by beachball)
|
19
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightly-20230321-0440.1 ([commit](https://github.com/microsoft/fluentui/commit/e913db5700c77cb74564f4422c775d52ef302e91) by beachball)
|
20
|
+
- Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230321-0440.1 ([commit](https://github.com/microsoft/fluentui/commit/e913db5700c77cb74564f4422c775d52ef302e91) by beachball)
|
21
|
+
- Bump @fluentui/react-label to v0.0.0-nightly-20230321-0440.1 ([commit](https://github.com/microsoft/fluentui/commit/e913db5700c77cb74564f4422c775d52ef302e91) by beachball)
|
22
22
|
|
23
23
|
## [9.2.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-spinbutton_v9.2.4)
|
24
24
|
|
package/lib/SpinButton.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from
|
1
|
+
export * from './components/SpinButton/index';
|
2
2
|
//# sourceMappingURL=SpinButton.js.map
|
package/lib/SpinButton.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"file":"SpinButton.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-spinbutton/src/SpinButton.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC","sourcesContent":["export * from './components/SpinButton/index';\n"]}
|
package/lib/SpinButtonField.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from
|
1
|
+
export * from './components/SpinButtonField/index';
|
2
2
|
//# sourceMappingURL=SpinButtonField.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"file":"SpinButtonField.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-spinbutton/src/SpinButtonField.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC","sourcesContent":["export * from './components/SpinButtonField/index';\n"]}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import * as React from
|
2
|
-
import { useSpinButton_unstable } from
|
3
|
-
import { renderSpinButton_unstable } from
|
4
|
-
import { useSpinButtonStyles_unstable } from
|
5
|
-
import { useCustomStyleHooks_unstable } from
|
1
|
+
import * as React from 'react';
|
2
|
+
import { useSpinButton_unstable } from './useSpinButton';
|
3
|
+
import { renderSpinButton_unstable } from './renderSpinButton';
|
4
|
+
import { useSpinButtonStyles_unstable } from './useSpinButtonStyles';
|
5
|
+
import { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';
|
6
6
|
/**
|
7
7
|
* A SpinButton allows someone to incrementally adjust a value in small steps.
|
8
8
|
*/
|
@@ -15,5 +15,5 @@ export const SpinButton = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
15
15
|
useCustomStyles(state);
|
16
16
|
return renderSpinButton_unstable(state);
|
17
17
|
});
|
18
|
-
SpinButton.displayName =
|
18
|
+
SpinButton.displayName = 'SpinButton';
|
19
19
|
//# sourceMappingURL=SpinButton.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","useSpinButton_unstable","renderSpinButton_unstable","useSpinButtonStyles_unstable","useCustomStyleHooks_unstable","SpinButton","forwardRef","props","ref","state","useCustomStyles","displayName"],"sources":["
|
1
|
+
{"version":3,"names":["React","useSpinButton_unstable","renderSpinButton_unstable","useSpinButtonStyles_unstable","useCustomStyleHooks_unstable","SpinButton","forwardRef","props","ref","state","useCustomStyles","displayName"],"sources":["../../../../../../../../../packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useSpinButton_unstable } from './useSpinButton';\nimport { renderSpinButton_unstable } from './renderSpinButton';\nimport { useSpinButtonStyles_unstable } from './useSpinButtonStyles';\nimport type { SpinButtonProps } from './SpinButton.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\nimport { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';\n\n/**\n * A SpinButton allows someone to incrementally adjust a value in small steps.\n */\nexport const SpinButton: ForwardRefComponent<SpinButtonProps> = React.forwardRef((props, ref) => {\n const state = useSpinButton_unstable(props, ref);\n\n useSpinButtonStyles_unstable(state);\n\n const { useSpinButtonStyles_unstable: useCustomStyles } = useCustomStyleHooks_unstable();\n useCustomStyles(state);\n\n return renderSpinButton_unstable(state);\n});\n\nSpinButton.displayName = 'SpinButton';\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,sBAAsB,QAAQ,iBAAiB;AACxD,SAASC,yBAAyB,QAAQ,oBAAoB;AAC9D,SAASC,4BAA4B,QAAQ,uBAAuB;AAGpE,SAASC,4BAA4B,QAAQ,iCAAiC;AAE9E;;;AAGA,OAAO,MAAMC,UAAU,gBAAyCL,KAAK,CAACM,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAI;EAC9F,MAAMC,KAAK,GAAGR,sBAAsB,CAACM,KAAK,EAAEC,GAAG,CAAC;EAEhDL,4BAA4B,CAACM,KAAK,CAAC;EAEnC,MAAM;IAAEN,4BAA4B,EAAEO;EAAe,CAAE,GAAGN,4BAA4B,EAAE;EACxFM,eAAe,CAACD,KAAK,CAAC;EAEtB,OAAOP,yBAAyB,CAACO,KAAK,CAAC;AACzC,CAAC,CAAC;AAEFJ,UAAU,CAACM,WAAW,GAAG,YAAY"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
export {};
|
2
2
|
//# sourceMappingURL=SpinButton.types.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"file":"SpinButton.types.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nexport type SpinButtonSlots = {\n /**\n * The root element of SpinButton is a container `<div>`.\n * The root slot receives the `className` and `style` specified on the `<SpinButton>`.\n * All other native props are applied to the primary slot: `input`.\n */\n root: NonNullable<Slot<'span'>>;\n\n /**\n * Input that displays the current value and accepts direct input from the user.\n * Displayed value is formatted.\n *\n * This is the primary slot.\n */\n input: NonNullable<Slot<'input'>>;\n\n /**\n * Renders the increment control.\n */\n incrementButton: NonNullable<Slot<'button'>>;\n\n /**\n * Renders the decrement control.\n */\n decrementButton: NonNullable<Slot<'button'>>;\n};\n\n/**\n * SpinButton Props\n */\nexport type SpinButtonProps = Omit<\n ComponentProps<Partial<SpinButtonSlots>, 'input'>,\n 'defaultValue' | 'onChange' | 'size' | 'value'\n> & {\n /**\n * Controls the colors and borders of the input.\n * @default 'outline'\n */\n appearance?: 'outline' | 'underline' | 'filled-darker' | 'filled-lighter';\n\n /**\n * Initial value of the control (assumed to be valid). Updates to this prop will not be respected.\n *\n * Use this if you intend for the SpinButton to be an uncontrolled component which maintains its\n * own value. For a controlled component, use `value` instead. (Mutually exclusive with `value`.)\n *\n * Use `null` to indicate the control has no value.\n */\n defaultValue?: number | null;\n\n /**\n * String representation of `value`.\n *\n * Use this when displaying the value to users as something other than a plain number.\n * For example, when displaying currency values this might be \"$1.00\" when value is `1`.\n *\n * Only provide this if the SpinButton is a controlled component where you are maintaining its\n * current state and passing updates based on change events. When SpinButton is used as an\n * uncontrolled component this prop is ignored.\n */\n displayValue?: string;\n\n /**\n * Max value of the control. If not provided, the control has no maximum value.\n */\n max?: number;\n\n /**\n * Min value of the control. If not provided, the control has no minimum value.\n */\n min?: number;\n\n /**\n * Callback for when the committed value changes.\n * - User presses the up/down buttons (on single press or every spin)\n * - User presses the up/down arrow keys (on single press or every spin)\n * - User *commits* edits to the input text by focusing away (blurring) or pressing enter.\n * Note that this is NOT called for every key press while the user is editing.\n */\n onChange?: (event: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => void;\n\n /**\n * How many decimal places the value should be rounded to.\n *\n * The default is calculated based on the precision of `step`: i.e. if step = 1, precision = 0.\n * step = 0.0089, precision = 4. step = 300, precision = 2. step = 23.00, precision = 2.\n */\n precision?: number;\n\n /**\n * Size of the input.\n * @default 'medium'\n */\n size?: 'small' | 'medium';\n\n /**\n * Difference between two adjacent values of the control.\n * This value is used to calculate the precision of the input if no `precision` is given.\n * The precision calculated this way will always be greater than or equal 0.\n * @default 1\n */\n step?: number;\n\n /**\n * Large difference between two values. This should be greater than `step` and is used\n * when users hit the Page Up or Page Down keys.\n * @default 1\n */\n stepPage?: number;\n\n /**\n * Current value of the control (assumed to be valid).\n *\n * Only provide this if the SpinButton is a controlled component where you are maintaining its\n * current state and passing updates based on change events; otherwise, use the `defaultValue`\n * property.\n *\n * Use `null` to indicate the control has no value.\n *\n * Mutually exclusive with `defaultValue`.\n */\n value?: number | null;\n};\n\n/**\n * State used in rendering SpinButton\n */\nexport type SpinButtonState = ComponentState<SpinButtonSlots> &\n Required<Pick<SpinButtonProps, 'appearance' | 'size'>> & {\n /**\n * State used to track which direction, if any, SpinButton is currently spinning.\n * @default 'rest'\n */\n spinState: SpinButtonSpinState;\n\n /**\n * State used to track if the value is at the range bounds of [min-max].\n * @default 'none'\n */\n atBound: SpinButtonBounds;\n };\n\nexport type SpinButtonChangeEvent =\n | React.MouseEvent<HTMLButtonElement>\n | React.ChangeEvent<HTMLElement>\n | React.FocusEvent<HTMLInputElement>\n | React.KeyboardEvent<HTMLInputElement>;\n\nexport type SpinButtonOnChangeData = {\n value?: number | null;\n displayValue?: string;\n};\n\nexport type SpinButtonSpinState = 'rest' | 'up' | 'down';\nexport type SpinButtonBounds = 'none' | 'min' | 'max' | 'both';\n"]}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
3
|
-
export * from
|
4
|
-
export * from
|
5
|
-
export * from
|
1
|
+
export * from './SpinButton';
|
2
|
+
export * from './SpinButton.types';
|
3
|
+
export * from './renderSpinButton';
|
4
|
+
export * from './useSpinButton';
|
5
|
+
export * from './useSpinButtonStyles';
|
6
6
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-spinbutton/src/components/SpinButton/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './SpinButton';\nexport * from './SpinButton.types';\nexport * from './renderSpinButton';\nexport * from './useSpinButton';\nexport * from './useSpinButtonStyles';\n"]}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as React from
|
2
|
-
import { getSlots } from
|
1
|
+
import * as React from 'react';
|
2
|
+
import { getSlots } from '@fluentui/react-utilities';
|
3
3
|
/**
|
4
4
|
* Render the final JSX of SpinButton
|
5
5
|
*/
|
@@ -8,6 +8,14 @@ export const renderSpinButton_unstable = state => {
|
|
8
8
|
slots,
|
9
9
|
slotProps
|
10
10
|
} = getSlots(state);
|
11
|
-
return /*#__PURE__*/React.createElement(slots.root,
|
11
|
+
return /*#__PURE__*/React.createElement(slots.root, {
|
12
|
+
...slotProps.root
|
13
|
+
}, /*#__PURE__*/React.createElement(slots.input, {
|
14
|
+
...slotProps.input
|
15
|
+
}), /*#__PURE__*/React.createElement(slots.incrementButton, {
|
16
|
+
...slotProps.incrementButton
|
17
|
+
}), /*#__PURE__*/React.createElement(slots.decrementButton, {
|
18
|
+
...slotProps.decrementButton
|
19
|
+
}));
|
12
20
|
};
|
13
21
|
//# sourceMappingURL=renderSpinButton.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","getSlots","renderSpinButton_unstable","state","slots","slotProps","createElement","root","input","incrementButton","decrementButton"],"sources":["
|
1
|
+
{"version":3,"names":["React","getSlots","renderSpinButton_unstable","state","slots","slotProps","createElement","root","input","incrementButton","decrementButton"],"sources":["../../../../../../../../../packages/react-components/react-spinbutton/src/components/SpinButton/renderSpinButton.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { SpinButtonState, SpinButtonSlots } from './SpinButton.types';\n\n/**\n * Render the final JSX of SpinButton\n */\nexport const renderSpinButton_unstable = (state: SpinButtonState) => {\n const { slots, slotProps } = getSlots<SpinButtonSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <slots.input {...slotProps.input} />\n <slots.incrementButton {...slotProps.incrementButton} />\n <slots.decrementButton {...slotProps.decrementButton} />\n </slots.root>\n );\n};\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,2BAA2B;AAGpD;;;AAGA,OAAO,MAAMC,yBAAyB,GAAIC,KAAsB,IAAI;EAClE,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGJ,QAAQ,CAAkBE,KAAK,CAAC;EAE7D,oBACEH,KAAA,CAAAM,aAAA,CAACF,KAAK,CAACG,IAAI;IAAA,GAAKF,SAAS,CAACE;EAAI,gBAC5BP,KAAA,CAAAM,aAAA,CAACF,KAAK,CAACI,KAAK;IAAA,GAAKH,SAAS,CAACG;EAAK,EAAI,eACpCR,KAAA,CAAAM,aAAA,CAACF,KAAK,CAACK,eAAe;IAAA,GAAKJ,SAAS,CAACI;EAAe,EAAI,eACxDT,KAAA,CAAAM,aAAA,CAACF,KAAK,CAACM,eAAe;IAAA,GAAKL,SAAS,CAACK;EAAe,EAAI,CAC7C;AAEjB,CAAC"}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import * as React from
|
2
|
-
import { getPartitionedNativeProps, mergeCallbacks, resolveShorthand, useControllableState, useTimeout } from
|
3
|
-
import { ArrowUp, ArrowDown, End, Enter, Escape, Home, PageDown, PageUp } from
|
4
|
-
import { calculatePrecision, precisionRound, getBound, clamp } from
|
5
|
-
import { ChevronUp16Regular, ChevronDown16Regular } from
|
6
|
-
import { useOverrides_unstable as useOverrides } from
|
1
|
+
import * as React from 'react';
|
2
|
+
import { getPartitionedNativeProps, mergeCallbacks, resolveShorthand, useControllableState, useTimeout } from '@fluentui/react-utilities';
|
3
|
+
import { ArrowUp, ArrowDown, End, Enter, Escape, Home, PageDown, PageUp } from '@fluentui/keyboard-keys';
|
4
|
+
import { calculatePrecision, precisionRound, getBound, clamp } from '../../utils/index';
|
5
|
+
import { ChevronUp16Regular, ChevronDown16Regular } from '@fluentui/react-icons';
|
6
|
+
import { useOverrides_unstable as useOverrides } from '@fluentui/react-shared-contexts';
|
7
7
|
const DEFAULT_SPIN_DELAY_MS = 150;
|
8
8
|
const MIN_SPIN_DELAY_MS = 80;
|
9
9
|
const MAX_SPIN_TIME_MS = 1000;
|
@@ -21,10 +21,11 @@ const lerp = (start, end, percent) => start + (end - start) * percent;
|
|
21
21
|
* @param ref - reference to root HTMLElement of SpinButton
|
22
22
|
*/
|
23
23
|
export const useSpinButton_unstable = (props, ref) => {
|
24
|
+
var _a, _b;
|
24
25
|
const nativeProps = getPartitionedNativeProps({
|
25
26
|
props,
|
26
|
-
primarySlotTagName:
|
27
|
-
excludedPropNames: [
|
27
|
+
primarySlotTagName: 'input',
|
28
|
+
excludedPropNames: ['defaultValue', 'max', 'min', 'onChange', 'size', 'value']
|
28
29
|
});
|
29
30
|
const overrides = useOverrides();
|
30
31
|
const {
|
@@ -37,15 +38,15 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
37
38
|
stepPage = 1,
|
38
39
|
precision: precisionFromProps,
|
39
40
|
onChange,
|
40
|
-
size =
|
41
|
-
appearance = overrides.inputDefaultAppearance
|
41
|
+
size = 'medium',
|
42
|
+
appearance = (_a = overrides.inputDefaultAppearance) !== null && _a !== void 0 ? _a : 'outline',
|
42
43
|
root,
|
43
44
|
input,
|
44
45
|
incrementButton,
|
45
46
|
decrementButton
|
46
47
|
} = props;
|
47
48
|
const precision = React.useMemo(() => {
|
48
|
-
return precisionFromProps
|
49
|
+
return precisionFromProps !== null && precisionFromProps !== void 0 ? precisionFromProps : Math.max(calculatePrecision(step), 0);
|
49
50
|
}, [precisionFromProps, step]);
|
50
51
|
const [currentValue, setCurrentValue] = useControllableState({
|
51
52
|
state: value,
|
@@ -54,13 +55,13 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
54
55
|
});
|
55
56
|
const isControlled = value !== undefined;
|
56
57
|
const [textValue, setTextValue] = React.useState(undefined);
|
57
|
-
const [keyboardSpinState, setKeyboardSpinState] = React.useState(
|
58
|
+
const [keyboardSpinState, setKeyboardSpinState] = React.useState('rest');
|
58
59
|
const internalState = React.useRef({
|
59
60
|
value: currentValue,
|
60
|
-
spinState:
|
61
|
+
spinState: 'rest',
|
61
62
|
spinTime: 0,
|
62
63
|
spinDelay: DEFAULT_SPIN_DELAY_MS,
|
63
|
-
atBound: currentValue !== null ? getBound(precisionRound(currentValue, precision), min, max) :
|
64
|
+
atBound: currentValue !== null ? getBound(precisionRound(currentValue, precision), min, max) : 'none'
|
64
65
|
});
|
65
66
|
const [setStepTimeout, clearStepTimeout] = useTimeout();
|
66
67
|
const stepValue = (e, direction, startFrom) => {
|
@@ -72,8 +73,8 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
72
73
|
}
|
73
74
|
}
|
74
75
|
const val = startValue;
|
75
|
-
const dir = direction ===
|
76
|
-
const stepSize = direction ===
|
76
|
+
const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;
|
77
|
+
const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;
|
77
78
|
if (val === null) {
|
78
79
|
const stepStart = min === undefined ? 0 : min;
|
79
80
|
const nullStep = clamp(stepStart + stepSize * dir, min, max);
|
@@ -85,7 +86,7 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
85
86
|
newValue = clamp(newValue, min, max);
|
86
87
|
}
|
87
88
|
commit(e, newValue);
|
88
|
-
if (internalState.current.spinState !==
|
89
|
+
if (internalState.current.spinState !== 'rest') {
|
89
90
|
setStepTimeout(() => {
|
90
91
|
// Ease the step speed a bit
|
91
92
|
internalState.current.spinTime += internalState.current.spinDelay;
|
@@ -96,22 +97,22 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
96
97
|
};
|
97
98
|
const handleInputChange = e => {
|
98
99
|
if (!internalState.current.previousTextValue) {
|
99
|
-
internalState.current.previousTextValue = textValue
|
100
|
+
internalState.current.previousTextValue = textValue !== null && textValue !== void 0 ? textValue : String(currentValue);
|
100
101
|
}
|
101
102
|
const newValue = e.target.value;
|
102
103
|
setTextValue(newValue);
|
103
104
|
};
|
104
105
|
const handleIncrementMouseDown = e => {
|
105
|
-
internalState.current.spinState =
|
106
|
-
stepValue(e,
|
106
|
+
internalState.current.spinState = 'up';
|
107
|
+
stepValue(e, 'up');
|
107
108
|
};
|
108
109
|
const handleDecrementMouseDown = e => {
|
109
|
-
internalState.current.spinState =
|
110
|
-
stepValue(e,
|
110
|
+
internalState.current.spinState = 'down';
|
111
|
+
stepValue(e, 'down');
|
111
112
|
};
|
112
113
|
const handleStepMouseUpOrLeave = e => {
|
113
114
|
clearStepTimeout();
|
114
|
-
internalState.current.spinState =
|
115
|
+
internalState.current.spinState = 'rest';
|
115
116
|
internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;
|
116
117
|
internalState.current.spinTime = 0;
|
117
118
|
};
|
@@ -120,27 +121,27 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
120
121
|
internalState.current.previousTextValue = undefined;
|
121
122
|
};
|
122
123
|
const handleKeyDown = e => {
|
123
|
-
let nextKeyboardSpinState =
|
124
|
+
let nextKeyboardSpinState = 'rest';
|
124
125
|
if (e.key === ArrowUp) {
|
125
|
-
stepValue(e,
|
126
|
-
nextKeyboardSpinState =
|
126
|
+
stepValue(e, 'up', textValue);
|
127
|
+
nextKeyboardSpinState = 'up';
|
127
128
|
} else if (e.key === ArrowDown) {
|
128
|
-
stepValue(e,
|
129
|
-
nextKeyboardSpinState =
|
129
|
+
stepValue(e, 'down', textValue);
|
130
|
+
nextKeyboardSpinState = 'down';
|
130
131
|
} else if (e.key === PageUp) {
|
131
132
|
e.preventDefault();
|
132
|
-
stepValue(e,
|
133
|
-
nextKeyboardSpinState =
|
133
|
+
stepValue(e, 'upPage', textValue);
|
134
|
+
nextKeyboardSpinState = 'up';
|
134
135
|
} else if (e.key === PageDown) {
|
135
136
|
e.preventDefault();
|
136
|
-
stepValue(e,
|
137
|
-
nextKeyboardSpinState =
|
137
|
+
stepValue(e, 'downPage', textValue);
|
138
|
+
nextKeyboardSpinState = 'down';
|
138
139
|
} else if (!e.shiftKey && e.key === Home && min !== undefined) {
|
139
140
|
commit(e, min);
|
140
|
-
nextKeyboardSpinState =
|
141
|
+
nextKeyboardSpinState = 'down';
|
141
142
|
} else if (!e.shiftKey && e.key === End && max !== undefined) {
|
142
143
|
commit(e, max);
|
143
|
-
nextKeyboardSpinState =
|
144
|
+
nextKeyboardSpinState = 'up';
|
144
145
|
} else if (e.key === Enter) {
|
145
146
|
commit(e, currentValue, textValue);
|
146
147
|
internalState.current.previousTextValue = undefined;
|
@@ -155,9 +156,9 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
155
156
|
}
|
156
157
|
};
|
157
158
|
const handleKeyUp = e => {
|
158
|
-
if (keyboardSpinState !==
|
159
|
-
setKeyboardSpinState(
|
160
|
-
internalState.current.spinState =
|
159
|
+
if (keyboardSpinState !== 'rest') {
|
160
|
+
setKeyboardSpinState('rest');
|
161
|
+
internalState.current.spinState = 'rest';
|
161
162
|
}
|
162
163
|
};
|
163
164
|
const commit = (e, newValue, newDisplayValue) => {
|
@@ -174,7 +175,7 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
174
175
|
}
|
175
176
|
}
|
176
177
|
if (valueChanged || displayValueChanged) {
|
177
|
-
onChange
|
178
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e, {
|
178
179
|
value: roundedValue,
|
179
180
|
displayValue: newDisplayValue
|
180
181
|
});
|
@@ -187,10 +188,10 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
187
188
|
spinState: keyboardSpinState,
|
188
189
|
atBound: internalState.current.atBound,
|
189
190
|
components: {
|
190
|
-
root:
|
191
|
-
input:
|
192
|
-
incrementButton:
|
193
|
-
decrementButton:
|
191
|
+
root: 'span',
|
192
|
+
input: 'input',
|
193
|
+
incrementButton: 'button',
|
194
|
+
decrementButton: 'button'
|
194
195
|
},
|
195
196
|
root: resolveShorthand(root, {
|
196
197
|
required: true,
|
@@ -200,10 +201,10 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
200
201
|
required: true,
|
201
202
|
defaultProps: {
|
202
203
|
ref,
|
203
|
-
autoComplete:
|
204
|
-
role:
|
204
|
+
autoComplete: 'off',
|
205
|
+
role: 'spinbutton',
|
205
206
|
appearance,
|
206
|
-
type:
|
207
|
+
type: 'text',
|
207
208
|
...nativeProps.primary
|
208
209
|
}
|
209
210
|
}),
|
@@ -213,8 +214,8 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
213
214
|
tabIndex: -1,
|
214
215
|
children: /*#__PURE__*/React.createElement(ChevronUp16Regular, null),
|
215
216
|
disabled: nativeProps.primary.disabled,
|
216
|
-
|
217
|
-
type:
|
217
|
+
'aria-label': 'Increment value',
|
218
|
+
type: 'button'
|
218
219
|
}
|
219
220
|
}),
|
220
221
|
decrementButton: resolveShorthand(decrementButton, {
|
@@ -223,8 +224,8 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
223
224
|
tabIndex: -1,
|
224
225
|
children: /*#__PURE__*/React.createElement(ChevronDown16Regular, null),
|
225
226
|
disabled: nativeProps.primary.disabled,
|
226
|
-
|
227
|
-
type:
|
227
|
+
'aria-label': 'Decrement value',
|
228
|
+
type: 'button'
|
228
229
|
}
|
229
230
|
})
|
230
231
|
};
|
@@ -232,24 +233,24 @@ export const useSpinButton_unstable = (props, ref) => {
|
|
232
233
|
if (textValue !== undefined) {
|
233
234
|
valueToDisplay = textValue;
|
234
235
|
} else if (value === null || currentValue === null) {
|
235
|
-
valueToDisplay = displayValue
|
236
|
+
valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : '';
|
236
237
|
internalState.current.value = null;
|
237
|
-
internalState.current.atBound =
|
238
|
+
internalState.current.atBound = 'none';
|
238
239
|
} else {
|
239
240
|
const roundedValue = precisionRound(currentValue, precision);
|
240
241
|
internalState.current.value = roundedValue;
|
241
242
|
internalState.current.atBound = getBound(roundedValue, min, max);
|
242
243
|
if (isControlled) {
|
243
|
-
valueToDisplay = displayValue
|
244
|
+
valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : String(roundedValue);
|
244
245
|
} else {
|
245
246
|
valueToDisplay = String(roundedValue);
|
246
247
|
}
|
247
248
|
}
|
248
249
|
state.input.value = valueToDisplay;
|
249
|
-
state.input[
|
250
|
-
state.input[
|
251
|
-
state.input[
|
252
|
-
state.input[
|
250
|
+
state.input['aria-valuemin'] = min;
|
251
|
+
state.input['aria-valuemax'] = max;
|
252
|
+
state.input['aria-valuenow'] = currentValue !== null && currentValue !== void 0 ? currentValue : undefined;
|
253
|
+
state.input['aria-valuetext'] = (_b = state.input['aria-valuetext']) !== null && _b !== void 0 ? _b : value !== undefined && displayValue || undefined;
|
253
254
|
state.input.onChange = mergeCallbacks(state.input.onChange, handleInputChange);
|
254
255
|
state.input.onBlur = mergeCallbacks(state.input.onBlur, handleBlur);
|
255
256
|
state.input.onKeyDown = mergeCallbacks(state.input.onKeyDown, handleKeyDown);
|