@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.
@@ -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)
@@ -1620,6 +1620,7 @@ var init_NumberInput = __esm({
1620
1620
  init_styled();
1621
1621
  init_UIConfigProvider2();
1622
1622
  init_numberLocale();
1623
+ init_valueMap();
1623
1624
  getDecimalPlaces = (num) => {
1624
1625
  const str = String(num);
1625
1626
  const decimalIndex = str.indexOf(".");
@@ -1862,12 +1863,15 @@ var init_NumberInput = __esm({
1862
1863
  showStepButtonsTrigger = "normal",
1863
1864
  lineType = "outlined",
1864
1865
  useThousandsSeparator = false,
1866
+ valueMap: valueMapProp,
1865
1867
  onChange,
1866
1868
  className,
1867
1869
  style,
1868
1870
  onFocus: onFocusProp,
1869
1871
  onBlur: onBlurProp,
1870
- onInputChange
1872
+ onInputChange,
1873
+ selectAllOnFocus = false,
1874
+ blurOnEscape = true
1871
1875
  }) => {
1872
1876
  const config = exports.useUIConfig();
1873
1877
  const locale = config?.locale ?? "en-US";
@@ -1877,6 +1881,12 @@ var init_NumberInput = __esm({
1877
1881
  const [isHovered, setIsHovered] = React3.useState(false);
1878
1882
  const inputRef = React3.useRef(null);
1879
1883
  const value = controlledValue !== void 0 ? controlledValue : internalValue;
1884
+ const extendedValueMap = React3.useMemo(() => {
1885
+ if (!valueMapProp) return void 0;
1886
+ return extendValueMap(valueMapProp);
1887
+ }, [valueMapProp]);
1888
+ const effectiveMin = extendedValueMap ? extendedValueMap.start : min;
1889
+ const effectiveMax = extendedValueMap ? extendedValueMap.end : max;
1880
1890
  const formatValue = React3.useCallback(
1881
1891
  (val) => {
1882
1892
  if (val === void 0) {
@@ -1933,9 +1943,9 @@ var init_NumberInput = __esm({
1933
1943
  if (val === void 0) {
1934
1944
  return void 0;
1935
1945
  }
1936
- return Math.max(min, Math.min(max, val));
1946
+ return Math.max(effectiveMin, Math.min(effectiveMax, val));
1937
1947
  },
1938
- [min, max]
1948
+ [effectiveMin, effectiveMax]
1939
1949
  );
1940
1950
  const handleValueChange = React3.useCallback(
1941
1951
  (newValue) => {
@@ -1950,23 +1960,23 @@ var init_NumberInput = __esm({
1950
1960
  const increment = React3.useCallback(() => {
1951
1961
  if (disabled) return;
1952
1962
  const currentValue = value ?? 0;
1953
- const newValue = precisionAdd(currentValue, step);
1963
+ const newValue = extendedValueMap ? changeByStep(currentValue, 1, extendedValueMap) : precisionAdd(currentValue, step);
1954
1964
  handleValueChange(newValue);
1955
1965
  if (isFocused) {
1956
1966
  const clampedValue = clampValue(newValue);
1957
1967
  setDisplayValue(formatValueForEdit(clampedValue));
1958
1968
  }
1959
- }, [disabled, value, step, handleValueChange, isFocused, clampValue, formatValueForEdit]);
1969
+ }, [disabled, value, step, handleValueChange, isFocused, clampValue, formatValueForEdit, extendedValueMap]);
1960
1970
  const decrement = React3.useCallback(() => {
1961
1971
  if (disabled) return;
1962
1972
  const currentValue = value ?? 0;
1963
- const newValue = precisionSubtract(currentValue, step);
1973
+ const newValue = extendedValueMap ? changeByStep(currentValue, -1, extendedValueMap) : precisionSubtract(currentValue, step);
1964
1974
  handleValueChange(newValue);
1965
1975
  if (isFocused) {
1966
1976
  const clampedValue = clampValue(newValue);
1967
1977
  setDisplayValue(formatValueForEdit(clampedValue));
1968
1978
  }
1969
- }, [disabled, value, step, handleValueChange, isFocused, clampValue, formatValueForEdit]);
1979
+ }, [disabled, value, step, handleValueChange, isFocused, clampValue, formatValueForEdit, extendedValueMap]);
1970
1980
  const handleInputChange = React3.useCallback(
1971
1981
  (e) => {
1972
1982
  const inputValue = e.target.value;
@@ -1988,22 +1998,28 @@ var init_NumberInput = __esm({
1988
1998
  const parsed = parseValue(trimmedValue);
1989
1999
  if (parsed !== null) {
1990
2000
  const preciseValue = applyPrecision(parsed);
1991
- handleValueChange(preciseValue);
2001
+ const finalValue = extendedValueMap && preciseValue !== void 0 ? snapToStep(preciseValue, extendedValueMap) : preciseValue;
2002
+ handleValueChange(finalValue);
1992
2003
  } else {
1993
2004
  setDisplayValue(formatValue(value));
1994
2005
  }
1995
2006
  }
1996
2007
  onBlurProp?.(e);
1997
2008
  },
1998
- [displayValue, parseValue, handleValueChange, value, formatValue, applyPrecision, onBlurProp]
2009
+ [displayValue, parseValue, handleValueChange, value, formatValue, applyPrecision, onBlurProp, extendedValueMap]
1999
2010
  );
2000
2011
  const handleFocus = React3.useCallback(
2001
2012
  (e) => {
2002
2013
  setIsFocused(true);
2003
2014
  setDisplayValue(formatValueForEdit(value));
2015
+ if (selectAllOnFocus) {
2016
+ requestAnimationFrame(() => {
2017
+ inputRef.current?.select();
2018
+ });
2019
+ }
2004
2020
  onFocusProp?.(e);
2005
2021
  },
2006
- [value, formatValueForEdit, onFocusProp]
2022
+ [value, formatValueForEdit, onFocusProp, selectAllOnFocus]
2007
2023
  );
2008
2024
  const handleKeyDown = React3.useCallback(
2009
2025
  (e) => {
@@ -2015,9 +2031,11 @@ var init_NumberInput = __esm({
2015
2031
  decrement();
2016
2032
  } else if (e.key === "Enter") {
2017
2033
  inputRef.current?.blur();
2034
+ } else if (e.key === "Escape" && blurOnEscape) {
2035
+ inputRef.current?.blur();
2018
2036
  }
2019
2037
  },
2020
- [increment, decrement]
2038
+ [increment, decrement, blurOnEscape]
2021
2039
  );
2022
2040
  const handleMouseEnter = React3.useCallback(() => {
2023
2041
  setIsHovered(true);
@@ -2120,6 +2138,7 @@ var init_SpinButton = __esm({
2120
2138
  precision,
2121
2139
  formatter,
2122
2140
  parser,
2141
+ valueMap,
2123
2142
  onChange,
2124
2143
  className,
2125
2144
  style,
@@ -2149,6 +2168,7 @@ var init_SpinButton = __esm({
2149
2168
  max,
2150
2169
  step,
2151
2170
  disabled,
2171
+ valueMap,
2152
2172
  onChange: handleValueChange
2153
2173
  }
2154
2174
  )), /* @__PURE__ */ React3__default.default.createElement(
@@ -2164,6 +2184,7 @@ var init_SpinButton = __esm({
2164
2184
  precision,
2165
2185
  formatter,
2166
2186
  parser,
2187
+ valueMap,
2167
2188
  ...inputProps,
2168
2189
  onChange: handleValueChange
2169
2190
  }