@instructure/ui-color-picker 8.26.1 → 8.26.2

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 (75) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/ColorContrast/index.js +43 -35
  3. package/es/ColorIndicator/index.js +4 -14
  4. package/es/ColorMixer/ColorPalette/index.js +6 -6
  5. package/es/ColorMixer/RGBAInput/index.js +5 -5
  6. package/es/ColorMixer/Slider/index.js +5 -5
  7. package/es/ColorMixer/index.js +6 -16
  8. package/es/ColorMixer/props.js +2 -2
  9. package/es/ColorPicker/index.js +65 -77
  10. package/es/ColorPicker/props.js +37 -3
  11. package/es/ColorPreset/ColorPresetLocator.js +53 -1
  12. package/es/ColorPreset/index.js +34 -24
  13. package/es/ColorPreset/props.js +32 -3
  14. package/lib/ColorContrast/index.js +47 -38
  15. package/lib/ColorIndicator/index.js +4 -14
  16. package/lib/ColorMixer/ColorPalette/index.js +7 -7
  17. package/lib/ColorMixer/RGBAInput/index.js +5 -5
  18. package/lib/ColorMixer/Slider/index.js +5 -5
  19. package/lib/ColorMixer/index.js +6 -16
  20. package/lib/ColorMixer/props.js +2 -2
  21. package/lib/ColorPicker/index.js +66 -78
  22. package/lib/ColorPicker/props.js +37 -3
  23. package/lib/ColorPreset/ColorPresetLocator.js +58 -1
  24. package/lib/ColorPreset/index.js +35 -25
  25. package/lib/ColorPreset/props.js +32 -3
  26. package/package.json +25 -25
  27. package/src/ColorContrast/index.tsx +60 -32
  28. package/src/ColorContrast/props.ts +4 -2
  29. package/src/ColorIndicator/index.tsx +5 -5
  30. package/src/ColorMixer/ColorPalette/index.tsx +8 -7
  31. package/src/ColorMixer/ColorPalette/props.ts +2 -1
  32. package/src/ColorMixer/RGBAInput/index.tsx +10 -9
  33. package/src/ColorMixer/RGBAInput/props.ts +2 -1
  34. package/src/ColorMixer/Slider/index.tsx +5 -5
  35. package/src/ColorMixer/index.tsx +12 -14
  36. package/src/ColorMixer/props.ts +5 -34
  37. package/src/ColorPicker/README.md +30 -34
  38. package/src/ColorPicker/index.tsx +71 -68
  39. package/src/ColorPicker/props.ts +79 -37
  40. package/src/ColorPreset/ColorPresetLocator.ts +47 -1
  41. package/src/ColorPreset/README.md +4 -2
  42. package/src/ColorPreset/index.tsx +34 -24
  43. package/src/ColorPreset/props.ts +44 -13
  44. package/tsconfig.build.tsbuildinfo +1 -1
  45. package/types/ColorContrast/index.d.ts +5 -1
  46. package/types/ColorContrast/index.d.ts.map +1 -1
  47. package/types/ColorContrast/props.d.ts +4 -2
  48. package/types/ColorContrast/props.d.ts.map +1 -1
  49. package/types/ColorIndicator/index.d.ts +0 -1
  50. package/types/ColorIndicator/index.d.ts.map +1 -1
  51. package/types/ColorMixer/ColorPalette/index.d.ts +6 -6
  52. package/types/ColorMixer/ColorPalette/index.d.ts.map +1 -1
  53. package/types/ColorMixer/ColorPalette/props.d.ts +1 -1
  54. package/types/ColorMixer/ColorPalette/props.d.ts.map +1 -1
  55. package/types/ColorMixer/RGBAInput/index.d.ts +22 -12
  56. package/types/ColorMixer/RGBAInput/index.d.ts.map +1 -1
  57. package/types/ColorMixer/RGBAInput/props.d.ts +1 -1
  58. package/types/ColorMixer/RGBAInput/props.d.ts.map +1 -1
  59. package/types/ColorMixer/Slider/index.d.ts +5 -5
  60. package/types/ColorMixer/Slider/index.d.ts.map +1 -1
  61. package/types/ColorMixer/index.d.ts +5 -4
  62. package/types/ColorMixer/index.d.ts.map +1 -1
  63. package/types/ColorMixer/props.d.ts +3 -24
  64. package/types/ColorMixer/props.d.ts.map +1 -1
  65. package/types/ColorPicker/ColorPickerLocator.d.ts +5 -5
  66. package/types/ColorPicker/index.d.ts +24 -25
  67. package/types/ColorPicker/index.d.ts.map +1 -1
  68. package/types/ColorPicker/props.d.ts +32 -33
  69. package/types/ColorPicker/props.d.ts.map +1 -1
  70. package/types/ColorPreset/ColorPresetLocator.d.ts +1452 -10
  71. package/types/ColorPreset/ColorPresetLocator.d.ts.map +1 -1
  72. package/types/ColorPreset/index.d.ts +17 -7
  73. package/types/ColorPreset/index.d.ts.map +1 -1
  74. package/types/ColorPreset/props.d.ts +9 -9
  75. package/types/ColorPreset/props.d.ts.map +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [8.26.2](https://github.com/instructure/instructure-ui/compare/v8.26.1...v8.26.2) (2022-07-11)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **ui-color-picker:** fix required props for `ColorPicker` and sub-components ([4d38fb6](https://github.com/instructure/instructure-ui/commit/4d38fb61caaf5ca9140403db75d2ae56fe5be46b))
11
+
12
+ **WARNING!** Since this commit fixes props that should be required props, some code changes might be needed.
13
+
6
14
  ## [8.26.1](https://github.com/instructure/instructure-ui/compare/v8.26.0...v8.26.1) (2022-07-06)
7
15
 
8
16
  **Note:** Version bump only for package @instructure/ui-color-picker
@@ -1,6 +1,3 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
- const _excluded = ["styles", "elementRef", "failureLabel", "successLabel", "withoutColorPreview", "firstColor", "secondColor", "label", "firstColorLabel", "secondColorLabel", "normalTextLabel", "largeTextLabel", "graphicsTextLabel"];
3
-
4
1
  var _dec, _dec2, _class, _class2;
5
2
 
6
3
  /*
@@ -31,23 +28,24 @@ var _dec, _dec2, _class, _class2;
31
28
 
32
29
  /** @jsxFrag React.Fragment */
33
30
  import React, { Component } from 'react';
34
- import { passthroughProps } from '@instructure/ui-react-utils';
31
+ import { omitProps } from '@instructure/ui-react-utils';
35
32
  import { testable } from '@instructure/ui-testable';
33
+ import { error } from '@instructure/console';
34
+ import { contrast as getContrast, colorToRGB, colorToHex8 } from '@instructure/ui-color-utils';
36
35
  import { withStyle, jsx } from '@instructure/emotion';
37
36
  import { Text } from '@instructure/ui-text';
37
+ import { Pill } from '@instructure/ui-pill';
38
38
  import ColorIndicator from '../ColorIndicator';
39
39
  import { propTypes, allowedProps } from './props';
40
40
  import generateStyle from './styles';
41
41
  import generateComponentTheme from './theme';
42
- import { contrast as getContrast, colorToRGB, colorToHex8 } from '@instructure/ui-color-utils';
43
- import { Pill } from '@instructure/ui-pill';
44
-
45
42
  /**
46
43
  ---
47
44
  category: components
48
45
  ---
49
46
  @tsProps
50
47
  **/
48
+
51
49
  let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class ColorContrast extends Component {
52
50
  constructor(props) {
53
51
  super(props);
@@ -115,6 +113,32 @@ let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _d
115
113
  (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
116
114
  }
117
115
 
116
+ renderPreview() {
117
+ const _this$props4 = this.props,
118
+ styles = _this$props4.styles,
119
+ withoutColorPreview = _this$props4.withoutColorPreview,
120
+ firstColor = _this$props4.firstColor,
121
+ secondColor = _this$props4.secondColor,
122
+ firstColorLabel = _this$props4.firstColorLabel,
123
+ secondColorLabel = _this$props4.secondColorLabel;
124
+
125
+ if (withoutColorPreview) {
126
+ return null;
127
+ }
128
+
129
+ if (!firstColorLabel || !secondColorLabel) {
130
+ error(false, 'When `withoutColorPreview` is not set to true, the properties `firstColorLabel` and `secondColorLabel` are required!');
131
+ }
132
+
133
+ return !withoutColorPreview && jsx("div", {
134
+ css: styles === null || styles === void 0 ? void 0 : styles.colorPreview
135
+ }, jsx("div", {
136
+ css: styles === null || styles === void 0 ? void 0 : styles.firstColorPreview
137
+ }, this.renderColorIndicator(firstColor, firstColorLabel || '')), jsx("div", {
138
+ css: styles === null || styles === void 0 ? void 0 : styles.secondColorPreview
139
+ }, this.renderColorIndicator(secondColor, secondColorLabel || '')));
140
+ }
141
+
118
142
  //We project the firstColor onto an opaque white background, then we project the secondColor onto
119
143
  //the projected first color. We calculate the contrast of these two, projected colors.
120
144
  get calcContrast() {
@@ -131,44 +155,28 @@ let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _d
131
155
  }
132
156
 
133
157
  render() {
134
- var _this$props$styles4, _this$props$styles5, _this$props$styles6, _this$props$styles7;
135
-
136
- const _this$props4 = this.props,
137
- styles = _this$props4.styles,
138
- elementRef = _this$props4.elementRef,
139
- failureLabel = _this$props4.failureLabel,
140
- successLabel = _this$props4.successLabel,
141
- withoutColorPreview = _this$props4.withoutColorPreview,
142
- firstColor = _this$props4.firstColor,
143
- secondColor = _this$props4.secondColor,
144
- label = _this$props4.label,
145
- firstColorLabel = _this$props4.firstColorLabel,
146
- secondColorLabel = _this$props4.secondColorLabel,
147
- normalTextLabel = _this$props4.normalTextLabel,
148
- largeTextLabel = _this$props4.largeTextLabel,
149
- graphicsTextLabel = _this$props4.graphicsTextLabel,
150
- props = _objectWithoutProperties(_this$props4, _excluded);
151
-
158
+ const _this$props5 = this.props,
159
+ styles = _this$props5.styles,
160
+ label = _this$props5.label,
161
+ normalTextLabel = _this$props5.normalTextLabel,
162
+ largeTextLabel = _this$props5.largeTextLabel,
163
+ graphicsTextLabel = _this$props5.graphicsTextLabel;
152
164
  const contrast = this.calcContrast;
153
- return jsx("div", Object.assign({}, passthroughProps(props), {
165
+ return jsx("div", Object.assign({}, omitProps(this.props, ColorContrast.allowedProps), {
154
166
  ref: this.handleRef,
155
167
  css: styles === null || styles === void 0 ? void 0 : styles.colorContrast
156
168
  }), jsx("div", {
157
- css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.label
169
+ css: styles === null || styles === void 0 ? void 0 : styles.label
158
170
  }, jsx(Text, {
159
171
  weight: "bold",
160
172
  as: "div"
161
173
  }, label)), jsx(Text, {
162
174
  size: "x-large"
163
- }, contrast, ":1"), !withoutColorPreview && jsx("div", {
164
- css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.colorPreview
165
- }, jsx("div", {
166
- css: (_this$props$styles6 = this.props.styles) === null || _this$props$styles6 === void 0 ? void 0 : _this$props$styles6.firstColorPreview
167
- }, this.renderColorIndicator(firstColor, firstColorLabel || '')), jsx("div", {
168
- css: (_this$props$styles7 = this.props.styles) === null || _this$props$styles7 === void 0 ? void 0 : _this$props$styles7.secondColorPreview
169
- }, this.renderColorIndicator(secondColor, secondColorLabel || ''))), this.renderStatus(contrast >= 4.5, normalTextLabel), this.renderStatus(contrast >= 3, largeTextLabel), this.renderStatus(contrast >= 3, graphicsTextLabel));
175
+ }, contrast, ":1"), this.renderPreview(), this.renderStatus(contrast >= 4.5, normalTextLabel), this.renderStatus(contrast >= 3, largeTextLabel), this.renderStatus(contrast >= 3, graphicsTextLabel));
170
176
  }
171
177
 
172
- }, _class2.displayName = "ColorContrast", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorContrast', _class2)) || _class) || _class);
178
+ }, _class2.displayName = "ColorContrast", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorContrast', _class2.defaultProps = {
179
+ withoutColorPreview: false
180
+ }, _class2)) || _class) || _class);
173
181
  export { ColorContrast };
