import React, { useState } from 'react'; import { ColorSwatch, Group, Popover, Text, useMantineTheme, MantineTheme } from '@mantine/core'; import { useConfig } from '../../tools/state'; import { useColorTheme } from '../../tools/color'; export function ShadeSelector() { const { config, setConfig } = useConfig(); const [opened, setOpened] = useState(false); const { primaryColor, secondaryColor, primaryShade, setPrimaryShade } = useColorTheme(); const theme = useMantineTheme(); const primaryShades = theme.colors[primaryColor].map((s, i) => ({ swatch: theme.colors[primaryColor][i], shade: i as MantineTheme['primaryShade'], })); const secondaryShades = theme.colors[secondaryColor].map((s, i) => ({ swatch: theme.colors[secondaryColor][i], shade: i as MantineTheme['primaryShade'], })); const setConfigShade = (shade: MantineTheme['primaryShade']) => { setPrimaryShade(shade); setConfig({ ...config, settings: { ...config.settings, primaryShade: shade, }, }); }; const primarySwatches = primaryShades.map(({ swatch, shade }) => ( setConfigShade(shade)} key={Number(shade)} color={swatch} size={22} style={{ color: theme.white, cursor: 'pointer' }} /> )); const secondarySwatches = secondaryShades.map(({ swatch, shade }) => ( setConfigShade(shade)} key={Number(shade)} color={swatch} size={22} style={{ color: theme.white, cursor: 'pointer' }} /> )); return ( setOpened(false)} transitionDuration={0} target={ setOpened((o) => !o)} size={22} style={{ display: 'block', cursor: 'pointer' }} /> } styles={{ root: { marginRight: theme.spacing.xs, }, body: { backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[8] : theme.white, }, arrow: { backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[8] : theme.white, }, }} position="bottom" placement="end" withArrow arrowSize={3} > {primarySwatches} {secondarySwatches} Shade ); }