Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 9915f0c

Browse files
committed
✨ feat: 初步完成 hsl、hsv 支持
1 parent ad3a96a commit 9915f0c

File tree

13 files changed

+393
-231
lines changed

13 files changed

+393
-231
lines changed

packages/color-picker/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
"classnames": "^2.3.1",
2828
"lodash": "^4.17.21",
2929
"reactcss": "^1.2.3",
30+
"rxjs": "^7.5.5",
3031
"tinycolor2": "^1.4.2",
3132
"zustand": "^3.7.1"
3233
},
3334
"devDependencies": {
34-
"@types/lodash": "^4.14.181"
35+
"@types/lodash": "^4.14.181",
36+
"@types/reactcss": "^1.2.6"
3537
}
3638
}

packages/color-picker/src/ColorPicker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ order: 2
44
group:
55
path: /
66
nav:
7-
path: /components
7+
path: /biz-components
88
---
99

1010
# ColorPicker 取色器
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.avx-color-fields-label {
2+
width: 31px;
3+
4+
line-height: 1;
5+
text-align: center;
6+
text-transform: capitalize;
7+
cursor: ew-resize;
8+
user-select: none;
9+
&:active {
10+
color: hsla(0, 0%, 0%, 0.65);
11+
}
12+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import type { CSSProperties, FC } from 'react';
2+
import React, { memo, useEffect, useMemo } from 'react';
3+
import { fromEvent, Subject, BehaviorSubject } from 'rxjs';
4+
import { distinctUntilChanged, withLatestFrom, concatMap, takeUntil, map } from 'rxjs/operators';
5+
import cls from 'classnames';
6+
7+
import './index.less';
8+
9+
interface DraggableLabelProps {
10+
text: string;
11+
value?: number;
12+
onChange?: (value: number) => void;
13+
className?: string;
14+
style?: CSSProperties;
15+
}
16+
17+
const DraggableLabel: FC<DraggableLabelProps> = memo(
18+
({ text, onChange, value, className, style }) => {
19+
const currentValue$ = useMemo(() => new BehaviorSubject(value), []);
20+
const mouseDown$ = useMemo(() => new Subject(), []);
21+
22+
useEffect(() => {
23+
currentValue$.next(value);
24+
}, [value]);
25+
26+
useEffect(() => {
27+
mouseDown$
28+
.pipe(
29+
concatMap(() =>
30+
fromEvent<MouseEvent>(window, 'mousemove').pipe(
31+
takeUntil(fromEvent(window, 'mouseup')),
32+
),
33+
),
34+
map((e) => e.movementX),
35+
withLatestFrom(currentValue$, (movementX, value) => Math.round(value + movementX)),
36+
distinctUntilChanged(),
37+
)
38+
.subscribe((value) => {
39+
onChange?.(value);
40+
});
41+
42+
return () => {
43+
mouseDown$.unsubscribe();
44+
};
45+
}, []);
46+
47+
return (
48+
<div
49+
className={cls(`avx-color-fields-label`, className)}
50+
onMouseDown={(e) => {
51+
mouseDown$.next(e);
52+
}}
53+
style={style}
54+
>
55+
{text}
56+
</div>
57+
);
58+
},
59+
);
60+
61+
export default DraggableLabel;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.avx-color-fields-input {
2+
width: 100%;
3+
padding: 2px 3px;
4+
font-size: 12px;
5+
border: none;
6+
border-radius: 4px;
7+
box-shadow: inset 0 0 0 1px #ccc;
8+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { CSSProperties, FC } from 'react';
2+
import React from 'react';
3+
import cls from 'classnames';
4+
5+
import './index.less';
6+
7+
export interface EditableInputProps {
8+
value: number | string;
9+
10+
onChange: (value) => void;
11+
className?: string;
12+
style?: CSSProperties;
13+
}
14+
15+
const EditableInput: FC<EditableInputProps> = ({ value, style, className, onChange }) => {
16+
return (
17+
<input
18+
className={cls('avx-color-fields-input', className)}
19+
value={value}
20+
// onKeyDown={this.handleKeyDown}
21+
// onChange={this.handleChange}
22+
onChange={onChange}
23+
// onBlur={this.handleBlur}
24+
spellCheck="false"
25+
style={style}
26+
/>
27+
);
28+
};
29+
30+
export default EditableInput;

packages/color-picker/src/components/SketchFields.tsx

Lines changed: 0 additions & 159 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.avx-color-fields {
2+
&-hex {
3+
flex: 2;
4+
width: 56px;
5+
}
6+
7+
&-input {
8+
width: 31px;
9+
}
10+
11+
&-switcher {
12+
position: relative;
13+
padding: 2px 0;
14+
border-radius: 4px;
15+
16+
&:hover {
17+
background: hsla(0, 0, 0, 0.04);
18+
}
19+
}
20+
21+
&-switcher:hover &-select {
22+
opacity: 1;
23+
}
24+
25+
&-select {
26+
position: absolute;
27+
top: 0;
28+
left: 0px;
29+
30+
display: flex;
31+
align-items: center;
32+
33+
width: 16px;
34+
height: 100%;
35+
padding: 0 2px;
36+
37+
//
38+
background: none;
39+
40+
border: none;
41+
border-radius: 4px;
42+
border-top-right-radius: 0;
43+
border-bottom-right-radius: 0;
44+
45+
cursor: pointer;
46+
opacity: 0;
47+
48+
&:hover {
49+
background: hsla(0, 0, 0, 0.02);
50+
}
51+
52+
&:focus-visible {
53+
outline-width: 0;
54+
}
55+
}
56+
57+
&-label-ctn {
58+
color: rgba(0, 0, 0, 0.45);
59+
font-size: 12px;
60+
}
61+
62+
&-label {
63+
&-hex {
64+
width: 48px;
65+
padding-left: 8px;
66+
}
67+
68+
&-alpha,
69+
&-hex {
70+
padding: 2px 0;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)