@easyv/react-components 0.0.14 → 0.0.16
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/Color/Preview.d.ts +8 -0
- package/dist/Color/Preview.js +78 -0
- package/dist/Color/Preview.less +48 -0
- package/dist/Color/index.d.ts +2 -0
- package/dist/Color/index.js +69 -0
- package/dist/Color/interface.d.ts +5 -0
- package/dist/Color/interface.js +1 -0
- package/dist/ColorPicker/Panel.d.ts +11 -0
- package/dist/ColorPicker/Panel.js +46 -0
- package/dist/ColorPicker/Panel.less +159 -0
- package/dist/ColorPicker/index.d.ts +9 -3
- package/dist/ColorPicker/index.js +265 -44
- package/dist/ColorPicker/index.less +194 -132
- package/dist/ColorPicker/utils.d.ts +16 -6
- package/dist/ColorPicker/utils.js +86 -40
- package/dist/RangeColor/Panel.d.ts +9 -0
- package/dist/RangeColor/Panel.js +187 -0
- package/dist/RangeColor/Panel.less +0 -0
- package/dist/RangeColor/Points.d.ts +2 -0
- package/dist/RangeColor/Points.js +88 -0
- package/dist/RangeColor/index.d.ts +3 -0
- package/dist/RangeColor/index.js +76 -0
- package/dist/RangeColor/index.less +49 -0
- package/dist/RangeColor/interface.d.ts +8 -0
- package/dist/RangeColor/interface.js +1 -0
- package/dist/SpaceModal/index.d.ts +5 -0
- package/dist/SpaceModal/index.js +19 -0
- package/dist/SpaceModal/index.less +5 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useClickOutside.d.ts +1 -0
- package/dist/hooks/useClickOutside.js +16 -0
- package/dist/hooks/useEventListener.d.ts +1 -0
- package/dist/hooks/useEventListener.js +19 -0
- package/dist/index.css +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/package.json +2 -2
- package/dist/ColorPicker/ColorPreview.d.ts +0 -19
- package/dist/ColorPicker/ColorPreview.js +0 -27
- package/dist/ColorPicker/ColorPreview.less +0 -5
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
export declare function toHex(x: any): string;
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
2
|
+
export declare function resolveColor(colorParam: string): {
|
|
3
|
+
r?: undefined;
|
|
4
|
+
g?: undefined;
|
|
5
|
+
b?: undefined;
|
|
6
|
+
a?: undefined;
|
|
7
|
+
hex?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
r: any;
|
|
10
|
+
g: any;
|
|
11
|
+
b: any;
|
|
12
|
+
a: any;
|
|
13
|
+
hex: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function transformColor(color: any, a: any): string | undefined;
|
|
16
|
+
export declare function getBackgroundAccordingColor(color: any, fixedAngle?: number): {
|
|
4
17
|
backgroundImage: string;
|
|
5
18
|
background?: undefined;
|
|
6
19
|
} | {
|
|
7
20
|
background: any;
|
|
8
21
|
backgroundImage?: undefined;
|
|
9
22
|
} | undefined;
|
|
10
|
-
export declare function getMiddleColor(colors:
|
|
11
|
-
color: string;
|
|
12
|
-
offset: number;
|
|
13
|
-
}[], offset: number): string;
|
|
23
|
+
export declare function getMiddleColor(colors: any, offset: any): any;
|
|
@@ -1,15 +1,56 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
import Color from 'rc-color-picker/lib/helpers/color';
|
|
3
2
|
export function toHex(x) {
|
|
4
3
|
return ('0' + parseInt(x).toString(16)).slice(-2);
|
|
5
4
|
}
|
|
5
|
+
export function resolveColor(colorParam) {
|
|
6
|
+
if (!colorParam || typeof colorParam !== 'string') {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 转为小写并去除空格
|
|
11
|
+
var color = colorParam.toLowerCase().replace(/\s+/g, '');
|
|
12
|
+
var hexReg = /^#([0-9|a-f]{3}|[0-9|a-f]{6})$/;
|
|
13
|
+
var rgbReg = /^(rgb\(\d+,\d+,\d+\)|rgba\(\d+,\d+,\d+,(\d+)?(\.)?(\d+)?\))$/;
|
|
14
|
+
// const rgbReg1 = /^(rgb\(\d+,\d+,\d+\)|rgba\((\d+)?(\.)?(\d+)?,(\d+)?(\.)?(\d+)?,(\d+)?(\.)?(\d+)?,(\d+)?(\.)?(\d+)?\))$/;
|
|
15
|
+
|
|
16
|
+
var r, g, b, a;
|
|
17
|
+
if (hexReg.test(color)) {
|
|
18
|
+
if (color.length === 4) {
|
|
19
|
+
r = parseInt(color.slice(1, 2) + color.slice(1, 2), 16);
|
|
20
|
+
g = parseInt(color.slice(2, 3) + color.slice(2, 3), 16);
|
|
21
|
+
b = parseInt(color.slice(3, 4) + color.slice(3, 4), 16);
|
|
22
|
+
} else {
|
|
23
|
+
r = parseInt(color.slice(1, 3), 16);
|
|
24
|
+
g = parseInt(color.slice(3, 5), 16);
|
|
25
|
+
b = parseInt(color.slice(5, 7), 16);
|
|
26
|
+
}
|
|
27
|
+
a = 1;
|
|
28
|
+
} else if (rgbReg.test(color)) {
|
|
29
|
+
var colors = color.replace(/rgba|rgb|\(|\)/g, '').split(',');
|
|
30
|
+
r = Number(colors[0]);
|
|
31
|
+
g = Number(colors[1]);
|
|
32
|
+
b = Number(colors[2]);
|
|
33
|
+
a = colors.length === 4 ? Number(colors[3]) : 1;
|
|
34
|
+
} else {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// return { r: Math.floor(r), g: Math.floor(g), b: Math.floor(b), a, hex: `#${toHex(r)}${toHex(g)}${toHex(b)}` };
|
|
39
|
+
return {
|
|
40
|
+
r: r,
|
|
41
|
+
g: g,
|
|
42
|
+
b: b,
|
|
43
|
+
a: a,
|
|
44
|
+
hex: "#".concat(toHex(r)).concat(toHex(g)).concat(toHex(b))
|
|
45
|
+
};
|
|
46
|
+
}
|
|
6
47
|
export function transformColor(color, a) {
|
|
7
|
-
var
|
|
8
|
-
r =
|
|
9
|
-
g =
|
|
10
|
-
b =
|
|
11
|
-
|
|
12
|
-
return a === 1 ?
|
|
48
|
+
var _resolveColor = resolveColor(color),
|
|
49
|
+
r = _resolveColor.r,
|
|
50
|
+
g = _resolveColor.g,
|
|
51
|
+
b = _resolveColor.b,
|
|
52
|
+
hex = _resolveColor.hex;
|
|
53
|
+
return a === 1 ? hex : "RGBA(".concat(r, ",").concat(g, ",").concat(b, ",").concat(a, ")");
|
|
13
54
|
}
|
|
14
55
|
export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
15
56
|
if (typeof color === 'string') {
|
|
@@ -22,19 +63,19 @@ export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
|
22
63
|
return a.offset - b.offset;
|
|
23
64
|
});
|
|
24
65
|
var colors = rebaseStops.map(function (item, index) {
|
|
25
|
-
var
|
|
26
|
-
r =
|
|
27
|
-
g =
|
|
28
|
-
b =
|
|
29
|
-
a =
|
|
66
|
+
var _resolveColor2 = resolveColor(item.color),
|
|
67
|
+
r = _resolveColor2.r,
|
|
68
|
+
g = _resolveColor2.g,
|
|
69
|
+
b = _resolveColor2.b,
|
|
70
|
+
a = _resolveColor2.a;
|
|
30
71
|
if (a === 1 || index === rebaseStops.length - 1) {
|
|
31
72
|
return "".concat(item.color, " ").concat(item.offset, "%");
|
|
32
73
|
} else {
|
|
33
|
-
var
|
|
34
|
-
nextR =
|
|
35
|
-
nextG =
|
|
36
|
-
nextB =
|
|
37
|
-
nextA =
|
|
74
|
+
var _resolveColor3 = resolveColor(rebaseStops[index + 1].color),
|
|
75
|
+
nextR = _resolveColor3.r,
|
|
76
|
+
nextG = _resolveColor3.g,
|
|
77
|
+
nextB = _resolveColor3.b,
|
|
78
|
+
nextA = _resolveColor3.a;
|
|
38
79
|
var stepOpacity = (nextA - a) / 5;
|
|
39
80
|
var stepOffset = (rebaseStops[index + 1].offset - item.offset) / 5;
|
|
40
81
|
var stepR = (nextR - r) / 5;
|
|
@@ -76,19 +117,19 @@ export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
|
76
117
|
return a.offset - b.offset;
|
|
77
118
|
});
|
|
78
119
|
var _colors = _rebaseStops.map(function (item, index) {
|
|
79
|
-
var
|
|
80
|
-
r =
|
|
81
|
-
g =
|
|
82
|
-
b =
|
|
83
|
-
a =
|
|
120
|
+
var _resolveColor4 = resolveColor(item.color),
|
|
121
|
+
r = _resolveColor4.r,
|
|
122
|
+
g = _resolveColor4.g,
|
|
123
|
+
b = _resolveColor4.b,
|
|
124
|
+
a = _resolveColor4.a;
|
|
84
125
|
if (a === 1 || index === _rebaseStops.length - 1) {
|
|
85
126
|
return "".concat(transformColor(item.color, a * opacity), " ").concat(item.offset, "%");
|
|
86
127
|
} else {
|
|
87
|
-
var
|
|
88
|
-
nextR =
|
|
89
|
-
nextG =
|
|
90
|
-
nextB =
|
|
91
|
-
nextA =
|
|
128
|
+
var _resolveColor5 = resolveColor(_rebaseStops[index + 1].color),
|
|
129
|
+
nextR = _resolveColor5.r,
|
|
130
|
+
nextG = _resolveColor5.g,
|
|
131
|
+
nextB = _resolveColor5.b,
|
|
132
|
+
nextA = _resolveColor5.a;
|
|
92
133
|
var stepOpacity = (nextA - a) / 5;
|
|
93
134
|
var stepOffset = (_rebaseStops[index + 1].offset - item.offset) / 5;
|
|
94
135
|
var stepR = (nextR - r) / 5;
|
|
@@ -102,7 +143,7 @@ export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
|
102
143
|
}
|
|
103
144
|
});
|
|
104
145
|
return {
|
|
105
|
-
backgroundImage: "linear-gradient(".concat(fixedAngle
|
|
146
|
+
backgroundImage: "linear-gradient(".concat(fixedAngle ? fixedAngle : angle, "deg, ").concat(_colors.join(','), ")")
|
|
106
147
|
};
|
|
107
148
|
} else {
|
|
108
149
|
return {
|
|
@@ -112,8 +153,7 @@ export function getBackgroundAccordingColor(color, fixedAngle) {
|
|
|
112
153
|
}
|
|
113
154
|
}
|
|
114
155
|
export function getMiddleColor(colors, offset) {
|
|
115
|
-
var leftColor;
|
|
116
|
-
var rightColor;
|
|
156
|
+
var leftColor, rightColor;
|
|
117
157
|
var leftColors = colors.filter(function (d) {
|
|
118
158
|
return d.offset < offset;
|
|
119
159
|
});
|
|
@@ -138,16 +178,22 @@ export function getMiddleColor(colors, offset) {
|
|
|
138
178
|
if (!rightColor) {
|
|
139
179
|
return leftColor.color;
|
|
140
180
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
181
|
+
|
|
182
|
+
// console.log(leftColor, rightColor, leftColors, rightColors, '计算color');
|
|
183
|
+
|
|
184
|
+
var _resolveColor6 = resolveColor(leftColor.color),
|
|
185
|
+
leftR = _resolveColor6.r,
|
|
186
|
+
leftG = _resolveColor6.g,
|
|
187
|
+
leftB = _resolveColor6.b,
|
|
188
|
+
leftA = _resolveColor6.a;
|
|
189
|
+
var _resolveColor7 = resolveColor(rightColor.color),
|
|
190
|
+
rightR = _resolveColor7.r,
|
|
191
|
+
rightG = _resolveColor7.g,
|
|
192
|
+
rightB = _resolveColor7.b,
|
|
193
|
+
rightA = _resolveColor7.a;
|
|
194
|
+
|
|
195
|
+
// console.log(resolveColor(leftColor.color), resolveColor(rightColor.color), '计算color');
|
|
196
|
+
|
|
151
197
|
var newR = Math.round((rightR - leftR) / (rightColor.offset - leftColor.offset) * (offset - leftColor.offset) + leftR);
|
|
152
198
|
var newG = Math.round((rightG - leftG) / (rightColor.offset - leftColor.offset) * (offset - leftColor.offset) + leftG);
|
|
153
199
|
var newB = Math.round((rightB - leftB) / (rightColor.offset - leftColor.offset) * (offset - leftColor.offset) + leftB);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import '../ColorPicker/index.less';
|
|
3
|
+
declare const _default: import("react").ForwardRefExoticComponent<{
|
|
4
|
+
color: any;
|
|
5
|
+
position: any;
|
|
6
|
+
onChange: any;
|
|
7
|
+
onCancel: any;
|
|
8
|
+
} & import("react").RefAttributes<unknown>>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
import { useState, useEffect, forwardRef, useRef } from 'react';
|
|
14
|
+
import classNames from 'classnames';
|
|
15
|
+
import { useLocalStorageState } from 'ahooks';
|
|
16
|
+
import { DownOutlined, SwapOutlined } from '@easyv/react-icons';
|
|
17
|
+
import SpaceModal from "../SpaceModal";
|
|
18
|
+
import { useClickOutside } from "../hooks";
|
|
19
|
+
import Points from "./Points";
|
|
20
|
+
import ColorPicker from "../ColorPicker/Panel";
|
|
21
|
+
import Button from "../Button";
|
|
22
|
+
import "../ColorPicker/index.less";
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
25
|
+
function CustomColorPicker(_ref, ref) {
|
|
26
|
+
var color = _ref.color,
|
|
27
|
+
position = _ref.position,
|
|
28
|
+
onChange = _ref.onChange,
|
|
29
|
+
onCancel = _ref.onCancel;
|
|
30
|
+
var _useLocalStorageState = useLocalStorageState('usedColors'),
|
|
31
|
+
_useLocalStorageState2 = _slicedToArray(_useLocalStorageState, 1),
|
|
32
|
+
usedPureColors = _useLocalStorageState2[0];
|
|
33
|
+
var _useLocalStorageState3 = useLocalStorageState('usedLinearColors'),
|
|
34
|
+
_useLocalStorageState4 = _slicedToArray(_useLocalStorageState3, 1),
|
|
35
|
+
usedLinearColors = _useLocalStorageState4[0];
|
|
36
|
+
var _useLocalStorageState5 = useLocalStorageState('recentCollapsed'),
|
|
37
|
+
_useLocalStorageState6 = _slicedToArray(_useLocalStorageState5, 2),
|
|
38
|
+
recentCollapsed = _useLocalStorageState6[0],
|
|
39
|
+
setRecentCollapsed = _useLocalStorageState6[1];
|
|
40
|
+
var _useState = useState(0),
|
|
41
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
42
|
+
active = _useState2[0],
|
|
43
|
+
setActive = _useState2[1];
|
|
44
|
+
var _useState3 = useState(''),
|
|
45
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
46
|
+
localColor = _useState4[0],
|
|
47
|
+
setLocalColor = _useState4[1];
|
|
48
|
+
var lastColorRef = useRef(null);
|
|
49
|
+
var currentColor = color[active] ? color[active].color : '#fff';
|
|
50
|
+
useEffect(function () {
|
|
51
|
+
setLocalColor(currentColor);
|
|
52
|
+
}, [currentColor]);
|
|
53
|
+
useClickOutside(ref, onCancel);
|
|
54
|
+
useEffect(function () {
|
|
55
|
+
return function () {
|
|
56
|
+
var lastColor = lastColorRef.current;
|
|
57
|
+
if (lastColor) {
|
|
58
|
+
if (typeof lastColor === 'string') {
|
|
59
|
+
var newColors = [lastColor].concat(usedPureColors || []);
|
|
60
|
+
newColors = Array.from(new Set(newColors)).slice(0, 16);
|
|
61
|
+
localStorage.setItem('usedColors', JSON.stringify(newColors));
|
|
62
|
+
} else {
|
|
63
|
+
var _newColors = [lastColor].concat(usedLinearColors || []);
|
|
64
|
+
_newColors = _newColors.slice(0, 16);
|
|
65
|
+
localStorage.setItem('usedLinearColors', JSON.stringify(_newColors));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
useEffect(function () {
|
|
71
|
+
var downHandler = function downHandler(e) {
|
|
72
|
+
e.stopPropagation();
|
|
73
|
+
if (e.key === 'Backspace') {
|
|
74
|
+
if (color.length > 2) {
|
|
75
|
+
var resultColor = color.filter(function (d, i) {
|
|
76
|
+
return i !== active;
|
|
77
|
+
});
|
|
78
|
+
setActive(active > 0 ? active - 1 : 0);
|
|
79
|
+
onChange(resultColor);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
document.body.addEventListener('keydown', downHandler);
|
|
84
|
+
return function () {
|
|
85
|
+
document.body.removeEventListener('keydown', downHandler);
|
|
86
|
+
};
|
|
87
|
+
}, [color, active]);
|
|
88
|
+
var handleColorChange = function handleColorChange(colorValue, used) {
|
|
89
|
+
// 判断颜色有没有更改,没有更改就不要执行。进来的第一次会把焦点定位到输入框中,点击其他地方时会失焦,会自动触发ColorPicker中的onchange事件,导致更新一次
|
|
90
|
+
if (color[active].color.replace(/\s/g, '') === colorValue) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// console.log(colorValue, 'colorValue');
|
|
94
|
+
var newColors = color.map(function (d, i) {
|
|
95
|
+
return i === active ? _objectSpread(_objectSpread({}, d), {}, {
|
|
96
|
+
color: colorValue
|
|
97
|
+
}) : d;
|
|
98
|
+
});
|
|
99
|
+
// ref.current._lastColor = used ? null : newColors;
|
|
100
|
+
lastColorRef.current = used ? null : colorValue;
|
|
101
|
+
// 增加一个定时器,延迟更新。点击最近使用的颜色时也会触发ColorPicker中的onChange事件,由于ColorPicker中的onChange事件有个100毫秒的延迟,所以给这个设置为101毫秒的延迟,主要目的是在ColorPicker中的onChange事件之后触发
|
|
102
|
+
setTimeout(function () {
|
|
103
|
+
onChange(newColors);
|
|
104
|
+
}, 101);
|
|
105
|
+
};
|
|
106
|
+
var handleCollapseRecent = function handleCollapseRecent() {
|
|
107
|
+
setRecentCollapsed(function (prev) {
|
|
108
|
+
return !prev;
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
var handleColorsChange = function handleColorsChange(colors, used) {
|
|
112
|
+
onChange(colors);
|
|
113
|
+
lastColorRef.current = used ? null : colors;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// 切换dot的排列方向
|
|
117
|
+
var handleReverseColor = function handleReverseColor() {
|
|
118
|
+
var copyStops = color.slice();
|
|
119
|
+
var newStops = copyStops.reduce(function (all, item) {
|
|
120
|
+
var obj = {};
|
|
121
|
+
obj['offset'] = 100 - item.offset;
|
|
122
|
+
obj['color'] = item.color;
|
|
123
|
+
all.push(obj);
|
|
124
|
+
return all;
|
|
125
|
+
}, []);
|
|
126
|
+
onChange(newStops);
|
|
127
|
+
};
|
|
128
|
+
return /*#__PURE__*/_jsx(SpaceModal, {
|
|
129
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
130
|
+
className: 'arco-color-picker',
|
|
131
|
+
style: {
|
|
132
|
+
left: position.x,
|
|
133
|
+
top: position.y
|
|
134
|
+
},
|
|
135
|
+
ref: ref,
|
|
136
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
137
|
+
className: 'arco-color-picker-colors',
|
|
138
|
+
children: [/*#__PURE__*/_jsx(Points, {
|
|
139
|
+
dots: color,
|
|
140
|
+
active: active,
|
|
141
|
+
setActive: setActive,
|
|
142
|
+
onChange: handleColorsChange
|
|
143
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
144
|
+
style: {
|
|
145
|
+
flex: 1
|
|
146
|
+
},
|
|
147
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
148
|
+
onClick: handleReverseColor,
|
|
149
|
+
children: /*#__PURE__*/_jsx(SwapOutlined, {})
|
|
150
|
+
})
|
|
151
|
+
})]
|
|
152
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
153
|
+
className: 'arco-color-picker-scroll-container',
|
|
154
|
+
children: [/*#__PURE__*/_jsx(ColorPicker, {
|
|
155
|
+
color: localColor,
|
|
156
|
+
onChange: handleColorChange,
|
|
157
|
+
active: active
|
|
158
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
159
|
+
className: 'arco-color-picker-recent',
|
|
160
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
161
|
+
className: 'arco-color-picker-title',
|
|
162
|
+
onClick: handleCollapseRecent,
|
|
163
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
164
|
+
children: "\u6700\u8FD1\u4F7F\u7528"
|
|
165
|
+
}), /*#__PURE__*/_jsx(DownOutlined, {
|
|
166
|
+
className: classNames('arco-color-picker-icon', _defineProperty({}, 'arco-color-picker-collapsed', recentCollapsed))
|
|
167
|
+
})]
|
|
168
|
+
}), !recentCollapsed && /*#__PURE__*/_jsx("div", {
|
|
169
|
+
className: 'arco-color-picker-list',
|
|
170
|
+
children: usedPureColors && usedPureColors.map(function (d) {
|
|
171
|
+
return /*#__PURE__*/_jsx("div", {
|
|
172
|
+
className: 'arco-color-picker-item',
|
|
173
|
+
style: {
|
|
174
|
+
background: d
|
|
175
|
+
},
|
|
176
|
+
onClick: function onClick() {
|
|
177
|
+
return handleColorChange(d, true);
|
|
178
|
+
}
|
|
179
|
+
}, d);
|
|
180
|
+
})
|
|
181
|
+
})]
|
|
182
|
+
})]
|
|
183
|
+
})]
|
|
184
|
+
})
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
export default /*#__PURE__*/forwardRef(CustomColorPicker);
|
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
import { useRef, useCallback } from 'react';
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
import { useEventListener } from "../hooks";
|
|
10
|
+
import { getBackgroundAccordingColor, getMiddleColor } from "../ColorPicker/utils";
|
|
11
|
+
import Tooltip from "../Tooltip";
|
|
12
|
+
import "../ColorPicker/index.less";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
export default function Points(props) {
|
|
15
|
+
var _props$dots = props.dots,
|
|
16
|
+
dots = _props$dots === void 0 ? [] : _props$dots,
|
|
17
|
+
active = props.active,
|
|
18
|
+
setActive = props.setActive,
|
|
19
|
+
onChange = props.onChange;
|
|
20
|
+
var mouseDownRef = useRef(false);
|
|
21
|
+
var containerRect = useRef({});
|
|
22
|
+
var containerRef = useRef(null);
|
|
23
|
+
var handleMouseDown = function handleMouseDown(index, e) {
|
|
24
|
+
e.stopPropagation();
|
|
25
|
+
mouseDownRef.current = true;
|
|
26
|
+
containerRect.current = containerRef.current.getBoundingClientRect();
|
|
27
|
+
setActive(index);
|
|
28
|
+
};
|
|
29
|
+
var handleMouseMove = function handleMouseMove(e) {
|
|
30
|
+
e.stopPropagation();
|
|
31
|
+
if (mouseDownRef.current) {
|
|
32
|
+
var newOffset = (e.clientX - containerRect.current.x) / containerRect.current.width * 100;
|
|
33
|
+
newOffset = newOffset > 100 ? 100 : newOffset < 0 ? 0 : newOffset;
|
|
34
|
+
var newDots = dots.map(function (d, i) {
|
|
35
|
+
return i === active ? _objectSpread(_objectSpread({}, d), {}, {
|
|
36
|
+
offset: newOffset
|
|
37
|
+
}) : d;
|
|
38
|
+
});
|
|
39
|
+
onChange(newDots);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var handleMouseUp = useCallback(function (e) {
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
mouseDownRef.current = false;
|
|
45
|
+
}, []);
|
|
46
|
+
useEventListener('mousemove', handleMouseMove);
|
|
47
|
+
useEventListener('mouseup', handleMouseUp);
|
|
48
|
+
var handleAddColor = function handleAddColor(e) {
|
|
49
|
+
if (mouseDownRef.current) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
var offset = Math.floor(e.nativeEvent.offsetX / e.target.offsetWidth * 100);
|
|
53
|
+
var newColor = getMiddleColor(dots, offset);
|
|
54
|
+
|
|
55
|
+
// console.log(newColor, 'newColor is NAN?');
|
|
56
|
+
|
|
57
|
+
onChange(dots.concat({
|
|
58
|
+
color: newColor,
|
|
59
|
+
offset: offset
|
|
60
|
+
}));
|
|
61
|
+
setActive(dots.length);
|
|
62
|
+
};
|
|
63
|
+
return /*#__PURE__*/_jsx("div", {
|
|
64
|
+
ref: containerRef,
|
|
65
|
+
className: 'arco-color-picker-bar',
|
|
66
|
+
style: getBackgroundAccordingColor(dots, 90),
|
|
67
|
+
onMouseDown: handleAddColor,
|
|
68
|
+
children: dots.map(function (dot, i) {
|
|
69
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
70
|
+
getPopupContainer: function getPopupContainer() {
|
|
71
|
+
return document.getElementsByClassName('arco-color-picker-bar')[0];
|
|
72
|
+
},
|
|
73
|
+
content: "".concat(Math.round(dot.offset), "%"),
|
|
74
|
+
position: "bottom",
|
|
75
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
76
|
+
className: classNames('arco-color-picker-item', _defineProperty({}, 'arco-color-picker-active', active === i)),
|
|
77
|
+
style: {
|
|
78
|
+
backgroundColor: dot.color,
|
|
79
|
+
left: "".concat(dot.offset, "%")
|
|
80
|
+
},
|
|
81
|
+
onMouseDown: function onMouseDown(e) {
|
|
82
|
+
return handleMouseDown(i, e);
|
|
83
|
+
}
|
|
84
|
+
}, i)
|
|
85
|
+
}, i);
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useState, useRef, useEffect, useDeferredValue } from 'react';
|
|
8
|
+
import ColorPicker from "./Panel";
|
|
9
|
+
import { getBackgroundAccordingColor } from "../ColorPicker/utils";
|
|
10
|
+
import "./index.less";
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
export default function RangeColor(_ref) {
|
|
15
|
+
var value = _ref.value,
|
|
16
|
+
onChange = _ref.onChange;
|
|
17
|
+
var _useState = useState(false),
|
|
18
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
19
|
+
show = _useState2[0],
|
|
20
|
+
setShow = _useState2[1];
|
|
21
|
+
var _useState3 = useState({
|
|
22
|
+
x: 0,
|
|
23
|
+
y: 0
|
|
24
|
+
}),
|
|
25
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
26
|
+
position = _useState4[0],
|
|
27
|
+
setPosition = _useState4[1];
|
|
28
|
+
var previewRef = useRef(null);
|
|
29
|
+
var pickerRef = useRef(null);
|
|
30
|
+
var deferedShow = useDeferredValue(show);
|
|
31
|
+
var handleClick = function handleClick() {
|
|
32
|
+
setShow(true);
|
|
33
|
+
};
|
|
34
|
+
var handleHide = function handleHide() {
|
|
35
|
+
setShow(false);
|
|
36
|
+
};
|
|
37
|
+
var handleColorChange = function handleColorChange(value) {
|
|
38
|
+
onChange(value);
|
|
39
|
+
};
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
if (deferedShow) {
|
|
42
|
+
var targetRect = previewRef.current.getBoundingClientRect();
|
|
43
|
+
var pickerRect = pickerRef.current.getBoundingClientRect();
|
|
44
|
+
var windowHeight = document.documentElement.clientHeight;
|
|
45
|
+
var windowWidth = document.documentElement.clientWidth;
|
|
46
|
+
var hexDOM = pickerRef.current.querySelector('.rc-color-picker-panel-params-hex');
|
|
47
|
+
if (hexDOM) {
|
|
48
|
+
hexDOM.focus();
|
|
49
|
+
hexDOM.select();
|
|
50
|
+
}
|
|
51
|
+
var top = windowHeight - targetRect.bottom < pickerRect.height ? targetRect.top - pickerRect.height < 0 ? 0 : targetRect.top - pickerRect.height : targetRect.bottom;
|
|
52
|
+
var left = windowWidth - targetRect.left < pickerRect.width ? windowWidth - pickerRect.width : targetRect.left;
|
|
53
|
+
setPosition({
|
|
54
|
+
x: left,
|
|
55
|
+
y: top
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}, [deferedShow]);
|
|
59
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
60
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
61
|
+
className: 'arco-range-color-preview',
|
|
62
|
+
onClick: handleClick,
|
|
63
|
+
ref: previewRef,
|
|
64
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
65
|
+
className: 'arco-range-color-inner',
|
|
66
|
+
style: getBackgroundAccordingColor(value, 90)
|
|
67
|
+
})
|
|
68
|
+
}), deferedShow && /*#__PURE__*/_jsx(ColorPicker, {
|
|
69
|
+
ref: pickerRef,
|
|
70
|
+
color: value,
|
|
71
|
+
position: position,
|
|
72
|
+
onCancel: handleHide,
|
|
73
|
+
onChange: handleColorChange
|
|
74
|
+
})]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
.arco-range-color-preview {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
height: 28px;
|
|
5
|
+
border-radius: 2px;
|
|
6
|
+
border: 1px solid var(--border-color-2);
|
|
7
|
+
margin-right: 8px;
|
|
8
|
+
padding: 6px;
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
background-color: var(--color-bg-1);
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
|
|
15
|
+
&::before {
|
|
16
|
+
content: '';
|
|
17
|
+
position: absolute;
|
|
18
|
+
left: 6px;
|
|
19
|
+
right: 6px;
|
|
20
|
+
top: 6px;
|
|
21
|
+
bottom: 6px;
|
|
22
|
+
border-radius: 2px;
|
|
23
|
+
background-image: linear-gradient(
|
|
24
|
+
45deg,
|
|
25
|
+
#404040 25%,
|
|
26
|
+
transparent 0,
|
|
27
|
+
transparent 75%,
|
|
28
|
+
#404040 0
|
|
29
|
+
),
|
|
30
|
+
linear-gradient(
|
|
31
|
+
45deg,
|
|
32
|
+
#404040 25%,
|
|
33
|
+
transparent 0,
|
|
34
|
+
transparent 75%,
|
|
35
|
+
#404040 0
|
|
36
|
+
);
|
|
37
|
+
background-color: #4a4a4a;
|
|
38
|
+
background-size: 10px 10px;
|
|
39
|
+
background-position: 0 0, 5px 5px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.arco-range-color-inner {
|
|
43
|
+
width: 100%;
|
|
44
|
+
height: 100%;
|
|
45
|
+
border-radius: 2px;
|
|
46
|
+
position: relative;
|
|
47
|
+
z-index: 1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|