-
Notifications
You must be signed in to change notification settings - Fork 673
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Enforce usage of the theme #440
Comments
This is an interesting idea that I see a few issues with:
|
One possible approach (that I have not actually done yet, but it's on my roadmap) is to use a type system in conjunction with tagged literals to enforce theme values while allowing opt-out. My plan is:
From a developer experience perspective, it would look something like: <MyComponent sx={{ color: 'red', backgroundColor: raw`gray` }} /> Where This way, the type system can enforce usage of the theme while still providing an opt-out when necessary. It gives you the ability to discover where engineers need to break out of the theme, but doesn't otherwise block that usage. Here's an example: Try Flow. Typescript doesn't quite have a concept of opaque types, but there are discussions about similar things in this issue: microsoft/TypeScript#202 If you do decide to go this route, I'd love to know how it works out! |
I like the idea of a Still think it'd be a good idea to default to theme, and explicitly unlink from the theme when needed. Here's a common case for me: The main reason for me is with the Imagine you have the following theme: const theme = {
lineHeights: [15, 20, 25, 35]
}; And you want to set the following CSS declaration on an element: line-height: 1;
Typically, you'd do: <Element sx={{ lineHeight: '1' }} /> But that returns the following declaration: line-height: 15px; Technically speaking, this is the correct behaviour, given the current implementation, but how does one achieve the desired goal? Since the <Element sx={{ lineHeight: () => '1' }} /> But no dice. |
@peduarte We've moved away from array indexing in favor of named tokens for all design system values, to avoid precisely that problem. That is, const theme = {
space: {
small: 2,
medium: 4,
}
};
<Box sx={{p: 'small'}} /> and not const theme = {
space: [0, 2, 4, ...]
}
<Box sx={{p: 1}} Feedback from engineers was overwhelmingly that array-based scales were confusing because they conflated literal values with array indexes, so you had to memorize the length of each scale or look it up each time. By switching to token keys, we avoided this problem. |
Quick note regarding the plans for the strict-ui PR (#719): I'm just experimenting around with some ideas, it is very possible that the entire thing will not go anywhere. That being said, we will very likely integrate the "only use tokens from the theme"-validation into a "theme-ui strict mode" (potentially Regarding the escape hatch from only using theme values (e.g. the Yes it will be ugly ("we already have |
Yeah, that's a fair position to take. We're still formalizing our design system at Nextdoor. I don't want to block potentially legitimate usage of things we haven't included yet, which is why I came up with the The |
This is interesting feedback! In all design systems I have seen user-level customization of the overall "theme" was possible. Is that not the case with yours? For example, the // company-some-app/index.js
import { theme } from '@company/design-system';
<ThemeProvider
theme={{
...theme,
colors: {
...theme.colors,
darkmediumlightgrey: '#FAFAFA' // NOTE: we should talk to the ds team about including this in the actual system based on why we need it
}
}}
>
<App />
</ThemeProvider> |
We do use ThemeProvider but it's not directly exposed as a public-level API. It's not deliberate - the idea of supporting that sort of userland customization didn't occur to me. But supporting that makes sense, and would help teams rely more on sx overall. Thanks for the idea. I think I'm in favor of it generally, but can think of four situations that might lead to issues:
All of these are more social problems and not really technical ones, though. Perhaps having a vendor-prefix style convention for userland overrides, like Do you, or anyone else in this thread, have thoughts on these possible issues and how (or if) to solve for them? |
At CircleCI, we do a lot of experimentation, so we want to be able to cheaply build things that may never go anywhere. Ideally those things fit our current design tokens, and we're leveraging our existing theme and components to build higher-level ideas, but when there's conflict that's not easy to resolve, we want to test the viability of the design we're implementing and validate that it's worth pursuing for real before we change our theme to accommodate it. That's where an escape hatch is useful. Similarly, I never want to use |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hi 😃
After using ThemeUI extensively for various websites and Styled-System as the core for a component library of a design system, I experienced issues with developer experience not following the constraint-based pattern:
Often developers end up hard coding the values instead of using the theme.
I know it's a problem of discoverability and documentation but I was thinking that there should also be a better way to make sure the developers know what they are doing.
So I see these options:
What do you guys think?
The text was updated successfully, but these errors were encountered: