2021-07-05 06:23:23 -04:00
|
|
|
// @ts-ignore
|
|
|
|
import pSBC from "shade-blend-color";
|
|
|
|
|
2021-06-19 17:37:12 -04:00
|
|
|
import styles from "./Panes.module.scss";
|
2021-07-05 06:23:23 -04:00
|
|
|
import { Text } from "preact-i18n";
|
|
|
|
import { useCallback, useContext, useEffect, useState } from "preact/hooks";
|
|
|
|
|
|
|
|
import TextAreaAutoSize from "../../../lib/TextAreaAutoSize";
|
2021-06-19 17:37:12 -04:00
|
|
|
import { debounce } from "../../../lib/debounce";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import { dispatch } from "../../../redux";
|
2021-06-19 17:37:12 -04:00
|
|
|
import { connectState } from "../../../redux/connector";
|
|
|
|
import { EmojiPacks, Settings } from "../../../redux/reducers/settings";
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
import {
|
2021-07-05 06:25:20 -04:00
|
|
|
DEFAULT_FONT,
|
|
|
|
DEFAULT_MONO_FONT,
|
|
|
|
FONTS,
|
|
|
|
FONT_KEYS,
|
|
|
|
MONOSCAPE_FONTS,
|
|
|
|
MONOSCAPE_FONT_KEYS,
|
|
|
|
Theme,
|
|
|
|
ThemeContext,
|
|
|
|
ThemeOptions,
|
2021-07-05 06:23:23 -04:00
|
|
|
} from "../../../context/Theme";
|
|
|
|
import { useIntermediate } from "../../../context/intermediate/Intermediate";
|
2021-06-20 06:05:12 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
import CollapsibleSection from "../../../components/common/CollapsibleSection";
|
|
|
|
import Button from "../../../components/ui/Button";
|
|
|
|
import Checkbox from "../../../components/ui/Checkbox";
|
|
|
|
import ColourSwatches from "../../../components/ui/ColourSwatches";
|
|
|
|
import ComboBox from "../../../components/ui/ComboBox";
|
|
|
|
import InputBox from "../../../components/ui/InputBox";
|
|
|
|
import darkSVG from "../assets/dark.svg";
|
|
|
|
import lightSVG from "../assets/light.svg";
|
|
|
|
import mutantSVG from "../assets/mutant_emoji.svg";
|
|
|
|
import notoSVG from "../assets/noto_emoji.svg";
|
|
|
|
import openmojiSVG from "../assets/openmoji_emoji.svg";
|
|
|
|
import twemojiSVG from "../assets/twemoji_emoji.svg";
|
2021-07-08 16:51:12 -04:00
|
|
|
import { Reset, Import, Pencil } from "@styled-icons/boxicons-regular";
|
2021-07-08 15:57:52 -04:00
|
|
|
import Tooltip from "../../../components/common/Tooltip";
|
2021-06-20 06:05:12 -04:00
|
|
|
|
2021-06-19 17:37:12 -04:00
|
|
|
interface Props {
|
2021-07-05 06:25:20 -04:00
|
|
|
settings: Settings;
|
2021-06-19 17:37:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ! FIXME: code needs to be rewritten to fix jittering
|
2021-07-05 05:59:48 -04:00
|
|
|
export function Component(props: Props) {
|
2021-07-05 06:25:20 -04:00
|
|
|
const theme = useContext(ThemeContext);
|
|
|
|
const { writeClipboard, openScreen } = useIntermediate();
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
function setTheme(theme: ThemeOptions) {
|
|
|
|
dispatch({
|
|
|
|
type: "SETTINGS_SET_THEME",
|
|
|
|
theme,
|
|
|
|
});
|
|
|
|
}
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
function pushOverride(custom: Partial<Theme>) {
|
|
|
|
dispatch({
|
|
|
|
type: "SETTINGS_SET_THEME_OVERRIDE",
|
|
|
|
custom,
|
|
|
|
});
|
|
|
|
}
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
function setAccent(accent: string) {
|
|
|
|
setOverride({
|
|
|
|
accent,
|
|
|
|
"scrollbar-thumb": pSBC(-0.2, accent),
|
|
|
|
});
|
|
|
|
}
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
const emojiPack = props.settings.appearance?.emojiPack ?? "mutant";
|
|
|
|
function setEmojiPack(emojiPack: EmojiPacks) {
|
|
|
|
dispatch({
|
|
|
|
type: "SETTINGS_SET_APPEARANCE",
|
|
|
|
options: {
|
|
|
|
emojiPack,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
const setOverride = useCallback(debounce(pushOverride, 200), []) as (
|
|
|
|
custom: Partial<Theme>,
|
|
|
|
) => void;
|
|
|
|
const [css, setCSS] = useState(props.settings.theme?.custom?.css ?? "");
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
useEffect(() => setOverride({ css }), [css]);
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
const selected = props.settings.theme?.preset ?? "dark";
|
|
|
|
return (
|
|
|
|
<div className={styles.appearance}>
|
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.appearance.theme" />
|
|
|
|
</h3>
|
|
|
|
<div className={styles.themes}>
|
|
|
|
<div className={styles.theme}>
|
|
|
|
<img
|
|
|
|
src={lightSVG}
|
|
|
|
data-active={selected === "light"}
|
|
|
|
onClick={() =>
|
|
|
|
selected !== "light" &&
|
|
|
|
setTheme({ preset: "light" })
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<h4>
|
|
|
|
<Text id="app.settings.pages.appearance.color.light" />
|
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
<div className={styles.theme}>
|
|
|
|
<img
|
|
|
|
src={darkSVG}
|
|
|
|
data-active={selected === "dark"}
|
|
|
|
onClick={() =>
|
|
|
|
selected !== "dark" && setTheme({ preset: "dark" })
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<h4>
|
|
|
|
<Text id="app.settings.pages.appearance.color.dark" />
|
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-05 18:06:03 -04:00
|
|
|
{/*<Checkbox
|
|
|
|
checked={props.settings.theme?.ligatures === true}
|
|
|
|
onChange={() =>
|
|
|
|
setTheme({
|
|
|
|
ligatures: !props.settings.theme?.ligatures,
|
|
|
|
})
|
|
|
|
}>
|
|
|
|
Use the system theme
|
|
|
|
</Checkbox>*/}
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.appearance.accent_selector" />
|
|
|
|
</h3>
|
|
|
|
<ColourSwatches value={theme.accent} onChange={setAccent} />
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
{/*<h3>
|
2021-06-19 17:37:12 -04:00
|
|
|
<Text id="app.settings.pages.appearance.message_display" />
|
|
|
|
</h3>
|
|
|
|
<div className={styles.display}>
|
|
|
|
<Radio
|
|
|
|
description={
|
|
|
|
<Text id="app.settings.pages.appearance.display.default_description" />
|
|
|
|
}
|
|
|
|
checked
|
|
|
|
>
|
|
|
|
<Text id="app.settings.pages.appearance.display.default" />
|
|
|
|
</Radio>
|
|
|
|
<Radio
|
|
|
|
description={
|
|
|
|
<Text id="app.settings.pages.appearance.display.compact_description" />
|
|
|
|
}
|
|
|
|
disabled
|
|
|
|
>
|
|
|
|
<Text id="app.settings.pages.appearance.display.compact" />
|
|
|
|
</Radio>
|
|
|
|
</div>*/}
|
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.appearance.font" />
|
|
|
|
</h3>
|
|
|
|
<ComboBox
|
|
|
|
value={theme.font ?? DEFAULT_FONT}
|
|
|
|
onChange={(e) =>
|
2021-07-05 16:03:34 -04:00
|
|
|
pushOverride({ font: e.currentTarget.value as any })
|
2021-07-05 06:25:20 -04:00
|
|
|
}>
|
|
|
|
{FONT_KEYS.map((key) => (
|
|
|
|
<option value={key}>
|
|
|
|
{FONTS[key as keyof typeof FONTS].name}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</ComboBox>
|
|
|
|
<p>
|
|
|
|
<Checkbox
|
|
|
|
checked={props.settings.theme?.ligatures === true}
|
|
|
|
onChange={() =>
|
|
|
|
setTheme({
|
|
|
|
ligatures: !props.settings.theme?.ligatures,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
description={
|
|
|
|
<Text id="app.settings.pages.appearance.ligatures_desc" />
|
|
|
|
}>
|
|
|
|
<Text id="app.settings.pages.appearance.ligatures" />
|
|
|
|
</Checkbox>
|
|
|
|
</p>
|
2021-07-04 12:56:18 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.appearance.emoji_pack" />
|
|
|
|
</h3>
|
|
|
|
<div className={styles.emojiPack}>
|
|
|
|
<div className={styles.row}>
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
className={styles.button}
|
|
|
|
onClick={() => setEmojiPack("mutant")}
|
|
|
|
data-active={emojiPack === "mutant"}>
|
|
|
|
<img src={mutantSVG} draggable={false} />
|
|
|
|
</div>
|
|
|
|
<h4>
|
|
|
|
Mutant Remix{" "}
|
|
|
|
<a
|
|
|
|
href="https://mutant.revolt.chat"
|
|
|
|
target="_blank">
|
|
|
|
(by Revolt)
|
|
|
|
</a>
|
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
className={styles.button}
|
|
|
|
onClick={() => setEmojiPack("twemoji")}
|
|
|
|
data-active={emojiPack === "twemoji"}>
|
|
|
|
<img src={twemojiSVG} draggable={false} />
|
|
|
|
</div>
|
|
|
|
<h4>Twemoji</h4>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.row}>
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
className={styles.button}
|
|
|
|
onClick={() => setEmojiPack("openmoji")}
|
|
|
|
data-active={emojiPack === "openmoji"}>
|
|
|
|
<img src={openmojiSVG} draggable={false} />
|
|
|
|
</div>
|
|
|
|
<h4>Openmoji</h4>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
className={styles.button}
|
|
|
|
onClick={() => setEmojiPack("noto")}
|
|
|
|
data-active={emojiPack === "noto"}>
|
|
|
|
<img src={notoSVG} draggable={false} />
|
|
|
|
</div>
|
|
|
|
<h4>Noto Emoji</h4>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
<CollapsibleSection
|
|
|
|
defaultValue={false}
|
2021-07-08 16:51:12 -04:00
|
|
|
id="settings_overrides"
|
|
|
|
summary={<Text id="app.settings.pages.appearance.overrides" />}>
|
2021-07-05 06:25:20 -04:00
|
|
|
<div className={styles.actions}>
|
2021-07-08 15:57:52 -04:00
|
|
|
<Tooltip content={<Text id="app.settings.pages.appearance.reset_overrides" />}>
|
|
|
|
<Button contrast iconbutton onClick={() => setTheme({ custom: {} })}>
|
|
|
|
<Reset size={22}/>
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
<div className={styles.code} onClick={() => writeClipboard(JSON.stringify(theme))}>
|
|
|
|
<Tooltip content={<Text id="app.special.copy" />}>
|
|
|
|
{JSON.stringify(theme)}
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
<Tooltip content={<Text id="app.settings.pages.appearance.import" />}>
|
|
|
|
<Button
|
|
|
|
contrast
|
|
|
|
iconbutton
|
|
|
|
onClick={async () => {
|
|
|
|
try {
|
|
|
|
const text = await navigator.clipboard.readText();
|
|
|
|
setOverride(JSON.parse(text));
|
|
|
|
} catch (err) {
|
|
|
|
openScreen({
|
|
|
|
id: "_input",
|
|
|
|
question: (
|
|
|
|
<Text id="app.settings.pages.appearance.import_theme" />
|
|
|
|
),
|
|
|
|
field: (
|
|
|
|
<Text id="app.settings.pages.appearance.theme_data" />
|
|
|
|
),
|
|
|
|
callback: async (string) =>
|
|
|
|
setOverride(JSON.parse(string)),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}>
|
|
|
|
<Import size={22}/>
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
2021-07-05 06:25:20 -04:00
|
|
|
</div>
|
|
|
|
<div className={styles.overrides}>
|
|
|
|
{(
|
|
|
|
[
|
|
|
|
"accent",
|
|
|
|
"background",
|
|
|
|
"foreground",
|
|
|
|
"primary-background",
|
|
|
|
"primary-header",
|
|
|
|
"secondary-background",
|
|
|
|
"secondary-foreground",
|
|
|
|
"secondary-header",
|
|
|
|
"tertiary-background",
|
|
|
|
"tertiary-foreground",
|
|
|
|
"block",
|
|
|
|
"message-box",
|
|
|
|
"mention",
|
|
|
|
"scrollbar-thumb",
|
|
|
|
"scrollbar-track",
|
|
|
|
"status-online",
|
|
|
|
"status-away",
|
|
|
|
"status-busy",
|
|
|
|
"status-streaming",
|
|
|
|
"status-invisible",
|
|
|
|
"success",
|
|
|
|
"warning",
|
|
|
|
"error",
|
|
|
|
"hover",
|
|
|
|
] as const
|
|
|
|
).map((x) => (
|
2021-07-08 16:51:12 -04:00
|
|
|
<div className={styles.entry} key={x}
|
|
|
|
style={{ backgroundColor: theme[x] }}>
|
|
|
|
<div className={styles.input}>
|
|
|
|
<input
|
|
|
|
type="color"
|
|
|
|
value={theme[x]}
|
|
|
|
onChange={(v) =>
|
|
|
|
setOverride({
|
|
|
|
[x]: v.currentTarget.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-07-05 06:25:20 -04:00
|
|
|
<span>{x}</span>
|
|
|
|
<div className={styles.override}>
|
2021-07-08 16:51:12 -04:00
|
|
|
<div className={styles.picker}
|
|
|
|
onClick={e => e.currentTarget.parentElement?.parentElement?.querySelector('input')?.click()}>
|
|
|
|
<Pencil size={24} />
|
2021-07-05 06:25:20 -04:00
|
|
|
</div>
|
|
|
|
<InputBox
|
2021-07-08 16:51:12 -04:00
|
|
|
type="text"
|
2021-07-05 06:25:20 -04:00
|
|
|
className={styles.text}
|
|
|
|
value={theme[x]}
|
|
|
|
onChange={(y) =>
|
|
|
|
setOverride({
|
|
|
|
[x]: y.currentTarget.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2021-07-08 16:51:12 -04:00
|
|
|
</CollapsibleSection>
|
2021-07-04 12:56:18 -04:00
|
|
|
|
2021-07-08 16:51:12 -04:00
|
|
|
<CollapsibleSection
|
|
|
|
id="settings_advanced_appearance"
|
|
|
|
defaultValue={false}
|
|
|
|
summary={<Text id="app.settings.pages.appearance.advanced" />}>
|
2021-07-05 06:25:20 -04:00
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.appearance.mono_font" />
|
|
|
|
</h3>
|
|
|
|
<ComboBox
|
|
|
|
value={theme.monoscapeFont ?? DEFAULT_MONO_FONT}
|
|
|
|
onChange={(e) =>
|
2021-07-05 16:03:34 -04:00
|
|
|
pushOverride({
|
|
|
|
monoscapeFont: e.currentTarget.value as any,
|
2021-07-05 06:25:20 -04:00
|
|
|
})
|
|
|
|
}>
|
|
|
|
{MONOSCAPE_FONT_KEYS.map((key) => (
|
|
|
|
<option value={key}>
|
|
|
|
{
|
|
|
|
MONOSCAPE_FONTS[
|
|
|
|
key as keyof typeof MONOSCAPE_FONTS
|
|
|
|
].name
|
|
|
|
}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</ComboBox>
|
2021-07-04 12:56:18 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.appearance.custom_css" />
|
|
|
|
</h3>
|
|
|
|
<TextAreaAutoSize
|
|
|
|
maxRows={20}
|
|
|
|
minHeight={480}
|
|
|
|
code
|
|
|
|
value={css}
|
|
|
|
onChange={(ev) => setCSS(ev.currentTarget.value)}
|
|
|
|
/>
|
|
|
|
</CollapsibleSection>
|
|
|
|
</div>
|
|
|
|
);
|
2021-06-19 17:37:12 -04:00
|
|
|
}
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
export const Appearance = connectState(Component, (state) => {
|
2021-07-05 06:25:20 -04:00
|
|
|
return {
|
|
|
|
settings: state.settings,
|
|
|
|
};
|
2021-07-05 06:23:23 -04:00
|
|
|
});
|