@synerise/ds-color-picker 0.3.99 → 0.3.101
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 +16 -0
- package/dist/ColorPicker.js +37 -55
- package/dist/ColorPicker.styles.js +2 -4
- package/dist/ColorPicker.types.js +0 -1
- package/dist/utils.js +6 -11
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.3.101](https://github.com/Synerise/synerise-design/compare/@synerise/ds-color-picker@0.3.100...@synerise/ds-color-picker@0.3.101) (2024-11-29)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-color-picker
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.3.100](https://github.com/Synerise/synerise-design/compare/@synerise/ds-color-picker@0.3.99...@synerise/ds-color-picker@0.3.100) (2024-11-28)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @synerise/ds-color-picker
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [0.3.99](https://github.com/Synerise/synerise-design/compare/@synerise/ds-color-picker@0.3.98...@synerise/ds-color-picker@0.3.99) (2024-11-21)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @synerise/ds-color-picker
|
package/dist/ColorPicker.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
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); }
|
|
2
|
-
|
|
3
2
|
import React from 'react';
|
|
4
3
|
import { HexColorPicker as ReactColorful } from 'react-colorful';
|
|
5
4
|
import Divider from '@synerise/ds-divider';
|
|
@@ -13,60 +12,50 @@ import { isValidHexColor, isValidTextColor, convert3DigitHexTo6Digit, filterAlph
|
|
|
13
12
|
import ColorPickerStyles from './ColorPicker.styles';
|
|
14
13
|
var DEFAULT_MAX_WIDTH_PICKER = 228;
|
|
15
14
|
var DEFAULT_COLOR = '#ffffff';
|
|
16
|
-
|
|
17
15
|
var ColorPicker = function ColorPicker(_ref) {
|
|
18
16
|
var maxWidth = _ref.maxWidth,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
17
|
+
value = _ref.value,
|
|
18
|
+
onChange = _ref.onChange,
|
|
19
|
+
_ref$colors = _ref.colors,
|
|
20
|
+
colors = _ref$colors === void 0 ? [] : _ref$colors,
|
|
21
|
+
onSaveColors = _ref.onSaveColors,
|
|
22
|
+
_ref$infix = _ref.infix,
|
|
23
|
+
infix = _ref$infix === void 0 ? function () {
|
|
24
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
25
|
+
} : _ref$infix,
|
|
26
|
+
placeholder = _ref.placeholder,
|
|
27
|
+
inputProps = _ref.inputProps,
|
|
28
|
+
_ref$maxSavedColors = _ref.maxSavedColors,
|
|
29
|
+
maxSavedColors = _ref$maxSavedColors === void 0 ? 9 : _ref$maxSavedColors,
|
|
30
|
+
tooltip = _ref.tooltip,
|
|
31
|
+
isShownSavedColors = _ref.isShownSavedColors,
|
|
32
|
+
_ref$size = _ref.size,
|
|
33
|
+
size = _ref$size === void 0 ? 'M' : _ref$size,
|
|
34
|
+
errorText = _ref.errorText,
|
|
35
|
+
description = _ref.description;
|
|
39
36
|
var _React$useState = React.useState(value),
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
colorTextInput = _React$useState[0],
|
|
38
|
+
setColorTextInput = _React$useState[1];
|
|
43
39
|
var _React$useState2 = React.useState(value),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
colorHexInput = _React$useState2[0],
|
|
41
|
+
setColorHexInput = _React$useState2[1];
|
|
47
42
|
var _React$useState3 = React.useState(value),
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
lastValidHexColor = _React$useState3[0],
|
|
44
|
+
setLastValidHexColor = _React$useState3[1];
|
|
51
45
|
var _React$useState4 = React.useState(-1),
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
pressed = _React$useState4[0],
|
|
47
|
+
setPressed = _React$useState4[1];
|
|
55
48
|
var _React$useState5 = React.useState(false),
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
dropdownVisible = _React$useState5[0],
|
|
50
|
+
setDropdownVisible = _React$useState5[1];
|
|
59
51
|
var _React$useState6 = React.useState(colors),
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
savedColors = _React$useState6[0],
|
|
53
|
+
setSavedColors = _React$useState6[1];
|
|
63
54
|
var _React$useState7 = React.useState(tooltip == null ? void 0 : tooltip.copy),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
tooltipText = _React$useState7[0],
|
|
56
|
+
setTooltipText = _React$useState7[1];
|
|
67
57
|
var onChangeTextColor = React.useCallback(function (colorValue) {
|
|
68
58
|
setColorTextInput(colorValue);
|
|
69
|
-
|
|
70
59
|
if (isValidTextColor(colorValue)) {
|
|
71
60
|
var standardizedColor = standardizeColor(colorValue);
|
|
72
61
|
setColorHexInput(standardizedColor);
|
|
@@ -78,19 +67,16 @@ var ColorPicker = function ColorPicker(_ref) {
|
|
|
78
67
|
setLastValidHexColor(fullHexColor);
|
|
79
68
|
onChange && onChange(fullHexColor);
|
|
80
69
|
}
|
|
81
|
-
|
|
82
70
|
setPressed(-1);
|
|
83
71
|
}, [onChange]);
|
|
84
72
|
var onChangeHexColor = React.useCallback(function (colorValue) {
|
|
85
73
|
setColorHexInput(colorValue);
|
|
86
|
-
|
|
87
74
|
if (isValidHexColor(colorValue)) {
|
|
88
75
|
var fullHexColor = convert3DigitHexTo6Digit(colorValue);
|
|
89
76
|
setColorTextInput(fullHexColor);
|
|
90
77
|
setLastValidHexColor(fullHexColor);
|
|
91
78
|
onChange && onChange(fullHexColor);
|
|
92
79
|
}
|
|
93
|
-
|
|
94
80
|
setPressed(-1);
|
|
95
81
|
}, [onChange]);
|
|
96
82
|
var onBlurHandler = React.useCallback(function () {
|
|
@@ -112,25 +98,22 @@ var ColorPicker = function ColorPicker(_ref) {
|
|
|
112
98
|
onChangeTextColor(value);
|
|
113
99
|
} else {
|
|
114
100
|
onChangeTextColor(DEFAULT_COLOR);
|
|
115
|
-
}
|
|
116
|
-
|
|
101
|
+
}
|
|
102
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
103
|
}, []);
|
|
118
104
|
var heightOfDropdown = React.useCallback(function () {
|
|
119
105
|
if (errorText || description) {
|
|
120
106
|
if (errorText && description) {
|
|
121
107
|
return -40;
|
|
122
108
|
}
|
|
123
|
-
|
|
124
109
|
return -20;
|
|
125
110
|
}
|
|
126
|
-
|
|
127
111
|
return 4;
|
|
128
112
|
}, [errorText, description]);
|
|
129
113
|
var ref = React.useRef(null);
|
|
130
114
|
useOnClickOutside(ref, function () {
|
|
131
115
|
setDropdownVisible(false);
|
|
132
116
|
});
|
|
133
|
-
|
|
134
117
|
var saveColor = function saveColor() {
|
|
135
118
|
setSavedColors(function (ar) {
|
|
136
119
|
var colorsArray = (lastValidHexColor ? [lastValidHexColor].concat(ar) : ar).slice(0, maxSavedColors);
|
|
@@ -138,7 +121,6 @@ var ColorPicker = function ColorPicker(_ref) {
|
|
|
138
121
|
return colorsArray;
|
|
139
122
|
});
|
|
140
123
|
};
|
|
141
|
-
|
|
142
124
|
var swatchSection = /*#__PURE__*/React.createElement(ColorPickerStyles.SwatchSectionWrapper, null, /*#__PURE__*/React.createElement(Tooltip, {
|
|
143
125
|
title: "Save color swatch"
|
|
144
126
|
}, /*#__PURE__*/React.createElement(ColorPickerStyles.AddColorButton, {
|
|
@@ -152,7 +134,8 @@ var ColorPicker = function ColorPicker(_ref) {
|
|
|
152
134
|
color: colorTextInput,
|
|
153
135
|
setColor: onChangeTextColor
|
|
154
136
|
}), savedColors.length > 0 && /*#__PURE__*/React.createElement(Tags, {
|
|
155
|
-
tagShape: TagShape.SINGLE_CHARACTER_SQUARE
|
|
137
|
+
tagShape: TagShape.SINGLE_CHARACTER_SQUARE
|
|
138
|
+
// @ts-ignore
|
|
156
139
|
,
|
|
157
140
|
selected: savedColors.map(function (colorEntry, i) {
|
|
158
141
|
return {
|
|
@@ -228,5 +211,4 @@ var ColorPicker = function ColorPicker(_ref) {
|
|
|
228
211
|
errorText: errorText
|
|
229
212
|
}, inputProps))));
|
|
230
213
|
};
|
|
231
|
-
|
|
232
214
|
export default ColorPicker;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
var _templateObject;
|
|
2
|
-
|
|
3
2
|
function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import styled, { createGlobalStyle } from 'styled-components';
|
|
4
|
+
// @ts-ignore
|
|
7
5
|
import { TagsStyles, Tag } from '@synerise/ds-tags';
|
|
8
6
|
import Button from '@synerise/ds-button';
|
|
9
7
|
import Icon from '@synerise/ds-icon';
|
package/dist/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ export var filterAlphanumeric = function filterAlphanumeric(colorValue) {
|
|
|
6
6
|
export var isValidHexColor = function isValidHexColor(hex) {
|
|
7
7
|
return hexColorRegex.test(hex);
|
|
8
8
|
};
|
|
9
|
+
|
|
9
10
|
/**
|
|
10
11
|
*
|
|
11
12
|
* Method that creates an option element and then assigns a colour to its styles.
|
|
@@ -14,14 +15,14 @@ export var isValidHexColor = function isValidHexColor(hex) {
|
|
|
14
15
|
* @param {string} strColor
|
|
15
16
|
* @returns {boolean}
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
18
|
export var isValidTextColor = function isValidTextColor(strColor) {
|
|
19
|
-
if (!strColor) return false;
|
|
20
|
-
|
|
19
|
+
if (!strColor) return false;
|
|
20
|
+
// eslint-disable-next-line no-undef
|
|
21
21
|
var s = new Option().style;
|
|
22
22
|
s.color = strColor;
|
|
23
23
|
return s.color === strColor;
|
|
24
24
|
};
|
|
25
|
+
|
|
25
26
|
/**
|
|
26
27
|
*
|
|
27
28
|
* A method that converts color in user-understandable notation to HEX notation.
|
|
@@ -30,29 +31,23 @@ export var isValidTextColor = function isValidTextColor(strColor) {
|
|
|
30
31
|
* @param {string} color
|
|
31
32
|
* @returns {string}
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
34
|
export var standardizeColor = function standardizeColor(color) {
|
|
35
35
|
var ctx = document.createElement('canvas').getContext('2d');
|
|
36
|
-
|
|
37
36
|
if (ctx) {
|
|
38
37
|
ctx.fillStyle = color;
|
|
39
38
|
return ctx.fillStyle;
|
|
40
39
|
}
|
|
41
|
-
|
|
42
40
|
return '';
|
|
43
41
|
};
|
|
44
42
|
export var convert3DigitHexTo6Digit = function convert3DigitHexTo6Digit(hexColor) {
|
|
45
43
|
var alphaHexColor = filterAlphanumeric(hexColor);
|
|
46
|
-
|
|
47
44
|
if (alphaHexColor.length === 3) {
|
|
48
|
-
var newAlphaHexColor = '';
|
|
49
|
-
|
|
45
|
+
var newAlphaHexColor = '';
|
|
46
|
+
// eslint-disable-next-line no-plusplus
|
|
50
47
|
for (var i = 0; i < alphaHexColor.length; i++) {
|
|
51
48
|
newAlphaHexColor += alphaHexColor[i] + alphaHexColor[i];
|
|
52
49
|
}
|
|
53
|
-
|
|
54
50
|
return "#" + newAlphaHexColor;
|
|
55
51
|
}
|
|
56
|
-
|
|
57
52
|
return hexColor;
|
|
58
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-color-picker",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.101",
|
|
4
4
|
"description": "Color-Picker Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
],
|
|
35
35
|
"types": "dist/index.d.ts",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@synerise/ds-button": "^0.21.
|
|
38
|
-
"@synerise/ds-divider": "^0.7.
|
|
39
|
-
"@synerise/ds-dropdown": "^0.18.
|
|
40
|
-
"@synerise/ds-icon": "^0.
|
|
41
|
-
"@synerise/ds-input": "^0.24.
|
|
42
|
-
"@synerise/ds-tags": "^0.10.
|
|
43
|
-
"@synerise/ds-tooltip": "^0.14.
|
|
37
|
+
"@synerise/ds-button": "^0.21.21",
|
|
38
|
+
"@synerise/ds-divider": "^0.7.17",
|
|
39
|
+
"@synerise/ds-dropdown": "^0.18.26",
|
|
40
|
+
"@synerise/ds-icon": "^0.68.0",
|
|
41
|
+
"@synerise/ds-input": "^0.24.16",
|
|
42
|
+
"@synerise/ds-tags": "^0.10.20",
|
|
43
|
+
"@synerise/ds-tooltip": "^0.14.51",
|
|
44
44
|
"@synerise/ds-utils": "^0.31.2",
|
|
45
45
|
"copy-to-clipboard": "^3.3.1",
|
|
46
46
|
"react-colorful": "^5.2.0"
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"react": ">=16.9.0 <= 17.0.2",
|
|
52
52
|
"styled-components": "5.0.1"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "9ebd107163650754a5f55680d62d30812d740084"
|
|
55
55
|
}
|