From fbfb1a92b1eb327b68d41b8a34f47d1d89567b1b Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 19 Dec 2023 11:09:10 -0600 Subject: [PATCH] Buttons, you get the idea --- src/alf/components/Button.tsx | 176 ++++++++++++++++++++++++++++++++-- src/alf/themes.ts | 8 +- src/view/screens/DebugNew.tsx | 13 +++ 3 files changed, 189 insertions(+), 8 deletions(-) diff --git a/src/alf/components/Button.tsx b/src/alf/components/Button.tsx index 4429046bb0..d6d625edd1 100644 --- a/src/alf/components/Button.tsx +++ b/src/alf/components/Button.tsx @@ -1,9 +1,171 @@ +import React from 'react' import {Pressable} from 'react-native' -import {styled} from '#/alf/system' -export const Button = styled(Pressable, { - px: 'l', - py: 's', - bg: 'l2', - radius: 40, -}) +import {useStyles} from '#/alf/system' +import {Text} from '#/alf/components/Typography' + +export type ButtonType = + | 'primary' + | 'secondary' + | 'tertiary' + | 'positive' + | 'negative' +export type ButtonSize = 'small' | 'large' + +export type ButtonProps = React.ComponentProps & { + type?: ButtonType + size?: ButtonSize +} + +const colorVariants: { + [key in ButtonType]: Parameters[0] +} = { + primary: { + pressable: { + bg: 'primary', + }, + pressableHovered: { + bg: 'primaryLight', + }, + pressableFocused: { + bg: 'primaryLight', + }, + pressablePressed: { + bg: 'primaryLight', + }, + text: { + color: 'white', + }, + }, + secondary: { + pressable: { + bg: 'l2', + }, + pressableHovered: { + bg: 'l1', + }, + pressableFocused: { + bg: 'l1', + }, + pressablePressed: { + bg: 'l1', + }, + text: { + color: 'l6', + }, + }, + tertiary: {}, + positive: { + pressable: { + bg: 'green', + }, + pressableHovered: { + bg: 'green', + }, + pressableFocused: { + bg: 'green', + }, + pressablePressed: { + bg: 'green', + }, + text: { + color: 'l0', + }, + }, + negative: { + pressable: { + bg: 'red', + }, + pressableHovered: { + bg: 'red', + }, + pressableFocused: { + bg: 'red', + }, + pressablePressed: { + bg: 'red', + }, + text: { + color: 'l0', + }, + }, +} + +const sizeVariants: { + [key in ButtonSize]: Parameters[0] +} = { + small: { + pressable: { + py: 'm', + px: 'l', + radius: 'm', + }, + text: { + fontSize: 'm', + fontWeight: 'semi', + }, + }, + large: { + pressable: { + py: 'm', + px: 'l', + radius: 'm', + }, + text: { + fontSize: 'm', + fontWeight: 'semi', + }, + }, +} + +export function Button({ + children, + type = 'primary', + size = 'large', + ...rest +}: React.PropsWithChildren) { + const styles = useStyles( + React.useMemo[0]>( + () => ({ + pressable: { + ...colorVariants[type].pressable, + ...sizeVariants[size].pressable, + }, + text: { + textAlign: 'center', + ...colorVariants[type].text, + ...sizeVariants[size].text, + }, + pressableHovered: { + ...colorVariants[type].pressableHovered, + }, + pressableFocused: { + ...colorVariants[type].pressableFocused, + }, + pressablePressed: { + ...colorVariants[type].pressablePressed, + }, + }), + [type, size], + ), + ) + + return ( + + [ + styles.pressable, + state.hovered && styles.pressableHovered, + state.focused && styles.pressableFocused, + state.pressed && styles.pressablePressed, + ].filter(Boolean) + }> + {typeof children === 'string' ? ( + {children} + ) : ( + children + )} + + ) +} diff --git a/src/alf/themes.ts b/src/alf/themes.ts index 1a6a963082..95b90f4c56 100644 --- a/src/alf/themes.ts +++ b/src/alf/themes.ts @@ -18,7 +18,10 @@ export const palette = { gray6: `hsl(${BLUE_HUE}, ${GRAYSCALE_SATURATION}%, 10%)`, black: `hsl(${BLUE_HUE}, ${GRAYSCALE_SATURATION}%, 5%)`, + blueLight: `hsl(${BLUE_HUE}, 100%, 63%)`, blue: `hsl(${BLUE_HUE}, 100%, 53%)`, + blueDark: `hsl(${BLUE_HUE}, 100%, 43%)`, + green: '#54D469', red: '#FB4566', } @@ -35,7 +38,10 @@ export const light = createTheme({ xxl: 32, }, color: { + primaryLight: palette.blueLight, primary: palette.blue, + primaryDark: palette.blueDark, + l0: palette.white, l1: palette.gray1, l2: palette.gray2, @@ -71,7 +77,7 @@ export const light = createTheme({ }, fontWeight: { normal: '400', - semi: '700', + semi: '600', bold: '900', }, }, diff --git a/src/view/screens/DebugNew.tsx b/src/view/screens/DebugNew.tsx index b45899d12b..a8b0bd21a8 100644 --- a/src/view/screens/DebugNew.tsx +++ b/src/view/screens/DebugNew.tsx @@ -232,6 +232,19 @@ export function DebugScreen() { + + +

+ Breakpoint styles +

+ + + + + + + +