From ccfd41d38318385edbf15998f48856a65a01e672 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Mon, 23 Feb 2026 22:33:04 -0600 Subject: [PATCH] Replace legacy colors with randomized pastel colors and move appearance related settings to appearance tab --- .../features/settings/cosmetics/Cosmetics.tsx | 20 + .../features/settings/cosmetics/Themes.tsx | 355 ++++++++++++++++++ src/app/features/settings/general/General.tsx | 333 ---------------- src/util/colorMXID.js | 10 +- 4 files changed, 383 insertions(+), 335 deletions(-) create mode 100644 src/app/features/settings/cosmetics/Themes.tsx diff --git a/src/app/features/settings/cosmetics/Cosmetics.tsx b/src/app/features/settings/cosmetics/Cosmetics.tsx index 01a0fd4d..0a8a2fe2 100644 --- a/src/app/features/settings/cosmetics/Cosmetics.tsx +++ b/src/app/features/settings/cosmetics/Cosmetics.tsx @@ -22,6 +22,7 @@ import { JumboEmojiSize, settingsAtom } from '../../../state/settings'; import { SettingTile } from '../../../components/setting-tile'; import { stopPropagation } from '../../../utils/keyboard'; import { SequenceCardStyle } from '../styles.css'; +import { Appearance } from './Themes'; const emojiSizeItems = [ { id: 'none', name: 'None (Same size as text)' }, @@ -149,6 +150,23 @@ function Privacy() { ); } +function IdentityCosmetics() { + const [legacyUsernameColor, setLegacyUsernameColor] = useSetting(settingsAtom, 'legacyUsernameColor'); + + return ( + + Identity + + } + /> + + + ); +} + type CosmeticsProps = { requestClose: () => void; }; @@ -174,6 +192,8 @@ export function Cosmetics({ requestClose }: CosmeticsProps) { + + diff --git a/src/app/features/settings/cosmetics/Themes.tsx b/src/app/features/settings/cosmetics/Themes.tsx new file mode 100644 index 00000000..4d94f61e --- /dev/null +++ b/src/app/features/settings/cosmetics/Themes.tsx @@ -0,0 +1,355 @@ +import React, { + ChangeEventHandler, + KeyboardEventHandler, + MouseEventHandler, + useState, +} from 'react'; +import { + as, + Box, + Button, + Chip, + config, + Icon, + Icons, + Input, + Menu, + MenuItem, + PopOut, + RectCords, + Switch, + Text, + toRem, +} from 'folds'; +import { isKeyHotkey } from 'is-hotkey'; +import FocusTrap from 'focus-trap-react'; +import { SequenceCard } from '../../../components/sequence-card'; +import { useSetting } from '../../../state/hooks/settings'; +import { settingsAtom } from '../../../state/settings'; +import { SettingTile } from '../../../components/setting-tile'; +import { + DarkTheme, + LightTheme, + Theme, + ThemeKind, + useSystemThemeKind, + useThemeNames, + useThemes, +} from '../../../hooks/useTheme'; +import { stopPropagation } from '../../../utils/keyboard'; +import { SequenceCardStyle } from '../styles.css'; + +type ThemeSelectorProps = { + themeNames: Record; + themes: Theme[]; + selected: Theme; + onSelect: (theme: Theme) => void; +}; +export const ThemeSelector = as<'div', ThemeSelectorProps>( + ({ themeNames, themes, selected, onSelect, ...props }, ref) => ( + + + {themes.map((theme) => ( + onSelect(theme)} + > + {themeNames[theme.id] ?? theme.id} + + ))} + + + ) +); + + +function SelectTheme({ disabled }: { disabled?: boolean }) { + const themes = useThemes(); + const themeNames = useThemeNames(); + const [themeId, setThemeId] = useSetting(settingsAtom, 'themeId'); + const [menuCords, setMenuCords] = useState(); + const selectedTheme = themes.find((theme) => theme.id === themeId) ?? LightTheme; + + const handleThemeMenu: MouseEventHandler = (evt) => { + setMenuCords(evt.currentTarget.getBoundingClientRect()); + }; + + const handleThemeSelect = (theme: Theme) => { + setThemeId(theme.id); + setMenuCords(undefined); + }; + + return ( + <> + + setMenuCords(undefined), + clickOutsideDeactivates: true, + isKeyForward: (evt: KeyboardEvent) => + evt.key === 'ArrowDown' || evt.key === 'ArrowRight', + isKeyBackward: (evt: KeyboardEvent) => + evt.key === 'ArrowUp' || evt.key === 'ArrowLeft', + escapeDeactivates: stopPropagation, + }} + > + + + } + /> + + ); +} + + +function SystemThemePreferences() { + const themeKind = useSystemThemeKind(); + const themeNames = useThemeNames(); + const themes = useThemes(); + const [lightThemeId, setLightThemeId] = useSetting(settingsAtom, 'lightThemeId'); + const [darkThemeId, setDarkThemeId] = useSetting(settingsAtom, 'darkThemeId'); + + const lightThemes = themes.filter((theme) => theme.kind === ThemeKind.Light); + const darkThemes = themes.filter((theme) => theme.kind === ThemeKind.Dark); + + const selectedLightTheme = lightThemes.find((theme) => theme.id === lightThemeId) ?? LightTheme; + const selectedDarkTheme = darkThemes.find((theme) => theme.id === darkThemeId) ?? DarkTheme; + + const [ltCords, setLTCords] = useState(); + const [dtCords, setDTCords] = useState(); + + const handleLightThemeMenu: MouseEventHandler = (evt) => { + setLTCords(evt.currentTarget.getBoundingClientRect()); + }; + const handleDarkThemeMenu: MouseEventHandler = (evt) => { + setDTCords(evt.currentTarget.getBoundingClientRect()); + }; + + const handleLightThemeSelect = (theme: Theme) => { + setLightThemeId(theme.id); + setLTCords(undefined); + }; + + const handleDarkThemeSelect = (theme: Theme) => { + setDarkThemeId(theme.id); + setDTCords(undefined); + }; + + return ( + + } + onClick={handleLightThemeMenu} + > + {themeNames[selectedLightTheme.id] ?? selectedLightTheme.id} + + } + /> + setLTCords(undefined), + clickOutsideDeactivates: true, + isKeyForward: (evt: KeyboardEvent) => + evt.key === 'ArrowDown' || evt.key === 'ArrowRight', + isKeyBackward: (evt: KeyboardEvent) => + evt.key === 'ArrowUp' || evt.key === 'ArrowLeft', + escapeDeactivates: stopPropagation, + }} + > + + + } + /> + } + onClick={handleDarkThemeMenu} + > + {themeNames[selectedDarkTheme.id] ?? selectedDarkTheme.id} + + } + /> + setDTCords(undefined), + clickOutsideDeactivates: true, + isKeyForward: (evt: KeyboardEvent) => + evt.key === 'ArrowDown' || evt.key === 'ArrowRight', + isKeyBackward: (evt: KeyboardEvent) => + evt.key === 'ArrowUp' || evt.key === 'ArrowLeft', + escapeDeactivates: stopPropagation, + }} + > + + + } + /> + + ); +} + +function ThemeSettings() { + const [systemTheme, setSystemTheme] = useSetting(settingsAtom, 'useSystemTheme'); + const [monochromeMode, setMonochromeMode] = useSetting(settingsAtom, 'monochromeMode'); + + return ( + + Theme + + + } + /> + {systemTheme && } + + + + } + /> + + + + } + /> + + + ); +} + +function PageZoomInput() { + const [pageZoom, setPageZoom] = useSetting(settingsAtom, 'pageZoom'); + const [currentZoom, setCurrentZoom] = useState(`${pageZoom}`); + + const handleZoomChange: ChangeEventHandler = (evt) => { + setCurrentZoom(evt.target.value); + }; + + const handleZoomEnter: KeyboardEventHandler = (evt) => { + if (isKeyHotkey('escape', evt)) { + evt.stopPropagation(); + setCurrentZoom(pageZoom.toString()); + } + if ( + isKeyHotkey('enter', evt) && + 'value' in evt.target && + typeof evt.target.value === 'string' + ) { + const newZoom = parseInt(evt.target.value, 10); + if (Number.isNaN(newZoom)) return; + const safeZoom = Math.max(Math.min(newZoom, 150), 75); + setPageZoom(safeZoom); + setCurrentZoom(safeZoom.toString()); + } + }; + + return ( + %} + outlined + /> + ); +} +export function Appearance() { + const [twitterEmoji, setTwitterEmoji] = useSetting(settingsAtom, 'twitterEmoji'); + + return ( + + + + + + Visual Tweaks + + + } + /> + + + + } /> + + + + ); +} diff --git a/src/app/features/settings/general/General.tsx b/src/app/features/settings/general/General.tsx index 273a7496..4ea86d82 100644 --- a/src/app/features/settings/general/General.tsx +++ b/src/app/features/settings/general/General.tsx @@ -1,17 +1,14 @@ import React, { ChangeEventHandler, FormEventHandler, - KeyboardEventHandler, MouseEventHandler, useEffect, useState, } from 'react'; import dayjs from 'dayjs'; import { - as, Box, Button, - Chip, config, Header, Icon, @@ -25,9 +22,7 @@ import { Scroll, Switch, Text, - toRem, } from 'folds'; -import { isKeyHotkey } from 'is-hotkey'; import FocusTrap from 'focus-trap-react'; import { Page, PageContent, PageHeader } from '../../../components/page'; import { SequenceCard } from '../../../components/sequence-card'; @@ -36,323 +31,12 @@ import { DateFormat, MessageLayout, MessageSpacing, RightSwipeAction, settingsAt import { SettingTile } from '../../../components/setting-tile'; import { KeySymbol } from '../../../utils/key-symbol'; import { isMacOS, mobileOrTablet } from '../../../utils/user-agent'; -import { - DarkTheme, - LightTheme, - Theme, - ThemeKind, - useSystemThemeKind, - useThemeNames, - useThemes, -} from '../../../hooks/useTheme'; import { stopPropagation } from '../../../utils/keyboard'; import { useMessageLayoutItems } from '../../../hooks/useMessageLayout'; import { useMessageSpacingItems } from '../../../hooks/useMessageSpacing'; import { useDateFormatItems } from '../../../hooks/useDateFormat'; import { SequenceCardStyle } from '../styles.css'; -type ThemeSelectorProps = { - themeNames: Record; - themes: Theme[]; - selected: Theme; - onSelect: (theme: Theme) => void; -}; -const ThemeSelector = as<'div', ThemeSelectorProps>( - ({ themeNames, themes, selected, onSelect, ...props }, ref) => ( - - - {themes.map((theme) => ( - onSelect(theme)} - > - {themeNames[theme.id] ?? theme.id} - - ))} - - - ) -); - -function SelectTheme({ disabled }: { disabled?: boolean }) { - const themes = useThemes(); - const themeNames = useThemeNames(); - const [themeId, setThemeId] = useSetting(settingsAtom, 'themeId'); - const [menuCords, setMenuCords] = useState(); - const selectedTheme = themes.find((theme) => theme.id === themeId) ?? LightTheme; - - const handleThemeMenu: MouseEventHandler = (evt) => { - setMenuCords(evt.currentTarget.getBoundingClientRect()); - }; - - const handleThemeSelect = (theme: Theme) => { - setThemeId(theme.id); - setMenuCords(undefined); - }; - - return ( - <> - - setMenuCords(undefined), - clickOutsideDeactivates: true, - isKeyForward: (evt: KeyboardEvent) => - evt.key === 'ArrowDown' || evt.key === 'ArrowRight', - isKeyBackward: (evt: KeyboardEvent) => - evt.key === 'ArrowUp' || evt.key === 'ArrowLeft', - escapeDeactivates: stopPropagation, - }} - > - - - } - /> - - ); -} - -function SystemThemePreferences() { - const themeKind = useSystemThemeKind(); - const themeNames = useThemeNames(); - const themes = useThemes(); - const [lightThemeId, setLightThemeId] = useSetting(settingsAtom, 'lightThemeId'); - const [darkThemeId, setDarkThemeId] = useSetting(settingsAtom, 'darkThemeId'); - - const lightThemes = themes.filter((theme) => theme.kind === ThemeKind.Light); - const darkThemes = themes.filter((theme) => theme.kind === ThemeKind.Dark); - - const selectedLightTheme = lightThemes.find((theme) => theme.id === lightThemeId) ?? LightTheme; - const selectedDarkTheme = darkThemes.find((theme) => theme.id === darkThemeId) ?? DarkTheme; - - const [ltCords, setLTCords] = useState(); - const [dtCords, setDTCords] = useState(); - - const handleLightThemeMenu: MouseEventHandler = (evt) => { - setLTCords(evt.currentTarget.getBoundingClientRect()); - }; - const handleDarkThemeMenu: MouseEventHandler = (evt) => { - setDTCords(evt.currentTarget.getBoundingClientRect()); - }; - - const handleLightThemeSelect = (theme: Theme) => { - setLightThemeId(theme.id); - setLTCords(undefined); - }; - - const handleDarkThemeSelect = (theme: Theme) => { - setDarkThemeId(theme.id); - setDTCords(undefined); - }; - - return ( - - } - onClick={handleLightThemeMenu} - > - {themeNames[selectedLightTheme.id] ?? selectedLightTheme.id} - - } - /> - setLTCords(undefined), - clickOutsideDeactivates: true, - isKeyForward: (evt: KeyboardEvent) => - evt.key === 'ArrowDown' || evt.key === 'ArrowRight', - isKeyBackward: (evt: KeyboardEvent) => - evt.key === 'ArrowUp' || evt.key === 'ArrowLeft', - escapeDeactivates: stopPropagation, - }} - > - - - } - /> - } - onClick={handleDarkThemeMenu} - > - {themeNames[selectedDarkTheme.id] ?? selectedDarkTheme.id} - - } - /> - setDTCords(undefined), - clickOutsideDeactivates: true, - isKeyForward: (evt: KeyboardEvent) => - evt.key === 'ArrowDown' || evt.key === 'ArrowRight', - isKeyBackward: (evt: KeyboardEvent) => - evt.key === 'ArrowUp' || evt.key === 'ArrowLeft', - escapeDeactivates: stopPropagation, - }} - > - - - } - /> - - ); -} - -function PageZoomInput() { - const [pageZoom, setPageZoom] = useSetting(settingsAtom, 'pageZoom'); - const [currentZoom, setCurrentZoom] = useState(`${pageZoom}`); - - const handleZoomChange: ChangeEventHandler = (evt) => { - setCurrentZoom(evt.target.value); - }; - - const handleZoomEnter: KeyboardEventHandler = (evt) => { - if (isKeyHotkey('escape', evt)) { - evt.stopPropagation(); - setCurrentZoom(pageZoom.toString()); - } - if ( - isKeyHotkey('enter', evt) && - 'value' in evt.target && - typeof evt.target.value === 'string' - ) { - const newZoom = parseInt(evt.target.value, 10); - if (Number.isNaN(newZoom)) return; - const safeZoom = Math.max(Math.min(newZoom, 150), 75); - setPageZoom(safeZoom); - setCurrentZoom(safeZoom.toString()); - } - }; - - return ( - %} - outlined - /> - ); -} - -function Appearance() { - const [systemTheme, setSystemTheme] = useSetting(settingsAtom, 'useSystemTheme'); - const [monochromeMode, setMonochromeMode] = useSetting(settingsAtom, 'monochromeMode'); - const [twitterEmoji, setTwitterEmoji] = useSetting(settingsAtom, 'twitterEmoji'); - - return ( - - Appearance - - } - /> - {systemTheme && } - - - - } - /> - - - - } - /> - - - - } - /> - - - - } /> - - - ); -} type DateHintProps = { hasChanges: boolean; @@ -983,10 +667,6 @@ function Gestures({ isMobile }: { isMobile: boolean }) { } function Messages() { - const [legacyUsernameColor, setLegacyUsernameColor] = useSetting( - settingsAtom, - 'legacyUsernameColor' - ); const [hideMembershipEvents, setHideMembershipEvents] = useSetting( settingsAtom, 'hideMembershipEvents' @@ -1009,18 +689,6 @@ function Messages() { } /> - - - } - /> - - diff --git a/src/util/colorMXID.js b/src/util/colorMXID.js index 95600d29..ef7d6edc 100644 --- a/src/util/colorMXID.js +++ b/src/util/colorMXID.js @@ -23,5 +23,11 @@ export function cssColorMXID(userId) { } export default function colorMXID(userId) { - return `var(${cssColorMXID(userId)})`; -} + const hash = hashCode(userId); + + const h = hash % 360; + const s = 65; + const l = 80; + + return `hsl(${h}, ${s}%, ${l}%)`; +} \ No newline at end of file