@synerise/ds-color-picker 0.1.7 → 0.2.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/CHANGELOG.md +27 -0
- package/dist/ColorPicker.d.ts +1 -1
- package/dist/ColorPicker.js +106 -47
- package/dist/ColorPicker.styles.d.ts +8 -0
- package/dist/ColorPicker.styles.js +21 -12
- package/dist/ColorPicker.types.d.ts +4 -3
- package/dist/ColorPicker.types.js +3 -3
- package/dist/utils.d.ts +21 -0
- package/dist/utils.js +58 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.2.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-color-picker@0.1.8...@synerise/ds-color-picker@0.2.0) (2023-02-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **color-picker:** color change logic separately for each input ([8eefaf0](https://github.com/Synerise/synerise-design/commit/8eefaf0b5028b4b916110d554f06b025bd2cdf45))
|
|
12
|
+
* **color-picker:** color change logic separately for each input ([54283f7](https://github.com/Synerise/synerise-design/commit/54283f7ab79b0da75ef78e26671a8ad675b04f44))
|
|
13
|
+
* **color-picker:** descriptions of methods and names ([45be774](https://github.com/Synerise/synerise-design/commit/45be774dff8bd50b6b201dbfed0a2d1d09a2b1a8))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [0.1.8](https://github.com/Synerise/synerise-design/compare/@synerise/ds-color-picker@0.1.7...@synerise/ds-color-picker@0.1.8) (2023-01-30)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* **color-picker:** bugs ([9702cad](https://github.com/Synerise/synerise-design/commit/9702cada1d33b94275681b905cba291684cf7732))
|
|
25
|
+
* **color-picker:** main wrapper for the color-picker component ([6c3ad7e](https://github.com/Synerise/synerise-design/commit/6c3ad7ea4d1b2a4a089a0494126a2f12962588df))
|
|
26
|
+
* **color-picker:** max-width of dropdown overlay ([42d2f60](https://github.com/Synerise/synerise-design/commit/42d2f60a7be3f63d486c8f27029f5602650fe1c7))
|
|
27
|
+
* **color-picker:** utils for colorPicker component ([d78395d](https://github.com/Synerise/synerise-design/commit/d78395d29b366f2a3edf06edc83351865e7bb875))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
## [0.1.7](https://github.com/Synerise/synerise-design/compare/@synerise/ds-color-picker@0.1.6...@synerise/ds-color-picker@0.1.7) (2023-01-12)
|
|
7
34
|
|
|
8
35
|
**Note:** Version bump only for package @synerise/ds-color-picker
|
package/dist/ColorPicker.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ColorPickerProps } from './ColorPicker.types';
|
|
3
|
-
|
|
3
|
+
declare const ColorPicker: ({ maxWidth, value, onChange, colors, onSaveColors, infix, placeholder, inputProps, maxSavedColors, tooltipText, isShownSavedColors, size, errorText, description, }: ColorPickerProps) => JSX.Element;
|
|
4
4
|
export default ColorPicker;
|
package/dist/ColorPicker.js
CHANGED
|
@@ -9,10 +9,14 @@ import * as copy from 'copy-to-clipboard';
|
|
|
9
9
|
import Tooltip from '@synerise/ds-tooltip';
|
|
10
10
|
import Dropdown from '@synerise/ds-dropdown';
|
|
11
11
|
import { useOnClickOutside } from '@synerise/ds-utils';
|
|
12
|
+
import { isValidHexColor, isValidTextColor, convert3DigitHexTo6Digit, filterAlphanumeric, standardizeColor } from './utils';
|
|
12
13
|
import ColorPickerStyles from './ColorPicker.styles';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
var DEFAULT_MAX_WIDTH_PICKER = 228;
|
|
15
|
+
var DEFAULT_COLOR = '#ffffff';
|
|
16
|
+
|
|
17
|
+
var ColorPicker = function ColorPicker(_ref) {
|
|
18
|
+
var maxWidth = _ref.maxWidth,
|
|
19
|
+
value = _ref.value,
|
|
16
20
|
onChange = _ref.onChange,
|
|
17
21
|
_ref$colors = _ref.colors,
|
|
18
22
|
colors = _ref$colors === void 0 ? [] : _ref$colors,
|
|
@@ -33,18 +37,80 @@ export function ColorPicker(_ref) {
|
|
|
33
37
|
description = _ref.description;
|
|
34
38
|
|
|
35
39
|
var _React$useState = React.useState(value),
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
colorTextInput = _React$useState[0],
|
|
41
|
+
setColorTextInput = _React$useState[1];
|
|
38
42
|
|
|
39
|
-
var _React$useState2 = React.useState(
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
var _React$useState2 = React.useState(value),
|
|
44
|
+
colorHexInput = _React$useState2[0],
|
|
45
|
+
setColorHexInput = _React$useState2[1];
|
|
42
46
|
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
var _React$useState3 = React.useState(value),
|
|
48
|
+
lastValidTextColor = _React$useState3[0],
|
|
49
|
+
setLastValidTextColor = _React$useState3[1];
|
|
50
|
+
|
|
51
|
+
var _React$useState4 = React.useState(value),
|
|
52
|
+
lastValidHexColor = _React$useState4[0],
|
|
53
|
+
setLastValidHexColor = _React$useState4[1];
|
|
54
|
+
|
|
55
|
+
var _React$useState5 = React.useState(-1),
|
|
56
|
+
pressed = _React$useState5[0],
|
|
57
|
+
setPressed = _React$useState5[1];
|
|
58
|
+
|
|
59
|
+
var _React$useState6 = React.useState(false),
|
|
60
|
+
dropdownVisible = _React$useState6[0],
|
|
61
|
+
setDropdownVisible = _React$useState6[1];
|
|
62
|
+
|
|
63
|
+
var _React$useState7 = React.useState(colors),
|
|
64
|
+
savedColors = _React$useState7[0],
|
|
65
|
+
setSavedColors = _React$useState7[1];
|
|
66
|
+
|
|
67
|
+
React.useEffect(function () {
|
|
68
|
+
if (lastValidHexColor) {
|
|
69
|
+
onChange && onChange(lastValidHexColor);
|
|
70
|
+
}
|
|
71
|
+
}, [onChange, lastValidHexColor]);
|
|
72
|
+
var onChangeTextColor = React.useCallback(function (colorValue) {
|
|
73
|
+
setColorTextInput(colorValue);
|
|
74
|
+
|
|
75
|
+
if (isValidTextColor(colorValue)) {
|
|
76
|
+
var standardizedColor = standardizeColor(colorValue);
|
|
77
|
+
setLastValidTextColor(colorValue);
|
|
78
|
+
setColorHexInput(standardizedColor);
|
|
79
|
+
setLastValidHexColor(standardizedColor);
|
|
80
|
+
} else if (isValidHexColor(colorValue)) {
|
|
81
|
+
var fullHexColor = convert3DigitHexTo6Digit(colorValue);
|
|
82
|
+
setLastValidTextColor(fullHexColor);
|
|
83
|
+
setColorHexInput(fullHexColor);
|
|
84
|
+
setLastValidHexColor(fullHexColor);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setPressed(-1);
|
|
88
|
+
}, []);
|
|
89
|
+
var onChangeHexColor = React.useCallback(function (colorValue) {
|
|
90
|
+
setColorHexInput(colorValue);
|
|
47
91
|
|
|
92
|
+
if (isValidHexColor(colorValue)) {
|
|
93
|
+
var fullHexColor = convert3DigitHexTo6Digit(colorValue);
|
|
94
|
+
setColorTextInput(fullHexColor);
|
|
95
|
+
setLastValidTextColor(fullHexColor);
|
|
96
|
+
setLastValidHexColor(fullHexColor);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
setPressed(-1);
|
|
100
|
+
}, []);
|
|
101
|
+
var onBlurHandler = React.useCallback(function () {
|
|
102
|
+
setColorTextInput(lastValidTextColor);
|
|
103
|
+
setColorHexInput(lastValidHexColor);
|
|
104
|
+
}, [lastValidHexColor, lastValidTextColor]);
|
|
105
|
+
var onClickHandler = React.useCallback(function () {
|
|
106
|
+
setDropdownVisible(!dropdownVisible);
|
|
107
|
+
}, [dropdownVisible]);
|
|
108
|
+
React.useEffect(function () {
|
|
109
|
+
if (!value || !isValidTextColor(value) || !isValidHexColor(value)) {
|
|
110
|
+
onChangeTextColor(DEFAULT_COLOR);
|
|
111
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
|
+
|
|
113
|
+
}, []);
|
|
48
114
|
var heightOfDropdown = React.useCallback(function () {
|
|
49
115
|
if (errorText || description) {
|
|
50
116
|
if (errorText && description) {
|
|
@@ -56,25 +122,14 @@ export function ColorPicker(_ref) {
|
|
|
56
122
|
|
|
57
123
|
return 4;
|
|
58
124
|
}, [errorText, description]);
|
|
59
|
-
|
|
60
|
-
var _React$useState3 = React.useState(false),
|
|
61
|
-
dropdownVisible = _React$useState3[0],
|
|
62
|
-
setDropdownVisible = _React$useState3[1];
|
|
63
|
-
|
|
64
125
|
var ref = React.useRef(null);
|
|
65
126
|
useOnClickOutside(ref, function () {
|
|
66
127
|
setDropdownVisible(false);
|
|
67
128
|
});
|
|
68
129
|
|
|
69
|
-
var _React$useState4 = React.useState(colors),
|
|
70
|
-
savedColors = _React$useState4[0],
|
|
71
|
-
setSavedColors = _React$useState4[1];
|
|
72
|
-
|
|
73
|
-
var hash = '#';
|
|
74
|
-
|
|
75
130
|
var saveColor = function saveColor() {
|
|
76
131
|
setSavedColors(function (ar) {
|
|
77
|
-
var colorsArray = (
|
|
132
|
+
var colorsArray = (lastValidHexColor ? [lastValidHexColor].concat(ar) : ar).slice(0, maxSavedColors);
|
|
78
133
|
onSaveColors && onSaveColors(colorsArray);
|
|
79
134
|
return colorsArray;
|
|
80
135
|
});
|
|
@@ -90,8 +145,8 @@ export function ColorPicker(_ref) {
|
|
|
90
145
|
size: 16,
|
|
91
146
|
component: /*#__PURE__*/React.createElement(FormulaPlusM, null)
|
|
92
147
|
}))), infix({
|
|
93
|
-
color:
|
|
94
|
-
setColor:
|
|
148
|
+
color: colorTextInput,
|
|
149
|
+
setColor: onChangeTextColor
|
|
95
150
|
}), savedColors.length > 0 && /*#__PURE__*/React.createElement(Tags, {
|
|
96
151
|
tagShape: TagShape.SINGLE_CHARACTER_SQUARE // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
97
152
|
// @ts-ignore
|
|
@@ -107,43 +162,46 @@ export function ColorPicker(_ref) {
|
|
|
107
162
|
})),
|
|
108
163
|
color: colorEntry,
|
|
109
164
|
onClick: function onClick() {
|
|
110
|
-
|
|
165
|
+
onChangeHexColor(colorEntry);
|
|
111
166
|
setPressed(i);
|
|
112
167
|
}
|
|
113
168
|
};
|
|
114
|
-
})
|
|
115
|
-
disabled: false
|
|
169
|
+
})
|
|
116
170
|
}));
|
|
117
171
|
var dropdown = /*#__PURE__*/React.createElement(ColorPickerStyles.Container, {
|
|
118
172
|
ref: ref,
|
|
119
173
|
size: size
|
|
120
174
|
}, /*#__PURE__*/React.createElement(ReactColorful, {
|
|
121
|
-
color:
|
|
122
|
-
onChange:
|
|
175
|
+
color: lastValidHexColor,
|
|
176
|
+
onChange: onChangeHexColor
|
|
123
177
|
}), /*#__PURE__*/React.createElement(ColorPickerStyles.PrefixTag, {
|
|
124
|
-
height: isShownSavedColors
|
|
178
|
+
height: isShownSavedColors,
|
|
179
|
+
size: size
|
|
125
180
|
}, /*#__PURE__*/React.createElement(Tag, {
|
|
126
181
|
shape: TagShape.SINGLE_CHARACTER_SQUARE,
|
|
127
|
-
color:
|
|
128
|
-
disabled: false
|
|
182
|
+
color: lastValidHexColor
|
|
129
183
|
})), /*#__PURE__*/React.createElement(ColorPickerStyles.SubContainer, {
|
|
130
184
|
savedColors: isShownSavedColors
|
|
131
185
|
}, /*#__PURE__*/React.createElement(ColorPickerStyles.ColorPickerInput, {
|
|
132
|
-
value:
|
|
186
|
+
value: colorHexInput && filterAlphanumeric(colorHexInput),
|
|
133
187
|
prefixel: /*#__PURE__*/React.createElement(ColorPickerStyles.PreffixWrapper, null, "#"),
|
|
134
188
|
onChange: function onChange(ev) {
|
|
135
|
-
|
|
189
|
+
onChangeHexColor("#" + ev.target.value);
|
|
136
190
|
},
|
|
191
|
+
onBlur: onBlurHandler,
|
|
137
192
|
placeholder: placeholder,
|
|
138
193
|
icon1: /*#__PURE__*/React.createElement(ColorPickerStyles.CopyIcon, {
|
|
139
194
|
onClick: function onClick() {
|
|
140
|
-
copy(
|
|
195
|
+
lastValidHexColor && copy(lastValidHexColor);
|
|
141
196
|
},
|
|
142
197
|
component: /*#__PURE__*/React.createElement(CopyClipboardM, null)
|
|
143
198
|
}),
|
|
144
|
-
icon1Tooltip: /*#__PURE__*/React.createElement("span", null, tooltipText)
|
|
199
|
+
icon1Tooltip: /*#__PURE__*/React.createElement("span", null, tooltipText || 'Copy to clipboard')
|
|
145
200
|
}), isShownSavedColors && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Divider, null), swatchSection)));
|
|
146
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(
|
|
201
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, maxWidth && maxWidth >= DEFAULT_MAX_WIDTH_PICKER && /*#__PURE__*/React.createElement(ColorPickerStyles.ColorPickerModalStyle, {
|
|
202
|
+
maxWidth: maxWidth
|
|
203
|
+
}), /*#__PURE__*/React.createElement(Dropdown, {
|
|
204
|
+
overlayClassName: "color-picker-overlay",
|
|
147
205
|
align: {
|
|
148
206
|
offset: [0, heightOfDropdown()]
|
|
149
207
|
},
|
|
@@ -153,19 +211,20 @@ export function ColorPicker(_ref) {
|
|
|
153
211
|
}, /*#__PURE__*/React.createElement(ColorPickerStyles.ColorPickerSelect, _extends({
|
|
154
212
|
prefix: /*#__PURE__*/React.createElement(ColorPickerStyles.ColorTag, {
|
|
155
213
|
shape: TagShape.SINGLE_CHARACTER_ROUND,
|
|
156
|
-
color:
|
|
157
|
-
disabled: false
|
|
214
|
+
color: lastValidHexColor,
|
|
215
|
+
disabled: false,
|
|
216
|
+
onClick: onClickHandler
|
|
158
217
|
}),
|
|
218
|
+
onClick: onClickHandler,
|
|
159
219
|
onChange: function onChange(ev) {
|
|
160
|
-
|
|
220
|
+
onChangeTextColor(ev.target.value);
|
|
161
221
|
},
|
|
222
|
+
onBlur: onBlurHandler,
|
|
162
223
|
placeholder: placeholder,
|
|
163
|
-
|
|
164
|
-
return setDropdownVisible(!dropdownVisible);
|
|
165
|
-
},
|
|
166
|
-
value: color,
|
|
224
|
+
value: colorTextInput,
|
|
167
225
|
description: description,
|
|
168
226
|
errorText: errorText
|
|
169
227
|
}, inputProps))));
|
|
170
|
-
}
|
|
228
|
+
};
|
|
229
|
+
|
|
171
230
|
export default ColorPicker;
|
|
@@ -38,10 +38,14 @@ export declare const ColorPickerSelect: import("styled-components").StyledCompon
|
|
|
38
38
|
}), any, {}, never>;
|
|
39
39
|
export declare const PrefixTag: import("styled-components").StyledComponent<"div", any, {
|
|
40
40
|
height?: boolean | undefined;
|
|
41
|
+
size?: "S" | "M" | "L" | undefined;
|
|
41
42
|
}, never>;
|
|
42
43
|
export declare const SwatchSectionWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
43
44
|
export declare const PreffixWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
44
45
|
export declare const ValueWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
46
|
+
export declare const ColorPickerModalStyle: import("styled-components").GlobalStyleComponent<{
|
|
47
|
+
maxWidth: number;
|
|
48
|
+
}, import("styled-components").DefaultTheme>;
|
|
45
49
|
declare const _default: {
|
|
46
50
|
Container: import("styled-components").StyledComponent<"div", any, {
|
|
47
51
|
size?: "S" | "M" | "L" | undefined;
|
|
@@ -52,6 +56,7 @@ declare const _default: {
|
|
|
52
56
|
ColorTag: import("styled-components").StyledComponent<import("react").FC<import("@synerise/ds-tags/dist/Tag/Tag.types").Props>, any, {}, never>;
|
|
53
57
|
PrefixTag: import("styled-components").StyledComponent<"div", any, {
|
|
54
58
|
height?: boolean | undefined;
|
|
59
|
+
size?: "S" | "M" | "L" | undefined;
|
|
55
60
|
}, never>;
|
|
56
61
|
AddColorButton: import("styled-components").StyledComponent<typeof Button, any, {}, never>;
|
|
57
62
|
SwatchSectionWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -91,5 +96,8 @@ declare const _default: {
|
|
|
91
96
|
})> & {
|
|
92
97
|
displayName: string;
|
|
93
98
|
}), any, {}, never>;
|
|
99
|
+
ColorPickerModalStyle: import("styled-components").GlobalStyleComponent<{
|
|
100
|
+
maxWidth: number;
|
|
101
|
+
}, import("styled-components").DefaultTheme>;
|
|
94
102
|
};
|
|
95
103
|
export default _default;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
var _templateObject;
|
|
2
|
+
|
|
3
|
+
function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
|
|
4
|
+
|
|
5
|
+
import styled, { createGlobalStyle } from 'styled-components'; // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
2
6
|
// @ts-ignore
|
|
3
7
|
|
|
4
8
|
import { TagsStyles, Tag } from '@synerise/ds-tags';
|
|
@@ -14,11 +18,11 @@ export var TagDot = styled.div.withConfig({
|
|
|
14
18
|
}, function (props) {
|
|
15
19
|
return props.theme.palette.white;
|
|
16
20
|
});
|
|
17
|
-
var SIZE_DEFAULT =
|
|
21
|
+
var SIZE_DEFAULT = 168;
|
|
18
22
|
var Container = styled.div.withConfig({
|
|
19
23
|
displayName: "ColorPickerstyles__Container",
|
|
20
24
|
componentId: "sc-1iu8b6j-1"
|
|
21
|
-
})(["
|
|
25
|
+
})(["width:100%;@media (min-width:200px){min-width:200px;margin:-8px;background-color:", ";}.react-colorful__last-control{margin:24px 56px 8px 17px;border-radius:4px;height:8px;}.react-colorful__saturation{border-bottom:0px;border-radius:4px 4px 0 0;height:96px;.react-colorful__interactive{width:100%;height:100%;}}&&& .ds-tag{width:16px;height:16px;border:1px solid ", ";margin:0 0 0 4px;&:hover{", "{display:flex;}}}.react-colorful__pointer{width:16px;height:16px;}.react-colorful{width:100%;height:", "px;}.react-colorful__hue-pointer{border:1px solid ", ";box-shadow:none !important;.react-colorful__pointer-fill{background-color:", " !important;}}.ant-divider-horizontal{margin:16px 0px;}", "{margin-bottom:-8px;}"], function (props) {
|
|
22
26
|
return props.theme.palette.white;
|
|
23
27
|
}, function (props) {
|
|
24
28
|
return props.theme.palette['grey-300'];
|
|
@@ -32,8 +36,8 @@ var Container = styled.div.withConfig({
|
|
|
32
36
|
var SubContainer = styled.div.withConfig({
|
|
33
37
|
displayName: "ColorPickerstyles__SubContainer",
|
|
34
38
|
componentId: "sc-1iu8b6j-2"
|
|
35
|
-
})(["padding:", ";"], function (props) {
|
|
36
|
-
return props.savedColors ?
|
|
39
|
+
})(["padding:8px 16px 16px;margin-bottom:", ";"], function (props) {
|
|
40
|
+
return props.savedColors ? "0" : "-16px";
|
|
37
41
|
});
|
|
38
42
|
export var ColorTag = styled(Tag).withConfig({
|
|
39
43
|
displayName: "ColorPickerstyles__ColorTag",
|
|
@@ -44,7 +48,7 @@ export var ColorTag = styled(Tag).withConfig({
|
|
|
44
48
|
export var AddColorButton = styled(Button).withConfig({
|
|
45
49
|
displayName: "ColorPickerstyles__AddColorButton",
|
|
46
50
|
componentId: "sc-1iu8b6j-4"
|
|
47
|
-
})(["&&&.ant-btn{width:16px;height:16px;margin-right:
|
|
51
|
+
})(["&&&.ant-btn{width:16px;height:16px;margin-right:0;}"]);
|
|
48
52
|
export var CopyIcon = styled(Icon).withConfig({
|
|
49
53
|
displayName: "ColorPickerstyles__CopyIcon",
|
|
50
54
|
componentId: "sc-1iu8b6j-5"
|
|
@@ -60,12 +64,10 @@ export var ColorPickerSelect = styled(Input).withConfig({
|
|
|
60
64
|
export var PrefixTag = styled.div.withConfig({
|
|
61
65
|
displayName: "ColorPickerstyles__PrefixTag",
|
|
62
66
|
componentId: "sc-1iu8b6j-8"
|
|
63
|
-
})(["&&& .ds-tag{width:24px;height:24px;border:1px solid ", ";cursor:auto;&:hover:before{cursor:auto;filter:brightness(100%);}}position:absolute;right:
|
|
67
|
+
})(["&&& .ds-tag{margin:0;width:24px;height:24px;border:1px solid ", ";cursor:auto;&:hover:before{cursor:auto;filter:brightness(100%);}}position:absolute;right:16px;top:", "px;z-index:2;cursor:auto;"], function (props) {
|
|
64
68
|
return props.theme.palette['grey-300'];
|
|
65
69
|
}, function (props) {
|
|
66
|
-
return props.
|
|
67
|
-
}, function (props) {
|
|
68
|
-
return props.height ? '97px' : '48px';
|
|
70
|
+
return (ColorPickerSize[props.size] || SIZE_DEFAULT) - 25;
|
|
69
71
|
});
|
|
70
72
|
export var SwatchSectionWrapper = styled.div.withConfig({
|
|
71
73
|
displayName: "ColorPickerstyles__SwatchSectionWrapper",
|
|
@@ -74,11 +76,17 @@ export var SwatchSectionWrapper = styled.div.withConfig({
|
|
|
74
76
|
export var PreffixWrapper = styled.div.withConfig({
|
|
75
77
|
displayName: "ColorPickerstyles__PreffixWrapper",
|
|
76
78
|
componentId: "sc-1iu8b6j-10"
|
|
77
|
-
})(["
|
|
79
|
+
})(["margin:0px 12px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:", ";"], function (props) {
|
|
80
|
+
return props.theme.palette['grey-500'];
|
|
81
|
+
});
|
|
78
82
|
export var ValueWrapper = styled.div.withConfig({
|
|
79
83
|
displayName: "ColorPickerstyles__ValueWrapper",
|
|
80
84
|
componentId: "sc-1iu8b6j-11"
|
|
81
85
|
})(["display:flex;font-size:12px;"]);
|
|
86
|
+
export var ColorPickerModalStyle = createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n.color-picker-overlay {\n min-width: unset !important;\n max-width: ", "px; \n width: 100%;\n}"])), function (_ref) {
|
|
87
|
+
var maxWidth = _ref.maxWidth;
|
|
88
|
+
return maxWidth;
|
|
89
|
+
});
|
|
82
90
|
export default {
|
|
83
91
|
Container: Container,
|
|
84
92
|
SubContainer: SubContainer,
|
|
@@ -91,5 +99,6 @@ export default {
|
|
|
91
99
|
CopyIcon: CopyIcon,
|
|
92
100
|
ColorPickerInput: ColorPickerInput,
|
|
93
101
|
TagDot: TagDot,
|
|
94
|
-
ColorPickerSelect: ColorPickerSelect
|
|
102
|
+
ColorPickerSelect: ColorPickerSelect,
|
|
103
|
+
ColorPickerModalStyle: ColorPickerModalStyle
|
|
95
104
|
};
|
|
@@ -5,11 +5,12 @@ export declare type ColorHookType = {
|
|
|
5
5
|
setColor: (color: string) => void;
|
|
6
6
|
};
|
|
7
7
|
export declare enum ColorPickerSize {
|
|
8
|
-
'S' =
|
|
9
|
-
'M' =
|
|
10
|
-
'L' =
|
|
8
|
+
'S' = 136,
|
|
9
|
+
'M' = 168,
|
|
10
|
+
'L' = 200
|
|
11
11
|
}
|
|
12
12
|
export interface ColorPickerProps extends Partial<Pick<HTMLInputElement, 'placeholder'>> {
|
|
13
|
+
maxWidth?: number;
|
|
13
14
|
value?: string;
|
|
14
15
|
onChange?: (color: string) => void;
|
|
15
16
|
colors?: string[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export var ColorPickerSize;
|
|
2
2
|
|
|
3
3
|
(function (ColorPickerSize) {
|
|
4
|
-
ColorPickerSize[ColorPickerSize["S"] =
|
|
5
|
-
ColorPickerSize[ColorPickerSize["M"] =
|
|
6
|
-
ColorPickerSize[ColorPickerSize["L"] =
|
|
4
|
+
ColorPickerSize[ColorPickerSize["S"] = 136] = "S";
|
|
5
|
+
ColorPickerSize[ColorPickerSize["M"] = 168] = "M";
|
|
6
|
+
ColorPickerSize[ColorPickerSize["L"] = 200] = "L";
|
|
7
7
|
})(ColorPickerSize || (ColorPickerSize = {}));
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const filterAlphanumeric: (colorValue: string) => string;
|
|
2
|
+
export declare const isValidHexColor: (hex: string) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Method that creates an option element and then assigns a colour to its styles.
|
|
6
|
+
* If the colour is correct, it is assigned to the element and can then be checked against the input data.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} strColor
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export declare const isValidTextColor: (strColor: string) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* A method that converts color in user-understandable notation to HEX notation.
|
|
15
|
+
* It uses the canvas element for this
|
|
16
|
+
*
|
|
17
|
+
* @param {string} color
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
export declare const standardizeColor: (color: string) => string;
|
|
21
|
+
export declare const convert3DigitHexTo6Digit: (hexColor: string) => string;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var alphanumericRegex = /[^a-zA-Z0-9]+/g;
|
|
2
|
+
var hexColorRegex = /^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$/;
|
|
3
|
+
export var filterAlphanumeric = function filterAlphanumeric(colorValue) {
|
|
4
|
+
return colorValue.replace(alphanumericRegex, '');
|
|
5
|
+
};
|
|
6
|
+
export var isValidHexColor = function isValidHexColor(hex) {
|
|
7
|
+
return hexColorRegex.test(hex);
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* Method that creates an option element and then assigns a colour to its styles.
|
|
12
|
+
* If the colour is correct, it is assigned to the element and can then be checked against the input data.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} strColor
|
|
15
|
+
* @returns {boolean}
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export var isValidTextColor = function isValidTextColor(strColor) {
|
|
19
|
+
if (!strColor) return false; // eslint-disable-next-line no-undef
|
|
20
|
+
|
|
21
|
+
var s = new Option().style;
|
|
22
|
+
s.color = strColor;
|
|
23
|
+
return s.color === strColor;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* A method that converts color in user-understandable notation to HEX notation.
|
|
28
|
+
* It uses the canvas element for this
|
|
29
|
+
*
|
|
30
|
+
* @param {string} color
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export var standardizeColor = function standardizeColor(color) {
|
|
35
|
+
var ctx = document.createElement('canvas').getContext('2d');
|
|
36
|
+
|
|
37
|
+
if (ctx) {
|
|
38
|
+
ctx.fillStyle = color;
|
|
39
|
+
return ctx.fillStyle;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return '';
|
|
43
|
+
};
|
|
44
|
+
export var convert3DigitHexTo6Digit = function convert3DigitHexTo6Digit(hexColor) {
|
|
45
|
+
var alphaHexColor = filterAlphanumeric(hexColor);
|
|
46
|
+
|
|
47
|
+
if (alphaHexColor.length === 3) {
|
|
48
|
+
var newAlphaHexColor = ''; // eslint-disable-next-line no-plusplus
|
|
49
|
+
|
|
50
|
+
for (var i = 0; i < alphaHexColor.length; i++) {
|
|
51
|
+
newAlphaHexColor += alphaHexColor[i] + alphaHexColor[i];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return "#" + newAlphaHexColor;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return hexColor;
|
|
58
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-color-picker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Color-Picker Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"@synerise/ds-core": "*",
|
|
46
46
|
"react": ">=16.9.0 < 17.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "05f16eaafa3de3ec33cc0d9a6712864646a0617e"
|
|
49
49
|
}
|