[theme] Always return default spacing value with px units#22552
Conversation
|
I'm not sure how to handle cases like: |
width: 300 + parseInt(theme.spacing(6).slice(0, -2));😄 It's the problem that @joshwooding raised here: #16205 (comment) |
|
How about if > theme.spacing(1)
'8px'
> theme.spacing([1, 'rem'])
'8rem'
> theme.spacing([1, ''])
8 |
|
I have tried to benchmark what the others are doing here.
I think that it would leak the intent, so not working. I wonder if the best answer here isn't on CSS land: |
Perfect - it even works in IE. |
|
Hmm: padding: theme.spacing(0.5, 0, 0.5, `${Math.max(0, theme.spacing(1) - 3)}px`),CSS |
|
Also: [theme.breakpoints.up(600 + theme.spacing(2) * 2)]: {
width: 600,
marginLeft: 'auto',
marginRight: 'auto',
}, |
|
@mbrookes For the first case we can use px, and the second a breakpoint value, md? |
|
I'm not sure what the second was about (and I wrote it! 😅 ) – it seems to work just the same with 'md'. I don't understand what you mean for the first - it is in px? |
Sorry for the confusion, I meant using hardcoded pixels, not. The value from the theme. |
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Breaking changes
theme.spacingnow returns single values with px units by default.This change improves the integration with styled-components & emotion.
Before:
After:
You can restore the previous behavior with:
Closes #16205