@zendeskgarden/react-colorpickers 8.75.1 → 8.76.0
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.
- package/dist/esm/elements/ColorSwatch/index.js +102 -0
- package/dist/esm/elements/ColorSwatchDialog/index.js +198 -0
- package/dist/esm/elements/Colorpicker/ColorWell.js +109 -0
- package/dist/esm/elements/Colorpicker/index.js +236 -0
- package/dist/esm/elements/Colorpicker/reducer.js +275 -0
- package/dist/esm/elements/ColorpickerDialog/index.js +156 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/12/check-sm-fill.svg.js +29 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg.js +25 -0
- package/dist/esm/styled/ColorSwatch/StyledCell.js +22 -0
- package/dist/esm/styled/ColorSwatch/StyledColorSwatch.js +23 -0
- package/dist/esm/styled/ColorSwatch/StyledIcon.js +48 -0
- package/dist/esm/styled/ColorSwatch/StyledSwatchButton.js +27 -0
- package/dist/esm/styled/Colorpicker/StyledAlphaRange.js +37 -0
- package/dist/esm/styled/Colorpicker/StyledColorPicker.js +25 -0
- package/dist/esm/styled/Colorpicker/StyledColorWell.js +36 -0
- package/dist/esm/styled/Colorpicker/StyledColorWellThumb.js +40 -0
- package/dist/esm/styled/Colorpicker/StyledHexField.js +24 -0
- package/dist/esm/styled/Colorpicker/StyledHueRange.js +23 -0
- package/dist/esm/styled/Colorpicker/StyledInput.js +24 -0
- package/dist/esm/styled/Colorpicker/StyledInputGroup.js +22 -0
- package/dist/esm/styled/Colorpicker/StyledLabel.js +23 -0
- package/dist/esm/styled/Colorpicker/StyledPreview.js +37 -0
- package/dist/esm/styled/Colorpicker/StyledRGBAField.js +32 -0
- package/dist/esm/styled/Colorpicker/StyledSliderGroup.js +22 -0
- package/dist/esm/styled/Colorpicker/StyledSliders.js +23 -0
- package/dist/esm/styled/ColorpickerDialog/StyledButton.js +24 -0
- package/dist/esm/styled/ColorpickerDialog/StyledButtonPreview.js +48 -0
- package/dist/esm/styled/ColorpickerDialog/StyledTooltipBody.js +23 -0
- package/dist/esm/styled/ColorpickerDialog/StyledTooltipModal.js +23 -0
- package/dist/esm/styled/common/StyledRange.js +151 -0
- package/dist/esm/styled/common/checkeredBackground.js +28 -0
- package/dist/esm/utils/conversion.js +34 -0
- package/dist/esm/utils/saturation.js +64 -0
- package/dist/esm/utils/validation.js +12 -0
- package/dist/index.cjs.js +33 -49
- package/package.json +9 -9
- package/dist/index.esm.js +0 -1583
package/dist/index.esm.js
DELETED
|
@@ -1,1583 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright Zendesk, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
-
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import * as React from 'react';
|
|
9
|
-
import React__default, { Children, useContext, useRef, useState, useEffect, useMemo, useCallback, forwardRef, useReducer, cloneElement } from 'react';
|
|
10
|
-
import PropTypes from 'prop-types';
|
|
11
|
-
import { Range, Field, Label, Input } from '@zendeskgarden/react-forms';
|
|
12
|
-
import throttle from 'lodash.throttle';
|
|
13
|
-
import styled, { ThemeContext } from 'styled-components';
|
|
14
|
-
import { retrieveComponentStyles, DEFAULT_THEME, getColorV8, focusStyles, useText } from '@zendeskgarden/react-theming';
|
|
15
|
-
import { stripUnit, math, rgba, hsl, parseToRgb, readableColor, parseToHsl, rgb } from 'polished';
|
|
16
|
-
import { Button } from '@zendeskgarden/react-buttons';
|
|
17
|
-
import { TooltipModal, PLACEMENT } from '@zendeskgarden/react-modals';
|
|
18
|
-
import isEqual from 'lodash.isequal';
|
|
19
|
-
import { composeEventHandlers, useId } from '@zendeskgarden/container-utilities';
|
|
20
|
-
import { Tooltip } from '@zendeskgarden/react-tooltips';
|
|
21
|
-
import { useGrid } from '@zendeskgarden/container-grid';
|
|
22
|
-
|
|
23
|
-
function _extends$2() {
|
|
24
|
-
_extends$2 = Object.assign ? Object.assign.bind() : function (target) {
|
|
25
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
26
|
-
var source = arguments[i];
|
|
27
|
-
for (var key in source) {
|
|
28
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
29
|
-
target[key] = source[key];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return target;
|
|
34
|
-
};
|
|
35
|
-
return _extends$2.apply(this, arguments);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function hslToHsv(h, s, l) {
|
|
39
|
-
let saturation = s;
|
|
40
|
-
saturation *= (l < 50 ? l : 100 - l) / 100;
|
|
41
|
-
const v = l + saturation;
|
|
42
|
-
return {
|
|
43
|
-
h,
|
|
44
|
-
s: v === 0 ? 0 : 2 * saturation / v * 100,
|
|
45
|
-
v
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function hsvToHsl(h, s, v) {
|
|
49
|
-
let saturation = s;
|
|
50
|
-
let value = v;
|
|
51
|
-
saturation /= 100;
|
|
52
|
-
value /= 100;
|
|
53
|
-
let l = (2 - saturation) * value;
|
|
54
|
-
let sl = saturation * value;
|
|
55
|
-
sl /= l <= 1 ? l : 2 - l;
|
|
56
|
-
sl = sl || 0;
|
|
57
|
-
l /= 2;
|
|
58
|
-
return {
|
|
59
|
-
h,
|
|
60
|
-
s: sl * 100,
|
|
61
|
-
l: l * 100
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const getSaturationLightness = (element, x, y, rtl) => {
|
|
66
|
-
const {
|
|
67
|
-
width,
|
|
68
|
-
height
|
|
69
|
-
} = element.getBoundingClientRect();
|
|
70
|
-
let left = x - (element.getBoundingClientRect().left + window.pageXOffset);
|
|
71
|
-
let top = y - (element.getBoundingClientRect().top + window.pageYOffset);
|
|
72
|
-
if (left < 0) {
|
|
73
|
-
left = 0;
|
|
74
|
-
} else if (left > width) {
|
|
75
|
-
left = width;
|
|
76
|
-
}
|
|
77
|
-
if (top < 0) {
|
|
78
|
-
top = 0;
|
|
79
|
-
} else if (top > height) {
|
|
80
|
-
top = height;
|
|
81
|
-
}
|
|
82
|
-
if (rtl) {
|
|
83
|
-
left = width - left;
|
|
84
|
-
}
|
|
85
|
-
const saturation = left / width;
|
|
86
|
-
const bright = 1 - top / height;
|
|
87
|
-
return {
|
|
88
|
-
saturation,
|
|
89
|
-
bright
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
function getNextHsv(e, hue, container, rtl) {
|
|
93
|
-
const {
|
|
94
|
-
saturation,
|
|
95
|
-
bright
|
|
96
|
-
} = getSaturationLightness(container, e.pageX, e.pageY, rtl);
|
|
97
|
-
return {
|
|
98
|
-
h: hue,
|
|
99
|
-
s: saturation,
|
|
100
|
-
v: bright
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
const getThumbPosition = (x, y, rtl, container) => {
|
|
104
|
-
if (container.current) {
|
|
105
|
-
const {
|
|
106
|
-
saturation,
|
|
107
|
-
bright
|
|
108
|
-
} = getSaturationLightness(container.current, x, y, rtl);
|
|
109
|
-
const topFromMouse = (1 - bright) * 100;
|
|
110
|
-
const leftFromMouse = rtl ? 100 - saturation * 100 : saturation * 100;
|
|
111
|
-
return {
|
|
112
|
-
topFromMouse,
|
|
113
|
-
leftFromMouse
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
topFromMouse: 0,
|
|
118
|
-
leftFromMouse: 0
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const COMPONENT_ID$l = 'colorpickers.colorpicker';
|
|
123
|
-
const getColorV8PickerWidth = props => {
|
|
124
|
-
return props.isOpaque ? 268 : 312;
|
|
125
|
-
};
|
|
126
|
-
const StyledColorPicker = styled.div.attrs({
|
|
127
|
-
'data-garden-id': COMPONENT_ID$l,
|
|
128
|
-
'data-garden-version': '8.75.1'
|
|
129
|
-
}).withConfig({
|
|
130
|
-
displayName: "StyledColorPicker",
|
|
131
|
-
componentId: "sc-1donyl9-0"
|
|
132
|
-
})(["width:", "px;min-width:", "px;", ";"], getColorV8PickerWidth, getColorV8PickerWidth, props => retrieveComponentStyles(COMPONENT_ID$l, props));
|
|
133
|
-
StyledColorPicker.defaultProps = {
|
|
134
|
-
theme: DEFAULT_THEME
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const COMPONENT_ID$k = 'colorpickers.colorpicker_range';
|
|
138
|
-
const thumbStyles = function (styles) {
|
|
139
|
-
let modifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
140
|
-
return `
|
|
141
|
-
&${modifier}::-moz-range-thumb {
|
|
142
|
-
${styles}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
&${modifier}::-ms-thumb {
|
|
146
|
-
${styles}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
&${modifier}::-webkit-slider-thumb {
|
|
150
|
-
${styles}
|
|
151
|
-
}
|
|
152
|
-
`;
|
|
153
|
-
};
|
|
154
|
-
const trackStyles = function (styles) {
|
|
155
|
-
let modifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
156
|
-
return `
|
|
157
|
-
&${modifier}::-moz-range-track {
|
|
158
|
-
${styles}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
&${modifier}::-ms-track {
|
|
162
|
-
${styles}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
&${modifier}::-webkit-slider-runnable-track {
|
|
166
|
-
${styles}
|
|
167
|
-
}
|
|
168
|
-
`;
|
|
169
|
-
};
|
|
170
|
-
const trackLowerStyles = function (styles) {
|
|
171
|
-
let modifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
172
|
-
return `
|
|
173
|
-
&${modifier}::-moz-range-progress {
|
|
174
|
-
${styles}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
&${modifier}::-ms-fill-lower {
|
|
178
|
-
${styles}
|
|
179
|
-
}
|
|
180
|
-
`;
|
|
181
|
-
};
|
|
182
|
-
const colorStyles$1 = props => {
|
|
183
|
-
const thumbBackgroundColor = getColorV8('neutralHue', 100, props.theme);
|
|
184
|
-
const thumbBorderColor = thumbBackgroundColor;
|
|
185
|
-
const thumbActiveBackgroundColor = getColorV8('neutralHue', 200, props.theme);
|
|
186
|
-
const thumbActiveBorderColor = getColorV8('primaryHue', 600, props.theme);
|
|
187
|
-
const thumbFocusBorderColor = getColorV8('primaryHue', 400, props.theme);
|
|
188
|
-
const thumbHoverBackgroundColor = thumbActiveBackgroundColor;
|
|
189
|
-
const thumbHoverBorderColor = thumbHoverBackgroundColor;
|
|
190
|
-
return `
|
|
191
|
-
border-color: ${props.isOpaque && getColorV8('background', 600 , props.theme)};
|
|
192
|
-
|
|
193
|
-
${trackStyles(`
|
|
194
|
-
background-color: transparent;
|
|
195
|
-
`)}
|
|
196
|
-
|
|
197
|
-
${thumbStyles(`
|
|
198
|
-
border-color: ${thumbBorderColor};
|
|
199
|
-
background-color: ${thumbBackgroundColor};
|
|
200
|
-
`)}
|
|
201
|
-
|
|
202
|
-
${trackLowerStyles(`
|
|
203
|
-
background-color: transparent;
|
|
204
|
-
`)}
|
|
205
|
-
|
|
206
|
-
${thumbStyles(`
|
|
207
|
-
border-color: ${thumbHoverBorderColor};
|
|
208
|
-
background-color: ${thumbHoverBackgroundColor};
|
|
209
|
-
`, ':hover')}
|
|
210
|
-
|
|
211
|
-
${thumbStyles(`
|
|
212
|
-
background-color: ${thumbBackgroundColor};
|
|
213
|
-
border-color: ${thumbFocusBorderColor};
|
|
214
|
-
`, '[data-garden-focus-visible="true"]')}
|
|
215
|
-
|
|
216
|
-
${thumbStyles(`
|
|
217
|
-
border-color: ${thumbActiveBorderColor};
|
|
218
|
-
background-color: ${thumbActiveBackgroundColor}
|
|
219
|
-
`, ':active')}
|
|
220
|
-
`;
|
|
221
|
-
};
|
|
222
|
-
const getThumbSize = props => props.theme.space.base * (props.isOpaque ? 6 : 4);
|
|
223
|
-
const getTrackHeight = props => props.theme.space.base * (props.isOpaque ? 6 : 3);
|
|
224
|
-
const getTrackMargin = props => (getThumbSize(props) - getTrackHeight(props)) / 2 + stripUnit(props.theme.shadowWidths.md);
|
|
225
|
-
const sizeStyles$2 = props => {
|
|
226
|
-
const thumbSize = getThumbSize(props);
|
|
227
|
-
const trackHeight = getTrackHeight(props);
|
|
228
|
-
const trackMargin = getTrackMargin(props);
|
|
229
|
-
const thumbMargin = (trackHeight - thumbSize) / 2;
|
|
230
|
-
const trackOffset = props.theme.space.base * (props.isOpaque ? -2 : -1);
|
|
231
|
-
const height = props.isOpaque ? trackHeight : trackMargin * 2 + trackHeight;
|
|
232
|
-
let marginHorizontal;
|
|
233
|
-
let border;
|
|
234
|
-
let borderRadius;
|
|
235
|
-
if (props.isOpaque) {
|
|
236
|
-
marginHorizontal = `-${trackMargin}px`;
|
|
237
|
-
border = `${trackMargin}px ${props.theme.borderStyles.solid}`;
|
|
238
|
-
borderRadius = `${trackMargin + stripUnit(props.theme.shadowWidths.md)}px`;
|
|
239
|
-
}
|
|
240
|
-
return `
|
|
241
|
-
/* stylelint-disable-next-line declaration-no-important */
|
|
242
|
-
margin-top: 0 !important;
|
|
243
|
-
margin-${props.theme.rtl ? 'right' : 'left'}: ${marginHorizontal};
|
|
244
|
-
height: ${height}px; /* [1] */
|
|
245
|
-
box-sizing: content-box; /* [2] */
|
|
246
|
-
border: ${border};
|
|
247
|
-
border-radius: ${borderRadius};
|
|
248
|
-
|
|
249
|
-
${trackStyles(`
|
|
250
|
-
margin: ${trackMargin}px ${trackOffset}px;
|
|
251
|
-
height: ${trackHeight}px;
|
|
252
|
-
`)}
|
|
253
|
-
|
|
254
|
-
${thumbStyles(`
|
|
255
|
-
margin: ${thumbMargin}px 0;
|
|
256
|
-
border-width: ${math(`${props.theme.borderWidths.sm} * 2`)};
|
|
257
|
-
height: ${thumbSize}px;
|
|
258
|
-
width: ${thumbSize}px;
|
|
259
|
-
`)};
|
|
260
|
-
`;
|
|
261
|
-
};
|
|
262
|
-
const StyledRange = styled(Range).attrs({
|
|
263
|
-
'data-garden-id': COMPONENT_ID$k,
|
|
264
|
-
'data-garden-version': '8.75.1',
|
|
265
|
-
hasLowerTrack: false
|
|
266
|
-
}).withConfig({
|
|
267
|
-
displayName: "StyledRange",
|
|
268
|
-
componentId: "sc-ug3wi9-0"
|
|
269
|
-
})(["", ";", " ", ";", ";"], sizeStyles$2, trackStyles(`
|
|
270
|
-
border-radius: 0;
|
|
271
|
-
`), colorStyles$1, props => retrieveComponentStyles(COMPONENT_ID$k, props));
|
|
272
|
-
StyledRange.defaultProps = {
|
|
273
|
-
theme: DEFAULT_THEME
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
const COMPONENT_ID$j = 'colorpickers.colorpicker_hue';
|
|
277
|
-
const StyledHueRange = styled(StyledRange).attrs({
|
|
278
|
-
'data-garden-id': COMPONENT_ID$j,
|
|
279
|
-
'data-garden-version': '8.75.1'
|
|
280
|
-
}).withConfig({
|
|
281
|
-
displayName: "StyledHueRange",
|
|
282
|
-
componentId: "sc-13ly7p-0"
|
|
283
|
-
})(["background:linear-gradient( to ", ",#f00 0%,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,#f00 100% ) no-repeat;background-position:", ";background-size:100% ", "px;"], props => props.theme.rtl ? 'left' : 'right', props => !props.isOpaque && `0 ${getTrackMargin(props)}px`, props => getTrackHeight(props));
|
|
284
|
-
StyledHueRange.defaultProps = {
|
|
285
|
-
theme: DEFAULT_THEME
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
const checkeredBackground = function (theme, size) {
|
|
289
|
-
let positionY = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
290
|
-
let repeat = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'repeat';
|
|
291
|
-
const color = getColorV8('neutralHue', 400, theme);
|
|
292
|
-
const dimensions = `${size}px ${size}px`;
|
|
293
|
-
const positionX1 = theme.rtl ? '100%' : '0';
|
|
294
|
-
const positionX2 = theme.rtl ? `calc(100% - ${size / 2}px)` : `${size / 2}px`;
|
|
295
|
-
const position1 = `${positionX1} ${positionY}px`;
|
|
296
|
-
const position2 = `${positionX2} ${size / 2 + positionY}px`;
|
|
297
|
-
const position3 = `${positionX2} ${positionY}px`;
|
|
298
|
-
const position4 = `${positionX1} ${size / -2 + positionY}px`;
|
|
299
|
-
return `
|
|
300
|
-
linear-gradient(45deg, ${color} 25%, transparent 25%) ${position1} / ${dimensions} ${repeat},
|
|
301
|
-
linear-gradient(45deg, transparent 75%, ${color} 75%) ${position2} / ${dimensions} ${repeat},
|
|
302
|
-
linear-gradient(135deg, ${color} 25%, transparent 25%) ${position3} / ${dimensions} ${repeat},
|
|
303
|
-
linear-gradient(135deg, transparent 75%, ${color} 75%) ${position4} / ${dimensions} ${repeat}
|
|
304
|
-
`;
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const COMPONENT_ID$i = 'colorpickers.colorpicker_alpha';
|
|
308
|
-
const background$3 = props => {
|
|
309
|
-
const direction = `to ${props.theme.rtl ? 'left' : 'right'}`;
|
|
310
|
-
const fromColor = `rgba(${props.red}, ${props.green}, ${props.blue}, 0)`;
|
|
311
|
-
const toColor = `rgb(${props.red}, ${props.green}, ${props.blue})`;
|
|
312
|
-
const positionY = getTrackMargin(props);
|
|
313
|
-
const height = getTrackHeight(props);
|
|
314
|
-
const gradientBackground = `linear-gradient(${direction}, ${fromColor}, ${toColor}) 0 ${positionY}px / 100% ${height}px no-repeat`;
|
|
315
|
-
return `${gradientBackground}, ${checkeredBackground(props.theme, height, positionY, 'repeat-x')}`;
|
|
316
|
-
};
|
|
317
|
-
const StyledAlphaRange = styled(StyledRange).attrs(props => ({
|
|
318
|
-
style: {
|
|
319
|
-
backgroundSize: 'auto',
|
|
320
|
-
background: background$3(props)
|
|
321
|
-
},
|
|
322
|
-
'data-garden-id': COMPONENT_ID$i,
|
|
323
|
-
'data-garden-version': '8.75.1'
|
|
324
|
-
})).withConfig({
|
|
325
|
-
displayName: "StyledAlphaRange",
|
|
326
|
-
componentId: "sc-kuh2xc-0"
|
|
327
|
-
})([""]);
|
|
328
|
-
StyledAlphaRange.defaultProps = {
|
|
329
|
-
theme: DEFAULT_THEME
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
const COMPONENT_ID$h = 'colorpickers.colorpicker_preview_box';
|
|
333
|
-
const background$2 = props => {
|
|
334
|
-
const alpha = props.alpha ? props.alpha / 100 : 0;
|
|
335
|
-
const color = `rgba(${props.red}, ${props.green}, ${props.blue}, ${alpha})`;
|
|
336
|
-
let retVal = `linear-gradient(${color}, ${color})`;
|
|
337
|
-
if (!props.isOpaque) {
|
|
338
|
-
retVal = `${retVal}, ${checkeredBackground(props.theme, 13)}`;
|
|
339
|
-
}
|
|
340
|
-
return retVal;
|
|
341
|
-
};
|
|
342
|
-
const StyledPreview = styled.div.attrs(props => ({
|
|
343
|
-
style: {
|
|
344
|
-
background: background$2(props)
|
|
345
|
-
},
|
|
346
|
-
'data-garden-id': COMPONENT_ID$h,
|
|
347
|
-
'data-garden-version': '8.75.1',
|
|
348
|
-
'data-test-id': 'preview-box'
|
|
349
|
-
})).withConfig({
|
|
350
|
-
displayName: "StyledPreview",
|
|
351
|
-
componentId: "sc-d70mj1-0"
|
|
352
|
-
})(["flex-shrink:0;border-radius:", ";box-shadow:inset 0 0 0 ", " ", ";width:", "px;height:", "px;", ";"], props => props.theme.borderRadii.md, props => props.theme.borderWidths.sm, props => rgba(props.theme.palette.black, 0.19), props => props.theme.space.base * (props.isOpaque ? 6 : 8), props => props.theme.space.base * (props.isOpaque ? 6 : 8), props => retrieveComponentStyles(COMPONENT_ID$h, props));
|
|
353
|
-
StyledPreview.defaultProps = {
|
|
354
|
-
theme: DEFAULT_THEME
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
const COMPONENT_ID$g = 'colorpickers.colorpicker_colorwell';
|
|
358
|
-
const background$1 = props => {
|
|
359
|
-
const blackAlpha = rgba(props.theme.palette.black, 0.9);
|
|
360
|
-
const black = `linear-gradient(0deg, ${props.theme.palette.black}, ${blackAlpha} 1%, transparent 99%)`;
|
|
361
|
-
const whiteAngle = `${props.theme.rtl ? -90 : 90}deg`;
|
|
362
|
-
const white = `linear-gradient(${whiteAngle}, ${props.theme.palette.white} 1%, transparent)`;
|
|
363
|
-
const colorValue = hsl(props.hue, 1, 0.5);
|
|
364
|
-
const color = `linear-gradient(${colorValue}, ${colorValue})`;
|
|
365
|
-
return `${black}, ${white}, ${color}`;
|
|
366
|
-
};
|
|
367
|
-
const StyledColorWell = styled.div.attrs(props => ({
|
|
368
|
-
'data-garden-id': COMPONENT_ID$g,
|
|
369
|
-
'data-garden-version': '8.75.1',
|
|
370
|
-
'data-test-id': 'colorwell',
|
|
371
|
-
style: {
|
|
372
|
-
background: background$1(props)
|
|
373
|
-
}
|
|
374
|
-
})).withConfig({
|
|
375
|
-
displayName: "StyledColorWell",
|
|
376
|
-
componentId: "sc-54ly7s-0"
|
|
377
|
-
})(["position:relative;margin-bottom:", "px;cursor:pointer;height:208px;overflow:hidden;", ";"], props => props.theme.space.base * 2, props => retrieveComponentStyles(COMPONENT_ID$g, props));
|
|
378
|
-
StyledColorWell.defaultProps = {
|
|
379
|
-
theme: DEFAULT_THEME
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
const COMPONENT_ID$f = 'colorpickers.colorpicker_colorwell_thumb';
|
|
383
|
-
const sizeStyles$1 = theme => {
|
|
384
|
-
const borderWidth = stripUnit(theme.borderWidths.sm) * 2;
|
|
385
|
-
const size = theme.space.base * 5;
|
|
386
|
-
const translateValue = size / -2;
|
|
387
|
-
return `
|
|
388
|
-
transform: translate(${translateValue}px, ${translateValue}px);
|
|
389
|
-
box-sizing: border-box;
|
|
390
|
-
border-width: ${borderWidth}px;
|
|
391
|
-
width: ${size}px;
|
|
392
|
-
height: ${size}px;
|
|
393
|
-
`;
|
|
394
|
-
};
|
|
395
|
-
const StyledColorWellThumb = styled.div.attrs(props => ({
|
|
396
|
-
'data-garden-id': COMPONENT_ID$f,
|
|
397
|
-
'data-garden-version': '8.75.1',
|
|
398
|
-
'data-test-id': 'colorwell-thumb',
|
|
399
|
-
style: {
|
|
400
|
-
top: `${props.top}%`,
|
|
401
|
-
left: `${props.left}%`
|
|
402
|
-
}
|
|
403
|
-
})).withConfig({
|
|
404
|
-
displayName: "StyledColorWellThumb",
|
|
405
|
-
componentId: "sc-1pnz3jz-0"
|
|
406
|
-
})(["position:absolute;border:solid ", ";border-radius:50%;box-shadow:", ";", ";", ";"], props => props.theme.palette.white, props => props.theme.shadows.lg(`${props.theme.space.base}px`, `${props.theme.space.base * 2}px`, getColorV8('neutralHue', 800, props.theme, 0.24)), props => sizeStyles$1(props.theme), props => retrieveComponentStyles(COMPONENT_ID$f, props));
|
|
407
|
-
StyledColorWellThumb.defaultProps = {
|
|
408
|
-
theme: DEFAULT_THEME
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
const COMPONENT_ID$e = 'colorpickers.colorpicker_slider_group';
|
|
412
|
-
const StyledSliderGroup = styled.div.attrs({
|
|
413
|
-
'data-garden-id': COMPONENT_ID$e,
|
|
414
|
-
'data-garden-version': '8.75.1'
|
|
415
|
-
}).withConfig({
|
|
416
|
-
displayName: "StyledSliderGroup",
|
|
417
|
-
componentId: "sc-rsq0ak-0"
|
|
418
|
-
})(["display:flex;justify-content:space-between;margin-bottom:", "px;", ";"], props => props.theme.space.base * 2, props => retrieveComponentStyles(COMPONENT_ID$e, props));
|
|
419
|
-
StyledSliderGroup.defaultProps = {
|
|
420
|
-
theme: DEFAULT_THEME
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
const COMPONENT_ID$d = 'colorpickers.colorpicker_hex_field';
|
|
424
|
-
const StyledHexField = styled(Field).attrs({
|
|
425
|
-
'data-garden-id': COMPONENT_ID$d,
|
|
426
|
-
'data-garden-version': '8.75.1',
|
|
427
|
-
spellcheck: false
|
|
428
|
-
}).withConfig({
|
|
429
|
-
displayName: "StyledHexField",
|
|
430
|
-
componentId: "sc-1lk14t4-0"
|
|
431
|
-
})(["display:flex;flex-basis:0;flex-direction:column;flex-grow:1;width:auto;text-align:center;input{direction:ltr;}", ";"], props => retrieveComponentStyles(COMPONENT_ID$d, props));
|
|
432
|
-
StyledHexField.defaultProps = {
|
|
433
|
-
theme: DEFAULT_THEME
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
const COMPONENT_ID$c = 'colorpickers.colorpicker_label';
|
|
437
|
-
const StyledLabel = styled(Label).attrs({
|
|
438
|
-
'data-garden-id': COMPONENT_ID$c,
|
|
439
|
-
'data-garden-version': '8.75.1'
|
|
440
|
-
}).withConfig({
|
|
441
|
-
displayName: "StyledLabel",
|
|
442
|
-
componentId: "sc-1klhp6m-0"
|
|
443
|
-
})(["overflow:hidden;text-overflow:ellipsis;white-space:nowrap;", ";"], props => retrieveComponentStyles(COMPONENT_ID$c, props));
|
|
444
|
-
StyledLabel.defaultProps = {
|
|
445
|
-
theme: DEFAULT_THEME
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
const COMPONENT_ID$b = 'colorpickers.colorpicker_input';
|
|
449
|
-
const StyledInput = styled(Input).attrs({
|
|
450
|
-
'data-garden-id': COMPONENT_ID$b,
|
|
451
|
-
'data-garden-version': '8.75.1',
|
|
452
|
-
focusInset: false
|
|
453
|
-
}).withConfig({
|
|
454
|
-
displayName: "StyledInput",
|
|
455
|
-
componentId: "sc-1iap93p-0"
|
|
456
|
-
})(["text-align:center;", ";"], props => retrieveComponentStyles(COMPONENT_ID$b, props));
|
|
457
|
-
StyledInput.defaultProps = {
|
|
458
|
-
theme: DEFAULT_THEME
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
const COMPONENT_ID$a = 'colorpickers.colorpicker_input_group';
|
|
462
|
-
const StyledInputGroup = styled.div.attrs({
|
|
463
|
-
'data-garden-id': COMPONENT_ID$a,
|
|
464
|
-
'data-garden-version': '8.75.1'
|
|
465
|
-
}).withConfig({
|
|
466
|
-
displayName: "StyledInputGroup",
|
|
467
|
-
componentId: "sc-mmy93w-0"
|
|
468
|
-
})(["display:flex;justify-content:space-between;", ";"], props => retrieveComponentStyles(COMPONENT_ID$a, props));
|
|
469
|
-
StyledInputGroup.defaultProps = {
|
|
470
|
-
theme: DEFAULT_THEME
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
const COMPONENT_ID$9 = 'colorpickers.colorpicker_rgb_field';
|
|
474
|
-
const sizeStyles = theme => {
|
|
475
|
-
const margin = `${theme.space.base * 1.5}px`;
|
|
476
|
-
const width = `${theme.space.base * 12.75}px`;
|
|
477
|
-
return `
|
|
478
|
-
margin-${theme.rtl ? 'right' : 'left'}: ${margin};
|
|
479
|
-
width: ${width};
|
|
480
|
-
min-width: ${width};
|
|
481
|
-
`;
|
|
482
|
-
};
|
|
483
|
-
const StyledRGBAField = styled(Field).attrs({
|
|
484
|
-
'data-garden-id': COMPONENT_ID$9,
|
|
485
|
-
'data-garden-version': '8.75.1'
|
|
486
|
-
}).withConfig({
|
|
487
|
-
displayName: "StyledRGBAField",
|
|
488
|
-
componentId: "sc-ibo1yw-0"
|
|
489
|
-
})(["display:flex;flex-direction:column;text-align:center;", ";", ";"], props => sizeStyles(props.theme), props => retrieveComponentStyles(COMPONENT_ID$9, props));
|
|
490
|
-
StyledRGBAField.defaultProps = {
|
|
491
|
-
theme: DEFAULT_THEME
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
const COMPONENT_ID$8 = 'colorpickers.colorpicker_sliders';
|
|
495
|
-
const StyledSliders = styled.div.attrs({
|
|
496
|
-
'data-garden-id': COMPONENT_ID$8,
|
|
497
|
-
'data-garden-version': '8.75.1'
|
|
498
|
-
}).withConfig({
|
|
499
|
-
displayName: "StyledSliders",
|
|
500
|
-
componentId: "sc-aclca2-0"
|
|
501
|
-
})(["position:relative;margin-", ":", "px;width:100%;& > *{position:absolute;width:100%;height:", "px;}& > :first-child{top:-", "px;}& > :last-child{bottom:-", "px;}", ";"], props => props.theme.rtl ? 'right' : 'left', props => props.theme.space.base * 2, props => getTrackMargin(props) * 2 + getTrackHeight(props), getTrackMargin, getTrackMargin, props => retrieveComponentStyles(COMPONENT_ID$8, props));
|
|
502
|
-
StyledSliders.defaultProps = {
|
|
503
|
-
theme: DEFAULT_THEME
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
const COMPONENT_ID$7 = 'colorpickers.colordialog_button';
|
|
507
|
-
const StyledButton = styled(Button).attrs({
|
|
508
|
-
isNeutral: true,
|
|
509
|
-
'data-garden-id': COMPONENT_ID$7,
|
|
510
|
-
'data-garden-version': '8.75.1'
|
|
511
|
-
}).withConfig({
|
|
512
|
-
displayName: "StyledButton",
|
|
513
|
-
componentId: "sc-101xjve-0"
|
|
514
|
-
})(["padding:0;width:", "px;max-width:", "px;&:last-of-type:not(:first-child){border-top-", "-radius:", " !important;border-bottom-", "-radius:", " !important;}", ";"], props => props.theme.space.base * 17, props => props.theme.space.base * 17, props => props.theme.rtl ? 'left' : 'right', props => props.theme.borderRadii.md, props => props.theme.rtl ? 'left' : 'right', props => props.theme.borderRadii.md, props => retrieveComponentStyles(COMPONENT_ID$7, props));
|
|
515
|
-
StyledButton.defaultProps = {
|
|
516
|
-
theme: DEFAULT_THEME
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
const COMPONENT_ID$6 = 'colorpickers.colordialog_preview';
|
|
520
|
-
const background = props => {
|
|
521
|
-
const {
|
|
522
|
-
backgroundColor
|
|
523
|
-
} = props;
|
|
524
|
-
let color;
|
|
525
|
-
if (typeof backgroundColor === 'string') {
|
|
526
|
-
color = backgroundColor;
|
|
527
|
-
} else if (backgroundColor === undefined) {
|
|
528
|
-
color = props.theme.palette.white;
|
|
529
|
-
} else {
|
|
530
|
-
const {
|
|
531
|
-
red,
|
|
532
|
-
green,
|
|
533
|
-
blue,
|
|
534
|
-
alpha = 1
|
|
535
|
-
} = backgroundColor;
|
|
536
|
-
color = `rgba(${red}, ${green}, ${blue}, ${alpha ? alpha / 100 : 0})`;
|
|
537
|
-
}
|
|
538
|
-
return `linear-gradient(${color}, ${color})`;
|
|
539
|
-
};
|
|
540
|
-
const StyledButtonPreview = styled.span.attrs(props => ({
|
|
541
|
-
style: {
|
|
542
|
-
background: `${background(props)}, ${checkeredBackground(props.theme, 8)}`
|
|
543
|
-
},
|
|
544
|
-
'data-garden-id': COMPONENT_ID$6,
|
|
545
|
-
'data-garden-version': '8.75.1',
|
|
546
|
-
'data-test-id': 'dialog-preview'
|
|
547
|
-
})).withConfig({
|
|
548
|
-
displayName: "StyledButtonPreview",
|
|
549
|
-
componentId: "sc-1jzysg3-0"
|
|
550
|
-
})(["display:inline-block;bottom:", "px;border-radius:", ";box-shadow:inset 0 0 0 ", " ", ";width:", "px;height:", "px;", ";"], props => props.theme.space.base, props => props.theme.borderRadii.sm, props => props.theme.borderWidths.sm, props => rgba(props.theme.palette.black, 0.19), props => props.theme.space.base * 5, props => props.theme.space.base * 5, props => retrieveComponentStyles(COMPONENT_ID$6, props));
|
|
551
|
-
StyledButtonPreview.defaultProps = {
|
|
552
|
-
theme: DEFAULT_THEME
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
const COMPONENT_ID$5 = 'colorpickers.colordialog_tooltipmodal';
|
|
556
|
-
const StyledTooltipModal = styled(TooltipModal).attrs({
|
|
557
|
-
'data-garden-id': COMPONENT_ID$5,
|
|
558
|
-
'data-garden-version': '8.75.1'
|
|
559
|
-
}).withConfig({
|
|
560
|
-
displayName: "StyledTooltipModal",
|
|
561
|
-
componentId: "sc-o022s8-0"
|
|
562
|
-
})(["width:auto !important;", ";"], props => retrieveComponentStyles(COMPONENT_ID$5, props));
|
|
563
|
-
StyledTooltipModal.defaultProps = {
|
|
564
|
-
theme: DEFAULT_THEME
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
const COMPONENT_ID$4 = 'colorpickers.colordialog_tooltipmodal_body';
|
|
568
|
-
const StyledTooltipBody = styled(TooltipModal.Body).attrs({
|
|
569
|
-
'data-garden-id': COMPONENT_ID$4,
|
|
570
|
-
'data-garden-version': '8.75.1'
|
|
571
|
-
}).withConfig({
|
|
572
|
-
displayName: "StyledTooltipBody",
|
|
573
|
-
componentId: "sc-6gsgsy-0"
|
|
574
|
-
})(["padding:0;", ";"], props => retrieveComponentStyles(COMPONENT_ID$4, props));
|
|
575
|
-
StyledTooltipBody.defaultProps = {
|
|
576
|
-
theme: DEFAULT_THEME
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
const COMPONENT_ID$3 = 'colorpickers.swatch_button';
|
|
580
|
-
const StyledSwatchButton = styled(StyledButtonPreview).attrs(props => ({
|
|
581
|
-
as: 'button',
|
|
582
|
-
'data-garden-id': COMPONENT_ID$3,
|
|
583
|
-
'data-test-id': props.backgroundColor,
|
|
584
|
-
'data-garden-version': '8.75.1'
|
|
585
|
-
})).withConfig({
|
|
586
|
-
displayName: "StyledSwatchButton",
|
|
587
|
-
componentId: "sc-edpwpp-0"
|
|
588
|
-
})(["transition:box-shadow 0.1s ease-in-out;outline:none;border:none;border-radius:", ";cursor:pointer;padding:0;", " ", ";"], props => props.theme.borderRadii.md, props => focusStyles({
|
|
589
|
-
theme: props.theme
|
|
590
|
-
}), props => retrieveComponentStyles(COMPONENT_ID$3, props));
|
|
591
|
-
StyledSwatchButton.defaultProps = {
|
|
592
|
-
theme: DEFAULT_THEME
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
const COMPONENT_ID$2 = 'colorpickers.color_swatch';
|
|
596
|
-
const StyledColorSwatch = styled.table.attrs({
|
|
597
|
-
'data-garden-id': COMPONENT_ID$2,
|
|
598
|
-
'data-garden-version': '8.75.1',
|
|
599
|
-
role: 'grid'
|
|
600
|
-
}).withConfig({
|
|
601
|
-
displayName: "StyledColorSwatch",
|
|
602
|
-
componentId: "sc-ajx440-0"
|
|
603
|
-
})(["border-collapse:collapse;line-height:normal;", ";"], props => retrieveComponentStyles(COMPONENT_ID$2, props));
|
|
604
|
-
StyledColorSwatch.defaultProps = {
|
|
605
|
-
theme: DEFAULT_THEME
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
const COMPONENT_ID$1 = 'colorpickers.colorswatch_check';
|
|
609
|
-
const colorStyles = props => {
|
|
610
|
-
const {
|
|
611
|
-
theme,
|
|
612
|
-
color
|
|
613
|
-
} = props;
|
|
614
|
-
const {
|
|
615
|
-
alpha
|
|
616
|
-
} = parseToRgb(color);
|
|
617
|
-
let checkColor = readableColor(color, getColorV8('foreground', 600 , theme), getColorV8('background', 600 , theme));
|
|
618
|
-
if (alpha !== undefined && alpha < 0.4) {
|
|
619
|
-
checkColor = getColorV8('foreground', 600 , theme);
|
|
620
|
-
}
|
|
621
|
-
return `
|
|
622
|
-
color: ${checkColor}
|
|
623
|
-
`;
|
|
624
|
-
};
|
|
625
|
-
const StyledIcon = styled(_ref => {
|
|
626
|
-
let {
|
|
627
|
-
children,
|
|
628
|
-
color,
|
|
629
|
-
theme,
|
|
630
|
-
...props
|
|
631
|
-
} = _ref;
|
|
632
|
-
return React__default.cloneElement(Children.only(children), props);
|
|
633
|
-
}).attrs({
|
|
634
|
-
'data-garden-id': COMPONENT_ID$1,
|
|
635
|
-
'data-garden-version': '8.75.1'
|
|
636
|
-
}).withConfig({
|
|
637
|
-
displayName: "StyledIcon",
|
|
638
|
-
componentId: "sc-8oigif-0"
|
|
639
|
-
})(["transition:opacity 0.2s ease-in-out;opacity:", ";width:", "px;height:", "px;", " ", ";"], props => props.selected ? 1 : 0, props => props.theme.space.base * 5, props => props.theme.space.base * 5, colorStyles, props => retrieveComponentStyles(COMPONENT_ID$1, props));
|
|
640
|
-
StyledIcon.defaultProps = {
|
|
641
|
-
theme: DEFAULT_THEME
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
const COMPONENT_ID = 'colorpickers.swatch_cell';
|
|
645
|
-
const StyledCell = styled.td.attrs({
|
|
646
|
-
'data-garden-id': COMPONENT_ID,
|
|
647
|
-
'data-garden-version': '8.75.1'
|
|
648
|
-
}).withConfig({
|
|
649
|
-
displayName: "StyledCell",
|
|
650
|
-
componentId: "sc-qr3oit-0"
|
|
651
|
-
})(["padding:", "px;font-size:0;", ";"], props => props.theme.space.base, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
652
|
-
StyledCell.defaultProps = {
|
|
653
|
-
theme: DEFAULT_THEME
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
const ColorWell = React__default.memo(_ref => {
|
|
657
|
-
let {
|
|
658
|
-
hue,
|
|
659
|
-
saturation,
|
|
660
|
-
lightness,
|
|
661
|
-
onChange
|
|
662
|
-
} = _ref;
|
|
663
|
-
const {
|
|
664
|
-
rtl
|
|
665
|
-
} = useContext(ThemeContext);
|
|
666
|
-
const containerRef = useRef(null);
|
|
667
|
-
const hsv = hslToHsv(hue, saturation, lightness);
|
|
668
|
-
const mouseActiveRef = useRef(false);
|
|
669
|
-
const [x, setX] = useState(0);
|
|
670
|
-
const [y, setY] = useState(0);
|
|
671
|
-
const {
|
|
672
|
-
topFromMouse,
|
|
673
|
-
leftFromMouse
|
|
674
|
-
} = getThumbPosition(x, y, rtl, containerRef);
|
|
675
|
-
const [topPosition, setTopPosition] = useState(0);
|
|
676
|
-
const [leftPosition, setLeftPosition] = useState(0);
|
|
677
|
-
useEffect(() => {
|
|
678
|
-
setTopPosition(100 - hsv.v);
|
|
679
|
-
setLeftPosition(rtl ? 100 - hsv.s : hsv.s);
|
|
680
|
-
}, [hsv.s, hsv.v, rtl]);
|
|
681
|
-
const throttledChange = useMemo(() => {
|
|
682
|
-
return throttle(e => {
|
|
683
|
-
if (containerRef.current) {
|
|
684
|
-
const nextHsv = getNextHsv(e, hue, containerRef.current, rtl);
|
|
685
|
-
onChange && onChange(nextHsv, e);
|
|
686
|
-
}
|
|
687
|
-
}, 50);
|
|
688
|
-
}, [hue, rtl, onChange]);
|
|
689
|
-
const handleMouseMove = useCallback(e => {
|
|
690
|
-
mouseActiveRef.current = true;
|
|
691
|
-
setX(e.pageX);
|
|
692
|
-
setY(e.pageY);
|
|
693
|
-
throttledChange(e);
|
|
694
|
-
}, [throttledChange]);
|
|
695
|
-
const handleMouseUp = useCallback(() => {
|
|
696
|
-
mouseActiveRef.current = true;
|
|
697
|
-
setTimeout(() => {
|
|
698
|
-
mouseActiveRef.current = false;
|
|
699
|
-
});
|
|
700
|
-
throttledChange.cancel();
|
|
701
|
-
window.removeEventListener('mousemove', handleMouseMove);
|
|
702
|
-
window.removeEventListener('mouseup', handleMouseUp);
|
|
703
|
-
}, [throttledChange, handleMouseMove]);
|
|
704
|
-
const handleMouseDown = useCallback(e => {
|
|
705
|
-
mouseActiveRef.current = true;
|
|
706
|
-
e.persist();
|
|
707
|
-
handleMouseMove(e);
|
|
708
|
-
throttledChange(e);
|
|
709
|
-
window.addEventListener('mousemove', handleMouseMove);
|
|
710
|
-
window.addEventListener('mouseup', handleMouseUp);
|
|
711
|
-
}, [throttledChange, handleMouseMove, handleMouseUp]);
|
|
712
|
-
useEffect(() => {
|
|
713
|
-
return () => {
|
|
714
|
-
throttledChange.cancel();
|
|
715
|
-
};
|
|
716
|
-
}, [throttledChange]);
|
|
717
|
-
return (
|
|
718
|
-
React__default.createElement(StyledColorWell, {
|
|
719
|
-
hue: hue,
|
|
720
|
-
ref: containerRef,
|
|
721
|
-
role: "presentation",
|
|
722
|
-
onMouseDown: handleMouseDown
|
|
723
|
-
}, React__default.createElement(StyledColorWellThumb, {
|
|
724
|
-
top: mouseActiveRef.current ? topFromMouse : topPosition,
|
|
725
|
-
left: mouseActiveRef.current ? leftFromMouse : leftPosition
|
|
726
|
-
}))
|
|
727
|
-
);
|
|
728
|
-
});
|
|
729
|
-
ColorWell.displayName = 'ColorWell';
|
|
730
|
-
|
|
731
|
-
const isValidHex = hexString => {
|
|
732
|
-
const regEx = /^#(?:(?:[0-9A-F]{6}(?:[0-9A-F]{2})?)|(?:[0-9A-F]{3})(?:[0-9A-F]?))$/iu;
|
|
733
|
-
return regEx.test(hexString);
|
|
734
|
-
};
|
|
735
|
-
|
|
736
|
-
function convertStringToColor(colorString) {
|
|
737
|
-
if (colorString.includes('#') && !isValidHex(colorString)) {
|
|
738
|
-
return undefined;
|
|
739
|
-
}
|
|
740
|
-
const {
|
|
741
|
-
hue,
|
|
742
|
-
saturation,
|
|
743
|
-
lightness
|
|
744
|
-
} = parseToHsl(colorString);
|
|
745
|
-
const {
|
|
746
|
-
red,
|
|
747
|
-
green,
|
|
748
|
-
blue,
|
|
749
|
-
alpha
|
|
750
|
-
} = parseToRgb(colorString);
|
|
751
|
-
const computedAlpha = alpha === undefined ? 100 : alpha * 100;
|
|
752
|
-
const computedHex = rgb({
|
|
753
|
-
red,
|
|
754
|
-
green,
|
|
755
|
-
blue
|
|
756
|
-
});
|
|
757
|
-
return {
|
|
758
|
-
hue,
|
|
759
|
-
saturation: saturation * 100,
|
|
760
|
-
lightness: lightness * 100,
|
|
761
|
-
red,
|
|
762
|
-
green,
|
|
763
|
-
blue,
|
|
764
|
-
alpha: computedAlpha,
|
|
765
|
-
hex: computedHex
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
const areColorsEqual = (a, b) => {
|
|
769
|
-
if (a === undefined || b === undefined) {
|
|
770
|
-
return false;
|
|
771
|
-
}
|
|
772
|
-
const colorA = typeof a === 'string' ? convertStringToColor(a) : a;
|
|
773
|
-
const colorB = typeof b === 'string' ? convertStringToColor(b) : b;
|
|
774
|
-
if (colorA === undefined || colorB === undefined) {
|
|
775
|
-
return false;
|
|
776
|
-
}
|
|
777
|
-
return isEqual(colorA, colorB);
|
|
778
|
-
};
|
|
779
|
-
function getInitialState(color) {
|
|
780
|
-
const whiteColor = {
|
|
781
|
-
hue: 0,
|
|
782
|
-
saturation: 0,
|
|
783
|
-
lightness: 0,
|
|
784
|
-
red: 255,
|
|
785
|
-
green: 255,
|
|
786
|
-
blue: 255,
|
|
787
|
-
alpha: 100,
|
|
788
|
-
hex: '#ffffff'
|
|
789
|
-
};
|
|
790
|
-
if (color === undefined) {
|
|
791
|
-
return getInitialState(whiteColor);
|
|
792
|
-
}
|
|
793
|
-
if (typeof color === 'string') {
|
|
794
|
-
const computedColor = convertStringToColor(color);
|
|
795
|
-
return getInitialState(computedColor || whiteColor);
|
|
796
|
-
}
|
|
797
|
-
return {
|
|
798
|
-
color,
|
|
799
|
-
hexInput: color.hex,
|
|
800
|
-
redInput: color.red.toString(),
|
|
801
|
-
blueInput: color.blue.toString(),
|
|
802
|
-
greenInput: color.green.toString(),
|
|
803
|
-
alphaInput: color.alpha.toString()
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
const reducer = (state, action) => {
|
|
807
|
-
switch (action.type) {
|
|
808
|
-
case 'SATURATION_CHANGE':
|
|
809
|
-
{
|
|
810
|
-
const hsl$1 = hsvToHsl(action.payload.h, action.payload.s * 100, action.payload.v * 100);
|
|
811
|
-
const hex = hsl({
|
|
812
|
-
hue: action.payload.h,
|
|
813
|
-
saturation: hsl$1.s / 100,
|
|
814
|
-
lightness: hsl$1.l / 100
|
|
815
|
-
});
|
|
816
|
-
const rgb = parseToRgb(hex);
|
|
817
|
-
return {
|
|
818
|
-
...state,
|
|
819
|
-
color: {
|
|
820
|
-
...state.color,
|
|
821
|
-
saturation: hsl$1.s,
|
|
822
|
-
lightness: hsl$1.l,
|
|
823
|
-
hex,
|
|
824
|
-
red: rgb.red,
|
|
825
|
-
green: rgb.green,
|
|
826
|
-
blue: rgb.blue
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
case 'HUE_CHANGE':
|
|
831
|
-
{
|
|
832
|
-
const hue = Number(action.payload);
|
|
833
|
-
const hex = hsl({
|
|
834
|
-
hue,
|
|
835
|
-
saturation: state.color.saturation / 100,
|
|
836
|
-
lightness: state.color.lightness / 100
|
|
837
|
-
});
|
|
838
|
-
const rgb = parseToRgb(hex);
|
|
839
|
-
return {
|
|
840
|
-
...state,
|
|
841
|
-
color: {
|
|
842
|
-
...state.color,
|
|
843
|
-
hue,
|
|
844
|
-
hex,
|
|
845
|
-
red: rgb.red,
|
|
846
|
-
green: rgb.green,
|
|
847
|
-
blue: rgb.blue
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
case 'ALPHA_SLIDER_CHANGE':
|
|
852
|
-
{
|
|
853
|
-
return {
|
|
854
|
-
...state,
|
|
855
|
-
color: {
|
|
856
|
-
...state.color,
|
|
857
|
-
alpha: Math.round(Number(action.payload) * 100)
|
|
858
|
-
}
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
case 'HEX_CHANGE':
|
|
862
|
-
{
|
|
863
|
-
let color = state.color;
|
|
864
|
-
if (isValidHex(action.payload)) {
|
|
865
|
-
const rgb = parseToRgb(action.payload);
|
|
866
|
-
const hsl = parseToHsl(`rgb(${rgb.red}, ${rgb.green}, ${rgb.blue})`);
|
|
867
|
-
color = {
|
|
868
|
-
...color,
|
|
869
|
-
hue: hsl.hue,
|
|
870
|
-
saturation: hsl.saturation * 100,
|
|
871
|
-
lightness: hsl.lightness * 100,
|
|
872
|
-
hex: action.payload,
|
|
873
|
-
red: rgb.red,
|
|
874
|
-
green: rgb.green,
|
|
875
|
-
blue: rgb.blue
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
return {
|
|
879
|
-
...state,
|
|
880
|
-
hexInput: action.payload,
|
|
881
|
-
color
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
case 'RED_CHANGE':
|
|
885
|
-
{
|
|
886
|
-
let red = parseInt(action.payload, 10);
|
|
887
|
-
let color = state.color;
|
|
888
|
-
if (!isNaN(red)) {
|
|
889
|
-
if (red >= 255) {
|
|
890
|
-
red = 255;
|
|
891
|
-
}
|
|
892
|
-
if (red < 0) {
|
|
893
|
-
red = 0;
|
|
894
|
-
}
|
|
895
|
-
const hsl = parseToHsl(`rgb(${red}, ${color.green}, ${color.blue})`);
|
|
896
|
-
const hex = rgb(red, color.green, color.blue);
|
|
897
|
-
color = {
|
|
898
|
-
...color,
|
|
899
|
-
hex,
|
|
900
|
-
red: action.payload === '' ? color.red : red,
|
|
901
|
-
hue: hsl.hue,
|
|
902
|
-
saturation: hsl.saturation * 100,
|
|
903
|
-
lightness: hsl.lightness * 100
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
return {
|
|
907
|
-
...state,
|
|
908
|
-
redInput: action.payload,
|
|
909
|
-
color
|
|
910
|
-
};
|
|
911
|
-
}
|
|
912
|
-
case 'GREEN_CHANGE':
|
|
913
|
-
{
|
|
914
|
-
let green = parseInt(action.payload, 10);
|
|
915
|
-
let color = state.color;
|
|
916
|
-
if (!isNaN(green)) {
|
|
917
|
-
if (green >= 255) {
|
|
918
|
-
green = 255;
|
|
919
|
-
}
|
|
920
|
-
if (green < 0) {
|
|
921
|
-
green = 0;
|
|
922
|
-
}
|
|
923
|
-
const hsl = parseToHsl(`rgb(${color.red}, ${green}, ${color.blue})`);
|
|
924
|
-
const hex = rgb(color.red, green, color.blue);
|
|
925
|
-
color = {
|
|
926
|
-
...color,
|
|
927
|
-
hex,
|
|
928
|
-
green: action.payload === '' ? color.green : green,
|
|
929
|
-
hue: hsl.hue,
|
|
930
|
-
saturation: hsl.saturation * 100,
|
|
931
|
-
lightness: hsl.lightness * 100
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
|
-
return {
|
|
935
|
-
...state,
|
|
936
|
-
greenInput: action.payload,
|
|
937
|
-
color
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
case 'BLUE_CHANGE':
|
|
941
|
-
{
|
|
942
|
-
let blue = parseInt(action.payload, 10);
|
|
943
|
-
let color = state.color;
|
|
944
|
-
if (!isNaN(blue)) {
|
|
945
|
-
if (blue >= 255) {
|
|
946
|
-
blue = 255;
|
|
947
|
-
}
|
|
948
|
-
if (blue < 0) {
|
|
949
|
-
blue = 0;
|
|
950
|
-
}
|
|
951
|
-
const hsl = parseToHsl(`rgb(${color.red}, ${color.green}, ${blue})`);
|
|
952
|
-
const hex = rgb(color.red, color.green, blue);
|
|
953
|
-
color = {
|
|
954
|
-
...color,
|
|
955
|
-
hex,
|
|
956
|
-
blue: action.payload === '' ? color.blue : blue,
|
|
957
|
-
hue: hsl.hue,
|
|
958
|
-
saturation: hsl.saturation * 100,
|
|
959
|
-
lightness: hsl.lightness * 100
|
|
960
|
-
};
|
|
961
|
-
}
|
|
962
|
-
return {
|
|
963
|
-
...state,
|
|
964
|
-
blueInput: action.payload,
|
|
965
|
-
color
|
|
966
|
-
};
|
|
967
|
-
}
|
|
968
|
-
case 'ALPHA_CHANGE':
|
|
969
|
-
{
|
|
970
|
-
let alpha = parseInt(action.payload, 10);
|
|
971
|
-
let color = state.color;
|
|
972
|
-
if (!isNaN(alpha)) {
|
|
973
|
-
if (alpha > 100) {
|
|
974
|
-
alpha = 100;
|
|
975
|
-
}
|
|
976
|
-
if (alpha < 0) {
|
|
977
|
-
alpha = 0;
|
|
978
|
-
}
|
|
979
|
-
color = {
|
|
980
|
-
...color,
|
|
981
|
-
alpha
|
|
982
|
-
};
|
|
983
|
-
}
|
|
984
|
-
return {
|
|
985
|
-
...state,
|
|
986
|
-
alphaInput: action.payload,
|
|
987
|
-
color
|
|
988
|
-
};
|
|
989
|
-
}
|
|
990
|
-
case 'RESET_COLOR':
|
|
991
|
-
{
|
|
992
|
-
return getInitialState(action.payload);
|
|
993
|
-
}
|
|
994
|
-
default:
|
|
995
|
-
throw new Error('Unknown reducer case.');
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
|
|
999
|
-
const Colorpicker = forwardRef((_ref, ref) => {
|
|
1000
|
-
let {
|
|
1001
|
-
color,
|
|
1002
|
-
defaultColor,
|
|
1003
|
-
isOpaque,
|
|
1004
|
-
labels = {},
|
|
1005
|
-
autofocus,
|
|
1006
|
-
onChange,
|
|
1007
|
-
...props
|
|
1008
|
-
} = _ref;
|
|
1009
|
-
const [state, dispatch] = useReducer(reducer, getInitialState(color || defaultColor));
|
|
1010
|
-
const previousComputedColorRef = useRef(state.color);
|
|
1011
|
-
const previousStateColorRef = useRef(state.color);
|
|
1012
|
-
const computedColor = useMemo(() => {
|
|
1013
|
-
let retVal = state.color;
|
|
1014
|
-
if (color) {
|
|
1015
|
-
if (typeof color === 'string') {
|
|
1016
|
-
const convertedColor = convertStringToColor(color);
|
|
1017
|
-
if (convertedColor) {
|
|
1018
|
-
retVal = convertedColor;
|
|
1019
|
-
}
|
|
1020
|
-
} else {
|
|
1021
|
-
retVal = color;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
if (isOpaque) {
|
|
1025
|
-
retVal.alpha = 100;
|
|
1026
|
-
}
|
|
1027
|
-
if (areColorsEqual(retVal, previousComputedColorRef.current)) {
|
|
1028
|
-
return previousComputedColorRef.current;
|
|
1029
|
-
}
|
|
1030
|
-
return retVal;
|
|
1031
|
-
}, [color, isOpaque, state.color]);
|
|
1032
|
-
useEffect(() => {
|
|
1033
|
-
if (!areColorsEqual(previousStateColorRef.current, state.color) && !areColorsEqual(color, state.color)) {
|
|
1034
|
-
onChange && onChange(state.color);
|
|
1035
|
-
}
|
|
1036
|
-
previousStateColorRef.current = state.color;
|
|
1037
|
-
}, [color, onChange, state.color]);
|
|
1038
|
-
if (previousComputedColorRef.current !== computedColor) {
|
|
1039
|
-
dispatch({
|
|
1040
|
-
type: 'RESET_COLOR',
|
|
1041
|
-
payload: computedColor
|
|
1042
|
-
});
|
|
1043
|
-
previousComputedColorRef.current = computedColor;
|
|
1044
|
-
}
|
|
1045
|
-
const handleColorWellChange = useCallback(hsv => {
|
|
1046
|
-
dispatch({
|
|
1047
|
-
type: 'SATURATION_CHANGE',
|
|
1048
|
-
payload: hsv
|
|
1049
|
-
});
|
|
1050
|
-
}, []);
|
|
1051
|
-
const handleHueChange = useCallback(e => {
|
|
1052
|
-
dispatch({
|
|
1053
|
-
type: 'HUE_CHANGE',
|
|
1054
|
-
payload: e.target.value
|
|
1055
|
-
});
|
|
1056
|
-
}, []);
|
|
1057
|
-
const handleAlphaSliderChange = useCallback(e => {
|
|
1058
|
-
dispatch({
|
|
1059
|
-
type: 'ALPHA_SLIDER_CHANGE',
|
|
1060
|
-
payload: e.target.value
|
|
1061
|
-
});
|
|
1062
|
-
}, []);
|
|
1063
|
-
const handleHexChange = useCallback(e => {
|
|
1064
|
-
dispatch({
|
|
1065
|
-
type: 'HEX_CHANGE',
|
|
1066
|
-
payload: e.target.value
|
|
1067
|
-
});
|
|
1068
|
-
}, []);
|
|
1069
|
-
const handleRedChange = useCallback(e => {
|
|
1070
|
-
dispatch({
|
|
1071
|
-
type: 'RED_CHANGE',
|
|
1072
|
-
payload: e.target.value
|
|
1073
|
-
});
|
|
1074
|
-
}, []);
|
|
1075
|
-
const handleGreenChange = useCallback(e => {
|
|
1076
|
-
dispatch({
|
|
1077
|
-
type: 'GREEN_CHANGE',
|
|
1078
|
-
payload: e.target.value
|
|
1079
|
-
});
|
|
1080
|
-
}, []);
|
|
1081
|
-
const handleBlueChange = useCallback(e => {
|
|
1082
|
-
dispatch({
|
|
1083
|
-
type: 'BLUE_CHANGE',
|
|
1084
|
-
payload: e.target.value
|
|
1085
|
-
});
|
|
1086
|
-
}, []);
|
|
1087
|
-
const handleAlphaChange = useCallback(e => {
|
|
1088
|
-
dispatch({
|
|
1089
|
-
type: 'ALPHA_CHANGE',
|
|
1090
|
-
payload: e.target.value
|
|
1091
|
-
});
|
|
1092
|
-
}, []);
|
|
1093
|
-
const handleBlur = useCallback(() => {
|
|
1094
|
-
dispatch({
|
|
1095
|
-
type: 'RESET_COLOR',
|
|
1096
|
-
payload: computedColor
|
|
1097
|
-
});
|
|
1098
|
-
}, [computedColor]);
|
|
1099
|
-
return React__default.createElement(StyledColorPicker, _extends$2({
|
|
1100
|
-
ref: ref,
|
|
1101
|
-
isOpaque: isOpaque
|
|
1102
|
-
}, props), React__default.createElement(ColorWell, {
|
|
1103
|
-
hue: computedColor.hue,
|
|
1104
|
-
saturation: computedColor.saturation,
|
|
1105
|
-
lightness: computedColor.lightness,
|
|
1106
|
-
onChange: handleColorWellChange
|
|
1107
|
-
}), React__default.createElement(StyledSliderGroup, null, React__default.createElement(StyledPreview, {
|
|
1108
|
-
red: computedColor.red,
|
|
1109
|
-
green: computedColor.green,
|
|
1110
|
-
blue: computedColor.blue,
|
|
1111
|
-
alpha: computedColor.alpha,
|
|
1112
|
-
isOpaque: isOpaque
|
|
1113
|
-
}), React__default.createElement(StyledSliders, {
|
|
1114
|
-
isOpaque: isOpaque
|
|
1115
|
-
}, React__default.createElement(Field, null, React__default.createElement(Label, {
|
|
1116
|
-
hidden: true
|
|
1117
|
-
}, labels.hueSlider || 'Hue slider'), React__default.createElement(StyledHueRange, {
|
|
1118
|
-
step: 1,
|
|
1119
|
-
max: 360,
|
|
1120
|
-
value: computedColor.hue,
|
|
1121
|
-
isOpaque: isOpaque,
|
|
1122
|
-
onChange: handleHueChange
|
|
1123
|
-
})), !isOpaque && React__default.createElement(Field, null, React__default.createElement(Label, {
|
|
1124
|
-
hidden: true
|
|
1125
|
-
}, labels.alphaSlider || 'Alpha slider'), React__default.createElement(StyledAlphaRange, {
|
|
1126
|
-
max: 1,
|
|
1127
|
-
step: 0.01,
|
|
1128
|
-
value: computedColor.alpha / 100,
|
|
1129
|
-
onChange: handleAlphaSliderChange,
|
|
1130
|
-
red: computedColor.red,
|
|
1131
|
-
green: computedColor.green,
|
|
1132
|
-
blue: computedColor.blue
|
|
1133
|
-
})))), React__default.createElement(StyledInputGroup, null, React__default.createElement(StyledHexField, null, React__default.createElement(StyledLabel, {
|
|
1134
|
-
isRegular: true
|
|
1135
|
-
}, labels.hex || 'Hex'), React__default.createElement(StyledInput, {
|
|
1136
|
-
isCompact: true,
|
|
1137
|
-
maxLength: 7,
|
|
1138
|
-
value: state.hexInput
|
|
1139
|
-
,
|
|
1140
|
-
autoFocus: autofocus,
|
|
1141
|
-
spellCheck: false,
|
|
1142
|
-
onBlur: handleBlur,
|
|
1143
|
-
onChange: handleHexChange
|
|
1144
|
-
})), React__default.createElement(StyledRGBAField, null, React__default.createElement(StyledLabel, {
|
|
1145
|
-
isRegular: true
|
|
1146
|
-
}, labels.red || 'R'), React__default.createElement(StyledInput, {
|
|
1147
|
-
isCompact: true,
|
|
1148
|
-
type: "number",
|
|
1149
|
-
min: "0",
|
|
1150
|
-
max: "255",
|
|
1151
|
-
maxLength: 3,
|
|
1152
|
-
value: state.redInput,
|
|
1153
|
-
onBlur: handleBlur,
|
|
1154
|
-
onChange: handleRedChange
|
|
1155
|
-
})), React__default.createElement(StyledRGBAField, null, React__default.createElement(StyledLabel, {
|
|
1156
|
-
isRegular: true
|
|
1157
|
-
}, labels.green || 'G'), React__default.createElement(StyledInput, {
|
|
1158
|
-
isCompact: true,
|
|
1159
|
-
type: "number",
|
|
1160
|
-
min: "0",
|
|
1161
|
-
max: "255",
|
|
1162
|
-
maxLength: 3,
|
|
1163
|
-
value: state.greenInput,
|
|
1164
|
-
onBlur: handleBlur,
|
|
1165
|
-
onChange: handleGreenChange
|
|
1166
|
-
})), React__default.createElement(StyledRGBAField, null, React__default.createElement(StyledLabel, {
|
|
1167
|
-
isRegular: true
|
|
1168
|
-
}, labels.blue || 'B'), React__default.createElement(StyledInput, {
|
|
1169
|
-
isCompact: true,
|
|
1170
|
-
type: "number",
|
|
1171
|
-
min: "0",
|
|
1172
|
-
max: "255",
|
|
1173
|
-
maxLength: 3,
|
|
1174
|
-
value: state.blueInput,
|
|
1175
|
-
onBlur: handleBlur,
|
|
1176
|
-
onChange: handleBlueChange
|
|
1177
|
-
})), !isOpaque && React__default.createElement(StyledRGBAField, null, React__default.createElement(StyledLabel, {
|
|
1178
|
-
isRegular: true
|
|
1179
|
-
}, labels.alpha || 'A'), React__default.createElement(StyledInput, {
|
|
1180
|
-
isCompact: true,
|
|
1181
|
-
type: "number",
|
|
1182
|
-
min: "0",
|
|
1183
|
-
max: "100",
|
|
1184
|
-
value: state.alphaInput,
|
|
1185
|
-
onBlur: handleBlur,
|
|
1186
|
-
onChange: handleAlphaChange
|
|
1187
|
-
}))));
|
|
1188
|
-
});
|
|
1189
|
-
Colorpicker.defaultProps = {
|
|
1190
|
-
defaultColor: '#fff'
|
|
1191
|
-
};
|
|
1192
|
-
Colorpicker.displayName = 'Colorpicker';
|
|
1193
|
-
Colorpicker.propTypes = {
|
|
1194
|
-
color: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
1195
|
-
isOpaque: PropTypes.bool,
|
|
1196
|
-
onChange: PropTypes.func,
|
|
1197
|
-
labels: PropTypes.object,
|
|
1198
|
-
defaultColor: PropTypes.oneOfType([PropTypes.object, PropTypes.string])
|
|
1199
|
-
};
|
|
1200
|
-
|
|
1201
|
-
var _path$1;
|
|
1202
|
-
function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
|
|
1203
|
-
var SvgChevronDownStroke = function SvgChevronDownStroke(props) {
|
|
1204
|
-
return /*#__PURE__*/React.createElement("svg", _extends$1({
|
|
1205
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1206
|
-
width: 16,
|
|
1207
|
-
height: 16,
|
|
1208
|
-
focusable: "false",
|
|
1209
|
-
viewBox: "0 0 16 16",
|
|
1210
|
-
"aria-hidden": "true"
|
|
1211
|
-
}, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
|
|
1212
|
-
fill: "currentColor",
|
|
1213
|
-
d: "M12.688 5.61a.5.5 0 01.69.718l-.066.062-5 4a.5.5 0 01-.542.054l-.082-.054-5-4a.5.5 0 01.55-.83l.074.05L8 9.359l4.688-3.75z"
|
|
1214
|
-
})));
|
|
1215
|
-
};
|
|
1216
|
-
|
|
1217
|
-
const ColorpickerDialog = forwardRef((_ref, ref) => {
|
|
1218
|
-
let {
|
|
1219
|
-
color,
|
|
1220
|
-
defaultColor,
|
|
1221
|
-
placement,
|
|
1222
|
-
onChange,
|
|
1223
|
-
onClose,
|
|
1224
|
-
labels,
|
|
1225
|
-
hasArrow,
|
|
1226
|
-
isAnimated,
|
|
1227
|
-
isOpaque,
|
|
1228
|
-
isOpen,
|
|
1229
|
-
popperModifiers,
|
|
1230
|
-
zIndex,
|
|
1231
|
-
focusInset,
|
|
1232
|
-
disabled,
|
|
1233
|
-
buttonProps,
|
|
1234
|
-
onDialogChange,
|
|
1235
|
-
'aria-label': ariaLabel,
|
|
1236
|
-
children,
|
|
1237
|
-
...props
|
|
1238
|
-
} = _ref;
|
|
1239
|
-
const isControlled = color !== null && color !== undefined;
|
|
1240
|
-
const isDialogControlled = isOpen !== undefined && isOpen !== null;
|
|
1241
|
-
const buttonRef = useRef(null);
|
|
1242
|
-
const colorPickerRef = useRef(null);
|
|
1243
|
-
const [referenceElement, setReferenceElement] = useState();
|
|
1244
|
-
const [uncontrolledColor, setUncontrolledColor] = useState(defaultColor);
|
|
1245
|
-
const ariaLabelText = useText(ColorpickerDialog, {
|
|
1246
|
-
'aria-label': ariaLabel
|
|
1247
|
-
}, 'aria-label', 'Color picker');
|
|
1248
|
-
const openDialog = () => {
|
|
1249
|
-
setReferenceElement(buttonRef.current);
|
|
1250
|
-
onDialogChange && onDialogChange({
|
|
1251
|
-
isOpen: true
|
|
1252
|
-
});
|
|
1253
|
-
};
|
|
1254
|
-
const closeDialog = () => {
|
|
1255
|
-
setReferenceElement(null);
|
|
1256
|
-
onDialogChange && onDialogChange({
|
|
1257
|
-
isOpen: false
|
|
1258
|
-
});
|
|
1259
|
-
};
|
|
1260
|
-
const onClick = composeEventHandlers(props.onClick, () => {
|
|
1261
|
-
if (referenceElement) {
|
|
1262
|
-
closeDialog();
|
|
1263
|
-
} else {
|
|
1264
|
-
openDialog();
|
|
1265
|
-
}
|
|
1266
|
-
});
|
|
1267
|
-
useEffect(() => {
|
|
1268
|
-
if (isDialogControlled) {
|
|
1269
|
-
if (isOpen) {
|
|
1270
|
-
setReferenceElement(buttonRef.current);
|
|
1271
|
-
} else {
|
|
1272
|
-
setReferenceElement(null);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
}, [isOpen, isDialogControlled]);
|
|
1276
|
-
return React__default.createElement(React__default.Fragment, null, children ? ( cloneElement(Children.only(children), {
|
|
1277
|
-
onClick,
|
|
1278
|
-
ref: buttonRef
|
|
1279
|
-
})) : React__default.createElement(StyledButton, _extends$2({
|
|
1280
|
-
disabled: disabled,
|
|
1281
|
-
focusInset: focusInset,
|
|
1282
|
-
ref: buttonRef,
|
|
1283
|
-
onClick: onClick
|
|
1284
|
-
}, buttonProps), React__default.createElement(StyledButtonPreview, {
|
|
1285
|
-
backgroundColor: isControlled ? color : uncontrolledColor
|
|
1286
|
-
}), React__default.createElement(Button.EndIcon, {
|
|
1287
|
-
isRotated: referenceElement != null
|
|
1288
|
-
}, React__default.createElement(SvgChevronDownStroke, null))), React__default.createElement(StyledTooltipModal, _extends$2({
|
|
1289
|
-
ref: ref,
|
|
1290
|
-
hasArrow: hasArrow,
|
|
1291
|
-
popperModifiers: popperModifiers,
|
|
1292
|
-
zIndex: zIndex,
|
|
1293
|
-
isAnimated: isAnimated,
|
|
1294
|
-
isOpaque: isOpaque,
|
|
1295
|
-
focusOnMount: false,
|
|
1296
|
-
placement: placement,
|
|
1297
|
-
referenceElement: referenceElement,
|
|
1298
|
-
onClose: () => {
|
|
1299
|
-
closeDialog();
|
|
1300
|
-
onClose && onClose(isControlled ? color : uncontrolledColor);
|
|
1301
|
-
},
|
|
1302
|
-
"aria-label": ariaLabelText
|
|
1303
|
-
}, props), React__default.createElement(StyledTooltipBody, null, React__default.createElement(Colorpicker, {
|
|
1304
|
-
autofocus: true,
|
|
1305
|
-
color: color,
|
|
1306
|
-
isOpaque: isOpaque,
|
|
1307
|
-
labels: labels,
|
|
1308
|
-
ref: colorPickerRef,
|
|
1309
|
-
defaultColor: uncontrolledColor,
|
|
1310
|
-
onChange: isControlled ? onChange : setUncontrolledColor
|
|
1311
|
-
}))));
|
|
1312
|
-
});
|
|
1313
|
-
ColorpickerDialog.propTypes = {
|
|
1314
|
-
...Colorpicker.propTypes,
|
|
1315
|
-
placement: PropTypes.oneOf(PLACEMENT),
|
|
1316
|
-
onClose: PropTypes.func,
|
|
1317
|
-
onDialogChange: PropTypes.func,
|
|
1318
|
-
disabled: PropTypes.bool,
|
|
1319
|
-
labels: PropTypes.object,
|
|
1320
|
-
buttonProps: PropTypes.object,
|
|
1321
|
-
popperModifiers: PropTypes.any,
|
|
1322
|
-
zIndex: PropTypes.number,
|
|
1323
|
-
hasArrow: PropTypes.bool,
|
|
1324
|
-
isAnimated: PropTypes.bool,
|
|
1325
|
-
isOpen: PropTypes.bool,
|
|
1326
|
-
focusInset: PropTypes.bool
|
|
1327
|
-
};
|
|
1328
|
-
ColorpickerDialog.defaultProps = {
|
|
1329
|
-
placement: 'bottom-start',
|
|
1330
|
-
isAnimated: true,
|
|
1331
|
-
zIndex: 1000,
|
|
1332
|
-
hasArrow: false
|
|
1333
|
-
};
|
|
1334
|
-
ColorpickerDialog.displayName = 'ColorpickerDialog';
|
|
1335
|
-
|
|
1336
|
-
var _path;
|
|
1337
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
1338
|
-
var SvgCheckSmFill = function SvgCheckSmFill(props) {
|
|
1339
|
-
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
1340
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1341
|
-
width: 12,
|
|
1342
|
-
height: 12,
|
|
1343
|
-
focusable: "false",
|
|
1344
|
-
viewBox: "0 0 12 12",
|
|
1345
|
-
"aria-hidden": "true"
|
|
1346
|
-
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
1347
|
-
fill: "none",
|
|
1348
|
-
stroke: "currentColor",
|
|
1349
|
-
strokeLinecap: "round",
|
|
1350
|
-
strokeLinejoin: "round",
|
|
1351
|
-
strokeWidth: 2,
|
|
1352
|
-
d: "M3 6l2 2 4-4"
|
|
1353
|
-
})));
|
|
1354
|
-
};
|
|
1355
|
-
|
|
1356
|
-
const ColorSwatch = forwardRef((_ref, ref) => {
|
|
1357
|
-
let {
|
|
1358
|
-
colors,
|
|
1359
|
-
...props
|
|
1360
|
-
} = _ref;
|
|
1361
|
-
const {
|
|
1362
|
-
rtl
|
|
1363
|
-
} = useContext(ThemeContext);
|
|
1364
|
-
const {
|
|
1365
|
-
getGridCellProps
|
|
1366
|
-
} = useGrid({
|
|
1367
|
-
rtl,
|
|
1368
|
-
matrix: colors,
|
|
1369
|
-
selection: true,
|
|
1370
|
-
wrap: true,
|
|
1371
|
-
idPrefix: useId(undefined),
|
|
1372
|
-
...props
|
|
1373
|
-
});
|
|
1374
|
-
return React__default.createElement(StyledColorSwatch, {
|
|
1375
|
-
ref: ref
|
|
1376
|
-
}, React__default.createElement("tbody", null, colors.map((row, rowIdx) => React__default.createElement("tr", {
|
|
1377
|
-
key: row[0].value
|
|
1378
|
-
}, row.map((color, colIdx) => {
|
|
1379
|
-
const {
|
|
1380
|
-
label,
|
|
1381
|
-
value
|
|
1382
|
-
} = color;
|
|
1383
|
-
const {
|
|
1384
|
-
'aria-selected': ariaSelected,
|
|
1385
|
-
...other
|
|
1386
|
-
} = getGridCellProps({
|
|
1387
|
-
colIdx,
|
|
1388
|
-
rowIdx,
|
|
1389
|
-
type: 'button',
|
|
1390
|
-
role: undefined
|
|
1391
|
-
});
|
|
1392
|
-
return React__default.createElement(StyledCell, {
|
|
1393
|
-
key: value,
|
|
1394
|
-
"aria-selected": ariaSelected
|
|
1395
|
-
}, React__default.createElement(Tooltip, {
|
|
1396
|
-
content: label
|
|
1397
|
-
}, React__default.createElement(StyledSwatchButton, _extends$2({
|
|
1398
|
-
backgroundColor: value,
|
|
1399
|
-
"aria-pressed": ariaSelected,
|
|
1400
|
-
"aria-label": label
|
|
1401
|
-
}, other), React__default.createElement(StyledIcon, {
|
|
1402
|
-
color: value,
|
|
1403
|
-
selected: ariaSelected
|
|
1404
|
-
}, React__default.createElement(SvgCheckSmFill, null)))));
|
|
1405
|
-
})))));
|
|
1406
|
-
});
|
|
1407
|
-
ColorSwatch.displayName = 'ColorSwatch';
|
|
1408
|
-
ColorSwatch.propTypes = {
|
|
1409
|
-
colors: PropTypes.arrayOf(PropTypes.any).isRequired,
|
|
1410
|
-
rowIndex: PropTypes.number,
|
|
1411
|
-
colIndex: PropTypes.number,
|
|
1412
|
-
selectedRowIndex: PropTypes.number,
|
|
1413
|
-
selectedColIndex: PropTypes.number,
|
|
1414
|
-
defaultRowIndex: PropTypes.number,
|
|
1415
|
-
defaultColIndex: PropTypes.number,
|
|
1416
|
-
defaultSelectedRowIndex: PropTypes.number,
|
|
1417
|
-
defaultSelectedColIndex: PropTypes.number,
|
|
1418
|
-
onChange: PropTypes.func,
|
|
1419
|
-
onSelect: PropTypes.func
|
|
1420
|
-
};
|
|
1421
|
-
|
|
1422
|
-
const ColorSwatchDialog = forwardRef((_ref, ref) => {
|
|
1423
|
-
let {
|
|
1424
|
-
colors,
|
|
1425
|
-
rowIndex,
|
|
1426
|
-
colIndex,
|
|
1427
|
-
selectedRowIndex,
|
|
1428
|
-
selectedColIndex,
|
|
1429
|
-
defaultRowIndex,
|
|
1430
|
-
defaultColIndex,
|
|
1431
|
-
defaultSelectedRowIndex,
|
|
1432
|
-
defaultSelectedColIndex,
|
|
1433
|
-
placement,
|
|
1434
|
-
onChange,
|
|
1435
|
-
onSelect,
|
|
1436
|
-
hasArrow,
|
|
1437
|
-
isAnimated,
|
|
1438
|
-
popperModifiers,
|
|
1439
|
-
zIndex,
|
|
1440
|
-
isOpen,
|
|
1441
|
-
focusInset,
|
|
1442
|
-
disabled,
|
|
1443
|
-
buttonProps,
|
|
1444
|
-
onDialogChange,
|
|
1445
|
-
children,
|
|
1446
|
-
'aria-label': ariaLabel,
|
|
1447
|
-
...props
|
|
1448
|
-
} = _ref;
|
|
1449
|
-
const controlledFocus = rowIndex !== null && colIndex !== null && rowIndex !== undefined && colIndex !== undefined;
|
|
1450
|
-
const controlledSelect = selectedRowIndex !== null && selectedColIndex !== null && selectedRowIndex !== undefined && selectedColIndex !== undefined;
|
|
1451
|
-
const isControlled = controlledFocus || controlledSelect;
|
|
1452
|
-
const isDialogControlled = isOpen !== undefined && isOpen !== null;
|
|
1453
|
-
const buttonRef = useRef(null);
|
|
1454
|
-
const colorSwatchRef = useRef(null);
|
|
1455
|
-
const [referenceElement, setReferenceElement] = useState();
|
|
1456
|
-
const [uncontrolledSelectedRowIndex, setUncontrolledSelectedRowIndex] = useState(defaultSelectedRowIndex || 0);
|
|
1457
|
-
const [uncontrolledSelectedColIndex, setUncontrolledSelectedColIndex] = useState(defaultSelectedColIndex || 0);
|
|
1458
|
-
const [uncontrolledRowIndex, setUncontrolledRowIndex] = useState(defaultRowIndex || 0);
|
|
1459
|
-
const [uncontrolledColIndex, setUncontrolledColIndex] = useState(defaultColIndex || 0);
|
|
1460
|
-
const ariaLabelText = useText(ColorSwatchDialog, {
|
|
1461
|
-
'aria-label': ariaLabel
|
|
1462
|
-
}, 'aria-label', 'Color swatch');
|
|
1463
|
-
useEffect(() => {
|
|
1464
|
-
if (isDialogControlled) {
|
|
1465
|
-
if (isOpen) {
|
|
1466
|
-
setReferenceElement(buttonRef.current);
|
|
1467
|
-
} else {
|
|
1468
|
-
setReferenceElement(null);
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
}, [isOpen, isDialogControlled]);
|
|
1472
|
-
let uncontrolledSelectedColor;
|
|
1473
|
-
let controlledSelectedColor;
|
|
1474
|
-
if (uncontrolledSelectedRowIndex > -1 && uncontrolledSelectedColIndex > -1) {
|
|
1475
|
-
uncontrolledSelectedColor = colors[uncontrolledSelectedRowIndex][uncontrolledSelectedColIndex];
|
|
1476
|
-
}
|
|
1477
|
-
if (selectedRowIndex !== undefined && selectedColIndex !== undefined && selectedRowIndex > -1 && selectedColIndex > -1) {
|
|
1478
|
-
controlledSelectedColor = colors[selectedRowIndex][selectedColIndex];
|
|
1479
|
-
}
|
|
1480
|
-
const openDialog = () => {
|
|
1481
|
-
setReferenceElement(buttonRef.current);
|
|
1482
|
-
onDialogChange && onDialogChange({
|
|
1483
|
-
isOpen: true
|
|
1484
|
-
});
|
|
1485
|
-
};
|
|
1486
|
-
const closeDialog = () => {
|
|
1487
|
-
setUncontrolledRowIndex(uncontrolledSelectedRowIndex);
|
|
1488
|
-
setUncontrolledColIndex(uncontrolledSelectedColIndex);
|
|
1489
|
-
setReferenceElement(null);
|
|
1490
|
-
onDialogChange && onDialogChange({
|
|
1491
|
-
isOpen: false
|
|
1492
|
-
});
|
|
1493
|
-
};
|
|
1494
|
-
const onClick = composeEventHandlers(props.onClick, () => {
|
|
1495
|
-
if (referenceElement) {
|
|
1496
|
-
closeDialog();
|
|
1497
|
-
} else {
|
|
1498
|
-
openDialog();
|
|
1499
|
-
}
|
|
1500
|
-
});
|
|
1501
|
-
useEffect(() => {
|
|
1502
|
-
if (referenceElement && colorSwatchRef.current) {
|
|
1503
|
-
const focusableButton = colorSwatchRef.current.querySelector('[tabindex="0"]');
|
|
1504
|
-
const selectedCell = colorSwatchRef.current.querySelector('[aria-selected="true"]');
|
|
1505
|
-
if (selectedCell) {
|
|
1506
|
-
selectedCell.children[0].focus();
|
|
1507
|
-
} else {
|
|
1508
|
-
focusableButton?.focus();
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
}, [referenceElement]);
|
|
1512
|
-
return React__default.createElement(React__default.Fragment, null, children ? ( cloneElement(Children.only(children), {
|
|
1513
|
-
onClick,
|
|
1514
|
-
ref: buttonRef
|
|
1515
|
-
})) : React__default.createElement(StyledButton, _extends$2({
|
|
1516
|
-
disabled: disabled,
|
|
1517
|
-
focusInset: focusInset,
|
|
1518
|
-
ref: buttonRef,
|
|
1519
|
-
onClick: onClick
|
|
1520
|
-
}, buttonProps), React__default.createElement(StyledButtonPreview, {
|
|
1521
|
-
backgroundColor: isControlled ? controlledSelectedColor?.value : uncontrolledSelectedColor?.value
|
|
1522
|
-
}), React__default.createElement(Button.EndIcon, {
|
|
1523
|
-
isRotated: referenceElement != null
|
|
1524
|
-
}, React__default.createElement(SvgChevronDownStroke, null))), React__default.createElement(StyledTooltipModal, _extends$2({
|
|
1525
|
-
ref: ref,
|
|
1526
|
-
zIndex: zIndex,
|
|
1527
|
-
hasArrow: hasArrow,
|
|
1528
|
-
focusOnMount: false,
|
|
1529
|
-
placement: placement,
|
|
1530
|
-
isAnimated: isAnimated,
|
|
1531
|
-
popperModifiers: popperModifiers,
|
|
1532
|
-
referenceElement: referenceElement,
|
|
1533
|
-
onClose: closeDialog,
|
|
1534
|
-
"aria-label": ariaLabelText
|
|
1535
|
-
}, props), React__default.createElement(StyledTooltipBody, null, React__default.createElement(ColorSwatch, {
|
|
1536
|
-
colors: colors,
|
|
1537
|
-
ref: colorSwatchRef,
|
|
1538
|
-
rowIndex: rowIndex,
|
|
1539
|
-
colIndex: colIndex,
|
|
1540
|
-
selectedRowIndex: selectedRowIndex,
|
|
1541
|
-
selectedColIndex: selectedColIndex,
|
|
1542
|
-
defaultRowIndex: uncontrolledRowIndex,
|
|
1543
|
-
defaultColIndex: uncontrolledColIndex,
|
|
1544
|
-
defaultSelectedRowIndex: uncontrolledSelectedRowIndex,
|
|
1545
|
-
defaultSelectedColIndex: uncontrolledSelectedColIndex,
|
|
1546
|
-
onChange: (rowIdx, colIdx) => {
|
|
1547
|
-
if (isControlled === false) {
|
|
1548
|
-
setUncontrolledRowIndex(rowIdx);
|
|
1549
|
-
setUncontrolledColIndex(colIdx);
|
|
1550
|
-
}
|
|
1551
|
-
onChange && onChange(rowIdx, colIdx);
|
|
1552
|
-
},
|
|
1553
|
-
onSelect: (rowIdx, colIdx) => {
|
|
1554
|
-
if (isControlled === false) {
|
|
1555
|
-
setUncontrolledSelectedRowIndex(rowIdx);
|
|
1556
|
-
setUncontrolledSelectedColIndex(colIdx);
|
|
1557
|
-
}
|
|
1558
|
-
onSelect && onSelect(rowIdx, colIdx);
|
|
1559
|
-
}
|
|
1560
|
-
}))));
|
|
1561
|
-
});
|
|
1562
|
-
ColorSwatchDialog.propTypes = {
|
|
1563
|
-
...ColorSwatch.propTypes,
|
|
1564
|
-
placement: PropTypes.oneOf(PLACEMENT),
|
|
1565
|
-
onDialogChange: PropTypes.func,
|
|
1566
|
-
disabled: PropTypes.bool,
|
|
1567
|
-
buttonProps: PropTypes.object,
|
|
1568
|
-
popperModifiers: PropTypes.any,
|
|
1569
|
-
zIndex: PropTypes.number,
|
|
1570
|
-
hasArrow: PropTypes.bool,
|
|
1571
|
-
isAnimated: PropTypes.bool,
|
|
1572
|
-
focusInset: PropTypes.bool,
|
|
1573
|
-
isOpen: PropTypes.bool
|
|
1574
|
-
};
|
|
1575
|
-
ColorSwatchDialog.defaultProps = {
|
|
1576
|
-
placement: 'bottom-start',
|
|
1577
|
-
isAnimated: true,
|
|
1578
|
-
zIndex: 1000,
|
|
1579
|
-
hasArrow: false
|
|
1580
|
-
};
|
|
1581
|
-
ColorSwatchDialog.displayName = 'ColorSwatchDialog';
|
|
1582
|
-
|
|
1583
|
-
export { ColorSwatch, ColorSwatchDialog, Colorpicker, ColorpickerDialog };
|