From ca50055118b823efbfff6bac5e028289065e4067 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 14 Sep 2023 20:19:02 -0500 Subject: [PATCH] refactor toggle button --- src/view/com/util/forms/ToggleButton.tsx | 53 ++++++++++++++++++++++-- src/view/screens/DesignSystem.tsx | 22 ++++++++-- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/view/com/util/forms/ToggleButton.tsx b/src/view/com/util/forms/ToggleButton.tsx index 46ceb8c818..aab917dd03 100644 --- a/src/view/com/util/forms/ToggleButton.tsx +++ b/src/view/com/util/forms/ToggleButton.tsx @@ -1,12 +1,55 @@ import React from 'react' -import {StyleProp, StyleSheet, TextStyle, View, ViewStyle} from 'react-native' -import {Text} from '../text/Text' +import { + StyleProp, + StyleSheet, + TextStyle, + View, + ViewStyle, + Pressable, +} from 'react-native' +import {Text as RNText} from '../text/Text' import {Button, ButtonType} from './Button' import {useTheme} from 'lib/ThemeContext' import {choose} from 'lib/functions' import {colors} from 'lib/styles' import {TypographyVariant} from 'lib/ThemeContext' +import {ComponentProps, Box, Text} from 'lib/design-system' + +export function Toggle({ + children, + selected, + ...props +}: React.PropsWithChildren< + ComponentProps & { + selected: boolean + } +>) { + return ( + + + + + + + + {/* @ts-ignore userSelect is a web property */} + {children} + + + + ) +} + export function ToggleButton({ type = 'default-light', label, @@ -146,9 +189,11 @@ export function ToggleButton({ /> {label === '' ? null : ( - + {label} - + )} diff --git a/src/view/screens/DesignSystem.tsx b/src/view/screens/DesignSystem.tsx index cc48b6cc6a..960734e40e 100644 --- a/src/view/screens/DesignSystem.tsx +++ b/src/view/screens/DesignSystem.tsx @@ -4,28 +4,44 @@ import {NativeStackScreenProps, CommonNavigatorParams} from 'lib/routes/types' import {withAuthRequired} from 'view/com/auth/withAuthRequired' import {ThemeProvider, Box, Text, H1, H2, H3, P} from 'lib/design-system' +import {Toggle} from 'view/com/util/forms/ToggleButton' type Props = NativeStackScreenProps +function ToggleButtons() { + const [selected, setSelected] = React.useState(false) + return ( + <> + setSelected(!selected)}> + Toggle button + + + ) +} + export const DesignSystemScreen = withAuthRequired( observer(function DesignSystem({}: Props) { return ( -

+

Heading 1

-

+

Heading 2

Heading 3

Paragraph

- + Monospace + + + +
)