From 6b0e0e5c9d842a2d9af31b53affe2f6291c3fa0d Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 2 Jan 2024 10:49:55 -0600 Subject: [PATCH] Playing around with curves --- src/alf/themes.ts | 28 ++++++++++++++++----------- src/alf/tokens.ts | 23 +++++++++++++++++++++- src/view/com/Button.tsx | 12 ++++++++---- src/view/com/Typography.tsx | 36 ++++++----------------------------- src/view/screens/DebugNew.tsx | 12 +++++------- 5 files changed, 58 insertions(+), 53 deletions(-) diff --git a/src/alf/themes.ts b/src/alf/themes.ts index f5af08e567..a23b2d8f11 100644 --- a/src/alf/themes.ts +++ b/src/alf/themes.ts @@ -10,15 +10,15 @@ export type Palette = { } export const lightPalette: Palette = { - primary: tokens.color.blue_500, - positive: tokens.color.green_500, - negative: tokens.color.red_500, + primary: tokens.color.blue_600, + positive: tokens.color.green_600, + negative: tokens.color.red_600, } as const export const darkPalette: Palette = { - primary: tokens.color.blue_500, - positive: tokens.color.green_400, - negative: tokens.color.red_400, + primary: tokens.color.blue_600, + positive: tokens.color.green_600, + negative: tokens.color.red_600, } as const export const light = { @@ -30,6 +30,9 @@ export const light = { text_contrast_700: { color: tokens.color.gray_700, }, + text_contrast_600: { + color: tokens.color.gray_600, + }, text_contrast_500: { color: tokens.color.gray_500, }, @@ -49,13 +52,13 @@ export const light = { backgroundColor: tokens.color.gray_300, }, bg_positive: { - backgroundColor: tokens.color.green_500, + backgroundColor: lightPalette.positive, }, bg_negative: { - backgroundColor: tokens.color.red_400, + backgroundColor: lightPalette.negative, }, border: { - borderColor: tokens.color.gray_200, + borderColor: tokens.color.gray_300, }, border_contrast_500: { borderColor: tokens.color.gray_500, @@ -72,6 +75,9 @@ export const dark: Theme = { text_contrast_700: { color: tokens.color.gray_300, }, + text_contrast_600: { + color: tokens.color.gray_400, + }, text_contrast_500: { color: tokens.color.gray_500, }, @@ -91,10 +97,10 @@ export const dark: Theme = { backgroundColor: tokens.color.gray_700, }, bg_positive: { - backgroundColor: tokens.color.green_400, + backgroundColor: darkPalette.positive, }, bg_negative: { - backgroundColor: tokens.color.red_400, + backgroundColor: darkPalette.negative, }, border: { borderColor: tokens.color.gray_800, diff --git a/src/alf/tokens.ts b/src/alf/tokens.ts index 159a7213cd..7e469ed345 100644 --- a/src/alf/tokens.ts +++ b/src/alf/tokens.ts @@ -1,7 +1,9 @@ const BLUE_HUE = 211 const GRAYSCALE_SATURATION = 22 -export const color = { +export const color: { + [key: string]: string +} = { white: '#FFFFFF', gray_0: `hsl(${BLUE_HUE}, ${GRAYSCALE_SATURATION}%, 100%)`, @@ -53,6 +55,25 @@ export const color = { red_1000: `hsl(349, 96%, 5%)`, } +function bezier(time: number, start: number, end: number, duration: number) { + if ((time /= duration / 2) < 1) return (end / 2) * time * time + start + return (-end / 2) * (--time * (time - 2) - 1) + start +} + +for (let i = 0; i < 11; i++) { + const slope = bezier((i / 11) * 89, 0, 100, 100) + const percent = Math.ceil(100 - slope) + + color[ + `gray_${i * 100}` + ] = `hsl(${BLUE_HUE}, ${GRAYSCALE_SATURATION}%, ${percent}%)` + color[`blue_${i * 100}`] = `hsl(${BLUE_HUE}, 99%, ${percent}%)` + color[`green_${i * 100}`] = `hsl(130, 60%, ${percent}%)` + color[`red_${i * 100}`] = `hsl(349, 90%, ${percent}%)` +} + +console.log(color) + export const space = { xxs: 2, xs: 4, diff --git a/src/view/com/Button.tsx b/src/view/com/Button.tsx index d1f70d4aeb..09331db8fc 100644 --- a/src/view/com/Button.tsx +++ b/src/view/com/Button.tsx @@ -1,7 +1,7 @@ import React from 'react' import {Pressable, Text, PressableProps, TextProps} from 'react-native' import * as tokens from '#/alf/tokens' -import {atoms} from '#/alf' +import {useTheme, atoms} from '#/alf' export type ButtonType = | 'primary' @@ -34,6 +34,7 @@ export type ButtonProps = Omit & export type ButtonTextProps = TextProps & VariantProps export function Button({children, style, type, size, ...rest}: ButtonProps) { + const t = useTheme() const {baseStyles, hoverStyles} = React.useMemo(() => { const baseStyles = [] const hoverStyles = [] @@ -41,15 +42,18 @@ export function Button({children, style, type, size, ...rest}: ButtonProps) { switch (type) { case 'primary': baseStyles.push({ + backgroundColor: t.palette.primary, + }) + hoverStyles.push({ backgroundColor: tokens.color.blue_500, }) break case 'secondary': baseStyles.push({ - backgroundColor: tokens.color.gray_200, + backgroundColor: tokens.color.gray_300, }) hoverStyles.push({ - backgroundColor: tokens.color.gray_100, + backgroundColor: tokens.color.gray_200, }) break default: @@ -79,7 +83,7 @@ export function Button({children, style, type, size, ...rest}: ButtonProps) { baseStyles, hoverStyles, } - }, [type, size]) + }, [type, size, t]) const [state, setState] = React.useState({ pressed: false, diff --git a/src/view/com/Typography.tsx b/src/view/com/Typography.tsx index 6579c2e511..91da6a3042 100644 --- a/src/view/com/Typography.tsx +++ b/src/view/com/Typography.tsx @@ -15,11 +15,7 @@ export function H1({style, ...rest}: TextProps) { 'aria-level': 1, }) || {} return ( - + ) } @@ -31,11 +27,7 @@ export function H2({style, ...rest}: TextProps) { 'aria-level': 2, }) || {} return ( - + ) } @@ -47,11 +39,7 @@ export function H3({style, ...rest}: TextProps) { 'aria-level': 3, }) || {} return ( - + ) } @@ -63,11 +51,7 @@ export function H4({style, ...rest}: TextProps) { 'aria-level': 4, }) || {} return ( - + ) } @@ -79,11 +63,7 @@ export function H5({style, ...rest}: TextProps) { 'aria-level': 5, }) || {} return ( - + ) } @@ -95,10 +75,6 @@ export function H6({style, ...rest}: TextProps) { 'aria-level': 6, }) || {} return ( - + ) } diff --git a/src/view/screens/DebugNew.tsx b/src/view/screens/DebugNew.tsx index 0b7c5f03bc..209e288d23 100644 --- a/src/view/screens/DebugNew.tsx +++ b/src/view/screens/DebugNew.tsx @@ -61,15 +61,13 @@ function ThemedSection() { return ( -

theme.atoms.text

+

theme.atoms.text

-

- theme.atoms.text_contrast_700 -

+

theme.atoms.text_contrast_700

-

- theme.atoms.text_contrast_500 -

+

theme.atoms.text_contrast_600

+ +

theme.atoms.text_contrast_500