@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.
Files changed (41) hide show
  1. package/dist/Color/Preview.d.ts +8 -0
  2. package/dist/Color/Preview.js +78 -0
  3. package/dist/Color/Preview.less +48 -0
  4. package/dist/Color/index.d.ts +2 -0
  5. package/dist/Color/index.js +69 -0
  6. package/dist/Color/interface.d.ts +5 -0
  7. package/dist/Color/interface.js +1 -0
  8. package/dist/ColorPicker/Panel.d.ts +11 -0
  9. package/dist/ColorPicker/Panel.js +46 -0
  10. package/dist/ColorPicker/Panel.less +159 -0
  11. package/dist/ColorPicker/index.d.ts +9 -3
  12. package/dist/ColorPicker/index.js +265 -44
  13. package/dist/ColorPicker/index.less +194 -132
  14. package/dist/ColorPicker/utils.d.ts +16 -6
  15. package/dist/ColorPicker/utils.js +86 -40
  16. package/dist/RangeColor/Panel.d.ts +9 -0
  17. package/dist/RangeColor/Panel.js +187 -0
  18. package/dist/RangeColor/Panel.less +0 -0
  19. package/dist/RangeColor/Points.d.ts +2 -0
  20. package/dist/RangeColor/Points.js +88 -0
  21. package/dist/RangeColor/index.d.ts +3 -0
  22. package/dist/RangeColor/index.js +76 -0
  23. package/dist/RangeColor/index.less +49 -0
  24. package/dist/RangeColor/interface.d.ts +8 -0
  25. package/dist/RangeColor/interface.js +1 -0
  26. package/dist/SpaceModal/index.d.ts +5 -0
  27. package/dist/SpaceModal/index.js +19 -0
  28. package/dist/SpaceModal/index.less +5 -0
  29. package/dist/hooks/index.d.ts +2 -0
  30. package/dist/hooks/index.js +2 -0
  31. package/dist/hooks/useClickOutside.d.ts +1 -0
  32. package/dist/hooks/useClickOutside.js +16 -0
  33. package/dist/hooks/useEventListener.d.ts +1 -0
  34. package/dist/hooks/useEventListener.js +19 -0
  35. package/dist/index.css +4 -0
  36. package/dist/index.d.ts +2 -1
  37. package/dist/index.js +4 -1
  38. package/package.json +2 -2
  39. package/dist/ColorPicker/ColorPreview.d.ts +0 -19
  40. package/dist/ColorPicker/ColorPreview.js +0 -27
  41. package/dist/ColorPicker/ColorPreview.less +0 -5
