From ce049f1e1bd035def57a465fdc13dd2b5b259fd4 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 16 Jan 2024 10:41:35 -0600 Subject: [PATCH] Gradient colors and hovers --- src/alf/tokens.ts | 50 +++++++++++++++++++++ src/components/Button.tsx | 56 ++++++++++++++++++++--- src/view/screens/Storybook/Buttons.tsx | 62 ++++++++++++++++++++++---- 3 files changed, 154 insertions(+), 14 deletions(-) diff --git a/src/alf/tokens.ts b/src/alf/tokens.ts index 0bcffaebef..36f6f3992a 100644 --- a/src/alf/tokens.ts +++ b/src/alf/tokens.ts @@ -98,6 +98,56 @@ export const fontWeight = { bold: '900', } as const +export const gradients = { + sky: { + values: [ + [0, '#0A7AFF'], + [1, '#59B9FF'], + ], + hover_value: '#0A7AFF', + }, + midnight: { + values: [ + [0, '#022C5E'], + [1, '#4079BC'], + ], + hover_value: '#022C5E', + }, + sunrise: { + values: [ + [0, '#4E90AE'], + [0.4, '#AEA3AB'], + [0.8, '#E6A98F'], + [1, '#F3A84C'], + ], + hover_value: '#AEA3AB', + }, + sunset: { + values: [ + [0, '#6772AF'], + [0.6, '#B88BB6'], + [1, '#FFA6AC'], + ], + hover_value: '#B88BB6', + }, + nordic: { + values: [ + [0, '#083367'], + [1, '#9EE8C1'], + ], + hover_value: '#3A7085', + }, + bonfire: { + values: [ + [0, '#203E4E'], + [0.4, '#755B62'], + [0.8, '#CD7765'], + [1, '#EF956E'], + ], + hover_value: '#755B62', + }, +} as const + export type Color = keyof typeof color export type Space = keyof typeof space export type FontSize = keyof typeof fontSize diff --git a/src/components/Button.tsx b/src/components/Button.tsx index b44fb05cac..b76839de49 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -12,7 +12,16 @@ import LinearGradient from 'react-native-linear-gradient' import {useTheme, atoms, tokens, web, native} from '#/alf' export type ButtonVariant = 'solid' | 'outline' | 'ghost' | 'gradient' -export type ButtonColor = 'primary' | 'secondary' | 'negative' +export type ButtonColor = + | 'primary' + | 'secondary' + | 'negative' + | 'gradient_sky' + | 'gradient_midnight' + | 'gradient_sunrise' + | 'gradient_sunset' + | 'gradient_nordic' + | 'gradient_bonfire' export type ButtonSize = 'small' | 'large' export type VariantProps = { /** @@ -270,6 +279,36 @@ export function Button({ } }, [t, variant, color, size, disabled]) + const {gradientColors, gradientHoverColors, gradientLocations} = + React.useMemo(() => { + const colors: string[] = [] + const hoverColors: string[] = [] + const locations: number[] = [] + const gradient = { + primary: tokens.gradients.sky, + secondary: tokens.gradients.sky, + negative: tokens.gradients.sky, + gradient_sky: tokens.gradients.sky, + gradient_midnight: tokens.gradients.midnight, + gradient_sunrise: tokens.gradients.sunrise, + gradient_sunset: tokens.gradients.sunset, + gradient_nordic: tokens.gradients.nordic, + gradient_bonfire: tokens.gradients.bonfire, + }[color || 'primary'] + + if (variant === 'gradient') { + colors.push(...gradient.values.map(([_, color]) => color)) + hoverColors.push(...gradient.values.map(_ => gradient.hover_value)) + locations.push(...gradient.values.map(([location, _]) => location)) + } + + return { + gradientColors: colors, + gradientHoverColors: hoverColors, + gradientLocations: locations, + } + }, [variant, color]) + const childProps = React.useMemo( () => ({ state, @@ -311,10 +350,11 @@ export function Button({ {variant === 'gradient' && (

Buttons

- + {['primary', 'secondary', 'negative'].map(color => ( {['solid', 'outline', 'ghost'].map(variant => ( @@ -37,14 +37,58 @@ export function Buttons() { ))} - + + + {['gradient_sky', 'gradient_midnight', 'gradient_sunrise'].map( + name => ( + + + + + ), + )} + + + {['gradient_sunset', 'gradient_nordic', 'gradient_bonfire'].map( + name => ( + + + + + ), + )} + + )