174
182
  export default ColorContrast;
@@ -1,6 +1,3 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
- const _excluded = ["color", "elementRef"];
3
-
4
1
  var _dec, _dec2, _class, _class2;
5
2
 
6
3
  /*
@@ -30,7 +27,7 @@ var _dec, _dec2, _class, _class2;
30
27
  /** @jsx jsx */
31
28
  import { Component } from 'react';
32
29
  import { testable } from '@instructure/ui-testable';
33
- import { passthroughProps } from '@instructure/ui-react-utils';
30
+ import { omitProps } from '@instructure/ui-react-utils';
34
31
  import { withStyle, jsx } from '@instructure/emotion';
35
32
  import generateStyle from './styles';
36
33
  import generateComponentTheme from './theme';
@@ -70,21 +67,14 @@ let ColorIndicator = (_dec = withStyle(generateStyle, generateComponentTheme), _
70
67
  }
71
68
 
72
69
  render() {
73
- var _this$props$styles;
74
-
75
- const _this$props3 = this.props,
76
- color = _this$props3.color,
77
- elementRef = _this$props3.elementRef,
78
- props = _objectWithoutProperties(_this$props3, _excluded);
79
-
80
- return jsx("div", Object.assign({}, passthroughProps(props), {
70
+ const styles = this.props.styles;
71
+ return jsx("div", Object.assign({}, omitProps(this.props, ColorIndicator.allowedProps), {
81
72
  ref: this.handleRef,
82
- css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.colorIndicator
73
+ css: styles === null || styles === void 0 ? void 0 : styles.colorIndicator
83
74
  }));
84
75
  }
85
76
 
86
77
  }, _class2.displayName = "ColorIndicator", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorIndicator', _class2.defaultProps = {
87
- color: '',
88
78
  shape: 'circle'
89
79
  }, _class2)) || _class) || _class);
