Skip to content

Commit

Permalink
fix(tokens)!: tokens.md-comp-*-values() include custom properties b…
Browse files Browse the repository at this point in the history
…y default

BREAKING CHANGE: Sass component tokens, such as `tokens.md-comp-checkbox-values()`, return `var(--md-<component>, <value>)` instead of just the CSS value. Use `$exclude-custom-properties: true` to remove them.

PiperOrigin-RevId: 652550625
  • Loading branch information
asyncLiz authored and copybara-github committed Jul 15, 2024
1 parent a2aa5a3 commit 55b4650
Show file tree
Hide file tree
Showing 90 changed files with 134 additions and 267 deletions.
4 changes: 1 addition & 3 deletions button/internal/_elevated-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-elevated-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-elevated-button-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions button/internal/_filled-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-filled-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-filled-button-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions button/internal/_filled-tonal-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-filled-tonal-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-filled-tonal-button-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions button/internal/_outlined-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-outlined-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-outlined-button-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions button/internal/_text-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-text-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-text-button-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions checkbox/internal/_checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ $_checkmark-bottom-left: 7px, -14px;
}

@mixin styles() {
$tokens: tokens.md-comp-checkbox-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-checkbox-values();

:host {
border-start-start-radius: map.get($tokens, 'container-shape-start-start');
Expand Down
4 changes: 1 addition & 3 deletions chips/internal/_assist-chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-assist-chip-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-assist-chip-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions chips/internal/_filter-chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-filter-chip-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-filter-chip-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions chips/internal/_input-chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-input-chip-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-input-chip-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions chips/internal/_suggestion-chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-suggestion-chip-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-suggestion-chip-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions dialog/internal/_dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
@mixin styles() {
$md-sys-color: tokens.md-sys-color-values-light();
$md-sys-motion: tokens.md-sys-motion-values();
$tokens: tokens.md-comp-dialog-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-dialog-values();

:host {
border-start-start-radius: map.get($tokens, 'container-shape-start-start');
Expand Down
4 changes: 1 addition & 3 deletions divider/internal/_divider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-divider-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-divider-values();

:host {
box-sizing: border-box;
Expand Down
4 changes: 1 addition & 3 deletions elevation/internal/_elevation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-elevation-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-elevation-values();

:host,
.shadow,
Expand Down
4 changes: 1 addition & 3 deletions fab/internal/_fab-branded.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-fab-branded-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-fab-branded-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions fab/internal/_fab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-fab-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-fab-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions field/internal/_filled-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ $_md-sys-motion: tokens.md-sys-motion-values();
}

@mixin styles() {
$tokens: tokens.md-comp-filled-field-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-filled-field-values();

@layer styles {
:host {
Expand Down
4 changes: 1 addition & 3 deletions field/internal/_outlined-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ $_md-sys-motion: tokens.md-sys-motion-values();
}

@mixin styles() {
$tokens: tokens.md-comp-outlined-field-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-outlined-field-values();

@layer styles {
:host {
Expand Down
4 changes: 1 addition & 3 deletions focus/internal/_focus-ring.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ $_md-sys-motion: tokens.md-sys-motion-values();
}

@mixin styles() {
$tokens: tokens.md-comp-focus-ring-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-focus-ring-values();

$active-width: map.get($tokens, 'active-width');
$color: map.get($tokens, 'color');
Expand Down
4 changes: 1 addition & 3 deletions icon/internal/_icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-icon-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-icon-values();

:host {
font-size: map.get($tokens, 'size');
Expand Down
4 changes: 1 addition & 3 deletions iconbutton/internal/_filled-icon-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-filled-icon-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-filled-icon-button-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions iconbutton/internal/_filled-tonal-icon-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-filled-tonal-icon-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-filled-tonal-icon-button-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions iconbutton/internal/_icon-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-icon-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-icon-button-values();

:host {
@each $token, $value in $tokens {
Expand Down
4 changes: 1 addition & 3 deletions iconbutton/internal/_outlined-icon-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-outlined-icon-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-outlined-icon-button-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions labs/card/internal/_elevated-card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-elevated-card-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-elevated-card-values();

:host {
@each $token, $value in $tokens {
Expand Down
4 changes: 1 addition & 3 deletions labs/card/internal/_filled-card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-filled-card-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-filled-card-values();

:host {
@each $token, $value in $tokens {
Expand Down
4 changes: 1 addition & 3 deletions labs/card/internal/_outlined-card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-outlined-card-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-outlined-card-values();

:host {
@each $token, $value in $tokens {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-outlined-segmented-button-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-outlined-segmented-button-values();

:host {
// Only use the logical properties.
Expand Down
4 changes: 1 addition & 3 deletions list/internal/_list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-list-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-list-values();

:host {
background: map.get($tokens, 'container-color');
Expand Down
4 changes: 1 addition & 3 deletions list/internal/listitem/_list-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-list-item-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-list-item-values();

:host {
border-radius: map.get($tokens, 'container-shape');
Expand Down
4 changes: 1 addition & 3 deletions menu/internal/_menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-menu-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-menu-values();

:host {
@include elevation.theme(
Expand Down
4 changes: 1 addition & 3 deletions menu/internal/menuitem/_menu-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
}

@mixin styles() {
$tokens: tokens.md-comp-menu-item-values(
$exclude-custom-properties: false,
);
$tokens: tokens.md-comp-menu-item-values();

:host {
border-radius: map.get($tokens, 'container-shape');
Expand Down
45 changes: 45 additions & 0 deletions migrations/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,48 @@ const agreeCheckbox = document.querySelector(

Note: Element APIs, such as `element.getAttribute('role')` and
`element.ariaLabel` will continue to work as expected.

## Sass `tokens.md-comp-*-values()` include custom properties by default

**What changed?**

Sass component token functions return a `var()` with the component's custom
property, instead of just a value.

```scss
@use '@material/web/tokens';

$checkbox-tokens: tokens.md-comp-checkbox-values();
// (
// // 'icon-size': 18px, // Before
// 'icon-size': var(--md-checkbox-icon-size, 18px), // After
// )
```

**What broke?**

Sass token values from `tokens.md-comp-*-values()` functions are `var()`
functions instead of CSS values. This may introduce additional unnecessary CSS
or break Sass.

```scss
@use '@material/web/tokens';

$checkbox-tokens: tokens.md-comp-checkbox-values();

$double-icon-size: math.mult(map.get($checkbox-tokens, 'icon-size'), 2);
// @error var(--md-checkbox-icon-size, 18px) is not a number.
```

**How to fix?**

Add the parameter `$exclude-custom-properties: true` to the values function.

```scss
@use '@material/web/tokens';

$checkbox-tokens: tokens.md-comp-checkbox-values($exclude-custom-properties: true);
// (
// 'icon-size': 18px,
// )
```
Loading

0 comments on commit 55b4650

Please sign in to comment.