import {CustomPicker, InjectedColorProps} from "react-color"; import {ReactElement, useMemo} from "react"; import { renderCoordinatesToPolygonPoints, RenderOffsets, storageCoordinatesToRenderCoordinates } from "../../../common/src/state/Coordinates"; import {HexagonOrientation, LineParity} from "../../../common/src/state/HexMap"; import {normalizeColor} from "../../../common/src/util/ColorUtils"; function HexSwatch({color, index, offsets, classNames, onClick}: {color: string, index: number, offsets: RenderOffsets, classNames?: readonly string[], onClick: () => void}): ReactElement { const renderCoordinates = useMemo(() => storageCoordinatesToRenderCoordinates({line: index, cell: 0}, offsets), [index, offsets]); const points = useMemo(() => renderCoordinatesToPolygonPoints(renderCoordinates), [renderCoordinates]); return e.preventDefault()}/> } const ACTIVE_OFFSETS: RenderOffsets = { layout: { orientation: HexagonOrientation.POINTY_TOP, indentedLines: LineParity.ODD }, top: 13, left: 13, size: 50, } const SWATCH_OFFSETS: RenderOffsets = { layout: { orientation: HexagonOrientation.FLAT_TOP, indentedLines: LineParity.EVEN }, top: 34, left: 110, size: 30, } const COLORS: readonly string[] = [ "#000000FF", "#555555FF", "#800000FF", "#FF0000FF", "#008000FF", "#00FF00FF", "#808000FF", "#FFFF00FF", "#000080FF", "#0000FFFF", "#800080FF", "#FF00FFFF", "#008080FF", "#00FFFFFF", "#AAAAAAFF", "#FFFFFFFF", ] function HexColorPicker({ hex, onChange }: InjectedColorProps): ReactElement { const selected = COLORS.indexOf(normalizeColor(hex || "#INVALID")) const swatches = COLORS.map((color, index) => index === selected ? null : onChange !== undefined ? onChange(color) : null} /> ) return null} /> {swatches} {selected !== -1 ? onChange !== undefined ? onChange(COLORS[selected]) : null} /> : null} } export default CustomPicker(HexColorPicker);