@easyv/react-components 0.2.0 → 0.2.1
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/ColorsPicker/ControlBar.d.ts +3 -2
- package/dist/ColorsPicker/ControlBar.js +11 -3
- package/dist/ColorsPicker/LinearColorPicker/LinearColorPanel.d.ts +3 -2
- package/dist/ColorsPicker/LinearColorPicker/LinearColorPanel.js +21 -9
- package/dist/ColorsPicker/LinearColorPicker/LinearPointsBar.d.ts +3 -2
- package/dist/ColorsPicker/LinearColorPicker/LinearPointsBar.js +21 -5
- package/dist/ColorsPicker/MixedColorPicker/MixedPanel.d.ts +3 -2
- package/dist/ColorsPicker/MixedColorPicker/MixedPanel.js +18 -6
- package/dist/ColorsPicker/Palette.d.ts +3 -2
- package/dist/ColorsPicker/Palette.js +6 -2
- package/dist/ColorsPicker/Panel.d.ts +3 -2
- package/dist/ColorsPicker/Panel.js +48 -14
- package/dist/ColorsPicker/PureColorPicker/PureColorInput.d.ts +1 -1
- package/dist/ColorsPicker/PureColorPicker/PureColorInput.js +2 -2
- package/dist/ColorsPicker/PureColorPicker/PureColorPanel.d.ts +3 -2
- package/dist/ColorsPicker/PureColorPicker/PureColorPanel.js +6 -3
- package/dist/ColorsPicker/PuresColorPicker/PuresColorPanel.d.ts +3 -2
- package/dist/ColorsPicker/PuresColorPicker/PuresColorPanel.js +18 -6
- package/dist/ColorsPicker/RangeColorPicker/RangeColorPanel.d.ts +3 -2
- package/dist/ColorsPicker/RangeColorPicker/RangeColorPanel.js +15 -7
- package/dist/ColorsPicker/hooks/useColorsPicker.d.ts +2 -25
- package/dist/ColorsPicker/hooks/useColorsPicker.js +36 -8
- package/dist/ColorsPicker/hooks/useControlBlock.d.ts +3 -2
- package/dist/ColorsPicker/hooks/useControlBlock.js +13 -5
- package/dist/ColorsPicker/index.js +26 -9
- package/dist/ColorsPicker/interface.d.ts +2 -1
- package/dist/ColorsPicker/style/index.less +10 -10
- package/package.json +1 -1
|
@@ -2,7 +2,8 @@ import { Color } from './interface';
|
|
|
2
2
|
interface ControlBarProps {
|
|
3
3
|
color: Color;
|
|
4
4
|
type: 'hue' | 'alpha';
|
|
5
|
-
onChange
|
|
5
|
+
onChange?: (x: number) => void;
|
|
6
|
+
onChangeComplete?: (x: number) => void;
|
|
6
7
|
}
|
|
7
|
-
export default function ControlBar({ color, type, onChange }: ControlBarProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default function ControlBar({ color, type, onChange, onChangeComplete, }: ControlBarProps): import("react/jsx-runtime").JSX.Element;
|
|
8
9
|
export {};
|
|
@@ -6,7 +6,8 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
export default function ControlBar(_ref) {
|
|
7
7
|
var color = _ref.color,
|
|
8
8
|
type = _ref.type,
|
|
9
|
-
_onChange = _ref.onChange
|
|
9
|
+
_onChange = _ref.onChange,
|
|
10
|
+
_onChangeComplete = _ref.onChangeComplete;
|
|
10
11
|
var x;
|
|
11
12
|
if (type === 'alpha') {
|
|
12
13
|
x = color.alpha;
|
|
@@ -18,9 +19,16 @@ export default function ControlBar(_ref) {
|
|
|
18
19
|
value: [x, 0],
|
|
19
20
|
onChange: function onChange(value) {
|
|
20
21
|
if (type === 'hue') {
|
|
21
|
-
_onChange(value[0] * 360);
|
|
22
|
+
_onChange === null || _onChange === void 0 ? void 0 : _onChange(value[0] * 360);
|
|
22
23
|
} else {
|
|
23
|
-
_onChange(value[0]);
|
|
24
|
+
_onChange === null || _onChange === void 0 ? void 0 : _onChange(value[0]);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
onChangeComplete: function onChangeComplete(value) {
|
|
28
|
+
if (type === 'hue') {
|
|
29
|
+
_onChangeComplete === null || _onChangeComplete === void 0 ? void 0 : _onChangeComplete(value[0] * 360);
|
|
30
|
+
} else {
|
|
31
|
+
_onChangeComplete === null || _onChangeComplete === void 0 ? void 0 : _onChangeComplete(value[0]);
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
34
|
}),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ColorValueMap } from '../interface';
|
|
2
2
|
interface LinearColorPanelProps {
|
|
3
3
|
value: ColorValueMap['linear'];
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: ColorValueMap['linear']) => void;
|
|
5
|
+
onChangeComplete?: (value: ColorValueMap['linear']) => void;
|
|
5
6
|
}
|
|
6
|
-
export default function LinearColorPanel({ value, onChange, }: LinearColorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default function LinearColorPanel({ value, onChange, onChangeComplete, }: LinearColorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export {};
|
|
@@ -25,7 +25,8 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
25
25
|
export default function LinearColorPanel(_ref) {
|
|
26
26
|
var _value$stops$currentI;
|
|
27
27
|
var value = _ref.value,
|
|
28
|
-
onChange = _ref.onChange
|
|
28
|
+
onChange = _ref.onChange,
|
|
29
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
29
30
|
var _useState = useState(0),
|
|
30
31
|
_useState2 = _slicedToArray(_useState, 2),
|
|
31
32
|
currentIndex = _useState2[0],
|
|
@@ -37,12 +38,18 @@ export default function LinearColorPanel(_ref) {
|
|
|
37
38
|
useHistory({
|
|
38
39
|
value: value
|
|
39
40
|
});
|
|
40
|
-
var handleChange = function handleChange(color) {
|
|
41
|
+
var handleChange = function handleChange(color, complete) {
|
|
41
42
|
var newStops = _toConsumableArray(value.stops);
|
|
42
43
|
newStops[currentIndex].color = color;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
if (complete) {
|
|
45
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(_objectSpread(_objectSpread({}, value), {}, {
|
|
46
|
+
stops: newStops
|
|
47
|
+
}));
|
|
48
|
+
} else {
|
|
49
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
50
|
+
stops: newStops
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
46
53
|
};
|
|
47
54
|
var handleIndexSelect = function handleIndexSelect(index) {
|
|
48
55
|
setCurrentIndex(index);
|
|
@@ -52,9 +59,10 @@ export default function LinearColorPanel(_ref) {
|
|
|
52
59
|
};
|
|
53
60
|
var handleSelect = function handleSelect(val) {
|
|
54
61
|
if (typeof val === 'string') {
|
|
55
|
-
handleChange(val);
|
|
62
|
+
handleChange(val, true);
|
|
56
63
|
} else {
|
|
57
|
-
onChange(val);
|
|
64
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(val);
|
|
65
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(val);
|
|
58
66
|
}
|
|
59
67
|
setUpdateKey(function (prev) {
|
|
60
68
|
return prev + 1;
|
|
@@ -65,10 +73,14 @@ export default function LinearColorPanel(_ref) {
|
|
|
65
73
|
active: currentIndex,
|
|
66
74
|
value: value,
|
|
67
75
|
onSelect: handleIndexSelect,
|
|
68
|
-
onChange: onChange
|
|
76
|
+
onChange: onChange,
|
|
77
|
+
onChangeComplete: onChangeComplete
|
|
69
78
|
}), /*#__PURE__*/_jsx(Panel, {
|
|
70
79
|
color: (_value$stops$currentI = value.stops[currentIndex]) === null || _value$stops$currentI === void 0 ? void 0 : _value$stops$currentI.color,
|
|
71
|
-
onChange: handleChange
|
|
80
|
+
onChange: handleChange,
|
|
81
|
+
onChangeComplete: function onChangeComplete(val) {
|
|
82
|
+
return handleChange(val, true);
|
|
83
|
+
}
|
|
72
84
|
}, updateKey), /*#__PURE__*/_jsx(History, {
|
|
73
85
|
type: "linear",
|
|
74
86
|
onSelect: handleSelect
|
|
@@ -3,7 +3,8 @@ interface LinearPointsBarProps {
|
|
|
3
3
|
active: number;
|
|
4
4
|
value: ColorValueMap['linear'];
|
|
5
5
|
onSelect: (current: number) => void;
|
|
6
|
-
onChange
|
|
6
|
+
onChange?: (value: ColorValueMap['linear']) => void;
|
|
7
|
+
onChangeComplete?: (value: ColorValueMap['linear']) => void;
|
|
7
8
|
}
|
|
8
|
-
export default function LinearPointsBar({ active, value, onSelect, onChange, }: LinearPointsBarProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default function LinearPointsBar({ active, value, onSelect, onChange, onChangeComplete, }: LinearPointsBarProps): import("react/jsx-runtime").JSX.Element;
|
|
9
10
|
export {};
|
|
@@ -22,7 +22,8 @@ export default function LinearPointsBar(_ref) {
|
|
|
22
22
|
var active = _ref.active,
|
|
23
23
|
value = _ref.value,
|
|
24
24
|
onSelect = _ref.onSelect,
|
|
25
|
-
_onChange = _ref.onChange
|
|
25
|
+
_onChange = _ref.onChange,
|
|
26
|
+
_onChangeComplete = _ref.onChangeComplete;
|
|
26
27
|
var currentIndexRef = useRef(active);
|
|
27
28
|
var valueRef = useRef(value);
|
|
28
29
|
useEffect(function () {
|
|
@@ -35,7 +36,10 @@ export default function LinearPointsBar(_ref) {
|
|
|
35
36
|
if (value.stops.length <= 2) return;
|
|
36
37
|
var newStops = _toConsumableArray(value.stops);
|
|
37
38
|
newStops.splice(active, 1);
|
|
38
|
-
_onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
39
|
+
_onChange === null || _onChange === void 0 ? void 0 : _onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
40
|
+
stops: newStops
|
|
41
|
+
}));
|
|
42
|
+
_onChangeComplete === null || _onChangeComplete === void 0 ? void 0 : _onChangeComplete(_objectSpread(_objectSpread({}, value), {}, {
|
|
39
43
|
stops: newStops
|
|
40
44
|
}));
|
|
41
45
|
handleSelect(Math.max(active - 1, 0));
|
|
@@ -72,11 +76,11 @@ export default function LinearPointsBar(_ref) {
|
|
|
72
76
|
stops: [].concat(_toConsumableArray(value.stops), [newStop])
|
|
73
77
|
});
|
|
74
78
|
valueRef.current = newValue;
|
|
75
|
-
_onChange(newValue);
|
|
79
|
+
_onChange === null || _onChange === void 0 ? void 0 : _onChange(newValue);
|
|
76
80
|
handleSelect(value.stops.length);
|
|
77
81
|
}
|
|
78
82
|
} else {
|
|
79
|
-
_onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
83
|
+
_onChange === null || _onChange === void 0 ? void 0 : _onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
80
84
|
stops: valueRef.current.stops.map(function (d, i) {
|
|
81
85
|
return _objectSpread(_objectSpread({}, d), {}, {
|
|
82
86
|
offset: i === currentIndexRef.current ? val[0] * 100 : d.offset
|
|
@@ -84,6 +88,15 @@ export default function LinearPointsBar(_ref) {
|
|
|
84
88
|
})
|
|
85
89
|
}));
|
|
86
90
|
}
|
|
91
|
+
},
|
|
92
|
+
onChangeComplete: function onChangeComplete(val) {
|
|
93
|
+
_onChangeComplete === null || _onChangeComplete === void 0 ? void 0 : _onChangeComplete(_objectSpread(_objectSpread({}, value), {}, {
|
|
94
|
+
stops: valueRef.current.stops.map(function (d, i) {
|
|
95
|
+
return _objectSpread(_objectSpread({}, d), {}, {
|
|
96
|
+
offset: i === currentIndexRef.current ? val[0] * 100 : d.offset
|
|
97
|
+
});
|
|
98
|
+
})
|
|
99
|
+
}));
|
|
87
100
|
}
|
|
88
101
|
}),
|
|
89
102
|
blockRef = _useControlBlock.blockRef,
|
|
@@ -94,7 +107,10 @@ export default function LinearPointsBar(_ref) {
|
|
|
94
107
|
offset: 100 - d.offset
|
|
95
108
|
});
|
|
96
109
|
});
|
|
97
|
-
_onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
110
|
+
_onChange === null || _onChange === void 0 ? void 0 : _onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
111
|
+
stops: newStops
|
|
112
|
+
}));
|
|
113
|
+
_onChangeComplete === null || _onChangeComplete === void 0 ? void 0 : _onChangeComplete(_objectSpread(_objectSpread({}, value), {}, {
|
|
98
114
|
stops: newStops
|
|
99
115
|
}));
|
|
100
116
|
};
|
|
@@ -2,7 +2,8 @@ import { ColorType, ColorValueObj } from '../interface';
|
|
|
2
2
|
interface MixedPanelProps {
|
|
3
3
|
type: ColorType[];
|
|
4
4
|
value: ColorValueObj;
|
|
5
|
-
onChange
|
|
5
|
+
onChange?: (value: ColorValueObj) => void;
|
|
6
|
+
onChangeComplete?: (value: ColorValueObj) => void;
|
|
6
7
|
}
|
|
7
|
-
export default function MixedPanel({ type, value, onChange }: MixedPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default function MixedPanel({ type, value, onChange, onChangeComplete, }: MixedPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
8
9
|
export {};
|
|
@@ -14,14 +14,23 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
export default function MixedPanel(_ref) {
|
|
15
15
|
var type = _ref.type,
|
|
16
16
|
value = _ref.value,
|
|
17
|
-
onChange = _ref.onChange
|
|
17
|
+
onChange = _ref.onChange,
|
|
18
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
18
19
|
var handleChange = function handleChange(type) {
|
|
19
20
|
return function (newValue) {
|
|
20
|
-
onChange(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, type, newValue)));
|
|
21
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, type, newValue)));
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
var handleChangeComplete = function handleChangeComplete(type) {
|
|
25
|
+
return function (newValue) {
|
|
26
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, type, newValue)));
|
|
21
27
|
};
|
|
22
28
|
};
|
|
23
29
|
var handleTypeChange = function handleTypeChange(newType) {
|
|
24
|
-
onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
30
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
31
|
+
type: newType
|
|
32
|
+
}));
|
|
33
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(_objectSpread(_objectSpread({}, value), {}, {
|
|
25
34
|
type: newType
|
|
26
35
|
}));
|
|
27
36
|
};
|
|
@@ -31,21 +40,24 @@ export default function MixedPanel(_ref) {
|
|
|
31
40
|
{
|
|
32
41
|
return /*#__PURE__*/_jsx(PureColorPanel, {
|
|
33
42
|
value: value['pure'],
|
|
34
|
-
onChange: handleChange('pure')
|
|
43
|
+
onChange: handleChange('pure'),
|
|
44
|
+
onChangeComplete: handleChangeComplete('pure')
|
|
35
45
|
});
|
|
36
46
|
}
|
|
37
47
|
case 'pures':
|
|
38
48
|
{
|
|
39
49
|
return /*#__PURE__*/_jsx(PuresColorPanel, {
|
|
40
50
|
value: value['pures'],
|
|
41
|
-
onChange: handleChange('pures')
|
|
51
|
+
onChange: handleChange('pures'),
|
|
52
|
+
onChangeComplete: handleChangeComplete('pures')
|
|
42
53
|
});
|
|
43
54
|
}
|
|
44
55
|
case 'linear':
|
|
45
56
|
{
|
|
46
57
|
return /*#__PURE__*/_jsx(LinearColorPanel, {
|
|
47
58
|
value: value['linear'],
|
|
48
|
-
onChange: handleChange('linear')
|
|
59
|
+
onChange: handleChange('linear'),
|
|
60
|
+
onChangeComplete: handleChangeComplete('linear')
|
|
49
61
|
});
|
|
50
62
|
}
|
|
51
63
|
default:
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Color } from './interface';
|
|
2
2
|
interface PaletteProps {
|
|
3
3
|
color: Color;
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (s: number, v: number) => void;
|
|
5
|
+
onChangeComplete?: (s: number, v: number) => void;
|
|
5
6
|
}
|
|
6
|
-
export default function Palette({ color, onChange }: PaletteProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default function Palette({ color, onChange, onChangeComplete, }: PaletteProps): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export {};
|
|
@@ -3,7 +3,8 @@ import { useControlBlock } from "./hooks/useControlBlock";
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
export default function Palette(_ref) {
|
|
5
5
|
var color = _ref.color,
|
|
6
|
-
_onChange = _ref.onChange
|
|
6
|
+
_onChange = _ref.onChange,
|
|
7
|
+
_onChangeComplete = _ref.onChangeComplete;
|
|
7
8
|
var _color$hsv = color.hsv,
|
|
8
9
|
h = _color$hsv.h,
|
|
9
10
|
s = _color$hsv.s,
|
|
@@ -16,7 +17,10 @@ export default function Palette(_ref) {
|
|
|
16
17
|
var _useControlBlock = useControlBlock({
|
|
17
18
|
value: [s, 1 - v],
|
|
18
19
|
onChange: function onChange(value) {
|
|
19
|
-
return _onChange(value[0], 1 - value[1]);
|
|
20
|
+
return _onChange === null || _onChange === void 0 ? void 0 : _onChange(value[0], 1 - value[1]);
|
|
21
|
+
},
|
|
22
|
+
onChangeComplete: function onChangeComplete(value) {
|
|
23
|
+
return _onChangeComplete === null || _onChangeComplete === void 0 ? void 0 : _onChangeComplete(value[0], 1 - value[1]);
|
|
20
24
|
}
|
|
21
25
|
}),
|
|
22
26
|
blockRef = _useControlBlock.blockRef,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
interface PanelProps {
|
|
2
2
|
color: string;
|
|
3
|
-
onChange
|
|
3
|
+
onChange?: (color: string) => void;
|
|
4
|
+
onChangeComplete?: (color: string) => void;
|
|
4
5
|
}
|
|
5
|
-
export default function Panel({ color: propsColor, onChange }: PanelProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export default function Panel({ color: propsColor, onChange, onChangeComplete, }: PanelProps): import("react/jsx-runtime").JSX.Element;
|
|
6
7
|
export {};
|
|
@@ -22,7 +22,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
22
22
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
23
|
export default function Panel(_ref) {
|
|
24
24
|
var propsColor = _ref.color,
|
|
25
|
-
onChange = _ref.onChange
|
|
25
|
+
onChange = _ref.onChange,
|
|
26
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
26
27
|
var _useState = useState(function () {
|
|
27
28
|
return {
|
|
28
29
|
hsv: tinycolor(propsColor).toHsv(),
|
|
@@ -43,21 +44,33 @@ export default function Panel(_ref) {
|
|
|
43
44
|
var colorString = tinycolor(color.hsv).setAlpha(color.alpha).toRgbString();
|
|
44
45
|
var hexString = tinycolor(color.hsv).toHexString();
|
|
45
46
|
var hexRef = useRef(null);
|
|
46
|
-
var handleHsvChange = function handleHsvChange(hsv) {
|
|
47
|
+
var handleHsvChange = function handleHsvChange(hsv, complete) {
|
|
47
48
|
setColor(_objectSpread(_objectSpread({}, color), {}, {
|
|
48
49
|
hsv: hsv
|
|
49
50
|
}));
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
if (complete) {
|
|
52
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
|
|
53
|
+
a: color.alpha
|
|
54
|
+
})).toRgbString());
|
|
55
|
+
} else {
|
|
56
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
|
|
57
|
+
a: color.alpha
|
|
58
|
+
})).toRgbString());
|
|
59
|
+
}
|
|
53
60
|
};
|
|
54
|
-
var handleAlphaChange = function handleAlphaChange(alpha) {
|
|
61
|
+
var handleAlphaChange = function handleAlphaChange(alpha, complete) {
|
|
55
62
|
setColor(_objectSpread(_objectSpread({}, color), {}, {
|
|
56
63
|
alpha: alpha
|
|
57
64
|
}));
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
if (complete) {
|
|
66
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(tinycolor(_objectSpread(_objectSpread({}, color.hsv), {}, {
|
|
67
|
+
a: alpha
|
|
68
|
+
})).toRgbString());
|
|
69
|
+
} else {
|
|
70
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(tinycolor(_objectSpread(_objectSpread({}, color.hsv), {}, {
|
|
71
|
+
a: alpha
|
|
72
|
+
})).toRgbString());
|
|
73
|
+
}
|
|
61
74
|
};
|
|
62
75
|
var handleHexChange = function handleHexChange(val) {
|
|
63
76
|
var hexVal = getHexValue(val);
|
|
@@ -67,7 +80,7 @@ export default function Panel(_ref) {
|
|
|
67
80
|
setColor(_objectSpread(_objectSpread({}, color), {}, {
|
|
68
81
|
hsv: hsv
|
|
69
82
|
}));
|
|
70
|
-
|
|
83
|
+
onChangeWithComplete(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
|
|
71
84
|
a: color.alpha
|
|
72
85
|
})).toRgbString());
|
|
73
86
|
};
|
|
@@ -80,7 +93,7 @@ export default function Panel(_ref) {
|
|
|
80
93
|
setColor(_objectSpread(_objectSpread({}, color), {}, {
|
|
81
94
|
hsv: hsv
|
|
82
95
|
}));
|
|
83
|
-
|
|
96
|
+
onChangeWithComplete(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
|
|
84
97
|
a: color.alpha
|
|
85
98
|
})).toRgbString());
|
|
86
99
|
};
|
|
@@ -89,7 +102,11 @@ export default function Panel(_ref) {
|
|
|
89
102
|
hsv: tinycolor(color).toHsv(),
|
|
90
103
|
alpha: 1
|
|
91
104
|
});
|
|
92
|
-
|
|
105
|
+
onChangeWithComplete(color);
|
|
106
|
+
};
|
|
107
|
+
var onChangeWithComplete = function onChangeWithComplete(color) {
|
|
108
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(color);
|
|
109
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(color);
|
|
93
110
|
};
|
|
94
111
|
return /*#__PURE__*/_jsxs("div", {
|
|
95
112
|
className: "colors-picker-panel",
|
|
@@ -101,6 +118,13 @@ export default function Panel(_ref) {
|
|
|
101
118
|
s: newS,
|
|
102
119
|
v: newV
|
|
103
120
|
});
|
|
121
|
+
},
|
|
122
|
+
onChangeComplete: function onChangeComplete(newS, newV) {
|
|
123
|
+
return handleHsvChange({
|
|
124
|
+
h: h,
|
|
125
|
+
s: newS,
|
|
126
|
+
v: newV
|
|
127
|
+
}, true);
|
|
104
128
|
}
|
|
105
129
|
}), /*#__PURE__*/_jsxs("div", {
|
|
106
130
|
className: "colors-picker-control-wrapper",
|
|
@@ -125,11 +149,21 @@ export default function Panel(_ref) {
|
|
|
125
149
|
s: s,
|
|
126
150
|
v: v
|
|
127
151
|
});
|
|
152
|
+
},
|
|
153
|
+
onChangeComplete: function onChangeComplete(newH) {
|
|
154
|
+
return handleHsvChange({
|
|
155
|
+
h: newH,
|
|
156
|
+
s: s,
|
|
157
|
+
v: v
|
|
158
|
+
}, true);
|
|
128
159
|
}
|
|
129
160
|
}), /*#__PURE__*/_jsx(ControlBar, {
|
|
130
161
|
type: "alpha",
|
|
131
162
|
color: color,
|
|
132
|
-
onChange: handleAlphaChange
|
|
163
|
+
onChange: handleAlphaChange,
|
|
164
|
+
onChangeComplete: function onChangeComplete(val) {
|
|
165
|
+
return handleAlphaChange(val, true);
|
|
166
|
+
}
|
|
133
167
|
})]
|
|
134
168
|
}), /*#__PURE__*/_jsx(Preview, {
|
|
135
169
|
type: "pure",
|
|
@@ -212,7 +246,7 @@ export default function Panel(_ref) {
|
|
|
212
246
|
return +val >= 0 && +val <= 100;
|
|
213
247
|
},
|
|
214
248
|
onChange: function onChange(val) {
|
|
215
|
-
return handleAlphaChange(+val / 100);
|
|
249
|
+
return handleAlphaChange(+val / 100, true);
|
|
216
250
|
}
|
|
217
251
|
}), /*#__PURE__*/_jsx("span", {
|
|
218
252
|
className: "colors-picker-input-label",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
interface PureColorInputProps {
|
|
2
2
|
value: string;
|
|
3
3
|
onTrigger: () => void;
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (val: string) => void;
|
|
5
5
|
}
|
|
6
6
|
export default function PureColorInput({ value, onChange, onTrigger, }: PureColorInputProps): import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export {};
|
|
@@ -18,11 +18,11 @@ export default function PureColorInput(_ref) {
|
|
|
18
18
|
var hexString = tinycolor(hsv).toHexString();
|
|
19
19
|
hexRef.current.forceUpdate(hexString.slice(1).toUpperCase());
|
|
20
20
|
var newColor = tinycolor(hexString).setAlpha(alpha).toRgbString();
|
|
21
|
-
onChange(newColor);
|
|
21
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newColor);
|
|
22
22
|
};
|
|
23
23
|
var handleAlphaChange = function handleAlphaChange(val) {
|
|
24
24
|
var newColor = tinycolor(hexString).setAlpha(val).toRgbString();
|
|
25
|
-
onChange(newColor);
|
|
25
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newColor);
|
|
26
26
|
};
|
|
27
27
|
return /*#__PURE__*/_jsxs("div", {
|
|
28
28
|
className: "pure-color-picker",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ColorValueMap } from '../interface';
|
|
2
2
|
interface PureColorPanelProps {
|
|
3
3
|
value: ColorValueMap['pure'];
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: ColorValueMap['pure']) => void;
|
|
5
|
+
onChangeComplete?: (value: ColorValueMap['pure']) => void;
|
|
5
6
|
}
|
|
6
|
-
export default function PureColorPanel({ value, onChange, }: PureColorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default function PureColorPanel({ value, onChange, onChangeComplete, }: PureColorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export {};
|
|
@@ -13,13 +13,15 @@ import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
|
13
13
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
export default function PureColorPanel(_ref) {
|
|
15
15
|
var value = _ref.value,
|
|
16
|
-
onChange = _ref.onChange
|
|
16
|
+
onChange = _ref.onChange,
|
|
17
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
17
18
|
var _useState = useState(0),
|
|
18
19
|
_useState2 = _slicedToArray(_useState, 2),
|
|
19
20
|
updateKey = _useState2[0],
|
|
20
21
|
setUpdateKey = _useState2[1];
|
|
21
22
|
var handleSelect = function handleSelect(val) {
|
|
22
|
-
onChange(val);
|
|
23
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(val);
|
|
24
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(val);
|
|
23
25
|
setUpdateKey(function (prev) {
|
|
24
26
|
return prev + 1;
|
|
25
27
|
});
|
|
@@ -30,7 +32,8 @@ export default function PureColorPanel(_ref) {
|
|
|
30
32
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
31
33
|
children: [/*#__PURE__*/_jsx(Panel, {
|
|
32
34
|
color: value,
|
|
33
|
-
onChange: onChange
|
|
35
|
+
onChange: onChange,
|
|
36
|
+
onChangeComplete: onChangeComplete
|
|
34
37
|
}, updateKey), /*#__PURE__*/_jsx(History, {
|
|
35
38
|
type: "pure",
|
|
36
39
|
onSelect: handleSelect
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ColorValueMap } from '../interface';
|
|
2
2
|
interface PuresColorPanelProps {
|
|
3
3
|
value: ColorValueMap['pures'];
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: ColorValueMap['pures']) => void;
|
|
5
|
+
onChangeComplete?: (value: ColorValueMap['pures']) => void;
|
|
5
6
|
}
|
|
6
|
-
export default function PuresColorPanel({ value, onChange, }: PuresColorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default function PuresColorPanel({ value, onChange, onChangeComplete, }: PuresColorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export {};
|
|
@@ -18,7 +18,8 @@ import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
|
18
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
19
|
export default function PuresColorPanel(_ref) {
|
|
20
20
|
var value = _ref.value,
|
|
21
|
-
onChange = _ref.onChange
|
|
21
|
+
onChange = _ref.onChange,
|
|
22
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
22
23
|
var _useState = useState(0),
|
|
23
24
|
_useState2 = _slicedToArray(_useState, 2),
|
|
24
25
|
currentIndex = _useState2[0],
|
|
@@ -34,16 +35,25 @@ export default function PuresColorPanel(_ref) {
|
|
|
34
35
|
var handleChange = function handleChange(color) {
|
|
35
36
|
var newValue = _toConsumableArray(value);
|
|
36
37
|
newValue[currentIndex] = color;
|
|
37
|
-
onChange(newValue);
|
|
38
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
39
|
+
};
|
|
40
|
+
var handleChangeComplete = function handleChangeComplete(color) {
|
|
41
|
+
var newValue = _toConsumableArray(value);
|
|
42
|
+
newValue[currentIndex] = color;
|
|
43
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(newValue);
|
|
38
44
|
};
|
|
39
45
|
var handleAdd = function handleAdd() {
|
|
40
|
-
onChange(value.concat('#000000'));
|
|
46
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value.concat('#000000'));
|
|
47
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(value.concat('#000000'));
|
|
41
48
|
setCurrentIndex(value.length);
|
|
42
49
|
setUpdateKey(updateKey + 1);
|
|
43
50
|
};
|
|
44
51
|
var handleDelete = function handleDelete() {
|
|
45
52
|
if (value.length > 1) {
|
|
46
|
-
onChange(value.filter(function (_, index) {
|
|
53
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value.filter(function (_, index) {
|
|
54
|
+
return index !== currentIndex;
|
|
55
|
+
}));
|
|
56
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(value.filter(function (_, index) {
|
|
47
57
|
return index !== currentIndex;
|
|
48
58
|
}));
|
|
49
59
|
setCurrentIndex(currentIndex > 0 ? currentIndex - 1 : 0);
|
|
@@ -57,7 +67,8 @@ export default function PuresColorPanel(_ref) {
|
|
|
57
67
|
var handleHistorySelect = function handleHistorySelect(val) {
|
|
58
68
|
var newValue = _toConsumableArray(value);
|
|
59
69
|
newValue[currentIndex] = val;
|
|
60
|
-
onChange(newValue);
|
|
70
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
71
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(newValue);
|
|
61
72
|
setUpdateKey(updateKey + 1);
|
|
62
73
|
};
|
|
63
74
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
@@ -69,7 +80,8 @@ export default function PuresColorPanel(_ref) {
|
|
|
69
80
|
onSelect: handleSelect
|
|
70
81
|
}), /*#__PURE__*/_jsx(Panel, {
|
|
71
82
|
color: value[currentIndex],
|
|
72
|
-
onChange: handleChange
|
|
83
|
+
onChange: handleChange,
|
|
84
|
+
onChangeComplete: handleChangeComplete
|
|
73
85
|
}, updateKey), /*#__PURE__*/_jsx(History, {
|
|
74
86
|
type: "pure",
|
|
75
87
|
onSelect: handleHistorySelect
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ColorValueMap } from '../interface';
|
|
2
2
|
interface RangeColorPanelProps {
|
|
3
3
|
value: ColorValueMap['range'];
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: ColorValueMap['range']) => void;
|
|
5
|
+
onChangeComplete?: (value: ColorValueMap['range']) => void;
|
|
5
6
|
}
|
|
6
|
-
export default function RangeColorPanel({ value, onChange, }: RangeColorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default function RangeColorPanel({ value, onChange, onChangeComplete, }: RangeColorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export {};
|
|
@@ -17,7 +17,8 @@ import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
|
17
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
18
|
export default function RangeColorPanel(_ref) {
|
|
19
19
|
var value = _ref.value,
|
|
20
|
-
onChange = _ref.onChange
|
|
20
|
+
onChange = _ref.onChange,
|
|
21
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
21
22
|
var _useState = useState(0),
|
|
22
23
|
_useState2 = _slicedToArray(_useState, 2),
|
|
23
24
|
currentIndex = _useState2[0],
|
|
@@ -26,17 +27,21 @@ export default function RangeColorPanel(_ref) {
|
|
|
26
27
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
27
28
|
updateKey = _useState4[0],
|
|
28
29
|
setUpdateKey = _useState4[1];
|
|
29
|
-
var handleChange = function handleChange(newValue) {
|
|
30
|
+
var handleChange = function handleChange(newValue, complete) {
|
|
30
31
|
var newValueArray = _toConsumableArray(value);
|
|
31
32
|
newValueArray[currentIndex] = newValue;
|
|
32
|
-
|
|
33
|
+
if (complete) {
|
|
34
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(newValueArray);
|
|
35
|
+
} else {
|
|
36
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValueArray);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var handleSelect = function handleSelect(val) {
|
|
40
|
+
handleChange(val, true);
|
|
33
41
|
setUpdateKey(function (prev) {
|
|
34
42
|
return prev + 1;
|
|
35
43
|
});
|
|
36
44
|
};
|
|
37
|
-
var handleSelect = function handleSelect(val) {
|
|
38
|
-
handleChange(val);
|
|
39
|
-
};
|
|
40
45
|
var handleIndexSelect = function handleIndexSelect(index) {
|
|
41
46
|
setCurrentIndex(index);
|
|
42
47
|
setUpdateKey(function (prev) {
|
|
@@ -50,7 +55,10 @@ export default function RangeColorPanel(_ref) {
|
|
|
50
55
|
onSelect: handleIndexSelect
|
|
51
56
|
}), /*#__PURE__*/_jsx(Panel, {
|
|
52
57
|
color: value[currentIndex],
|
|
53
|
-
onChange: handleChange
|
|
58
|
+
onChange: handleChange,
|
|
59
|
+
onChangeComplete: function onChangeComplete(val) {
|
|
60
|
+
return handleChange(val, true);
|
|
61
|
+
}
|
|
54
62
|
}, updateKey), /*#__PURE__*/_jsx(History, {
|
|
55
63
|
type: "pure",
|
|
56
64
|
onSelect: handleSelect
|
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function useColorsPicker<T extends ColorsPickerType>(props: ColorsPickerProps<T>): ColorsPickerProps<T
|
|
3
|
-
type: string | T;
|
|
4
|
-
value: string;
|
|
5
|
-
onChange: (value: T extends import("../interface").ColorType ? import("../interface").ColorValueMap[T] : ColorValueObj) => void;
|
|
6
|
-
} | {
|
|
7
|
-
type: T;
|
|
8
|
-
value: string[];
|
|
9
|
-
onChange: (value: T extends import("../interface").ColorType ? import("../interface").ColorValueMap[T] : ColorValueObj) => void;
|
|
10
|
-
} | {
|
|
11
|
-
type: T;
|
|
12
|
-
value: {
|
|
13
|
-
stops: {
|
|
14
|
-
color: string;
|
|
15
|
-
offset: number;
|
|
16
|
-
}[];
|
|
17
|
-
angle: number;
|
|
18
|
-
opacity: number;
|
|
19
|
-
};
|
|
20
|
-
onChange: (value: T extends import("../interface").ColorType ? import("../interface").ColorValueMap[T] : ColorValueObj) => void;
|
|
21
|
-
} | {
|
|
22
|
-
type: T & any[];
|
|
23
|
-
value: {};
|
|
24
|
-
onChange: (value: T extends import("../interface").ColorType ? import("../interface").ColorValueMap[T] : ColorValueObj) => void;
|
|
25
|
-
};
|
|
1
|
+
import { ColorsPickerProps, ColorsPickerType } from '../interface';
|
|
2
|
+
export default function useColorsPicker<T extends ColorsPickerType>(props: ColorsPickerProps<T>): ColorsPickerProps<T>;
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
var _excluded = ["type", "value"];
|
|
1
|
+
var _excluded = ["type", "value", "onChange"];
|
|
2
2
|
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); }
|
|
3
3
|
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; }
|
|
4
4
|
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; }
|
|
5
5
|
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; }
|
|
6
6
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
7
|
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); }
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
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."); }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
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; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
14
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
10
17
|
var defaultValues = {
|
|
11
18
|
pure: '#000000',
|
|
12
19
|
pures: ['#ffffff', '#000000'],
|
|
@@ -20,18 +27,32 @@ var defaultValues = {
|
|
|
20
27
|
}],
|
|
21
28
|
angle: 0,
|
|
22
29
|
opacity: 1
|
|
23
|
-
}
|
|
30
|
+
},
|
|
31
|
+
range: ['#ffffff', '#000000']
|
|
24
32
|
};
|
|
25
33
|
export default function useColorsPicker(props) {
|
|
26
34
|
var _props$type = props.type,
|
|
27
35
|
type = _props$type === void 0 ? 'pure' : _props$type,
|
|
28
36
|
value = props.value,
|
|
37
|
+
onChange = props.onChange,
|
|
29
38
|
rest = _objectWithoutProperties(props, _excluded);
|
|
39
|
+
var _useState = useState(value),
|
|
40
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
41
|
+
localValue = _useState2[0],
|
|
42
|
+
setLocalValue = _useState2[1];
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
setLocalValue(value);
|
|
45
|
+
}, [value]);
|
|
46
|
+
var handleChange = useCallback(function (val) {
|
|
47
|
+
setLocalValue(val);
|
|
48
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(val);
|
|
49
|
+
}, [onChange]);
|
|
30
50
|
if (type === 'pure') {
|
|
31
51
|
if (!value || typeof value !== 'string') {
|
|
32
52
|
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
33
53
|
type: type,
|
|
34
|
-
value: defaultValues.pure
|
|
54
|
+
value: defaultValues.pure,
|
|
55
|
+
onChange: handleChange
|
|
35
56
|
});
|
|
36
57
|
}
|
|
37
58
|
} else if (type === 'pures') {
|
|
@@ -40,14 +61,16 @@ export default function useColorsPicker(props) {
|
|
|
40
61
|
})) {
|
|
41
62
|
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
42
63
|
type: type,
|
|
43
|
-
value: defaultValues.pures
|
|
64
|
+
value: defaultValues.pures,
|
|
65
|
+
onChange: handleChange
|
|
44
66
|
});
|
|
45
67
|
}
|
|
46
68
|
} else if (type === 'linear') {
|
|
47
69
|
if (!value || _typeof(value) !== 'object') {
|
|
48
70
|
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
49
71
|
type: type,
|
|
50
|
-
value: defaultValues.linear
|
|
72
|
+
value: defaultValues.linear,
|
|
73
|
+
onChange: handleChange
|
|
51
74
|
});
|
|
52
75
|
}
|
|
53
76
|
} else if (Array.isArray(type)) {
|
|
@@ -56,7 +79,8 @@ export default function useColorsPicker(props) {
|
|
|
56
79
|
type: type,
|
|
57
80
|
value: type.reduce(function (all, cur) {
|
|
58
81
|
return all[cur] = defaultValues[cur];
|
|
59
|
-
}, {})
|
|
82
|
+
}, {}),
|
|
83
|
+
onChange: handleChange
|
|
60
84
|
});
|
|
61
85
|
} else if (type.some(function (d) {
|
|
62
86
|
return !value[d];
|
|
@@ -70,9 +94,13 @@ export default function useColorsPicker(props) {
|
|
|
70
94
|
});
|
|
71
95
|
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
72
96
|
type: type,
|
|
73
|
-
value: newValue
|
|
97
|
+
value: newValue,
|
|
98
|
+
onChange: handleChange
|
|
74
99
|
});
|
|
75
100
|
}
|
|
76
101
|
}
|
|
77
|
-
return props
|
|
102
|
+
return _objectSpread(_objectSpread({}, props), {}, {
|
|
103
|
+
value: localValue,
|
|
104
|
+
onChange: handleChange
|
|
105
|
+
});
|
|
78
106
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
interface UsePaletteControlProps {
|
|
3
3
|
value: [number, number];
|
|
4
|
-
onChange?: (value: [number, number], e: MouseEvent | React.MouseEvent
|
|
4
|
+
onChange?: (value: [number, number], e: MouseEvent | React.MouseEvent) => void;
|
|
5
|
+
onChangeComplete?: (value: [number, number]) => void;
|
|
5
6
|
}
|
|
6
|
-
export declare function useControlBlock({ value, onChange }: UsePaletteControlProps): {
|
|
7
|
+
export declare function useControlBlock({ value, onChange, onChangeComplete, }: UsePaletteControlProps): {
|
|
7
8
|
active: boolean;
|
|
8
9
|
blockRef: React.RefObject<HTMLDivElement>;
|
|
9
10
|
onMouseDown: (ev: React.MouseEvent) => void;
|
|
@@ -7,7 +7,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
7
7
|
import { useRef, useState } from 'react';
|
|
8
8
|
export function useControlBlock(_ref) {
|
|
9
9
|
var value = _ref.value,
|
|
10
|
-
onChange = _ref.onChange
|
|
10
|
+
onChange = _ref.onChange,
|
|
11
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
11
12
|
var _useState = useState(false),
|
|
12
13
|
_useState2 = _slicedToArray(_useState, 2),
|
|
13
14
|
active = _useState2[0],
|
|
@@ -22,13 +23,17 @@ export function useControlBlock(_ref) {
|
|
|
22
23
|
}
|
|
23
24
|
return value / max;
|
|
24
25
|
};
|
|
25
|
-
var setCurrentPosition = function setCurrentPosition(ev
|
|
26
|
+
var setCurrentPosition = function setCurrentPosition(ev) {
|
|
26
27
|
var clientX = ev.clientX,
|
|
27
28
|
clientY = ev.clientY;
|
|
28
29
|
var rect = blockRef.current.getBoundingClientRect();
|
|
29
30
|
var newValue = [getPercentNumber(clientX - rect.x, rect.width), getPercentNumber(clientY - rect.y, rect.height)];
|
|
30
31
|
if (newValue[0] !== value[0] || newValue[1] !== value[1]) {
|
|
31
|
-
|
|
32
|
+
if (ev.type === 'mouseup') {
|
|
33
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(newValue);
|
|
34
|
+
} else {
|
|
35
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ev);
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
};
|
|
34
39
|
function onMouseMove(ev) {
|
|
@@ -39,7 +44,10 @@ export function useControlBlock(_ref) {
|
|
|
39
44
|
removeListener();
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
|
-
var removeListener = function removeListener() {
|
|
47
|
+
var removeListener = function removeListener(e) {
|
|
48
|
+
if ((e === null || e === void 0 ? void 0 : e.type) === 'mouseup') {
|
|
49
|
+
setCurrentPosition(e);
|
|
50
|
+
}
|
|
43
51
|
setActive(false);
|
|
44
52
|
window.removeEventListener('mousemove', onMouseMove);
|
|
45
53
|
window.removeEventListener('mouseup', removeListener);
|
|
@@ -48,7 +56,7 @@ export function useControlBlock(_ref) {
|
|
|
48
56
|
var onMouseDown = function onMouseDown(ev) {
|
|
49
57
|
ev.stopPropagation();
|
|
50
58
|
setActive(true);
|
|
51
|
-
setCurrentPosition(ev
|
|
59
|
+
setCurrentPosition(ev);
|
|
52
60
|
window.addEventListener('mousemove', onMouseMove);
|
|
53
61
|
window.addEventListener('mouseup', removeListener);
|
|
54
62
|
window.addEventListener('contextmenu', removeListener);
|
|
@@ -25,7 +25,8 @@ function ColorsPicker(props) {
|
|
|
25
25
|
var _useColorsPicker = useColorsPicker(props),
|
|
26
26
|
type = _useColorsPicker.type,
|
|
27
27
|
value = _useColorsPicker.value,
|
|
28
|
-
onChange = _useColorsPicker.onChange
|
|
28
|
+
onChange = _useColorsPicker.onChange,
|
|
29
|
+
onChangeComplete = _useColorsPicker.onChangeComplete;
|
|
29
30
|
var _useState = useState(false),
|
|
30
31
|
_useState2 = _slicedToArray(_useState, 2),
|
|
31
32
|
visible = _useState2[0],
|
|
@@ -34,9 +35,13 @@ function ColorsPicker(props) {
|
|
|
34
35
|
switch (type) {
|
|
35
36
|
case 'pure':
|
|
36
37
|
{
|
|
38
|
+
var handleChange = function handleChange(val) {
|
|
39
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(val);
|
|
40
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(val);
|
|
41
|
+
};
|
|
37
42
|
return /*#__PURE__*/_jsx(PureColorInput, {
|
|
38
43
|
value: value,
|
|
39
|
-
onChange:
|
|
44
|
+
onChange: handleChange,
|
|
40
45
|
onTrigger: function onTrigger() {
|
|
41
46
|
return setVisible(!visible);
|
|
42
47
|
}
|
|
@@ -53,9 +58,13 @@ function ColorsPicker(props) {
|
|
|
53
58
|
}
|
|
54
59
|
case 'linear':
|
|
55
60
|
{
|
|
61
|
+
var _handleChange = function _handleChange(val) {
|
|
62
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(val);
|
|
63
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(val);
|
|
64
|
+
};
|
|
56
65
|
return /*#__PURE__*/_jsx(LinearColorInput, {
|
|
57
66
|
value: value,
|
|
58
|
-
onChange:
|
|
67
|
+
onChange: _handleChange,
|
|
59
68
|
onTrigger: function onTrigger() {
|
|
60
69
|
return setVisible(!visible);
|
|
61
70
|
}
|
|
@@ -74,7 +83,10 @@ function ColorsPicker(props) {
|
|
|
74
83
|
{
|
|
75
84
|
if (Array.isArray(type)) {
|
|
76
85
|
var val = value;
|
|
77
|
-
var onValueChange =
|
|
86
|
+
var onValueChange = function onValueChange(val) {
|
|
87
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(val);
|
|
88
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(val);
|
|
89
|
+
};
|
|
78
90
|
if (val.type === 'pure') {
|
|
79
91
|
return /*#__PURE__*/_jsx(PureColorInput, {
|
|
80
92
|
value: val.pure,
|
|
@@ -126,28 +138,32 @@ function ColorsPicker(props) {
|
|
|
126
138
|
{
|
|
127
139
|
return /*#__PURE__*/_jsx(PureColorPanel, {
|
|
128
140
|
value: value,
|
|
129
|
-
onChange: onChange
|
|
141
|
+
onChange: onChange,
|
|
142
|
+
onChangeComplete: onChangeComplete
|
|
130
143
|
});
|
|
131
144
|
}
|
|
132
145
|
case 'pures':
|
|
133
146
|
{
|
|
134
147
|
return /*#__PURE__*/_jsx(PuresColorPanel, {
|
|
135
148
|
value: value,
|
|
136
|
-
onChange: onChange
|
|
149
|
+
onChange: onChange,
|
|
150
|
+
onChangeComplete: onChangeComplete
|
|
137
151
|
});
|
|
138
152
|
}
|
|
139
153
|
case 'linear':
|
|
140
154
|
{
|
|
141
155
|
return /*#__PURE__*/_jsx(LinearColorPanel, {
|
|
142
156
|
value: value,
|
|
143
|
-
onChange: onChange
|
|
157
|
+
onChange: onChange,
|
|
158
|
+
onChangeComplete: onChangeComplete
|
|
144
159
|
});
|
|
145
160
|
}
|
|
146
161
|
case 'range':
|
|
147
162
|
{
|
|
148
163
|
return /*#__PURE__*/_jsx(RangeColorPanel, {
|
|
149
164
|
value: value,
|
|
150
|
-
onChange: onChange
|
|
165
|
+
onChange: onChange,
|
|
166
|
+
onChangeComplete: onChangeComplete
|
|
151
167
|
});
|
|
152
168
|
}
|
|
153
169
|
default:
|
|
@@ -156,7 +172,8 @@ function ColorsPicker(props) {
|
|
|
156
172
|
return /*#__PURE__*/_jsx(MixedPanel, {
|
|
157
173
|
type: type,
|
|
158
174
|
value: value,
|
|
159
|
-
onChange: onChange
|
|
175
|
+
onChange: onChange,
|
|
176
|
+
onChangeComplete: onChangeComplete
|
|
160
177
|
});
|
|
161
178
|
}
|
|
162
179
|
console.error('unknown color picker type');
|
|
@@ -33,7 +33,8 @@ export declare type ColorsPickerType = ColorType | ColorType[];
|
|
|
33
33
|
export interface ColorsPickerProps<T extends ColorsPickerType> {
|
|
34
34
|
type: T;
|
|
35
35
|
value: T extends ColorType ? ColorValueMap[T] : ColorValueObj;
|
|
36
|
-
onChange
|
|
36
|
+
onChange?: (value: T extends ColorType ? ColorValueMap[T] : ColorValueObj) => void;
|
|
37
|
+
onChangeComplete?: (value: T extends ColorType ? ColorValueMap[T] : ColorValueObj) => void;
|
|
37
38
|
}
|
|
38
39
|
export interface ColorValueMap {
|
|
39
40
|
pure: string;
|
|
@@ -313,6 +313,16 @@
|
|
|
313
313
|
.pure-color-picker {
|
|
314
314
|
display: flex;
|
|
315
315
|
gap: 12px;
|
|
316
|
+
|
|
317
|
+
.pure-color-picker-hex {
|
|
318
|
+
font-size: 12px;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.pure-color-picker-alpha {
|
|
322
|
+
width: 64px;
|
|
323
|
+
flex-shrink: 0;
|
|
324
|
+
font-size: 12px;
|
|
325
|
+
}
|
|
316
326
|
}
|
|
317
327
|
|
|
318
328
|
.pure-color-picker-preview {
|
|
@@ -348,16 +358,6 @@
|
|
|
348
358
|
}
|
|
349
359
|
}
|
|
350
360
|
|
|
351
|
-
.pure-color-picker-hex {
|
|
352
|
-
font-size: 12px;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
.pure-color-picker-alpha {
|
|
356
|
-
width: 64px;
|
|
357
|
-
flex-shrink: 0;
|
|
358
|
-
font-size: 12px;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
361
|
// 多种类型的颜色选择 Tab
|
|
362
362
|
.colors-picker-tabs {
|
|
363
363
|
padding: 10px 12px;
|