90
80
  export default ColorIndicator;
@@ -28,17 +28,17 @@ var _dec, _class, _class2;
28
28
  import React, { Component } from 'react';
29
29
  import { withStyle, jsx } from '@instructure/emotion';
30
30
  import { addEventListener } from '@instructure/ui-dom-utils';
31
- import shallowCompare from '../utils/shallowCompare';
32
31
  import { View } from '@instructure/ui-view';
32
+ import shallowCompare from '../utils/shallowCompare';
33
33
  import { propTypes, allowedProps } from './props';
34
34
  import generateStyle from './styles';
35
35
  import generateComponentTheme from './theme';
36
36
  /**
37
- * ---
38
- * private: true
39
- * ---
40
- * @tsProps
41
- **/
37
+ ---
38
+ private: true
39
+ ---
40
+ @tsProps
41
+ **/
42
42
 
43
43
  let ColorPalette = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_class2 = class ColorPalette extends Component {
44
44
  constructor(props) {
@@ -34,11 +34,11 @@ import { propTypes, allowedProps } from './props';
34
34
  import generateStyle from './styles';
35
35
  import generateComponentTheme from './theme';
36
36
  /**
37
- * ---
38
- * private: true
39
- * ---
40
- * @tsProps
41
- **/
37
+ ---
38
+ private: true
39
+ ---
40
+ @tsProps
41
+ **/
42
42
 
43
43
  let RGBAInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_class2 = class RGBAInput extends Component {
44
44
  constructor(props) {
@@ -33,11 +33,11 @@ import { propTypes, allowedProps } from './props';
33
33
  import generateStyle from './styles';
34
34
  import generateComponentTheme from './theme';
35
35
  /**
36
- * ---
37
- * private: true
38
- * ---
39
- * @tsProps
40
- **/
36
+ ---
37
+ private: true
38
+ ---
39
+ @tsProps
40
+ **/
41
41
 
42
42
  let Slider = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_class2 = class Slider extends Component {
43
43
  constructor() {
@@ -1,6 +1,3 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
- const _excluded = ["disabled", "onChange", "value", "elementRef", "styles", "withAlpha", "rgbRedInputScreenReaderLabel", "rgbGreenInputScreenReaderLabel", "rgbBlueInputScreenReaderLabel", "rgbAlphaInputScreenReaderLabel", "colorSliderNavigationExplanationScreenReaderLabel", "alphaSliderNavigationExplanationScreenReaderLabel", "colorPaletteNavigationExplanationScreenReaderLabel"];
3
-
4
1
  var _dec, _dec2, _class, _class2;
5
2
 
6
3
  /*
@@ -30,7 +27,7 @@ var _dec, _dec2, _class, _class2;
30
27
  /** @jsx jsx */
31
28
  import { Component } from 'react';
32
29
  import { withStyle, jsx } from '@instructure/emotion';
33
- import { passthroughProps } from '@instructure/ui-react-utils';
30
+ import { omitProps } from '@instructure/ui-react-utils';
34
31
  import { testable } from '@instructure/ui-testable';
35
32
  import { colorToHex8, colorToHsva, colorToRGB } from '@instructure/ui-color-utils';
36
33
  import ColorPalette from './ColorPalette';
@@ -76,11 +73,8 @@ let ColorMixer = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _de
76
73
  var _this$props$makeStyle, _this$props;
77
74
 
78
75
  (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
79
-
80
- if (this.props.value) {
81
- this.setState({ ...colorToHsva(this.props.value)
82
- });
83
- }
76
+ this.setState({ ...colorToHsva(this.props.value)
77
+ });
84
78
  }
85
79
 
86
80
  componentDidUpdate(prevProps, prevState) {
@@ -116,9 +110,6 @@ let ColorMixer = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _de
116
110
  render() {
117
111
  const _this$props3 = this.props,
118
112
  disabled = _this$props3.disabled,
119
- onChange = _this$props3.onChange,
120
- value = _this$props3.value,
121
- elementRef = _this$props3.elementRef,
122
113
  styles = _this$props3.styles,
123
114
  withAlpha = _this$props3.withAlpha,
124
115
  rgbRedInputScreenReaderLabel = _this$props3.rgbRedInputScreenReaderLabel,
@@ -127,15 +118,13 @@ let ColorMixer = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _de
127
118
  rgbAlphaInputScreenReaderLabel = _this$props3.rgbAlphaInputScreenReaderLabel,
128
119
  colorSliderNavigationExplanationScreenReaderLabel = _this$props3.colorSliderNavigationExplanationScreenReaderLabel,
129
120
  alphaSliderNavigationExplanationScreenReaderLabel = _this$props3.alphaSliderNavigationExplanationScreenReaderLabel,
130
- colorPaletteNavigationExplanationScreenReaderLabel = _this$props3.colorPaletteNavigationExplanationScreenReaderLabel,
131
- props = _objectWithoutProperties(_this$props3, _excluded);
132
-
121
+ colorPaletteNavigationExplanationScreenReaderLabel = _this$props3.colorPaletteNavigationExplanationScreenReaderLabel;
133
122
  const _this$state2 = this.state,
134
123
  h = _this$state2.h,
135
124
  s = _this$state2.s,
136
125
  v = _this$state2.v,
137
126
  a = _this$state2.a;
138
- return jsx("div", Object.assign({}, passthroughProps(props), {
127
+ return jsx("div", Object.assign({}, omitProps(this.props, ColorMixer.allowedProps), {
139
128
  "aria-disabled": disabled,
140
129
  ref: this.handleRef,
141
130
  css: styles === null || styles === void 0 ? void 0 : styles.colorMixer
@@ -225,6 +214,7 @@ let ColorMixer = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _de
225
214
  }
226
215
 
227
216
  }, _class2.displayName = "ColorMixer", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorMixer', _class2.defaultProps = {
217
+ value: '#000',
228
218
  withAlpha: false,
229
219
  disabled: false
230
220
  }, _class2)) || _class) || _class);
@@ -25,9 +25,9 @@ import PropTypes from 'prop-types';
25
25
  const propTypes = {
26
26
  disabled: PropTypes.bool,
27
27
  elementRef: PropTypes.func,
28
- value: PropTypes.string,
29
- onChange: PropTypes.func,
30
28
  withAlpha: PropTypes.bool,
29
+ value: PropTypes.string,
30
+ onChange: PropTypes.func.isRequired,
31
31
  rgbRedInputScreenReaderLabel: PropTypes.string.isRequired,
32
32
  rgbGreenInputScreenReaderLabel: PropTypes.string.isRequired,
33
33
  rgbBlueInputScreenReaderLabel: PropTypes.string.isRequired,
@@ -1,6 +1,3 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
- const _excluded = ["checkContrast", "colorMixerSettings", "disabled", "elementRef", "isRequired", "label", "onChange", "placeholderText", "popoverButtonScreenReaderLabel", "renderInvalidColorMessage", "renderIsRequiredMessage", "renderMessages", "tooltip", "value", "width", "withAlpha"];
3
-
4
1
  var _dec, _dec2, _class, _class2, _IconTroubleLine, _IconWarningLine, _IconCheckDarkLine, _IconInfoLine;
5
2
 
6
3
  /*
@@ -32,8 +29,8 @@ var _dec, _dec2, _class, _class2, _IconTroubleLine, _IconWarningLine, _IconCheck
32
29
  /** @jsxFrag React.Fragment */
33
30
  import React, { Component } from 'react';
34
31
  import { withStyle, jsx } from '@instructure/emotion';
35
- import { warn } from '@instructure/console';
36
- import { passthroughProps } from '@instructure/ui-react-utils';
32
+ import { warn, error } from '@instructure/console';
33
+ import { omitProps } from '@instructure/ui-react-utils';
37
34
  import { testable } from '@instructure/ui-testable';
38
35
  import { colorToHex8, isValid, contrast as getContrast } from '@instructure/ui-color-utils';
39
36
  import { TextInput } from '@instructure/ui-text-input';
@@ -72,11 +69,13 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
72
69
 
73
70
  this.checkSettings = () => {
74
71
  if (this.props.children && this.props.colorMixerSettings) {
75
- warn(false, 'You should either use children, colorMixerSettings or neither, not both. In this case, the colorMixerSettings will be ignored', '');
72
+ warn(false, 'You should either use children, colorMixerSettings or neither, not both. In this case, the colorMixerSettings will be ignored.', '');
76
73
  }
77
- };
78
74
 
79
- this.stripAlphaIfNeeded = hex => hex.length === 8 && hex.slice(-2) === 'FF' ? hex.slice(0, -2) : hex;
75
+ if (this.props.value && typeof this.props.onChange !== 'function') {
76
+ error(false, 'You provided a `value` prop on ColorPicker, which will render a controlled component. Please provide an `onChange` handler.');
77
+ }
78
+ };
80
79
 
81
80
  this.renderPopover = () => {
82
81
  var _this$props$styles;
@@ -101,7 +100,7 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
101
100
  });
102
101
  },
103
102
  on: "click",
104
- screenReaderLabel: this.props.popoverScreenReaderLabel || '',
103
+ screenReaderLabel: this.props.popoverScreenReaderLabel,
105
104
  shouldContainFocus: true,
106
105
  shouldReturnFocus: true,
107
106
  shouldCloseOnDocumentClick: true,
@@ -112,34 +111,34 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
112
111
  };
113
112
 
114
113
  this.renderCustomPopoverContent = () => {
115
- var _this$props$styles2, _this$props, _this$props2;
116
-
114
+ const _this$props = this.props,
115
+ styles = _this$props.styles,
116
+ children = _this$props.children,
117
+ onChange = _this$props.onChange;
117
118
  return jsx("div", {
118
- css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.popoverContent
119
- }, typeof ((_this$props = this.props) === null || _this$props === void 0 ? void 0 : _this$props.children) === 'function' && ((_this$props2 = this.props) === null || _this$props2 === void 0 ? void 0 : _this$props2.children(this.stripAlphaIfNeeded(this.state.mixedColor), color => {
119
+ css: styles === null || styles === void 0 ? void 0 : styles.popoverContent
120
+ }, typeof children === 'function' && children(`#${this.mixedColorWithStrippedAlpha}`, newColor => {
120
121
  this.setState({
121
- mixedColor: color
122
+ mixedColor: colorToHex8(newColor).slice(1)
122
123
  });
123
124
  }, () => {
124
- var _this$props3, _this$props3$onChange;
125
-
126
125
  this.setState({
127
126
  openColorPicker: false,
128
- hexCode: `${this.stripAlphaIfNeeded(this.state.mixedColor)}`
127
+ hexCode: this.mixedColorWithStrippedAlpha
129
128
  });
130
- (_this$props3 = this.props) === null || _this$props3 === void 0 ? void 0 : (_this$props3$onChange = _this$props3.onChange) === null || _this$props3$onChange === void 0 ? void 0 : _this$props3$onChange.call(_this$props3, `#${this.stripAlphaIfNeeded(this.state.mixedColor.slice(1))}`);
129
+ onChange === null || onChange === void 0 ? void 0 : onChange(`#${this.mixedColorWithStrippedAlpha}`);
131
130
  }, () => this.setState({
132
131
  openColorPicker: false,
133
132
  mixedColor: this.state.hexCode
134
- }))));
133
+ })));
135
134
  };
136
135
 
137
136
  this.renderDefaultPopoverContent = () => {
138
- var _this$props$styles3, _this$props4, _this$props4$colorMix, _this$props5, _this$props5$colorMix, _this$props$styles4, _this$props6, _this$props6$colorMix, _this$props$styles5, _this$props$styles6, _this$props$colorMixe, _this$props$colorMixe2;
137
+ var _this$props$styles2, _this$props2, _this$props2$colorMix, _this$props3, _this$props3$colorMix, _this$props$styles3, _this$props4, _this$props4$colorMix, _this$props$styles4, _this$props$styles5, _this$props$colorMixe, _this$props$colorMixe2;
139
138
 
140
139
  return jsx(React.Fragment, null, jsx("div", {
141
- css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.popoverContent
142
- }, ((_this$props4 = this.props) === null || _this$props4 === void 0 ? void 0 : (_this$props4$colorMix = _this$props4.colorMixerSettings) === null || _this$props4$colorMix === void 0 ? void 0 : _this$props4$colorMix.colorMixer) && jsx(ColorMixer, {
140
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.popoverContent
141
+ }, ((_this$props2 = this.props) === null || _this$props2 === void 0 ? void 0 : (_this$props2$colorMix = _this$props2.colorMixerSettings) === null || _this$props2$colorMix === void 0 ? void 0 : _this$props2$colorMix.colorMixer) && jsx(ColorMixer, {
143
142
  value: `#${this.state.mixedColor}`,
144
143
  onChange: newColor => this.setState({
145
144
  mixedColor: colorToHex8(newColor).slice(1)
@@ -152,20 +151,20 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
152
151
  colorSliderNavigationExplanationScreenReaderLabel: this.props.colorMixerSettings.colorMixer.colorSliderNavigationExplanationScreenReaderLabel,
153
152
  alphaSliderNavigationExplanationScreenReaderLabel: this.props.colorMixerSettings.colorMixer.alphaSliderNavigationExplanationScreenReaderLabel,
154
153
  colorPaletteNavigationExplanationScreenReaderLabel: this.props.colorMixerSettings.colorMixer.colorPaletteNavigationExplanationScreenReaderLabel
155
- }), ((_this$props5 = this.props) === null || _this$props5 === void 0 ? void 0 : (_this$props5$colorMix = _this$props5.colorMixerSettings) === null || _this$props5$colorMix === void 0 ? void 0 : _this$props5$colorMix.colorPreset) && jsx("div", {
156
- css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.popoverContentBlock
154
+ }), ((_this$props3 = this.props) === null || _this$props3 === void 0 ? void 0 : (_this$props3$colorMix = _this$props3.colorMixerSettings) === null || _this$props3$colorMix === void 0 ? void 0 : _this$props3$colorMix.colorPreset) && jsx("div", {
155
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.popoverContentBlock
157
156
  }, jsx(ColorPreset, {
158
157
  label: this.props.colorMixerSettings.colorPreset.label,
159
158
  colors: this.props.colorMixerSettings.colorPreset.colors,
160
- selected: this.state.mixedColor,
159
+ selected: this.mixedColorWithStrippedAlpha ? `#${this.mixedColorWithStrippedAlpha}` : void 0,
161
160
  onSelect: color => this.setState({
162
161
  mixedColor: color.slice(1)
163
162
  })
164
- })), ((_this$props6 = this.props) === null || _this$props6 === void 0 ? void 0 : (_this$props6$colorMix = _this$props6.colorMixerSettings) === null || _this$props6$colorMix === void 0 ? void 0 : _this$props6$colorMix.colorContrast) && jsx("div", {
165
- css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.popoverContentBlock
163
+ })), ((_this$props4 = this.props) === null || _this$props4 === void 0 ? void 0 : (_this$props4$colorMix = _this$props4.colorMixerSettings) === null || _this$props4$colorMix === void 0 ? void 0 : _this$props4$colorMix.colorContrast) && jsx("div", {
164
+ css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.popoverContentBlock
166
165
  }, jsx(ColorContrast, {
167
166
  firstColor: this.props.colorMixerSettings.colorContrast.firstColor,
168
- secondColor: `#${this.stripAlphaIfNeeded(this.state.mixedColor)}`,
167
+ secondColor: `#${this.mixedColorWithStrippedAlpha}`,
169
168
  label: this.props.colorMixerSettings.colorContrast.label,
170
169
  successLabel: this.props.colorMixerSettings.colorContrast.successLabel,
171
170
  failureLabel: this.props.colorMixerSettings.colorContrast.failureLabel,
@@ -175,7 +174,7 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
175
174
  firstColorLabel: this.props.colorMixerSettings.colorContrast.firstColorLabel,
176
175
  secondColorLabel: this.props.colorMixerSettings.colorContrast.secondColorLabel
177
176
  }))), jsx("div", {
178
- css: (_this$props$styles6 = this.props.styles) === null || _this$props$styles6 === void 0 ? void 0 : _this$props$styles6.popoverFooter
177
+ css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.popoverFooter
179
178
  }, jsx(Button, {
180
179
  onClick: () => this.setState({
181
180
  openColorPicker: false,
@@ -186,14 +185,14 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
186
185
  }, (_this$props$colorMixe = this.props.colorMixerSettings) === null || _this$props$colorMixe === void 0 ? void 0 : _this$props$colorMixe.popoverCloseButtonLabel), jsx(Button, {
187
186
  onClick: () => {
188
187
  if (typeof this.props.onChange === 'function') {
189
- this.props.onChange(`#${this.stripAlphaIfNeeded(this.state.mixedColor)}`);
188
+ this.props.onChange(`#${this.mixedColorWithStrippedAlpha}`);
190
189
  this.setState({
191
190
  openColorPicker: false
192
191
  });
193
192
  } else {
194
193
  this.setState({
195
194
  openColorPicker: false,
196
- hexCode: `${this.stripAlphaIfNeeded(this.state.mixedColor)}`
195
+ hexCode: `${this.mixedColorWithStrippedAlpha}`
197
196
  });
198
197
  }
199
198
  },
@@ -211,9 +210,9 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
211
210
  }
212
211
 
213
212
  componentDidMount() {
214
- var _this$props$makeStyle, _this$props7, _this$props$value;
213
+ var _this$props$makeStyle, _this$props5, _this$props$value;
215
214
 
216
- (_this$props$makeStyle = (_this$props7 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props7, { ...this.state,
215
+ (_this$props$makeStyle = (_this$props5 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props5, { ...this.state,
217
216
  isSimple: this.isSimple
218
217
  });
219
218
  this.checkSettings();
@@ -223,9 +222,9 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
223
222
  }
224
223
 
225
224
  componentDidUpdate(prevProps) {
226
- var _this$props$makeStyle2, _this$props8;
225
+ var _this$props$makeStyle2, _this$props6;
227
226
 
228
- (_this$props$makeStyle2 = (_this$props8 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props8, { ...this.state,
227
+ (_this$props$makeStyle2 = (_this$props6 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props6, { ...this.state,
229
228
  isSimple: this.isSimple
230
229
  });
231
230
 
@@ -265,6 +264,11 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
265
264
  return this.renderMode === 'customPopover';
266
265
  }
267
266
 
267
+ get mixedColorWithStrippedAlpha() {
268
+ const mixedColor = this.state.mixedColor;
269
+ return mixedColor.length === 8 && mixedColor.slice(-2) === 'FF' ? mixedColor.slice(0, -2) : mixedColor;
270
+ }
271
+
268
272
  getMinContrast(strength) {
269
273
  return {
270
274
  min: 3,
@@ -280,12 +284,12 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
280
284
  hexCode = _this$state.hexCode,
281
285
  showHelperErrorMessages = _this$state.showHelperErrorMessages;
282
286
  const isValidHex = isValid(hexCode);
283
- const _this$props9 = this.props,
284
- checkContrast = _this$props9.checkContrast,
285
- renderMessages = _this$props9.renderMessages,
286
- renderInvalidColorMessage = _this$props9.renderInvalidColorMessage,
287
- renderIsRequiredMessage = _this$props9.renderIsRequiredMessage,
288
- isRequired = _this$props9.isRequired;
287
+ const _this$props7 = this.props,
288
+ checkContrast = _this$props7.checkContrast,
289
+ renderMessages = _this$props7.renderMessages,
290
+ renderInvalidColorMessage = _this$props7.renderInvalidColorMessage,
291
+ renderIsRequiredMessage = _this$props7.renderIsRequiredMessage,
292
+ isRequired = _this$props7.isRequired;
289
293
  const contrast = isValidHex ? getContrast(((_this$props$checkCont = this.props.checkContrast) === null || _this$props$checkCont === void 0 ? void 0 : _this$props$checkCont.contrastAgainst) || '#fff', hexCode, 2) : void 0;
290
294
  const contrastStrength = checkContrast !== null && checkContrast !== void 0 && checkContrast.contrastStrength ? checkContrast.contrastStrength : 'mid';
291
295
  const minContrast = this.getMinContrast(contrastStrength);
@@ -338,9 +342,9 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
338
342
  }
339
343
 
340
344
  renderAfterInput() {
341
- const _this$props10 = this.props,
342
- checkContrast = _this$props10.checkContrast,
343
- styles = _this$props10.styles;
345
+ const _this$props8 = this.props,
346
+ checkContrast = _this$props8.checkContrast,
347
+ styles = _this$props8.styles;
344
348
  const hexCode = this.state.hexCode;
345
349
 
346
350
  if (checkContrast && isValid(hexCode)) {
@@ -413,10 +417,10 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
413
417
  }
414
418
 
415
419
  renderLabel() {
416
- const _this$props11 = this.props,
417
- label = _this$props11.label,
418
- tooltip = _this$props11.tooltip,
419
- styles = _this$props11.styles;
420
+ const _this$props9 = this.props,
421
+ label = _this$props9.label,
422
+ tooltip = _this$props9.tooltip,
423
+ styles = _this$props9.styles;
420
424
  return tooltip ? jsx("div", null, jsx("span", {
421
425
  css: styles === null || styles === void 0 ? void 0 : styles.label
422
426
  }, label), jsx("span", null, jsx(Tooltip, {
@@ -427,29 +431,15 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
427
431
  }
428
432
 
429
433
  render() {
430
- var _this$props$styles7, _this$props$styles8, _this$props$styles9;
431
-
432
- const _this$props12 = this.props,
433
- checkContrast = _this$props12.checkContrast,
434
- colorMixerSettings = _this$props12.colorMixerSettings,
435
- disabled = _this$props12.disabled,
436
- elementRef = _this$props12.elementRef,
437
- isRequired = _this$props12.isRequired,
438
- label = _this$props12.label,
439
- onChange = _this$props12.onChange,
440
- placeholderText = _this$props12.placeholderText,
441
- popoverButtonScreenReaderLabel = _this$props12.popoverButtonScreenReaderLabel,
442
- renderInvalidColorMessage = _this$props12.renderInvalidColorMessage,
443
- renderIsRequiredMessage = _this$props12.renderIsRequiredMessage,
444
- renderMessages = _this$props12.renderMessages,
445
- tooltip = _this$props12.tooltip,
446
- value = _this$props12.value,
447
- width = _this$props12.width,
448
- withAlpha = _this$props12.withAlpha,
449
- props = _objectWithoutProperties(_this$props12, _excluded);
450
-
451
- return jsx("div", Object.assign({}, passthroughProps(props), {
452
- css: (_this$props$styles7 = this.props.styles) === null || _this$props$styles7 === void 0 ? void 0 : _this$props$styles7.colorPicker,
434
+ var _this$props$styles6, _this$props$styles7, _this$props$styles8;
435
+
436
+ const _this$props10 = this.props,
437
+ disabled = _this$props10.disabled,
438
+ isRequired = _this$props10.isRequired,
439
+ placeholderText = _this$props10.placeholderText,
440
+ width = _this$props10.width;
441
+ return jsx("div", Object.assign({}, omitProps(this.props, ColorPicker.allowedProps), {
442
+ css: (_this$props$styles6 = this.props.styles) === null || _this$props$styles6 === void 0 ? void 0 : _this$props$styles6.colorPicker,
453
443
  ref: this.handleRef
454
444
  }), jsx(TextInput, {
455
445
  isRequired: isRequired,
@@ -469,19 +459,17 @@ let ColorPicker = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
469
459
  onBlur: () => this.handleOnBlur(),
470
460
  messages: this.renderMessages()
471
461
  }), !this.isSimple && jsx("div", {
472
- css: (_this$props$styles8 = this.props.styles) === null || _this$props$styles8 === void 0 ? void 0 : _this$props$styles8.colorMixerButtonContainer
462
+ css: (_this$props$styles7 = this.props.styles) === null || _this$props$styles7 === void 0 ? void 0 : _this$props$styles7.colorMixerButtonContainer
473
463
  }, jsx("div", {
474
- css: (_this$props$styles9 = this.props.styles) === null || _this$props$styles9 === void 0 ? void 0 : _this$props$styles9.colorMixerButtonWrapper
464
+ css: (_this$props$styles8 = this.props.styles) === null || _this$props$styles8 === void 0 ? void 0 : _this$props$styles8.colorMixerButtonWrapper
475
465
  }, this.renderPopover())));
476
466
  }
477
467
 
478
468
  }, _class2.displayName = "ColorPicker", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorPicker', _class2.defaultProps = {
479
- elementRef: () => null,
480
469
  disabled: false,
481
- label: 'Color',
482
- checkContrast: false,
470
+ withAlpha: false,
483
471
  width: '22.5rem',
484
- withAlpha: false
472
+ popoverMaxHeight: '100vh'
485
473
  }, _class2)) || _class) || _class);
486
474
  export { ColorPicker };
487
475
  export default ColorPicker;