From d1ac1beb9104d512e4210ddbf68b9b9b2f848c24 Mon Sep 17 00:00:00 2001 From: Josie Date: Fri, 7 Aug 2026 07:45:02 +0100 Subject: [PATCH 1/2] Accessible color stuff --- src/app/features/room/message/Message.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx index d4698fd58..9ce8dca54 100644 --- a/src/app/features/room/message/Message.tsx +++ b/src/app/features/room/message/Message.tsx @@ -134,6 +134,7 @@ export type MessageProps = { import { useMenuAnchor } from '$hooks/useMenuAnchor'; import { ThemeKind, useActiveTheme } from '$hooks/useTheme'; import { shouldIgnoreMessageLongPress } from './messageTouch'; +import { accessibleColor } from '$plugins/color'; const clamp = (str: string, len: number) => (str.length > len ? `${str.slice(0, len)}...` : str); @@ -477,6 +478,11 @@ function MessageInternal( false, isVisible ); + + const accessibleNameColor = useCallback((color: any) => + (color) ? accessibleColor(activeTheme.kind, color) : color + , []) + const senderFallbackName = getMxIdLocalPart(senderId) ?? senderId; const resolvedSenderDisplayName = senderDisplayName === senderFallbackName || senderDisplayName === senderId @@ -588,7 +594,7 @@ function MessageInternal( )} {showPmPInfo && ( From 85526654568c64ae8be9507afe5689f8e08bae5f Mon Sep 17 00:00:00 2001 From: Josie Date: Fri, 7 Aug 2026 10:04:32 +0100 Subject: [PATCH 2/2] Add accessibility tab --- ...ity_tab_and_accessible_color_correction.md | 5 + src/app/components/message/Reply.tsx | 30 ++- src/app/features/room/message/Message.tsx | 23 ++- src/app/features/settings/Settings.tsx | 8 +- .../settings/accessibility/Accessibility.tsx | 181 ++++++++++++++++++ .../features/settings/cosmetics/Cosmetics.tsx | 38 ---- .../features/settings/cosmetics/Themes.tsx | 41 ---- src/app/features/settings/routes.ts | 2 + src/app/features/settings/settingsLink.ts | 15 +- src/app/hooks/useSableCosmetics.ts | 21 +- src/app/plugins/color.ts | 31 ++- src/app/state/settings.ts | 15 +- 12 files changed, 301 insertions(+), 109 deletions(-) create mode 100644 .changeset/add_accessibility_tab_and_accessible_color_correction.md create mode 100644 src/app/features/settings/accessibility/Accessibility.tsx diff --git a/.changeset/add_accessibility_tab_and_accessible_color_correction.md b/.changeset/add_accessibility_tab_and_accessible_color_correction.md new file mode 100644 index 000000000..1ca120853 --- /dev/null +++ b/.changeset/add_accessibility_tab_and_accessible_color_correction.md @@ -0,0 +1,5 @@ +--- +default: minor +--- + +# Add accessibility tab and accessible color correction diff --git a/src/app/components/message/Reply.tsx b/src/app/components/message/Reply.tsx index 96898cdd4..6e7c7fc7f 100644 --- a/src/app/components/message/Reply.tsx +++ b/src/app/components/message/Reply.tsx @@ -68,6 +68,7 @@ import { convertBeeperFormatToOurPerMessageProfile, stripPerMessageProfileFormattedBody, } from '$hooks/usePerMessageProfile'; +import { accessibleColor, accessibleColorWeakCorrection } from '$plugins/color'; const ROOM_REPLY_TIMELINE_EVENT_TYPES = new Set([ EventType.RoomMessage as string, @@ -296,10 +297,29 @@ export const Reply = as<'div', ReplyProps>( const { color: usernameColor, font: usernameFont } = useSableCosmetics(sender ?? '', room); const activeTheme = useActiveTheme(); - const pmpNameColor = - activeTheme.kind === ThemeKind.Dark - ? pmp?.['eu.she-a.color']?.on_dark - : pmp?.['eu.she-a.color']?.on_light; + + const [nameColorLightnessCorrection] = useSetting(settingsAtom, 'nameColorLightnessCorrection'); + const accessibleNameColor = useCallback( + (nameColor: string | undefined) => { + const colorCorrection = + nameColorLightnessCorrection === 'strong' + ? accessibleColor + : nameColorLightnessCorrection === 'weak' + ? accessibleColorWeakCorrection + : () => nameColor; + + return nameColor ? colorCorrection(activeTheme.kind, nameColor) : nameColor; + }, + [nameColorLightnessCorrection, activeTheme] + ); + const pmpNameColor = useMemo(() => { + return accessibleNameColor( + activeTheme.kind === ThemeKind.Dark + ? pmp?.['eu.she-a.color']?.on_dark + : pmp?.['eu.she-a.color']?.on_light + ); + }, [activeTheme, pmp, accessibleNameColor]); + const nicknames = useAtomValue(nicknamesAtom); const cachedProfiles = useAtomValue(profilesCacheAtom); useRoomMemberHydration(room, sender ?? ''); @@ -512,7 +532,7 @@ export const Reply = as<'div', ReplyProps>( )} (str.length > len ? `${str.slice(0, len)}...` : str); @@ -374,6 +374,7 @@ function MessageInternal( const [isVisible, setIsVisible] = useState(() => typeof IntersectionObserver === 'undefined'); const activeTheme = useActiveTheme(); const [renderPersonaColors] = useSetting(settingsAtom, 'renderPersonaColors'); + const [nameColorLightnessCorrection] = useSetting(settingsAtom, 'nameColorLightnessCorrection'); useEffect(() => { const element = messageRef.current; @@ -479,9 +480,19 @@ function MessageInternal( isVisible ); - const accessibleNameColor = useCallback((color: any) => - (color) ? accessibleColor(activeTheme.kind, color) : color - , []) + const accessibleNameColor = useCallback( + (color: string | undefined) => { + if (!color || nameColorLightnessCorrection === 'off') { + return color; + } else if (nameColorLightnessCorrection === 'strong') { + return accessibleColor(activeTheme.kind, color); + } else { + /* weak color correction */ + return accessibleColorWeakCorrection(activeTheme.kind, color); + } + }, + [nameColorLightnessCorrection, activeTheme] + ); const senderFallbackName = getMxIdLocalPart(senderId) ?? senderId; const resolvedSenderDisplayName = @@ -594,7 +605,7 @@ function MessageInternal( )} {showPmPInfo && ( diff --git a/src/app/features/settings/Settings.tsx b/src/app/features/settings/Settings.tsx index 3d9b30689..cc7af5e3d 100644 --- a/src/app/features/settings/Settings.tsx +++ b/src/app/features/settings/Settings.tsx @@ -1,6 +1,6 @@ import { useMemo, useState } from 'react'; import type { ComponentType, ReactNode } from 'react'; -import { DesktopIcon, type IconProps } from '@phosphor-icons/react'; +import { DesktopIcon, PersonSimpleCircleIcon, type IconProps } from '@phosphor-icons/react'; import { Avatar, Box, Button, config, Text } from 'folds'; import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize'; import { useUserProfile } from '$hooks/useUserProfile'; @@ -46,10 +46,12 @@ import { SettingsLinkProvider } from './SettingsLinkContext'; import { useSettingsLinkBaseUrl } from './useSettingsLinkBaseUrl'; import { Desktop } from './desktop'; import { isDesktopTauri } from '$utils/platform'; +import { Accessibility } from './accessibility/Accessibility'; enum SettingsPages { GeneralPage, AccountPage, + AccessibilityPage, PerMessageProfilesPage, NotificationPage, DevicesPage, @@ -79,6 +81,7 @@ const settingsMenuIcons: Record< account: { icon: User }, persona: { icon: UsersThree }, appearance: { icon: Palette }, + accessibility: { icon: PersonSimpleCircleIcon }, notifications: { icon: Bell }, devices: { icon: DevicesIcon }, desktop: { icon: DesktopIcon }, @@ -92,6 +95,7 @@ const settingsMenuIcons: Record< const settingsPageToSectionId: Record = { [SettingsPages.GeneralPage]: 'general', [SettingsPages.AccountPage]: 'account', + [SettingsPages.AccessibilityPage]: 'accessibility', [SettingsPages.PerMessageProfilesPage]: 'persona', [SettingsPages.NotificationPage]: 'notifications', [SettingsPages.DevicesPage]: 'devices', @@ -109,6 +113,7 @@ const settingsSectionIdToPage: Record = { account: SettingsPages.AccountPage, persona: SettingsPages.PerMessageProfilesPage, appearance: SettingsPages.CosmeticsPage, + accessibility: SettingsPages.AccessibilityPage, notifications: SettingsPages.NotificationPage, devices: SettingsPages.DevicesPage, desktop: SettingsPages.DesktopPage, @@ -124,6 +129,7 @@ const settingsSectionComponents = { account: Account, persona: PerMessageProfilePage, appearance: Cosmetics, + accessibility: Accessibility, notifications: Notifications, devices: Devices, desktop: Desktop, diff --git a/src/app/features/settings/accessibility/Accessibility.tsx b/src/app/features/settings/accessibility/Accessibility.tsx new file mode 100644 index 000000000..9b6ae564c --- /dev/null +++ b/src/app/features/settings/accessibility/Accessibility.tsx @@ -0,0 +1,181 @@ +import { useRef } from 'react'; +import { Box, config, Scroll, Text, toRem } from 'folds'; +import { PageContent, SettingsSectionPage } from '$components/page'; +import { SequenceCard, SequenceCardStyle } from '$components/sequence-card'; +import { useSetting } from '$state/hooks/settings'; +import { settingsAtom } from '$state/settings'; +import { SettingTile, SettingToggle } from '$components/setting-tile'; +import { SettingMenuSelector } from '$components/setting-menu-selector'; + +function MotionPreferences() { + const [reducedMotion, setReducedMotion] = useSetting(settingsAtom, 'reducedMotion'); + const [autoplayGifs, setAutoplayGifs] = useSetting(settingsAtom, 'autoplayGifs'); + const [autoplayStickers, setAutoplayStickers] = useSetting(settingsAtom, 'autoplayStickers'); + const [autoplayEmojis, setAutoplayEmojis] = useSetting(settingsAtom, 'autoplayEmojis'); + + return ( + + Motion + + + + + + ); +} + +function TextColorPreferences() { + const [saturation, setSaturation] = useSetting(settingsAtom, 'saturationLevel'); + const [underlineLinks, setUnderlineLinks] = useSetting(settingsAtom, 'underlineLinks'); + + const [renderGlobalColors, setRenderGlobalColors] = useSetting( + settingsAtom, + 'renderGlobalNameColors' + ); + const [renderRoomColors, setRenderRoomColors] = useSetting(settingsAtom, 'renderRoomColors'); + const [renderPersonaColors, setRenderPersonaColors] = useSetting( + settingsAtom, + 'renderPersonaColors' + ); + const [nameColorLightnessCorrection, setNameColorLightnessCorrection] = useSetting( + settingsAtom, + 'nameColorLightnessCorrection' + ); + const [renderRoomFonts, setRenderRoomFonts] = useSetting(settingsAtom, 'renderRoomFonts'); + + return ( + + Text and Color + + + setSaturation(Number.parseInt(e.target.value, 10))} + style={{ + width: toRem(160), + cursor: 'pointer', + appearance: 'none', + height: toRem(6), + borderRadius: config.radii.Pill, + backgroundColor: 'var(--sable-surface-container-line)', + accentColor: 'var(--sable-primary-main)', + }} + /> + } + /> + + + + + + + + + + + } + /> + + + ); +} + +type AccessibilityProps = { + requestBack?: () => void; + requestClose: () => void; +}; + +export function Accessibility({ requestBack, requestClose }: AccessibilityProps) { + const appearanceScrollRef = useRef(null); + + return ( + + + + + + + + + + + + + ); +} diff --git a/src/app/features/settings/cosmetics/Cosmetics.tsx b/src/app/features/settings/cosmetics/Cosmetics.tsx index ea3ef5bb7..9e6a69b90 100644 --- a/src/app/features/settings/cosmetics/Cosmetics.tsx +++ b/src/app/features/settings/cosmetics/Cosmetics.tsx @@ -407,16 +407,6 @@ function IdentityCosmetics() { ); const [showPronouns, setShowPronouns] = useSetting(settingsAtom, 'showPronouns'); const [parsePronouns, setParsePronouns] = useSetting(settingsAtom, 'parsePronouns'); - const [renderGlobalColors, setRenderGlobalColors] = useSetting( - settingsAtom, - 'renderGlobalNameColors' - ); - const [renderRoomColors, setRenderRoomColors] = useSetting(settingsAtom, 'renderRoomColors'); - const [renderPersonaColors, setRenderPersonaColors] = useSetting( - settingsAtom, - 'renderPersonaColors' - ); - const [renderRoomFonts, setRenderRoomFonts] = useSetting(settingsAtom, 'renderRoomFonts'); const [uniformIcons, setUniformIcons] = useSetting(settingsAtom, 'uniformIcons'); return ( @@ -477,34 +467,6 @@ function IdentityCosmetics() { after={} /> - - - - - - - - - - { if (!room || !userId) return { color: undefined, font: undefined }; - let finalColor = isUserHero ? profile.heroNameColor : profile.resolvedColor; + const accessibleNameColor = (color: string | undefined) => { + if (!color || nameColorLightnessCorrection === 'off') { + return color; + } else if (nameColorLightnessCorrection === 'strong') { + return accessibleColor(theme.kind, color); + } else { + /* weak color correction */ + return accessibleColorWeakCorrection(theme.kind, color); + } + }; + + let finalColor = accessibleNameColor( + isUserHero ? profile.heroNameColor : profile.resolvedColor + ); if (!finalColor) { const memberPowerTag = getPowerTag(userId); finalColor = memberPowerTag?.color @@ -51,5 +68,7 @@ export function useSableCosmetics( profile.resolvedFont, getPowerTag, accessibleTagColors, + nameColorLightnessCorrection, + theme.kind, ]); } diff --git a/src/app/plugins/color.ts b/src/app/plugins/color.ts index 97b756e3a..869683681 100644 --- a/src/app/plugins/color.ts +++ b/src/app/plugins/color.ts @@ -1,16 +1,35 @@ import chroma from 'chroma-js'; import { ThemeKind } from '$hooks/useTheme'; +const clampColor = ( + lightness: number, + lightCap: number, + darkCap: number, + themeKind: ThemeKind +): number => { + if (themeKind === ThemeKind.Dark && lightness < darkCap) { + lightness = darkCap; + } + if (themeKind === ThemeKind.Light && lightness > lightCap) { + lightness = lightCap; + } + return lightness; +}; + export const accessibleColor = (themeKind: ThemeKind, color: string): string => { if (!chroma.valid(color)) return color; let lightness = chroma(color).lab()[0]; - if (themeKind === ThemeKind.Dark && lightness < 60) { - lightness = 60; - } - if (themeKind === ThemeKind.Light && lightness > 50) { - lightness = 50; - } + lightness = clampColor(lightness, 50, 60, themeKind); + + return chroma(color).set('lab.l', lightness).hex(); +}; + +export const accessibleColorWeakCorrection = (themeKind: ThemeKind, color: string): string => { + if (!chroma.valid(color)) return color; + + let lightness = chroma(color).lab()[0]; + lightness = clampColor(lightness, 70, 40, themeKind); return chroma(color).set('lab.l', lightness).hex(); }; diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts index 1833db37e..b4d106c3f 100644 --- a/src/app/state/settings.ts +++ b/src/app/state/settings.ts @@ -216,11 +216,6 @@ export interface Settings { showEasterEggs: boolean; hideReads: boolean; emojiSuggestThreshold: number; - underlineLinks: boolean; - reducedMotion: boolean; - autoplayGifs: boolean; - autoplayStickers: boolean; - autoplayEmojis: boolean; oldSidebar: boolean; pixelatedImageRendering: PixelatedImageRenderingMode; incomingInlineImagesDefaultHeight: number; @@ -262,6 +257,14 @@ export interface Settings { isShowingAllRoomsInHome: boolean; sendIndividualAttachmentAsCaption: boolean; + // accessibility stuff + underlineLinks: boolean; + reducedMotion: boolean; + autoplayGifs: boolean; + autoplayStickers: boolean; + autoplayEmojis: boolean; + nameColorLightnessCorrection: 'off' | 'weak' | 'strong'; + // furry stuff renderAnimals: boolean; animalKind: string | undefined; @@ -443,6 +446,8 @@ export const defaultSettings: Settings = { widgetSidebarWidth: 420, isShowingAllRoomsInHome: false, sendIndividualAttachmentAsCaption: true, + nameColorLightnessCorrection: 'off', + // furry stuff renderAnimals: true, animalKind: undefined,