Theme-ui: Individual border properties should reference theme values

Created on 7 Aug 2019  路  10Comments  路  Source: system-ui/theme-ui

I'd be happy to create a PR for this, if it makes sense. For example, this works just fine:

borderWidth: 'thin',
borderStyle: 'solid',
borderColor: 'primary',

however, this will result in the literal values winding up in the CSS:

borderBottomWidth: 'thin',
borderBottomStyle: 'solid',
borderBottomColor: 'primary',

I think it would make sense for the API to support all possible values:

X = Top, Bottom, Left, Right

borderXWidth
borderXColor
borderXStyle
X = Top, Bottom

borderXLeftRadius
borderXRightRadius

All 10 comments

PR https://github.com/styled-system/styled-system/pull/671 :)

In my case, when I do the following: border: '2px solid muted', where muted is a theme variable, it does not resolve it correctly, also, if I try borderBottomColor: 'muted' it does not work either, is this the same issue? :)

Yeah, that's right it won't resolve anything inside the shorthand string. You can either do something like:

border: theme => `${theme.borderWidths.thin}px ${theme.borderStyles.thick} ${theme.colors.muted}`

(which kinda sucks) or, a mix (which I think still has a bug if you order them incorrectly) such as:

border: theme => `${theme.borderWidths.thin}px ${theme.borderStyles.thick}`,
borderColor: 'muted'

or you can apply them individually:

borderWidth: 'thin',
borderStyle: 'thick',
borderColor: 'muted',

but it won't support borderBottomColor, which the PR addresses

Awesome, that did the trick in the meantime, thanks! 馃檶馃徏

which I think still has a bug if you order them incorrectly

This isn鈥檛 a bug, this is due to the cascade and how CSS is designed to work FWIW

@jxnblk Cool thanks for clarifying, couldn't remember the exact details around it!

This is now supported in the latest version of @styled-system/css 馃帀 run npm i theme-ui to update the dependency!

Now, this works:

  borderBottomWidth: '2px',
  borderBottomStyle: 'solid',
  borderBottomColor: 'muted',

but this still does not 馃槦 borderBottom: '2px solid muted'

@kutyel think about how the values are resolved, borderBottom references borders. borderBottomColor references color, borderBottomWidth references borderWidths. Passing in a string containing values that need to be resolved across different parts of the global theme object won't work. That's why for shorthand you need to provide a function to reference the theme:

borderBottom: theme => `${theme.borderWidths.thin}px ${theme.borderStyles.thick} ${theme.colors.muted}`

@kutyel see also #81

Was this page helpful?
0 / 5 - 0 ratings