-
Notifications
You must be signed in to change notification settings - Fork 673
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
Support a "default" key for object in scales #951
Conversation
Thanks for tackling this! I think this is a great addition to the API as-is -- it also sets up a nice convention for handling default variants.
I think this is something we'd like to solve for. In the v1 issue, I put this as Idea: Provide some solution for self-referencing scales in other scale definitions. I don't think we need to solve for that in this PR, but feel free to take a stab at proposing what that could look like, if you have time As far as the ensure path points to a primitive point, that's something I hadn't really considered, but might be good to at least warn users if an object or invalid value is being passed on as CSS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few nits/comments, but nothing blocking -- this looks great, thanks!
- Update color scale to use actual colors - Include a test for variant object default behavior - Leave comment indicating object values can't become valid CSS
Thanks for the review! I made the changes you suggested. I'll open a new issue/PR about themeGet functions in themes. |
Opened an issue to track |
Sweet! Thanks, I think this looks good to go, but want to let it sit for a bit so others have time to review or comment |
This is a really good PR. Why didn't we merge it? |
Bumps [lint-staged](https://github.com/okonet/lint-staged) from 10.5.1 to 10.5.3. - [Release notes](https://github.com/okonet/lint-staged/releases) - [Commits](lint-staged/lint-staged@v10.5.1...v10.5.3) Signed-off-by: dependabot-preview[bot] <[email protected]>
Bumps [babel-preset-gatsby](https://github.com/gatsbyjs/gatsby/tree/HEAD/packages/babel-preset-gatsby) from 0.6.0 to 0.8.0. - [Release notes](https://github.com/gatsbyjs/gatsby/releases) - [Changelog](https://github.com/gatsbyjs/gatsby/blob/master/packages/babel-preset-gatsby/CHANGELOG.md) - [Commits](https://github.com/gatsbyjs/gatsby/commits/[email protected]/packages/babel-preset-gatsby) Signed-off-by: dependabot-preview[bot] <[email protected]>
Bumps [execa](https://github.com/sindresorhus/execa) from 4.1.0 to 5.0.0. - [Release notes](https://github.com/sindresorhus/execa/releases) - [Commits](sindresorhus/execa@v4.1.0...v5.0.0) Signed-off-by: dependabot-preview[bot] <[email protected]>
Bumps [@emotion/react](https://github.com/emotion-js/emotion) from 11.1.1 to 11.1.2. - [Release notes](https://github.com/emotion-js/emotion/releases) - [Changelog](https://github.com/emotion-js/emotion/blob/master/CHANGELOG.md) - [Commits](https://github.com/emotion-js/emotion/compare/@emotion/[email protected]...@emotion/[email protected]) Signed-off-by: dependabot-preview[bot] <[email protected]>
…on/react-11.1.2 chore(deps): bump @emotion/react from 11.1.1 to 11.1.2
Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.7. **This update includes a security fix.** - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](npm/ini@v1.3.5...v1.3.7) Signed-off-by: dependabot-preview[bot] <[email protected]>
…staged-10.5.3 chore(deps-dev): bump lint-staged from 10.5.1 to 10.5.3
….3.7 chore(deps): [security] bump ini from 1.3.5 to 1.3.7
…-preset-gatsby-0.8.0 chore(deps-dev): bump babel-preset-gatsby from 0.6.0 to 0.8.0
Bumps [babel-jest](https://github.com/facebook/jest/tree/HEAD/packages/babel-jest) from 26.1.0 to 26.6.3. - [Release notes](https://github.com/facebook/jest/releases) - [Changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md) - [Commits](https://github.com/facebook/jest/commits/v26.6.3/packages/babel-jest) Signed-off-by: dependabot-preview[bot] <[email protected]>
…-jest-26.6.3 chore(deps-dev): bump babel-jest from 26.1.0 to 26.6.3
…-5.0.0 chore(deps-dev): bump execa from 4.1.0 to 5.0.0
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/systemui/theme-ui/cr5r1fra4 |
@folz, I'm gonna change this to |
The implementation is straightforward, but I wanted to discuss something that I think is a pretty large change to the meaning of
get
and/or theme paths.Before this PR, theme-ui does not enforce that
get
on a theme path will return a primitive value suitable for inclusion in CSS. It assumes either that the theme author will write the theme such that all paths lead to primitive values (that is, avoid using objects or arrays at the end of a path), or that the end programmer will ensure all paths will point to a primitive value (that is,'red.500'
, never'red'
).This PR changes the above by moving some of the "ensure path points to a primitive" responsibility to theme-ui, by establishing the convention that
path => object ? object.default
. This is a special case, though. Why notpath => object ? object.500
, orpath => object ? object.core
? Should we support this for object-like values such as Map? What about other ways to store values:path => array ? array['default']
?path => symbol ? symbol.description
?theme-ui also allows for
sx
to contain functions:sx={{color: (theme: Theme) => theme.colors.blue.500}}
This is less ergonomic but more precise than the
object.default
convention. It's also more typesafe, thanks to theTheme
type. What if we allowed the theme to also contain themeGet functions?path => function ? function(theme)
. This would allow things likeIs that a reasonable extension of the "ensure path points to a primitive" responsibility?
Anyway, we don't need to answer literally every question above. Maybe the single special case of
object => default
is fine here. But I still wanted to bring up the possible implications to have a discussion about.Closes #936