From 85dfef87ab8be42016fb146b4cc2fe0589a83fb1 Mon Sep 17 00:00:00 2001 From: Jaz Date: Tue, 16 May 2023 23:06:08 -0700 Subject: Use a three-state radio button for color mode --- src/view/shell/desktop/RightNav.tsx | 144 ++++++++++++++++++++++++++---------- 1 file changed, 106 insertions(+), 38 deletions(-) (limited to 'src/view/shell/desktop/RightNav.tsx') diff --git a/src/view/shell/desktop/RightNav.tsx b/src/view/shell/desktop/RightNav.tsx index 084e95607..f81c218cd 100644 --- a/src/view/shell/desktop/RightNav.tsx +++ b/src/view/shell/desktop/RightNav.tsx @@ -1,43 +1,20 @@ import React from 'react' import {observer} from 'mobx-react-lite' -import {StyleSheet, TouchableOpacity, View} from 'react-native' +import {Pressable, StyleSheet, TouchableOpacity, View} from 'react-native' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {usePalette} from 'lib/hooks/usePalette' import {DesktopSearch} from './Search' import {Text} from 'view/com/util/text/Text' import {TextLink} from 'view/com/util/Link' import {FEEDBACK_FORM_URL} from 'lib/constants' -import {s} from 'lib/styles' +import {colors, s} from 'lib/styles' import {useStores} from 'state/index' import {pluralize} from 'lib/strings/helpers' -import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle' -import {MoonIcon} from 'lib/icons' import {formatCount} from 'view/com/util/numeric/format' export const DesktopRightNav = observer(function DesktopRightNav() { const store = useStores() const pal = usePalette('default') - const colorModes = ['light', 'dark', 'system'] - const modeAccessibilityText = { - light: 'Sets display to light mode', - dark: 'Sets display to dark mode', - system: 'Sets display to system default', - } - const modeHelpText = { - light: 'Light Theme', - dark: 'Dark Theme', - system: 'System Default Theme', - } - - const nextColorMode = () => { - return colorModes[ - (colorModes.indexOf(store.shell.colorMode) + 1) % colorModes.length - ] - } - - const onModePress = React.useCallback(() => { - store.shell.setColorMode(nextColorMode()) - }, [store]) return ( @@ -76,19 +53,31 @@ export const DesktopRightNav = observer(function DesktopRightNav() { - - - - - - {modeHelpText[store.shell.colorMode]} - - + + Set color theme + + + store.shell.setColorMode(v)} + /> + store.shell.setColorMode(v)} + /> + store.shell.setColorMode(v)} + /> + ) @@ -132,6 +121,45 @@ const InviteCodes = observer(() => { ) }) +interface SelectableBtnProps { + current: string + value: string + label: string + left?: boolean + right?: boolean + onChange: (v: string) => void +} + +function SelectableBtn({ + current, + value, + label, + left, + right, + onChange, +}: SelectableBtnProps) { + const pal = usePalette('default') + const palPrimary = usePalette('inverted') + return ( + onChange(value)} + accessibilityRole="button" + accessibilityLabel={value} + accessibilityHint={`Set color theme to ${value}`}> + + {label} + + + ) +} + const styles = StyleSheet.create({ rightNav: { position: 'absolute', @@ -174,4 +202,44 @@ const styles = StyleSheet.create({ height: 26, borderRadius: 15, }, + + colorModeText: { + marginLeft: 10, + marginBottom: 6, + }, + + selectableBtns: { + flexDirection: 'row', + marginLeft: 10, + }, + selectableBtn: { + flexDirection: 'row', + justifyContent: 'center', + borderWidth: 1, + borderLeftWidth: 0, + paddingHorizontal: 10, + paddingVertical: 10, + }, + selectableBtnLeft: { + borderTopLeftRadius: 8, + borderBottomLeftRadius: 8, + borderLeftWidth: 1, + }, + selectableBtnRight: { + borderTopRightRadius: 8, + borderBottomRightRadius: 8, + }, + + btn: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + width: '100%', + borderRadius: 32, + padding: 14, + backgroundColor: colors.gray1, + }, + toggleBtn: { + paddingHorizontal: 0, + }, }) -- cgit 1.4.1