Margin and Padding lower than 9px powers its value when using sx or styled
See original GitHub issueIn our project, we’re using dripsy
within a styles.ts
file theming everything with styled
similar to styled-components
. ex:
import { styled } from 'dripsy'
import { Text, View } from 'react-native'
export const Container = styled(View)((_props) => ({
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#e03d26',
borderRadius: 5,
}))
But when I set margin or padding the final code get it’s value powered (happens on Next and Expo), examples:
Example 1
Padding with 8px using styled()
Code (8px):
export const Container = styled(View)((_props) => ({
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#e03d26',
borderRadius: 5,
padding: 8
}))
Browser (512px which is 2⁹):
Example 2
Padding with 7px using dripsy
<View/>
with sx
:
Code (7px):
import { View } from 'dripsy'
import { Title } from './styles'
const Button = ({ title }: { title: string }) => {
return (
<View
sx={{
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#e03d26',
borderRadius: 5,
padding: 7,
}}
>
<Title>{title}</Title>
</View>
)
}
Browser (256px wich is 2⁸)
Example 3 - Works as Expected
Padding with 9px using styled()
Code(9px):
export const Container = styled(View)((_props) => ({
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#e03d26',
borderRadius: 5,
padding: 9
}))
Browser (9px):
Issue Analytics
- State:
- Created a year ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
The sx prop - MUI System
The sx prop is a shortcut for defining custom styles that has access to the theme. The sx prop lets you work with...
Read more >The `sx` Prop - Theme UI
Margin and padding are treated as first-class citizens in Theme UI, using values defined in the theme.space scale, and include an optional shorthand...
Read more >MUI: how to style a <p> using sx prop? - Stack Overflow
When using MUI v5's styling system, when you write ... to <p> elements having a margin-bottom, because p is used as a shorthand...
Read more >All You Need To Know About CSS Margin And Padding
Styling spaces created by either padding or margin are mainly invisible. But when the background color is added to the mix, padding often...
Read more >API - Styled System
The space utility converts shorthand margin and padding props to margin and padding CSS declarations. Numbers from 0 to the length of theme.space...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oof, I see the issue:
Looks like we set the default
space
for you. So you can fix it with the comment above. I think this code is pulled over fromtheme-ui
, and since everyone always overrides it, it’s never been an issue until now.It would be a breaking change to remove this, but I can do it in the next release. For now, if you explicitly set
space
in your theme, it will solve this.I recommend doing this:
And then: