Replies: 4 comments 1 reply
-
I love this idea. I think adding size tokens would go a long way in terms of the maintainability of components that use the size prop, as well as future components or sizes we will need to implement. |
Beta Was this translation helpful? Give feedback.
-
Very very into this idea. The potential issues you describe seem to point to still needing |
Beta Was this translation helpful? Give feedback.
-
@janhassel thanks for taking the time to write this up! I really appreciate the proposal and the level of detail that went into it. Parts of this sound similar to the idea of container tokens, in a way, which may be worth resurrecting. If I remember that concept right it was a sequential scale: Another similar idea in this space was if we could ever want to "inline theme" the spacing scale, but that always seems to impact more things than we would like 🤷 . The idea was that this could make it easy to have different "modes" like condensed, default, cozy. Anyways, I definitely want to read more into this and more notes next week but just wanted to leave some thoughts on some of the questions or concerns that you brought up in the interim 👀
I do think that we need to be able to support:
Here's a quick codesandbox that models this idea: https://codesandbox.io/s/exciting-clarke-ebr0q?file=/src/App.js
Totally get what you mean. Since components have different size domains, we also can run into a situation where:
Component B can map to
Super small note, I think we'll align to the CSS logical properties naming scheme as we invest more into CSS Custom Properties / component tokens. Specifically |
Beta Was this translation helpful? Give feedback.
-
Just want to update - the initial PR is up here: #13287 |
Beta Was this translation helpful? Give feedback.
-
Related: #10616, #10617, #7701
Motivation
As of right now, the different size variants of components are implemented on a per component basis. Each component that offers different sizes accepts a
size
prop which the consumer can set to one of the supported size options (mostlysm
,md
andlg
). The component then adds a css class depending on the selected size, e.g.cds--text-input--lg
, to define the specific styles (in most cases just setting the component's height).This approach has some considerable drawbacks:
1.1 prop to accept a size
1.2 logic to add a css class to the container
1.3 css rules to apply the correct styles
lg
in Component A matcheslg
in component B. The sizes are however defined inrem
for each component (e.g..cds--text-input--lg { height: rem(48px); }
). This means if size definitions were to change it would need to be updated in all occurances. Adding new size variants throughout the system is a good amount of work.Approach
While creating semantic size tokens like
var(--cds-size-lg)
would mitigate point 2 already, there is more potential in combining this with a contextual token system (similar to how color layering works in v11 now).Most of the time, a consumer doesn't just need to adjust the size of one specific component but of a few adjacent components (as components in one group should always match in height).
When the sizing responsibility is outsourced to a utility component, points 1 and 3 could also be mitigated while reducing redundancy in the consumer's code.
At the same time, components would no longer need to individually support a
size
prop, handle the logic to add css classes and define their own styles. It would happen through contextual tokens:Design
All size tokens would be defined in
:root
(or wherever the theme is emitted) and the contextual token would be redefined by the utility component (<Layout>
in the examples above though I'm not at all attached to the name).This would solve the redundancy in code for individual components as well as making it easier for development teams to create custom components and compositions that adapt automagically to the rest of the UI.
Advancing the approach to spacing tokens
Since most components use the same spacing / padding logic to achieve alignment throughout the UI, these values would be an interesting candidate for semantic, contextual tokens as well. Instead of defining
padding-left
andpadding-right
tovar(--cds-spacing-05)
for each component, there could be a semantic alias like--cds-padding-x
.If this semantic token is now made contextual, building out a condensed zoning component (#10617) would be quite easy.
In the theme:
In the component:
As a consumer:
This design also leaves room for a potential
wide
layout mode as all it would take is one additional css custom property and css rule handling it. All components would support it out of the box.padding-x
is only one of many opportunities to standardize the way components are rendered and each one will make it easier for development teams to implement custom components and compositions that strictly follow Carbon components.Demo
Here is a quick codepen of how it could work: https://codepen.io/janhassel/pen/gOXryGZ/87b8dd253d26231bfa573d4a6c90f93e?editors=1100
Potential issues
md
vs. Button withlg
for example)?<Layout>
component be too confusing or verbose for some developers when they actually only need to adjust the size of one component?2xl
where aButton
needs to when they're in a modal)Overall, as a consumer of the Carbon Design System and someone that regularily develops custom components this would be such a big help to ensure my components and application will always be aligned with the standard Carbon ones and they would grow together with the system (refering to the example above with condensed or wide UI zones) without me actively needing to add support.
I'm very excited about the amount of opportunities for a truly adaptive and smart design system a technology like css custom properties actually opens and I'd love y'alls thoughts and feedback on this.
Beta Was this translation helpful? Give feedback.
All reactions