|
1 |
| -import { HsvColor, RgbColor } from "@keybr/color"; |
2 |
| -import { Spacer } from "@keybr/widget"; |
3 |
| -import { ColorInput } from "./ColorInput.tsx"; |
| 1 | +import { Icon } from "@keybr/widget"; |
| 2 | +import { mdiGrid, mdiPalette } from "@mdi/js"; |
| 3 | +import { useState } from "react"; |
| 4 | +import { ColorPaletteTab } from "./ColorPaletteTab.tsx"; |
4 | 5 | import * as styles from "./ColorPicker.module.less";
|
5 |
| -import { Slider } from "./Slider.tsx"; |
6 |
| -import { Thumb } from "./Thumb.tsx"; |
| 6 | +import { ColorPickerTab } from "./ColorPickerTab.tsx"; |
7 | 7 | import { type ColorEditorProps } from "./types.ts";
|
8 | 8 |
|
9 | 9 | export function ColorPicker({ color, onChange }: ColorEditorProps) {
|
10 |
| - const { h, s, v } = color.toHsv(); |
11 |
| - const { r, g, b } = color.toRgb(); |
12 |
| - const saturationValue = { x: s, y: v }; |
13 |
| - const hueValue = { x: h, y: 0.5 }; |
14 |
| - const hueColor = new HsvColor(h, 1, 1); |
15 |
| - const rValue = { x: r, y: 0.5 }; |
16 |
| - const gValue = { x: g, y: 0.5 }; |
17 |
| - const bValue = { x: b, y: 0.5 }; |
| 10 | + const [tab, setTab] = useState(0); |
18 | 11 | return (
|
19 | 12 | <div className={styles.root}>
|
20 |
| - <Slider |
21 |
| - className={styles.saturation} |
22 |
| - style={{ |
23 |
| - backgroundColor: String(hueColor), |
24 |
| - backgroundImage: `linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))`, |
25 |
| - }} |
26 |
| - value={saturationValue} |
27 |
| - onChange={({ x, y }) => { |
28 |
| - onChange(new HsvColor(h, x, y)); |
29 |
| - }} |
30 |
| - > |
31 |
| - <Thumb color={color} value={saturationValue} /> |
32 |
| - </Slider> |
33 |
| - <Spacer size={1} /> |
34 |
| - <Slider |
35 |
| - className={styles.hue} |
36 |
| - style={{ |
37 |
| - backgroundImage: `linear-gradient(to right,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00)`, |
38 |
| - }} |
39 |
| - value={hueValue} |
40 |
| - onChange={({ x }) => { |
41 |
| - onChange(new HsvColor(x, s, v)); |
42 |
| - }} |
43 |
| - > |
44 |
| - <Thumb color={hueColor} value={hueValue} /> |
45 |
| - </Slider> |
46 |
| - <Slider |
47 |
| - className={styles.channel} |
48 |
| - style={{ |
49 |
| - backgroundImage: `linear-gradient(to right,${new RgbColor(0, g, b)},${new RgbColor(1, g, b)})`, |
50 |
| - }} |
51 |
| - value={rValue} |
52 |
| - onChange={({ x }) => { |
53 |
| - onChange(new RgbColor(x, g, b)); |
54 |
| - }} |
55 |
| - > |
56 |
| - <Thumb color={color} value={rValue} /> |
57 |
| - </Slider> |
58 |
| - <Slider |
59 |
| - className={styles.channel} |
60 |
| - style={{ |
61 |
| - backgroundImage: `linear-gradient(to right,${new RgbColor(r, 0, b)},${new RgbColor(r, 1, b)})`, |
62 |
| - }} |
63 |
| - value={gValue} |
64 |
| - onChange={({ x }) => { |
65 |
| - onChange(new RgbColor(r, x, b)); |
66 |
| - }} |
67 |
| - > |
68 |
| - <Thumb color={color} value={gValue} /> |
69 |
| - </Slider> |
70 |
| - <Slider |
71 |
| - className={styles.channel} |
72 |
| - style={{ |
73 |
| - backgroundImage: `linear-gradient(to right,${new RgbColor(r, g, 0)},${new RgbColor(r, g, 1)})`, |
74 |
| - }} |
75 |
| - value={gValue} |
76 |
| - onChange={({ x }) => { |
77 |
| - onChange(new RgbColor(r, g, x)); |
78 |
| - }} |
79 |
| - > |
80 |
| - <Thumb color={color} value={bValue} /> |
81 |
| - </Slider> |
82 |
| - <ColorInput color={color} onChange={onChange} /> |
| 13 | + <div className={styles.tabs}> |
| 14 | + <span |
| 15 | + className={styles.tab} |
| 16 | + onClick={() => { |
| 17 | + setTab(0); |
| 18 | + }} |
| 19 | + > |
| 20 | + <Icon shape={mdiPalette} /> |
| 21 | + </span> |
| 22 | + <span |
| 23 | + className={styles.tab} |
| 24 | + onClick={() => { |
| 25 | + setTab(1); |
| 26 | + }} |
| 27 | + > |
| 28 | + <Icon shape={mdiGrid} /> |
| 29 | + </span> |
| 30 | + </div> |
| 31 | + {tab === 0 && <ColorPickerTab color={color} onChange={onChange} />} |
| 32 | + {tab === 1 && <ColorPaletteTab color={color} onChange={onChange} />} |
83 | 33 | </div>
|
84 | 34 | );
|
85 | 35 | }
|
0 commit comments