import { BlockBackground } from '@/blocks/Background'; // import Sketch from '@uiw/react-color-sketch'; import Sketch, { ChromeInputType } from '@uiw/react-color-chrome'; import Wheel from '@uiw/react-color-wheel'; import { hexToRgba, HsvaColor, hsvaToHexa } from '@uiw/color-convert'; import { useControllableValue, useLocalStorageState } from 'ahooks'; import { Typography, Popover } from 'antd'; import { AiFillCloseCircle } from 'react-icons/ai'; import clsx from 'clsx'; import React, { useMemo, useState } from 'react'; import locale from '@/locale'; const { Link, Text } = Typography; function Colours({ maxColours, ctx, dispatch, block, setBlock, }: { maxColours?: number; ctx: IPicexContext; dispatch: IPicexDispatch; block: null | BlockBackground; setBlock: (block: BlockBackground) => void; }) { const viewport = ctx.blocks[0]; const value = block?.fill; const [hsva, setV] = useState(); const v = useMemo(() => (hsva ? hsvaToHexa(hsva) : 'transparent'), [hsva]); const [open, setOpen] = useState(false); const [hex, setHex] = useControllableValue({ value: typeof value === 'string' && value ? value : 'transparent', onChange: (fill) => { if (!viewport) { return; } if (block) { block.setX(viewport.getX()); block.setY(viewport.getY()); dispatch({ type: 'updateBlock', block, payload: { fill: fill, }, }); } else { BlockBackground.fromColour(fill, { width: viewport?.width, height: viewport?.height, }).then((newBlock) => { dispatch({ type: 'addBlock', block: newBlock, }); setBlock(newBlock); }); } }, }); const [localHexes, setLocalHexes] = useLocalStorageState( 'picex-background-colors', { defaultValue: [] as string[], }, ); return (

); } function ColourItem({ hex, colour, border, setHex, removable, onRemove, }: { hex: string; colour: string; border?: string; setHex: (hex: string) => void; removable?: boolean; onRemove?: (hex: string) => void; }) { return (
  • { setHex(colour); }} >
    {removable ? ( { e.stopPropagation(); onRemove?.(hex); }} > ) : null}
  • ); } export default Colours;