import React, {useContext} from 'react'; import {ThemeContext} from '../../contexts/contexts'; import {systemTheme, themeChoices} from '../../themes/names'; import {Icon} from './Icon'; import {Toggle} from './Inputs'; /* * The theme picker. * * Used on the Settings page. The navigation bar has its own compact menu; both * read their options from `themeChoices` so they cannot drift apart. */ export interface ThemePickerProps { /** Show each theme's description under its name. */ withDescriptions?: boolean; } /** * The media filter toggle for the current theme. * * Rendered only by themes that offer a filter, because there is nothing to say * about it otherwise — light and dark have no monochrome media treatment. */ export function MediaFilterToggle() { const {mediaFilter, mediaFilterEnabled, setMediaFilterEnabled} = useContext(ThemeContext); if (!mediaFilter) return null; return
setMediaFilterEnabled(event.currentTarget.checked)} />
} export function ThemePicker({withDescriptions = true}: ThemePickerProps) { const {savedTheme, setTheme} = useContext(ThemeContext); // A user who has never chosen is following the system preference. const selected = savedTheme ?? systemTheme; return <>
{themeChoices.map(choice => { const active = choice.value === selected; return })}
}