@zendeskgarden/react-colorpickers 9.0.0-next.2 → 9.0.0-next.21
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/README.md +72 -2
- package/dist/esm/elements/ColorPicker/ColorWell.js +110 -0
- package/dist/esm/elements/ColorPicker/index.js +237 -0
- package/dist/esm/elements/ColorPicker/reducer.js +275 -0
- package/dist/esm/elements/ColorPickerDialog/index.js +153 -0
- package/dist/esm/elements/ColorSwatch/index.js +149 -0
- package/dist/esm/elements/ColorSwatchDialog/index.js +179 -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/ColorPicker/StyledAlphaRange.js +42 -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 +51 -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 +39 -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 +45 -0
- package/dist/esm/styled/ColorPickerDialog/StyledButton.js +22 -0
- package/dist/esm/styled/ColorPickerDialog/StyledButtonPreview.js +52 -0
- package/dist/esm/styled/ColorPickerDialog/StyledTooltipBody.js +23 -0
- package/dist/esm/styled/ColorPickerDialog/StyledTooltipModal.js +23 -0
- package/dist/esm/styled/ColorSwatch/StyledCell.js +22 -0
- package/dist/esm/styled/ColorSwatch/StyledColorSwatch.js +22 -0
- package/dist/esm/styled/ColorSwatch/StyledColorSwatchInput.js +22 -0
- package/dist/esm/styled/ColorSwatch/StyledColorSwatchLabel.js +53 -0
- package/dist/esm/styled/ColorSwatch/StyledIcon.js +24 -0
- package/dist/esm/styled/common/StyledRange.js +160 -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 +267 -243
- package/dist/typings/elements/{Colorpicker → ColorPicker}/index.d.ts +2 -2
- package/dist/typings/elements/{ColorpickerDialog → ColorPickerDialog}/index.d.ts +2 -2
- package/dist/typings/index.d.ts +3 -3
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledAlphaRange.d.ts +2 -2
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledColorPicker.d.ts +1 -1
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledColorWell.d.ts +1 -1
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledPreview.d.ts +3 -3
- package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledSliders.d.ts +3 -2
- package/dist/typings/styled/{ColorpickerDialog → ColorPickerDialog}/StyledButton.d.ts +0 -1
- package/dist/typings/styled/{ColorpickerDialog → ColorPickerDialog}/StyledButtonPreview.d.ts +2 -2
- package/dist/typings/styled/ColorSwatch/StyledColorSwatchLabel.d.ts +3 -3
- package/dist/typings/styled/common/StyledRange.d.ts +2 -2
- package/dist/typings/styled/index.d.ts +17 -17
- package/dist/typings/styled/types.d.ts +12 -0
- package/dist/typings/types/index.d.ts +2 -2
- package/package.json +12 -12
- package/dist/index.esm.js +0 -1612
- package/dist/typings/styled/common/checkeredBackground.d.ts +0 -8
- /package/dist/typings/elements/{Colorpicker → ColorPicker}/ColorWell.d.ts +0 -0
- /package/dist/typings/elements/{Colorpicker → ColorPicker}/reducer.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledColorWellThumb.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledHexField.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledHueRange.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledInput.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledInputGroup.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledLabel.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledRGBAField.d.ts +0 -0
- /package/dist/typings/styled/{Colorpicker → ColorPicker}/StyledSliderGroup.d.ts +0 -0
- /package/dist/typings/styled/{ColorpickerDialog → ColorPickerDialog}/StyledTooltipBody.d.ts +0 -0
- /package/dist/typings/styled/{ColorpickerDialog → ColorPickerDialog}/StyledTooltipModal.d.ts +0 -0
|
@@ -0,0 +1,160 @@
|
|
|
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
|
+
import { Range } from '@zendeskgarden/react-forms';
|
|
8
|
+
import styled from 'styled-components';
|
|
9
|
+
import { stripUnit } from 'polished';
|
|
10
|
+
import { retrieveComponentStyles, DEFAULT_THEME, getColor } from '@zendeskgarden/react-theming';
|
|
11
|
+
|
|
12
|
+
const COMPONENT_ID = 'colorpickers.colorpicker_range';
|
|
13
|
+
const thumbStyles = function (styles) {
|
|
14
|
+
let modifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
15
|
+
return `
|
|
16
|
+
&${modifier}::-moz-range-thumb {
|
|
17
|
+
${styles}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&${modifier}::-ms-thumb {
|
|
21
|
+
${styles}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&${modifier}::-webkit-slider-thumb {
|
|
25
|
+
${styles}
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
};
|
|
29
|
+
const trackStyles = function (styles) {
|
|
30
|
+
let modifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
31
|
+
return `
|
|
32
|
+
&${modifier}::-moz-range-track {
|
|
33
|
+
${styles}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&${modifier}::-ms-track {
|
|
37
|
+
${styles}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&${modifier}::-webkit-slider-runnable-track {
|
|
41
|
+
${styles}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
};
|
|
45
|
+
const trackLowerStyles = function (styles) {
|
|
46
|
+
let modifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
47
|
+
return `
|
|
48
|
+
&${modifier}::-moz-range-progress {
|
|
49
|
+
${styles}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&${modifier}::-ms-fill-lower {
|
|
53
|
+
${styles}
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
};
|
|
57
|
+
const colorStyles = _ref => {
|
|
58
|
+
let {
|
|
59
|
+
theme
|
|
60
|
+
} = _ref;
|
|
61
|
+
const thumbBackgroundColor = getColor({
|
|
62
|
+
theme,
|
|
63
|
+
variable: 'background.default'
|
|
64
|
+
});
|
|
65
|
+
const thumbBorderColor = getColor({
|
|
66
|
+
theme,
|
|
67
|
+
variable: 'border.default',
|
|
68
|
+
dark: {
|
|
69
|
+
offset: -100
|
|
70
|
+
},
|
|
71
|
+
light: {
|
|
72
|
+
offset: 100
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const thumbActiveBackgroundColor = thumbBackgroundColor;
|
|
76
|
+
const thumbActiveBorderColor = getColor({
|
|
77
|
+
theme,
|
|
78
|
+
variable: 'border.primaryEmphasis'
|
|
79
|
+
});
|
|
80
|
+
const thumbFocusBorderColor = thumbActiveBorderColor;
|
|
81
|
+
const thumbHoverBackgroundColor = getColor({
|
|
82
|
+
theme,
|
|
83
|
+
variable: 'background.subtle'
|
|
84
|
+
});
|
|
85
|
+
const thumbHoverBorderColor = thumbActiveBorderColor;
|
|
86
|
+
return `
|
|
87
|
+
${trackStyles(`
|
|
88
|
+
background-color: transparent;
|
|
89
|
+
`)}
|
|
90
|
+
|
|
91
|
+
${thumbStyles(`
|
|
92
|
+
border-color: ${thumbBorderColor};
|
|
93
|
+
background-color: ${thumbBackgroundColor};
|
|
94
|
+
`)}
|
|
95
|
+
|
|
96
|
+
${trackLowerStyles(`
|
|
97
|
+
background-color: transparent;
|
|
98
|
+
`)}
|
|
99
|
+
|
|
100
|
+
${thumbStyles(`
|
|
101
|
+
border-color: ${thumbHoverBorderColor};
|
|
102
|
+
background-color: ${thumbHoverBackgroundColor};
|
|
103
|
+
`, ':hover')}
|
|
104
|
+
|
|
105
|
+
${thumbStyles(`
|
|
106
|
+
background-color: ${thumbBackgroundColor};
|
|
107
|
+
border-color: ${thumbFocusBorderColor};
|
|
108
|
+
`, ':focus-visible')}
|
|
109
|
+
|
|
110
|
+
${thumbStyles(`
|
|
111
|
+
border-color: ${thumbActiveBorderColor};
|
|
112
|
+
background-color: ${thumbActiveBackgroundColor}
|
|
113
|
+
`, ':active')}
|
|
114
|
+
`;
|
|
115
|
+
};
|
|
116
|
+
const getThumbSize = props => props.theme.space.base * (props.$isOpaque ? 6 : 4);
|
|
117
|
+
const getTrackHeight = props => props.theme.space.base * (props.$isOpaque ? 6 : 3);
|
|
118
|
+
const getTrackMargin = props => (getThumbSize(props) - getTrackHeight(props)) / 2 + stripUnit(props.theme.shadowWidths.md);
|
|
119
|
+
const sizeStyles = props => {
|
|
120
|
+
const thumbSize = getThumbSize(props);
|
|
121
|
+
const trackHeight = getTrackHeight(props);
|
|
122
|
+
const trackMargin = getTrackMargin(props);
|
|
123
|
+
const thumbMargin = (trackHeight - thumbSize) / 2;
|
|
124
|
+
const trackOffset = props.theme.space.base * (props.$isOpaque ? -2 : -1);
|
|
125
|
+
const height = props.$isOpaque ? trackHeight : trackMargin * 2 + trackHeight;
|
|
126
|
+
return `
|
|
127
|
+
/* stylelint-disable-next-line declaration-no-important */
|
|
128
|
+
margin-top: 0 !important;
|
|
129
|
+
height: ${height}px; /* [1] */
|
|
130
|
+
box-sizing: content-box; /* [2] */
|
|
131
|
+
border-radius: ${props.$isOpaque && props.theme.borderRadii.md};
|
|
132
|
+
|
|
133
|
+
${trackStyles(`
|
|
134
|
+
margin: ${trackMargin}px ${trackOffset}px;
|
|
135
|
+
height: ${trackHeight}px;
|
|
136
|
+
`)}
|
|
137
|
+
|
|
138
|
+
${thumbStyles(`
|
|
139
|
+
margin: ${thumbMargin}px 0;
|
|
140
|
+
border-width: ${props.theme.borderWidths.sm};
|
|
141
|
+
height: ${thumbSize}px;
|
|
142
|
+
width: ${thumbSize}px;
|
|
143
|
+
`)};
|
|
144
|
+
`;
|
|
145
|
+
};
|
|
146
|
+
const StyledRange = styled(Range).attrs({
|
|
147
|
+
'data-garden-id': COMPONENT_ID,
|
|
148
|
+
'data-garden-version': '9.0.0-next.21',
|
|
149
|
+
hasLowerTrack: false
|
|
150
|
+
}).withConfig({
|
|
151
|
+
displayName: "StyledRange",
|
|
152
|
+
componentId: "sc-ug3wi9-0"
|
|
153
|
+
})(["", ";", " ", ";", ";"], sizeStyles, trackStyles(`
|
|
154
|
+
border-radius: 0;
|
|
155
|
+
`), colorStyles, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
156
|
+
StyledRange.defaultProps = {
|
|
157
|
+
theme: DEFAULT_THEME
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export { StyledRange, getTrackHeight, getTrackMargin, trackStyles };
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
function hslToHsv(h, s, l) {
|
|
8
|
+
let saturation = s;
|
|
9
|
+
saturation *= (l < 50 ? l : 100 - l) / 100;
|
|
10
|
+
const v = l + saturation;
|
|
11
|
+
return {
|
|
12
|
+
h,
|
|
13
|
+
s: v === 0 ? 0 : 2 * saturation / v * 100,
|
|
14
|
+
v
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function hsvToHsl(h, s, v) {
|
|
18
|
+
let saturation = s;
|
|
19
|
+
let value = v;
|
|
20
|
+
saturation /= 100;
|
|
21
|
+
value /= 100;
|
|
22
|
+
let l = (2 - saturation) * value;
|
|
23
|
+
let sl = saturation * value;
|
|
24
|
+
sl /= l <= 1 ? l : 2 - l;
|
|
25
|
+
sl = sl || 0;
|
|
26
|
+
l /= 2;
|
|
27
|
+
return {
|
|
28
|
+
h,
|
|
29
|
+
s: sl * 100,
|
|
30
|
+
l: l * 100
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { hslToHsv, hsvToHsl };
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
const getSaturationLightness = (element, x, y, rtl) => {
|
|
8
|
+
const {
|
|
9
|
+
width,
|
|
10
|
+
height
|
|
11
|
+
} = element.getBoundingClientRect();
|
|
12
|
+
let left = x - (element.getBoundingClientRect().left + window.pageXOffset);
|
|
13
|
+
let top = y - (element.getBoundingClientRect().top + window.pageYOffset);
|
|
14
|
+
if (left < 0) {
|
|
15
|
+
left = 0;
|
|
16
|
+
} else if (left > width) {
|
|
17
|
+
left = width;
|
|
18
|
+
}
|
|
19
|
+
if (top < 0) {
|
|
20
|
+
top = 0;
|
|
21
|
+
} else if (top > height) {
|
|
22
|
+
top = height;
|
|
23
|
+
}
|
|
24
|
+
if (rtl) {
|
|
25
|
+
left = width - left;
|
|
26
|
+
}
|
|
27
|
+
const saturation = left / width;
|
|
28
|
+
const bright = 1 - top / height;
|
|
29
|
+
return {
|
|
30
|
+
saturation,
|
|
31
|
+
bright
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
function getNextHsv(e, hue, container, rtl) {
|
|
35
|
+
const {
|
|
36
|
+
saturation,
|
|
37
|
+
bright
|
|
38
|
+
} = getSaturationLightness(container, e.pageX, e.pageY, rtl);
|
|
39
|
+
return {
|
|
40
|
+
h: hue,
|
|
41
|
+
s: saturation,
|
|
42
|
+
v: bright
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const getThumbPosition = (x, y, rtl, container) => {
|
|
46
|
+
if (container.current) {
|
|
47
|
+
const {
|
|
48
|
+
saturation,
|
|
49
|
+
bright
|
|
50
|
+
} = getSaturationLightness(container.current, x, y, rtl);
|
|
51
|
+
const topFromMouse = (1 - bright) * 100;
|
|
52
|
+
const leftFromMouse = rtl ? 100 - saturation * 100 : saturation * 100;
|
|
53
|
+
return {
|
|
54
|
+
topFromMouse,
|
|
55
|
+
leftFromMouse
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
topFromMouse: 0,
|
|
60
|
+
leftFromMouse: 0
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { getNextHsv, getThumbPosition };
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
const isValidHex = hexString => {
|
|
8
|
+
const regEx = /^#(?:(?:[0-9A-F]{6}(?:[0-9A-F]{2})?)|(?:[0-9A-F]{3})(?:[0-9A-F]?))$/iu;
|
|
9
|
+
return regEx.test(hexString);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { isValidHex };
|