Reputation: 8102
I have this code:
const styles = theme => ({
root: {
paddingTop: theme.spacing.unit * 3,
paddingBottom: theme.spacing.unit * 3,
paddingLeft: 0,
paddingRight: 0,
}
});
Is it posible to set padding with only one line? (I want to do something like this:)
const styles = theme => ({
root: {
padding: 0 theme.spacing.unit * 3',
}
});
Upvotes: 0
Views: 34
Reputation: 14927
Yes, you can do it by creating the string like so (using template literals):
const styles = theme => ({
root: {
padding: `${theme.spacing.unit * 3} 0`,
}
});
If the theme spacing unit was 10px
that would result in padding: 10px 0
, which is shorthand for padding: 10px 0 10px 0;
It is important to use the back ticks (`) and not quotes.
One thing to note, if your theme.spacing.unit
does not include the unit of measure, add it after the curly braces like so:
padding: `${theme.spacing.unit * 3}px 0`,
Upvotes: 1