@oliasoft-open-source/react-ui-library 4.13.0 → 4.14.0-beta-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/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import React__default, { useContext, isValidElement, useState, useRef, useEffect
15
15
  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
- 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";
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, isNil, isEqual as isEqual$4 } from "lodash";
19
19
  import { toString as toString$1, isScientificStringNum, roundToPrecision, toNum, validateNumber, cleanNumStr, stripLeadingZeros, roundToFixed, roundByMagnitude, 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) {
@@ -4181,34 +4181,34 @@ const styles$M = {
4181
4181
  actionComponentContainer,
4182
4182
  active: active$7
4183
4183
  };
4184
- const wrapper$4 = "_wrapper_1f7k2_1";
4185
- const layer$1 = "_layer_1f7k2_5";
4186
- const layerContainer$1 = "_layerContainer_1f7k2_8";
4187
- const nested = "_nested_1f7k2_24";
4188
- const fileInput$1 = "_fileInput_1f7k2_36";
4189
- const trigger$2 = "_trigger_1f7k2_41";
4190
- const middleAlignedInline = "_middleAlignedInline_1f7k2_50";
4191
- const heading$5 = "_heading_1f7k2_56";
4192
- const headingIcon = "_headingIcon_1f7k2_62";
4193
- const option$1 = "_option_1f7k2_74";
4194
- const active$6 = "_active_1f7k2_93";
4195
- const selected$1 = "_selected_1f7k2_98";
4196
- const optionContent$1 = "_optionContent_1f7k2_104";
4197
- const inline$4 = "_inline_1f7k2_108";
4198
- const icon$4 = "_icon_1f7k2_113";
4199
- const check$1 = "_check_1f7k2_114";
4200
- const text$3 = "_text_1f7k2_140";
4201
- const label$a = "_label_1f7k2_145";
4202
- const description = "_description_1f7k2_156";
4203
- const arrow$1 = "_arrow_1f7k2_160";
4204
- const divider$1 = "_divider_1f7k2_164";
4205
- const deprecatedSemanticIcon = "_deprecatedSemanticIcon_1f7k2_168";
4206
- const disabled$8 = "_disabled_1f7k2_172";
4207
- const buttonLabel = "_buttonLabel_1f7k2_177";
4208
- const buttonCaret = "_buttonCaret_1f7k2_183";
4209
- const component = "_component_1f7k2_187";
4210
- const right$7 = "_right_1f7k2_193";
4211
- const actions$1 = "_actions_1f7k2_198";
4184
+ const wrapper$4 = "_wrapper_8cxhw_1";
4185
+ const layer$1 = "_layer_8cxhw_5";
4186
+ const layerContainer$1 = "_layerContainer_8cxhw_8";
4187
+ const nested = "_nested_8cxhw_24";
4188
+ const fileInput$1 = "_fileInput_8cxhw_36";
4189
+ const trigger$2 = "_trigger_8cxhw_41";
4190
+ const middleAlignedInline = "_middleAlignedInline_8cxhw_50";
4191
+ const heading$5 = "_heading_8cxhw_56";
4192
+ const headingIcon = "_headingIcon_8cxhw_62";
4193
+ const option$1 = "_option_8cxhw_74";
4194
+ const active$6 = "_active_8cxhw_93";
4195
+ const selected$1 = "_selected_8cxhw_98";
4196
+ const optionContent$1 = "_optionContent_8cxhw_105";
4197
+ const inline$4 = "_inline_8cxhw_109";
4198
+ const icon$4 = "_icon_8cxhw_114";
4199
+ const check$1 = "_check_8cxhw_115";
4200
+ const text$3 = "_text_8cxhw_141";
4201
+ const label$a = "_label_8cxhw_146";
4202
+ const description = "_description_8cxhw_157";
4203
+ const arrow$1 = "_arrow_8cxhw_161";
4204
+ const divider$1 = "_divider_8cxhw_165";
4205
+ const deprecatedSemanticIcon = "_deprecatedSemanticIcon_8cxhw_169";
4206
+ const disabled$8 = "_disabled_8cxhw_173";
4207
+ const buttonLabel = "_buttonLabel_8cxhw_178";
4208
+ const buttonCaret = "_buttonCaret_8cxhw_184";
4209
+ const component = "_component_8cxhw_188";
4210
+ const right$7 = "_right_8cxhw_194";
4211
+ const actions$1 = "_actions_8cxhw_199";
4212
4212
  const styles$L = {
4213
4213
  wrapper: wrapper$4,
4214
4214
  layer: layer$1,
@@ -4354,6 +4354,7 @@ const Section$1 = ({
4354
4354
  path,
4355
4355
  maxHeight
4356
4356
  }) => {
4357
+ var _a2, _b;
4357
4358
  const disabledContext = useContext(DisabledContext);
4358
4359
  switch (section2.type) {
4359
4360
  case MenuType.HEADING:
@@ -4391,10 +4392,14 @@ const Section$1 = ({
4391
4392
  }
4392
4393
  );
4393
4394
  case MenuType.MENU:
4395
+ const selected2 = !!((_b = (_a2 = section2 == null ? void 0 : section2.menu) == null ? void 0 : _a2.sections) == null ? void 0 : _b.find(
4396
+ (s) => s.selected
4397
+ ));
4394
4398
  return /* @__PURE__ */ jsx(
4395
4399
  DropDownMenu,
4396
4400
  {
4397
4401
  menu: section2.menu,
4402
+ selected: selected2,
4398
4403
  title: section2.title,
4399
4404
  closeOnOptionClick,
4400
4405
  isNested: true,
@@ -4597,7 +4602,8 @@ const Text$1 = ({
4597
4602
  title: title2,
4598
4603
  carat,
4599
4604
  disabled: disabled2,
4600
- isOpen: isOpen2
4605
+ isOpen: isOpen2,
4606
+ selected: selected2
4601
4607
  }) => {
4602
4608
  let titleText;
4603
4609
  if (title2) {
@@ -4611,7 +4617,8 @@ const Text$1 = ({
4611
4617
  className: cx$2(
4612
4618
  styles$L.trigger,
4613
4619
  disabled2 ? styles$L.disabled : null,
4614
- isOpen2 ? styles$L.active : null
4620
+ isOpen2 ? styles$L.active : null,
4621
+ selected2 ? styles$L.selected : null
4615
4622
  ),
4616
4623
  children: [
4617
4624
  /* @__PURE__ */ jsx("span", { className: styles$L.label, title: titleText, children: label2 }),
@@ -4677,6 +4684,7 @@ const Trigger$1 = React__default.forwardRef(
4677
4684
  warning: warning2,
4678
4685
  tooltip: tooltip2,
4679
4686
  testId,
4687
+ selected: selected2,
4680
4688
  ...restProps
4681
4689
  }, ref2) => {
4682
4690
  const triggerElement = trigger2 === TriggerType.BUTTON || trigger2 === TriggerType.DROP_DOWN_BUTTON ? /* @__PURE__ */ jsx(
@@ -4701,7 +4709,8 @@ const Trigger$1 = React__default.forwardRef(
4701
4709
  title: title2,
4702
4710
  disabled: isDisabled,
4703
4711
  carat: !contextMenu ? isNested ? MenuCarat.RIGHT : MenuCarat.DOWN : void 0,
4704
- isOpen: isOpen2
4712
+ isOpen: isOpen2,
4713
+ selected: selected2
4705
4714
  }
4706
4715
  ) : trigger2 === TriggerType.COMPONENT ? /* @__PURE__ */ jsx(Component, { component: component2, disabled: isDisabled }) : null;
4707
4716
  const wrappedTrigger = !isNested && (badgeTitle || badgeDot) ? /* @__PURE__ */ jsx(Badge, { title: badgeTitle, dot: badgeDot, small: !badgeDot, children: triggerElement }) : triggerElement;
@@ -4856,7 +4865,8 @@ const DropDownMenu = ({
4856
4865
  setOpen: setOpenProp,
4857
4866
  tooltip: tooltip2,
4858
4867
  error: error2,
4859
- warning: warning2
4868
+ warning: warning2,
4869
+ selected: selected2
4860
4870
  }) => {
4861
4871
  const disabledContext = useContext(DisabledContext);
4862
4872
  const {
@@ -4925,7 +4935,8 @@ const DropDownMenu = ({
4925
4935
  tooltip: tooltip2,
4926
4936
  error: error2,
4927
4937
  warning: warning2,
4928
- testId
4938
+ testId,
4939
+ selected: selected2
4929
4940
  }
4930
4941
  ),
4931
4942
  isOpen2 && renderLayer(
@@ -70233,6 +70244,7 @@ const safeConvertValue = ({
70233
70244
  }) => {
70234
70245
  const rawValue = getValue$1(value);
70235
70246
  const isInvalidInput = isWrongValue(rawValue);
70247
+ const availableUnits = ALT_UNITS[unitkey];
70236
70248
  if (isValueWithUnknownUnit(value)) {
70237
70249
  return { value: rawValue };
70238
70250
  }
@@ -70242,6 +70254,9 @@ const safeConvertValue = ({
70242
70254
  if (!isValueWithUnit(value)) {
70243
70255
  return { value };
70244
70256
  }
70257
+ if (!(availableUnits == null ? void 0 : availableUnits.includes(getUnit(value)))) {
70258
+ return { value: rawValue };
70259
+ }
70245
70260
  return convertUnit({
70246
70261
  value,
70247
70262
  unitkey,
@@ -70276,6 +70291,144 @@ const initializeContext = (context2) => {
70276
70291
  UnitContext = context2;
70277
70292
  }
70278
70293
  };
70294
+ const extractValue = (value) => {
70295
+ if (isNil(value)) return value;
70296
+ return isValueWithUnit(value) ? getValue$1(value) : value;
70297
+ };
70298
+ const PredefinedOptionsMenu = ({
70299
+ predefinedOptions,
70300
+ displayLayer,
70301
+ unitkey: rootUnitKey,
70302
+ unitTemplate,
70303
+ onPredefinedOptionSelect,
70304
+ disabled: disabled2,
70305
+ initialPredefinedOption,
70306
+ predefinedOptionLinked,
70307
+ predefinedOptionsMenuState,
70308
+ setPredefinedOptionsMenuState,
70309
+ testId
70310
+ }) => {
70311
+ const extractedValue = extractValue(displayLayer == null ? void 0 : displayLayer.value);
70312
+ const [foundPredefinedMenuOption, setFoundPredefinedMenuOption] = useState(void 0);
70313
+ const convertPredefinedOptions = ({
70314
+ value,
70315
+ unit: optionUnitKey
70316
+ }) => {
70317
+ if (!value || !rootUnitKey) return value;
70318
+ if (!isValueWithUnit(value)) return value;
70319
+ const selectedUnitKey = optionUnitKey || rootUnitKey;
70320
+ const preferredOptionUnit = getPreferredUnit(selectedUnitKey, unitTemplate);
70321
+ const { value: resultValue } = safeConvertValue({
70322
+ value,
70323
+ toUnit: preferredOptionUnit,
70324
+ unitkey: selectedUnitKey,
70325
+ defaultFromUnit: "",
70326
+ doNotConvertValue: false
70327
+ });
70328
+ return withUnit(resultValue, preferredOptionUnit);
70329
+ };
70330
+ const createPredefinedOption = (el2) => {
70331
+ const convertedValue = convertPredefinedOptions(el2);
70332
+ const [inputValue = "", unit2 = ""] = split$1(convertedValue);
70333
+ return {
70334
+ type: MenuType.OPTION,
70335
+ inline: true,
70336
+ onClick: () => {
70337
+ const validation = validateNumber(inputValue);
70338
+ const optionState = {
70339
+ predefinedSelected: true,
70340
+ predefinedOption: el2
70341
+ };
70342
+ if (validation.valid && !disabled2) {
70343
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70344
+ onPredefinedOptionSelect(convertedValue, optionState);
70345
+ setFoundPredefinedMenuOption(el2);
70346
+ }
70347
+ },
70348
+ label: /* @__PURE__ */ jsxs(Fragment$1, { children: [
70349
+ /* @__PURE__ */ jsx(Text, { children: el2.label }),
70350
+ /* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
70351
+ ] }),
70352
+ description: `${inputValue} ${unit2}`,
70353
+ selected: isEqual$4(foundPredefinedMenuOption, el2) && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
70354
+ };
70355
+ };
70356
+ const initialPredefinedOptionObject = useMemo$1(() => {
70357
+ return predefinedOptions.find(
70358
+ (option2) => [option2.value, option2.label, option2.valueKey].includes(
70359
+ initialPredefinedOption
70360
+ )
70361
+ );
70362
+ }, [initialPredefinedOption, predefinedOptionLinked]);
70363
+ useEffect(() => {
70364
+ if (initialPredefinedOptionObject) {
70365
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70366
+ setFoundPredefinedMenuOption(initialPredefinedOptionObject);
70367
+ if (predefinedOptionLinked) {
70368
+ onPredefinedOptionSelect(initialPredefinedOptionObject.value, {
70369
+ predefinedSelected: true,
70370
+ predefinedOption: initialPredefinedOptionObject
70371
+ });
70372
+ }
70373
+ }
70374
+ }, [
70375
+ initialPredefinedOptionObject == null ? void 0 : initialPredefinedOptionObject.value,
70376
+ initialPredefinedOptionObject == null ? void 0 : initialPredefinedOptionObject.label
70377
+ ]);
70378
+ useEffect(() => {
70379
+ const foundOption = predefinedOptionLinked && predefinedOptions.find((option2) => {
70380
+ const convertedValue = convertPredefinedOptions(option2);
70381
+ return convertedValue === withUnit(displayLayer == null ? void 0 : displayLayer.value, (displayLayer == null ? void 0 : displayLayer.unit) ?? "");
70382
+ });
70383
+ if (foundOption || initialPredefinedOptionObject) {
70384
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70385
+ setFoundPredefinedMenuOption(
70386
+ foundOption || initialPredefinedOptionObject
70387
+ );
70388
+ } else {
70389
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
70390
+ setFoundPredefinedMenuOption(void 0);
70391
+ }
70392
+ }, [extractedValue, predefinedOptionLinked]);
70393
+ const sectionsPredefinedMenu = [
70394
+ {
70395
+ type: MenuType.OPTION,
70396
+ inline: true,
70397
+ onClick: () => {
70398
+ if (!disabled2) {
70399
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
70400
+ }
70401
+ },
70402
+ label: "Custom",
70403
+ selected: predefinedOptionsMenuState === PredefinedOptionsMenuState.CUSTOM
70404
+ },
70405
+ ...predefinedOptions.map(createPredefinedOption)
70406
+ ];
70407
+ return /* @__PURE__ */ jsx(
70408
+ Menu,
70409
+ {
70410
+ testId: testId && `${testId}-predefined-menu`,
70411
+ maxHeight: 380,
70412
+ groupOrder: "first",
70413
+ disabled: disabled2,
70414
+ menu: {
70415
+ colored: true,
70416
+ trigger: "Component",
70417
+ component: /* @__PURE__ */ jsx(
70418
+ Button$1,
70419
+ {
70420
+ groupOrder: "first",
70421
+ active: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED,
70422
+ icon: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? "link" : "unlink"
70423
+ }
70424
+ ),
70425
+ small: true,
70426
+ sections: sectionsPredefinedMenu
70427
+ },
70428
+ tooltip: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? foundPredefinedMenuOption == null ? void 0 : foundPredefinedMenuOption.label : ""
70429
+ }
70430
+ );
70431
+ };
70279
70432
  const predefinedMenuActive = "_predefinedMenuActive_ye9w9_1";
70280
70433
  const inputWrapper = "_inputWrapper_ye9w9_4";
70281
70434
  const styles = {
@@ -70300,17 +70453,14 @@ const UnitInput = ({
70300
70453
  onFocus = noop$3,
70301
70454
  onSwitchUnit = noop$3,
70302
70455
  unitTemplate,
70303
- doNotConvertValue = false,
70304
70456
  testId,
70305
70457
  warning: warning2 = null,
70306
70458
  predefinedOptions,
70307
- initialPredefinedOption = false,
70308
- shouldLinkAutomaticly = true,
70309
- selectedPredefinedOptionKey,
70459
+ initialPredefinedOption = "",
70460
+ predefinedOptionLinked = true,
70310
70461
  validationCallback = () => ({ name: "", error: null }),
70311
70462
  disabledValidation = false,
70312
70463
  allowEmpty = false,
70313
- autoValue,
70314
70464
  convertBackToStorageUnit = false,
70315
70465
  enableCosmeticRounding = true,
70316
70466
  enableDisplayRounding = false,
@@ -70318,11 +70468,11 @@ const UnitInput = ({
70318
70468
  }) => {
70319
70469
  const context2 = useUnitContext();
70320
70470
  const runAfterUpdate = useRunAfterUpdate();
70471
+ const [predefinedOptionsMenuState, setPredefinedOptionsMenuState] = useState(PredefinedOptionsMenuState.CUSTOM);
70321
70472
  if (typeof value === "number") {
70322
70473
  value = `${value}`;
70323
70474
  }
70324
70475
  const [propValue = "", propUnit = ""] = value !== void 0 ? split$1(value) : [];
70325
- const propAutoUnit = autoValue ? getUnit(autoValue) : "";
70326
70476
  const preferredUnit = useMemo$1(
70327
70477
  () => getPreferredUnit(unitkey, unitTemplate || (context2 == null ? void 0 : context2.unitTemplate)),
70328
70478
  [unitkey, unitTemplate, context2 == null ? void 0 : context2.unitTemplate]
@@ -70335,39 +70485,15 @@ const UnitInput = ({
70335
70485
  toUnit: initDisplayUnit,
70336
70486
  unitkey,
70337
70487
  defaultFromUnit: propUnit,
70338
- doNotConvertValue
70339
- });
70340
- const { value: convertedAutoValue } = safeConvertValue({
70341
- value: autoValue,
70342
- toUnit: initDisplayUnit,
70343
- unitkey,
70344
- defaultFromUnit: propAutoUnit,
70345
- doNotConvertValue
70488
+ doNotConvertValue: noConversion
70346
70489
  });
70347
- const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : convertedAutoValue !== "" ? { value: convertedAutoValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
70490
+ const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
70348
70491
  const [displayLayer, setDisplayLayer] = useState(initDisplayLayer);
70349
70492
  const derivedAllowEmpty = allowEmpty || (displayLayer == null ? void 0 : displayLayer.value) === void 0;
70350
- const [predefinedOptionsMenuState, setPredefinedOptionsMenuState] = useState(
70351
- initialPredefinedOption ? PredefinedOptionsMenuState.PREDEFINED : PredefinedOptionsMenuState.CUSTOM
70352
- );
70353
- const isAutoValue = propValue === "" && autoValue;
70354
- const disableInternalErrorValidationMessages = !!(disabledValidation || autoValue || disabled2);
70355
- const foundPredefinedMenuOption = predefinedOptions && predefinedOptions.find((el2) => {
70356
- if (!(el2 == null ? void 0 : el2.value)) return;
70357
- if (selectedPredefinedOptionKey) {
70358
- return selectedPredefinedOptionKey === el2.valueKey;
70359
- }
70360
- const predefinedMenuItemUnit = isValueWithUnit(el2.value) ? getUnit(el2.value) : "";
70361
- const { value: resultValue = value } = convertUnit({
70362
- value: String(value),
70363
- unitkey,
70364
- toUnit: predefinedMenuItemUnit
70365
- });
70366
- return withUnit(resultValue, predefinedMenuItemUnit) === el2.value;
70367
- });
70493
+ const disableInternalErrorValidationMessages = !!disabledValidation || disabled2;
70368
70494
  const getAlternativeUnits = () => {
70369
- const valueToList = isAutoValue ? autoValue : value ?? "";
70370
- const initToUnit = displayLayer.unit;
70495
+ const valueToList = value ?? "";
70496
+ const initToUnit = displayLayer == null ? void 0 : displayLayer.unit;
70371
70497
  const shouldConvert = checkConversion({
70372
70498
  value: valueToList,
70373
70499
  unitkey,
@@ -70425,7 +70551,7 @@ const UnitInput = ({
70425
70551
  toUnit: initDisplayUnit,
70426
70552
  unitkey,
70427
70553
  defaultFromUnit: propUnit,
70428
- doNotConvertValue
70554
+ doNotConvertValue: noConversion
70429
70555
  });
70430
70556
  newValue = resultValue;
70431
70557
  newUnit = initDisplayUnit;
@@ -70435,96 +70561,29 @@ const UnitInput = ({
70435
70561
  toUnit: displayLayer.unit,
70436
70562
  unitkey,
70437
70563
  defaultFromUnit: propUnit,
70438
- doNotConvertValue
70564
+ doNotConvertValue: noConversion
70439
70565
  });
70440
70566
  newValue = resultValue;
70441
70567
  newUnit = displayLayer.unit;
70442
70568
  }
70443
- if (newValue !== void 0) {
70569
+ if (newValue !== void 0 && !initialPredefinedOption) {
70444
70570
  setDisplayLayer({ value: newValue, unit: newUnit });
70445
70571
  }
70446
- if (predefinedOptions) {
70447
- if (foundPredefinedMenuOption && shouldLinkAutomaticly) {
70448
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70449
- } else {
70450
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
70451
- }
70452
- }
70453
70572
  }
70454
- }, [initDisplayUnit, value, error2, shouldLinkAutomaticly]);
70573
+ }, [initDisplayUnit, value, error2]);
70455
70574
  const alternativeUnits = getAlternativeUnits();
70456
70575
  const displayUnitLabel = label$b(displayLayer.unit) || displayLayer.unit || "";
70457
70576
  const noConvert = noConversion || !alternativeUnits || alternativeUnits && alternativeUnits.length === 1;
70458
70577
  const stringName = getStringName(name2);
70459
- let sectionsPredefinedMenu;
70460
- const createPredefinedOption = (el2) => {
70461
- const elementValue = (el2 == null ? void 0 : el2.value) ? el2.value : "";
70462
- const [value2 = "", unit2 = ""] = isValueWithUnit(elementValue) ? split$1(elementValue) : [elementValue];
70463
- return {
70464
- type: MenuType.OPTION,
70465
- inline: true,
70466
- onClick: () => {
70467
- const validation = validateNumber(value2);
70468
- if (validation.valid && !disabled2) {
70469
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70470
- onChange({
70471
- target: {
70472
- value: elementValue,
70473
- name: typeof name2 === "string" ? name2 : (name2 == null ? void 0 : name2.fieldName) || "",
70474
- predefinedSelected: true,
70475
- predefinedOption: el2
70476
- }
70477
- });
70478
- }
70479
- },
70480
- label: /* @__PURE__ */ jsxs(Fragment$1, { children: [
70481
- /* @__PURE__ */ jsx(Text, { children: el2.label }),
70482
- /* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
70483
- ] }),
70484
- description: isValueWithUnit(elementValue) ? `${value2} ${unit2}` : elementValue,
70485
- selected: foundPredefinedMenuOption === el2 && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
70486
- };
70487
- };
70488
- sectionsPredefinedMenu = [
70489
- {
70490
- type: MenuType.OPTION,
70491
- inline: true,
70492
- onClick: () => {
70493
- if (predefinedOptionsMenuState !== PredefinedOptionsMenuState.CUSTOM && !disabled2) {
70494
- onChange({
70495
- target: {
70496
- value: withUnit(displayLayer.value, displayLayer.unit),
70497
- name: typeof name2 === "string" ? name2 : (name2 == null ? void 0 : name2.fieldName) || ""
70498
- }
70499
- });
70500
- }
70501
- },
70502
- label: "Custom",
70503
- selected: predefinedOptionsMenuState === PredefinedOptionsMenuState.CUSTOM
70504
- }
70505
- ];
70506
- if (predefinedOptions == null ? void 0 : predefinedOptions.length) {
70507
- const dynamicOptions = predefinedOptions.map(createPredefinedOption);
70508
- sectionsPredefinedMenu = [...sectionsPredefinedMenu, ...dynamicOptions];
70509
- }
70510
70578
  const getPlaceholder = (placeholder22) => {
70511
- if (isAutoValue) {
70512
- const { value: resultValue } = safeConvertValue({
70513
- value: autoValue,
70514
- toUnit: displayLayer.unit,
70515
- unitkey,
70516
- defaultFromUnit: propAutoUnit,
70517
- doNotConvertValue
70518
- });
70519
- return resultValue;
70520
- } else if (isValueWithUnit(placeholder22)) {
70579
+ if (isValueWithUnit(placeholder22)) {
70521
70580
  const placeholderUnit = getUnit(placeholder22);
70522
70581
  const { value: resultValue } = safeConvertValue({
70523
70582
  value: placeholder22,
70524
70583
  toUnit: displayLayer.unit,
70525
70584
  unitkey,
70526
70585
  defaultFromUnit: placeholderUnit,
70527
- doNotConvertValue
70586
+ doNotConvertValue: noConversion
70528
70587
  });
70529
70588
  return resultValue;
70530
70589
  }
@@ -70536,32 +70595,44 @@ const UnitInput = ({
70536
70595
  className: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? cx$2(styles.predefinedMenuActive) : "",
70537
70596
  children: /* @__PURE__ */ jsxs(InputGroup, { small: small2, width: width2, children: [
70538
70597
  predefinedOptions && /* @__PURE__ */ jsx(
70539
- Tooltip,
70598
+ PredefinedOptionsMenu,
70540
70599
  {
70541
- text: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? foundPredefinedMenuOption == null ? void 0 : foundPredefinedMenuOption.label : "",
70542
- children: /* @__PURE__ */ jsx(
70543
- Menu,
70544
- {
70545
- maxHeight: 380,
70546
- groupOrder: "first",
70547
- testId: testId && `${testId}-predefined-menu`,
70548
- disabled: disabled2,
70549
- menu: {
70550
- colored: true,
70551
- trigger: "Component",
70552
- component: /* @__PURE__ */ jsx(
70553
- Button$1,
70554
- {
70555
- groupOrder: "first",
70556
- active: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED,
70557
- icon: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? "link" : "unlink"
70558
- }
70559
- ),
70560
- small: small2,
70561
- sections: sectionsPredefinedMenu
70562
- }
70600
+ testId,
70601
+ unitTemplate: unitTemplate || (context2 == null ? void 0 : context2.unitTemplate),
70602
+ unitkey,
70603
+ predefinedOptions,
70604
+ displayLayer,
70605
+ onPredefinedOptionSelect: (newValue, optionState) => {
70606
+ var _a2;
70607
+ if (predefinedOptionLinked && ((_a2 = optionState == null ? void 0 : optionState.predefinedOption) == null ? void 0 : _a2.unit)) {
70608
+ onChange({
70609
+ target: {
70610
+ value: withUnit(displayLayer == null ? void 0 : displayLayer.value, displayLayer == null ? void 0 : displayLayer.unit),
70611
+ name: stringName,
70612
+ predefinedSelected: optionState == null ? void 0 : optionState.predefinedSelected,
70613
+ predefinedOption: optionState == null ? void 0 : optionState.predefinedOption
70614
+ }
70615
+ });
70616
+ } else {
70617
+ onChange({
70618
+ target: {
70619
+ value: newValue,
70620
+ name: stringName,
70621
+ predefinedSelected: optionState == null ? void 0 : optionState.predefinedSelected,
70622
+ predefinedOption: optionState == null ? void 0 : optionState.predefinedOption
70623
+ }
70624
+ });
70625
+ setDisplayLayer({
70626
+ value: newValue,
70627
+ unit: getUnit(newValue) || displayLayer.unit
70628
+ });
70563
70629
  }
70564
- )
70630
+ },
70631
+ disabled: disabled2,
70632
+ initialPredefinedOption,
70633
+ predefinedOptionLinked,
70634
+ predefinedOptionsMenuState,
70635
+ setPredefinedOptionsMenuState
70565
70636
  }
70566
70637
  ),
70567
70638
  /* @__PURE__ */ jsx("div", { className: styles.inputWrapper, children: /* @__PURE__ */ jsx(
@@ -70609,7 +70680,7 @@ const UnitInput = ({
70609
70680
  inline: true,
70610
70681
  onClick: (evt) => {
70611
70682
  evt.stopPropagation();
70612
- onClickUnit(isAutoValue ? "" : value2, altUnit);
70683
+ onClickUnit(value2, altUnit);
70613
70684
  },
70614
70685
  description: displayUnit,
70615
70686
  selected: displayUnit === displayUnitLabel,