@fluentui/react-spinbutton 0.0.0-nightly-20230317-1454.1 → 0.0.0-nightly-20230322-0439.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/.swcrc +2 -11
- package/CHANGELOG.json +86 -17
- package/CHANGELOG.md +29 -11
- package/lib/SpinButton.js +1 -1
- package/lib/SpinButtonField.js +1 -1
- package/lib/components/SpinButton/SpinButton.js +6 -6
- package/lib/components/SpinButton/SpinButton.types.js +1 -1
- package/lib/components/SpinButton/index.js +5 -5
- package/lib/components/SpinButton/renderSpinButton.js +2 -2
- package/lib/components/SpinButton/useSpinButton.js +58 -56
- package/lib/components/SpinButton/useSpinButton.js.map +1 -1
- package/lib/components/SpinButton/useSpinButtonStyles.js +14 -14
- package/lib/components/SpinButtonField/SpinButtonField.js +2 -2
- package/lib/components/SpinButtonField/index.js +1 -1
- package/lib/index.js +2 -2
- package/lib/utils/clamp.js +1 -1
- package/lib/utils/getBound.js +4 -4
- package/lib/utils/index.js +3 -3
- package/lib-commonjs/SpinButton.js.map +1 -1
- package/lib-commonjs/SpinButtonField.js.map +1 -1
- package/lib-commonjs/components/SpinButton/SpinButton.js +1 -1
- package/lib-commonjs/components/SpinButton/SpinButton.js.map +1 -1
- package/lib-commonjs/components/SpinButton/SpinButton.types.js.map +1 -1
- package/lib-commonjs/components/SpinButton/index.js.map +1 -1
- package/lib-commonjs/components/SpinButton/renderSpinButton.js.map +1 -1
- package/lib-commonjs/components/SpinButton/useSpinButton.js +56 -54
- package/lib-commonjs/components/SpinButton/useSpinButton.js.map +1 -1
- package/lib-commonjs/components/SpinButton/useSpinButtonStyles.js +16 -16
- package/lib-commonjs/components/SpinButton/useSpinButtonStyles.js.map +1 -1
- package/lib-commonjs/components/SpinButtonField/SpinButtonField.js.map +1 -1
- package/lib-commonjs/components/SpinButtonField/index.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/clamp.js +1 -1
- package/lib-commonjs/utils/clamp.js.map +1 -1
- package/lib-commonjs/utils/getBound.js +4 -4
- package/lib-commonjs/utils/getBound.js.map +1 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/package.json +10 -9
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","getPartitionedNativeProps","mergeCallbacks","resolveShorthand","useControllableState","useTimeout","ArrowUp","ArrowDown","End","Enter","Escape","Home","PageDown","PageUp","calculatePrecision","precisionRound","getBound","clamp","ChevronUp16Regular","ChevronDown16Regular","useOverrides_unstable","useOverrides","DEFAULT_SPIN_DELAY_MS","MIN_SPIN_DELAY_MS","MAX_SPIN_TIME_MS","lerp","start","end","percent","useSpinButton_unstable","props","ref","nativeProps","primarySlotTagName","excludedPropNames","overrides","value","displayValue","defaultValue","min","max","step","stepPage","precision","precisionFromProps","onChange","size","appearance","inputDefaultAppearance","root","input","incrementButton","decrementButton","useMemo","Math","currentValue","setCurrentValue","state","defaultState","initialState","isControlled","undefined","textValue","setTextValue","useState","keyboardSpinState","setKeyboardSpinState","internalState","useRef","spinState","spinTime","spinDelay","atBound","setStepTimeout","clearStepTimeout","stepValue","e","direction","startFrom","startValue","current","num","parseFloat","isNaN","val","dir","stepSize","stepStart","nullStep","commit","newValue","Number","handleInputChange","previousTextValue","String","target","handleIncrementMouseDown","handleDecrementMouseDown","handleStepMouseUpOrLeave","handleBlur","handleKeyDown","nextKeyboardSpinState","key","preventDefault","shiftKey","handleKeyUp","newDisplayValue","valueChanged","displayValueChanged","roundedValue","nextValue","components","required","defaultProps","autoComplete","role","type","primary","tabIndex","children","createElement","disabled","valueToDisplay","onBlur","onKeyDown","onKeyUp","onMouseDown","onMouseUp","onMouseLeave"],"sources":["../../../src/components/SpinButton/useSpinButton.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n resolveShorthand,\n useControllableState,\n useTimeout,\n} from '@fluentui/react-utilities';\nimport { ArrowUp, ArrowDown, End, Enter, Escape, Home, PageDown, PageUp } from '@fluentui/keyboard-keys';\nimport {\n SpinButtonProps,\n SpinButtonState,\n SpinButtonSpinState,\n SpinButtonChangeEvent,\n SpinButtonBounds,\n} from './SpinButton.types';\nimport { calculatePrecision, precisionRound, getBound, clamp } from '../../utils/index';\nimport { ChevronUp16Regular, ChevronDown16Regular } from '@fluentui/react-icons';\nimport { useOverrides_unstable as useOverrides } from '@fluentui/react-shared-contexts';\n\ntype InternalState = {\n value: number | null;\n spinState: SpinButtonSpinState;\n spinTime: number;\n spinDelay: number;\n previousTextValue?: string;\n atBound: SpinButtonBounds;\n};\n\nconst DEFAULT_SPIN_DELAY_MS = 150;\nconst MIN_SPIN_DELAY_MS = 80;\nconst MAX_SPIN_TIME_MS = 1000;\n\n// This is here to give an ease for the mouse held down case.\n// Exact easing it to be defined. Once it is we'll likely\n// pull this out into a util function in the SpinButton package.\nconst lerp = (start: number, end: number, percent: number): number => start + (end - start) * percent;\n\n/**\n * Create the state required to render SpinButton.\n *\n * The returned state can be modified with hooks such as useSpinButtonStyles_unstable,\n * before being passed to renderSpinButton_unstable.\n *\n * @param props - props from this instance of SpinButton\n * @param ref - reference to root HTMLElement of SpinButton\n */\nexport const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HTMLInputElement>): SpinButtonState => {\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['defaultValue', 'max', 'min', 'onChange', 'size', 'value'],\n });\n\n const overrides = useOverrides();\n\n const {\n value,\n displayValue,\n defaultValue,\n min,\n max,\n step = 1,\n stepPage = 1,\n precision: precisionFromProps,\n onChange,\n size = 'medium',\n appearance = overrides.inputDefaultAppearance ?? 'outline',\n root,\n input,\n incrementButton,\n decrementButton,\n } = props;\n\n const precision = React.useMemo(() => {\n return precisionFromProps ?? Math.max(calculatePrecision(step), 0);\n }, [precisionFromProps, step]);\n\n const [currentValue, setCurrentValue] = useControllableState({\n state: value,\n defaultState: defaultValue,\n initialState: 0,\n });\n\n const isControlled = value !== undefined;\n\n const [textValue, setTextValue] = React.useState<string | undefined>(undefined);\n const [keyboardSpinState, setKeyboardSpinState] = React.useState<SpinButtonSpinState>('rest');\n\n const internalState = React.useRef<InternalState>({\n value: currentValue,\n spinState: 'rest',\n spinTime: 0,\n spinDelay: DEFAULT_SPIN_DELAY_MS,\n atBound: currentValue !== null ? getBound(precisionRound(currentValue, precision), min, max) : 'none',\n });\n\n const [setStepTimeout, clearStepTimeout] = useTimeout();\n\n const stepValue = (\n e: SpinButtonChangeEvent,\n direction: 'up' | 'down' | 'upPage' | 'downPage',\n startFrom?: string,\n ) => {\n let startValue = internalState.current.value;\n if (startFrom) {\n const num = parseFloat(startFrom);\n if (!isNaN(num)) {\n startValue = num;\n }\n }\n const val = startValue;\n const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;\n const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;\n\n if (val === null) {\n const stepStart = min === undefined ? 0 : min;\n const nullStep = clamp(stepStart + stepSize * dir, min, max);\n commit(e, nullStep);\n return;\n }\n\n let newValue = val + stepSize * dir;\n if (!Number.isNaN(newValue)) {\n newValue = clamp(newValue, min, max);\n }\n\n commit(e, newValue);\n\n if (internalState.current.spinState !== 'rest') {\n setStepTimeout(() => {\n // Ease the step speed a bit\n internalState.current.spinTime += internalState.current.spinDelay;\n internalState.current.spinDelay = lerp(\n DEFAULT_SPIN_DELAY_MS,\n MIN_SPIN_DELAY_MS,\n internalState.current.spinTime / MAX_SPIN_TIME_MS,\n );\n stepValue(e, direction);\n }, internalState.current.spinDelay);\n }\n };\n\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!internalState.current.previousTextValue) {\n internalState.current.previousTextValue = textValue ?? String(currentValue);\n }\n const newValue = e.target.value;\n setTextValue(newValue);\n };\n\n const handleIncrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n internalState.current.spinState = 'up';\n stepValue(e, 'up');\n };\n\n const handleDecrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n internalState.current.spinState = 'down';\n stepValue(e, 'down');\n };\n\n const handleStepMouseUpOrLeave = (e: React.MouseEvent<HTMLButtonElement>) => {\n clearStepTimeout();\n internalState.current.spinState = 'rest';\n internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;\n internalState.current.spinTime = 0;\n };\n\n const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {\n commit(e, currentValue, textValue);\n internalState.current.previousTextValue = undefined;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n let nextKeyboardSpinState: SpinButtonSpinState = 'rest';\n\n if (e.key === ArrowUp) {\n stepValue(e, 'up', textValue);\n nextKeyboardSpinState = 'up';\n } else if (e.key === ArrowDown) {\n stepValue(e, 'down', textValue);\n nextKeyboardSpinState = 'down';\n } else if (e.key === PageUp) {\n e.preventDefault();\n stepValue(e, 'upPage', textValue);\n nextKeyboardSpinState = 'up';\n } else if (e.key === PageDown) {\n e.preventDefault();\n stepValue(e, 'downPage', textValue);\n nextKeyboardSpinState = 'down';\n } else if (!e.shiftKey && e.key === Home && min !== undefined) {\n commit(e, min);\n nextKeyboardSpinState = 'down';\n } else if (!e.shiftKey && e.key === End && max !== undefined) {\n commit(e, max);\n nextKeyboardSpinState = 'up';\n } else if (e.key === Enter) {\n commit(e, currentValue, textValue);\n internalState.current.previousTextValue = undefined;\n } else if (e.key === Escape) {\n if (internalState.current.previousTextValue) {\n setTextValue(undefined);\n internalState.current.previousTextValue = undefined;\n }\n }\n\n if (keyboardSpinState !== nextKeyboardSpinState) {\n setKeyboardSpinState(nextKeyboardSpinState);\n }\n };\n\n const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (keyboardSpinState !== 'rest') {\n setKeyboardSpinState('rest');\n internalState.current.spinState = 'rest';\n }\n };\n\n const commit = (e: SpinButtonChangeEvent, newValue?: number | null, newDisplayValue?: string) => {\n const valueChanged = newValue !== undefined && currentValue !== newValue;\n const displayValueChanged =\n newDisplayValue !== undefined &&\n internalState.current.previousTextValue !== undefined &&\n internalState.current.previousTextValue !== newDisplayValue;\n\n let roundedValue;\n if (valueChanged) {\n roundedValue = precisionRound(newValue!, precision);\n setCurrentValue(roundedValue);\n } else if (displayValueChanged && !isControlled) {\n const nextValue = parseFloat(newDisplayValue as string);\n if (!isNaN(nextValue)) {\n setCurrentValue(precisionRound(nextValue, precision));\n }\n }\n\n if (valueChanged || displayValueChanged) {\n onChange?.(e, { value: roundedValue, displayValue: newDisplayValue });\n }\n\n setTextValue(undefined);\n };\n\n const state: SpinButtonState = {\n size,\n appearance,\n spinState: keyboardSpinState,\n atBound: internalState.current.atBound,\n\n components: {\n root: 'span',\n input: 'input',\n incrementButton: 'button',\n decrementButton: 'button',\n },\n root: resolveShorthand(root, {\n required: true,\n defaultProps: nativeProps.root,\n }),\n input: resolveShorthand(input, {\n required: true,\n defaultProps: {\n ref,\n autoComplete: 'off',\n role: 'spinbutton',\n appearance,\n type: 'text',\n ...nativeProps.primary,\n },\n }),\n incrementButton: resolveShorthand(incrementButton, {\n required: true,\n defaultProps: {\n tabIndex: -1,\n children: <ChevronUp16Regular />,\n disabled: nativeProps.primary.disabled,\n 'aria-label': 'Increment value',\n type: 'button',\n },\n }),\n decrementButton: resolveShorthand(decrementButton, {\n required: true,\n defaultProps: {\n tabIndex: -1,\n children: <ChevronDown16Regular />,\n disabled: nativeProps.primary.disabled,\n 'aria-label': 'Decrement value',\n type: 'button',\n },\n }),\n };\n\n let valueToDisplay;\n if (textValue !== undefined) {\n valueToDisplay = textValue;\n } else if (value === null || currentValue === null) {\n valueToDisplay = displayValue ?? '';\n internalState.current.value = null;\n internalState.current.atBound = 'none';\n } else {\n const roundedValue = precisionRound(currentValue, precision);\n internalState.current.value = roundedValue;\n internalState.current.atBound = getBound(roundedValue, min, max);\n if (isControlled) {\n valueToDisplay = displayValue ?? String(roundedValue);\n } else {\n valueToDisplay = String(roundedValue);\n }\n }\n\n state.input.value = valueToDisplay;\n state.input['aria-valuemin'] = min;\n state.input['aria-valuemax'] = max;\n state.input['aria-valuenow'] = currentValue ?? undefined;\n state.input['aria-valuetext'] = state.input['aria-valuetext'] ?? ((value !== undefined && displayValue) || undefined);\n state.input.onChange = mergeCallbacks(state.input.onChange, handleInputChange);\n state.input.onBlur = mergeCallbacks(state.input.onBlur, handleBlur);\n state.input.onKeyDown = mergeCallbacks(state.input.onKeyDown, handleKeyDown);\n state.input.onKeyUp = mergeCallbacks(state.input.onKeyUp, handleKeyUp);\n\n state.incrementButton.onMouseDown = mergeCallbacks(handleIncrementMouseDown, state.incrementButton.onMouseDown);\n state.incrementButton.onMouseUp = mergeCallbacks(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);\n state.incrementButton.onMouseLeave = mergeCallbacks(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n state.decrementButton.onMouseDown = mergeCallbacks(handleDecrementMouseDown, state.decrementButton.onMouseDown);\n state.decrementButton.onMouseUp = mergeCallbacks(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);\n state.decrementButton.onMouseLeave = mergeCallbacks(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SACEC,yBAAyB,EACzBC,cAAc,EACdC,gBAAgB,EAChBC,oBAAoB,EACpBC,UAAU,QACL;AACP,SAASC,OAAO,EAAEC,SAAS,EAAEC,GAAG,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,MAAM,QAAQ;AAQ/E,SAASC,kBAAkB,EAAEC,cAAc,EAAEC,QAAQ,EAAEC,KAAK,QAAQ;AACpE,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ;AACzD,SAASC,qBAAA,IAAyBC,YAAY,QAAQ;AAWtD,MAAMC,qBAAA,GAAwB;AAC9B,MAAMC,iBAAA,GAAoB;AAC1B,MAAMC,gBAAA,GAAmB;AAEzB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AAQ,EAAE+C,iBAAA;EAC5DnC,KAAA,CAAMP,KAAK,CAACyE,MAAM,GAAGzH,cAAA,CAAeuD,KAAA,CAAMP,KAAK,CAACyE,MAAM,EAAExB,UAAA;EACxD1C,KAAA,CAAMP,KAAK,CAAC0E,SAAS,GAAG1H,cAAA,CAAeuD,KAAA,CAAMP,KAAK,CAAC0E,SAAS,EAAExB,aAAA;EAC9D3C,KAAA,CAAMP,KAAK,CAAC2E,OAAO,GAAG3H,cAAA,CAAeuD,KAAA,CAAMP,KAAK,CAAC2E,OAAO,EAAEpB,WAAA;EAE1DhD,KAAA,CAAMN,eAAe,CAAC2E,WAAW,GAAG5H,cAAA,CAAe8F,wBAAA,EAA0BvC,KAAA,CAAMN,eAAe,CAAC2E,WAAW;EAC9GrE,KAAA,CAAMN,eAAe,CAAC4E,SAAS,GAAG7H,cAAA,CAAeuD,KAAA,CAAMN,eAAe,CAAC4E,SAAS,EAAE7B,wBAAA;EAClFzC,KAAA,CAAMN,eAAe,CAAC6E,YAAY,GAAG9H,cAAA,CAAeuD,KAAA,CAAMN,eAAe,CAAC6E,YAAY,EAAE9B,wBAAA;EAExFzC,KAAA,CAAML,eAAe,CAAC0E,WAAW,GAAG5H,cAAA,CAAe+F,wBAAA,EAA0BxC,KAAA,CAAML,eAAe,CAAC0E,WAAW;EAC9GrE,KAAA,CAAML,eAAe,CAAC2E,SAAS,GAAG7H,cAAA,CAAeuD,KAAA,CAAML,eAAe,CAAC2E,SAAS,EAAE7B,wBAAA;EAClFzC,KAAA,CAAML,eAAe,CAAC4E,YAAY,GAAG9H,cAAA,CAAeuD,KAAA,CAAML,eAAe,CAAC4E,YAAY,EAAE9B,wBAAA;EAExF,OAAOzC,KAAA;AACT"}
|
1
|
+
{"version":3,"names":["React","getPartitionedNativeProps","mergeCallbacks","resolveShorthand","useControllableState","useTimeout","ArrowUp","ArrowDown","End","Enter","Escape","Home","PageDown","PageUp","calculatePrecision","precisionRound","getBound","clamp","ChevronUp16Regular","ChevronDown16Regular","useOverrides_unstable","useOverrides","DEFAULT_SPIN_DELAY_MS","MIN_SPIN_DELAY_MS","MAX_SPIN_TIME_MS","lerp","start","end","percent","useSpinButton_unstable","props","ref","nativeProps","primarySlotTagName","excludedPropNames","overrides","_overrides_inputDefaultAppearance","value","displayValue","defaultValue","min","max","step","stepPage","precision","precisionFromProps","onChange","size","appearance","inputDefaultAppearance","root","input","incrementButton","decrementButton","useMemo","Math","currentValue","setCurrentValue","state","defaultState","initialState","isControlled","undefined","textValue","setTextValue","useState","keyboardSpinState","setKeyboardSpinState","internalState","useRef","spinState","spinTime","spinDelay","atBound","setStepTimeout","clearStepTimeout","stepValue","e","direction","startFrom","startValue","current","num","parseFloat","isNaN","val","dir","stepSize","stepStart","nullStep","commit","newValue","Number","handleInputChange","previousTextValue","String","target","handleIncrementMouseDown","handleDecrementMouseDown","handleStepMouseUpOrLeave","handleBlur","handleKeyDown","nextKeyboardSpinState","key","preventDefault","shiftKey","handleKeyUp","newDisplayValue","valueChanged","displayValueChanged","roundedValue","nextValue","components","required","defaultProps","autoComplete","role","type","primary","tabIndex","children","createElement","disabled","valueToDisplay","_state_input_ariavaluetext","onBlur","onKeyDown","onKeyUp","onMouseDown","onMouseUp","onMouseLeave"],"sources":["../../../src/components/SpinButton/useSpinButton.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n resolveShorthand,\n useControllableState,\n useTimeout,\n} from '@fluentui/react-utilities';\nimport { ArrowUp, ArrowDown, End, Enter, Escape, Home, PageDown, PageUp } from '@fluentui/keyboard-keys';\nimport {\n SpinButtonProps,\n SpinButtonState,\n SpinButtonSpinState,\n SpinButtonChangeEvent,\n SpinButtonBounds,\n} from './SpinButton.types';\nimport { calculatePrecision, precisionRound, getBound, clamp } from '../../utils/index';\nimport { ChevronUp16Regular, ChevronDown16Regular } from '@fluentui/react-icons';\nimport { useOverrides_unstable as useOverrides } from '@fluentui/react-shared-contexts';\n\ntype InternalState = {\n value: number | null;\n spinState: SpinButtonSpinState;\n spinTime: number;\n spinDelay: number;\n previousTextValue?: string;\n atBound: SpinButtonBounds;\n};\n\nconst DEFAULT_SPIN_DELAY_MS = 150;\nconst MIN_SPIN_DELAY_MS = 80;\nconst MAX_SPIN_TIME_MS = 1000;\n\n// This is here to give an ease for the mouse held down case.\n// Exact easing it to be defined. Once it is we'll likely\n// pull this out into a util function in the SpinButton package.\nconst lerp = (start: number, end: number, percent: number): number => start + (end - start) * percent;\n\n/**\n * Create the state required to render SpinButton.\n *\n * The returned state can be modified with hooks such as useSpinButtonStyles_unstable,\n * before being passed to renderSpinButton_unstable.\n *\n * @param props - props from this instance of SpinButton\n * @param ref - reference to root HTMLElement of SpinButton\n */\nexport const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HTMLInputElement>): SpinButtonState => {\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['defaultValue', 'max', 'min', 'onChange', 'size', 'value'],\n });\n\n const overrides = useOverrides();\n\n const {\n value,\n displayValue,\n defaultValue,\n min,\n max,\n step = 1,\n stepPage = 1,\n precision: precisionFromProps,\n onChange,\n size = 'medium',\n appearance = overrides.inputDefaultAppearance ?? 'outline',\n root,\n input,\n incrementButton,\n decrementButton,\n } = props;\n\n const precision = React.useMemo(() => {\n return precisionFromProps ?? Math.max(calculatePrecision(step), 0);\n }, [precisionFromProps, step]);\n\n const [currentValue, setCurrentValue] = useControllableState({\n state: value,\n defaultState: defaultValue,\n initialState: 0,\n });\n\n const isControlled = value !== undefined;\n\n const [textValue, setTextValue] = React.useState<string | undefined>(undefined);\n const [keyboardSpinState, setKeyboardSpinState] = React.useState<SpinButtonSpinState>('rest');\n\n const internalState = React.useRef<InternalState>({\n value: currentValue,\n spinState: 'rest',\n spinTime: 0,\n spinDelay: DEFAULT_SPIN_DELAY_MS,\n atBound: currentValue !== null ? getBound(precisionRound(currentValue, precision), min, max) : 'none',\n });\n\n const [setStepTimeout, clearStepTimeout] = useTimeout();\n\n const stepValue = (\n e: SpinButtonChangeEvent,\n direction: 'up' | 'down' | 'upPage' | 'downPage',\n startFrom?: string,\n ) => {\n let startValue = internalState.current.value;\n if (startFrom) {\n const num = parseFloat(startFrom);\n if (!isNaN(num)) {\n startValue = num;\n }\n }\n const val = startValue;\n const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;\n const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;\n\n if (val === null) {\n const stepStart = min === undefined ? 0 : min;\n const nullStep = clamp(stepStart + stepSize * dir, min, max);\n commit(e, nullStep);\n return;\n }\n\n let newValue = val + stepSize * dir;\n if (!Number.isNaN(newValue)) {\n newValue = clamp(newValue, min, max);\n }\n\n commit(e, newValue);\n\n if (internalState.current.spinState !== 'rest') {\n setStepTimeout(() => {\n // Ease the step speed a bit\n internalState.current.spinTime += internalState.current.spinDelay;\n internalState.current.spinDelay = lerp(\n DEFAULT_SPIN_DELAY_MS,\n MIN_SPIN_DELAY_MS,\n internalState.current.spinTime / MAX_SPIN_TIME_MS,\n );\n stepValue(e, direction);\n }, internalState.current.spinDelay);\n }\n };\n\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!internalState.current.previousTextValue) {\n internalState.current.previousTextValue = textValue ?? String(currentValue);\n }\n const newValue = e.target.value;\n setTextValue(newValue);\n };\n\n const handleIncrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n internalState.current.spinState = 'up';\n stepValue(e, 'up');\n };\n\n const handleDecrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n internalState.current.spinState = 'down';\n stepValue(e, 'down');\n };\n\n const handleStepMouseUpOrLeave = (e: React.MouseEvent<HTMLButtonElement>) => {\n clearStepTimeout();\n internalState.current.spinState = 'rest';\n internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;\n internalState.current.spinTime = 0;\n };\n\n const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {\n commit(e, currentValue, textValue);\n internalState.current.previousTextValue = undefined;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n let nextKeyboardSpinState: SpinButtonSpinState = 'rest';\n\n if (e.key === ArrowUp) {\n stepValue(e, 'up', textValue);\n nextKeyboardSpinState = 'up';\n } else if (e.key === ArrowDown) {\n stepValue(e, 'down', textValue);\n nextKeyboardSpinState = 'down';\n } else if (e.key === PageUp) {\n e.preventDefault();\n stepValue(e, 'upPage', textValue);\n nextKeyboardSpinState = 'up';\n } else if (e.key === PageDown) {\n e.preventDefault();\n stepValue(e, 'downPage', textValue);\n nextKeyboardSpinState = 'down';\n } else if (!e.shiftKey && e.key === Home && min !== undefined) {\n commit(e, min);\n nextKeyboardSpinState = 'down';\n } else if (!e.shiftKey && e.key === End && max !== undefined) {\n commit(e, max);\n nextKeyboardSpinState = 'up';\n } else if (e.key === Enter) {\n commit(e, currentValue, textValue);\n internalState.current.previousTextValue = undefined;\n } else if (e.key === Escape) {\n if (internalState.current.previousTextValue) {\n setTextValue(undefined);\n internalState.current.previousTextValue = undefined;\n }\n }\n\n if (keyboardSpinState !== nextKeyboardSpinState) {\n setKeyboardSpinState(nextKeyboardSpinState);\n }\n };\n\n const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (keyboardSpinState !== 'rest') {\n setKeyboardSpinState('rest');\n internalState.current.spinState = 'rest';\n }\n };\n\n const commit = (e: SpinButtonChangeEvent, newValue?: number | null, newDisplayValue?: string) => {\n const valueChanged = newValue !== undefined && currentValue !== newValue;\n const displayValueChanged =\n newDisplayValue !== undefined &&\n internalState.current.previousTextValue !== undefined &&\n internalState.current.previousTextValue !== newDisplayValue;\n\n let roundedValue;\n if (valueChanged) {\n roundedValue = precisionRound(newValue!, precision);\n setCurrentValue(roundedValue);\n } else if (displayValueChanged && !isControlled) {\n const nextValue = parseFloat(newDisplayValue as string);\n if (!isNaN(nextValue)) {\n setCurrentValue(precisionRound(nextValue, precision));\n }\n }\n\n if (valueChanged || displayValueChanged) {\n onChange?.(e, { value: roundedValue, displayValue: newDisplayValue });\n }\n\n setTextValue(undefined);\n };\n\n const state: SpinButtonState = {\n size,\n appearance,\n spinState: keyboardSpinState,\n atBound: internalState.current.atBound,\n\n components: {\n root: 'span',\n input: 'input',\n incrementButton: 'button',\n decrementButton: 'button',\n },\n root: resolveShorthand(root, {\n required: true,\n defaultProps: nativeProps.root,\n }),\n input: resolveShorthand(input, {\n required: true,\n defaultProps: {\n ref,\n autoComplete: 'off',\n role: 'spinbutton',\n appearance,\n type: 'text',\n ...nativeProps.primary,\n },\n }),\n incrementButton: resolveShorthand(incrementButton, {\n required: true,\n defaultProps: {\n tabIndex: -1,\n children: <ChevronUp16Regular />,\n disabled: nativeProps.primary.disabled,\n 'aria-label': 'Increment value',\n type: 'button',\n },\n }),\n decrementButton: resolveShorthand(decrementButton, {\n required: true,\n defaultProps: {\n tabIndex: -1,\n children: <ChevronDown16Regular />,\n disabled: nativeProps.primary.disabled,\n 'aria-label': 'Decrement value',\n type: 'button',\n },\n }),\n };\n\n let valueToDisplay;\n if (textValue !== undefined) {\n valueToDisplay = textValue;\n } else if (value === null || currentValue === null) {\n valueToDisplay = displayValue ?? '';\n internalState.current.value = null;\n internalState.current.atBound = 'none';\n } else {\n const roundedValue = precisionRound(currentValue, precision);\n internalState.current.value = roundedValue;\n internalState.current.atBound = getBound(roundedValue, min, max);\n if (isControlled) {\n valueToDisplay = displayValue ?? String(roundedValue);\n } else {\n valueToDisplay = String(roundedValue);\n }\n }\n\n state.input.value = valueToDisplay;\n state.input['aria-valuemin'] = min;\n state.input['aria-valuemax'] = max;\n state.input['aria-valuenow'] = currentValue ?? undefined;\n state.input['aria-valuetext'] = state.input['aria-valuetext'] ?? ((value !== undefined && displayValue) || undefined);\n state.input.onChange = mergeCallbacks(state.input.onChange, handleInputChange);\n state.input.onBlur = mergeCallbacks(state.input.onBlur, handleBlur);\n state.input.onKeyDown = mergeCallbacks(state.input.onKeyDown, handleKeyDown);\n state.input.onKeyUp = mergeCallbacks(state.input.onKeyUp, handleKeyUp);\n\n state.incrementButton.onMouseDown = mergeCallbacks(handleIncrementMouseDown, state.incrementButton.onMouseDown);\n state.incrementButton.onMouseUp = mergeCallbacks(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);\n state.incrementButton.onMouseLeave = mergeCallbacks(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n state.decrementButton.onMouseDown = mergeCallbacks(handleDecrementMouseDown, state.decrementButton.onMouseDown);\n state.decrementButton.onMouseUp = mergeCallbacks(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);\n state.decrementButton.onMouseLeave = mergeCallbacks(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SACEC,yBAAyB,EACzBC,cAAc,EACdC,gBAAgB,EAChBC,oBAAoB,EACpBC,UAAU,QACL;AACP,SAASC,OAAO,EAAEC,SAAS,EAAEC,GAAG,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,MAAM,QAAQ;AAQ/E,SAASC,kBAAkB,EAAEC,cAAc,EAAEC,QAAQ,EAAEC,KAAK,QAAQ;AACpE,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ;AACzD,SAASC,qBAAA,IAAyBC,YAAY,QAAQ;AAWtD,MAAMC,qBAAA,GAAwB;AAC9B,MAAMC,iBAAA,GAAoB;AAC1B,MAAMC,gBAAA,GAAmB;AAEzB;AACA;AACA;AACA,MAAMC,IAAA,GAAOA,CAACC,KAAA,EAAeC,GAAA,EAAaC,OAAA,KAA4BF,KAAA,GAAQ,CAACC,GAAA,GAAMD,KAAI,IAAKE,OAAA;AAE9F;;;;;;;;;AASA,OAAO,MAAMC,sBAAA,GAAyBA,CAACC,KAAA,EAAwBC,GAAA,KAAsD;EACnH,MAAMC,WAAA,GAAc/B,yBAAA,CAA0B;IAC5C6B,KAAA;IACAG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GAAG5C,cAAA,CAAewD,KAAA,CAAMP,KAAK,CAACL,QAAQ,EAAE+C,iBAAA;EAC5DnC,KAAA,CAAMP,KAAK,CAAC0E,MAAM,GAAG3H,cAAA,CAAewD,KAAA,CAAMP,KAAK,CAAC0E,MAAM,EAAEzB,UAAA;EACxD1C,KAAA,CAAMP,KAAK,CAAC2E,SAAS,GAAG5H,cAAA,CAAewD,KAAA,CAAMP,KAAK,CAAC2E,SAAS,EAAEzB,aAAA;EAC9D3C,KAAA,CAAMP,KAAK,CAAC4E,OAAO,GAAG7H,cAAA,CAAewD,KAAA,CAAMP,KAAK,CAAC4E,OAAO,EAAErB,WAAA;EAE1DhD,KAAA,CAAMN,eAAe,CAAC4E,WAAW,GAAG9H,cAAA,CAAe+F,wBAAA,EAA0BvC,KAAA,CAAMN,eAAe,CAAC4E,WAAW;EAC9GtE,KAAA,CAAMN,eAAe,CAAC6E,SAAS,GAAG/H,cAAA,CAAewD,KAAA,CAAMN,eAAe,CAAC6E,SAAS,EAAE9B,wBAAA;EAClFzC,KAAA,CAAMN,eAAe,CAAC8E,YAAY,GAAGhI,cAAA,CAAewD,KAAA,CAAMN,eAAe,CAAC8E,YAAY,EAAE/B,wBAAA;EAExFzC,KAAA,CAAML,eAAe,CAAC2E,WAAW,GAAG9H,cAAA,CAAegG,wBAAA,EAA0BxC,KAAA,CAAML,eAAe,CAAC2E,WAAW;EAC9GtE,KAAA,CAAML,eAAe,CAAC4E,SAAS,GAAG/H,cAAA,CAAewD,KAAA,CAAML,eAAe,CAAC4E,SAAS,EAAE9B,wBAAA;EAClFzC,KAAA,CAAML,eAAe,CAAC6E,YAAY,GAAGhI,cAAA,CAAewD,KAAA,CAAML,eAAe,CAAC6E,YAAY,EAAE/B,wBAAA;EAExF,OAAOzC,KAAA;AACT"}
|
@@ -1,17 +1,17 @@
|
|
1
|
-
import { __resetStyles, __styles, mergeClasses, shorthands } from
|
2
|
-
import { tokens, typographyStyles } from
|
1
|
+
import { __resetStyles, __styles, mergeClasses, shorthands } from '@griffel/react';
|
2
|
+
import { tokens, typographyStyles } from '@fluentui/react-theme';
|
3
3
|
export const spinButtonClassNames = {
|
4
|
-
root:
|
5
|
-
input:
|
6
|
-
incrementButton:
|
7
|
-
decrementButton:
|
4
|
+
root: 'fui-SpinButton',
|
5
|
+
input: 'fui-SpinButton__input',
|
6
|
+
incrementButton: 'fui-SpinButton__incrementButton',
|
7
|
+
decrementButton: 'fui-SpinButton__decrementButton'
|
8
8
|
};
|
9
9
|
const spinButtonExtraClassNames = {
|
10
|
-
buttonActive:
|
10
|
+
buttonActive: 'fui-SpinButton__button_active'
|
11
11
|
};
|
12
12
|
const fieldHeights = {
|
13
|
-
small:
|
14
|
-
medium:
|
13
|
+
small: '24px',
|
14
|
+
medium: '32px'
|
15
15
|
};
|
16
16
|
const useRootClassName = /*#__PURE__*/__resetStyles("rkqmps4", "r1trw52p", [".rkqmps4{display:inline-grid;grid-template-columns:1fr 24px;grid-template-rows:1fr 1fr;-webkit-column-gap:var(--spacingHorizontalXS);column-gap:var(--spacingHorizontalXS);row-gap:0;position:relative;isolation:isolate;background-color:var(--colorNeutralBackground1);min-height:32px;padding:0 0 0 var(--spacingHorizontalMNudge);border-radius:var(--borderRadiusMedium);}", ".rkqmps4::before{content:\"\";box-sizing:border-box;position:absolute;top:0;right:0;bottom:0;left:0;pointer-events:none;z-index:10;border:1px solid var(--colorNeutralStroke1);border-bottom-color:var(--colorNeutralStrokeAccessible);border-radius:var(--borderRadiusMedium);}", ".rkqmps4::after{box-sizing:border-box;content:\"\";position:absolute;right:0;bottom:0;left:0;z-index:20;height:max(2px, var(--borderRadiusMedium));border-bottom-left-radius:var(--borderRadiusMedium);border-bottom-right-radius:var(--borderRadiusMedium);border-bottom:2px solid var(--colorCompoundBrandStroke);-webkit-clip-path:inset(calc(100% - 2px) 0 0 0);clip-path:inset(calc(100% - 2px) 0 0 0);-webkit-transform:scaleX(0);-moz-transform:scaleX(0);-ms-transform:scaleX(0);transform:scaleX(0);transition-property:transform;transition-duration:var(--durationUltraFast);transition-delay:var(--curveAccelerateMid);}", "@media screen and (prefers-reduced-motion: reduce){.rkqmps4::after{transition-duration:0.01ms;transition-delay:0.01ms;}}", ".rkqmps4:focus-within::after{-webkit-transform:scaleX(1);-moz-transform:scaleX(1);-ms-transform:scaleX(1);transform:scaleX(1);transition-property:transform;transition-duration:var(--durationNormal);transition-delay:var(--curveDecelerateMid);}", "@media screen and (prefers-reduced-motion: reduce){.rkqmps4:focus-within::after{transition-duration:0.01ms;transition-delay:0.01ms;}}", ".rkqmps4:focus-within:active::after{border-bottom-color:var(--colorCompoundBrandStrokePressed);}", ".rkqmps4:focus-within{outline:2px solid transparent;}", ".r1trw52p{display:inline-grid;grid-template-columns:1fr 24px;grid-template-rows:1fr 1fr;-webkit-column-gap:var(--spacingHorizontalXS);column-gap:var(--spacingHorizontalXS);row-gap:0;position:relative;isolation:isolate;background-color:var(--colorNeutralBackground1);min-height:32px;padding:0 var(--spacingHorizontalMNudge) 0 0;border-radius:var(--borderRadiusMedium);}", ".r1trw52p::before{content:\"\";box-sizing:border-box;position:absolute;top:0;left:0;bottom:0;right:0;pointer-events:none;z-index:10;border:1px solid var(--colorNeutralStroke1);border-bottom-color:var(--colorNeutralStrokeAccessible);border-radius:var(--borderRadiusMedium);}", ".r1trw52p::after{box-sizing:border-box;content:\"\";position:absolute;left:0;bottom:0;right:0;z-index:20;height:max(2px, var(--borderRadiusMedium));border-bottom-right-radius:var(--borderRadiusMedium);border-bottom-left-radius:var(--borderRadiusMedium);border-bottom:2px solid var(--colorCompoundBrandStroke);-webkit-clip-path:inset(calc(100% - 2px) 0 0 0);clip-path:inset(calc(100% - 2px) 0 0 0);-webkit-transform:scaleX(0);-moz-transform:scaleX(0);-ms-transform:scaleX(0);transform:scaleX(0);transition-property:transform;transition-duration:var(--durationUltraFast);transition-delay:var(--curveAccelerateMid);}", "@media screen and (prefers-reduced-motion: reduce){.r1trw52p::after{transition-duration:0.01ms;transition-delay:0.01ms;}}", ".r1trw52p:focus-within::after{-webkit-transform:scaleX(1);-moz-transform:scaleX(1);-ms-transform:scaleX(1);transform:scaleX(1);transition-property:transform;transition-duration:var(--durationNormal);transition-delay:var(--curveDecelerateMid);}", "@media screen and (prefers-reduced-motion: reduce){.r1trw52p:focus-within::after{transition-duration:0.01ms;transition-delay:0.01ms;}}", ".r1trw52p:focus-within:active::after{border-bottom-color:var(--colorCompoundBrandStrokePressed);}", ".r1trw52p:focus-within{outline:2px solid transparent;}"]);
|
17
17
|
const useRootStyles = /*#__PURE__*/__styles({
|
@@ -243,15 +243,15 @@ export const useSpinButtonStyles_unstable = state => {
|
|
243
243
|
size
|
244
244
|
} = state;
|
245
245
|
const disabled = state.input.disabled;
|
246
|
-
const invalid = `${state.input[
|
247
|
-
const filled = appearance.startsWith(
|
246
|
+
const invalid = `${state.input['aria-invalid']}` === 'true';
|
247
|
+
const filled = appearance.startsWith('filled');
|
248
248
|
const rootStyles = useRootStyles();
|
249
249
|
const buttonStyles = useButtonStyles();
|
250
250
|
const buttonDisabledStyles = useButtonDisabledStyles();
|
251
251
|
const inputStyles = useInputStyles();
|
252
|
-
state.root.className = mergeClasses(spinButtonClassNames.root, useRootClassName(), rootStyles[size], rootStyles[appearance], filled && rootStyles.filled, !disabled && appearance ===
|
253
|
-
state.incrementButton.className = mergeClasses(spinButtonClassNames.incrementButton, spinState ===
|
254
|
-
state.decrementButton.className = mergeClasses(spinButtonClassNames.decrementButton, spinState ===
|
252
|
+
state.root.className = mergeClasses(spinButtonClassNames.root, useRootClassName(), rootStyles[size], rootStyles[appearance], filled && rootStyles.filled, !disabled && appearance === 'outline' && rootStyles.outlineInteractive, !disabled && appearance === 'underline' && rootStyles.underlineInteractive, !disabled && filled && rootStyles.filledInteractive, !disabled && invalid && rootStyles.invalid, disabled && rootStyles.disabled, state.root.className);
|
253
|
+
state.incrementButton.className = mergeClasses(spinButtonClassNames.incrementButton, spinState === 'up' && `${spinButtonExtraClassNames.buttonActive}`, useBaseButtonClassName(), buttonStyles.increment, buttonStyles[appearance], size === 'small' && buttonStyles.incrementButtonSmall, (atBound === 'max' || atBound === 'both') && buttonDisabledStyles.base, (atBound === 'max' || atBound === 'both') && buttonDisabledStyles[appearance], state.incrementButton.className);
|
254
|
+
state.decrementButton.className = mergeClasses(spinButtonClassNames.decrementButton, spinState === 'down' && `${spinButtonExtraClassNames.buttonActive}`, useBaseButtonClassName(), buttonStyles.decrement, buttonStyles[appearance], size === 'small' && buttonStyles.decrementButtonSmall, (atBound === 'min' || atBound === 'both') && buttonDisabledStyles.base, (atBound === 'min' || atBound === 'both') && buttonDisabledStyles[appearance], state.decrementButton.className);
|
255
255
|
state.input.className = mergeClasses(spinButtonClassNames.input, useInputClassName(), disabled && inputStyles.disabled, state.input.className);
|
256
256
|
return state;
|
257
257
|
};
|
@@ -1,5 +1,5 @@
|
|
1
|
-
/* eslint-disable deprecation/deprecation */import { getDeprecatedFieldClassNames, makeDeprecatedField } from
|
2
|
-
import { SpinButton, spinButtonClassNames } from
|
1
|
+
/* eslint-disable deprecation/deprecation */import { getDeprecatedFieldClassNames, makeDeprecatedField } from '@fluentui/react-field';
|
2
|
+
import { SpinButton, spinButtonClassNames } from '../../SpinButton';
|
3
3
|
/** @deprecated Use Field with SpinButton: `<Field><SpinButton /></Field>` */
|
4
4
|
export const spinButtonFieldClassNames = /*#__PURE__*/getDeprecatedFieldClassNames(spinButtonClassNames.root);
|
5
5
|
/** @deprecated Use Field with SpinButton: `<Field><SpinButton /></Field>` */
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from
|
1
|
+
export * from './SpinButtonField';
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export { SpinButton, renderSpinButton_unstable, spinButtonClassNames, useSpinButtonStyles_unstable, useSpinButton_unstable } from
|
1
|
+
export { SpinButton, renderSpinButton_unstable, spinButtonClassNames, useSpinButtonStyles_unstable, useSpinButton_unstable } from './SpinButton';
|
2
2
|
// eslint-disable-next-line deprecation/deprecation
|
3
|
-
export { SpinButtonField as SpinButtonField_unstable, spinButtonFieldClassNames } from
|
3
|
+
export { SpinButtonField as SpinButtonField_unstable, spinButtonFieldClassNames } from './SpinButtonField';
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/clamp.js
CHANGED
@@ -3,7 +3,7 @@ export const clamp = (value, min, max) => {
|
|
3
3
|
if (min !== undefined) {
|
4
4
|
if (max !== undefined && min > max) {
|
5
5
|
const error = new Error();
|
6
|
-
if (process.env.NODE_ENV !==
|
6
|
+
if (process.env.NODE_ENV !== 'production') {
|
7
7
|
// eslint-disable-next-line no-console
|
8
8
|
console.error([`"min" value "${min}" is greater than "max" value "${max}".`, '"min" must be less than or equal to "max".', `Returning value "${value}".`, error.stack].join());
|
9
9
|
}
|
package/lib/utils/getBound.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
export const getBound = (value, min, max) => {
|
2
2
|
if (min !== undefined && value === min) {
|
3
3
|
if (max === min) {
|
4
|
-
return
|
4
|
+
return 'both';
|
5
5
|
}
|
6
|
-
return
|
6
|
+
return 'min';
|
7
7
|
} else if (max !== undefined && value === max) {
|
8
|
-
return
|
8
|
+
return 'max';
|
9
9
|
}
|
10
|
-
return
|
10
|
+
return 'none';
|
11
11
|
};
|
12
12
|
//# sourceMappingURL=getBound.js.map
|
package/lib/utils/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
3
|
-
export * from
|
1
|
+
export * from './clamp';
|
2
|
+
export * from './getBound';
|
3
|
+
export * from './precision';
|
4
4
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../lib/SpinButton.js"],"sourcesContent":["export * from
|
1
|
+
{"version":3,"sources":["../lib/SpinButton.js"],"sourcesContent":["export * from './components/SpinButton/index';\n//# sourceMappingURL=SpinButton.js.map"],"names":[],"mappings":";;;;;oBAAc;CACd,sCAAsC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../lib/SpinButtonField.js"],"sourcesContent":["export * from
|
1
|
+
{"version":3,"sources":["../lib/SpinButtonField.js"],"sourcesContent":["export * from './components/SpinButtonField/index';\n//# sourceMappingURL=SpinButtonField.js.map"],"names":[],"mappings":";;;;;oBAAc;CACd,2CAA2C"}
|
@@ -19,6 +19,6 @@ const SpinButton = /*#__PURE__*/ _react.forwardRef((props, ref)=>{
|
|
19
19
|
useCustomStyles(state);
|
20
20
|
return (0, _renderSpinButton.renderSpinButton_unstable)(state);
|
21
21
|
});
|
22
|
-
SpinButton.displayName =
|
22
|
+
SpinButton.displayName = 'SpinButton'; //# sourceMappingURL=SpinButton.js.map
|
23
23
|
|
24
24
|
//# sourceMappingURL=SpinButton.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../lib/components/SpinButton/SpinButton.js"],"sourcesContent":["import * as React from
|
1
|
+
{"version":3,"sources":["../../../lib/components/SpinButton/SpinButton.js"],"sourcesContent":["import * as React from 'react';\nimport { useSpinButton_unstable } from './useSpinButton';\nimport { renderSpinButton_unstable } from './renderSpinButton';\nimport { useSpinButtonStyles_unstable } from './useSpinButtonStyles';\nimport { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';\n/**\n * A SpinButton allows someone to incrementally adjust a value in small steps.\n */\nexport const SpinButton = /*#__PURE__*/React.forwardRef((props, ref) => {\n const state = useSpinButton_unstable(props, ref);\n useSpinButtonStyles_unstable(state);\n const {\n useSpinButtonStyles_unstable: useCustomStyles\n } = useCustomStyleHooks_unstable();\n useCustomStyles(state);\n return renderSpinButton_unstable(state);\n});\nSpinButton.displayName = 'SpinButton';\n//# sourceMappingURL=SpinButton.js.map"],"names":["SpinButton","React","forwardRef","props","ref","state","useSpinButton_unstable","useSpinButtonStyles_unstable","useCustomStyles","useCustomStyleHooks_unstable","renderSpinButton_unstable","displayName"],"mappings":";;;;+BAQaA;;aAAAA;;;6DARU;+BACgB;kCACG;qCACG;qCACA;AAItC,MAAMA,aAAa,WAAW,GAAEC,OAAMC,UAAU,CAAC,CAACC,OAAOC,MAAQ;IACtE,MAAMC,QAAQC,IAAAA,qCAAsB,EAACH,OAAOC;IAC5CG,IAAAA,iDAA4B,EAACF;IAC7B,MAAM,EACJE,8BAA8BC,gBAAe,EAC9C,GAAGC,IAAAA,iDAA4B;IAChCD,gBAAgBH;IAChB,OAAOK,IAAAA,2CAAyB,EAACL;AACnC;AACAL,WAAWW,WAAW,GAAG,cACzB,sCAAsC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../lib/components/SpinButton/SpinButton.types.js"],"sourcesContent":["import * as React from
|
1
|
+
{"version":3,"sources":["../../../lib/components/SpinButton/SpinButton.types.js"],"sourcesContent":["import * as React from 'react';\n//# sourceMappingURL=SpinButton.types.js.map"],"names":[],"mappings":";;;;;6DAAuB;CACvB,4CAA4C"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../lib/components/SpinButton/index.js"],"sourcesContent":["export * from
|
1
|
+
{"version":3,"sources":["../../../lib/components/SpinButton/index.js"],"sourcesContent":["export * from './SpinButton';\nexport * from './SpinButton.types';\nexport * from './renderSpinButton';\nexport * from './useSpinButton';\nexport * from './useSpinButtonStyles';\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;oBAAc;oBACA;oBACA;oBACA;oBACA;CACd,iCAAiC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../lib/components/SpinButton/renderSpinButton.js"],"sourcesContent":["import * as React from
|
1
|
+
{"version":3,"sources":["../../../lib/components/SpinButton/renderSpinButton.js"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\n/**\n * Render the final JSX of SpinButton\n */\nexport const renderSpinButton_unstable = state => {\n const {\n slots,\n slotProps\n } = getSlots(state);\n return /*#__PURE__*/React.createElement(slots.root, slotProps.root, /*#__PURE__*/React.createElement(slots.input, slotProps.input), /*#__PURE__*/React.createElement(slots.incrementButton, slotProps.incrementButton), /*#__PURE__*/React.createElement(slots.decrementButton, slotProps.decrementButton));\n};\n//# sourceMappingURL=renderSpinButton.js.map"],"names":["renderSpinButton_unstable","state","slots","slotProps","getSlots","React","createElement","root","input","incrementButton","decrementButton"],"mappings":";;;;+BAKaA;;aAAAA;;;6DALU;gCACE;AAIlB,MAAMA,4BAA4BC,CAAAA,QAAS;IAChD,MAAM,EACJC,MAAK,EACLC,UAAS,EACV,GAAGC,IAAAA,wBAAQ,EAACH;IACb,OAAO,WAAW,GAAEI,OAAMC,aAAa,CAACJ,MAAMK,IAAI,EAAEJ,UAAUI,IAAI,EAAE,WAAW,GAAEF,OAAMC,aAAa,CAACJ,MAAMM,KAAK,EAAEL,UAAUK,KAAK,GAAG,WAAW,GAAEH,OAAMC,aAAa,CAACJ,MAAMO,eAAe,EAAEN,UAAUM,eAAe,GAAG,WAAW,GAAEJ,OAAMC,aAAa,CAACJ,MAAMQ,eAAe,EAAEP,UAAUO,eAAe;AAC3S,GACA,4CAA4C"}
|
@@ -23,20 +23,21 @@ const lerp = (start, end, percent)=>start + (end - start) * percent;
|
|
23
23
|
const useSpinButton_unstable = (props, ref)=>{
|
24
24
|
const nativeProps = (0, _reactUtilities.getPartitionedNativeProps)({
|
25
25
|
props,
|
26
|
-
primarySlotTagName:
|
26
|
+
primarySlotTagName: 'input',
|
27
27
|
excludedPropNames: [
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
'defaultValue',
|
29
|
+
'max',
|
30
|
+
'min',
|
31
|
+
'onChange',
|
32
|
+
'size',
|
33
|
+
'value'
|
34
34
|
]
|
35
35
|
});
|
36
36
|
const overrides = (0, _reactSharedContexts.useOverrides_unstable)();
|
37
|
-
|
37
|
+
var _overrides_inputDefaultAppearance;
|
38
|
+
const { value , displayValue , defaultValue , min , max , step =1 , stepPage =1 , precision: precisionFromProps , onChange , size ='medium' , appearance =(_overrides_inputDefaultAppearance = overrides.inputDefaultAppearance) !== null && _overrides_inputDefaultAppearance !== void 0 ? _overrides_inputDefaultAppearance : 'outline' , root , input , incrementButton , decrementButton } = props;
|
38
39
|
const precision = _react.useMemo(()=>{
|
39
|
-
return precisionFromProps
|
40
|
+
return precisionFromProps !== null && precisionFromProps !== void 0 ? precisionFromProps : Math.max((0, _index.calculatePrecision)(step), 0);
|
40
41
|
}, [
|
41
42
|
precisionFromProps,
|
42
43
|
step
|
@@ -48,13 +49,13 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
48
49
|
});
|
49
50
|
const isControlled = value !== undefined;
|
50
51
|
const [textValue, setTextValue] = _react.useState(undefined);
|
51
|
-
const [keyboardSpinState, setKeyboardSpinState] = _react.useState(
|
52
|
+
const [keyboardSpinState, setKeyboardSpinState] = _react.useState('rest');
|
52
53
|
const internalState = _react.useRef({
|
53
54
|
value: currentValue,
|
54
|
-
spinState:
|
55
|
+
spinState: 'rest',
|
55
56
|
spinTime: 0,
|
56
57
|
spinDelay: DEFAULT_SPIN_DELAY_MS,
|
57
|
-
atBound: currentValue !== null ? (0, _index.getBound)((0, _index.precisionRound)(currentValue, precision), min, max) :
|
58
|
+
atBound: currentValue !== null ? (0, _index.getBound)((0, _index.precisionRound)(currentValue, precision), min, max) : 'none'
|
58
59
|
});
|
59
60
|
const [setStepTimeout, clearStepTimeout] = (0, _reactUtilities.useTimeout)();
|
60
61
|
const stepValue = (e, direction, startFrom)=>{
|
@@ -66,8 +67,8 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
66
67
|
}
|
67
68
|
}
|
68
69
|
const val = startValue;
|
69
|
-
const dir = direction ===
|
70
|
-
const stepSize = direction ===
|
70
|
+
const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;
|
71
|
+
const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;
|
71
72
|
if (val === null) {
|
72
73
|
const stepStart = min === undefined ? 0 : min;
|
73
74
|
const nullStep = (0, _index.clamp)(stepStart + stepSize * dir, min, max);
|
@@ -79,7 +80,7 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
79
80
|
newValue = (0, _index.clamp)(newValue, min, max);
|
80
81
|
}
|
81
82
|
commit(e, newValue);
|
82
|
-
if (internalState.current.spinState !==
|
83
|
+
if (internalState.current.spinState !== 'rest') {
|
83
84
|
setStepTimeout(()=>{
|
84
85
|
// Ease the step speed a bit
|
85
86
|
internalState.current.spinTime += internalState.current.spinDelay;
|
@@ -90,22 +91,22 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
90
91
|
};
|
91
92
|
const handleInputChange = (e)=>{
|
92
93
|
if (!internalState.current.previousTextValue) {
|
93
|
-
internalState.current.previousTextValue = textValue
|
94
|
+
internalState.current.previousTextValue = textValue !== null && textValue !== void 0 ? textValue : String(currentValue);
|
94
95
|
}
|
95
96
|
const newValue = e.target.value;
|
96
97
|
setTextValue(newValue);
|
97
98
|
};
|
98
99
|
const handleIncrementMouseDown = (e)=>{
|
99
|
-
internalState.current.spinState =
|
100
|
-
stepValue(e,
|
100
|
+
internalState.current.spinState = 'up';
|
101
|
+
stepValue(e, 'up');
|
101
102
|
};
|
102
103
|
const handleDecrementMouseDown = (e)=>{
|
103
|
-
internalState.current.spinState =
|
104
|
-
stepValue(e,
|
104
|
+
internalState.current.spinState = 'down';
|
105
|
+
stepValue(e, 'down');
|
105
106
|
};
|
106
107
|
const handleStepMouseUpOrLeave = (e)=>{
|
107
108
|
clearStepTimeout();
|
108
|
-
internalState.current.spinState =
|
109
|
+
internalState.current.spinState = 'rest';
|
109
110
|
internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;
|
110
111
|
internalState.current.spinTime = 0;
|
111
112
|
};
|
@@ -114,27 +115,27 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
114
115
|
internalState.current.previousTextValue = undefined;
|
115
116
|
};
|
116
117
|
const handleKeyDown = (e)=>{
|
117
|
-
let nextKeyboardSpinState =
|
118
|
+
let nextKeyboardSpinState = 'rest';
|
118
119
|
if (e.key === _keyboardKeys.ArrowUp) {
|
119
|
-
stepValue(e,
|
120
|
-
nextKeyboardSpinState =
|
120
|
+
stepValue(e, 'up', textValue);
|
121
|
+
nextKeyboardSpinState = 'up';
|
121
122
|
} else if (e.key === _keyboardKeys.ArrowDown) {
|
122
|
-
stepValue(e,
|
123
|
-
nextKeyboardSpinState =
|
123
|
+
stepValue(e, 'down', textValue);
|
124
|
+
nextKeyboardSpinState = 'down';
|
124
125
|
} else if (e.key === _keyboardKeys.PageUp) {
|
125
126
|
e.preventDefault();
|
126
|
-
stepValue(e,
|
127
|
-
nextKeyboardSpinState =
|
127
|
+
stepValue(e, 'upPage', textValue);
|
128
|
+
nextKeyboardSpinState = 'up';
|
128
129
|
} else if (e.key === _keyboardKeys.PageDown) {
|
129
130
|
e.preventDefault();
|
130
|
-
stepValue(e,
|
131
|
-
nextKeyboardSpinState =
|
131
|
+
stepValue(e, 'downPage', textValue);
|
132
|
+
nextKeyboardSpinState = 'down';
|
132
133
|
} else if (!e.shiftKey && e.key === _keyboardKeys.Home && min !== undefined) {
|
133
134
|
commit(e, min);
|
134
|
-
nextKeyboardSpinState =
|
135
|
+
nextKeyboardSpinState = 'down';
|
135
136
|
} else if (!e.shiftKey && e.key === _keyboardKeys.End && max !== undefined) {
|
136
137
|
commit(e, max);
|
137
|
-
nextKeyboardSpinState =
|
138
|
+
nextKeyboardSpinState = 'up';
|
138
139
|
} else if (e.key === _keyboardKeys.Enter) {
|
139
140
|
commit(e, currentValue, textValue);
|
140
141
|
internalState.current.previousTextValue = undefined;
|
@@ -149,9 +150,9 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
149
150
|
}
|
150
151
|
};
|
151
152
|
const handleKeyUp = (e)=>{
|
152
|
-
if (keyboardSpinState !==
|
153
|
-
setKeyboardSpinState(
|
154
|
-
internalState.current.spinState =
|
153
|
+
if (keyboardSpinState !== 'rest') {
|
154
|
+
setKeyboardSpinState('rest');
|
155
|
+
internalState.current.spinState = 'rest';
|
155
156
|
}
|
156
157
|
};
|
157
158
|
const commit = (e, newValue, newDisplayValue)=>{
|
@@ -168,7 +169,7 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
168
169
|
}
|
169
170
|
}
|
170
171
|
if (valueChanged || displayValueChanged) {
|
171
|
-
onChange
|
172
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e, {
|
172
173
|
value: roundedValue,
|
173
174
|
displayValue: newDisplayValue
|
174
175
|
});
|
@@ -181,10 +182,10 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
181
182
|
spinState: keyboardSpinState,
|
182
183
|
atBound: internalState.current.atBound,
|
183
184
|
components: {
|
184
|
-
root:
|
185
|
-
input:
|
186
|
-
incrementButton:
|
187
|
-
decrementButton:
|
185
|
+
root: 'span',
|
186
|
+
input: 'input',
|
187
|
+
incrementButton: 'button',
|
188
|
+
decrementButton: 'button'
|
188
189
|
},
|
189
190
|
root: (0, _reactUtilities.resolveShorthand)(root, {
|
190
191
|
required: true,
|
@@ -194,10 +195,10 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
194
195
|
required: true,
|
195
196
|
defaultProps: {
|
196
197
|
ref,
|
197
|
-
autoComplete:
|
198
|
-
role:
|
198
|
+
autoComplete: 'off',
|
199
|
+
role: 'spinbutton',
|
199
200
|
appearance,
|
200
|
-
type:
|
201
|
+
type: 'text',
|
201
202
|
...nativeProps.primary
|
202
203
|
}
|
203
204
|
}),
|
@@ -207,8 +208,8 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
207
208
|
tabIndex: -1,
|
208
209
|
children: /*#__PURE__*/ _react.createElement(_reactIcons.ChevronUp16Regular, null),
|
209
210
|
disabled: nativeProps.primary.disabled,
|
210
|
-
|
211
|
-
type:
|
211
|
+
'aria-label': 'Increment value',
|
212
|
+
type: 'button'
|
212
213
|
}
|
213
214
|
}),
|
214
215
|
decrementButton: (0, _reactUtilities.resolveShorthand)(decrementButton, {
|
@@ -217,8 +218,8 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
217
218
|
tabIndex: -1,
|
218
219
|
children: /*#__PURE__*/ _react.createElement(_reactIcons.ChevronDown16Regular, null),
|
219
220
|
disabled: nativeProps.primary.disabled,
|
220
|
-
|
221
|
-
type:
|
221
|
+
'aria-label': 'Decrement value',
|
222
|
+
type: 'button'
|
222
223
|
}
|
223
224
|
})
|
224
225
|
};
|
@@ -226,24 +227,25 @@ const useSpinButton_unstable = (props, ref)=>{
|
|
226
227
|
if (textValue !== undefined) {
|
227
228
|
valueToDisplay = textValue;
|
228
229
|
} else if (value === null || currentValue === null) {
|
229
|
-
valueToDisplay = displayValue
|
230
|
+
valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : '';
|
230
231
|
internalState.current.value = null;
|
231
|
-
internalState.current.atBound =
|
232
|
+
internalState.current.atBound = 'none';
|
232
233
|
} else {
|
233
234
|
const roundedValue = (0, _index.precisionRound)(currentValue, precision);
|
234
235
|
internalState.current.value = roundedValue;
|
235
236
|
internalState.current.atBound = (0, _index.getBound)(roundedValue, min, max);
|
236
237
|
if (isControlled) {
|
237
|
-
valueToDisplay = displayValue
|
238
|
+
valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : String(roundedValue);
|
238
239
|
} else {
|
239
240
|
valueToDisplay = String(roundedValue);
|
240
241
|
}
|
241
242
|
}
|
242
243
|
state.input.value = valueToDisplay;
|
243
|
-
state.input[
|
244
|
-
state.input[
|
245
|
-
state.input[
|
246
|
-
|
244
|
+
state.input['aria-valuemin'] = min;
|
245
|
+
state.input['aria-valuemax'] = max;
|
246
|
+
state.input['aria-valuenow'] = currentValue !== null && currentValue !== void 0 ? currentValue : undefined;
|
247
|
+
var _state_input_ariavaluetext;
|
248
|
+
state.input['aria-valuetext'] = (_state_input_ariavaluetext = state.input['aria-valuetext']) !== null && _state_input_ariavaluetext !== void 0 ? _state_input_ariavaluetext : value !== undefined && displayValue || undefined;
|
247
249
|
state.input.onChange = (0, _reactUtilities.mergeCallbacks)(state.input.onChange, handleInputChange);
|
248
250
|
state.input.onBlur = (0, _reactUtilities.mergeCallbacks)(state.input.onBlur, handleBlur);
|
249
251
|
state.input.onKeyDown = (0, _reactUtilities.mergeCallbacks)(state.input.onKeyDown, handleKeyDown);
|