import React, { useState } from 'react'; import { ColorSwatch, Group, Popover, Text, useMantineTheme, MantineTheme, Stack, Grid, } from '@mantine/core'; import { useTranslation } from 'next-i18next'; import { useConfig } from '../../tools/state'; import { useColorTheme } from '../../tools/color'; export function ShadeSelector() { const { config, setConfig } = useConfig(); const [opened, setOpened] = useState(false); const { t } = useTranslation('settings/general/shade-selector'); 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)} color={swatch} size={22} style={{ cursor: 'pointer' }} /> )); const secondarySwatches = secondaryShades.map(({ swatch, shade }) => ( setConfigShade(shade)} color={swatch} size={22} style={{ cursor: 'pointer' }} /> )); return ( setOpened(false)} position="left" withArrow > setOpened((o) => !o)} size={22} style={{ display: 'block', cursor: 'pointer' }} /> {primarySwatches} {secondarySwatches} {t('label')} ); }