mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-24 06:58:10 -05:00
* Kysely initial * Badges initial * Badge routes migrated * Badges migrated * Calendar work * Fix one type problem * Calendar work * findResultsByUserId work * Calendar reworking finished * PlusSuggestions work * Migrated suggestions * Builds progress * Migrated builds * Admin migrated * Migrate articles * User search * Faster getUser * Selectable/insertable as global * Refresh prod db script + patronTier index * identifierToUserId * updateProfile * findByIdentifier * More indexes * User upsert * upsertLite * findAllPlusMembers * updateResultHighlights * updateMany * User finished migration * Fix types * Fix PlusVotingResult typing * PlusVotingRepository WIP * Migrated resultsByMonthYear * Migrated plusVotes (done with db. related migrations) * Plus code to features folder * Fix TODOs * Export * Fix range * Migrate some user pages * Move rest user routes * Move /play * Map list generator * Front page * Move map list generation logic * Move plus voting logic * Info * API * Adjust TODOs * theme * Auth * Remove TODO
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { useTranslation } from "~/hooks/useTranslation";
|
|
import { Button } from "../Button";
|
|
import { MoonIcon } from "../icons/Moon";
|
|
import { SunIcon } from "../icons/Sun";
|
|
import { SunAndMoonIcon } from "../icons/SunAndMoon";
|
|
import { Popover } from "../Popover";
|
|
import { SelectedThemeIcon } from "./SelectedThemeIcon";
|
|
import { Theme, useTheme } from "~/features/theme/core/provider";
|
|
|
|
const ThemeIcons = {
|
|
[Theme.LIGHT]: SunIcon,
|
|
[Theme.DARK]: MoonIcon,
|
|
auto: SunAndMoonIcon,
|
|
};
|
|
|
|
export function ThemeChanger({
|
|
children,
|
|
plain,
|
|
}: {
|
|
children?: React.ReactNode;
|
|
plain?: boolean;
|
|
}) {
|
|
const { userTheme, setUserTheme } = useTheme();
|
|
const { t } = useTranslation();
|
|
|
|
if (!userTheme) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Popover
|
|
buttonChildren={children ?? <SelectedThemeIcon />}
|
|
triggerClassName={plain ? undefined : "layout__header__button"}
|
|
>
|
|
<div className="layout__user-popover">
|
|
{(["auto", Theme.DARK, Theme.LIGHT] as const).map((theme) => {
|
|
const Icon = ThemeIcons[theme];
|
|
const selected = userTheme === theme;
|
|
return (
|
|
<Button
|
|
variant="minimal"
|
|
key={theme}
|
|
size="tiny"
|
|
icon={<Icon alt="" />}
|
|
// TODO: Remove this and find better semantic representation than
|
|
// just multiple buttons. Maybe radio group?
|
|
aria-current={selected}
|
|
className={selected ? undefined : "text-main-forced"}
|
|
onClick={() => setUserTheme(theme)}
|
|
>
|
|
{t(`theme.${theme}`)}
|
|
</Button>
|
|
);
|
|
})}
|
|
</div>
|
|
</Popover>
|
|
);
|
|
}
|