-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add options to tweak main text/bg colors
- Loading branch information
Showing
8 changed files
with
163 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* TrguiNG - next gen remote GUI for transmission torrent daemon | ||
* Copyright (C) 2023 qu1ck (mail at qu1ck.org) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import type { DefaultMantineColor } from "@mantine/core"; | ||
import { ActionIcon, ColorSwatch, Grid, Popover, useMantineTheme } from "@mantine/core"; | ||
import React, { useState } from "react"; | ||
|
||
export interface ColorSetting { | ||
color: DefaultMantineColor, | ||
shade: number, | ||
} | ||
|
||
interface ColorChooserProps { | ||
value: ColorSetting, | ||
onChange: (value: ColorSetting | undefined) => void, | ||
} | ||
|
||
const shades = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | ||
|
||
export default function ColorChooser(props: ColorChooserProps) { | ||
const theme = useMantineTheme(); | ||
const [opened, setOpened] = useState(false); | ||
const swatchOutline = theme.colorScheme === "dark" ? theme.colors.gray[7] : theme.colors.dark[6]; | ||
|
||
return ( | ||
<Popover width="25rem" position="bottom" withArrow withinPortal shadow="md" opened={opened} onChange={setOpened} > | ||
<Popover.Target> | ||
<ActionIcon onClick={() => { setOpened((o) => !o); }}> | ||
<ColorSwatch | ||
color={theme.colors[props.value.color][props.value.shade]} | ||
sx={{ border: `1px solid ${swatchOutline}` }} /> | ||
</ActionIcon> | ||
</Popover.Target> | ||
<Popover.Dropdown> | ||
<ActionIcon p="lg" onClick={() => { | ||
props.onChange(undefined); | ||
setOpened(false); | ||
}}> | ||
Reset | ||
</ActionIcon> | ||
<Grid columns={10}> | ||
{Object.keys(theme.colors).map((color) => shades.map((shade) => ( | ||
<Grid.Col key={`${color}:${shade}`} span={1}> | ||
<ActionIcon onClick={() => { | ||
props.onChange({ color, shade }); | ||
setOpened(false); | ||
}}> | ||
<ColorSwatch color={theme.colors[color][shade]} /> | ||
</ActionIcon> | ||
</Grid.Col> | ||
)))} | ||
</Grid> | ||
</Popover.Dropdown> | ||
</Popover> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters