✨ Added primary/secondary color selection
Added two new inputs to the options menu: primary and secondary color selectors.
This commit is contained in:
@@ -36,7 +36,9 @@ export default function TitleChanger() {
|
||||
placeholder="/favicon.svg"
|
||||
{...form.getInputProps('favicon')}
|
||||
/>
|
||||
<Button type="submit">Save</Button>
|
||||
<Button type="submit" color={config.settings.primary_color || 'red'}>
|
||||
Save
|
||||
</Button>
|
||||
</Group>
|
||||
</form>
|
||||
</Group>
|
||||
|
||||
93
src/components/Settings/ColorSelector.tsx
Normal file
93
src/components/Settings/ColorSelector.tsx
Normal file
@@ -0,0 +1,93 @@
|
||||
import React, { useState } from 'react';
|
||||
import { ColorSwatch, Group, Popover, Text, useMantineTheme } from '@mantine/core';
|
||||
import { useConfig } from '../../tools/state';
|
||||
|
||||
interface ColorControlProps {
|
||||
type: string;
|
||||
}
|
||||
|
||||
export function ColorSelector({ type }: ColorControlProps) {
|
||||
const { config, setConfig } = useConfig();
|
||||
const [opened, setOpened] = useState(false);
|
||||
const theme = useMantineTheme();
|
||||
const colors = Object.keys(theme.colors).map((color) => ({
|
||||
swatch: theme.colors[color][6],
|
||||
color,
|
||||
}));
|
||||
|
||||
const configColor =
|
||||
type === 'primary'
|
||||
? config.settings.primary_color || 'red'
|
||||
: config.settings.secondary_color || 'orange';
|
||||
|
||||
const setConfigColor = (color: string) => {
|
||||
if (type === 'primary') {
|
||||
setConfig({
|
||||
...config,
|
||||
settings: {
|
||||
...config.settings,
|
||||
primary_color: color,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
setConfig({
|
||||
...config,
|
||||
settings: {
|
||||
...config.settings,
|
||||
secondary_color: color,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const swatches = colors.map(({ color, swatch }) => (
|
||||
<ColorSwatch
|
||||
component="button"
|
||||
type="button"
|
||||
onClick={() => setConfigColor(color)}
|
||||
key={color}
|
||||
color={swatch}
|
||||
size={22}
|
||||
style={{ color: theme.white, cursor: 'pointer' }}
|
||||
/>
|
||||
));
|
||||
|
||||
return (
|
||||
<Group direction="row" spacing={3}>
|
||||
<Popover
|
||||
opened={opened}
|
||||
onClose={() => setOpened(false)}
|
||||
transitionDuration={0}
|
||||
target={
|
||||
<ColorSwatch
|
||||
component="button"
|
||||
type="button"
|
||||
color={theme.colors[configColor || 'red'][6]}
|
||||
onClick={() => setOpened((o) => !o)}
|
||||
size={22}
|
||||
style={{ display: 'block', cursor: 'pointer' }}
|
||||
/>
|
||||
}
|
||||
styles={{
|
||||
root: {
|
||||
marginRight: theme.spacing.xs,
|
||||
},
|
||||
body: {
|
||||
width: 152,
|
||||
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}
|
||||
>
|
||||
<Group spacing="xs">{swatches}</Group>
|
||||
</Popover>
|
||||
<Text>{type[0].toUpperCase() + type.slice(1)} color</Text>
|
||||
</Group>
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import {
|
||||
SegmentedControl,
|
||||
TextInput,
|
||||
Anchor,
|
||||
ColorPicker,
|
||||
useMantineTheme,
|
||||
} from '@mantine/core';
|
||||
import { useState } from 'react';
|
||||
import { IconBrandGithub as BrandGithub } from '@tabler/icons';
|
||||
@@ -14,6 +16,7 @@ import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch';
|
||||
import ConfigChanger from '../Config/ConfigChanger';
|
||||
import SaveConfigComponent from '../Config/SaveConfig';
|
||||
import ModuleEnabler from './ModuleEnabler';
|
||||
import { ColorSelector } from './ColorSelector';
|
||||
|
||||
export default function CommonSettings(args: any) {
|
||||
const { config, setConfig } = useConfig();
|
||||
@@ -30,6 +33,24 @@ export default function CommonSettings(args: any) {
|
||||
matches.find((match) => match.value === config.settings.searchUrl)?.value ?? 'Custom'
|
||||
);
|
||||
|
||||
const theme = useMantineTheme();
|
||||
const colors = Object.keys(theme.colors).map((color) => theme.colors[color][6]);
|
||||
|
||||
const [primaryColor, setPrimaryColor] = useState(config.settings.primary_color);
|
||||
const [secondaryColor, setSecondaryColor] = useState(config.settings.secondary_color);
|
||||
|
||||
// const convertColorHexToNames = (hex: string) => {
|
||||
// // Have to add some exceptions here because it's not converting cleanly
|
||||
// let colorName = Object.keys(theme.colors).find((key) => theme.colors[key].includes(hex));
|
||||
// if (!colorName) {
|
||||
// if (hex === '#228ae6') colorName = 'blue';
|
||||
// else if (hex === '#15abbf') colorName = 'cyan';
|
||||
// else if (hex === '#3fbf57') colorName = 'green';
|
||||
// else if (hex === '#fc7d14') colorName = 'orange';
|
||||
// }
|
||||
// return colorName;
|
||||
// };
|
||||
|
||||
return (
|
||||
<Group direction="column" grow>
|
||||
<Group grow direction="column" spacing={0}>
|
||||
@@ -76,6 +97,8 @@ export default function CommonSettings(args: any) {
|
||||
</Group>
|
||||
<ModuleEnabler />
|
||||
<ColorSchemeSwitch />
|
||||
<ColorSelector type="primary" />
|
||||
<ColorSelector type="secondary" />
|
||||
<ConfigChanger />
|
||||
<SaveConfigComponent />
|
||||
<Text
|
||||
|
||||
@@ -13,6 +13,7 @@ export default function ModuleEnabler(props: any) {
|
||||
size="md"
|
||||
checked={config.modules?.[module.title]?.enabled ?? false}
|
||||
label={`Enable ${module.title}`}
|
||||
color={config.settings.primary_color || 'red'}
|
||||
onChange={(e) => {
|
||||
setConfig({
|
||||
...config,
|
||||
|
||||
Reference in New Issue
Block a user