/** @jsx jsx */ import { jsx, ThemeUICSSObject } from "theme-ui" import ColorSwatch from "./color-swatch" import ColorRow from "./color-row" import theme from "../theme" import type { INormalizeResult } from "../utils/normalize-theme-ui-colors" const join = (...args: any) => args.filter(Boolean).join(`.`) type ModeTypes = "list" | "swatch" type PaletteProps = { colors: INormalizeResult[] mode?: ModeTypes single?: boolean minimal?: boolean prefix?: string className?: string } const Palette = ({ colors, mode = `list`, single = false, minimal = false, prefix = ``, className = ``, }: PaletteProps) => { let wrapperStyles: ThemeUICSSObject if (mode === `list`) { wrapperStyles = { display: `grid`, overflow: `hidden`, borderRadius: theme.radii.lg, boxShadow: theme.shadows.default, "> div": { mb: theme.space[0], borderRadius: 0, boxShadow: `none`, }, "> div:not(:last-child)": { borderBottomWidth: `1px`, borderBottomStyle: `solid`, borderBottomColor: theme.colors.gray[3], }, } } else { wrapperStyles = { display: `grid`, gridTemplateColumns: `repeat(auto-fit,minmax(265px,1fr))`, gridGap: theme.space[3], "> div": { mb: theme.space[0], mr: theme.space[0], }, } } return (
{colors.map(({ name, color }) => { if (!color) return false if (single && (Array.isArray(color) || typeof color === `object`)) { return false } if (Array.isArray(color)) { const arr: { name: string; color: string }[] = [] color.forEach((colorValue, index) => { if (colorValue == null) return false arr.push({ name: join(name, index), color: colorValue, }) }) return ( ) } if (mode === `swatch`) { return ( ) } return })}
) } export default Palette