Skip to content

Initializing design token system for sizes #251271

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

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

mrleemurray
Copy link
Contributor

This pull request introduces support for a new category of CSS variables (sizes) and updates the codebase to use these variables for styling, improving maintainability and consistency.

Key changes include:

  • creating sizeRegistry & sizeUtils to handle the registration of size tokens and provide utility functions for size-related operations
  • refactoring CSS files in src/base/browser/ui to replace hardcoded values with the new sizes variables
  • adding the sizes category to the known variables list, updating JSON data

Support for new sizes category:

  • build/lib/stylelint/validateVariableNames.js and build/lib/stylelint/validateVariableNames.ts: Added the sizes category to the known variables set, allowing the use of size-related CSS variables. [1] [2]
  • build/lib/stylelint/vscode-known-variables.json: Introduced a comprehensive list of size-related variables under the new sizes category.

Refactoring CSS files to use size variables:

The following CSS files in src/base/browser/ui have been updated to use the new sizes variables for improved consistency and maintainability:

  • actionbar/actionbar.css
  • button/button.css
  • countBadge/countBadge.css
  • dialog/dialog.css
  • dnd/dnd.css
  • dropdown/dropdown.css
  • findInput/findInput.css
  • hover/hoverWidget.css
  • iconLabel/iconLabel.css
  • icons/iconSelectBox.css
  • inputbox/inputBox.css
  • keybindingLabel/keybindingLabel.css
  • list/list.css
  • menu/menubar.css
  • progressbar/progressbar.css
  • radio/radio.css
  • sash/sash.css
  • scrollbar/media/scrollbars.css
  • splitview/paneview.css
  • splitview/splitview.css
  • table/table.css
  • toggle/toggle.css
  • toolbar/toolbar.css
  • tree/media/paneviewlet.css
  • tree/media/tree.css

Moving forward, the design team will make incremental updates to tokens & styles during debt weeks.

lemurra_microsoft added 21 commits May 27, 2025 10:41
…ton focus outline offset, and refine spacing sizes
… improved consistency and maintainability; update size registry with new dimensions and corner radii for controls.
…aintainability

- Updated selectBox styles to use CSS variables for corner radius, font size, and dimensions.
- Modified paneview styles to utilize CSS variables for header height, width, and spacing.
- Adjusted splitview styles to incorporate CSS variables for separator dimensions.
- Changed table styles to apply CSS variables for border dimensions.
- Revised toggle styles to implement CSS variables for margin and padding.
- Altered toolbar styles to use CSS variables for padding.
- Updated tree styles to utilize CSS variables for spacing and dimensions.
- Enhanced sizeRegistry to include new CSS variables for various UI components.
- Introduced new sizes for corner radii, iconography, shadows, and spacing.
- Improved typography sizes with additional font size variables for better text rendering.
@mrleemurray mrleemurray requested a review from bpasero June 12, 2025 11:29
@vs-code-engineering vs-code-engineering bot added this to the June 2025 milestone Jun 12, 2025
@bpasero bpasero requested a review from aeschli June 12, 2025 11:55
@bpasero
Copy link
Member

bpasero commented Jun 12, 2025

Adding also @aeschli

@mrleemurray for an easier review: is this change already changing dimensions that we had or is it taking the value it used to have and extract that into a variable?

@mrleemurray
Copy link
Contributor Author

@bpasero no values are being changed - only converting current values into variables.

@aeschli
Copy link
Contributor

aeschli commented Jun 13, 2025

Looks great.
Is there already a SizeTheme, or a color theme that has a 'getSize' method?

@mrleemurray
Copy link
Contributor Author

@aeschli no SizeTheme yet - I'd like to have a full working set of tokens before creating themes, but I'm happy to start exploring that functionality now

@mrleemurray
Copy link
Contributor Author

@aeschli I have just added a sizeFromId utility function to allow js to access the values

