Skip to content

Commit

Permalink
feat: update color data.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 29, 2021
1 parent 7c4c1e9 commit 615cbc4
Show file tree
Hide file tree
Showing 3 changed files with 3,331 additions and 240 deletions.
1 change: 1 addition & 0 deletions src/app/App.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ html, body {
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
user-select: none;
flex: 1;
}

Expand Down
35 changes: 24 additions & 11 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { useState } from 'react';
import { useMemo, useState } from 'react';
import GitHubCorners from '@uiw/react-github-corners';
import { SketchPicker, ColorResult, RGBColor, CirclePicker, CirclePickerProps } from 'react-color';
import styles from './App.module.css';
import Code from './Code';
import colorsData from './colors.json';

function CircleColors(props: CirclePickerProps & { title?: string }) {
return (
<div className={styles.color}>
<CirclePicker {...props} />
<label>{props.title}</label>
</div>
);
function CircleColors(props: CirclePickerProps & { title?: string; index: number }) {
const { index, ...other } = props;
const color = (props.colors || []).join('');
return useMemo(() => {
return (
<div className={styles.color}>
<CirclePicker {...other} />
<label>{props.title}</label>
</div>
);
}, [color, index]);
}

export default function App() {
const [color, setColor] = useState<RGBColor>({ r: 224, g: 224, b: 224, a: 0.61 });
const [hex, setHex] = useState('#E0E0E0');
const handleColorChange = (data: ColorResult) => {
setColor(data.rgb);
setHex(data.hex);
};
const handleSwatchesPicker = (data: ColorResult) => {
setColor(data.rgb);
setHex(data.hex);
};

return (
Expand All @@ -33,9 +40,15 @@ export default function App() {
<div className={styles.warpper}>
<div className={styles.colors}>
<div>
{colorsData.map((item, idx) => {
return <CircleColors color={color} key={idx} {...item} onChange={handleSwatchesPicker} />;
})}
{colorsData.map((item, idx) => (
<CircleColors
index={item.colors.indexOf(hex.toLocaleUpperCase())}
color={hex}
key={idx}
{...item}
onChange={handleSwatchesPicker}
/>
))}
</div>
</div>
<div className={styles.pane}>
Expand Down
Loading

0 comments on commit 615cbc4

Please sign in to comment.