[Layout] Responsive props #7500
-
Let's discuss a couple options for setting responsive values in our layout components. In some cases it feels like over engineering to allow values to each of our 5 breakpoints. Take padding for instance: --pc-box-padding-xs: var(--p-space-4);
--pc-box-padding-sm: var(--pc-box-padding-xs);
--pc-box-padding-md: var(--pc-box-padding-sm);
--pc-box-padding-lg: var(--pc-box-padding-md);
--pc-box-padding-xl: var(--pc-box-padding-lg);
padding: var(--pc-box-padding-xs);
@media #{$p-breakpoints-sm-up} {
padding: var(--pc-box-padding-sm);
}
@media #{$p-breakpoints-md-up} {
padding: var(--pc-box-padding-md);
}
@media #{$p-breakpoints-lg-up} {
padding: var(--pc-box-padding-lg);
}
@media #{$p-breakpoints-xl-up} {
padding: var(--pc-box-padding-xl);
} This is a lot of overhead for something as simple as padding. How often are we or our consumers going to need different values at each of these breakpoints? Alternative solution: Use our breakpoint utility function: const {smUp, mdUp, lgUp, xlUp} = useBreakpoints();
const padding = () => {
switch (true) {
case xlUp:
return '5';
case lgUp:
return '4';
case mdUp:
return '3';
case smUp:
return '2';
default:
return '1';
}
};
return (
<Box padding={padding()}>
); This is an extreme example where the consumer needs different values at each breakpoint where 99% of the time it would probably look more like this: <Box padding={mdUp ? '2' : '1'} /> Because layouts in the admin don't usually change padding at more than one breakpoint. There are drawbacks to each option here. One major one would be how difficult migrations would be where we'd have to import I think the responsive props object is generally clearer but it does add a lot of overhead |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
@aaronccasanova and I jammed on this @mixin responsive-props($componentName, $componentProp, $declartionProp) {
--pc-#{$componentName}-#{$componentProp}-xs: initial;
--pc-#{$componentName}-#{$componentProp}-sm: var(--pc-#{$componentName}-#{$componentProp}-xs);
--pc-#{$componentName}-#{$componentProp}-md: var(--pc-#{$componentName}-#{$componentProp}-sm);
--pc-#{$componentName}-#{$componentProp}-lg: var(--pc-#{$componentName}-#{$componentProp}-md);
--pc-#{$componentName}-#{$componentProp}-xl: var(--pc-#{$componentName}-#{$componentProp}-lg);
#{$declartionProp}: var(--pc-#{$componentName}-#{$componentProp}-xs);
@media #{$p-breakpoints-sm-up} {
#{$declartionProp}: var(--pc-#{$componentName}-#{$componentProp}-sm);
}
@media #{$p-breakpoints-md-up} {
#{$declartionProp}: var(--pc-#{$componentName}-#{$componentProp}-md);
}
@media #{$p-breakpoints-lg-up} {
#{$declartionProp}: var(--pc-#{$componentName}-#{$componentProp}-lg);
}
@media #{$p-breakpoints-xl-up} {
#{$declartionProp}: var(--pc-#{$componentName}-#{$componentProp}-xl);
}
}
.AlphaStack {
@include responsive-props(stack, spacing, gap);
[...]
} We want to avoid using the So we can see us having a set of utilities including this |
Beta Was this translation helpful? Give feedback.
-
Is there more context for why |
Beta Was this translation helpful? Give feedback.
-
IMO, it would be great to avoid a solution that requires responsive conditions to be resolved in JavaScript, like the
|
Beta Was this translation helpful? Give feedback.
-
Thanks folks! Going to close this with the consensus that css approaches are better for everyone here. We're going to update some APIs to allow responsive props as well as single values |
Beta Was this translation helpful? Give feedback.
Thanks folks! Going to close this with the consensus that css approaches are better for everyone here. We're going to update some APIs to allow responsive props as well as single values