@officesdk/design 0.2.7 → 0.2.8
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/dist/components/cjs/index.d.ts +40 -20
- package/dist/components/cjs/index.js +32 -11
- package/dist/components/cjs/index.js.map +1 -1
- package/dist/components/esm/index.d.ts +40 -20
- package/dist/components/esm/index.js +32 -11
- package/dist/components/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -73,6 +73,25 @@ interface ButtonProps extends React$1.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
73
73
|
*/
|
|
74
74
|
declare const Button: React$1.FC<ButtonProps>;
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Value map utilities for piecewise linear mapping (non-linear slider)
|
|
78
|
+
*/
|
|
79
|
+
interface ValueMapPiece {
|
|
80
|
+
/** Size of the piece (value range) */
|
|
81
|
+
size: number;
|
|
82
|
+
/** Step increment, defaults to 1 */
|
|
83
|
+
step?: number;
|
|
84
|
+
/** Visual size (relative), defaults to size/step */
|
|
85
|
+
visualSize?: number;
|
|
86
|
+
}
|
|
87
|
+
interface ValueMap {
|
|
88
|
+
type: 'piecewise';
|
|
89
|
+
/** Starting value */
|
|
90
|
+
start: number;
|
|
91
|
+
/** Array of pieces defining the mapping */
|
|
92
|
+
pieces: ValueMapPiece[];
|
|
93
|
+
}
|
|
94
|
+
|
|
76
95
|
type LineType$1 = 'outlined' | 'underlined' | 'borderless';
|
|
77
96
|
interface NumberInputProps {
|
|
78
97
|
/**
|
|
@@ -152,6 +171,11 @@ interface NumberInputProps {
|
|
|
152
171
|
* @default false
|
|
153
172
|
*/
|
|
154
173
|
useThousandsSeparator?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Value map for piecewise linear mapping (non-linear stepping)
|
|
176
|
+
* When provided, min/max/step props are ignored
|
|
177
|
+
*/
|
|
178
|
+
valueMap?: ValueMap;
|
|
155
179
|
/**
|
|
156
180
|
* Callback when value changes
|
|
157
181
|
* @param fixedValue - The clamped value within min/max range (can be undefined if empty)
|
|
@@ -181,6 +205,16 @@ interface NumberInputProps {
|
|
|
181
205
|
* @param parsedValue - The parsed number value (undefined if invalid)
|
|
182
206
|
*/
|
|
183
207
|
onInputChange?: (inputValue: string, parsedValue: number | undefined) => void;
|
|
208
|
+
/**
|
|
209
|
+
* Whether to select all text when the input receives focus
|
|
210
|
+
* @default false
|
|
211
|
+
*/
|
|
212
|
+
selectAllOnFocus?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Whether to blur the input when Escape key is pressed
|
|
215
|
+
* @default true
|
|
216
|
+
*/
|
|
217
|
+
blurOnEscape?: boolean;
|
|
184
218
|
}
|
|
185
219
|
/**
|
|
186
220
|
* NumberInput Component
|
|
@@ -241,6 +275,11 @@ interface SpinButtonProps {
|
|
|
241
275
|
* Parse the input value
|
|
242
276
|
*/
|
|
243
277
|
parser?: (displayValue: string) => number;
|
|
278
|
+
/**
|
|
279
|
+
* Value map for piecewise linear mapping (non-linear stepping)
|
|
280
|
+
* When provided, min/max/step props are ignored in NumberInput and Slider
|
|
281
|
+
*/
|
|
282
|
+
valueMap?: ValueMap;
|
|
244
283
|
/**
|
|
245
284
|
* Callback when value changes
|
|
246
285
|
*/
|
|
@@ -257,7 +296,7 @@ interface SpinButtonProps {
|
|
|
257
296
|
* Additional props passed to the internal NumberInput component
|
|
258
297
|
* Allows customizing unit, placeholder, lineType, showStepButtons, etc.
|
|
259
298
|
*/
|
|
260
|
-
inputProps?: Partial<Omit<NumberInputProps, 'value' | 'defaultValue' | 'min' | 'max' | 'step' | 'size' | 'disabled' | 'alert' | 'precision' | 'formatter' | 'parser' | 'onChange' | 'className' | 'style'>>;
|
|
299
|
+
inputProps?: Partial<Omit<NumberInputProps, 'value' | 'defaultValue' | 'min' | 'max' | 'step' | 'size' | 'disabled' | 'alert' | 'precision' | 'formatter' | 'parser' | 'valueMap' | 'onChange' | 'className' | 'style'>>;
|
|
261
300
|
}
|
|
262
301
|
/**
|
|
263
302
|
* SpinButton Component - Spin Button
|
|
@@ -425,25 +464,6 @@ interface CheckboxProps {
|
|
|
425
464
|
*/
|
|
426
465
|
declare const Checkbox: React$1.FC<CheckboxProps>;
|
|
427
466
|
|
|
428
|
-
/**
|
|
429
|
-
* Value map utilities for piecewise linear mapping (non-linear slider)
|
|
430
|
-
*/
|
|
431
|
-
interface ValueMapPiece {
|
|
432
|
-
/** Size of the piece (value range) */
|
|
433
|
-
size: number;
|
|
434
|
-
/** Step increment, defaults to 1 */
|
|
435
|
-
step?: number;
|
|
436
|
-
/** Visual size (relative), defaults to size/step */
|
|
437
|
-
visualSize?: number;
|
|
438
|
-
}
|
|
439
|
-
interface ValueMap {
|
|
440
|
-
type: 'piecewise';
|
|
441
|
-
/** Starting value */
|
|
442
|
-
start: number;
|
|
443
|
-
/** Array of pieces defining the mapping */
|
|
444
|
-
pieces: ValueMapPiece[];
|
|
445
|
-
}
|
|
446
|
-
|
|
447
467
|
interface SliderProps {
|
|
448
468
|
/**
|
|
449
469
|
* Current value (0-100)
|
|
@@ -1607,6 +1607,7 @@ var init_NumberInput = __esm({
|
|
|
1607
1607
|
init_styled();
|
|
1608
1608
|
init_UIConfigProvider2();
|
|
1609
1609
|
init_numberLocale();
|
|
1610
|
+
init_valueMap();
|
|
1610
1611
|
getDecimalPlaces = (num) => {
|
|
1611
1612
|
const str = String(num);
|
|
1612
1613
|
const decimalIndex = str.indexOf(".");
|
|
@@ -1849,12 +1850,15 @@ var init_NumberInput = __esm({
|
|
|
1849
1850
|
showStepButtonsTrigger = "normal",
|
|
1850
1851
|
lineType = "outlined",
|
|
1851
1852
|
useThousandsSeparator = false,
|
|
1853
|
+
valueMap: valueMapProp,
|
|
1852
1854
|
onChange,
|
|
1853
1855
|
className,
|
|
1854
1856
|
style,
|
|
1855
1857
|
onFocus: onFocusProp,
|
|
1856
1858
|
onBlur: onBlurProp,
|
|
1857
|
-
onInputChange
|
|
1859
|
+
onInputChange,
|
|
1860
|
+
selectAllOnFocus = false,
|
|
1861
|
+
blurOnEscape = true
|
|
1858
1862
|
}) => {
|
|
1859
1863
|
const config = useUIConfig();
|
|
1860
1864
|
const locale = config?.locale ?? "en-US";
|
|
@@ -1864,6 +1868,12 @@ var init_NumberInput = __esm({
|
|
|
1864
1868
|
const [isHovered, setIsHovered] = useState(false);
|
|
1865
1869
|
const inputRef = useRef(null);
|
|
1866
1870
|
const value = controlledValue !== void 0 ? controlledValue : internalValue;
|
|
1871
|
+
const extendedValueMap = useMemo(() => {
|
|
1872
|
+
if (!valueMapProp) return void 0;
|
|
1873
|
+
return extendValueMap(valueMapProp);
|
|
1874
|
+
}, [valueMapProp]);
|
|
1875
|
+
const effectiveMin = extendedValueMap ? extendedValueMap.start : min;
|
|
1876
|
+
const effectiveMax = extendedValueMap ? extendedValueMap.end : max;
|
|
1867
1877
|
const formatValue = useCallback(
|
|
1868
1878
|
(val) => {
|
|
1869
1879
|
if (val === void 0) {
|
|
@@ -1920,9 +1930,9 @@ var init_NumberInput = __esm({
|
|
|
1920
1930
|
if (val === void 0) {
|
|
1921
1931
|
return void 0;
|
|
1922
1932
|
}
|
|
1923
|
-
return Math.max(
|
|
1933
|
+
return Math.max(effectiveMin, Math.min(effectiveMax, val));
|
|
1924
1934
|
},
|
|
1925
|
-
[
|
|
1935
|
+
[effectiveMin, effectiveMax]
|
|
1926
1936
|
);
|
|
1927
1937
|
const handleValueChange = useCallback(
|
|
1928
1938
|
(newValue) => {
|
|
@@ -1937,23 +1947,23 @@ var init_NumberInput = __esm({
|
|
|
1937
1947
|
const increment = useCallback(() => {
|
|
1938
1948
|
if (disabled) return;
|
|
1939
1949
|
const currentValue = value ?? 0;
|
|
1940
|
-
const newValue = precisionAdd(currentValue, step);
|
|
1950
|
+
const newValue = extendedValueMap ? changeByStep(currentValue, 1, extendedValueMap) : precisionAdd(currentValue, step);
|
|
1941
1951
|
handleValueChange(newValue);
|
|
1942
1952
|
if (isFocused) {
|
|
1943
1953
|
const clampedValue = clampValue(newValue);
|
|
1944
1954
|
setDisplayValue(formatValueForEdit(clampedValue));
|
|
1945
1955
|
}
|
|
1946
|
-
}, [disabled, value, step, handleValueChange, isFocused, clampValue, formatValueForEdit]);
|
|
1956
|
+
}, [disabled, value, step, handleValueChange, isFocused, clampValue, formatValueForEdit, extendedValueMap]);
|
|
1947
1957
|
const decrement = useCallback(() => {
|
|
1948
1958
|
if (disabled) return;
|
|
1949
1959
|
const currentValue = value ?? 0;
|
|
1950
|
-
const newValue = precisionSubtract(currentValue, step);
|
|
1960
|
+
const newValue = extendedValueMap ? changeByStep(currentValue, -1, extendedValueMap) : precisionSubtract(currentValue, step);
|
|
1951
1961
|
handleValueChange(newValue);
|
|
1952
1962
|
if (isFocused) {
|
|
1953
1963
|
const clampedValue = clampValue(newValue);
|
|
1954
1964
|
setDisplayValue(formatValueForEdit(clampedValue));
|
|
1955
1965
|
}
|
|
1956
|
-
}, [disabled, value, step, handleValueChange, isFocused, clampValue, formatValueForEdit]);
|
|
1966
|
+
}, [disabled, value, step, handleValueChange, isFocused, clampValue, formatValueForEdit, extendedValueMap]);
|
|
1957
1967
|
const handleInputChange = useCallback(
|
|
1958
1968
|
(e) => {
|
|
1959
1969
|
const inputValue = e.target.value;
|
|
@@ -1975,22 +1985,28 @@ var init_NumberInput = __esm({
|
|
|
1975
1985
|
const parsed = parseValue(trimmedValue);
|
|
1976
1986
|
if (parsed !== null) {
|
|
1977
1987
|
const preciseValue = applyPrecision(parsed);
|
|
1978
|
-
|
|
1988
|
+
const finalValue = extendedValueMap && preciseValue !== void 0 ? snapToStep(preciseValue, extendedValueMap) : preciseValue;
|
|
1989
|
+
handleValueChange(finalValue);
|
|
1979
1990
|
} else {
|
|
1980
1991
|
setDisplayValue(formatValue(value));
|
|
1981
1992
|
}
|
|
1982
1993
|
}
|
|
1983
1994
|
onBlurProp?.(e);
|
|
1984
1995
|
},
|
|
1985
|
-
[displayValue, parseValue, handleValueChange, value, formatValue, applyPrecision, onBlurProp]
|
|
1996
|
+
[displayValue, parseValue, handleValueChange, value, formatValue, applyPrecision, onBlurProp, extendedValueMap]
|
|
1986
1997
|
);
|
|
1987
1998
|
const handleFocus = useCallback(
|
|
1988
1999
|
(e) => {
|
|
1989
2000
|
setIsFocused(true);
|
|
1990
2001
|
setDisplayValue(formatValueForEdit(value));
|
|
2002
|
+
if (selectAllOnFocus) {
|
|
2003
|
+
requestAnimationFrame(() => {
|
|
2004
|
+
inputRef.current?.select();
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
1991
2007
|
onFocusProp?.(e);
|
|
1992
2008
|
},
|
|
1993
|
-
[value, formatValueForEdit, onFocusProp]
|
|
2009
|
+
[value, formatValueForEdit, onFocusProp, selectAllOnFocus]
|
|
1994
2010
|
);
|
|
1995
2011
|
const handleKeyDown = useCallback(
|
|
1996
2012
|
(e) => {
|
|
@@ -2002,9 +2018,11 @@ var init_NumberInput = __esm({
|
|
|
2002
2018
|
decrement();
|
|
2003
2019
|
} else if (e.key === "Enter") {
|
|
2004
2020
|
inputRef.current?.blur();
|
|
2021
|
+
} else if (e.key === "Escape" && blurOnEscape) {
|
|
2022
|
+
inputRef.current?.blur();
|
|
2005
2023
|
}
|
|
2006
2024
|
},
|
|
2007
|
-
[increment, decrement]
|
|
2025
|
+
[increment, decrement, blurOnEscape]
|
|
2008
2026
|
);
|
|
2009
2027
|
const handleMouseEnter = useCallback(() => {
|
|
2010
2028
|
setIsHovered(true);
|
|
@@ -2107,6 +2125,7 @@ var init_SpinButton = __esm({
|
|
|
2107
2125
|
precision,
|
|
2108
2126
|
formatter,
|
|
2109
2127
|
parser,
|
|
2128
|
+
valueMap,
|
|
2110
2129
|
onChange,
|
|
2111
2130
|
className,
|
|
2112
2131
|
style,
|
|
@@ -2136,6 +2155,7 @@ var init_SpinButton = __esm({
|
|
|
2136
2155
|
max,
|
|
2137
2156
|
step,
|
|
2138
2157
|
disabled,
|
|
2158
|
+
valueMap,
|
|
2139
2159
|
onChange: handleValueChange
|
|
2140
2160
|
}
|
|
2141
2161
|
)), /* @__PURE__ */ React3.createElement(
|
|
@@ -2151,6 +2171,7 @@ var init_SpinButton = __esm({
|
|
|
2151
2171
|
precision,
|
|
2152
2172
|
formatter,
|
|
2153
2173
|
parser,
|
|
2174
|
+
valueMap,
|
|
2154
2175
|
...inputProps,
|
|
2155
2176
|
onChange: handleValueChange
|
|
2156
2177
|
}
|