@northlight/ui 2.36.9 → 2.36.11

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.
@@ -2589,7 +2589,7 @@ declare const useOverflowGroup: () => {
2589
2589
  containerRef: (node: any) => void;
2590
2590
  };
2591
2591
 
2592
- declare const getContrastColor: (color: string) => "text.default" | "text.inverted";
2592
+ declare const getContrastColor: (color: string) => "text.default" | "text.inverted" | undefined;
2593
2593
 
2594
2594
  declare const luminosity: (hexcolor: string) => number;
2595
2595
 
@@ -364,12 +364,16 @@ const useDidUpdateEffect = (effect, dependencies) => {
364
364
  };
365
365
 
366
366
  const luminosity = (hexcolor) => {
367
- let color = hexcolor;
368
- if (color.slice(0, 1) === "#") {
369
- color = color.slice(1);
367
+ if (!hexcolor || typeof hexcolor !== "string")
368
+ return Number.NaN;
369
+ let color = hexcolor.trim();
370
+ if (!/^#?[0-9a-f]{3}([0-9a-f]{3})?$/i.test(color)) {
371
+ return Number.NaN;
370
372
  }
373
+ if (color[0] === "#")
374
+ color = color.slice(1);
371
375
  if (color.length === 3) {
372
- color = color.split("").map((hex) => hex + hex).join("");
376
+ color = color.split("").map((h) => h + h).join("");
373
377
  }
374
378
  const r = parseInt(color.substring(0, 2), 16);
375
379
  const g = parseInt(color.substring(2, 4), 16);
@@ -378,16 +382,28 @@ const luminosity = (hexcolor) => {
378
382
  return brightness;
379
383
  };
380
384
 
385
+ function safeUseToken(tokenOrValue) {
386
+ try {
387
+ return useToken("colors", tokenOrValue);
388
+ } catch (e) {
389
+ return tokenOrValue;
390
+ }
391
+ }
381
392
  const getContrastColor = (color) => {
382
- const colorTwo = useToken("colors", "text.default");
383
- const colorOne = useToken("colors", "text.inverted");
384
- const colorInHex = useToken("colors", color);
385
- const l1 = luminosity(colorOne);
386
- const l2 = luminosity(colorTwo);
387
- const threshold = (l1 + l2) / 2;
388
- const brightColor = l1 > l2 ? colorOne : colorTwo;
389
- const darkColor = l1 > l2 ? colorTwo : colorOne;
390
- return luminosity(colorInHex) >= threshold ? darkColor : brightColor;
393
+ const textDefault = useToken("colors", "text.default");
394
+ const textInverted = useToken("colors", "text.inverted");
395
+ const normalized = typeof color === "string" ? color.trim() : color;
396
+ const isHex = /^#?[0-9a-f]{3}([0-9a-f]{3})?$/i.test(normalized);
397
+ const bgResolved = isHex ? normalized[0] === "#" ? normalized : `#${normalized}` : safeUseToken(normalized);
398
+ const lInverted = luminosity(textInverted);
399
+ const lDefault = luminosity(textDefault);
400
+ const threshold = (lInverted + lDefault) / 2;
401
+ const brightColor = lInverted > lDefault ? textInverted : textDefault;
402
+ const darkColor = lInverted > lDefault ? textDefault : textInverted;
403
+ const lBg = luminosity(bgResolved);
404
+ if (Number.isNaN(lBg))
405
+ return void 0;
406
+ return lBg >= threshold ? darkColor : brightColor;
391
407
  };
392
408
 
393
409
  const ring = {
@@ -784,14 +800,14 @@ const Button$1 = {
784
800
  }
785
801
  }),
786
802
  brandSubdued: ({ theme: { colors: color } }) => ({
787
- color: color.text.button.link,
803
+ color: color.text.button.brandSubdued,
788
804
  bgColor: color.background.button.ghost,
789
805
  _hover: {
790
806
  bg: color.background.button.brand,
791
807
  color: color.text.inverted,
792
808
  _disabled: {
793
809
  bgColor: color.background.button.ghost,
794
- color: color.text.button.link
810
+ color: color.text.button.brandSubdued
795
811
  }
796
812
  },
797
813
  _active: {
@@ -1646,7 +1662,8 @@ const Tag$1 = {
1646
1662
  variants: {
1647
1663
  solid: ({ theme: { colors }, bgColor, colorScheme, currentTheme }) => {
1648
1664
  const processedColorScheme = processColorSchemeBasedOnTheme({ currentTheme, colorScheme });
1649
- const tagBgColor = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][500] ? colors[processedColorScheme][500] : processedColorScheme;
1665
+ const tagBgColorRaw = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][500] ? colors[processedColorScheme][500] : processedColorScheme;
1666
+ const tagBgColor = typeof tagBgColorRaw === "string" ? tagBgColorRaw.trim() : tagBgColorRaw;
1650
1667
  const tagColor = getContrastColor(useToken$1("colors", tagBgColor));
1651
1668
  return {
1652
1669
  container: {
@@ -1657,7 +1674,8 @@ const Tag$1 = {
1657
1674
  },
1658
1675
  subtle: ({ theme: { colors }, colorScheme, bgColor, currentTheme }) => {
1659
1676
  const processedColorScheme = processColorSchemeBasedOnTheme({ currentTheme, colorScheme });
1660
- const tagBgColor = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][100] ? colors[processedColorScheme][100] : processedColorScheme;
1677
+ const tagBgColorRaw = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][100] ? colors[processedColorScheme][100] : processedColorScheme;
1678
+ const tagBgColor = typeof tagBgColorRaw === "string" ? tagBgColorRaw.trim() : tagBgColorRaw;
1661
1679
  const tagColor = getContrastColor(useToken$1("colors", tagBgColor));
1662
1680
  return {
1663
1681
  container: {
@@ -3576,12 +3594,13 @@ const Badge$1 = {
3576
3594
  };
3577
3595
  },
3578
3596
  variants: {
3579
- solid: ({ colorScheme, theme: { colors }, currentTheme }) => {
3597
+ solid: ({ colorScheme, theme: { colors }, currentTheme, bg, bgColor }) => {
3598
+ var _a;
3580
3599
  const processedColorScheme = processColorSchemeBasedOnTheme({ currentTheme, colorScheme });
3581
- const bgColor = processedColorScheme === "mediatoolBlue" ? colors[processedColorScheme][500] : colors[processedColorScheme] && colors[processedColorScheme][500];
3600
+ const finalBg = (_a = bg != null ? bg : bgColor) != null ? _a : processedColorScheme === "mediatoolBlue" ? colors[processedColorScheme][500] : colors[processedColorScheme] && colors[processedColorScheme][500];
3582
3601
  return {
3583
- bgColor,
3584
- color: getContrastColor(bgColor != null ? bgColor : useToken$1("colors", processedColorScheme))
3602
+ bgColor: finalBg,
3603
+ color: getContrastColor(finalBg != null ? finalBg : useToken$1("colors", processedColorScheme))
3585
3604
  };
3586
3605
  },
3587
3606
  outline: ({ colorScheme, theme: { colors }, currentTheme }) => {
@@ -3616,7 +3635,8 @@ const Badge$1 = {
3616
3635
  }
3617
3636
  },
3618
3637
  defaultProps: {
3619
- size: "sm"
3638
+ size: "sm",
3639
+ variant: "solid"
3620
3640
  }
3621
3641
  };
3622
3642
 
@@ -13485,10 +13505,8 @@ const FormattedNumberInput = (_a) => {
13485
13505
  "inputRightElement",
13486
13506
  "onBlur"
13487
13507
  ]);
13488
- const [valueState, setValueState] = useState(valueProp);
13489
- const isControlled = typeof valueProp !== "undefined";
13490
- const value = isControlled ? valueProp : valueState;
13491
13508
  const props = presetMap[preset];
13509
+ const value = valueProp != null ? valueProp : "";
13492
13510
  const getNumberFormatValues = (number) => ({
13493
13511
  floatValue: number,
13494
13512
  formattedValue: numericFormatter(number.toString(), props),
@@ -13501,18 +13519,15 @@ const FormattedNumberInput = (_a) => {
13501
13519
  const factor = isPercentage ? 100 : 1;
13502
13520
  if (vNum * factor > max) {
13503
13521
  const newValue = roundToPrecision(max / factor, numberOfDecimals);
13504
- setValueState(newValue);
13505
13522
  onChange(getNumberFormatValues(newValue));
13506
13523
  }
13507
13524
  if (vNum * factor < min) {
13508
13525
  const newValue = roundToPrecision(min / factor, numberOfDecimals);
13509
- setValueState(newValue);
13510
13526
  onChange(getNumberFormatValues(newValue));
13511
13527
  }
13512
13528
  };
13513
13529
  const onValueChangeHandler = (values, sourceInfo) => {
13514
13530
  const newFloatValue = values.floatValue && isPercentage ? roundToPrecision(values.floatValue / 100, numberOfDecimals) : values.floatValue;
13515
- setValueState(newFloatValue);
13516
13531
  onChange(
13517
13532
  __spreadProps$3(__spreadValues$k({}, values), {
13518
13533
  floatValue: newFloatValue
@@ -14748,13 +14763,9 @@ const ComboPicker = (_a) => {
14748
14763
  ]);
14749
14764
  var _a2, _b2, _c;
14750
14765
  const { isOpen, onToggle, onClose } = useDisclosure();
14751
- const [inputValueState, setInputValueState] = useState(valueProp == null ? void 0 : valueProp.input);
14752
- const [selectOptionState, setselectOptionState] = useState(valueProp == null ? void 0 : valueProp.option);
14766
+ const [inputValue, setInputValue] = useState(valueProp == null ? void 0 : valueProp.input);
14767
+ const [selectOption, setSelectOption] = useState(valueProp == null ? void 0 : valueProp.option);
14753
14768
  const [enableSelectInput, setEnableSelectInput] = useState(false);
14754
- const isInputValueControlled = typeof (valueProp == null ? void 0 : valueProp.input) !== "undefined";
14755
- const inputValue = isInputValueControlled ? valueProp.input : inputValueState;
14756
- const isOptionControlled = typeof (valueProp == null ? void 0 : valueProp.option) !== "undefined";
14757
- const selectOption = isOptionControlled ? valueProp.option : selectOptionState;
14758
14769
  const buttonRef = useRef();
14759
14770
  const selectRef = useRef();
14760
14771
  const getNewValue = (option, input) => {
@@ -14762,8 +14773,7 @@ const ComboPicker = (_a) => {
14762
14773
  return is(Number, input) ? { input: Number(input), option: newValueOption } : { option: newValueOption };
14763
14774
  };
14764
14775
  const handleInputChange = (newInputvalue) => {
14765
- const newValue = getNewValue(selectOption, newInputvalue);
14766
- setInputValueState(newValue.input);
14776
+ const newValue = getNewValue(valueProp == null ? void 0 : valueProp.option, newInputvalue);
14767
14777
  onChange == null ? void 0 : onChange(newValue);
14768
14778
  };
14769
14779
  const handleSelectClose = () => {
@@ -14775,8 +14785,7 @@ const ComboPicker = (_a) => {
14775
14785
  };
14776
14786
  const handleSelectChange = (selectedOption) => {
14777
14787
  if (selectedOption) {
14778
- setselectOptionState(selectedOption);
14779
- onChange == null ? void 0 : onChange(getNewValue(selectedOption, inputValue));
14788
+ onChange == null ? void 0 : onChange(getNewValue(selectedOption, valueProp == null ? void 0 : valueProp.input));
14780
14789
  if (isOpen) {
14781
14790
  handleSelectClose();
14782
14791
  }
@@ -14794,20 +14803,13 @@ const ComboPicker = (_a) => {
14794
14803
  }
14795
14804
  }, [enableSelectInput]);
14796
14805
  useEffect(() => {
14797
- const needsToCorrectOption = !selectOption;
14798
- const needsToCorrectInput = !is(Number, inputValue) && defaultToZeroIfEmpty;
14799
- const option = needsToCorrectOption ? options[0] : selectOption;
14800
- const input = needsToCorrectInput ? clamp(min, max, 0) : inputValue;
14801
- if (needsToCorrectOption) {
14802
- setselectOptionState(option);
14803
- }
14804
- if (needsToCorrectInput) {
14805
- setInputValueState(input);
14806
- }
14807
- if (needsToCorrectOption || needsToCorrectInput) {
14808
- onChange == null ? void 0 : onChange(getNewValue(option, input));
14809
- }
14810
- }, [inputValue, defaultToZeroIfEmpty]);
14806
+ var _a3, _b3;
14807
+ const option = (_a3 = valueProp == null ? void 0 : valueProp.option) != null ? _a3 : options[0];
14808
+ const input = defaultToZeroIfEmpty ? (_b3 = valueProp == null ? void 0 : valueProp.input) != null ? _b3 : 0 : valueProp == null ? void 0 : valueProp.input;
14809
+ setSelectOption(option);
14810
+ setInputValue(input);
14811
+ onChange == null ? void 0 : onChange(getNewValue(option, input));
14812
+ }, [valueProp == null ? void 0 : valueProp.input, valueProp == null ? void 0 : valueProp.option, defaultToZeroIfEmpty, options]);
14811
14813
  const buttonWidth = (_b2 = (_a2 = buttonRef.current) == null ? void 0 : _a2.offsetWidth) != null ? _b2 : 0;
14812
14814
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
14813
14815
  FormattedNumberInput,