-
Notifications
You must be signed in to change notification settings - Fork 679
Description
Say I have the variant for buttons defined as follows:
buttons: {
primary: {
bg: 'primary'
}
}Currently the order of the props matters. e.g.
sx={{
variant: 'buttons.primary',
bg: 'secondary'
}}Will correctly overwrite the color set with the bg prop to secondary but
sx={{
bg: 'secondary',
variant: 'buttons.primary'
}}will not. The bg prop set in the button.primary variant will overwrite the bg prop set specifically on the sx prop.
I'm not sure if there is any use for this overwriting behaviour, but it makes sense to me that styles defined specifically should overwrite the styles defined in variant regardless of the order they are set.
A potential solution is to perhaps swap the order of styles when they are spread in the @theme-ui/css package so from:
theme-ui/packages/css/src/index.ts
Lines 212 to 216 in cf5b00a
| if (key === 'variant') { | |
| const variant = css(get(theme, val))(theme) | |
| result = { ...result, ...variant } | |
| continue | |
| } |
to
if (key === 'variant') {
const variant = css(get(theme, val))(theme)
result = { ...variant, ...result }
continue
}Not sure if this will work exhaustively, but it does pass all the tests in my fork