@itwin/itwinui-react 1.23.2 → 1.26.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/cjs/core/Buttons/Button/Button.d.ts +1 -1
  3. package/cjs/core/ColorPicker/ColorBuilder.js +40 -15
  4. package/cjs/core/ColorPicker/ColorInputPanel.js +125 -46
  5. package/cjs/core/ColorPicker/ColorPicker.d.ts +5 -0
  6. package/cjs/core/ColorPicker/ColorPicker.js +7 -6
  7. package/cjs/core/ColorPicker/ColorPickerContext.d.ts +4 -2
  8. package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
  9. package/cjs/core/ColorPicker/ColorSwatch.js +10 -4
  10. package/cjs/core/DatePicker/DatePicker.d.ts +1 -1
  11. package/cjs/core/InformationPanel/InformationPanel.d.ts +4 -1
  12. package/cjs/core/InformationPanel/InformationPanel.js +4 -1
  13. package/cjs/core/InformationPanel/InformationPanelContent.d.ts +42 -0
  14. package/cjs/core/InformationPanel/InformationPanelContent.js +66 -0
  15. package/cjs/core/InformationPanel/index.d.ts +2 -0
  16. package/cjs/core/InformationPanel/index.js +3 -1
  17. package/cjs/core/Label/Label.d.ts +31 -0
  18. package/cjs/core/Label/Label.js +53 -0
  19. package/cjs/core/Label/index.d.ts +4 -0
  20. package/cjs/core/Label/index.js +10 -0
  21. package/cjs/core/LabeledInput/LabeledInput.d.ts +2 -2
  22. package/cjs/core/LabeledTextarea/LabeledTextarea.d.ts +1 -1
  23. package/cjs/core/Menu/MenuItem.d.ts +1 -1
  24. package/cjs/core/Table/TablePaginator.d.ts +1 -1
  25. package/cjs/core/Table/TablePaginator.js +9 -4
  26. package/cjs/core/Tabs/Tabs.js +23 -29
  27. package/cjs/core/index.d.ts +6 -4
  28. package/cjs/core/index.js +6 -2
  29. package/cjs/core/utils/color/ColorValue.d.ts +1 -0
  30. package/cjs/core/utils/color/ColorValue.js +101 -85
  31. package/cjs/core/utils/components/MiddleTextTruncation.d.ts +21 -0
  32. package/cjs/core/utils/components/MiddleTextTruncation.js +56 -0
  33. package/cjs/core/utils/components/index.d.ts +1 -0
  34. package/cjs/core/utils/components/index.js +1 -0
  35. package/cjs/core/utils/hooks/index.d.ts +1 -0
  36. package/cjs/core/utils/hooks/index.js +1 -0
  37. package/cjs/core/utils/hooks/useContainerWidth.d.ts +17 -0
  38. package/cjs/core/utils/hooks/useContainerWidth.js +50 -0
  39. package/cjs/core/utils/hooks/useOverflow.d.ts +1 -1
  40. package/cjs/core/utils/hooks/useOverflow.js +30 -17
  41. package/esm/core/Buttons/Button/Button.d.ts +1 -1
  42. package/esm/core/ColorPicker/ColorBuilder.js +40 -15
  43. package/esm/core/ColorPicker/ColorInputPanel.js +125 -46
  44. package/esm/core/ColorPicker/ColorPicker.d.ts +5 -0
  45. package/esm/core/ColorPicker/ColorPicker.js +7 -6
  46. package/esm/core/ColorPicker/ColorPickerContext.d.ts +4 -2
  47. package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
  48. package/esm/core/ColorPicker/ColorSwatch.js +10 -4
  49. package/esm/core/DatePicker/DatePicker.d.ts +1 -1
  50. package/esm/core/InformationPanel/InformationPanel.d.ts +4 -1
  51. package/esm/core/InformationPanel/InformationPanel.js +4 -1
  52. package/esm/core/InformationPanel/InformationPanelContent.d.ts +42 -0
  53. package/esm/core/InformationPanel/InformationPanelContent.js +59 -0
  54. package/esm/core/InformationPanel/index.d.ts +2 -0
  55. package/esm/core/InformationPanel/index.js +1 -0
  56. package/esm/core/Label/Label.d.ts +31 -0
  57. package/esm/core/Label/Label.js +46 -0
  58. package/esm/core/Label/index.d.ts +4 -0
  59. package/esm/core/Label/index.js +6 -0
  60. package/esm/core/LabeledInput/LabeledInput.d.ts +2 -2
  61. package/esm/core/LabeledTextarea/LabeledTextarea.d.ts +1 -1
  62. package/esm/core/Menu/MenuItem.d.ts +1 -1
  63. package/esm/core/Table/TablePaginator.d.ts +1 -1
  64. package/esm/core/Table/TablePaginator.js +9 -4
  65. package/esm/core/Tabs/Tabs.js +24 -30
  66. package/esm/core/index.d.ts +6 -4
  67. package/esm/core/index.js +3 -2
  68. package/esm/core/utils/color/ColorValue.d.ts +1 -0
  69. package/esm/core/utils/color/ColorValue.js +101 -85
  70. package/esm/core/utils/components/MiddleTextTruncation.d.ts +21 -0
  71. package/esm/core/utils/components/MiddleTextTruncation.js +49 -0
  72. package/esm/core/utils/components/index.d.ts +1 -0
  73. package/esm/core/utils/components/index.js +1 -0
  74. package/esm/core/utils/hooks/index.d.ts +1 -0
  75. package/esm/core/utils/hooks/index.js +1 -0
  76. package/esm/core/utils/hooks/useContainerWidth.d.ts +17 -0
  77. package/esm/core/utils/hooks/useContainerWidth.js +43 -0
  78. package/esm/core/utils/hooks/useOverflow.d.ts +1 -1
  79. package/esm/core/utils/hooks/useOverflow.js +30 -17
  80. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ### [1.26.1](https://www.github.com/iTwin/iTwinUI-react/compare/v1.26.0...v1.26.1) (2021-12-03)
