-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typography): add typography Sass APIs
BREAKING CHANGE: composite `-type` tokens are no longer supported. Use discrete `-font`, `-size`, `-line-height`, and `-weight` tokens instead. PiperOrigin-RevId: 563797716
- Loading branch information
1 parent
70ce0d2
commit 8e480de
Showing
4 changed files
with
173 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Copyright 2023 Google LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
// go/keep-sorted start | ||
@use 'sass:list'; | ||
// go/keep-sorted end | ||
// go/keep-sorted start | ||
@use '../tokens'; | ||
// go/keep-sorted end | ||
|
||
/// `typeface.theme()` emits `--md-ref-typeface-*` custom properties for given | ||
/// font families and weights. | ||
/// | ||
/// Use this to change the font families or weights for all typescales. | ||
/// | ||
/// @example scss | ||
/// @use '@material/web/typography/typeface'; | ||
/// | ||
/// :root { | ||
/// @include typeface.theme( | ||
/// 'brand': 'Open Sans', | ||
/// 'plain': sans-serif, | ||
/// 'weight-bold': 900, | ||
/// ); | ||
/// } | ||
/// | ||
/// /* Generated CSS */ | ||
/// :root { | ||
/// --md-ref-typeface-brand: 'Open Sans'; | ||
/// --md-ref-typeface-plain: sans-serif; | ||
/// --md-ref-typeface-weight-bold: 900; | ||
/// } | ||
/// | ||
/// @param {Map} $tokens - A Map with `md-ref-typeface` token name keys and | ||
/// their corresponding font family or weight values. | ||
/// @output Emits `--md-ref-typeface-*` custom properties. | ||
@mixin theme($tokens) { | ||
@each $token, $value in $tokens { | ||
@if list.index(tokens.$md-ref-typeface-supported-tokens, $token) == null { | ||
@error 'md-ref-typeface `#{$token}` is not a supported token.'; | ||
} | ||
|
||
@if $value { | ||
--md-ref-typeface-#{$token}: #{$value}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Copyright 2023 Google LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
// go/keep-sorted start | ||
@use 'sass:list'; | ||
// go/keep-sorted end | ||
// go/keep-sorted start | ||
@use '../tokens'; | ||
// go/keep-sorted end | ||
|
||
/// `typescale.theme()` emits `--md-sys-typescale-*` custom properties for given | ||
/// typescale tokens. | ||
/// | ||
/// Use `typeface.theme()` to change font family and weight for all typescales, | ||
/// rather than individually. | ||
/// | ||
/// @example scss | ||
/// @use '@material/web/typography/typescale'; | ||
/// | ||
/// :root { | ||
/// @include typescale.theme( | ||
/// 'body-medium-size': 1rem, | ||
/// 'body-medium-line-height': 1.5rem, | ||
/// /* ... */ | ||
/// ); | ||
/// } | ||
/// | ||
/// /* Generated CSS */ | ||
/// :root { | ||
/// --md-sys-typescale-body-medium-size: 1rem; | ||
/// --md-sys-typescale-body-medium-line-height: 1.5rem; | ||
/// /* ... */ | ||
/// } | ||
/// | ||
/// @param {Map} $tokens - A Map with `md-sys-typescale` token name keys and | ||
/// their corresponding `font` shorthand values. | ||
/// @output Emits `--md-sys-typescale-*` custom properties for given typescales. | ||
@mixin theme($tokens) { | ||
@each $token, $value in $tokens { | ||
@if list.index(tokens.$md-sys-typescale-supported-tokens, $token) == null { | ||
@error 'md-sys-typescale `#{$token}` is not a supported token.'; | ||
} | ||
|
||
@if $value { | ||
--md-sys-typescale-#{$token}: #{$value}; | ||
} | ||
} | ||
} |