Skip to content

feat: change data-size to work like Figma size mode#3866

Merged
unekinn merged 24 commits intomainfrom
feat/size-modes-rem-font-size
Sep 11, 2025
Merged

feat: change data-size to work like Figma size mode#3866
unekinn merged 24 commits intomainfrom
feat/size-modes-rem-font-size

Conversation

@unekinn
Copy link
Contributor

@unekinn unekinn commented Jul 16, 2025

resolves #3547

Summary

Changes size and font-size variable generation to not use the local font size (em) but rather the --ds-size-mode-font-size variable. This can be set using data-size="<mode>" attribute or --ds-size: var(--ds-size--<mode>) css, where <mode> is sm, md or lg.

Read Sizes in code for info on how size modes work after these changes.

There are no breaking API changes, but potentially large spacing changes when size variables have been applied on Heading elements (typically as margin)

Checks

@changeset-bot
Copy link

changeset-bot bot commented Jul 16, 2025

🦋 Changeset detected

Latest commit: ca6b261

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@digdir/designsystemet-react Minor
@digdir/designsystemet-theme Minor
@digdir/designsystemet Minor
@digdir/designsystemet-css Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jul 16, 2025

Preview deployments for this pull request:

storybook - 8. Sep 2025 - 14:23

www - 8. Sep 2025 - 14:25

@unekinn unekinn force-pushed the feat/size-modes-rem-font-size branch from c4251ac to 84429bb Compare July 16, 2025 13:01
@unekinn unekinn force-pushed the feat/size-modes-rem-font-size branch 3 times, most recently from 0101eea to 8a38225 Compare July 17, 2025 11:39
@unekinn unekinn marked this pull request as ready for review July 17, 2025 17:40
@unekinn unekinn force-pushed the feat/size-modes-rem-font-size branch from 8a38225 to edcb56b Compare July 17, 2025 17:40
@Barsnes
Copy link
Member

Barsnes commented Aug 7, 2025

This looks really good. We'll have a deeper look at this once more people are back from vacation

@unekinn unekinn force-pushed the feat/size-modes-rem-font-size branch 4 times, most recently from c9bd3a8 to 68b4e76 Compare August 29, 2025 12:58
@Barsnes
Copy link
Member

Barsnes commented Sep 1, 2025

Could you add a changeset?
We'll also have to wait until Chromatic usage resets

@unekinn unekinn force-pushed the feat/size-modes-rem-font-size branch from 68b4e76 to a36c16c Compare September 1, 2025 09:07
@oddvernes
Copy link
Collaborator

oddvernes commented Sep 5, 2025

Something funky is going on with the rounding here that causes md and lg to have same size?

https://codepen.io/Oddbj-rn-vernes/pen/jEbdVPX?editors=1100

scroll down to line 70 here where it says @supports (width: round(down, .1em, 1px)) and rename it to @slupports for example to disable the line to see the raw numbers. Then re-enable it and change down to nearest which different but also wrong results (not nearest 1px)

Edit: i tested with the earlier version not-simplified by multiplying everything with --size-1 and that works correctly

Edit2: ok its not so funky but rather makes sense if you look at the numbers more closely
bilde

…e` on parent actually scale these four components
@unekinn
Copy link
Contributor Author

unekinn commented Sep 8, 2025

Something funky is going on with the rounding here that causes md and lg to have same size?

https://codepen.io/Oddbj-rn-vernes/pen/jEbdVPX?editors=1100
...

I was a bit confused about what you meant at first @oddvernes , but you're totally right. In the "simplified" version, when rounding is supported, the resulting values for "md" and "lg" are the same! Also, the "sm" sizes increase less per size than before. So I'll have to revert this 🤔

@oddvernes
Copy link
Collaborator

Looking really good now! 👍

Interestingly --ds-size-30 in data-size="lg" is 139px in chrome and 140px in firefox. There is a couple of other places it is off by 1. But I guess this is a difference in how round() is implemented/behaves and not really an issue

@unekinn
Copy link
Contributor Author

unekinn commented Sep 9, 2025

Looking really good now! 👍

Nice 🎉

Interestingly --ds-size-30 in data-size="lg" is 139px in chrome and 140px in firefox. There is a couple of other places it is off by 1. But I guess this is a difference in how round() is implemented/behaves and not really an issue

Interesting! For instance this...

--ds-size-30: round(down, 139.999999px, 1px);

...rounds to 140px in Firefox, but 139px in Safari. I guess floating point gonna float 🤷‍♀️

@Barsnes
Copy link
Member

Barsnes commented Sep 10, 2025

This is looking good to me! I've tested a bit and can't find any glaring issues

@unekinn
Copy link
Contributor Author

unekinn commented Sep 10, 2025

This is looking good to me! I've tested a bit and can't find any glaring issues

I went through the visual diff thoroughly now, and discovered that Chip is larger than before. This is the only unexpected diff, though. Looking into it now!

@unekinn
Copy link
Contributor Author

unekinn commented Sep 10, 2025

I went through the visual diff thoroughly now, and discovered that Chip is larger than before.

@Barsnes
The sizes are the same in main and this PR when size mode is set directly, but in main the default Chip size was "sm" (height 28px). Also, in main, this:

<div data-size="sm">
  <Chip.Radio>Label</Chip.Radio>
</div>

...would result in a 24px height Chip, while this:

<div>
  <Chip.Radio data-size="sm">Label</Chip.Radio>
</div>

...would result in a 28px height chip 🤯

The new Chip size behavior in this PR matches Chip sizes in Figma "Designsystemet - Core UI Kit" — sm = 28px, md = 32px, lg = 37px — so I'm concluding that this is a bugfix 🎉

@Barsnes
Copy link
Member

Barsnes commented Sep 10, 2025

I went through the visual diff thoroughly now, and discovered that Chip is larger than before.

@Barsnes The sizes are the same in main and this PR when size mode is set directly, but in main the default Chip size was "sm" (height 28px). Also, in main, this:

<div data-size="sm">
  <Chip.Radio>Label</Chip.Radio>
</div>

...would result in a 24px height Chip, while this:

<div>
  <Chip.Radio data-size="sm">Label</Chip.Radio>
</div>

...would result in a 28px height chip 🤯

The new Chip size behavior in this PR matches Chip sizes in Figma "Designsystemet - Core UI Kit" — sm = 28px, md = 32px, lg = 37px — so I'm concluding that this is a bugfix 🎉

well spotted, I have not gone through the visual tests yet.
Could you go through the tests, and I'll go through the review?

Copy link
Member

@Barsnes Barsnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWESOME work! 🔥

@unekinn unekinn merged commit 8f40d64 into main Sep 11, 2025
18 checks passed
@unekinn unekinn deleted the feat/size-modes-rem-font-size branch September 11, 2025 07:52
@github-actions github-actions bot mentioned this pull request Sep 11, 2025
Barsnes added a commit that referenced this pull request Sep 11, 2025
Co-authored-by: Tobias Barsnes <tobias.barsnes@digdir.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Heading-component to behave consistently with data-size

4 participants