4
+
5
+ ### Fixes
6
+
7
+ * **MiddleTextTruncation:** Fix resizing by adding flex grow ([#455](https://www.github.com/iTwin/iTwinUI-react/issues/455)) ([17cd7fb](https://www.github.com/iTwin/iTwinUI-react/commit/17cd7fbbef9f5c35a121d664922fb1a5706be037))
8
+
9
+ ## [1.26.0](https://www.github.com/iTwin/iTwinUI-react/compare/v1.25.0...v1.26.0) (2021-11-30)
10
+
11
+ ### What's new
12
+
13
+ * **InformationPanel:** Add `InformationPanelContent` for inner rows ([#433](https://www.github.com/iTwin/iTwinUI-react/issues/433)) ([a706bcb](https://www.github.com/iTwin/iTwinUI-react/commit/a706bcb04f9af512131d9ed08fef1529314d2bb1))
14
+ * **MiddleTextTruncation:** Utility to truncate text with ellipsis in the middle ([#330](https://www.github.com/iTwin/iTwinUI-react/issues/330)) ([371b56f](https://www.github.com/iTwin/iTwinUI-react/commit/371b56fa9150fdd110c92d05b3944f376d37441c))
15
+
16
+ ### Fixes
17
+
18
+ * **DatePicker:** Make date arg required in `onChange` ([#437](https://www.github.com/iTwin/iTwinUI-react/issues/437)) ([ee79248](https://www.github.com/iTwin/iTwinUI-react/commit/ee792488a10e43a9b0f8ea6d77c30ef1897eb86c))
19
+ * **Table:** Don't show paginator when there is only one page ([#441](https://www.github.com/iTwin/iTwinUI-react/issues/441)) ([e40cbc8](https://www.github.com/iTwin/iTwinUI-react/commit/e40cbc81929da14ea2754e5d847c0efe8af70203))
20
+
21
+ ## [1.25.0](https://www.github.com/iTwin/iTwinUI-react/compare/v1.24.0...v1.25.0) (2021-11-16)
22
+
23
+ ### What's new
24
+
25
+ * **Label:** Add new standalone `Label` component ([#431](https://www.github.com/iTwin/iTwinUI-react/issues/431)) ([8e40b69](https://www.github.com/iTwin/iTwinUI-react/commit/8e40b69d2b5e9272c01e528cdfd75060357069a8))
26
+
27
+ ### Fixes
28
+
29
+ * **ColorPicker:** Upgrade color conversion to remove rounding issues ([#425](https://www.github.com/iTwin/iTwinUI-react/issues/425)) ([1ce4905](https://www.github.com/iTwin/iTwinUI-react/commit/1ce4905219325080b5a6a4e5de200101d5b0860e))
30
+ * **Table:** Fixed pagniator to handle a large number of items ([#428](https://www.github.com/iTwin/iTwinUI-react/issues/428)) ([1d947fc](https://www.github.com/iTwin/iTwinUI-react/commit/1d947fc3f55091b9b6da1ed7e7fa167b931cb8a0))
31
+
32
+ ## [1.24.0](https://www.github.com/iTwin/iTwinUI-react/compare/v1.23.2...v1.24.0) (2021-11-09)
33
+
34
+ ### What's new
35
+
36
+ * **ColorPicker:** Add `showAlpha` prop to show opacity slider and input ([#408](https://www.github.com/iTwin/iTwinUI-react/issues/408)) ([a2a7528](https://www.github.com/iTwin/iTwinUI-react/commit/a2a75283f20d2fad937361779cbe04dc99d0cc74))
37
+
3
38
  ### [1.23.2](https://www.github.com/iTwin/iTwinUI-react/compare/v1.23.1...v1.23.2) (2021-11-04)
4
39
 
5
40
  ### Fixes
@@ -43,7 +43,7 @@ export declare const Button: React.ForwardRefExoticComponent<{
43
43
  * Use 'borderless' to hide outline.
44
44
  * @default 'default'
45
45
  */
46
- styleType?: "cta" | "high-visibility" | "default" | "borderless" | undefined;
46
+ styleType?: "default" | "cta" | "high-visibility" | "borderless" | undefined;
47
47
  /**
48
48
  * Icon shown before the main button content.
49
49
  */
@@ -50,20 +50,24 @@ var getHorizontalPercentageOfRectangle = function (rect, pointer) {
50
50
  * and a set of sliders to adjust hue and alpha values.
51
51
  */
52
52
  exports.ColorBuilder = react_1.default.forwardRef(function (props, ref) {
53
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
53
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
54
54
  var className = props.className, rest = __rest(props, ["className"]);
55
55
  var builderRef = react_1.default.useRef();
56
56
  var refs = (0, utils_1.useMergedRefs)(builderRef, ref);
57
57
  (0, utils_1.useTheme)();
58
- var _k = (0, ColorPickerContext_1.useColorPickerContext)(), activeColor = _k.activeColor, hsvColor = _k.hsvColor, onChangeComplete = _k.onChangeComplete, applyHsvColorChange = _k.applyHsvColorChange;
58
+ var _o = (0, ColorPickerContext_1.useColorPickerContext)(), activeColor = _o.activeColor, hsvColor = _o.hsvColor, onChangeComplete = _o.onChangeComplete, applyHsvColorChange = _o.applyHsvColorChange, showAlpha = _o.showAlpha;
59
59
  // Set values for slider
60
- var hueSliderColor = react_1.default.useMemo(function () { return utils_1.ColorValue.create({ h: hsvColor.h, s: 100, v: 100 }); }, [hsvColor]);
60
+ var hueSliderColor = react_1.default.useMemo(function () { return utils_1.ColorValue.create({ h: hsvColor.h, s: 100, v: 100 }); }, [hsvColor.h]);
61
61
  var sliderValue = react_1.default.useMemo(function () { return hsvColor.h; }, [hsvColor]);
62
+ var alphaValue = react_1.default.useMemo(function () { var _a; return (showAlpha ? (_a = hsvColor.a) !== null && _a !== void 0 ? _a : 1 : 1); }, [
63
+ hsvColor.a,
64
+ showAlpha,
65
+ ]);
62
66
  // Set values for color square and color dot
63
67
  var dotColorString = react_1.default.useMemo(function () { return activeColor.toHexString(); }, [
64
68
  activeColor,
65
69
  ]);
66
- var _l = react_1.default.useState(false), colorDotActive = _l[0], setColorDotActive = _l[1];
70
+ var _p = react_1.default.useState(false), colorDotActive = _p[0], setColorDotActive = _p[1];
67
71
  var hueColorString = hueSliderColor.toHexString();
68
72
  var colorSquareStyle = ((_c = (_b = (_a = (0, utils_1.getWindow)()) === null || _a === void 0 ? void 0 : _a.CSS) === null || _b === void 0 ? void 0 : _b.supports) === null || _c === void 0 ? void 0 : _c.call(_b, "--hue:\u00A0" + hueColorString))
69
73
  ? {
@@ -71,9 +75,12 @@ exports.ColorBuilder = react_1.default.forwardRef(function (props, ref) {
71
75
  '--selected-color': dotColorString,
72
76
  }
73
77
  : { backgroundColor: hueColorString };
78
+ var opacitySliderStyle = ((_f = (_e = (_d = (0, utils_1.getWindow)()) === null || _d === void 0 ? void 0 : _d.CSS) === null || _e === void 0 ? void 0 : _e.supports) === null || _f === void 0 ? void 0 : _f.call(_e, "--selected-color:\u00A0" + hueColorString))
79
+ ? { '--selected-color': hueColorString }
80
+ : { backgroundColor: hueColorString };
74
81
  var squareTop = 100 - hsvColor.v;
75
82
  var squareLeft = hsvColor.s;
76
- var colorDotStyle = ((_f = (_e = (_d = (0, utils_1.getWindow)()) === null || _d === void 0 ? void 0 : _d.CSS) === null || _e === void 0 ? void 0 : _e.supports) === null || _f === void 0 ? void 0 : _f.call(_e, "--top:\u00A0" + squareTop.toString() + "%"))
83
+ var colorDotStyle = ((_j = (_h = (_g = (0, utils_1.getWindow)()) === null || _g === void 0 ? void 0 : _g.CSS) === null || _h === void 0 ? void 0 : _h.supports) === null || _j === void 0 ? void 0 : _j.call(_h, "--top:\u00A0" + squareTop.toString() + "%"))
77
84
  ? {
78
85
  '--top': squareTop.toString() + '%',
79
86
  '--left': squareLeft.toString() + '%',
@@ -84,15 +91,27 @@ exports.ColorBuilder = react_1.default.forwardRef(function (props, ref) {
84
91
  left: squareLeft.toString() + '%',
85
92
  };
86
93
  // Update slider change
87
- var updateSlider = react_1.default.useCallback(function (huePercent, selectionChanged) {
88
- var hue = Math.round(huePercent);
94
+ var updateHueSlider = react_1.default.useCallback(function (huePercent, selectionChanged) {
95
+ var hue = Number(huePercent.toFixed(2));
89
96
  var newHsvColor = {
90
97
  h: hue,
91
98
  s: hsvColor.s,
92
99
  v: hsvColor.v,
100
+ a: hsvColor.a,
93
101
  };
94
102
  applyHsvColorChange(newHsvColor, selectionChanged);
95
- }, [applyHsvColorChange, hsvColor.s, hsvColor.v]);
103
+ }, [applyHsvColorChange, hsvColor]);
104
+ // Update opacity slider change
105
+ var updateOpacitySlider = react_1.default.useCallback(function (alphaPercent, selectionChanged) {
106
+ var alpha = Number(alphaPercent.toFixed(2));
107
+ var newHsvColor = {
108
+ h: hsvColor.h,
109
+ s: hsvColor.s,
110
+ v: hsvColor.v,
111
+ a: alpha,
112
+ };
113
+ applyHsvColorChange(newHsvColor, selectionChanged);
114
+ }, [applyHsvColorChange, hsvColor]);
96
115
  // Update Color field square change
97
116
  var squareRef = react_1.default.useRef(null);
98
117
  var colorDotRef = react_1.default.useRef(null);
@@ -101,9 +120,10 @@ exports.ColorBuilder = react_1.default.forwardRef(function (props, ref) {
101
120
  h: hsvColor.h,
102
121
  s: x,
103
122
  v: 100 - y,
123
+ a: hsvColor.a,
104
124
  };
105
125
  applyHsvColorChange(newHsvColor, selectionChanged);
106
- }, [applyHsvColorChange, hsvColor.h]);
126
+ }, [applyHsvColorChange, hsvColor]);
107
127
  var updateSquareValue = react_1.default.useCallback(function (event, callbackType) {
108
128
  if ((squareRef.current && colorDotActive) ||
109
129
  (squareRef.current && callbackType === 'onClick')) {
@@ -123,18 +143,18 @@ exports.ColorBuilder = react_1.default.forwardRef(function (props, ref) {
123
143
  event.preventDefault();
124
144
  event.stopPropagation();
125
145
  }, [updateSquareValue]);
126
- (0, utils_1.useEventListener)('pointerup', handleSquarePointerUp, (_g = builderRef.current) === null || _g === void 0 ? void 0 : _g.ownerDocument);
146
+ (0, utils_1.useEventListener)('pointerup', handleSquarePointerUp, (_k = builderRef.current) === null || _k === void 0 ? void 0 : _k.ownerDocument);
127
147
  var handleSquarePointerMove = react_1.default.useCallback(function (event) {
128
148
  event.preventDefault();
129
149
  event.stopPropagation();
130
150
  updateSquareValue(event, 'onUpdate');
131
151
  }, [updateSquareValue]);
132
- (0, utils_1.useEventListener)('pointermove', handleSquarePointerMove, (_h = builderRef.current) === null || _h === void 0 ? void 0 : _h.ownerDocument);
152
+ (0, utils_1.useEventListener)('pointermove', handleSquarePointerMove, (_l = builderRef.current) === null || _l === void 0 ? void 0 : _l.ownerDocument);
133
153
  var handleSquarePointerLeave = react_1.default.useCallback(function (event) {
134
154
  updateSquareValue(event, 'onChange');
135
155
  setColorDotActive(false);
136
156
  }, [updateSquareValue]);
137
- (0, utils_1.useEventListener)('pointerleave', handleSquarePointerLeave, (_j = builderRef.current) === null || _j === void 0 ? void 0 : _j.ownerDocument);
157
+ (0, utils_1.useEventListener)('pointerleave', handleSquarePointerLeave, (_m = builderRef.current) === null || _m === void 0 ? void 0 : _m.ownerDocument);
138
158
  var keysPressed = react_1.default.useRef({}); // keep track of which keys are currently pressed
139
159
  // Arrow key navigation for color dot
140
160
  var handleColorDotKeyDown = function (event) {
@@ -193,8 +213,13 @@ exports.ColorBuilder = react_1.default.forwardRef(function (props, ref) {
193
213
  (_a = colorDotRef.current) === null || _a === void 0 ? void 0 : _a.focus();
194
214
  }, onKeyDown: handleColorDotKeyDown, onKeyUp: handleColorDotKeyUp, tabIndex: 0, ref: colorDotRef })),
195
215
  react_1.default.createElement(Slider_1.Slider, { minLabel: '', maxLabel: '', values: [sliderValue], className: 'iui-hue-slider', trackDisplayMode: 'none', tooltipProps: function () { return ({ visible: false }); }, onChange: function (values) {
196
- updateSlider(values[0], true);
216
+ updateHueSlider(values[0], true);
217
+ }, onUpdate: function (values) {
218
+ updateHueSlider(values[0], false);
219
+ }, min: 0, max: 359 }),
220
+ showAlpha && (react_1.default.createElement(Slider_1.Slider, { minLabel: '', maxLabel: '', values: [alphaValue], className: 'iui-opacity-slider', trackDisplayMode: 'none', tooltipProps: function () { return ({ visible: false }); }, onChange: function (values) {
221
+ updateOpacitySlider(values[0], true);
197
222
  }, onUpdate: function (values) {
198
- updateSlider(values[0], false);
199
- }, min: 0, max: 359 })));
223
+ updateOpacitySlider(values[0], false);
224
+ }, min: 0, max: 1, step: 0.01, style: opacitySliderStyle }))));
200
225
  });
@@ -47,43 +47,62 @@ require("@itwin/itwinui-css/css/color-picker.css");
47
47
  * </ColorPicker>
48
48
  */
49
49
  exports.ColorInputPanel = react_1.default.forwardRef(function (props, ref) {
50
- var defaultColorFormat = props.defaultColorFormat, _a = props.allowedColorFormats, allowedColorFormats = _a === void 0 ? ['hsl', 'rgb', 'hex'] : _a, className = props.className, rest = __rest(props, ["defaultColorFormat", "allowedColorFormats", "className"]);
50
+ var _a, _b, _c, _d, _f, _g, _h, _j;
51
+ var defaultColorFormat = props.defaultColorFormat, _k = props.allowedColorFormats, allowedColorFormats = _k === void 0 ? ['hsl', 'rgb', 'hex'] : _k, className = props.className, rest = __rest(props, ["defaultColorFormat", "allowedColorFormats", "className"]);
51
52
  (0, utils_1.useTheme)();
52
- var _b = (0, ColorPickerContext_1.useColorPickerContext)(), activeColor = _b.activeColor, applyHsvColorChange = _b.applyHsvColorChange, hsvColor = _b.hsvColor;
53
- var _c = react_1.default.useState(defaultColorFormat), currentFormat = _c[0], setCurrentFormat = _c[1];
53
+ var inputsContainerRef = react_1.default.useRef(null);
54
+ var _l = (0, ColorPickerContext_1.useColorPickerContext)(), activeColor = _l.activeColor, applyHsvColorChange = _l.applyHsvColorChange, hsvColor = _l.hsvColor, showAlpha = _l.showAlpha;
55
+ var _m = react_1.default.useState(defaultColorFormat), currentFormat = _m[0], setCurrentFormat = _m[1];
54
56
  react_1.default.useEffect(function () {
55
57
  setCurrentFormat(defaultColorFormat);
56
58
  }, [defaultColorFormat]);
57
59
  // need to use state since input may have parsing error
58
- var _d = react_1.default.useState([]), input = _d[0], setInput = _d[1];
60
+ var _o = react_1.default.useState(['', '', '', '']), input = _o[0], setInput = _o[1];
59
61
  react_1.default.useEffect(function () {
62
+ var _a, _b;
60
63
  if (currentFormat === 'hsl') {
61
64
  var hsl = activeColor.toHslColor();
62
- // use activeHue to preserve hue for 0,0,0 edge case
63
- setInput([hsvColor.h.toString(), hsl.s.toString(), hsl.l.toString()]);
65
+ setInput([
66
+ utils_1.ColorValue.getFormattedColorNumber(hsvColor.h),
67
+ utils_1.ColorValue.getFormattedColorNumber(hsl.s),
68
+ utils_1.ColorValue.getFormattedColorNumber(hsl.l),
69
+ utils_1.ColorValue.getFormattedColorNumber((_a = hsl.a) !== null && _a !== void 0 ? _a : activeColor.getAlpha() / 255, 2),
70
+ ]);
64
71
  }
65
72
  else if (currentFormat === 'rgb') {
66
73
  var rgb = activeColor.toRgbColor();
67
- setInput([rgb.r.toString(), rgb.g.toString(), rgb.b.toString()]);
74
+ setInput([
75
+ rgb.r.toString(),
76
+ rgb.g.toString(),
77
+ rgb.b.toString(),
78
+ utils_1.ColorValue.getFormattedColorNumber((_b = rgb.a) !== null && _b !== void 0 ? _b : activeColor.getAlpha() / 255, 2),
79
+ ]);
68
80
  }
69
81
  else {
70
- setInput([activeColor.toHexString()]);
82
+ setInput([activeColor.toHexString(showAlpha)]);
83
+ setValidHexInput(true);
71
84
  }
72
- }, [activeColor, hsvColor.h, currentFormat]);
73
- var _f = react_1.default.useState(true), validHexInput = _f[0], setValidHexInput = _f[1];
85
+ }, [activeColor, hsvColor.h, currentFormat, showAlpha]);
86
+ var _p = react_1.default.useState(true), validHexInput = _p[0], setValidHexInput = _p[1];
74
87
  var swapColorFormat = react_1.default.useCallback(function () {
75
88
  var _a;
76
89
  var newFormat = (_a = allowedColorFormats[(allowedColorFormats.indexOf(currentFormat) + 1) %
77
90
  allowedColorFormats.length]) !== null && _a !== void 0 ? _a : allowedColorFormats[0];
78
91
  setCurrentFormat(newFormat);
79
92
  }, [currentFormat, allowedColorFormats]);
93
+ var isFocusInside = function (focused) {
94
+ return !!(focused &&
95
+ inputsContainerRef.current &&
96
+ inputsContainerRef.current.contains(focused));
97
+ };
80
98
  var handleColorInputChange = function () {
81
99
  var color;
82
100
  if (currentFormat === 'hex') {
83
101
  try {
84
- color = utils_1.ColorValue.fromString(input[0]);
102
+ var value = input[0].replace(/ /g, '').toLowerCase(); // remove white space from input
103
+ color = utils_1.ColorValue.create(value);
85
104
  setValidHexInput(true);
86
- if (activeColor.toHexString() === input[0]) {
105
+ if (activeColor.toHexString(showAlpha).toLowerCase() === value) {
87
106
  return;
88
107
  }
89
108
  }
@@ -93,33 +112,47 @@ exports.ColorInputPanel = react_1.default.forwardRef(function (props, ref) {
93
112
  }
94
113
  }
95
114
  if (currentFormat === 'hsl') {
96
- var _a = input.map(Number), h = _a[0], s = _a[1], l = _a[2];
97
- if (h < 0 || h > 360 || s < 0 || s > 100 || l < 0 || l > 100) {
115
+ var _a = input.map(Number), h = _a[0], s = _a[1], l = _a[2], a = _a[3];
116
+ if (h < 0 ||
117
+ h > 360 ||
118
+ s < 0 ||
119
+ s > 100 ||
120
+ l < 0 ||
121
+ l > 100 ||
122
+ a < 0 ||
123
+ a > 1) {
98
124
  return;
99
125
  }
100
126
  var hsl = activeColor.toHslColor();
101
- if (hsl.h === h && hsl.s === s && hsl.l === l) {
127
+ if (hsl.h === h && hsl.s === s && hsl.l === l && hsl.a === a) {
102
128
  return;
103
129
  }
104
- color = utils_1.ColorValue.create({ h: h, s: s, l: l });
130
+ color = utils_1.ColorValue.create({ h: h, s: s, l: l, a: a });
105
131
  }
106
132
  if (currentFormat === 'rgb') {
107
- var _b = input.map(Number), r = _b[0], g = _b[1], b = _b[2];
108
- if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
133
+ var _b = input.map(Number), r = _b[0], g = _b[1], b = _b[2], a = _b[3];
134
+ if (r < 0 ||
135
+ r > 255 ||
136
+ g < 0 ||
137
+ g > 255 ||
138
+ b < 0 ||
139
+ b > 255 ||
140
+ a < 0 ||
141
+ a > 1) {
109
142
  return;
110
143
  }
111
144
  var rgb = activeColor.toRgbColor();
112
- if (rgb.r === r && rgb.g === g && rgb.b === b) {
145
+ if (rgb.r === r && rgb.g === g && rgb.b === b && rgb.a === a) {
113
146
  return;
114
147
  }
115
- color = utils_1.ColorValue.create({ r: r, g: g, b: b });
148
+ color = utils_1.ColorValue.create({ r: r, g: g, b: b, a: a });
116
149
  }
117
150
  if (color) {
118
- applyHsvColorChange(color.toHsvColor(), true);
151
+ applyHsvColorChange(color.toHsvColor(), true, color);
119
152
  }
120
153
  };
121
154
  var hexInputField = (react_1.default.createElement(utils_1.InputContainer, { status: validHexInput ? undefined : 'negative' },
122
- react_1.default.createElement(Input_1.Input, { size: 'small', maxLength: 7, minLength: 1, placeholder: 'HEX', value: input[0], onChange: function (event) {
155
+ react_1.default.createElement(Input_1.Input, { size: 'small', maxLength: showAlpha ? 9 : 7, minLength: 1, placeholder: 'HEX', value: input[0], onChange: function (event) {
123
156
  var value = event.target.value.startsWith('#')
124
157
  ? event.target.value
125
158
  : "#" + event.target.value;
@@ -137,8 +170,8 @@ exports.ColorInputPanel = react_1.default.forwardRef(function (props, ref) {
137
170
  react_1.default.createElement(utils_1.InputContainer, { status: Number(input[0]) < 0 || Number(input[0]) > 360
138
171
  ? 'negative'
139
172
  : undefined },
140
- react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '359', placeholder: 'H', value: input[0], onChange: function (event) {
141
- setInput([event.target.value, input[1], input[2]]);
173
+ react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '359', step: '.1', placeholder: 'H', value: (_a = input[0]) !== null && _a !== void 0 ? _a : '', onChange: function (event) {
174
+ setInput([event.target.value, input[1], input[2], input[3]]);
142
175
  }, onKeyDown: function (event) {
143
176
  if (event.key === 'Enter') {
144
177
  event.preventDefault();
@@ -146,13 +179,15 @@ exports.ColorInputPanel = react_1.default.forwardRef(function (props, ref) {
146
179
  }
147
180
  }, onBlur: function (event) {
148
181
  event.preventDefault();
149
- handleColorInputChange();
182
+ if (!isFocusInside(event.relatedTarget)) {
183
+ handleColorInputChange();
184
+ }
150
185
  } })),
151
186
  react_1.default.createElement(utils_1.InputContainer, { status: Number(input[1]) < 0 || Number(input[1]) > 100
152
187
  ? 'negative'
153
188
  : undefined },
154
- react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '100', placeholder: 'S', value: input[1], onChange: function (event) {
155
- setInput([input[0], event.target.value, input[2]]);
189
+ react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '100', step: '.1', placeholder: 'S', value: (_b = input[1]) !== null && _b !== void 0 ? _b : '', onChange: function (event) {
190
+ setInput([input[0], event.target.value, input[2], input[3]]);
156
191
  }, onKeyDown: function (event) {
157
192
  if (event.key === 'Enter') {
158
193
  event.preventDefault();
@@ -160,13 +195,15 @@ exports.ColorInputPanel = react_1.default.forwardRef(function (props, ref) {
160
195
  }
161
196
  }, onBlur: function (event) {
162
197
  event.preventDefault();
163
- handleColorInputChange();
198
+ if (!isFocusInside(event.relatedTarget)) {
199
+ handleColorInputChange();
200
+ }
164
201
  } })),
165
202
  react_1.default.createElement(utils_1.InputContainer, { status: Number(input[2]) < 0 || Number(input[2]) > 100
166
203
  ? 'negative'
167
204
  : undefined },
168
- react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '100', placeholder: 'L', value: input[2], onChange: function (event) {
169
- setInput([input[0], input[1], event.target.value]);
205
+ react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '100', step: '.1', placeholder: 'L', value: (_c = input[2]) !== null && _c !== void 0 ? _c : '', onChange: function (event) {
206
+ setInput([input[0], input[1], event.target.value, input[3]]);
170
207
  }, onKeyDown: function (event) {
171
208
  if (event.key === 'Enter') {
172
209
  event.preventDefault();
@@ -174,14 +211,32 @@ exports.ColorInputPanel = react_1.default.forwardRef(function (props, ref) {
174
211
  }
175
212
  }, onBlur: function (event) {
176
213
  event.preventDefault();
177
- handleColorInputChange();
178
- } }))));
214
+ if (!isFocusInside(event.relatedTarget)) {
215
+ handleColorInputChange();
216
+ }
217
+ } })),
218
+ showAlpha && (react_1.default.createElement(utils_1.InputContainer, { status: Number(input[3]) < 0 || Number(input[3]) > 1
219
+ ? 'negative'
220
+ : undefined },
221
+ react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '1', step: '.01', placeholder: 'A', value: (_d = input[3]) !== null && _d !== void 0 ? _d : '', onChange: function (event) {
222
+ setInput([input[0], input[1], input[2], event.target.value]);
223
+ }, onKeyDown: function (event) {
224
+ if (event.key === 'Enter') {
225
+ event.preventDefault();
226
+ handleColorInputChange();
227
+ }
228
+ }, onBlur: function (event) {
229
+ event.preventDefault();
230
+ if (!isFocusInside(event.relatedTarget)) {
231
+ handleColorInputChange();
232
+ }
233
+ } })))));
179
234
  var rgbInputs = (react_1.default.createElement(react_1.default.Fragment, null,
180
235
  react_1.default.createElement(utils_1.InputContainer, { status: Number(input[0]) < 0 || Number(input[0]) > 255
181
236
  ? 'negative'
182
237
  : undefined },
183
- react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '255', placeholder: 'R', value: input[0], onChange: function (event) {
184
- setInput([event.target.value, input[1], input[2]]);
238
+ react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '255', placeholder: 'R', value: (_f = input[0]) !== null && _f !== void 0 ? _f : '', onChange: function (event) {
239
+ setInput([event.target.value, input[1], input[2], input[3]]);
185
240
  }, onKeyDown: function (event) {
186
241
  if (event.key === 'Enter') {
187
242
  event.preventDefault();
@@ -189,13 +244,15 @@ exports.ColorInputPanel = react_1.default.forwardRef(function (props, ref) {
189
244
  }
190
245
  }, onBlur: function (event) {
191
246
  event.preventDefault();
192
- handleColorInputChange();
247
+ if (!isFocusInside(event.relatedTarget)) {
248
+ handleColorInputChange();
249
+ }
193
250
  } })),
194
251
  react_1.default.createElement(utils_1.InputContainer, { status: Number(input[1]) < 0 || Number(input[1]) > 255
195
252
  ? 'negative'
196
253
  : undefined },
197
- react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '255', placeholder: 'G', value: input[1], onChange: function (event) {
198
- setInput([input[0], event.target.value, input[2]]);
254
+ react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '255', placeholder: 'G', value: (_g = input[1]) !== null && _g !== void 0 ? _g : '', onChange: function (event) {
255
+ setInput([input[0], event.target.value, input[2], input[3]]);
199
256
  }, onKeyDown: function (event) {
200
257
  if (event.key === 'Enter') {
201
258
  event.preventDefault();
@@ -203,13 +260,15 @@ exports.ColorInputPanel = react_1.default.forwardRef(function (props, ref) {
203
260
  }
204
261
  }, onBlur: function (event) {
205
262
  event.preventDefault();
206
- handleColorInputChange();
263
+ if (!isFocusInside(event.relatedTarget)) {
264
+ handleColorInputChange();
265
+ }
207
266
  } })),
208
267
  react_1.default.createElement(utils_1.InputContainer, { status: Number(input[2]) < 0 || Number(input[2]) > 255
209
268
  ? 'negative'
210
269
  : undefined },
211
- react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '255', placeholder: 'B', value: input[2], onChange: function (event) {
212
- setInput([input[0], input[1], event.target.value]);
270
+ react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '255', placeholder: 'B', value: (_h = input[2]) !== null && _h !== void 0 ? _h : '', onChange: function (event) {
271
+ setInput([input[0], input[1], event.target.value, input[3]]);
213
272
  }, onKeyDown: function (event) {
214
273
  if (event.key === 'Enter') {
215
274
  event.preventDefault();
@@ -217,17 +276,37 @@ exports.ColorInputPanel = react_1.default.forwardRef(function (props, ref) {
217
276
  }
218
277
  }, onBlur: function (event) {
219
278
  event.preventDefault();
220
- handleColorInputChange();
221
- } }))));
279
+ if (!isFocusInside(event.relatedTarget)) {
280
+ handleColorInputChange();
281
+ }
282
+ } })),
283
+ showAlpha && (react_1.default.createElement(utils_1.InputContainer, { status: Number(input[3]) < 0 || Number(input[3]) > 1
284
+ ? 'negative'
285
+ : undefined },
286
+ react_1.default.createElement(Input_1.Input, { size: 'small', type: 'number', min: '0', max: '1', step: '.01', placeholder: 'A', value: (_j = input[3]) !== null && _j !== void 0 ? _j : '', onChange: function (event) {
287
+ setInput([input[0], input[1], input[2], event.target.value]);
288
+ }, onKeyDown: function (event) {
289
+ if (event.key === 'Enter') {
290
+ event.preventDefault();
291
+ handleColorInputChange();
292
+ }
293
+ }, onBlur: function (event) {
294
+ event.preventDefault();
295
+ if (!isFocusInside(event.relatedTarget)) {
296
+ handleColorInputChange();
297
+ }
298
+ } })))));
222
299
  return (react_1.default.createElement("div", __assign({ className: (0, classnames_1.default)('iui-color-input-wrapper', className), ref: ref }, rest),
223
- react_1.default.createElement("div", { className: 'iui-color-picker-section-label' }, currentFormat.toUpperCase()),
300
+ react_1.default.createElement("div", { className: 'iui-color-picker-section-label' }, showAlpha && currentFormat != 'hex'
301
+ ? currentFormat.toUpperCase() + 'A'
302
+ : currentFormat.toUpperCase()),
224
303
  react_1.default.createElement("div", { className: 'iui-color-input' },
225
304
  allowedColorFormats.length > 1 && (react_1.default.createElement(Buttons_1.IconButton, { styleType: 'borderless', onClick: swapColorFormat, size: 'small' },
226
305
  react_1.default.createElement("svg", { viewBox: '0 0 16 16', className: 'iui-icon', "aria-hidden": true },
227
306
  react_1.default.createElement("path", { d: 'm5 15-3.78125-3.5 3.78125-3.5v2h8v3h-8zm6-7 3.78125-3.5-3.78125-3.5v2h-8v3h8z' })))),
228
- react_1.default.createElement("div", { className: 'iui-color-input-fields' },
307
+ react_1.default.createElement("div", { ref: inputsContainerRef, className: 'iui-color-input-fields' },
229
308
  currentFormat === 'hex' && hexInputField,
230
- currentFormat === 'hsl' && hslInputs,
231
- currentFormat === 'rgb' && rgbInputs))));
309
+ currentFormat === 'rgb' && rgbInputs,
310
+ currentFormat === 'hsl' && hslInputs))));
232
311
  });
233
312
  exports.default = exports.ColorInputPanel;
@@ -30,6 +30,11 @@ export declare type ColorPickerProps = {
30
30
  * @default false
31
31
  */
32
32
  setFocus?: boolean;
33
+ /**
34
+ * If true, ColorBuilder will show the alpha slider and ColorInputPanel will show an alpha input.
35
+ * @default false
36
+ */
37
+ showAlpha?: boolean;
33
38
  } & Omit<CommonProps, 'title'>;
34
39
  /**
35
40
  * ColorPicker to display color builder options, color inputs, and a palette of ColorSwatches.
@@ -56,7 +56,7 @@ exports.getColorValue = getColorValue;
56
56
  * </ColorPicker>
57
57
  */
58
58
  var ColorPicker = function (props) {
59
- var children = props.children, className = props.className, selectedColor = props.selectedColor, onChange = props.onChange, onChangeComplete = props.onChangeComplete, _a = props.setFocus, setFocus = _a === void 0 ? false : _a, rest = __rest(props, ["children", "className", "selectedColor", "onChange", "onChangeComplete", "setFocus"]);
59
+ var children = props.children, className = props.className, selectedColor = props.selectedColor, onChange = props.onChange, onChangeComplete = props.onChangeComplete, _a = props.setFocus, setFocus = _a === void 0 ? false : _a, _b = props.showAlpha, showAlpha = _b === void 0 ? false : _b, rest = __rest(props, ["children", "className", "selectedColor", "onChange", "onChangeComplete", "setFocus", "showAlpha"]);
60
60
  (0, utils_1.useTheme)();
61
61
  var ref = react_1.default.useRef(null);
62
62
  // set focus on the first tabbable element
@@ -70,13 +70,13 @@ var ColorPicker = function (props) {
70
70
  selectedColor,
71
71
  ]);
72
72
  var activeColorTbgr = react_1.default.useRef(inColor.toTbgr());
73
- var _b = react_1.default.useState(inColor), activeColor = _b[0], setActiveColor = _b[1]; // Color of colorDot or active ColorSwatch
73
+ var _c = react_1.default.useState(inColor), activeColor = _c[0], setActiveColor = _c[1]; // Color of colorDot or active ColorSwatch
74
74
  react_1.default.useEffect(function () {
75
75
  setActiveColor(inColor);
76
76
  }, [inColor]);
77
- var _c = react_1.default.useState(function () {
77
+ var _d = react_1.default.useState(function () {
78
78
  return activeColor.toHsvColor();
79
- }), hsvColor = _c[0], setHsvColor = _c[1];
79
+ }), hsvColor = _d[0], setHsvColor = _d[1];
80
80
  // The following code is used to preserve the Hue after initial mount. If the current HSV value produces the same rgb value
81
81
  // as the selectedColor prop then leave the HSV color unchanged. This prevents the jumping of HUE as the s/v values are changed
82
82
  // by user moving the pointer.
@@ -86,10 +86,10 @@ var ColorPicker = function (props) {
86
86
  setHsvColor(inColor.toHsvColor());
87
87
  }
88
88
  }, [inColor]);
89
- var applyHsvColorChange = react_1.default.useCallback(function (newColor, selectionChanged) {
89
+ var applyHsvColorChange = react_1.default.useCallback(function (newColor, selectionChanged, newColorValue) {
90
90
  // save the HSV values
91
91
  setHsvColor(newColor);
92
- var newActiveColor = utils_1.ColorValue.create(newColor);
92
+ var newActiveColor = newColorValue !== null && newColorValue !== void 0 ? newColorValue : utils_1.ColorValue.create(newColor);
93
93
  // Only update selected color when dragging is done
94
94
  if (selectionChanged) {
95
95
  onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(newActiveColor);
@@ -108,6 +108,7 @@ var ColorPicker = function (props) {
108
108
  hsvColor: hsvColor,
109
109
  applyHsvColorChange: applyHsvColorChange,
110
110
  onChangeComplete: onChangeComplete,
111
+ showAlpha: showAlpha,
111
112
  } }, children)));
112
113
  };
113
114
  exports.ColorPicker = ColorPicker;
@@ -5,12 +5,14 @@ export declare const ColorPickerContext: React.Context<{
5
5
  setActiveColor: (color: ColorValue | ((prevColor: ColorValue) => ColorValue)) => void;
6
6
  hsvColor: HsvColor;
7
7
  onChangeComplete?: ((color: ColorValue) => void) | undefined;
8
- applyHsvColorChange: (newColor: HsvColor, selectionChanged: boolean) => void;
8
+ applyHsvColorChange: (newColor: HsvColor, selectionChanged: boolean, newColorValue?: ColorValue | undefined) => void;
9
+ showAlpha: boolean;
9
10
  } | undefined>;
10
11
  export declare const useColorPickerContext: () => {
11
12
  activeColor: ColorValue;
12
13
  setActiveColor: (color: ColorValue | ((prevColor: ColorValue) => ColorValue)) => void;
13
14
  hsvColor: HsvColor;
14
15
  onChangeComplete?: ((color: ColorValue) => void) | undefined;
15
- applyHsvColorChange: (newColor: HsvColor, selectionChanged: boolean) => void;
16
+ applyHsvColorChange: (newColor: HsvColor, selectionChanged: boolean, newColorValue?: ColorValue | undefined) => void;
17
+ showAlpha: boolean;
16
18
  };
@@ -17,5 +17,5 @@ export declare type ColorSwatchProps = {
17
17
  * <ColorSwatch color='#23450b' onClick={onClick}/>
18
18
  * <ColorSwatch color={{ r: 255, g: 255, b: 0 }} onClick={onClick}/>
19
19
  */
20
- export declare const ColorSwatch: React.ForwardRefExoticComponent<Pick<ColorSwatchProps, "dir" | "slot" | "style" | "title" | "id" | "role" | "children" | "className" | "accessKey" | "draggable" | "hidden" | "lang" | "translate" | "prefix" | "contentEditable" | "inputMode" | "tabIndex" | "onFocus" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "contextMenu" | "placeholder" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "isActive" | "key"> & React.RefAttributes<HTMLDivElement>>;
20
+ export declare const ColorSwatch: React.ForwardRefExoticComponent<Pick<ColorSwatchProps, "dir" | "slot" | "style" | "title" | "id" | "role" | "children" | "className" | "accessKey" | "draggable" | "hidden" | "lang" | "translate" | "prefix" | "contentEditable" | "inputMode" | "tabIndex" | "onFocus" | "color" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "contextMenu" | "placeholder" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "isActive" | "key"> & React.RefAttributes<HTMLDivElement>>;
21
21
  export default ColorSwatch;
@@ -42,12 +42,18 @@ var ColorPicker_1 = require("./ColorPicker");
42
42
  * <ColorSwatch color={{ r: 255, g: 255, b: 0 }} onClick={onClick}/>
43
43
  */
44
44
  exports.ColorSwatch = react_1.default.forwardRef(function (props, ref) {
45
- var _a, _b, _c;
46
45
  var color = props.color, style = props.style, onClick = props.onClick, isActive = props.isActive, className = props.className, rest = __rest(props, ["color", "style", "onClick", "isActive", "className"]);
47
46
  (0, utils_1.useTheme)();
48
- var c = typeof color === 'string' ? color : (0, ColorPicker_1.getColorValue)(color).toHexString();
49
- var _style = color && ((_c = (_b = (_a = (0, utils_1.getWindow)()) === null || _a === void 0 ? void 0 : _a.CSS) === null || _b === void 0 ? void 0 : _b.supports) === null || _c === void 0 ? void 0 : _c.call(_b, "--swatch-color: " + c))
50
- ? __assign({ '--swatch-color': c }, style) : __assign({ backgroundColor: c }, style);
47
+ var colorString = react_1.default.useMemo(function () {
48
+ return typeof color === 'string'
49
+ ? color
50
+ : (0, ColorPicker_1.getColorValue)(color).toHslString(true);
51
+ }, [color]);
52
+ var _style = react_1.default.useMemo(function () {
53
+ var _a, _b, _c;
54
+ return ((_c = (_b = (_a = (0, utils_1.getWindow)()) === null || _a === void 0 ? void 0 : _a.CSS) === null || _b === void 0 ? void 0 : _b.supports) === null || _c === void 0 ? void 0 : _c.call(_b, "--swatch-color: " + colorString))
55
+ ? __assign({ '--swatch-color': colorString }, style) : __assign({ backgroundColor: colorString }, style);
56
+ }, [colorString, style]);
51
57
  return (react_1.default.createElement("div", __assign({ className: (0, classnames_1.default)('iui-color-swatch', { 'iui-active': isActive }, className), style: _style, onClick: onClick, tabIndex: isActive ? 0 : -1, "aria-selected": isActive, ref: ref }, rest)));
52
58
  });
53
59
  exports.default = exports.ColorSwatch;