@evergis/uilib-gl 1.0.122 → 1.0.124

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.
@@ -2,5 +2,6 @@ import { Color } from "@evergis/color";
2
2
  import { IMaskedComponentProps } from "../Input";
3
3
  export interface IColorInputProps extends Omit<IMaskedComponentProps, "onChange" | "value"> {
4
4
  value: Color;
5
+ withAlpha?: boolean;
5
6
  onChange?: (value: Color) => void;
6
7
  }
@@ -27,6 +27,7 @@ export interface IColorPickerProps extends Omit<IColorButtonProps, "value" | "on
27
27
  root?: HTMLElement | null;
28
28
  small?: boolean;
29
29
  withHex?: boolean;
30
+ withOpacity?: boolean;
30
31
  }
31
32
  export interface IColorPickerHSVA {
32
33
  h: number;
@@ -14090,13 +14090,14 @@ const TextButton = /*#__PURE__*/styled(IconButtonButton)`
14090
14090
  const ColorInputComponent = _ref => {
14091
14091
  let {
14092
14092
  value,
14093
+ withAlpha = true,
14093
14094
  onChange,
14094
14095
  ...props
14095
14096
  } = _ref;
14096
14097
  const inputRef = useRef(null);
14097
14098
  const [hexMode, setHexMode] = useState(false);
14098
14099
  const [focused, setFocused] = useState(false);
14099
- const text = hexMode ? "HEX #" : "RGBA";
14100
+ const text = hexMode ? "HEX #" : withAlpha ? "RGBA" : "RGB";
14100
14101
  const formatting = useMemo(() => {
14101
14102
  var _inputRef$current;
14102
14103
 
@@ -14111,11 +14112,11 @@ const ColorInputComponent = _ref => {
14111
14112
 
14112
14113
  const alpha = value.toString("hex").slice(-2);
14113
14114
  const hex = value.toString("hex").slice(1, 7);
14114
- return hexMode ? hex + alpha : `${r}, ${g}, ${b}, ${Math.round(a / 255 * 100) / 100}`;
14115
+ return hexMode ? withAlpha ? hex + alpha : hex : withAlpha ? `${r}, ${g}, ${b}, ${Math.round(a / 255 * 100) / 100}` : `${r}, ${g}, ${b}`;
14115
14116
  }
14116
14117
 
14117
14118
  return (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.value;
14118
- }, [focused, hexMode, value]);
14119
+ }, [focused, hexMode, value, withAlpha]);
14119
14120
  const onRGBAChange = useCallback(newValue => {
14120
14121
  const [channel1, channel2, channel3, alpha] = newValue.split(",");
14121
14122
  const newColor = new Color(`rgba(
@@ -18243,6 +18244,7 @@ const ColorPickerComponent = _ref => {
18243
18244
  root,
18244
18245
  small,
18245
18246
  withHex,
18247
+ withOpacity = true,
18246
18248
  ...props
18247
18249
  } = _ref;
18248
18250
  const [isOpen, setIsOpen] = useState(false);
@@ -18293,7 +18295,7 @@ const ColorPickerComponent = _ref => {
18293
18295
  const newColor = new Color(currentColor.toString());
18294
18296
  newColor.setHsv(value.h || h, value.s || s, value.v || v);
18295
18297
 
18296
- if (value.a !== void 0) {
18298
+ if (value.a !== undefined) {
18297
18299
  newColor.a = Math.round(value.a * 255);
18298
18300
  }
18299
18301
 
@@ -18310,7 +18312,15 @@ const ColorPickerComponent = _ref => {
18310
18312
  updateColorPart(value);
18311
18313
  }
18312
18314
  }, [updateColorPart, updateState]);
18313
- const colorVariants = useMemo(() => colors || colorsHistory.map(stringColor => new Color(stringColor)), [colors, colorsHistory]);
18315
+ const colorVariants = useMemo(() => {
18316
+ return [...(colors || colorsHistory.map(stringColor => new Color(stringColor)))].map(color => {
18317
+ if (!withOpacity) {
18318
+ color.a = 255;
18319
+ }
18320
+
18321
+ return color;
18322
+ });
18323
+ }, [colors, withOpacity, colorsHistory]);
18314
18324
  useEffect(() => {
18315
18325
  const newColor = new Color(value == null ? void 0 : value.toString());
18316
18326
  const colorsHistory = window.localStorage.getItem(COLORS_HISTORY_STORAGE_ITEM);
@@ -18336,7 +18346,9 @@ const ColorPickerComponent = _ref => {
18336
18346
  setIsOpen(false);
18337
18347
  }, [addCurrentColorToHistory, currentColor, onChangeProp]);
18338
18348
  useEffect(() => {
18339
- if (prevIsOpen.current === isOpen) return;
18349
+ if (prevIsOpen.current === isOpen) {
18350
+ return;
18351
+ }
18340
18352
 
18341
18353
  if (!prevIsOpen.current && isOpen) {
18342
18354
  setColorsHistory(getColorsHistory());
@@ -18396,7 +18408,7 @@ const ColorPickerComponent = _ref => {
18396
18408
  onChange: hue => onChange({
18397
18409
  h: hue
18398
18410
  })
18399
- }), React.createElement(OpacitySlider$1, {
18411
+ }), withOpacity && React.createElement(OpacitySlider$1, {
18400
18412
  color: currentColor,
18401
18413
  value: a,
18402
18414
  onChange: alpha => onChange({
@@ -18404,16 +18416,20 @@ const ColorPickerComponent = _ref => {
18404
18416
  })
18405
18417
  }), colorVariants && colorVariants.length > 0 && React.createElement(Flex, {
18406
18418
  gap: "0.25rem",
18407
- mb: "1rem"
18408
- }, colorVariants.map((color, index) => index < COLORS_HISTORY_LIMIT && React.createElement(FlexSpan, {
18409
- key: `color-btn-${index}-${color.toString()}`
18410
- }, React.createElement(ColorButton, {
18411
- color: color.toString(),
18412
- onClick: () => onChange(color),
18413
- className: "color-variants-button"
18414
- })))), React.createElement(ColorInput, {
18419
+ mb: "1rem",
18420
+ mt: withOpacity ? undefined : "0.75rem"
18421
+ }, colorVariants.map((color, index) => {
18422
+ return index < COLORS_HISTORY_LIMIT && React.createElement(FlexSpan, {
18423
+ key: `color-btn-${index}-${color.toString()}`
18424
+ }, React.createElement(ColorButton, {
18425
+ color: color.toString(),
18426
+ onClick: () => onChange(color),
18427
+ className: "color-variants-button"
18428
+ }));
18429
+ })), React.createElement(ColorInput, {
18415
18430
  value: currentColor,
18416
- onChange: onChange
18431
+ onChange: onChange,
18432
+ withAlpha: withOpacity
18417
18433
  }), withSave && React.createElement(ApplyButtonsContainer, null, React.createElement(IconButton, {
18418
18434
  kind: "close",
18419
18435
  error: true,