Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update styles to always use arrays instead of sometimes object merging #250

Open
mmarcuccio opened this issue Sep 14, 2018 · 0 comments
Open

Comments

@mmarcuccio
Copy link
Collaborator

mmarcuccio commented Sep 14, 2018

Radium allows you to use (potentially nested) arrays of style objects that are later flattened and merged correctly. Currently, users of Snacks components can only specify a style object. We then sometimes combine this style with existing Snacks styles via the spread operator.

This can be problematic when the user needs to combine multiple style objects with the built in styles of the Snacks component. Also, if the user is passing in a nested object (e.g. a style object w/ a media query), only the top level object is merged while the nested object properties replace existing properties.

The property foo goes missing below:

const styleFromSnacks = { color: 'red', myMediaQuery: { foo: 1  } }
const styleFromUser = { myMediaQuery: { bar: 2 } }
const mergedStyles = {...styleFromSnacks, ...styleFromUser}
console.log(mergedStyles.myMediaQuery) // => {bar: 2}

Some places in the codebase use arrays, but others are merging objects directly.

To solve this issue, we could:

  • Update all Snacks components' style prop to accept either an array or object.
  • Stop using object spreading to combine styles. Instead, build an array of style objects.
@mmarcuccio mmarcuccio changed the title Update style merging to accept arrays Update styles to always use arrays instead of sometimes object merging Sep 14, 2018
@instacart instacart deleted a comment from metatron1973 Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants