@oliasoft-open-source/react-ui-library 4.12.0-beta-2 → 4.12.0-beta-4

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.
Files changed (58) hide show
  1. package/dist/index.d.ts +6 -2
  2. package/dist/index.js +143 -139
  3. package/dist/index.js.map +1 -1
  4. package/dist/storybook/assets/{Color-KGDBMAHA-BODMLRvZ.js → Color-KGDBMAHA-Bnj89L-A.js} +1 -1
  5. package/dist/storybook/assets/{DocsRenderer-PKQXORMH-DEi7ICVq.js → DocsRenderer-PKQXORMH-QUJl5DIT.js} +1 -1
  6. package/dist/storybook/assets/{accordion.stories-C_Vx7GEC.js → accordion.stories-BlHfHegj.js} +1 -1
  7. package/dist/storybook/assets/{afe.stories-OEYJqexC.js → afe.stories-C9XjJj62.js} +1 -1
  8. package/dist/storybook/assets/{buttons-and-links-BHNS6Ebw.js → buttons-and-links-CzMplQyX.js} +1 -1
  9. package/dist/storybook/assets/{casing-loads.stories-BAdZ87Oc.js → casing-loads.stories-Cl2tJipP.js} +1 -1
  10. package/dist/storybook/assets/{cell.stories-Bu5u9qEl.js → cell.stories-rzJE_qJC.js} +1 -1
  11. package/dist/storybook/assets/{chunk-HLWAVYOI-BbzmrmoZ.js → chunk-HLWAVYOI-BzjfwAFt.js} +1 -1
  12. package/dist/storybook/assets/{color-oeF0-Pph.js → color-DMI_LL9Y.js} +1 -1
  13. package/dist/storybook/assets/{footer.stories-LUxEpSgD.js → footer.stories-C6M5S0UZ.js} +1 -1
  14. package/dist/storybook/assets/{form.stories-B7V77yuI.js → form.stories-BNORsn6Z.js} +1 -1
  15. package/dist/storybook/assets/{formation.stories-D7MX0dSY.js → formation.stories-1WX1Nu1P.js} +1 -1
  16. package/dist/storybook/assets/{iframe-nuCPRPrd.js → iframe-D7uA6LlZ.js} +2 -2
  17. package/dist/storybook/assets/{index-CN6H1a0D.js → index-BL00YxVv.js} +1 -1
  18. package/dist/storybook/assets/{index-BFtO1KgR.js → index-CDbixbhF.js} +4 -4
  19. package/dist/storybook/assets/{initialize-context-rEvM6bdZ.js → initialize-context-Y03pJPr5.js} +1 -1
  20. package/dist/storybook/assets/{input-group.stories-BdQ1prY4.js → input-group.stories-BCajsqAk.js} +1 -1
  21. package/dist/storybook/assets/{input-validation-Ccu8WMpy.js → input-validation-D-Ft5BCF.js} +1 -1
  22. package/dist/storybook/assets/{inputs-C4fsY4Ua.js → inputs-cQ55JAoI.js} +1 -1
  23. package/dist/storybook/assets/{layout-forms-DOgsanng.js → layout-forms-Bvrdok9B.js} +1 -1
  24. package/dist/storybook/assets/{layout-general-DtDx77FI.js → layout-general-Cg0gSZB3.js} +1 -1
  25. package/dist/storybook/assets/menu.test-case.stories-XN9XFV-D.js +3 -0
  26. package/dist/storybook/assets/{modal.stories-DUXRRhK-.js → modal.stories-C2d-Em5V.js} +1 -1
  27. package/dist/storybook/assets/{number-input-CNnU6gOF.js → number-input-B3_gmeWr.js} +1 -1
  28. package/dist/storybook/assets/{number-input.stories-Bo26PJmJ.js → number-input.stories-epjUq9ve.js} +1 -1
  29. package/dist/storybook/assets/number-input.test-case.stories-DeEtalIU.js +95 -0
  30. package/dist/storybook/assets/{padding-and-spacing-Mfm_1hn5.js → padding-and-spacing-DDAtfb-b.js} +1 -1
  31. package/dist/storybook/assets/{pagination-CoyQUC4R.js → pagination-CR1nxnnq.js} +1 -1
  32. package/dist/storybook/assets/{pagination.stories-qfpnU8DC.js → pagination.stories-qXmBYwYc.js} +1 -1
  33. package/dist/storybook/assets/{popover.stories-TwNkFkWa.js → popover.stories-DZTfimDf.js} +1 -1
  34. package/dist/storybook/assets/{preview-DVjsIOwK.js → preview-CUJNe5HT.js} +1 -1
  35. package/dist/storybook/assets/{preview-BIv_KaBF.js → preview-Rrrgw5d3.js} +2 -2
  36. package/dist/storybook/assets/{reservoirs.stories-DE9FrS0f.js → reservoirs.stories-r1Ip90kJ.js} +1 -1
  37. package/dist/storybook/assets/{rich-text-input.stories-BNwcnp92.js → rich-text-input.stories-DwaseXZv.js} +1 -1
  38. package/dist/storybook/assets/{row.stories-D3Bnp8i4.js → row.stories-DRvH8Grn.js} +1 -1
  39. package/dist/storybook/assets/select-Cwks-WA0.js +61 -0
  40. package/dist/storybook/assets/{select.stories-BRGk9iYK.js → select.stories-DjGSNDXK.js} +1 -1
  41. package/dist/storybook/assets/select.test-case.stories-CrXzt4qn.js +82 -0
  42. package/dist/storybook/assets/{table-DPbEkZqw.js → table-DoyDBG6l.js} +1 -1
  43. package/dist/storybook/assets/{table.stories-BBzqpsyH.js → table.stories-BgWKzIob.js} +1 -1
  44. package/dist/storybook/assets/{title.stories-B4PYbA22.js → title.stories-Rv6ZO_Wl.js} +1 -1
  45. package/dist/storybook/assets/unit-input-C07ZKMj5.js +10 -0
  46. package/dist/storybook/assets/{unit-input.stories-CChVbxmI.js → unit-input.stories-BP03WTYV.js} +1 -1
  47. package/dist/storybook/assets/{unit-input.test-case.stories-BeFM9DuK.js → unit-input.test-case.stories-D9PyN8YI.js} +1 -1
  48. package/dist/storybook/assets/{unit-table.stories-9x5S71wv.js → unit-table.stories-CISvZMxX.js} +1 -1
  49. package/dist/storybook/assets/{unit-table.test-case.stories-DZJ-hZ72.js → unit-table.test-case.stories-tEype9om.js} +1 -1
  50. package/dist/storybook/iframe.html +1 -1
  51. package/dist/storybook/index.json +1 -1
  52. package/dist/storybook/project.json +1 -1
  53. package/package.json +1 -1
  54. package/dist/storybook/assets/menu.test-case.stories-W-jG-Jk8.js +0 -3
  55. package/dist/storybook/assets/number-input.test-case.stories-CHGSaGbj.js +0 -92
  56. package/dist/storybook/assets/select-BQzJMnK1.js +0 -61
  57. package/dist/storybook/assets/select.test-case.stories-BYMK9M8u.js +0 -82
  58. package/dist/storybook/assets/unit-input-Byipu-z0.js +0 -10
