Reduce and Simplify Type Variants #1062
Replies: 3 comments 2 replies
-
Also worth noting for folks who would prefer to use object styles, they could still interact with our type tokens like this: import { type, typeColors } from '@workday/canvas-kit-labs-react/tokens';
...
<p css={{ ...type.body.small, ...type.variant.hint, fontWeight: type.fontWeights.bold }}>Small, bold hint text</p> |
Beta Was this translation helpful? Give feedback.
-
Update: The labs |
Beta Was this translation helpful? Give feedback.
-
TL;DR
One consideration: Due to the limitations of Figma, making these changes will cause some drift between CK and our Figma libraries. We should discuss with Sean. ReasoningLabel, Button & CapsFor some history/context, our original Canvas type hierarchy explicitly specified the font weight for each level of the hierarchy. Variants were added for agreed upon "divergences" that didn't fit within the hierarchy (e.g. labels, buttons, caps). MonoUsing HintSame thing goes for ErrorSame here InverseSame here! LinkWhile I agree with your reasoning, this locks people in to using the utility components rather than an object spread, which I don't know will be popular. Probably not the worst thing in the world though - you have to draw a line somewhere. |
Beta Was this translation helpful? Give feedback.
-
Overview
We've done a bit of research for our new type hierarchy and tested out a few component API prototypes, but there wasn't much exploration into our type variants. I'd like to discuss our variants today and whether we'd like to update them along with our type hierarchy. I believe some of the new patterns in canvas-kit may be able to reduce and simplify our type variants making choices more straight-forward for consumers and reducing the cost and complexity for maintainers.
TLDR: Simplify type variants to
error
,hint
, andinverse
, and support other variants through style props, separate components, or both. (Though I believe it's plausible for us to remove all of our current variants if we wanted).I'd like to review each of these variants in turn and propose updates. I believe these changes will make our type components more consistent with our other components, reduce maintenance, and more straightforward for consumers to use in their applications. Below is a list of our current variants and usage guidelines from our design docs.
Label
The
label
variant is a bit odd as the name maps to a particular HTML element, not a particular state or variation such aserror
orinverse
. And the only actual style modification isfontWeight: 500
, though it's described usage is for "body 1/2 and small."Suggested Update
We could better support this usage with the
fontWeight
style prop on our new Typography components. Here's an example:We could also provide a
Label
component on top ofType
that would set these values by default at a fairly low maintenance cost.Button
Similarly, the
button
variant also feels misplaced as it describes an HTML element. And also likelabel
it setsfontWeight
to500
. I'm uncertain why the usage guidelines state that it's also used for "headings, subheadings, and emphasis on paragraph text."Suggested Update
Along with
label
, we could better support this usage with thefontWeight
style prop. Should we decide to make ourButton
s composable, we could create aButton.Text
as a convenient wrapper for this default, or we could hide it within theButton
itself.Caps
The
caps
variant mostly does what you would expect by setting thetextTransform
touppercase
. But it also sets thefontWeight
to700
(I presume for improved readability).Suggested Update
I would recommend we use two style props to accomplish this:
textTransform
andfontWeight
. Below is an example:If we wanted, we could button this up into a
Caps
component, though it feels less necessary thanMono
The
mono
variant only setsfontFamily
tomonoFontFamily
, and while this feels like somewhat like a variation, it seems less clear than others.Suggested Update
Similar to
caps
I would rather support this with a style prop.And / or we could provide a simple wrapper component:
Hint
The
hint
variant feels like a better fit than the former variants overall. Its only modification is settingcolor
totypeColors.hint
, but it seems to be communicating a true variation in usage. `Hint is also the variant most missed by developers in our research. They often chose to modify the color directly instead of applying the variant.Suggested Update
Because the only modification is
color
, you could make a case for supportinghint
with a color style prop instead, and I think that's an option worth considering:But if we wanted to use a variant, I think that would work as well:
And, as previously suggested, if we wanted to add a
Hint
component, it would be a fairly low-maintenance abstraction.Error
Similarly
error
only modifies the text color tostatusColors.error
. It does feel like a true type variant.Suggested Update
Identical to
hint
, we could supporterror
in the same three ways:With the
color
prop:Or with the
variant
prop:And / or with an
Error
component:Inverse
The
inverse
variant follows the same patttern ashint
anderror
. It only modifiescolor
totypeColors.inverse
and feels like a valid type variant.Suggested Update
We can follow the same patterns for
hint
anderror
forinverse
.With the
color
prop:Or with the
variant
prop:And / or with an
Inverse
component:Link
The
link
variant is by far the most complex. And it's worth noting that we have aHyperlink
component that uses variant styles directly (in addition toinverse
variant) and then adds its own styles on top.Suggested Update
I understand the value of having this variant so that it could be applied to many different types of text (headings, standalone links, inline with text, et al). However, now that
Hyperlink
usescreateComponent
and properly supportsas
, I feel thelink
variant is obsolete and is better served by the component directly. When our otherType
components are added,Hyperlink
can be built on top and use those to support any use case.Here's an example in body text:
Or in a heading:
Beta Was this translation helpful? Give feedback.
All reactions