From 85dfef87ab8be42016fb146b4cc2fe0589a83fb1 Mon Sep 17 00:00:00 2001
From: Jaz <ericvolp12@gmail.com>
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 (
     <View style={[styles.rightNav, pal.view]}>
@@ -76,19 +53,31 @@ export const DesktopRightNav = observer(function DesktopRightNav() {
       </View>
       <InviteCodes />
       <View>
-        <TouchableOpacity
-          style={[styles.cycleColorModeToggle]}
-          onPress={onModePress}
-          accessibilityRole="button"
-          accessibilityLabel="Cycle color mode"
-          accessibilityHint={modeAccessibilityText[nextColorMode()]}>
-          <View style={[pal.viewLight, styles.cycleColorModeToggleIcon]}>
-            <MoonIcon size={18} style={pal.textLight} />
-          </View>
-          <Text type="sm" style={pal.textLight}>
-            {modeHelpText[store.shell.colorMode]}
-          </Text>
-        </TouchableOpacity>
+        <Text type="sm" style={[pal.textLight, styles.colorModeText]}>
+          Set color theme
+        </Text>
+        <View style={styles.selectableBtns}>
+          <SelectableBtn
+            current={store.shell.colorMode}
+            value="system"
+            label="System"
+            left
+            onChange={(v: string) => store.shell.setColorMode(v)}
+          />
+          <SelectableBtn
+            current={store.shell.colorMode}
+            value="light"
+            label="Light"
+            onChange={(v: string) => store.shell.setColorMode(v)}
+          />
+          <SelectableBtn
+            current={store.shell.colorMode}
+            value="dark"
+            label="Dark"
+            right
+            onChange={(v: string) => store.shell.setColorMode(v)}
+          />
+        </View>
       </View>
     </View>
   )
@@ -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 (
+    <Pressable
+      style={[
+        styles.selectableBtn,
+        left && styles.selectableBtnLeft,
+        right && styles.selectableBtnRight,
+        pal.border,
+        current === value ? palPrimary.view : pal.view,
+      ]}
+      onPress={() => onChange(value)}
+      accessibilityRole="button"
+      accessibilityLabel={value}
+      accessibilityHint={`Set color theme to  ${value}`}>
+      <Text style={current === value ? palPrimary.text : pal.text}>
+        {label}
+      </Text>
+    </Pressable>
+  )
+}
+
 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

