Skip to content

Commit 52be3fb

Browse files
committed
use getSxColor util in button
1 parent 2620a4f commit 52be3fb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/button.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { forwardRef, cloneElement } from 'react'
22
import { Box, BoxProps, ThemeUIStyleObject } from 'theme-ui'
33
import Link, { LinkProps } from './link'
44
import getSizeStyles from './utils/get-size-styles'
5+
import getSxColor from './utils/get-sx-color'
56

67
const hasCustomHover = (comp: unknown): comp is { hover: ThemeUIStyleObject } =>
78
comp != null && typeof comp === 'object' && 'hover' in comp
@@ -23,9 +24,6 @@ export interface ButtonProps extends Omit<BoxProps, 'prefix'> {
2324
inverted?: boolean
2425
href?: string
2526
internal?: boolean
26-
sx?: ThemeUIStyleObject & {
27-
color?: string // ThemeUIStyleObject doesn't have a color property
28-
}
2927
}
3028

3129
const Button = (
@@ -47,10 +45,12 @@ const Button = (
4745
throw new Error('Size must be xs, sm, md, lg, or xl')
4846
}
4947

50-
const { color, ...sxProp } = sx || {}
51-
52-
const baseColor = color || (inverted ? 'secondary' : 'primary')
53-
const hoverColor = color ? 'primary' : inverted ? 'primary' : 'secondary'
48+
const defaultColor = inverted ? 'secondary' : 'primary'
49+
const baseColor = getSxColor(sx, defaultColor)
50+
const hoverColor =
51+
baseColor !== defaultColor || inverted ? 'primary' : 'secondary'
52+
const { color: _, ...sxProp } =
53+
sx && typeof sx === 'object' ? (sx as Record<string, unknown>) : {}
5454

5555
const sizeConfig = {
5656
xs: {

0 commit comments

Comments
 (0)