@@ -0,0 +1,8 @@
1
+ import './Preview.less';
2
+ interface PreviewProps {
3
+ mode?: 'multi';
4
+ value: string;
5
+ onChange: (color: string) => void;
6
+ }
7
+ export default function Preview({ mode, value, onChange }: PreviewProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,78 @@
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 "../ColorPicker";
9
+ import { getBackgroundAccordingColor } from "../ColorPicker/utils";
10
+ import "./Preview.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 Preview(_ref) {
15
+ var mode = _ref.mode,
16
+ value = _ref.value,
17
+ onChange = _ref.onChange;
18
+ var _useState = useState(false),
19
+ _useState2 = _slicedToArray(_useState, 2),
20
+ show = _useState2[0],
21
+ setShow = _useState2[1];
22
+ var _useState3 = useState({
23
+ x: 0,
24
+ y: 0
25
+ }),
26
+ _useState4 = _slicedToArray(_useState3, 2),
27
+ position = _useState4[0],
28
+ setPosition = _useState4[1];
29
+ var previewRef = useRef(null);
30
+ var pickerRef = useRef(null);
31
+ var deferedShow = useDeferredValue(show);
32
+ var handleClick = function handleClick() {
33
+ setShow(true);
34
+ };
35
+ var handleHide = function handleHide() {
36
+ setShow(false);
37
+ };
38
+ var handleColorChange = function handleColorChange(value) {
39
+ onChange(value);
40
+ };
41
+ useEffect(function () {
42
+ if (deferedShow) {
43
+ var targetRect = previewRef.current.getBoundingClientRect();
44
+ var pickerRect = pickerRef.current.getBoundingClientRect();
45
+ var windowHeight = document.documentElement.clientHeight;
46
+ var windowWidth = document.documentElement.clientWidth;
47
+ var hexDOM = pickerRef.current.querySelector('.rc-color-picker-panel-params-hex');
48
+ if (hexDOM) {
49
+ hexDOM.focus();
50
+ hexDOM.select();
51
+ }
52
+ var top = windowHeight - targetRect.bottom < pickerRect.height ? targetRect.top - pickerRect.height < 0 ? 0 : targetRect.top - pickerRect.height : targetRect.bottom;
53
+ var left = windowWidth - targetRect.left < pickerRect.width ? windowWidth - pickerRect.width : targetRect.left;
54
+ setPosition({
55
+ x: left,
56
+ y: top
57
+ });
58
+ }
59
+ }, [deferedShow]);
60
+ return /*#__PURE__*/_jsxs(_Fragment, {
61
+ children: [/*#__PURE__*/_jsx("span", {
62
+ className: 'arco-color-preview',
63
+ onClick: handleClick,
64
+ ref: previewRef,
65
+ children: /*#__PURE__*/_jsx("span", {
66
+ className: 'arco-color-inner',
67
+ style: getBackgroundAccordingColor(value)
68
+ })
69
+ }), deferedShow && /*#__PURE__*/_jsx(ColorPicker, {
70
+ ref: pickerRef,
71
+ mode: mode,
72
+ color: value,
73
+ position: position,
74
+ onCancel: handleHide,
75
+ onChange: handleColorChange
76
+ })]
77
+ });
78
+ }
@@ -0,0 +1,48 @@
1
+ .arco-color-preview {
2
+ position: relative;
3
+ width: 28px;
4
+ height: 28px;
5
+ border-radius: 4px;
6
+ border: 1px solid var(--color-border-2);
7
+ padding: 6px;
8
+ display: flex;
9
+ align-items: center;
10
+ justify-content: center;
11
+ background-color: var(--color-bg-1);
12
+ cursor: pointer;
13
+
14
+ &::before {
15
+ content: '';
16
+ position: absolute;
17
+ left: 6px;
18
+ right: 6px;
19
+ top: 6px;
20
+ bottom: 6px;
21
+ border-radius: 2px;
22
+ background-image: linear-gradient(
23
+ 45deg,
24
+ #404040 25%,
25
+ transparent 0,
26
+ transparent 75%,
27
+ #404040 0
28
+ ),
29
+ linear-gradient(
30
+ 45deg,
31
+ #404040 25%,
32
+ transparent 0,
33
+ transparent 75%,
34
+ #404040 0
35
+ );
36
+ background-color: #4a4a4a;
37
+ background-size: 10px 10px;
38
+ background-position: 0 0, 5px 5px;
39
+ }
40
+
41
+ .arco-color-inner {
42
+ width: 100%;
43
+ height: 100%;
44
+ border-radius: 2px;
45
+ position: relative;
46
+ z-index: 1;
47
+ }
48
+ }
@@ -0,0 +1,2 @@
1
+ import type { ColorProps } from './interface';
2
+ export default function Color({ value, simple, onChange }: ColorProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,69 @@
1
+ import { Input, InputNumber, Space } from "../index";
2
+ import Preview from "./Preview";
3
+ import { resolveColor, transformColor } from "../ColorPicker/utils";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { jsxs as _jsxs } from "react/jsx-runtime";
6
+ export default function Color(_ref) {
7
+ var value = _ref.value,
8
+ simple = _ref.simple,
9
+ onChange = _ref.onChange;
10
+ if (simple) {
11
+ return /*#__PURE__*/_jsx(Preview, {
12
+ value: value,
13
+ onChange: onChange
14
+ });
15
+ }
16
+ var handleOpacityChange = function handleOpacityChange(opacity) {
17
+ var color = value;
18
+ var _ref2 = resolveColor(color) || {},
19
+ _ref2$hex = _ref2.hex,
20
+ hex = _ref2$hex === void 0 ? '' : _ref2$hex;
21
+ var newValue = transformColor(hex, opacity / 100);
22
+ if (newValue) {
23
+ onChange(newValue);
24
+ }
25
+ };
26
+ var handleHexChange = function handleHexChange(hexParam) {
27
+ var hex = hexParam.startsWith('#') ? hexParam : '#' + hexParam;
28
+ hex = hex.toUpperCase();
29
+ var hexReg = /^#([0-9|A-F]{3}|[0-9|A-F]{6})$/;
30
+ if (!hexReg.test(hex)) {
31
+ hex = '#000000';
32
+ }
33
+ var _ref3 = resolveColor(value) || {},
34
+ a = _ref3.a;
35
+ var newValue = transformColor(hex, a);
36
+ if (newValue) {
37
+ onChange(newValue);
38
+ }
39
+ };
40
+ var color = value;
41
+ var _ref4 = resolveColor(color) || {},
42
+ _ref4$hex = _ref4.hex,
43
+ hex = _ref4$hex === void 0 ? '' : _ref4$hex,
44
+ _ref4$a = _ref4.a,
45
+ a = _ref4$a === void 0 ? 0 : _ref4$a;
46
+ var hexValue = hex.replace('#', '').toUpperCase();
47
+ var opacityValue = Math.floor(a * 100);
48
+ return /*#__PURE__*/_jsxs(Space, {
49
+ children: [/*#__PURE__*/_jsx(Preview, {
50
+ value: value,
51
+ onChange: onChange
52
+ }), /*#__PURE__*/_jsx(Input, {
53
+ size: "small",
54
+ prefix: "#",
55
+ value: hexValue,
56
+ onChange: handleHexChange
57
+ }), /*#__PURE__*/_jsx(InputNumber, {
58
+ size: "small",
59
+ value: opacityValue,
60
+ suffix: "%",
61
+ min: 0,
62
+ max: 100,
63
+ style: {
64
+ width: 64
65
+ },
66
+ onChange: handleOpacityChange
67
+ })]
68
+ });
69
+ }
@@ -0,0 +1,5 @@
1
+ export interface ColorProps {
2
+ value: string;
3
+ simple?: boolean;
4
+ onChange: (value: string) => void;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import 'rc-color-picker/assets/index.css';
3
+ import './Panel.less';
4
+ interface ColorPickerPanelProps {
5
+ record?: unknown;
6
+ color: string;
7
+ active: number;
8
+ onChange: (color: string) => void;
9
+ }
10
+ declare const _default: import("react").NamedExoticComponent<ColorPickerPanelProps>;
11
+ export default _default;
@@ -0,0 +1,46 @@
1
+ import { memo, useMemo, useRef } from 'react';
2
+ import { Panel } from 'rc-color-picker';
3
+ import { useDebounceFn } from 'ahooks';
4
+ import Color from 'rc-color-picker/lib/helpers/color';
5
+ import 'rc-color-picker/assets/index.css';
6
+ import "./Panel.less";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export default /*#__PURE__*/memo(function ColorPickerPanel(_ref) {
9
+ var _ref$color = _ref.color,
10
+ color = _ref$color === void 0 ? 'rgba(255,0,255,0.5)' : _ref$color,
11
+ onChange = _ref.onChange;
12
+ var lastColor = useRef(color);
13
+ var colorObj = new Color(color);
14
+ useMemo(function () {
15
+ lastColor.current = color;
16
+ }, [color]);
17
+ var _useDebounceFn = useDebounceFn(function (_ref2) {
18
+ var changedColor = _ref2.color,
19
+ alpha = _ref2.alpha;
20
+ var isSameColor = new Color(changedColor).hex === new Color(lastColor.current).hex && new Color(changedColor).alpha === new Color(lastColor.current).alpha;
21
+ if (isSameColor) {
22
+ return;
23
+ }
24
+ var newColor;
25
+ var rgbColor;
26
+ if (alpha === 100) {
27
+ newColor = changedColor;
28
+ } else {
29
+ rgbColor = new Color(changedColor).RGB;
30
+ newColor = "RGBA(".concat(rgbColor[0], ",").concat(rgbColor[1], ",").concat(rgbColor[2], ",").concat(alpha / 100, ")");
31
+ }
32
+ onChange(newColor);
33
+ }, {
34
+ wait: 100,
35
+ leading: true,
36
+ trailing: false
37
+ }),
38
+ run = _useDebounceFn.run;
39
+ return /*#__PURE__*/_jsx(Panel, {
40
+ className: 'arco-color-picker-panel',
41
+ color: colorObj.toHexString(),
42
+ alpha: colorObj.alpha,
43
+ mode: "RGB",
44
+ onChange: run
45
+ });
46
+ });
@@ -0,0 +1,159 @@
1
+ .arco-color-picker-panel {
2
+ background-color: var(--color-bg-1);
3
+ width: 238px;
4
+
5
+ .rc-color-picker-panel-board {
6
+ margin: 11px 11px 0;
7
+ }
8
+
9
+ .rc-color-picker-panel-board-hsv {
10
+ width: 216px;
11
+ }
12
+
13
+ .rc-color-picker-panel-ribbon,
14
+ .rc-color-picker-panel-alpha {
15
+ border-radius: 0;
16
+ box-shadow: none;
17
+
18
+ span {
19
+ width: 12px;
20
+ height: 12px;
21
+ border-radius: 6px;
22
+ border: 2px solid #fff;
23
+ background-color: transparent;
24
+ margin-left: -6px;
25
+ margin-top: -3px;
26
+ }
27
+ }
28
+
29
+ .rc-color-picker-panel-wrap {
30
+ margin-top: 16px;
31
+ }
32
+
33
+ // rgb滑块
34
+ .rc-color-picker-panel-wrap-ribbon {
35
+ top: 3px;
36
+ left: 11px;
37
+ right: 50px;
38
+ height: 6px;
39
+ padding: 0 6px;
40
+ border-radius: 3px;
41
+ background-image: linear-gradient(
42
+ to right,
43
+ #ff0000 0%,
44
+ #ff9900 10%,
45
+ #cdff00 20%,
46
+ #35ff00 30%,
47
+ #00ff66 40%,
48
+ #00fffd 50%,
49
+ #0066ff 60%,
50
+ #3200ff 70%,
51
+ #cd00ff 80%,
52
+ #ff0099 90%,
53
+ #ff0000 100%
54
+ );
55
+ }
56
+
57
+ .rc-color-picker-panel-ribbon {
58
+ background-image: none;
59
+ }
60
+
61
+ // alpha 滑块
62
+ .rc-color-picker-panel-wrap-alpha {
63
+ bottom: 3px;
64
+ left: 11px;
65
+ right: 50px;
66
+ height: 6px;
67
+ padding: 0 6px;
68
+ border-radius: 3px;
69
+ background-image: linear-gradient(
70
+ 45deg,
71
+ #b9b8c1 25%,
72
+ transparent 0,
73
+ transparent 75%,
74
+ #b9b8c1 0
75
+ ),
76
+ linear-gradient(
77
+ 45deg,
78
+ #b9b8c1 25%,
79
+ transparent 0,
80
+ transparent 75%,
81
+ #b9b8c1 0
82
+ );
83
+ background-color: #e1e1ea;
84
+ background-size: 6px 6px;
85
+ background-position: 0 0, 3px 3px;
86
+ }
87
+
88
+ .rc-color-picker-panel-alpha {
89
+ width: auto;
90
+ background-image: none;
91
+ }
92
+
93
+ .rc-color-picker-panel-alpha-bg {
94
+ width: 177px;
95
+ border-radius: 3px;
96
+ margin-left: -6px;
97
+ }
98
+
99
+ .rc-color-picker-panel-params-input {
100
+ padding: 2px 11px;
101
+
102
+ input {
103
+ outline: none;
104
+ height: 24px;
105
+ border-color: #393b4a;
106
+ background-color: #2d2f38;
107
+ color: #bfbfbf;
108
+
109
+ &[type='number'] {
110
+ margin-left: 4px;
111
+ }
112
+ }
113
+ }
114
+
115
+ .rc-color-picker-panel-wrap-preview {
116
+ right: 11px;
117
+ border-radius: 50%;
118
+ overflow: hidden;
119
+
120
+ input {
121
+ display: none;
122
+ }
123
+ }
124
+
125
+ .rc-color-picker-panel-params-lable {
126
+ color: var(--easyv-text-color);
127
+ }
128
+
129
+ .rc-color-picker-panel-params-lable-number:hover {
130
+ border-radius: 0;
131
+ box-shadow: none;
132
+ background-color: transparent;
133
+ cursor: initial;
134
+ }
135
+
136
+ // 颜色板的圈
137
+ .rc-color-picker-panel-board span {
138
+ width: 12px;
139
+ height: 12px;
140
+ border-radius: 6px;
141
+ border-width: 2px;
142
+ margin: -6px 0 0 -6px;
143
+ }
144
+
145
+ .rc-color-picker-panel-params-hex {
146
+ width: 70px;
147
+ }
148
+
149
+ .rc-color-picker-panel-params-lable-hex {
150
+ width: 70px;
151
+ }
152
+
153
+ .rc-color-picker-panel-inner {
154
+ box-shadow: none;
155
+ border: none;
156
+ border-radius: 0;
157
+ overflow: hidden;
158
+ }
159
+ }
@@ -1,4 +1,10 @@
1
- import 'rc-color-picker/assets/index.css';
2
- import { ColorPickerProps } from './interface';
1
+ /// <reference types="react" />
3
2
  import './index.less';
4
- export default function ColorPicker({ value, onChange, }: ColorPickerProps): import("react/jsx-runtime").JSX.Element;
3
+ declare const _default: import("react").ForwardRefExoticComponent<{
4
+ mode: any;
5
+ color: any;
6
+ position: any;
7
+ onChange: any;
8
+ onCancel: any;
9
+ } & import("react").RefAttributes<unknown>>;
10
+ export default _default;