@instructure/ui-color-picker 8.25.1-snapshot-20

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 (201) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +46 -0
  3. package/es/ColorContrast/ColorContrastLocator.js +54 -0
  4. package/es/ColorContrast/index.js +174 -0
  5. package/es/ColorContrast/props.js +40 -0
  6. package/es/ColorContrast/styles.js +99 -0
  7. package/es/ColorContrast/theme.js +55 -0
  8. package/es/ColorIndicator/ColorIndicatorLocator.js +40 -0
  9. package/es/ColorIndicator/index.js +91 -0
  10. package/es/ColorIndicator/props.js +31 -0
  11. package/es/ColorIndicator/styles.js +70 -0
  12. package/es/ColorIndicator/theme.js +53 -0
  13. package/es/ColorMixer/ColorMixerLocator.js +27 -0
  14. package/es/ColorMixer/ColorPalette/index.js +258 -0
  15. package/es/ColorMixer/ColorPalette/props.js +37 -0
  16. package/es/ColorMixer/ColorPalette/styles.js +81 -0
  17. package/es/ColorMixer/ColorPalette/theme.js +48 -0
  18. package/es/ColorMixer/RGBAInput/index.js +148 -0
  19. package/es/ColorMixer/RGBAInput/props.js +39 -0
  20. package/es/ColorMixer/RGBAInput/styles.js +63 -0
  21. package/es/ColorMixer/RGBAInput/theme.js +43 -0
  22. package/es/ColorMixer/Slider/index.js +218 -0
  23. package/es/ColorMixer/Slider/props.js +38 -0
  24. package/es/ColorMixer/Slider/styles.js +95 -0
  25. package/es/ColorMixer/Slider/theme.js +53 -0
  26. package/es/ColorMixer/index.js +232 -0
  27. package/es/ColorMixer/props.js +40 -0
  28. package/es/ColorMixer/styles.js +49 -0
  29. package/es/ColorMixer/utils/shallowCompare.js +32 -0
  30. package/es/ColorPicker/ColorPickerLocator.js +137 -0
  31. package/es/ColorPicker/index.js +487 -0
  32. package/es/ColorPicker/props.js +47 -0
  33. package/es/ColorPicker/styles.js +119 -0
  34. package/es/ColorPicker/theme.js +76 -0
  35. package/es/ColorPreset/ColorPresetLocator.js +27 -0
  36. package/es/ColorPreset/index.js +268 -0
  37. package/es/ColorPreset/props.js +36 -0
  38. package/es/ColorPreset/styles.js +102 -0
  39. package/es/ColorPreset/theme.js +53 -0
  40. package/es/index.js +28 -0
  41. package/lib/ColorContrast/ColorContrastLocator.js +66 -0
  42. package/lib/ColorContrast/index.js +169 -0
  43. package/lib/ColorContrast/props.js +51 -0
  44. package/lib/ColorContrast/styles.js +107 -0
  45. package/lib/ColorContrast/theme.js +63 -0
  46. package/lib/ColorIndicator/ColorIndicatorLocator.js +51 -0
  47. package/lib/ColorIndicator/index.js +82 -0
  48. package/lib/ColorIndicator/props.js +42 -0
  49. package/lib/ColorIndicator/styles.js +78 -0
  50. package/lib/ColorIndicator/theme.js +63 -0
  51. package/lib/ColorMixer/ColorMixerLocator.js +37 -0
  52. package/lib/ColorMixer/ColorPalette/index.js +252 -0
  53. package/lib/ColorMixer/ColorPalette/props.js +48 -0
  54. package/lib/ColorMixer/ColorPalette/styles.js +90 -0
  55. package/lib/ColorMixer/ColorPalette/theme.js +57 -0
  56. package/lib/ColorMixer/RGBAInput/index.js +142 -0
  57. package/lib/ColorMixer/RGBAInput/props.js +50 -0
  58. package/lib/ColorMixer/RGBAInput/styles.js +71 -0
  59. package/lib/ColorMixer/RGBAInput/theme.js +51 -0
  60. package/lib/ColorMixer/Slider/index.js +211 -0
  61. package/lib/ColorMixer/Slider/props.js +49 -0
  62. package/lib/ColorMixer/Slider/styles.js +103 -0
  63. package/lib/ColorMixer/Slider/theme.js +62 -0
  64. package/lib/ColorMixer/index.js +226 -0
  65. package/lib/ColorMixer/props.js +51 -0
  66. package/lib/ColorMixer/styles.js +57 -0
  67. package/lib/ColorMixer/utils/shallowCompare.js +40 -0
  68. package/lib/ColorPicker/ColorPickerLocator.js +151 -0
  69. package/lib/ColorPicker/index.js +500 -0
  70. package/lib/ColorPicker/props.js +58 -0
  71. package/lib/ColorPicker/styles.js +127 -0
  72. package/lib/ColorPicker/theme.js +85 -0
  73. package/lib/ColorPreset/ColorPresetLocator.js +37 -0
  74. package/lib/ColorPreset/index.js +274 -0
  75. package/lib/ColorPreset/props.js +47 -0
  76. package/lib/ColorPreset/styles.js +110 -0
  77. package/lib/ColorPreset/theme.js +61 -0
  78. package/lib/index.js +45 -0
  79. package/lib/package.json +1 -0
  80. package/package.json +62 -0
  81. package/src/ColorContrast/ColorContrastLocator.ts +51 -0
  82. package/src/ColorContrast/README.md +111 -0
  83. package/src/ColorContrast/index.tsx +189 -0
  84. package/src/ColorContrast/props.ts +140 -0
  85. package/src/ColorContrast/styles.ts +102 -0
  86. package/src/ColorContrast/theme.ts +62 -0
  87. package/src/ColorIndicator/ColorIndicatorLocator.ts +41 -0
  88. package/src/ColorIndicator/README.md +76 -0
  89. package/src/ColorIndicator/index.tsx +89 -0
  90. package/src/ColorIndicator/props.ts +68 -0
  91. package/src/ColorIndicator/styles.ts +88 -0
  92. package/src/ColorIndicator/theme.ts +58 -0
  93. package/src/ColorMixer/ColorMixerLocator.ts +29 -0
  94. package/src/ColorMixer/ColorPalette/index.tsx +250 -0
  95. package/src/ColorMixer/ColorPalette/props.ts +87 -0
  96. package/src/ColorMixer/ColorPalette/styles.ts +94 -0
  97. package/src/ColorMixer/ColorPalette/theme.ts +52 -0
  98. package/src/ColorMixer/README.md +98 -0
  99. package/src/ColorMixer/RGBAInput/index.tsx +172 -0
  100. package/src/ColorMixer/RGBAInput/props.ts +93 -0
  101. package/src/ColorMixer/RGBAInput/styles.ts +69 -0
  102. package/src/ColorMixer/RGBAInput/theme.ts +48 -0
  103. package/src/ColorMixer/Slider/index.tsx +242 -0
  104. package/src/ColorMixer/Slider/props.ts +94 -0
  105. package/src/ColorMixer/Slider/styles.ts +114 -0
  106. package/src/ColorMixer/Slider/theme.ts +59 -0
  107. package/src/ColorMixer/index.tsx +221 -0
  108. package/src/ColorMixer/props.ts +169 -0
  109. package/src/ColorMixer/styles.ts +51 -0
  110. package/src/ColorMixer/utils/shallowCompare.ts +35 -0
  111. package/src/ColorPicker/ColorPickerLocator.ts +124 -0
  112. package/src/ColorPicker/README.md +420 -0
  113. package/src/ColorPicker/index.tsx +609 -0
  114. package/src/ColorPicker/props.ts +293 -0
  115. package/src/ColorPicker/styles.ts +131 -0
  116. package/src/ColorPicker/theme.ts +80 -0
  117. package/src/ColorPreset/ColorPresetLocator.ts +29 -0
  118. package/src/ColorPreset/README.md +121 -0
  119. package/src/ColorPreset/index.tsx +328 -0
  120. package/src/ColorPreset/props.ts +162 -0
  121. package/src/ColorPreset/styles.ts +107 -0
  122. package/src/ColorPreset/theme.ts +58 -0
  123. package/src/index.ts +34 -0
  124. package/tsconfig.build.json +36 -0
  125. package/tsconfig.build.tsbuildinfo +1 -0
  126. package/types/ColorContrast/ColorContrastLocator.d.ts +592 -0
  127. package/types/ColorContrast/ColorContrastLocator.d.ts.map +1 -0
  128. package/types/ColorContrast/index.d.ts +61 -0
  129. package/types/ColorContrast/index.d.ts.map +1 -0
  130. package/types/ColorContrast/props.d.ts +62 -0
  131. package/types/ColorContrast/props.d.ts.map +1 -0
  132. package/types/ColorContrast/styles.d.ts +76 -0
  133. package/types/ColorContrast/styles.d.ts.map +1 -0
  134. package/types/ColorContrast/theme.d.ts +10 -0
  135. package/types/ColorContrast/theme.d.ts.map +1 -0
  136. package/types/ColorIndicator/ColorIndicatorLocator.d.ts +577 -0
  137. package/types/ColorIndicator/ColorIndicatorLocator.d.ts.map +1 -0
  138. package/types/ColorIndicator/index.d.ts +35 -0
  139. package/types/ColorIndicator/index.d.ts.map +1 -0
  140. package/types/ColorIndicator/props.d.ts +25 -0
  141. package/types/ColorIndicator/props.d.ts.map +1 -0
  142. package/types/ColorIndicator/styles.d.ts +15 -0
  143. package/types/ColorIndicator/styles.d.ts.map +1 -0
  144. package/types/ColorIndicator/theme.d.ts +11 -0
  145. package/types/ColorIndicator/theme.d.ts.map +1 -0
  146. package/types/ColorMixer/ColorMixerLocator.d.ts +566 -0
  147. package/types/ColorMixer/ColorMixerLocator.d.ts.map +1 -0
  148. package/types/ColorMixer/ColorPalette/index.d.ts +70 -0
  149. package/types/ColorMixer/ColorPalette/index.d.ts.map +1 -0
  150. package/types/ColorMixer/ColorPalette/props.d.ts +29 -0
  151. package/types/ColorMixer/ColorPalette/props.d.ts.map +1 -0
  152. package/types/ColorMixer/ColorPalette/styles.d.ts +15 -0
  153. package/types/ColorMixer/ColorPalette/styles.d.ts.map +1 -0
  154. package/types/ColorMixer/ColorPalette/theme.d.ts +10 -0
  155. package/types/ColorMixer/ColorPalette/theme.d.ts.map +1 -0
  156. package/types/ColorMixer/RGBAInput/index.d.ts +51 -0
  157. package/types/ColorMixer/RGBAInput/index.d.ts.map +1 -0
  158. package/types/ColorMixer/RGBAInput/props.d.ts +28 -0
  159. package/types/ColorMixer/RGBAInput/props.d.ts.map +1 -0
  160. package/types/ColorMixer/RGBAInput/styles.d.ts +15 -0
  161. package/types/ColorMixer/RGBAInput/styles.d.ts.map +1 -0
  162. package/types/ColorMixer/RGBAInput/theme.d.ts +10 -0
  163. package/types/ColorMixer/RGBAInput/theme.d.ts.map +1 -0
  164. package/types/ColorMixer/Slider/index.d.ts +64 -0
  165. package/types/ColorMixer/Slider/index.d.ts.map +1 -0
  166. package/types/ColorMixer/Slider/props.d.ts +26 -0
  167. package/types/ColorMixer/Slider/props.d.ts.map +1 -0
  168. package/types/ColorMixer/Slider/styles.d.ts +15 -0
  169. package/types/ColorMixer/Slider/styles.d.ts.map +1 -0
  170. package/types/ColorMixer/Slider/theme.d.ts +10 -0
  171. package/types/ColorMixer/Slider/theme.d.ts.map +1 -0
  172. package/types/ColorMixer/index.d.ts +59 -0
  173. package/types/ColorMixer/index.d.ts.map +1 -0
  174. package/types/ColorMixer/props.d.ts +91 -0
  175. package/types/ColorMixer/props.d.ts.map +1 -0
  176. package/types/ColorMixer/styles.d.ts +14 -0
  177. package/types/ColorMixer/styles.d.ts.map +1 -0
  178. package/types/ColorMixer/utils/shallowCompare.d.ts +3 -0
  179. package/types/ColorMixer/utils/shallowCompare.d.ts.map +1 -0
  180. package/types/ColorPicker/ColorPickerLocator.d.ts +4113 -0
  181. package/types/ColorPicker/ColorPickerLocator.d.ts.map +1 -0
  182. package/types/ColorPicker/index.d.ts +158 -0
  183. package/types/ColorPicker/index.d.ts.map +1 -0
  184. package/types/ColorPicker/props.d.ts +166 -0
  185. package/types/ColorPicker/props.d.ts.map +1 -0
  186. package/types/ColorPicker/styles.d.ts +17 -0
  187. package/types/ColorPicker/styles.d.ts.map +1 -0
  188. package/types/ColorPicker/theme.d.ts +10 -0
  189. package/types/ColorPicker/theme.d.ts.map +1 -0
  190. package/types/ColorPreset/ColorPresetLocator.d.ts +566 -0
  191. package/types/ColorPreset/ColorPresetLocator.d.ts.map +1 -0
  192. package/types/ColorPreset/index.d.ts +100 -0
  193. package/types/ColorPreset/index.d.ts.map +1 -0
  194. package/types/ColorPreset/props.d.ts +87 -0
  195. package/types/ColorPreset/props.d.ts.map +1 -0
  196. package/types/ColorPreset/styles.d.ts +77 -0
  197. package/types/ColorPreset/styles.d.ts.map +1 -0
  198. package/types/ColorPreset/theme.d.ts +10 -0
  199. package/types/ColorPreset/theme.d.ts.map +1 -0
  200. package/types/index.d.ts +11 -0
  201. package/types/index.d.ts.map +1 -0
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.colorIndicatorBorderColor = void 0;
7
+
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+ const colorIndicatorBorderColor = '#384A5899';
32
+ /**
33
+ * Generates the theme object for the component from the theme and provided additional information
34
+ * @param {Object} theme The actual theme object.
35
+ * @return {Object} The final theme object with the overrides and component variables
36
+ */
37
+
38
+ exports.colorIndicatorBorderColor = colorIndicatorBorderColor;
39
+
40
+ const generateComponentTheme = theme => {
41
+ const colors = theme.colors,
42
+ borders = theme.borders,
43
+ spacing = theme.spacing;
44
+ const componentVariables = {
45
+ borderWidth: borders === null || borders === void 0 ? void 0 : borders.widthSmall,
46
+ backgroundImage: `linear-gradient(45deg, ${colors.tiara} 25%, transparent 25%),
47
+ linear-gradient(-45deg, ${colors.tiara} 25%, transparent 25%),
48
+ linear-gradient(45deg, transparent 75%, ${colors.tiara} 75%),
49
+ linear-gradient(-45deg, transparent 75%, ${colors.tiara} 75%)`,
50
+ backgroundSize: '.5rem .5rem',
51
+ backgroundPosition: '0 0, 0 .25rem, .25rem -0.25rem, -0.25rem 0px',
52
+ circleIndicatorSize: '1.5rem',
53
+ rectangleIndicatorSize: '2.375rem',
54
+ colorIndicatorBorderColor,
55
+ rectangularIndicatorBorderRadius: spacing === null || spacing === void 0 ? void 0 : spacing.xxSmall,
56
+ rectangularIndicatorBorderWidth: borders === null || borders === void 0 ? void 0 : borders.widthSmall
57
+ };
58
+ return { ...componentVariables
59
+ };
60
+ };
61
+
62
+ var _default = generateComponentTheme;
63
+ exports.default = _default;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ColorMixerLocator = void 0;
7
+
8
+ var _locator = require("@instructure/ui-test-locator/lib/utils/locator.js");
9
+
10
+ var _index = require("./index");
11
+
12
+ /*
13
+ * The MIT License (MIT)
14
+ *
15
+ * Copyright (c) 2015 - present Instructure, Inc.
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ * of this software and associated documentation files (the "Software"), to deal
19
+ * in the Software without restriction, including without limitation the rights
20
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ * copies of the Software, and to permit persons to whom the Software is
22
+ * furnished to do so, subject to the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be included in all
25
+ * copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ * SOFTWARE.
34
+ */
35
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
36
+ const ColorMixerLocator = (0, _locator.locator)(_index.ColorMixer.selector);
37
+ exports.ColorMixerLocator = ColorMixerLocator;
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = void 0;
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ var _emotion = require("@instructure/emotion");
15
+
16
+ var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
17
+
18
+ var _shallowCompare = _interopRequireDefault(require("../utils/shallowCompare"));
19
+
20
+ var _View = require("@instructure/ui-view/lib/View");
21
+
22
+ var _props = require("./props");
23
+
24
+ var _styles = _interopRequireDefault(require("./styles"));
25
+
26
+ var _theme = _interopRequireDefault(require("./theme"));
27
+
28
+ var _dec, _class, _class2;
29
+
30
+ /**
31
+ * ---
32
+ * private: true
33
+ * ---
34
+ * @tsProps
35
+ **/
36
+ let ColorPalette = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_class2 = class ColorPalette extends _react.Component {
37
+ constructor(props) {
38
+ super(props);
39
+ this.ref = null;
40
+ this._paletteRef = null;
41
+ this._mouseMoveListener = void 0;
42
+ this._mouseUpListener = void 0;
43
+
44
+ this.handleRef = el => {
45
+ const elementRef = this.props.elementRef;
46
+ this.ref = el;
47
+
48
+ if (typeof elementRef === 'function') {
49
+ elementRef(el);
50
+ }
51
+ };
52
+
53
+ this.calcSaturation = position => Math.round(position / this.paletteWidth * 100) / 100;
54
+
55
+ this.calcLuminance = position => Math.round((this.paletteHeight - position) / this.paletteHeight * 100) / 100;
56
+
57
+ this.handleMouseUp = () => {
58
+ this.removeEventListeners();
59
+ };
60
+
61
+ this.handleChange = e => {
62
+ if (this.props.disabled) return;
63
+ const clientX = e.clientX,
64
+ clientY = e.clientY;
65
+
66
+ const _this$calcColorPositi = this.calcColorPosition(clientX, clientY),
67
+ newXPosition = _this$calcColorPositi.newXPosition,
68
+ newYPosition = _this$calcColorPositi.newYPosition;
69
+
70
+ this.setState({
71
+ colorPosition: {
72
+ x: newXPosition,
73
+ y: newYPosition
74
+ }
75
+ });
76
+ this.props.onChange({
77
+ h: this.props.hue,
78
+ s: this.calcSaturation(newXPosition),
79
+ v: this.calcLuminance(newYPosition)
80
+ });
81
+ };
82
+
83
+ this.state = {
84
+ colorPosition: {
85
+ x: 0,
86
+ y: 0
87
+ }
88
+ };
89
+ }
90
+
91
+ componentDidMount() {
92
+ var _this$props$makeStyle, _this$props;
93
+
94
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.state);
95
+ this.setState({
96
+ colorPosition: this.calcPositionFromColor(this.props.color)
97
+ });
98
+ }
99
+
100
+ componentDidUpdate(prevProps) {
101
+ var _this$props$makeStyle2, _this$props2;
102
+
103
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.state);
104
+
105
+ if ((0, _shallowCompare.default)(prevProps.color, this.props.color)) {
106
+ this.setState({
107
+ colorPosition: this.calcPositionFromColor(this.props.color)
108
+ });
109
+ }
110
+ }
111
+
112
+ componentWillUnmount() {
113
+ this.removeEventListeners();
114
+ }
115
+
116
+ get paletteWidth() {
117
+ return this._paletteRef.getBoundingClientRect().width;
118
+ }
119
+
120
+ get paletteHeight() {
121
+ return this._paletteRef.getBoundingClientRect().height;
122
+ }
123
+
124
+ calcPositionFromColor(hsv) {
125
+ const s = hsv.s,
126
+ v = hsv.v;
127
+ return {
128
+ x: s * this.paletteWidth,
129
+ y: this.paletteHeight - v * this.paletteHeight
130
+ };
131
+ }
132
+
133
+ handlePaletteMouseDown(e) {
134
+ this.handleChange(e);
135
+ this._mouseMoveListener = (0, _addEventListener.addEventListener)(window, 'mousemove', this.handleChange);
136
+ this._mouseUpListener = (0, _addEventListener.addEventListener)(window, 'mouseup', this.handleMouseUp);
137
+ }
138
+
139
+ removeEventListeners() {
140
+ var _this$_mouseMoveListe, _this$_mouseUpListene;
141
+
142
+ (_this$_mouseMoveListe = this._mouseMoveListener) === null || _this$_mouseMoveListe === void 0 ? void 0 : _this$_mouseMoveListe.remove();
143
+ (_this$_mouseUpListene = this._mouseUpListener) === null || _this$_mouseUpListene === void 0 ? void 0 : _this$_mouseUpListene.remove();
144
+ }
145
+
146
+ calcColorPosition(clientX, clientY) {
147
+ const _getBoundingClientRec = this._paletteRef.getBoundingClientRect(),
148
+ x = _getBoundingClientRec.x,
149
+ y = _getBoundingClientRec.y;
150
+
151
+ return this.applyBoundaries(clientX - x, clientY - y);
152
+ }
153
+
154
+ applyBoundaries(x, y) {
155
+ let newXPosition = x;
156
+ let newYPosition = y;
157
+
158
+ if (x > this.paletteWidth) {
159
+ newXPosition = this.paletteWidth;
160
+ }
161
+
162
+ if (x < 0) {
163
+ newXPosition = 0;
164
+ }
165
+
166
+ if (y > this.paletteHeight) {
167
+ newYPosition = this.paletteHeight;
168
+ }
169
+
170
+ if (y < 0) {
171
+ newYPosition = 0;
172
+ }
173
+
174
+ return {
175
+ newXPosition,
176
+ newYPosition
177
+ };
178
+ }
179
+
180
+ handleKeyDown(e) {
181
+ if (this.props.disabled) return;
182
+ const key = e.key;
183
+ if (key === 'Tab') return;
184
+ e.preventDefault();
185
+ let deltaX = 0;
186
+ let deltaY = 0;
187
+
188
+ if (key === 'ArrowLeft' || key === 'a') {
189
+ deltaX = -2;
190
+ }
191
+
192
+ if (key === 'ArrowRight' || key === 'd') {
193
+ deltaX = 2;
194
+ }
195
+
196
+ if (key === 'ArrowUp' || key === 'w') {
197
+ deltaY = -2;
198
+ }
199
+
200
+ if (key === 'ArrowDown' || key === 's') {
201
+ deltaY = 2;
202
+ }
203
+
204
+ const _this$applyBoundaries = this.applyBoundaries(this.state.colorPosition.x + deltaX, this.state.colorPosition.y + deltaY),
205
+ newXPosition = _this$applyBoundaries.newXPosition,
206
+ newYPosition = _this$applyBoundaries.newYPosition;
207
+
208
+ this.setState({
209
+ colorPosition: {
210
+ x: newXPosition,
211
+ y: newYPosition
212
+ }
213
+ });
214
+ this.props.onChange({
215
+ h: this.props.hue,
216
+ s: this.calcSaturation(newXPosition),
217
+ v: this.calcLuminance(newYPosition)
218
+ });
219
+ }
220
+
221
+ render() {
222
+ var _this$props$styles, _this$props$styles2, _this$props$styles3;
223
+
224
+ return (0, _emotion.jsx)(_View.View, {
225
+ elementRef: this.handleRef,
226
+ disabled: this.props.disabled,
227
+ position: "relative",
228
+ background: "transparent",
229
+ display: "inline-block",
230
+ borderRadius: "medium",
231
+ borderWidth: "0",
232
+ padding: "0",
233
+ as: "div",
234
+ tabIndex: this.props.disabled ? void 0 : 0,
235
+ onKeyDown: e => this.handleKeyDown(e),
236
+ onMouseDown: e => this.handlePaletteMouseDown(e),
237
+ "aria-label": this.props.navigationExplanationScreenReaderLabel
238
+ }, (0, _emotion.jsx)("div", {
239
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.indicator
240
+ }), this.props.disabled && (0, _emotion.jsx)("div", {
241
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.disabledOverlay
242
+ }), (0, _emotion.jsx)("div", {
243
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.palette,
244
+ ref: ref => {
245
+ this._paletteRef = ref;
246
+ }
247
+ }));
248
+ }
249
+
250
+ }, _class2.displayName = "ColorPalette", _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.componentId = 'ColorMixer.Palette', _class2)) || _class);
251
+ var _default = ColorPalette;
252
+ exports.default = _default;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.propTypes = exports.allowedProps = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ /*
13
+ * The MIT License (MIT)
14
+ *
15
+ * Copyright (c) 2015 - present Instructure, Inc.
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ * of this software and associated documentation files (the "Software"), to deal
19
+ * in the Software without restriction, including without limitation the rights
20
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ * copies of the Software, and to permit persons to whom the Software is
22
+ * furnished to do so, subject to the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be included in all
25
+ * copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ * SOFTWARE.
34
+ */
35
+ const propTypes = {
36
+ disabled: _propTypes.default.bool,
37
+ hue: _propTypes.default.number.isRequired,
38
+ color: _propTypes.default.object.isRequired,
39
+ width: _propTypes.default.number.isRequired,
40
+ height: _propTypes.default.number.isRequired,
41
+ indicatorRadius: _propTypes.default.number.isRequired,
42
+ onChange: _propTypes.default.func.isRequired,
43
+ elementRef: _propTypes.default.func,
44
+ navigationExplanationScreenReaderLabel: _propTypes.default.string.isRequired
45
+ };
46
+ exports.propTypes = propTypes;
47
+ const allowedProps = ['disabled', 'hue', 'color', 'width', 'height', 'indicatorRadius', 'onChange', 'elementRef', 'navigationExplanationScreenReaderLabel'];
48
+ exports.allowedProps = allowedProps;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _px = require("@instructure/ui-utils/lib/px.js");
9
+
10
+ /*
11
+ * The MIT License (MIT)
12
+ *
13
+ * Copyright (c) 2015 - present Instructure, Inc.
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ */
33
+
34
+ /**
35
+ * ---
36
+ * private: true
37
+ * ---
38
+ * Generates the style object from the theme and provided additional information
39
+ * @param {Object} componentTheme The theme variable object.
40
+ * @param {Object} props the props of the component, the style is applied to
41
+ * @param {Object} state the state of the component, the style is applied to
42
+ * @return {Object} The final style object, which will be used in the component
43
+ */
44
+ const generateStyle = (componentTheme, props, state) => {
45
+ var _state$colorPosition, _state$colorPosition2;
46
+
47
+ return {
48
+ ColorPalette: {
49
+ label: 'ColorPalette'
50
+ },
51
+ indicator: {
52
+ label: 'ColorPalette__indicator',
53
+ width: `${props.indicatorRadius / 8}rem`,
54
+ height: `${props.indicatorRadius / 8}rem`,
55
+ borderRadius: `${props.indicatorRadius / 8}rem`,
56
+ background: componentTheme.whiteColor,
57
+ position: 'absolute',
58
+ borderStyle: 'solid',
59
+ borderWidth: componentTheme.indicatorBorderWidth,
60
+ borderColor: componentTheme.indicatorBorderColor,
61
+ top: `${(state === null || state === void 0 ? void 0 : (_state$colorPosition = state.colorPosition) === null || _state$colorPosition === void 0 ? void 0 : _state$colorPosition.y) - (0, _px.px)(`${props.indicatorRadius / 16}rem`)}px`,
62
+ left: `${(state === null || state === void 0 ? void 0 : (_state$colorPosition2 = state.colorPosition) === null || _state$colorPosition2 === void 0 ? void 0 : _state$colorPosition2.x) - (0, _px.px)(`${props.indicatorRadius / 16}rem`)}px`
63
+ },
64
+ palette: {
65
+ label: 'ColorPalette__palette',
66
+ width: `${props.width / 16}rem`,
67
+ height: `${props.height / 16}rem`,
68
+ borderRadius: componentTheme.paletteBorderRadius,
69
+ borderStyle: 'solid',
70
+ borderWidth: componentTheme.paletteBorderWidth,
71
+ boxSizing: 'border-box',
72
+ borderColor: componentTheme.colorIndicatorBorderColor,
73
+ background: `linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,1)),
74
+ linear-gradient(to right, white, hsl(${props.hue},100%,50%))`
75
+ },
76
+ disabledOverlay: {
77
+ label: 'ColorPalette__disabledOverlay',
78
+ background: 'rgba(255,255,255,.5)',
79
+ zIndex: componentTheme.disabledOverlayZIndex,
80
+ width: `${props.width / 16 + 1}rem`,
81
+ height: `${props.height / 16 + 1}rem`,
82
+ position: 'absolute',
83
+ top: '-.5rem',
84
+ left: '-.5rem'
85
+ }
86
+ };
87
+ };
88
+
89
+ var _default = generateStyle;
90
+ exports.default = _default;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _theme = require("../../ColorIndicator/theme");
9
+
10
+ /*
11
+ * The MIT License (MIT)
12
+ *
13
+ * Copyright (c) 2015 - present Instructure, Inc.
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ */
33
+
34
+ /**
35
+ * Generates the theme object for the component from the theme and provided additional information
36
+ * @param {Object} theme The actual theme object.
37
+ * @return {Object} The final theme object with the overrides and component variables
38
+ */
39
+ const generateComponentTheme = theme => {
40
+ const colors = theme.colors,
41
+ borders = theme.borders,
42
+ stacking = theme.stacking;
43
+ const componentVariables = {
44
+ indicatorBorderColor: colors.licorice,
45
+ whiteColor: colors.white,
46
+ colorIndicatorBorderColor: _theme.colorIndicatorBorderColor,
47
+ indicatorBorderWidth: borders.widthSmall,
48
+ paletteBorderRadius: borders.radiusMedium,
49
+ paletteBorderWidth: borders.widthSmall,
50
+ disabledOverlayZIndex: stacking.topmost
51
+ };
52
+ return { ...componentVariables
53
+ };
54
+ };
55
+
56
+ var _default = generateComponentTheme;
57
+ exports.default = _default;
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = void 0;
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ var _emotion = require("@instructure/emotion");
15
+
16
+ var _shallowCompare = _interopRequireDefault(require("../utils/shallowCompare"));
17
+
18
+ var _ScreenReaderContent = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
19
+
20
+ var _TextInput = require("@instructure/ui-text-input/lib/TextInput");
21
+
22
+ var _props = require("./props");
23
+
24
+ var _styles = _interopRequireDefault(require("./styles"));
25
+
26
+ var _theme = _interopRequireDefault(require("./theme"));
27
+
28
+ var _dec, _class, _class2, _span;
29
+
30
+ /**
31
+ * ---
32
+ * private: true
33
+ * ---
34
+ * @tsProps
35
+ **/
36
+ let RGBAInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_class2 = class RGBAInput extends _react.Component {
37
+ constructor(props) {
38
+ super(props);
39
+ this.ref = null;
40
+
41
+ this.handleRef = el => {
42
+ const elementRef = this.props.elementRef;
43
+ this.ref = el;
44
+
45
+ if (typeof elementRef === 'function') {
46
+ elementRef(el);
47
+ }
48
+ };
49
+
50
+ this.state = {
51
+ value: props.value
52
+ };
53
+ }
54
+
55
+ componentDidMount() {
56
+ var _this$props$makeStyle, _this$props;
57
+
58
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
59
+ }
60
+
61
+ componentDidUpdate(prevProps) {
62
+ var _this$props$makeStyle2, _this$props2;
63
+
64
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
65
+
66
+ if ((0, _shallowCompare.default)(prevProps.value, this.props.value) || (0, _shallowCompare.default)(this.state.value, this.props.value)) {
67
+ this.setState({
68
+ value: this.props.value
69
+ });
70
+ }
71
+ }
72
+
73
+ handleChange(type, e) {
74
+ const upperLimit = type === 'a' ? 100 : 255;
75
+ const newValue = type === 'a' ? Number(e.target.value) / 100 : Number(e.target.value);
76
+ const newColor = { ...this.props.value,
77
+ [type]: newValue
78
+ };
79
+
80
+ if (!isNaN(Number(newValue)) && newValue >= 0 && newValue <= upperLimit) {
81
+ this.setState({
82
+ value: newColor
83
+ });
84
+ this.props.onChange(newColor);
85
+ return;
86
+ }
87
+ }
88
+
89
+ render() {
90
+ const _this$props3 = this.props,
91
+ styles = _this$props3.styles,
92
+ disabled = _this$props3.disabled,
93
+ label = _this$props3.label,
94
+ withAlpha = _this$props3.withAlpha;
95
+ return (0, _emotion.jsx)("div", {
96
+ ref: this.handleRef,
97
+ css: styles === null || styles === void 0 ? void 0 : styles.RGBAInput
98
+ }, label && (0, _emotion.jsx)("div", {
99
+ css: styles === null || styles === void 0 ? void 0 : styles.label
100
+ }, label), (0, _emotion.jsx)("div", {
101
+ css: styles === null || styles === void 0 ? void 0 : styles.inputContainer
102
+ }, (0, _emotion.jsx)("span", {
103
+ css: styles === null || styles === void 0 ? void 0 : styles.rgbInput
104
+ }, (0, _emotion.jsx)(_TextInput.TextInput, {
105
+ disabled: disabled,
106
+ value: `${this.state.value.r}`,
107
+ onChange: e => this.handleChange('r', e),
108
+ renderLabel: (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, this.props.rgbRedInputScreenReaderLabel)
109
+ })), (0, _emotion.jsx)("span", {
110
+ css: styles === null || styles === void 0 ? void 0 : styles.rgbInput
111
+ }, (0, _emotion.jsx)(_TextInput.TextInput, {
112
+ disabled: disabled,
113
+ value: `${this.state.value.g}`,
114
+ onChange: e => this.handleChange('g', e),
115
+ renderLabel: (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, this.props.rgbGreenInputScreenReaderLabel)
116
+ })), (0, _emotion.jsx)("span", {
117
+ css: styles === null || styles === void 0 ? void 0 : styles.rgbInput
118
+ }, (0, _emotion.jsx)(_TextInput.TextInput, {
119
+ disabled: disabled,
120
+ value: `${this.state.value.b}`,
121
+ onChange: e => this.handleChange('b', e),
122
+ renderLabel: (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, this.props.rgbBlueInputScreenReaderLabel)
123
+ })), withAlpha && (0, _emotion.jsx)("span", {
124
+ css: styles === null || styles === void 0 ? void 0 : styles.aInput
125
+ }, (0, _emotion.jsx)(_TextInput.TextInput, {
126
+ "aria-label": "%",
127
+ disabled: disabled,
128
+ value: `${Math.round(this.state.value.a * 100)}`,
129
+ onChange: e => this.handleChange('a', e),
130
+ renderAfterInput: _span || (_span = (0, _emotion.jsx)("span", {
131
+ "aria-hidden": "true",
132
+ role: "presentation"
133
+ }, "%")),
134
+ renderLabel: (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, this.props.rgbAlphaInputScreenReaderLabel)
135
+ }))));
136
+ }
137
+
138
+ }, _class2.displayName = "RGBAInput", _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.componentId = 'ColorMixer.RGBAInput', _class2.defaultProps = {
139
+ withAlpha: false
140
+ }, _class2)) || _class);
141
+ var _default = RGBAInput;
142
+ exports.default = _default;