import React, { FC, useState } from 'react'; import { Switch, message, Tooltip } from 'antd'; import { QuestionCircleFilled } from '@ant-design/icons'; import classNames from 'classnames'; import styles from './Swatch.module.less'; interface SwatchProps { title: string; darkmode?: boolean; colors?: string; colornames?: string; grid?: 'sudoku'; descriptions?: string; } const copyToClipboard = (str: string) => { const el = document.createElement('textarea'); el.value = str; document.body.appendChild(el); el.select(); document.execCommand('copy'); document.body.removeChild(el); }; interface ColorsProps { colorStyle: React.CSSProperties; colors: string[]; names?: string[]; name?: string; description?: string; } const Colors: FC = ({ colorStyle = {}, colors = [], names = [], name, description, }) => { if (colors.length === 0) { return null; } return (
10 ? '100%' : '' }} >
{description ? (
{name}
) : ( {name} )} {colors.map((color: string, i: number) => (
{ copyToClipboard(color); message.success( Copied {color} , ); }} > 10 ? 'none' : '' }} > {names[i]}
))}
); }; const Swatch: FC = ({ title, darkmode = true, colors = '', colornames = '', descriptions = '', grid, }) => { const [dark, toggleDark] = useState(false); let colorsArray = [] as string[]; const colorsSwatchArray = [] as string[][]; const des = descriptions.split('|'); const colorNamesArray = colornames.split(','); const colorStyle: React.CSSProperties = {}; if (colors.includes('|')) { colors.split('|').forEach((item: string) => { colorsSwatchArray.push(item.split(',')); }); } else { colorsArray = colors.split(','); if (colorsArray.length < 5) { colorStyle.width = `calc(${100 / colorsArray.length}% - 150px)`; colorStyle.minWidth = 120; colorStyle.marginLeft = 12; colorStyle.marginRight = 12; colorStyle.fontSize = 16; } else if (colorsArray.length > 10) { colorStyle.width = 25; colorStyle.height = 25; colorStyle.marginLeft = 4; colorStyle.marginRight = 4; } } const isSudoKu = grid === 'sudoku'; return (
{(title || darkmode) && (

{title}

{darkmode && (
Dark Mode toggleDark(checked)} />
)}
)}
{colorsSwatchArray.map((swatch, i) => ( ))}
); }; export default Swatch;