Skip to content

Commit

Permalink
feat(buttons): update buttons to match facelift designs
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Sep 28, 2023
1 parent 2a47679 commit 9f4abe1
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 28 deletions.
12 changes: 9 additions & 3 deletions src/primitives/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {useArrayProp} from '../../hooks'
import {ThemeProps} from '../../styles'
import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
import {useTheme} from '../../theme'
import {ButtonMode, ButtonTextAlign, ButtonTone, FlexJustify} from '../../types'
import {ButtonMode, ButtonTextAlign, ButtonTone, FlexJustify, ButtonTextStyle} from '../../types'
import {Box} from '../box'
import {Flex} from '../flex'
import {Spinner} from '../spinner'
Expand All @@ -30,6 +30,10 @@ export interface ButtonProps extends ResponsivePaddingProps, ResponsiveRadiusPro
selected?: boolean
space?: number | number[]
textAlign?: ButtonTextAlign
/**
* @default primary
*/
textStyle?: ButtonTextStyle
text?: React.ReactNode
tone?: ButtonTone
type?: 'button' | 'reset' | 'submit'
Expand Down Expand Up @@ -84,6 +88,7 @@ export const Button = forwardRef(function Button(
textAlign,
tone = 'default',
type = 'button',
textStyle = 'primary',
...restProps
} = props

Expand Down Expand Up @@ -137,7 +142,7 @@ export const Button = forwardRef(function Button(
<Box as="span" {...boxProps}>
<Flex as="span" justify={justify}>
{icon && (
<Text size={fontSize}>
<Text size={fontSize} muted={textStyle === 'secondary'}>
{isValidElement(icon) && icon}
{isValidElementType(icon) && createElement(icon)}
</Text>
Expand All @@ -150,6 +155,7 @@ export const Button = forwardRef(function Button(
marginRight={iconRight ? space : undefined}
>
<Text
muted={textStyle === 'secondary'}
align={textAlign}
size={fontSize}
textOverflow="ellipsis"
Expand All @@ -161,7 +167,7 @@ export const Button = forwardRef(function Button(
)}

{iconRight && (
<Text size={fontSize}>
<Text size={fontSize} muted={textStyle === 'secondary'}>
{isValidElement(iconRight) && iconRight}
{isValidElementType(iconRight) && createElement(iconRight)}
</Text>
Expand Down
48 changes: 30 additions & 18 deletions src/theme/studioTheme/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const color = createColorTheme({
bg,
bg2: mix2(bg, tints[dark ? 50 : 950].hex),
border: bg,
fg: mix(base.bg, dark ? black.hex : white.hex),
fg: getColor(tints, dark, 'default', 'bg_base'),
muted: {
fg: mix(base.bg, tints[dark ? 950 : 50].hex),
},
Expand Down Expand Up @@ -259,19 +259,19 @@ export const color = createColorTheme({
bg,
bg2: mix(bg, tints[dark ? 950 : 50].hex),
border: mix(bg, tints[dark ? 950 : 50].hex),
fg: mix(bg, tints[dark ? 800 : 200].hex),
fg: getColor(tints, dark, tone, 'text_primary'),
muted: {
fg: mix(bg, tints[dark ? 900 : 100].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
accent: {
fg: mix(bg, tints[dark ? 900 : 100].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
link: {
fg: mix(bg, tints[dark ? 900 : 100].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
code: {
bg,
fg: mix(bg, tints[dark ? 900 : 100].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
skeleton: {
from: rgba(skeletonFrom, 0.5),
Expand All @@ -288,9 +288,12 @@ export const color = createColorTheme({
bg,
bg2: mix(bg, tints[dark ? 950 : 50].hex),
border: mix(bg, tints[dark ? 900 : 100].hex),
fg: mix(base.bg, tints[dark ? 200 : 800].hex),
fg:
tone !== 'default' && tone !== 'primary'
? getColor(tints, dark, tone, 'text_secondary')
: getColor(tints, dark, tone, 'text_primary'),
muted: {
fg: mix(base.bg, tints[dark ? 400 : 600].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
accent: {
fg: mix(base.bg, hues.red[dark ? 400 : 500].hex),
Expand All @@ -300,7 +303,7 @@ export const color = createColorTheme({
},
code: {
bg: mix(bg, tints[dark ? 950 : 50].hex),
fg: mix(base.bg, tints[dark ? 400 : 600].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
skeleton: {
from: skeletonFrom,
Expand All @@ -321,9 +324,12 @@ export const color = createColorTheme({
bg,
bg2: mix(bg, tints[dark ? 950 : 50].hex),
border: mix(bg, getColor(tints, dark, name, 'bg_base_active')),
fg: mix(base.bg, tints[dark ? 200 : 800].hex),
fg:
tone !== 'default' && tone !== 'primary'
? getColor(tints, dark, tone, 'text_secondary')
: getColor(tints, dark, tone, 'text_primary'),
muted: {
fg: mix(base.bg, tints[dark ? 400 : 600].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
accent: {
fg: mix(bg, hues.red[dark ? 400 : 500].hex),
Expand All @@ -333,7 +339,7 @@ export const color = createColorTheme({
},
code: {
bg: mix(bg, tints[dark ? 950 : 50].hex),
fg: mix(base.bg, tints[dark ? 400 : 600].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
skeleton: {
from: skeletonFrom,
Expand All @@ -354,9 +360,12 @@ export const color = createColorTheme({
bg,
bg2: mix(bg, tints[dark ? 950 : 50].hex),
border: mix(bg, tints[dark ? 900 : 100].hex),
fg: mix(base.bg, tints[dark ? 200 : 800].hex),
fg:
tone !== 'default' && tone !== 'primary'
? getColor(tints, dark, tone, 'text_secondary')
: getColor(tints, dark, tone, 'text_primary'),
muted: {
fg: mix(base.bg, tints[dark ? 400 : 600].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
accent: {
fg: mix(bg, hues.red[dark ? 400 : 500].hex),
Expand All @@ -366,7 +375,7 @@ export const color = createColorTheme({
},
code: {
bg: mix(bg, tints[dark ? 950 : 50].hex),
fg: mix(base.bg, tints[dark ? 400 : 600].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
skeleton: {
from: skeletonFrom,
Expand All @@ -382,9 +391,12 @@ export const color = createColorTheme({
bg,
bg2: mix(bg, tints[dark ? 950 : 50].hex),
border: mix(bg, getColor(tints, dark, name, 'bg_base')),
fg: mix(base.bg, tints[dark ? 300 : 700].hex),
fg:
tone !== 'default' && tone !== 'primary'
? getColor(tints, dark, tone, 'text_secondary')
: getColor(tints, dark, tone, 'text_primary'),
muted: {
fg: mix(base.bg, tints[dark ? 400 : 600].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
accent: {
fg: mix(base.bg, hues.red[dark ? 400 : 500].hex),
Expand All @@ -394,7 +406,7 @@ export const color = createColorTheme({
},
code: {
bg: mix(base.bg, tints[dark ? 950 : 50].hex),
fg: mix(base.bg, tints[dark ? 400 : 600].hex),
fg: getColor(tints, dark, tone, 'text_secondary'),
},
skeleton: {
from: skeletonFrom,
Expand Down
2 changes: 2 additions & 0 deletions src/types/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export type ButtonTextAlign = 'left' | 'right' | 'center'
* @public
*/
export type ButtonTone = 'default' | 'primary' | 'positive' | 'caution' | 'critical'

export type ButtonTextStyle = 'primary' | 'secondary'
17 changes: 14 additions & 3 deletions stories/helpers/matrixBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface MatrixBuilderProps<Rows extends string[], Cols extends string[]> {
columns: Cols
rows: Rows
title: string
subHeader?: React.ReactNode
renderItem: ({row, column}: {row: Rows[number]; column: Cols[number]}) => React.ReactNode
}

Expand Down Expand Up @@ -49,7 +50,7 @@ const Row = ({row, children}: RowProps) => {

type TableProps<Rows extends string[], Cols extends string[]> = Pick<
MatrixBuilderProps<Rows, Cols>,
'scheme' | 'columns' | 'rows' | 'title'
'scheme' | 'columns' | 'rows' | 'title' | 'subHeader'
> & {
children: React.ReactNode
}
Expand All @@ -60,12 +61,21 @@ const Table = <Rows extends string[], Cols extends string[]>({
columns,
rows,
title,
subHeader,
}: TableProps<Rows, Cols>) => {
return (
<Card scheme={scheme} padding={4} border radius={2}>
<Grid columns={columns.length + 1} rows={rows.length + 1} gap={2}>
<Grid
gapX={3}
gapY={2}
style={{
gridTemplateColumns: `repeat(${columns.length + 1}, auto)`,
gridTemplateRows: `repeat(${rows.length + 1}, auto)`,
}}
>
{/* First row, columns titles */}
<FirstRow title={title} columns={columns} />
{subHeader}
{/* Rows titles and items */}
{children}
</Grid>
Expand All @@ -83,9 +93,10 @@ export function matrixBuilder<Rows extends string[], Cols extends string[]>({
rows,
title,
renderItem,
subHeader,
}: MatrixBuilderProps<Rows, Cols>): JSX.Element {
return (
<Table scheme={scheme} columns={columns} rows={rows} title={title}>
<Table scheme={scheme} columns={columns} rows={rows} title={title} subHeader={subHeader}>
{rows.map((row) => (
<Row row={row} key={row}>
{columns.map((column) => renderItem({row, column}))}
Expand Down
Loading

0 comments on commit 9f4abe1

Please sign in to comment.