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

feature request: "default" key for objects in scales #936

Closed
folz opened this issue May 18, 2020 · 3 comments · Fixed by #951
Closed

feature request: "default" key for objects in scales #936

folz opened this issue May 18, 2020 · 3 comments · Fixed by #951
Labels
enhancement New feature or request

Comments

@folz
Copy link
Contributor

folz commented May 18, 2020

Is your feature request related to a problem? Please describe.
We're overhauling our colors. Formerly we had things like colors.green, colors.darkGreen, colors.lightGreen. We now would like to use a format like colors.green.dark or colors.green.500.

The issue is maintaining a backwards-compatible map of former colors to current colors. As-is, we can't have

// colors
green: {
  dark: ...,
  core: ...,
  light: ...,
}

because colors.green is an object in the new world, but before colors.green resolved to a color value. In order to ship this new theme, we would need to update every callsite that used a color-theme-aware sx rule to use colors.green.core.

Describe the solution you'd like
I would like to set a "default" value for objects, such that colors.green resolves to colors.green.default if colors.green is an object value and there is no subsequent .$key accessor.

Describe alternatives you've considered
We could work around this by using colors.greens (plural), avoiding the namespace collision. I dislike this because we would still have to maintain a colors.green that matches colors.greens.default by hand in order to change existing usages of colors.green. I also dislike this on aesthetic grounds (I just would prefer not having plurals in the namespace)

Additional context
Open to discussion on implementation particulars, I just wanted to get your thoughts on whether this sort of backwards-compatibility support is something you think belongs in theme-ui or should be the responsibility of consuming libraries.

@folz folz changed the title "default" key for object scales feature request: "default" key for object scales May 18, 2020
@folz folz changed the title feature request: "default" key for object scales feature request: "default" key for objects in scales May 18, 2020
@jxnblk
Copy link
Member

jxnblk commented May 18, 2020

Thanks! I like this idea a lot, and it seems like something we could try to put on the v1 roadmap -- I'd imagine the implementation would be fairly small, adding an additional check in the getter function's fallback, but haven't looked into it at all yet

@folz
Copy link
Contributor Author

folz commented May 18, 2020

Yeah, a getter check is what I was thinking as well. I can work on a PR with the changes for discussion. How do you want to approach putting this on the roadmap, if at all?

@jxnblk
Copy link
Member

jxnblk commented May 19, 2020

Feel free to start on a PR -- if it's fairly simple to put together, we can slot it in for v1 later or 0.4 sooner. I suspect this should be a breaking change, even if it only affects a small edge case. If it ends up being complicated or time-consuming, we can also hold off on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants