@douyinfe/semi-foundation 2.63.2-alpha.0 → 2.64.0
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/calendar/foundation.ts +20 -0
- package/colorPicker/AlphaSliderFoundation.ts +62 -0
- package/colorPicker/ColorChooseAreaFoundation.ts +86 -0
- package/colorPicker/ColorSliderFoundation.ts +61 -0
- package/colorPicker/DataPartFoundation.ts +113 -0
- package/colorPicker/colorPicker.scss +113 -0
- package/colorPicker/constants.ts +11 -0
- package/colorPicker/foundation.ts +206 -0
- package/colorPicker/interface.ts +51 -0
- package/colorPicker/utils/convert.ts +228 -0
- package/colorPicker/utils/round.ts +3 -0
- package/colorPicker/utils/split.ts +40 -0
- package/colorPicker/variables.scss +28 -0
- package/image/previewImageFoundation.ts +22 -17
- package/lib/cjs/calendar/foundation.js +18 -0
- package/lib/cjs/colorPicker/AlphaSliderFoundation.d.ts +27 -0
- package/lib/cjs/colorPicker/AlphaSliderFoundation.js +40 -0
- package/lib/cjs/colorPicker/ColorChooseAreaFoundation.d.ts +42 -0
- package/lib/cjs/colorPicker/ColorChooseAreaFoundation.js +62 -0
- package/lib/cjs/colorPicker/ColorSliderFoundation.d.ts +26 -0
- package/lib/cjs/colorPicker/ColorSliderFoundation.js +40 -0
- package/lib/cjs/colorPicker/DataPartFoundation.d.ts +28 -0
- package/lib/cjs/colorPicker/DataPartFoundation.js +115 -0
- package/lib/cjs/colorPicker/colorPicker.css +84 -0
- package/lib/cjs/colorPicker/colorPicker.scss +113 -0
- package/lib/cjs/colorPicker/constants.d.ts +4 -0
- package/lib/cjs/colorPicker/constants.js +11 -0
- package/lib/cjs/colorPicker/foundation.d.ts +66 -0
- package/lib/cjs/colorPicker/foundation.js +150 -0
- package/lib/cjs/colorPicker/interface.d.ts +40 -0
- package/lib/cjs/colorPicker/interface.js +5 -0
- package/lib/cjs/colorPicker/utils/convert.d.ts +28 -0
- package/lib/cjs/colorPicker/utils/convert.js +306 -0
- package/lib/cjs/colorPicker/utils/round.d.ts +1 -0
- package/lib/cjs/colorPicker/utils/round.js +12 -0
- package/lib/cjs/colorPicker/utils/split.d.ts +18 -0
- package/lib/cjs/colorPicker/utils/split.js +40 -0
- package/lib/cjs/colorPicker/variables.scss +28 -0
- package/lib/cjs/image/previewImageFoundation.js +22 -18
- package/lib/cjs/slider/foundation.d.ts +1 -0
- package/lib/cjs/slider/foundation.js +15 -0
- package/lib/cjs/tabs/constants.d.ts +0 -1
- package/lib/cjs/tabs/constants.js +1 -2
- package/lib/cjs/tabs/tabs.css +199 -28
- package/lib/cjs/tabs/tabs.scss +297 -336
- package/lib/cjs/tabs/variables.scss +2 -21
- package/lib/cjs/tooltip/foundation.js +2 -1
- package/lib/cjs/tree/treeUtil.d.ts +1 -1
- package/lib/cjs/upload/constants.d.ts +1 -1
- package/lib/cjs/upload/foundation.d.ts +1 -0
- package/lib/cjs/upload/foundation.js +30 -14
- package/lib/es/calendar/foundation.js +18 -0
- package/lib/es/colorPicker/AlphaSliderFoundation.d.ts +27 -0
- package/lib/es/colorPicker/AlphaSliderFoundation.js +33 -0
- package/lib/es/colorPicker/ColorChooseAreaFoundation.d.ts +42 -0
- package/lib/es/colorPicker/ColorChooseAreaFoundation.js +55 -0
- package/lib/es/colorPicker/ColorSliderFoundation.d.ts +26 -0
- package/lib/es/colorPicker/ColorSliderFoundation.js +33 -0
- package/lib/es/colorPicker/DataPartFoundation.d.ts +28 -0
- package/lib/es/colorPicker/DataPartFoundation.js +108 -0
- package/lib/es/colorPicker/colorPicker.css +84 -0
- package/lib/es/colorPicker/colorPicker.scss +113 -0
- package/lib/es/colorPicker/constants.d.ts +4 -0
- package/lib/es/colorPicker/constants.js +6 -0
- package/lib/es/colorPicker/foundation.d.ts +66 -0
- package/lib/es/colorPicker/foundation.js +143 -0
- package/lib/es/colorPicker/interface.d.ts +40 -0
- package/lib/es/colorPicker/interface.js +1 -0
- package/lib/es/colorPicker/utils/convert.d.ts +28 -0
- package/lib/es/colorPicker/utils/convert.js +277 -0
- package/lib/es/colorPicker/utils/round.d.ts +1 -0
- package/lib/es/colorPicker/utils/round.js +5 -0
- package/lib/es/colorPicker/utils/split.d.ts +18 -0
- package/lib/es/colorPicker/utils/split.js +34 -0
- package/lib/es/colorPicker/variables.scss +28 -0
- package/lib/es/image/previewImageFoundation.js +22 -18
- package/lib/es/slider/foundation.d.ts +1 -0
- package/lib/es/slider/foundation.js +15 -0
- package/lib/es/tabs/constants.d.ts +0 -1
- package/lib/es/tabs/constants.js +1 -2
- package/lib/es/tabs/tabs.css +199 -28
- package/lib/es/tabs/tabs.scss +297 -336
- package/lib/es/tabs/variables.scss +2 -21
- package/lib/es/tooltip/foundation.js +2 -1
- package/lib/es/tree/treeUtil.d.ts +1 -1
- package/lib/es/upload/constants.d.ts +1 -1
- package/lib/es/upload/foundation.d.ts +1 -0
- package/lib/es/upload/foundation.js +30 -14
- package/package.json +3 -3
- package/slider/foundation.ts +13 -0
- package/tabs/constants.ts +1 -2
- package/tabs/tabs.scss +297 -336
- package/tabs/variables.scss +2 -21
- package/tooltip/foundation.ts +1 -1
- package/upload/foundation.ts +19 -3
package/calendar/foundation.ts
CHANGED
|
@@ -248,7 +248,27 @@ export default class CalendarFoundation<P = Record<string, any>, S = Record<stri
|
|
|
248
248
|
if (!parsed.day) {
|
|
249
249
|
parsed.day = [];
|
|
250
250
|
}
|
|
251
|
+
|
|
251
252
|
parsed.day = parsed.day.map(item => renderDailyEvent(item));
|
|
253
|
+
// 将 startPos & endPos 完全相同的事件编为一组
|
|
254
|
+
const sameTimeRangeGroup = parsed.day.reduce((acc, item) => {
|
|
255
|
+
const key = `${item.startPos}-${item.endPos}`;
|
|
256
|
+
if (!acc[key]) {
|
|
257
|
+
acc[key] = [];
|
|
258
|
+
}
|
|
259
|
+
acc[key].push(item);
|
|
260
|
+
return acc;
|
|
261
|
+
}, {});
|
|
262
|
+
|
|
263
|
+
// 计算每个 item 的 left 值,
|
|
264
|
+
const eventCountMap = {};
|
|
265
|
+
parsed.day = parsed.day.map(item => {
|
|
266
|
+
const key = `${item.startPos}-${item.endPos}`;
|
|
267
|
+
let curCount = eventCountMap[key];
|
|
268
|
+
eventCountMap[key] = curCount === undefined ? 0 : ++curCount;
|
|
269
|
+
item.left = curCount !== 0 ? `${(curCount / sameTimeRangeGroup[key].length * 100)}%` : 0;
|
|
270
|
+
return item;
|
|
271
|
+
});
|
|
252
272
|
return parsed;
|
|
253
273
|
}
|
|
254
274
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import BaseFoundation, { DefaultAdapter } from "../base/foundation";
|
|
2
|
+
import ColorPickerFoundation, { ColorPickerAdapter, ColorPickerProps, ColorPickerState } from "./foundation";
|
|
3
|
+
import { HsvaColor } from "./interface";
|
|
4
|
+
|
|
5
|
+
export interface AlphaSliderBaseProps {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
hsva: HsvaColor;
|
|
9
|
+
handleSize: number;
|
|
10
|
+
foundation: ColorPickerFoundation
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AlphaSliderBaseState {
|
|
14
|
+
handlePosition: number;
|
|
15
|
+
isHandleGrabbing: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export interface AlphaSliderAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
20
|
+
handleMouseDown: (e: any) => void;
|
|
21
|
+
handleMouseUp: (e: any) => void;
|
|
22
|
+
getColorPickerFoundation: () => ColorPickerFoundation;
|
|
23
|
+
getDOM: () => HTMLDivElement
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class AlphaSliderFoundation extends BaseFoundation<AlphaSliderAdapter<AlphaSliderBaseProps, AlphaSliderBaseState>, AlphaSliderBaseProps, AlphaSliderBaseState> {
|
|
28
|
+
|
|
29
|
+
constructor(adapter: AlphaSliderAdapter<AlphaSliderBaseProps, AlphaSliderBaseState>) {
|
|
30
|
+
super({
|
|
31
|
+
...adapter
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
handleMouseDown = (e: any) => {
|
|
36
|
+
this._adapter.handleMouseDown(e);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
handleMouseUp = (e: any) => {
|
|
41
|
+
this._adapter.handleMouseUp(e);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
setHandlePositionByMousePosition = (e: MouseEvent) => {
|
|
46
|
+
const rect = this._adapter.getDOM()?.getBoundingClientRect();
|
|
47
|
+
if (!rect) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const { width, handleSize } = this._adapter.getProps();
|
|
51
|
+
const colorPickerFoundation = this._adapter.getColorPickerFoundation();
|
|
52
|
+
const mousePosition = e.clientX - rect.x;
|
|
53
|
+
const handlePosition = colorPickerFoundation.getAlphaHandlePositionByMousePosition(mousePosition, width, handleSize);
|
|
54
|
+
colorPickerFoundation.handleAlphaChangeByHandle({ a: Number((Math.min(Math.max(mousePosition / width, 0), 1)).toFixed(2)) });
|
|
55
|
+
this.setState({ handlePosition });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export default AlphaSliderFoundation;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import BaseFoundation, { DefaultAdapter } from "../base/foundation";
|
|
2
|
+
import ColorPickerFoundation from "./foundation";
|
|
3
|
+
import { HsvaColor } from "./interface";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export interface ColorChooseAreaBaseProps {
|
|
7
|
+
hsva: HsvaColor;
|
|
8
|
+
onChange: (newColor: { s: number; v: number }) => void;
|
|
9
|
+
handleSize: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
foundation: ColorPickerFoundation
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ColorChooseAreaBaseState {
|
|
16
|
+
handlePosition: { x: number; y: number };
|
|
17
|
+
isHandleGrabbing: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export interface ColorChooseAreaAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
22
|
+
getColorPickerFoundation: () => ColorPickerFoundation;
|
|
23
|
+
handleMouseDown: (e: any) => void;
|
|
24
|
+
handleMouseUp: (e: any) => void;
|
|
25
|
+
getDOM: () => HTMLDivElement;
|
|
26
|
+
notifyChange: (newColor: { s: number; v: number }) => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ColorChooseAreaFoundation extends BaseFoundation<ColorChooseAreaAdapter<ColorChooseAreaBaseProps, ColorChooseAreaBaseState>, ColorChooseAreaBaseProps, ColorChooseAreaBaseState> {
|
|
31
|
+
|
|
32
|
+
constructor(adapter: ColorChooseAreaAdapter<ColorChooseAreaBaseProps, ColorChooseAreaBaseState>) {
|
|
33
|
+
super({
|
|
34
|
+
...adapter
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getHandlePositionByHSVA = () => {
|
|
39
|
+
const { hsva, width, height, handleSize } = this.getProps();
|
|
40
|
+
|
|
41
|
+
return this._adapter.getColorPickerFoundation().getHandlePositionByHSVA(hsva, {
|
|
42
|
+
width: width,
|
|
43
|
+
height: height
|
|
44
|
+
}, handleSize);
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
handleMouseDown = (e: any) => {
|
|
49
|
+
this._adapter.handleMouseDown(e);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
handleMouseUp = (e: any) => {
|
|
53
|
+
this._adapter.handleMouseUp(e);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
setHandlePositionByMousePosition = (e: globalThis.MouseEvent) => {
|
|
58
|
+
const rect = this._adapter.getDOM()?.getBoundingClientRect();
|
|
59
|
+
if (!rect) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const mousePosition = {
|
|
63
|
+
x: e.clientX - rect.x,
|
|
64
|
+
y: e.clientY - rect.y
|
|
65
|
+
};
|
|
66
|
+
const { width, height, handleSize } = this.getProps();
|
|
67
|
+
const colorPickerFoundation = this._adapter.getColorPickerFoundation();
|
|
68
|
+
const handlePosition = colorPickerFoundation.getHandlePositionByMousePosition(mousePosition, {
|
|
69
|
+
width,
|
|
70
|
+
height
|
|
71
|
+
}, handleSize);
|
|
72
|
+
if (handlePosition) {
|
|
73
|
+
this.setState({ handlePosition });
|
|
74
|
+
this._adapter.notifyChange({
|
|
75
|
+
s: Math.round(mousePosition.x / width * 100),
|
|
76
|
+
v: Math.round(100 - (Math.min(Math.max(mousePosition.y / height, 0), 1)) * 100),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
export default ColorChooseAreaFoundation;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import BaseFoundation, { DefaultAdapter } from "../base/foundation";
|
|
2
|
+
import ColorPickerFoundation from "./foundation";
|
|
3
|
+
|
|
4
|
+
export interface ColorSliderBaseProps {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
hue: number;
|
|
8
|
+
handleSize: number;
|
|
9
|
+
foundation: ColorPickerFoundation
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ColorSliderBaseState {
|
|
13
|
+
handlePosition: number;
|
|
14
|
+
isHandleGrabbing: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export interface ColorSliderAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
19
|
+
handleMouseDown: (e: any) => void;
|
|
20
|
+
handleMouseUp: (e: any) => void;
|
|
21
|
+
getColorPickerFoundation: () => ColorPickerFoundation;
|
|
22
|
+
getDOM: () => HTMLDivElement
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ColorSliderFoundation extends BaseFoundation<ColorSliderAdapter<ColorSliderBaseProps, ColorSliderBaseState>, ColorSliderBaseProps, ColorSliderBaseState> {
|
|
27
|
+
|
|
28
|
+
constructor(adapter: ColorSliderAdapter<ColorSliderBaseProps, ColorSliderBaseState>) {
|
|
29
|
+
super({
|
|
30
|
+
...adapter
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
handleMouseDown = (e: any) => {
|
|
35
|
+
this._adapter.handleMouseDown(e);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
handleMouseUp = (e: any) => {
|
|
40
|
+
this._adapter.handleMouseUp(e);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
setHandlePositionByMousePosition = (e: MouseEvent) => {
|
|
45
|
+
const rect = this._adapter.getDOM()?.getBoundingClientRect();
|
|
46
|
+
if (!rect) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const { width, handleSize } = this._adapter.getProps();
|
|
50
|
+
const colorPickerFoundation = this._adapter.getColorPickerFoundation();
|
|
51
|
+
const mousePosition = e.clientX - rect.x;
|
|
52
|
+
colorPickerFoundation.handleColorChangeByHandle({ h: Math.round(Math.min(Math.max(mousePosition / width, 0), 1) * 360) });
|
|
53
|
+
const handlePosition = colorPickerFoundation.getColorHandlePositionByMousePosition(mousePosition, width, handleSize);
|
|
54
|
+
this.setState({ handlePosition });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
export default ColorSliderFoundation;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import BaseFoundation, { DefaultAdapter } from "../base/foundation";
|
|
2
|
+
import ColorPickerFoundation, { ColorPickerProps } from "./foundation";
|
|
3
|
+
import split from "./utils/split";
|
|
4
|
+
import { HsvaColor, RgbaColor } from "./interface";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
type Value = ColorPickerProps['value']
|
|
8
|
+
|
|
9
|
+
export interface DataPartBaseProps {
|
|
10
|
+
currentColor: Value;
|
|
11
|
+
defaultFormat: 'hex' | 'rgba' | 'hsva';
|
|
12
|
+
width: number;
|
|
13
|
+
alpha?: boolean;
|
|
14
|
+
foundation: ColorPickerFoundation;
|
|
15
|
+
eyeDropper: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface DataPartBaseState {
|
|
19
|
+
format: 'hex' | 'rgba' | 'hsva';
|
|
20
|
+
inputValue: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export interface DataPartAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
25
|
+
getColorPickerFoundation: () => ColorPickerFoundation
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class DataPartFoundation extends BaseFoundation<DataPartAdapter<DataPartBaseProps, DataPartBaseState>, DataPartBaseProps, DataPartBaseState> {
|
|
30
|
+
|
|
31
|
+
constructor(adapter: DataPartAdapter<DataPartBaseProps, DataPartBaseState>) {
|
|
32
|
+
super({
|
|
33
|
+
...adapter
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getInputValue = () => {
|
|
38
|
+
const { currentColor } = this._adapter.getProps();
|
|
39
|
+
const { format } = this._adapter.getStates();
|
|
40
|
+
const rgba = currentColor.rgba;
|
|
41
|
+
const hsva = currentColor.hsva;
|
|
42
|
+
const hex = currentColor.hex;
|
|
43
|
+
if (format === 'rgba') {
|
|
44
|
+
return `${rgba.r},${rgba.g},${rgba.b}`;
|
|
45
|
+
} else if (format === 'hsva') {
|
|
46
|
+
return `${hsva.h},${hsva.s},${hsva.v}`;
|
|
47
|
+
} else {
|
|
48
|
+
return hex.slice(0, 7);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getValueByInputValue = (value: string) => {
|
|
53
|
+
const { format } = this.getStates();
|
|
54
|
+
if (format === 'rgba') {
|
|
55
|
+
const result = split(value, format);
|
|
56
|
+
if (result) {
|
|
57
|
+
return result as RgbaColor;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
} else if (format === 'hsva') {
|
|
61
|
+
const result = split(value, format);
|
|
62
|
+
if (result) {
|
|
63
|
+
return result as HsvaColor;
|
|
64
|
+
}
|
|
65
|
+
} else if (format === 'hex') {
|
|
66
|
+
// hack chrome bug, format mismatch with w3c.
|
|
67
|
+
if (!value.startsWith('#')) {
|
|
68
|
+
value = '#' + value;
|
|
69
|
+
}
|
|
70
|
+
if (/#[\d\w]{6,8}/.test(value)) {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
handlePickValueWithStraw = async () => {
|
|
78
|
+
const colorPickerFoundation = this._adapter.getColorPickerFoundation();
|
|
79
|
+
if (!window['EyeDropper']) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
//@ts-ignore
|
|
83
|
+
const eyeDropper = new EyeDropper();
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const result = await eyeDropper.open();
|
|
87
|
+
const color = result['sRGBHex'];
|
|
88
|
+
if (color.startsWith("#")) {
|
|
89
|
+
colorPickerFoundation.handleChange(color, 'hex');
|
|
90
|
+
} else if (color.startsWith('rgba')) {
|
|
91
|
+
const rgba = ColorPickerFoundation.rgbaStringToRgba(color);
|
|
92
|
+
rgba.a = 1;
|
|
93
|
+
colorPickerFoundation.handleChange(rgba, 'rgba');
|
|
94
|
+
}
|
|
95
|
+
} catch (e) {
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
handleInputValueChange = (value: string) => {
|
|
102
|
+
this._adapter.setState({ inputValue: value });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
handleFormatChange = (format: DataPartBaseState['format']) => {
|
|
106
|
+
this._adapter.setState({ format });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
export default DataPartFoundation;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
@import "./variables.scss";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
$module: #{$prefix}-colorPicker;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
.#{$module} {
|
|
8
|
+
|
|
9
|
+
&-colorChooseArea{
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Referrer from https://github.com/web-padawan/vanilla-colorful/blob/5d219ee360ae2f29534864b28ca9e6074233b9ce/src/lib/styles/saturation.css
|
|
13
|
+
*/
|
|
14
|
+
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
|
|
15
|
+
position: relative;
|
|
16
|
+
flex-grow: 1;
|
|
17
|
+
border-color: transparent;
|
|
18
|
+
border-radius: $radius-colorPicker-topLeft $radius-colorPicker-topRight $radius-colorPicker-bottomLeft $radius-colorPicker-bottomRight;
|
|
19
|
+
background-image: linear-gradient(to top, #000, rgba(0, 0, 0, 0)), linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
&-handle{
|
|
24
|
+
border-radius: $radius-colorPicker-handle;
|
|
25
|
+
border: $width-colorPicker_handle-border solid $color-colorPicker_handle-border;
|
|
26
|
+
position: absolute;
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
cursor: grab;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
&-alphaSlider{
|
|
35
|
+
position: relative;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
margin-top: $spacing-colorPicker_slider-marginTop;
|
|
38
|
+
border-radius: $radius-colorPicker-handle;
|
|
39
|
+
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><rect x="8" width="8" height="8"/><rect y="8" width="8" height="8"/></svg>');
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
.#{$module}-alphaSliderInner{
|
|
43
|
+
width: 100%;
|
|
44
|
+
height: 100%;
|
|
45
|
+
border-radius: $radius-colorPicker-alphaSliderInner;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.#{$module}-alphaHandle{
|
|
49
|
+
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><rect x="8" width="8" height="8"/><rect y="8" width="8" height="8"/></svg>');
|
|
50
|
+
border-radius: $radius-colorPicker-handle;
|
|
51
|
+
border: $width-colorPicker_handle-border solid $color-colorPicker_handle-border;
|
|
52
|
+
position: absolute;
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
cursor: grab;
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
&-colorSlider{
|
|
61
|
+
position: relative;
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
margin-top: $spacing-colorPicker_slider-marginTop;
|
|
64
|
+
border-radius: $radius-colorPicker-handle;
|
|
65
|
+
background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
&-dataPart{
|
|
71
|
+
margin-top: $spacing-colorPicker_dataPart-marginTop;
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
.#{$module}-colorDemoBlock{
|
|
75
|
+
border-radius: $radius-colorPicker-demoBlock;
|
|
76
|
+
}
|
|
77
|
+
.#{$module}-inputGroup{
|
|
78
|
+
margin-left: $spacing-colorPicker_inputGroup-marginLeft;
|
|
79
|
+
width: 100%;
|
|
80
|
+
flex:1;
|
|
81
|
+
flex-wrap: nowrap;
|
|
82
|
+
.#{$module}-colorPickerInput{
|
|
83
|
+
flex: 1;
|
|
84
|
+
}
|
|
85
|
+
.#{$module}-colorPickerInputNumber{
|
|
86
|
+
width: $width-colorPicker-colorPickerInputNumber;
|
|
87
|
+
.#{$module}-inputNumberSuffix{
|
|
88
|
+
font-size: $font-colorPicker_inputNumberSuffix-fontSize;
|
|
89
|
+
padding: $spacing-colorPicker_inputNumberSuffix-vertical $spacing-colorPicker_inputNumberSuffix-horizontal;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
.#{$module}-formatSelect{
|
|
94
|
+
width: $width-colorPicker-formatSelect;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
&-popover{
|
|
100
|
+
padding: $spacing-colorPicker_popover-padding;
|
|
101
|
+
|
|
102
|
+
&-defaultChildren{
|
|
103
|
+
width:$width-colorPicker-defaultTrigger;
|
|
104
|
+
height: $width-colorPicker-defaultTrigger;
|
|
105
|
+
border-radius: $radius-colorPicker-defaultTrigger;
|
|
106
|
+
cursor: pointer;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { HsvaColor, RgbaColor } from './interface';
|
|
2
|
+
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
3
|
+
import {
|
|
4
|
+
hexToHsva,
|
|
5
|
+
hexToRgba,
|
|
6
|
+
hsvaToHex,
|
|
7
|
+
hsvaToHslaString,
|
|
8
|
+
hsvaToHslString,
|
|
9
|
+
hsvaToRgba, rgbaStringToHsva, rgbaStringToRgba,
|
|
10
|
+
rgbaToHex,
|
|
11
|
+
rgbaToHsva,
|
|
12
|
+
} from './utils/convert';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export type ColorValue = {
|
|
16
|
+
hsva: HsvaColor;
|
|
17
|
+
rgba: RgbaColor;
|
|
18
|
+
hex: string
|
|
19
|
+
}
|
|
20
|
+
export interface ColorPickerProps {
|
|
21
|
+
eyeDropper?: boolean;
|
|
22
|
+
defaultValue?: ColorValue;
|
|
23
|
+
value?: ColorValue;
|
|
24
|
+
onChange: (value: ColorValue) => void;
|
|
25
|
+
alpha: boolean;
|
|
26
|
+
width?: number;
|
|
27
|
+
height?: number;
|
|
28
|
+
defaultFormat: 'hex' | 'rgba' | 'hsva'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ColorPickerState {
|
|
32
|
+
currentColor: ColorValue
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export interface ColorPickerAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
37
|
+
notifyChange: (value: ColorValue) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ColorPickerFoundation extends BaseFoundation<ColorPickerAdapter<ColorPickerProps, ColorPickerState>, ColorPickerProps, ColorPickerState> {
|
|
42
|
+
|
|
43
|
+
constructor(adapter: ColorPickerAdapter<ColorPickerProps, ColorPickerState>) {
|
|
44
|
+
super({
|
|
45
|
+
...adapter
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static hsvaToRgba = hsvaToRgba
|
|
50
|
+
static rgbaToHsva = rgbaToHsva
|
|
51
|
+
static rgbaToHex = rgbaToHex
|
|
52
|
+
static hsvaToHex = hsvaToHex
|
|
53
|
+
static hexToRgba = hexToRgba
|
|
54
|
+
static hexToHsva = hexToHsva
|
|
55
|
+
static hsvaToHslaString = hsvaToHslaString
|
|
56
|
+
static hsvaToHslString = hsvaToHslString
|
|
57
|
+
static rgbaStringToHsva = rgbaStringToHsva
|
|
58
|
+
static rgbaStringToRgba = rgbaStringToRgba
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
handleChangeH = (currentColor: ColorValue, newH: number) => {
|
|
62
|
+
|
|
63
|
+
const hsva = {
|
|
64
|
+
...currentColor.hsva,
|
|
65
|
+
h: newH
|
|
66
|
+
};
|
|
67
|
+
const rgba = hsvaToRgba(hsva);
|
|
68
|
+
const hex = hsvaToHex(hsva);
|
|
69
|
+
|
|
70
|
+
const newCurrentColor = {
|
|
71
|
+
rgba,
|
|
72
|
+
hsva,
|
|
73
|
+
hex
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
this._adapter.notifyChange(newCurrentColor);
|
|
77
|
+
if (!this.getProp("value")) {
|
|
78
|
+
this._adapter.setState({ currentColor: newCurrentColor });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
handleChangeA = (currentColor: ColorValue, newAlpha: number) => {
|
|
85
|
+
let alpha = this._adapter.getProp('alpha');
|
|
86
|
+
if (!alpha) {
|
|
87
|
+
newAlpha = 1;
|
|
88
|
+
}
|
|
89
|
+
const rgba = {
|
|
90
|
+
...currentColor.rgba,
|
|
91
|
+
a: newAlpha
|
|
92
|
+
};
|
|
93
|
+
const hex = rgbaToHex(rgba);
|
|
94
|
+
currentColor = {
|
|
95
|
+
rgba,
|
|
96
|
+
hex: alpha ? hex : hex.slice(0, 7),
|
|
97
|
+
hsva: {
|
|
98
|
+
...currentColor.hsva,
|
|
99
|
+
a: newAlpha
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
this._adapter.notifyChange(currentColor);
|
|
103
|
+
if (!this.getProp("value")) {
|
|
104
|
+
this._adapter.setState({ currentColor: currentColor });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
getCurrentColor = ()=>{
|
|
110
|
+
|
|
111
|
+
const value = this.getProp("value");
|
|
112
|
+
const currentColor = this.getState("currentColor");
|
|
113
|
+
return value || currentColor;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
handleChange = (color: HsvaColor|RgbaColor|string, format: 'hex'|'rgba'|'hsva')=>{
|
|
117
|
+
let currentColor;
|
|
118
|
+
|
|
119
|
+
if (format === 'hsva') {
|
|
120
|
+
currentColor = {
|
|
121
|
+
hsva: color as HsvaColor,
|
|
122
|
+
rgba: ColorPickerFoundation.hsvaToRgba(color as HsvaColor),
|
|
123
|
+
hex: ColorPickerFoundation.hsvaToHex(color as HsvaColor)
|
|
124
|
+
};
|
|
125
|
+
} else if (format === 'rgba') {
|
|
126
|
+
currentColor = {
|
|
127
|
+
rgba: color as RgbaColor,
|
|
128
|
+
hsva: ColorPickerFoundation.rgbaToHsva(color as RgbaColor),
|
|
129
|
+
hex: ColorPickerFoundation.rgbaToHex(color as RgbaColor)
|
|
130
|
+
};
|
|
131
|
+
} else if (format === 'hex') {
|
|
132
|
+
currentColor = {
|
|
133
|
+
hex: color as string,
|
|
134
|
+
hsva: ColorPickerFoundation.hexToHsva(color as string),
|
|
135
|
+
rgba: ColorPickerFoundation.hexToRgba(color as string)
|
|
136
|
+
};
|
|
137
|
+
} else {
|
|
138
|
+
throw new Error('format error');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this._adapter.notifyChange(currentColor);
|
|
142
|
+
if (!this.getProp("value")) {
|
|
143
|
+
this._adapter.setState({ currentColor: currentColor });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
handleAlphaChangeByHandle = (newAlpha: {a: number})=>{
|
|
150
|
+
this.handleChangeA(this.getCurrentColor(), newAlpha.a);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
handleColorChangeByHandle = (newHue: {h: number})=>{
|
|
154
|
+
this.handleChangeH(this.getCurrentColor(), newHue.h);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
getHandlePositionByHSVA = (hsva: HsvaColor, { width, height }: {width: number;height: number}, handleSize: number)=>{
|
|
159
|
+
|
|
160
|
+
const defaultColorPosition = { x: hsva.s / 100 * width, y: (1 - hsva.v / 100) * height };
|
|
161
|
+
return { x: defaultColorPosition.x - handleSize / 2, y: defaultColorPosition.y - handleSize / 2 };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
getHandlePositionByMousePosition = (mousePosition: {x: number;y: number}, { width, height }: {width: number;height: number}, handleSize: number)=>{
|
|
165
|
+
if (mousePosition.x > width || mousePosition.x < 0) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (mousePosition.y > height || mousePosition.y < 0) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const handlePosition = {
|
|
174
|
+
x: mousePosition.x - handleSize / 2,
|
|
175
|
+
y: mousePosition.y - handleSize / 2
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return handlePosition;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
getAlphaHandlePositionByMousePosition = (mousePosition: number, width: number, handleSize: number)=>{
|
|
183
|
+
if (mousePosition < 0 || mousePosition > width) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return mousePosition - handleSize / 2;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
getColorHandlePositionByMousePosition = (mousePosition: number, width: number, handleSize: number)=>{
|
|
190
|
+
if (mousePosition < 0 || mousePosition > width) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return mousePosition - handleSize / 2;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export default ColorPickerFoundation;
|
|
206
|
+
|