@mrleemurray mrleemurray enabled auto-merge June 17, 2025 09:01
@mrleemurray
Copy link
Contributor Author

@aeschli is there anything else you require for the review?

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

@mrleemurray I am looking at this from a high level and I think you did a pretty good job in mimicking what we already have today for colors based on what @aeschli did. I defer to his 👁 for whether that integration into the theme story works for him.

I am having some question marks in my head around the naming of all the variables. I see that some widgets share the same variable (for example --vscode-base-spacing-xxs) but is there really also a logical relation between all the widgets sharing the same color?

To give an example:

  • the dialog has a vscode-base-spacing-none for its blocking div (the one we use so that you cannot click behind the dialog) (here)
  • but then this variable is also used for the dropdown widget as padding (here)

Changing the value of the variable will have a weird outcome: the dropdown has larger padding, but also the dialog now has parts where you can click through?

This is just one example, and I am sure there will be many more.

I believe we would actually have to begin with almost having a variable per widget specific size inside to have an overview of all the things before we can start to reuse things?

@mrleemurray
Copy link
Contributor Author

@bpasero I think you are right - I was trying to limit the amount of unique tokens, but we will run into issues mentioned above. I will make more specific, per widget tokens. These granular tokens can inherit base values, which will help with overall consistency, but can also be updated individually if required. I have a couple of questions that will also help with logic:

  • Do we need 0px tokens? In your dialog example it doesn't make much sense to have the ability to control the blocking element padding. Are there any instances where modifying a 0px value is required?
  • Should we even expose the base tokens as CSS Variables? They might be useful for extension developers, but again might cause unintended side effects of changing them

@bpasero
Copy link
Member

bpasero commented Jun 18, 2025

@mrleemurray yeah you bring up a good point that maybe not every size value should be controlled by a theme, there are sometimes reasons to have them at a fixed value, but then how do we track these in the CSS that we are not accidentally pulling them out?

Alternatively, a value like 0 could easily be a variable that we never allow to customise.

What specifically do you refer to as "base tokens"?

@mrleemurray
Copy link
Contributor Author

mrleemurray commented Jun 18, 2025

@bpasero do you mean that a 0 variable would still appear in the stylesheet, but not in a theme?

What specifically do you refer to as "base tokens"?

I mean the 4px grid / generic values that all other sizes should be derived from e.g. --vscode-base-spacing-s (any variable with the word base in the name)

@bpasero
Copy link
Member

bpasero commented Jun 18, 2025

do you mean that a 0 variable would still appear in the stylesheet, but not in a theme?

Either way, we need a solution to identify a size value in a CSS file as being externalised so that we know which values still need to be converted to a variable. If we leave some values around because they are not themeable then we need to mark them in some way.

mean the 4px grid / generic values that all other sizes should be derived from e.g. --vscode-base-spacing-s (any variable with the word base in the name)

I do not think that there should be base values like that that variables extend from, because changing them has impact that is not desired, as long as the variables are not correlated. I would have logical base variables that other variables can extend from. I am not sure the value of having variables like "grid-4px-variable"?

@mrleemurray
Copy link
Contributor Author

mrleemurray commented Jun 18, 2025

Okay, let's go with adding "static" CSS variables that can't be updated by themes.

I do not think that there should be base values like that that variables extend from, because changing them has impact that is not desired, as long as the variables are not correlated. I would have logical base variables that other variables can extend from. I am not sure the value of having variables like "grid-4px-variable"?

Apologies, I was meaning from the design stage - in Figma we use inheritance to define the values of each granular variable, but every variable will be exported as a standalone variable with it's own value, for future updates.

@mrleemurray mrleemurray requested a review from bpasero June 26, 2025 09:55
@mrleemurray
Copy link
Contributor Author

@bpasero I have created a much more granular set of tokens that allow fine tuning of specific components without affecting other parts of the UI. I have also created a new set of "static" tokens to represent values that will not be exposed in themes - these tokens currently represent 0px values.

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.

3 participants