dtable-ui-component 5.0.21-alpha.3 → 5.0.21-alpha.4
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/lib/DTableColorPicker/index.css +1 -1
- package/lib/DTableColorPicker/index.js +54 -38
- package/lib/DTableColorPicker/{utils/index.js → utils.js} +1 -2
- package/lib/locals/de.js +1 -1
- package/lib/locals/en.js +1 -1
- package/lib/locals/es.js +1 -1
- package/lib/locals/fr.js +1 -1
- package/lib/locals/pt.js +1 -1
- package/lib/locals/ru.js +1 -1
- package/lib/locals/zh-CN.js +1 -1
- package/package.json +1 -1
- package/lib/DTableColorPicker/constants/index.js +0 -16
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
padding: 0.75rem;
|
|
7
7
|
line-height: normal;
|
|
8
8
|
position: absolute;
|
|
9
|
-
box-shadow: rgba(0, 0, 0, 0.3) 0px 0px 2px, rgba(0, 0, 0, 0.3) 0px 4px 8px
|
|
9
|
+
box-shadow: rgba(0, 0, 0, 0.3) 0px 0px 2px, rgba(0, 0, 0, 0.3) 0px 4px 8px;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
.dtable-color-picker .chrome-picker {
|
|
@@ -11,16 +11,25 @@ var _reactstrap = require("reactstrap");
|
|
|
11
11
|
var _reactColor = require("react-color");
|
|
12
12
|
var _lang = require("../lang");
|
|
13
13
|
var _ClickOutside = _interopRequireDefault(require("../ClickOutside"));
|
|
14
|
-
var _constants = require("./constants");
|
|
15
14
|
var _utils = require("./utils");
|
|
16
15
|
require("./index.css");
|
|
16
|
+
const DEFAULT_COLORS = ['#ffffff', '#f5f5f5', '#eef6f9', '#deffe6', '#def7c4', '#fefdb5', '#feebb6', '#ffdde5'];
|
|
17
|
+
const COLOR_PICKER_MODE = {
|
|
18
|
+
HEX: 'hex',
|
|
19
|
+
RGBA: 'rgba'
|
|
20
|
+
};
|
|
21
|
+
const RGB_COLORS_MAP = {
|
|
22
|
+
RED: 'r',
|
|
23
|
+
GREEN: 'g',
|
|
24
|
+
BLUE: 'b'
|
|
25
|
+
};
|
|
26
|
+
const LOCAL_STORAGE_KEY = 'dtable-color-picker';
|
|
17
27
|
const DTableColorPicker = props => {
|
|
18
28
|
const {
|
|
19
29
|
onToggle,
|
|
20
30
|
popoverStyle,
|
|
21
31
|
color,
|
|
22
|
-
defaultColors
|
|
23
|
-
storageKey
|
|
32
|
+
defaultColors
|
|
24
33
|
} = props;
|
|
25
34
|
const initialRgbaColor = (0, _utils.hexToRgba)(color);
|
|
26
35
|
const [value, setValue] = (0, _react.useState)(initialRgbaColor);
|
|
@@ -29,11 +38,19 @@ const DTableColorPicker = props => {
|
|
|
29
38
|
const [redVal, setRedVal] = (0, _react.useState)(initialRgbaColor.r);
|
|
30
39
|
const [greenVal, setGreenVal] = (0, _react.useState)(initialRgbaColor.g);
|
|
31
40
|
const [blueVal, setBlueVal] = (0, _react.useState)(initialRgbaColor.b);
|
|
32
|
-
const [colorMode, setColorMode] = (0, _react.useState)(
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
const [colorMode, setColorMode] = (0, _react.useState)(COLOR_PICKER_MODE.HEX); // hex or rgb
|
|
42
|
+
let currentUsedColors = [];
|
|
43
|
+
const currentUsedColorsStr = window.localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
44
|
+
try {
|
|
45
|
+
currentUsedColors = currentUsedColorsStr ? JSON.parse(currentUsedColorsStr) : [];
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error("Error parsing current used colors from localStorage:", error);
|
|
48
|
+
}
|
|
35
49
|
(0, _react.useEffect)(() => {
|
|
36
|
-
document.querySelector('.chrome-picker > div:last-of-type > .flexbox-fix:first-of-type')
|
|
50
|
+
const colorBarElement = document.querySelector('.chrome-picker > div:last-of-type > .flexbox-fix:first-of-type');
|
|
51
|
+
if (colorBarElement) {
|
|
52
|
+
colorBarElement.classList.add('color-bar');
|
|
53
|
+
}
|
|
37
54
|
}, []);
|
|
38
55
|
const onChangeChromePicker = newColor => {
|
|
39
56
|
const rgba = newColor.rgb;
|
|
@@ -48,7 +65,7 @@ const DTableColorPicker = props => {
|
|
|
48
65
|
} = rgba;
|
|
49
66
|
setAlphaVal((0, _utils.toPercentage)(a));
|
|
50
67
|
updateValue(rgba);
|
|
51
|
-
if (colorMode ===
|
|
68
|
+
if (colorMode === COLOR_PICKER_MODE.HEX) {
|
|
52
69
|
setHexVal(hexVal);
|
|
53
70
|
} else {
|
|
54
71
|
setRedVal(r);
|
|
@@ -58,8 +75,8 @@ const DTableColorPicker = props => {
|
|
|
58
75
|
};
|
|
59
76
|
const onChangeMode = () => {
|
|
60
77
|
let newMode;
|
|
61
|
-
if (colorMode ===
|
|
62
|
-
newMode =
|
|
78
|
+
if (colorMode === COLOR_PICKER_MODE.HEX) {
|
|
79
|
+
newMode = COLOR_PICKER_MODE.RGBA;
|
|
63
80
|
const rgba = (0, _utils.hexToRgba)(color);
|
|
64
81
|
const {
|
|
65
82
|
r,
|
|
@@ -70,7 +87,7 @@ const DTableColorPicker = props => {
|
|
|
70
87
|
setGreenVal(g);
|
|
71
88
|
setBlueVal(b);
|
|
72
89
|
} else {
|
|
73
|
-
newMode =
|
|
90
|
+
newMode = COLOR_PICKER_MODE.HEX;
|
|
74
91
|
const hexVal = (0, _utils.rgbaToHex)(value, false, false);
|
|
75
92
|
setHexVal(hexVal);
|
|
76
93
|
}
|
|
@@ -117,17 +134,17 @@ const DTableColorPicker = props => {
|
|
|
117
134
|
if (!regex.test(newVal)) return;
|
|
118
135
|
if (newVal) newVal = parseInt(newVal);
|
|
119
136
|
switch (specColor) {
|
|
120
|
-
case
|
|
137
|
+
case RGB_COLORS_MAP.RED:
|
|
121
138
|
{
|
|
122
139
|
setRedVal(newVal);
|
|
123
140
|
break;
|
|
124
141
|
}
|
|
125
|
-
case
|
|
142
|
+
case RGB_COLORS_MAP.GREEN:
|
|
126
143
|
{
|
|
127
144
|
setGreenVal(newVal);
|
|
128
145
|
break;
|
|
129
146
|
}
|
|
130
|
-
case
|
|
147
|
+
case RGB_COLORS_MAP.BLUE:
|
|
131
148
|
{
|
|
132
149
|
setBlueVal(newVal);
|
|
133
150
|
break;
|
|
@@ -139,10 +156,10 @@ const DTableColorPicker = props => {
|
|
|
139
156
|
const onRgbInputBlur = specColor => {
|
|
140
157
|
let val = redVal;
|
|
141
158
|
let setSpecColor = setRedVal;
|
|
142
|
-
if (specColor ===
|
|
159
|
+
if (specColor === RGB_COLORS_MAP.GREEN) {
|
|
143
160
|
val = greenVal;
|
|
144
161
|
setSpecColor = setGreenVal;
|
|
145
|
-
} else if (specColor ===
|
|
162
|
+
} else if (specColor === RGB_COLORS_MAP.BLUE) {
|
|
146
163
|
val = blueVal;
|
|
147
164
|
setSpecColor = setBlueVal;
|
|
148
165
|
}
|
|
@@ -189,35 +206,34 @@ const DTableColorPicker = props => {
|
|
|
189
206
|
a
|
|
190
207
|
} = rgba;
|
|
191
208
|
const alphaVal = (0, _utils.toPercentage)(a);
|
|
192
|
-
if (colorMode ===
|
|
193
|
-
setHexVal(hexVal);
|
|
194
|
-
} else {
|
|
209
|
+
if (colorMode === COLOR_PICKER_MODE.RGBA) {
|
|
195
210
|
setRedVal(r);
|
|
196
211
|
setGreenVal(g);
|
|
197
212
|
setBlueVal(b);
|
|
198
213
|
}
|
|
214
|
+
setHexVal(hexVal);
|
|
199
215
|
setAlphaVal(alphaVal);
|
|
200
216
|
updateValue(rgba);
|
|
201
217
|
};
|
|
202
218
|
const onClosePopover = () => {
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
window.localStorage.setItem(storageKey, JSON.stringify(currentUsedColors));
|
|
209
|
-
}
|
|
219
|
+
if (currentUsedColors.length >= 8) currentUsedColors.pop();
|
|
220
|
+
const hex = (0, _utils.rgbaToHex)(value);
|
|
221
|
+
if (!currentUsedColors.includes(hex)) {
|
|
222
|
+
currentUsedColors.unshift(hex);
|
|
223
|
+
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(currentUsedColors));
|
|
210
224
|
}
|
|
211
225
|
onToggle();
|
|
212
226
|
};
|
|
213
227
|
const renderDefaultContainer = () => {
|
|
228
|
+
const colors = defaultColors ? defaultColors.slice(0, 8) : DEFAULT_COLORS;
|
|
214
229
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
215
230
|
className: "default-color-setting"
|
|
216
231
|
}, /*#__PURE__*/_react.default.createElement("span", null, (0, _lang.getLocale)('Default')), /*#__PURE__*/_react.default.createElement("div", {
|
|
217
232
|
className: "default-colors-container d-flex mt-2 mb-2"
|
|
218
|
-
},
|
|
233
|
+
}, colors.map((color, index) => {
|
|
234
|
+
const isLight = (0, _utils.isLightColor)(color);
|
|
219
235
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
220
|
-
className: "color-item mr-2",
|
|
236
|
+
className: "color-item mr-2 ".concat(isLight ? '' : 'dark'),
|
|
221
237
|
onClick: () => onSelectDefaultColor(color),
|
|
222
238
|
key: "default-color-".concat(index)
|
|
223
239
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
@@ -225,7 +241,7 @@ const DTableColorPicker = props => {
|
|
|
225
241
|
style: {
|
|
226
242
|
backgroundColor: color
|
|
227
243
|
}
|
|
228
|
-
}, color === "#".concat(hexVal) &&
|
|
244
|
+
}, color === "#".concat(hexVal) && alphaVal === 100 && /*#__PURE__*/_react.default.createElement("i", {
|
|
229
245
|
className: "dtable-icon-color-check dtable-font dtable-icon-check-mark"
|
|
230
246
|
})));
|
|
231
247
|
})));
|
|
@@ -239,10 +255,10 @@ const DTableColorPicker = props => {
|
|
|
239
255
|
className: "color-setting d-flex align-items-center ".concat(colorMode)
|
|
240
256
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
241
257
|
className: "mode-btn d-flex"
|
|
242
|
-
}, colorMode ===
|
|
258
|
+
}, colorMode === COLOR_PICKER_MODE.HEX ? 'HEX' : 'RGB', /*#__PURE__*/_react.default.createElement("i", {
|
|
243
259
|
onClick: onChangeMode,
|
|
244
260
|
className: "dtable-font dtable-icon-right"
|
|
245
|
-
})), colorMode ===
|
|
261
|
+
})), colorMode === COLOR_PICKER_MODE.HEX ? renderHexContainer() : renderRgbContainer(), /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
246
262
|
className: "alpha-input",
|
|
247
263
|
type: "text",
|
|
248
264
|
value: alphaVal + '%',
|
|
@@ -270,26 +286,26 @@ const DTableColorPicker = props => {
|
|
|
270
286
|
className: "rgb-input",
|
|
271
287
|
type: "text",
|
|
272
288
|
value: redVal,
|
|
273
|
-
onBlur: () => onRgbInputBlur(
|
|
274
|
-
onChange: e => onChangeRgb(e,
|
|
289
|
+
onBlur: () => onRgbInputBlur(RGB_COLORS_MAP.RED),
|
|
290
|
+
onChange: e => onChangeRgb(e, RGB_COLORS_MAP.RED)
|
|
275
291
|
}), /*#__PURE__*/_react.default.createElement("span", null, "G"), /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
276
292
|
className: "rgb-input",
|
|
277
293
|
type: "text",
|
|
278
294
|
value: greenVal,
|
|
279
|
-
onBlur: () => onRgbInputBlur(
|
|
280
|
-
onChange: e => onChangeRgb(e,
|
|
295
|
+
onBlur: () => onRgbInputBlur(RGB_COLORS_MAP.GREEN),
|
|
296
|
+
onChange: e => onChangeRgb(e, RGB_COLORS_MAP.GREEN)
|
|
281
297
|
}), /*#__PURE__*/_react.default.createElement("span", null, "B"), /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
282
298
|
className: "rgb-input",
|
|
283
299
|
type: "text",
|
|
284
300
|
value: blueVal,
|
|
285
|
-
onBlur: () => onRgbInputBlur(
|
|
286
|
-
onChange: e => onChangeRgb(e,
|
|
301
|
+
onBlur: () => onRgbInputBlur(RGB_COLORS_MAP.BLUE),
|
|
302
|
+
onChange: e => onChangeRgb(e, RGB_COLORS_MAP.BLUE)
|
|
287
303
|
}));
|
|
288
304
|
};
|
|
289
305
|
const renderUsedContainer = () => {
|
|
290
306
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
291
307
|
className: "current-used-container mt-2"
|
|
292
|
-
}, /*#__PURE__*/_react.default.createElement("span", null, (0, _lang.getLocale)('
|
|
308
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, (0, _lang.getLocale)('Recently_used')), /*#__PURE__*/_react.default.createElement("div", {
|
|
293
309
|
className: "current-used-colors d-flex mt-2"
|
|
294
310
|
}, currentUsedColors.length > 0 ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, currentUsedColors.map((color, index) => {
|
|
295
311
|
const isLight = (0, _utils.isLightColor)(color);
|
|
@@ -12,8 +12,7 @@ const hexToRgba = color => {
|
|
|
12
12
|
let g;
|
|
13
13
|
let b;
|
|
14
14
|
let a = 1;
|
|
15
|
-
|
|
16
|
-
hex = hex.replace(/^#/, '');
|
|
15
|
+
const hex = color.replace(/^#/, '');
|
|
17
16
|
if (hex.length === 6 || hex.length === 8) {
|
|
18
17
|
r = parseInt(hex.slice(0, 2), 16);
|
|
19
18
|
g = parseInt(hex.slice(2, 4), 16);
|
package/lib/locals/de.js
CHANGED
package/lib/locals/en.js
CHANGED
package/lib/locals/es.js
CHANGED
package/lib/locals/fr.js
CHANGED
package/lib/locals/pt.js
CHANGED
package/lib/locals/ru.js
CHANGED
package/lib/locals/zh-CN.js
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.RGB_COLORS_MAP = exports.DEFAULT_COLORS = exports.COLOR_PICKER_MODE = void 0;
|
|
7
|
-
const DEFAULT_COLORS = exports.DEFAULT_COLORS = ['#ffffff', '#f5f5f5', '#eef6f9', '#deffe6', '#def7c4', '#fefdb5', '#feebb6', '#ffdde5'];
|
|
8
|
-
const COLOR_PICKER_MODE = exports.COLOR_PICKER_MODE = {
|
|
9
|
-
HEX: 'hex',
|
|
10
|
-
RGBA: 'rgba'
|
|
11
|
-
};
|
|
12
|
-
const RGB_COLORS_MAP = exports.RGB_COLORS_MAP = {
|
|
13
|
-
RED: 'r',
|
|
14
|
-
GREEN: 'g',
|
|
15
|
-
BLUT: 'b'
|
|
16
|
-
};
|