package/dist/index.d.ts CHANGED
@@ -1569,13 +1569,17 @@ export declare interface IUnitInputProps {
1569
1569
  unitkey?: string;
1570
1570
  initUnit?: string;
1571
1571
  noConversion?: boolean;
1572
+ doNotConvertValue?: boolean;
1572
1573
  testId?: string;
1573
1574
  warning?: string | boolean | null;
1574
1575
  predefinedOptions?: IPredefinedOption[] | null;
1575
- initialPredefinedOption?: string;
1576
+ initialPredefinedOption?: boolean;
1577
+ shouldLinkAutomaticly?: boolean;
1578
+ selectedPredefinedOptionKey?: string;
1576
1579
  validationCallback?: (name: string, error: string | null) => any;
1577
1580
  disabledValidation?: boolean;
1578
1581
  allowEmpty?: boolean;
1582
+ autoValue?: string;
1579
1583
  onChange?: (event: TChangeEvent | ICustomChangeEvent) => void;
1580
1584
  onSwitchUnit?: (unit: string) => void;
1581
1585
  onClick?: MouseEventHandler<HTMLInputElement>;
@@ -1861,7 +1865,7 @@ declare type TUnitTableCellShape = TCellShape | IUnitTableStaticCell | IUnitTabl
1861
1865
 
1862
1866
  declare type UnitContextType = any;
1863
1867
 
1864
- export declare const UnitInput: ({ name, placeholder, disabled, disabledUnit, error, left, small, width, value, unitkey, initUnit, noConversion, onChange, onClick, onFocus, onSwitchUnit, unitTemplate, testId, warning, predefinedOptions, initialPredefinedOption, validationCallback, disabledValidation, allowEmpty, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitInputProps) => JSX_2.Element;
1868
+ export declare const UnitInput: ({ name, placeholder, disabled, disabledUnit, error, left, small, width, value, unitkey, initUnit, noConversion, onChange, onClick, onFocus, onSwitchUnit, unitTemplate, doNotConvertValue, testId, warning, predefinedOptions, initialPredefinedOption, shouldLinkAutomaticly, selectedPredefinedOptionKey, validationCallback, disabledValidation, allowEmpty, autoValue, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitInputProps) => JSX_2.Element;
1865
1869
 
1866
1870
  export declare const UnitTable: ({ table, unitConfig, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitTableProps) => JSX_2.Element;
1867
1871
 
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import * as PropTypes from "prop-types";
16
16
  import PropTypes__default from "prop-types";
17
17
  import ReactDOM, { createPortal, unstable_batchedUpdates, render } from "react-dom";
18
18
  import { noop as noop$3, set, get as get$2, isString as isString$3, isNumber as isNumber$1, isBoolean as isBoolean$2, isFunction as isFunction$3, isEmpty, isArray as isArray$1, toNumber, debounce as debounce$2, isObject as isObject$5, isEqual as isEqual$4 } from "lodash";
19
- import { toString as toString$1, isScientificStringNum, roundToPrecision, toNum, roundToFixed, validateNumber, cleanNumStr, stripLeadingZeros, unitFromQuantity, getUnit, ALT_UNITS, isValueWithUnit, getValue as getValue$1, withUnit, convertSamePrecision, convertAndGetValue, KNOWN_UNITS, split as split$1, label as label$b, isValidNum, getAltUnitsListByQuantity, altUnitsList, getUnitsForQuantity, roundByMagnitudeToFixed } from "@oliasoft-open-source/units";
19
+ import { toString as toString$1, isScientificStringNum, roundToPrecision, toNum, roundToFixed, validateNumber, cleanNumStr, stripLeadingZeros, unitFromQuantity, getUnit, KNOWN_UNITS, ALT_UNITS, isValueWithUnit, getValue as getValue$1, withUnit, convertSamePrecision, convertAndGetValue, split as split$1, label as label$b, isValidNum, getAltUnitsListByQuantity, altUnitsList, getUnitsForQuantity, roundByMagnitudeToFixed } from "@oliasoft-open-source/units";
20
20
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
21
21
  function getDefaultExportFromCjs(x2) {
22
22
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
@@ -55652,6 +55652,10 @@ const NumberInput = ({
55652
55652
  const validateInputValue = (value2) => {
55653
55653
  const validation = validateNumber(value2);
55654
55654
  const isPlaceholder = placeholder3 && isEmptyNullOrUndefined(value2);
55655
+ const isInfinity = [Infinity, -Infinity].includes(Number(value2));
55656
+ if (isInfinity) {
55657
+ return { valid: true, errors: [] };
55658
+ }
55655
55659
  if (isPlaceholder) {
55656
55660
  return { valid: true, errors: [] };
55657
55661
  }
@@ -70138,7 +70142,8 @@ const isWrongValue = (val) => {
70138
70142
  };
70139
70143
  const isValueWithUnknownUnit = (value) => {
70140
70144
  if (!value) return false;
70141
- return Boolean(getUnit(value));
70145
+ const unit2 = getUnit(value);
70146
+ return !KNOWN_UNITS.includes(unit2);
70142
70147
  };
70143
70148
  const checkConversion = ({
70144
70149
  value,
@@ -70202,13 +70207,15 @@ const safeConvertValue = ({
70202
70207
  defaultFromUnit,
70203
70208
  doNotConvertValue
70204
70209
  }) => {
70205
- const isWithUnit = isValueWithUnknownUnit(value) || isValueWithUnit(value);
70206
70210
  const rawValue = getValue$1(value);
70207
70211
  const isInvalidInput = isWrongValue(rawValue);
70212
+ if (isValueWithUnknownUnit(value)) {
70213
+ return { value: rawValue };
70214
+ }
70208
70215
  if (isInvalidInput) {
70209
70216
  return { value: rawValue };
70210
70217
  }
70211
- if (!isWithUnit) {
70218
+ if (!isValueWithUnit(value)) {
70212
70219
  return { value };
70213
70220
  }
70214
70221
  return convertUnit({
@@ -70245,109 +70252,6 @@ const initializeContext = (context2) => {
70245
70252
  UnitContext = context2;
70246
70253
  }
70247
70254
  };
70248
- const PredefinedOptionsMenu = ({
70249
- predefinedOptions,
70250
- value = "",
70251
- onPredefinedOptionSelect,
70252
- disabled: disabled2,
70253
- initialPredefinedOption,
70254
- predefinedOptionsMenuState,
70255
- setPredefinedOptionsMenuState,
70256
- testId
70257
- }) => {
70258
- const extractedValue = isValueWithUnit(value) ? getValue$1(value) : value;
70259
- const [foundPredefinedMenuOption, setFoundPredefinedMenuOption] = useState(void 0);
70260
- const createPredefinedOption = (el2) => {
70261
- const elementValue = (el2 == null ? void 0 : el2.value) ? el2.value : "";
70262
- const [inputValue = "", unit2 = ""] = isValueWithUnit(elementValue) ? split$1(elementValue) : [elementValue];
70263
- return {
70264
- type: MenuType.OPTION,
70265
- inline: true,
70266
- onClick: () => {
70267
- const validation = validateNumber(inputValue);
70268
- if (validation.valid && !disabled2) {
70269
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70270
- onPredefinedOptionSelect(elementValue);
70271
- setFoundPredefinedMenuOption(el2);
70272
- }
70273
- },
70274
- label: /* @__PURE__ */ jsxs(Fragment$1, { children: [
70275
- /* @__PURE__ */ jsx(Text, { children: el2.label }),
70276
- /* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
70277
- ] }),
70278
- description: isValueWithUnit(elementValue) ? `${inputValue} ${unit2}` : elementValue,
70279
- selected: extractedValue === elementValue && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
70280
- };
70281
- };
70282
- const initialPredefinedOptionObject = useMemo$1(() => {
70283
- return predefinedOptions.find(
70284
- (option2) => option2.value === initialPredefinedOption || option2.label === initialPredefinedOption || option2.valueKey === initialPredefinedOption
70285
- );
70286
- }, [initialPredefinedOption, predefinedOptions]);
70287
- useEffect(() => {
70288
- if (initialPredefinedOptionObject) {
70289
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70290
- setFoundPredefinedMenuOption(initialPredefinedOptionObject);
70291
- onPredefinedOptionSelect(initialPredefinedOptionObject.value);
70292
- }
70293
- }, [initialPredefinedOptionObject]);
70294
- useEffect(() => {
70295
- const foundOption = predefinedOptions.find((option2) => {
70296
- const currentValue = isValueWithUnit((option2 == null ? void 0 : option2.value) ?? "") ? getValue$1((option2 == null ? void 0 : option2.value) ?? "") : option2.value;
70297
- return currentValue === extractedValue;
70298
- });
70299
- if (foundOption) {
70300
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70301
- setFoundPredefinedMenuOption(foundOption);
70302
- } else {
70303
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
70304
- setFoundPredefinedMenuOption(void 0);
70305
- }
70306
- }, [extractedValue, predefinedOptions]);
70307
- const sectionsPredefinedMenu = [
70308
- {
70309
- type: MenuType.OPTION,
70310
- inline: true,
70311
- onClick: () => {
70312
- if (!disabled2) {
70313
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
70314
- }
70315
- },
70316
- label: "Custom",
70317
- selected: predefinedOptionsMenuState === PredefinedOptionsMenuState.CUSTOM
70318
- },
70319
- ...predefinedOptions.map(createPredefinedOption)
70320
- ];
70321
- return /* @__PURE__ */ jsx(
70322
- Tooltip,
70323
- {
70324
- text: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? foundPredefinedMenuOption == null ? void 0 : foundPredefinedMenuOption.label : "",
70325
- children: /* @__PURE__ */ jsx(
70326
- Menu,
70327
- {
70328
- testId: testId && `${testId}-predefined-menu`,
70329
- maxHeight: 380,
70330
- groupOrder: "first",
70331
- disabled: disabled2,
70332
- menu: {
70333
- colored: true,
70334
- trigger: "Component",
70335
- component: /* @__PURE__ */ jsx(
70336
- Button$1,
70337
- {
70338
- groupOrder: "first",
70339
- active: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED,
70340
- icon: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? "link" : "unlink"
70341
- }
70342
- ),
70343
- small: true,
70344
- sections: sectionsPredefinedMenu
70345
- }
70346
- }
70347
- )
70348
- }
70349
- );
70350
- };
70351
70255
  const predefinedMenuActive = "_predefinedMenuActive_ye9w9_1";
70352
70256
  const inputWrapper = "_inputWrapper_ye9w9_4";
70353
70257
  const styles = {
@@ -70372,24 +70276,28 @@ const UnitInput = ({
70372
70276
  onFocus = noop$3,
70373
70277
  onSwitchUnit = noop$3,
70374
70278
  unitTemplate,
70279
+ doNotConvertValue = false,
70375
70280
  testId,
70376
70281
  warning: warning2 = null,
70377
70282
  predefinedOptions,
70378
- initialPredefinedOption = "",
70283
+ initialPredefinedOption = false,
70284
+ shouldLinkAutomaticly = true,
70285
+ selectedPredefinedOptionKey,
70379
70286
  validationCallback = () => ({ name: "", error: null }),
70380
70287
  disabledValidation = false,
70381
70288
  allowEmpty = false,
70289
+ autoValue,
70382
70290
  convertBackToStorageUnit = false,
70383
70291
  enableCosmeticRounding = true,
70384
70292
  enableDisplayRounding = false
70385
70293
  }) => {
70386
70294
  const context2 = useUnitContext();
70387
70295
  const runAfterUpdate = useRunAfterUpdate();
70388
- const [predefinedOptionsMenuState, setPredefinedOptionsMenuState] = useState(PredefinedOptionsMenuState.CUSTOM);
70389
70296
  if (typeof value === "number") {
70390
70297
  value = `${value}`;
70391
70298
  }
70392
70299
  const [propValue = "", propUnit = ""] = value !== void 0 ? split$1(value) : [];
70300
+ const propAutoUnit = autoValue ? getUnit(autoValue) : "";
70393
70301
  const preferredUnit = useMemo$1(
70394
70302
  () => getPreferredUnit(unitkey, unitTemplate || (context2 == null ? void 0 : context2.unitTemplate)),
70395
70303
  [unitkey, unitTemplate, context2 == null ? void 0 : context2.unitTemplate]
@@ -70402,14 +70310,38 @@ const UnitInput = ({
70402
70310
  toUnit: initDisplayUnit,
70403
70311
  unitkey,
70404
70312
  defaultFromUnit: propUnit,
70405
- doNotConvertValue: noConversion
70313
+ doNotConvertValue
70406
70314
  });
70407
- const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
70315
+ const { value: convertedAutoValue } = safeConvertValue({
70316
+ value: autoValue,
70317
+ toUnit: initDisplayUnit,
70318
+ unitkey,
70319
+ defaultFromUnit: propAutoUnit,
70320
+ doNotConvertValue
70321
+ });
70322
+ const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : convertedAutoValue !== "" ? { value: convertedAutoValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
70408
70323
  const [displayLayer, setDisplayLayer] = useState(initDisplayLayer);
70409
70324
  const derivedAllowEmpty = allowEmpty || (displayLayer == null ? void 0 : displayLayer.value) === void 0;
70410
- const disableInternalErrorValidationMessages = !!disabledValidation;
70325
+ const [predefinedOptionsMenuState, setPredefinedOptionsMenuState] = useState(
70326
+ initialPredefinedOption ? PredefinedOptionsMenuState.PREDEFINED : PredefinedOptionsMenuState.CUSTOM
70327
+ );
70328
+ const isAutoValue = propValue === "" && autoValue;
70329
+ const disableInternalErrorValidationMessages = !!(disabledValidation || autoValue);
70330
+ const foundPredefinedMenuOption = predefinedOptions && predefinedOptions.find((el2) => {
70331
+ if (!(el2 == null ? void 0 : el2.value)) return;
70332
+ if (selectedPredefinedOptionKey) {
70333
+ return selectedPredefinedOptionKey === el2.valueKey;
70334
+ }
70335
+ const predefinedMenuItemUnit = isValueWithUnit(el2.value) ? getUnit(el2.value) : "";
70336
+ const { value: resultValue = value } = convertUnit({
70337
+ value: String(value),
70338
+ unitkey,
70339
+ toUnit: predefinedMenuItemUnit
70340
+ });
70341
+ return withUnit(resultValue, predefinedMenuItemUnit) === el2.value;
70342
+ });
70411
70343
  const getAlternativeUnits = () => {
70412
- const valueToList = value ?? "";
70344
+ const valueToList = isAutoValue ? autoValue : value ?? "";
70413
70345
  const initToUnit = displayLayer.unit;
70414
70346
  const shouldConvert = checkConversion({
70415
70347
  value: valueToList,
@@ -70468,7 +70400,7 @@ const UnitInput = ({
70468
70400
  toUnit: initDisplayUnit,
70469
70401
  unitkey,
70470
70402
  defaultFromUnit: propUnit,
70471
- doNotConvertValue: noConversion
70403
+ doNotConvertValue
70472
70404
  });
70473
70405
  newValue = resultValue;
70474
70406
  newUnit = initDisplayUnit;
@@ -70478,29 +70410,96 @@ const UnitInput = ({
70478
70410
  toUnit: displayLayer.unit,
70479
70411
  unitkey,
70480
70412
  defaultFromUnit: propUnit,
70481
- doNotConvertValue: noConversion
70413
+ doNotConvertValue
70482
70414
  });
70483
70415
  newValue = resultValue;
70484
70416
  newUnit = displayLayer.unit;
70485
70417
  }
70486
- if (newValue !== void 0 && !initialPredefinedOption) {
70418
+ if (newValue !== void 0) {
70487
70419
  setDisplayLayer({ value: newValue, unit: newUnit });
70488
70420
  }
70421
+ if (predefinedOptions) {
70422
+ if (foundPredefinedMenuOption && shouldLinkAutomaticly) {
70423
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70424
+ } else {
70425
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
70426
+ }
70427
+ }
70489
70428
  }
70490
- }, [initDisplayUnit, value, error2]);
70429
+ }, [initDisplayUnit, value, error2, shouldLinkAutomaticly]);
70491
70430
  const alternativeUnits = getAlternativeUnits();
70492
70431
  const displayUnitLabel = label$b(displayLayer.unit) || displayLayer.unit || "";
70493
70432
  const noConvert = noConversion || !alternativeUnits || alternativeUnits && alternativeUnits.length === 1;
70494
70433
  const stringName = getStringName(name2);
70434
+ let sectionsPredefinedMenu;
70435
+ const createPredefinedOption = (el2) => {
70436
+ const elementValue = (el2 == null ? void 0 : el2.value) ? el2.value : "";
70437
+ const [value2 = "", unit2 = ""] = isValueWithUnit(elementValue) ? split$1(elementValue) : [elementValue];
70438
+ return {
70439
+ type: MenuType.OPTION,
70440
+ inline: true,
70441
+ onClick: () => {
70442
+ const validation = validateNumber(value2);
70443
+ if (validation.valid && !disabled2) {
70444
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70445
+ onChange({
70446
+ target: {
70447
+ value: elementValue,
70448
+ name: typeof name2 === "string" ? name2 : (name2 == null ? void 0 : name2.fieldName) || "",
70449
+ predefinedSelected: true,
70450
+ predefinedOption: el2
70451
+ }
70452
+ });
70453
+ }
70454
+ },
70455
+ label: /* @__PURE__ */ jsxs(Fragment$1, { children: [
70456
+ /* @__PURE__ */ jsx(Text, { children: el2.label }),
70457
+ /* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
70458
+ ] }),
70459
+ description: isValueWithUnit(elementValue) ? `${value2} ${unit2}` : elementValue,
70460
+ selected: foundPredefinedMenuOption === el2 && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
70461
+ };
70462
+ };
70463
+ sectionsPredefinedMenu = [
70464
+ {
70465
+ type: MenuType.OPTION,
70466
+ inline: true,
70467
+ onClick: () => {
70468
+ if (predefinedOptionsMenuState !== PredefinedOptionsMenuState.CUSTOM && !disabled2) {
70469
+ onChange({
70470
+ target: {
70471
+ value: withUnit(displayLayer.value, displayLayer.unit),
70472
+ name: typeof name2 === "string" ? name2 : (name2 == null ? void 0 : name2.fieldName) || ""
70473
+ }
70474
+ });
70475
+ }
70476
+ },
70477
+ label: "Custom",
70478
+ selected: predefinedOptionsMenuState === PredefinedOptionsMenuState.CUSTOM
70479
+ }
70480
+ ];
70481
+ if (predefinedOptions == null ? void 0 : predefinedOptions.length) {
70482
+ const dynamicOptions = predefinedOptions.map(createPredefinedOption);
70483
+ sectionsPredefinedMenu = [...sectionsPredefinedMenu, ...dynamicOptions];
70484
+ }
70495
70485
  const getPlaceholder = (placeholder22) => {
70496
- if (isValueWithUnit(placeholder22)) {
70486
+ if (isAutoValue) {
70487
+ const { value: resultValue } = safeConvertValue({
70488
+ value: autoValue,
70489
+ toUnit: displayLayer.unit,
70490
+ unitkey,
70491
+ defaultFromUnit: propAutoUnit,
70492
+ doNotConvertValue
70493
+ });
70494
+ return resultValue;
70495
+ } else if (isValueWithUnit(placeholder22)) {
70497
70496
  const placeholderUnit = getUnit(placeholder22);
70498
70497
  const { value: resultValue } = safeConvertValue({
70499
70498
  value: placeholder22,
70500
70499
  toUnit: displayLayer.unit,
70501
70500
  unitkey,
70502
70501
  defaultFromUnit: placeholderUnit,
70503
- doNotConvertValue: noConversion
70502
+ doNotConvertValue
70504
70503
  });
70505
70504
  return resultValue;
70506
70505
  }
@@ -70512,27 +70511,32 @@ const UnitInput = ({
70512
70511
  className: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? cx$2(styles.predefinedMenuActive) : "",
70513
70512
  children: /* @__PURE__ */ jsxs(InputGroup, { small: small2, width: width2, children: [
70514
70513
  predefinedOptions && /* @__PURE__ */ jsx(
70515
- PredefinedOptionsMenu,
70514
+ Tooltip,
70516
70515
  {
70517
- testId,
70518
- predefinedOptions,
70519
- value: displayLayer.value,
70520
- onPredefinedOptionSelect: (newValue) => {
70521
- onChange({
70522
- target: {
70523
- value: newValue,
70524
- name: stringName
70516
+ text: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? foundPredefinedMenuOption == null ? void 0 : foundPredefinedMenuOption.label : "",
70517
+ children: /* @__PURE__ */ jsx(
70518
+ Menu,
70519
+ {
70520
+ maxHeight: 380,
70521
+ groupOrder: "first",
70522
+ testId: testId && `${testId}-predefined-menu`,
70523
+ disabled: disabled2,
70524
+ menu: {
70525
+ colored: true,
70526
+ trigger: "Component",
70527
+ component: /* @__PURE__ */ jsx(
70528
+ Button$1,
70529
+ {
70530
+ groupOrder: "first",
70531
+ active: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED,
70532
+ icon: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? "link" : "unlink"
70533
+ }
70534
+ ),
70535
+ small: small2,
70536
+ sections: sectionsPredefinedMenu
70525
70537
  }
70526
- });
70527
- setDisplayLayer({
70528
- value: newValue,
70529
- unit: getUnit(newValue) || displayLayer.unit
70530
- });
70531
- },
70532
- disabled: disabled2,
70533
- initialPredefinedOption,
70534
- predefinedOptionsMenuState,
70535
- setPredefinedOptionsMenuState
70538
+ }
70539
+ )
70536
70540
  }
70537
70541
  ),
70538
70542
  /* @__PURE__ */ jsx("div", { className: styles.inputWrapper, children: /* @__PURE__ */ jsx(
@@ -70579,7 +70583,7 @@ const UnitInput = ({
70579
70583
  inline: true,
70580
70584
  onClick: (evt) => {
70581
70585
  evt.stopPropagation();
70582
- onClickUnit(value2, altUnit);
70586
+ onClickUnit(isAutoValue ? "" : value2, altUnit);
70583
70587
  },
70584
70588
  description: displayUnit,
70585
70589
  selected: displayUnit === displayUnitLabel,