Refactor field description components for consistent typography#77791
Refactor field description components for consistent typography#77791kushagra-goyal-14 wants to merge 5 commits into
Conversation
…ent typography and remove unused styles
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| { | ||
| className: clsx( | ||
| defenseStyles.p, | ||
| fieldStyles.description, |
There was a problem hiding this comment.
Can you provide before/after screenshots? Because at first glance this looks like it dropped the color. Also unclear why we would no longer need the defense style.
|
|
||
| const element = useRender( { | ||
| defaultTagName: 'p', | ||
| render, |
There was a problem hiding this comment.
Looks like the render prop is silently dropped.
|
Thanks for the review, @mirka. The color styling and render prop were accidentally removed while I was trying to get the unit tests working. I've fixed both; defense styles are actually still applied through the Text component internally. |
| <Text | ||
| render={ render ?? <p ref={ ref } id={ id } { ...restProps } /> } | ||
| variant="body-sm" | ||
| className={ clsx( fieldStyles.description, className ) } | ||
| /> | ||
| ); |
There was a problem hiding this comment.
props like ref and id should be applied to Text — see the docs
Also, no need to explicitly merge classname with clsx, we can simply forward it via ...props
We should basically copy what Card.Title does (changing the variant to "body-sm")
gutenberg/packages/ui/src/card/title.tsx
Lines 5 to 24 in 1957df1
including defaulting render to the DEFAULT_TAG
| <Text | ||
| render={ <div ref={ ref } { ...restProps } /> } | ||
| variant="body-sm" | ||
| className={ className } |
There was a problem hiding this comment.
Same as previous comment re. ref and className
| .description { | ||
| --_gcd-p-font-size: var(--wpds-typography-font-size-sm); | ||
| --_gcd-p-line-height: var(--wpds-typography-line-height-xs); | ||
| --_gcd-p-margin: 0; |
There was a problem hiding this comment.
It looks like Text doesn't include this gcd variable — @mirka , do you think we should move it to Text ?
gutenberg/packages/ui/src/text/style.module.css
Lines 4 to 6 in 1e307ab
There was a problem hiding this comment.
If I'm not misunderstanding, I believe they'd be covered by this?
gutenberg/packages/ui/src/utils/css/global-css-defense.module.css
Lines 96 to 108 in 83f8f52
gutenberg/packages/ui/src/text/text.tsx
Lines 23 to 24 in 83f8f52
There was a problem hiding this comment.
Oh wait, I think I get what you're saying. #77461 was incomplete, we need to add both heading and p gcd settings for all the Text style variants. I'll prepare something.
There was a problem hiding this comment.
gutenberg/packages/ui/src/text/style.module.css
Lines 84 to 86 in 1e307ab
Thanks for the review, if I am not wrong, and for this case, doesn't body-sm already have the --_gcd-p-* variables set (text/style.module.css lines 84-86) ?
There was a problem hiding this comment.
@kushagra-goyal-14 I think it's ok remove those --_gcd-* variables in this PR, as already applied currently — @mirka will reinforce Text styles and overrides separately
|
@kushagra-goyal-14 as soon as #78172 is merged, you should be able to rebase (or merge trunk) to include those fixes. Let me know when you've done that and addressed remaining feedback, and we'll be able to take another look at this PR 🙌 |
What?
Part of #76929
Updates field utility styles in
@wordpress/uito use theTextcomponent for typography instead of ad hoc CSS utility classes. Specifically refactors:Field.DescriptionField.DetailsFieldset.DescriptionFieldset.DetailsMaintains original CSS styles for
Field.LabelandFieldset.Legendper design system direction to avoid creating limited-use typography variants.Why?
This follows the design system direction in #76929 to standardize typography via
Textvariants. Field descriptions and details have exact matches tobody-smtypography pairing, reducing CSS utility duplication and providing a consistent, documented typography system.How?
Refactored field components to compose:
Textwithvariant="body-sm"(for descriptions/details)render={ <_Field.Description|_Fieldset.Description /> }using Base UI's render propThis approach:
<p>tags remain<p>)Testing Instructions
npm run test:unit -- packages/ui/src/form/primitivesnpm run storybook:devUse of AI Tools
Used Claude AI to help analyze the codebase, draft migrations, and review typography token mappings.