priceline / design-system

Priceline.com Design System
https://priceline.github.io/design-system/
MIT License
722 stars 119 forks source link

Consider alternate object syntax for props that accept arrays #431

Open sdalonzo opened 5 years ago

sdalonzo commented 5 years ago

I always have to keep open a browser tab with theme.js to reference spacing and breakpoints as indices in the array. I would find it very helpful, especially for media query breakpoints, if the prop could also be passed as an object, with keys being the name of the breakpoints, like sm, md, etc

BeniCheni commented 5 years ago

One thought is that library level could coalesce the values being passed in the array in a way that:

So that syntax can be user-friendly for those who favor explicit values in reading the array code.

evanpipta commented 5 years ago

Example

Current syntax:

<Box w={['80px', null, null, null, 1 / 2]}></Box>

Proposed alternative:

<Box w={{xs: '80px', xl: 1 / 2}}></Box>

This would help with two things, for one it would save everyone from having to write null a bunch of times in arrays all across their jsx code, and the semantic key names may make it easier to remember the sizes instead of having to keep a mental mapping of which position in the array maps to which device width.

jxnblk commented 5 years ago

Object support is already being considered here: https://github.com/jxnblk/styled-system/pull/341

dansternfeld1 commented 4 years ago

There's an interest in reviving this topic, as we've got use cases to support additional breakpoints. We also have a ton of code using the arrays; we'd prefer an approach that works as expected with existing code and extends support to an object with named properties.

Using the object syntax described by @747823 might let us interpret the input differently based on type, I'm just not sure what the breakpoints object supplied to the theme will end up looking like. The support for objects in styled-system has evolved a bit since the change @jxnblk linked above, and theme breakpoints are now sorted by size when supplied as an object: https://github.com/styled-system/styled-system/blob/master/packages/core/src/index.js#L18