Random themes

This commit is contained in:
Sean Edmunds
2024-12-05 16:32:28 -06:00
parent 62b2f4c661
commit 00c141d8d7
2 changed files with 55 additions and 2 deletions

View File

@@ -39,8 +39,13 @@ function App() {
const [theme, setTheme] = useAtom(appTheme); const [theme, setTheme] = useAtom(appTheme);
useEffect(() => { useEffect(() => {
if (data && themeName) { if (data && themeName) {
if (themeName !== 'random') {
const temp = data.find((t: any) => t.name === themeName); const temp = data.find((t: any) => t.name === themeName);
setTheme(temp); setTheme(temp);
} else {
const index = Math.floor(Math.random() * data.length);
setTheme(data[index]);
}
} }
}, [isFetched, themeName]); }, [isFetched, themeName]);

View File

@@ -79,6 +79,10 @@ function ThemesSettings({ theme }: any) {
openDeleteConfirmModal(theme); openDeleteConfirmModal(theme);
close(); close();
}; };
const randomColor = () => {
return `rgba(${Math.random() * 255},${Math.random() * 255},${Math.random() * 255},1)`;
};
return ( return (
<> <>
<Modal.Root <Modal.Root
@@ -374,6 +378,50 @@ function ThemesSettings({ theme }: any) {
</Group> </Group>
</Stack> </Stack>
))} ))}
<Stack key={theme.name} w={'300px'}>
<Group gap={0} justify='space-between'>
<Button
w={'100%'}
h={'75px'}
style={{
backgroundSize: 'cover',
backgroundColor: 'white',
border: 'solid black',
color: 'black',
}}
data-theme={theme.name}
onClick={() => {
setValue('random');
}}
>
Random
</Button>
</Group>
<Group justify='space-between' gap={0}>
<Group className='theme-palette'>
<ActionIcon
className={actionIconClasses.editButton}
classNames={actionIconClasses}
onClick={() => handleOpen(theme)}
>
<FiEdit />
</ActionIcon>
<ColorSwatch color={randomColor()} />
<ColorSwatch color={randomColor()} />
<ColorSwatch color={randomColor()} />
<ColorSwatch color={randomColor()} />
<ColorSwatch color={randomColor()} />
<ActionIcon
className={actionIconClasses.editButton}
classNames={actionIconClasses}
onClick={() => handleDeleteTheme(theme)}
>
<FiTrash color='red' />
</ActionIcon>
</Group>
</Group>
</Stack>
</Group> </Group>
</Stack> </Stack>
</> </>