Skip to content

Commit 4f75c27

Browse files
authored
docs(material/theming): add SassDoc for public theming APIs (#22819)
This adds "correct" SassDoc for the core theming APIs, including parameters and return values with types. It doesn't look like either WebStorm or VS Code actually _support_ SassDoc, but this at least makes our source a bit more documented.
1 parent f68a1dc commit 4f75c27

File tree

5 files changed

+118
-45
lines changed

5 files changed

+118
-45
lines changed

src/cdk/a11y/_index.scss

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
@mixin a11y-visually-hidden {
1+
/// Emits a CSS class, `.cdk-visually-hidden`. This class can be applied to an element
2+
/// to make that element visually hidden while remaining available to assitive technology.
3+
@mixin a11y-visually-hidden() {
24
.cdk-visually-hidden {
35
border: 0;
46
clip: rect(0 0 0 0);
@@ -22,14 +24,14 @@
2224
}
2325
}
2426

25-
// @deprecated Use `a11y-visually-hidden`.
26-
@mixin a11y {
27+
/// @deprecated Use `a11y-visually-hidden`.
28+
@mixin a11y() {
2729
@include a11y-visually-hidden;
2830
}
2931

3032
/// Emits the mixin's content nested under `$selector-context` if `$selector-context`
3133
/// is non-empty.
32-
/// @param selector-context The selector under which to nest the mixin's content.
34+
/// @param {String} selector-context The selector under which to nest the mixin's content.
3335
@mixin _optionally-nest-content($selector-context) {
3436
@if ($selector-context == '') {
3537
@content;
@@ -45,9 +47,9 @@
4547
/// to Microsoft browsers. Chrome can be included by checking for the `html[hc]`
4648
/// attribute, however Chrome handles high contrast differently.
4749
///
48-
/// @param target Which kind of high contrast setting to target. Defaults to `active`, can be
49-
/// `white-on-black` or `black-on-white`.
50-
/// @param encapsulation Whether to emit styles for view encapsulation. Values are:
50+
/// @param {String} target Type of high contrast setting to target. Defaults to `active`, can be
51+
/// `white-on-black` or `black-on-white`.
52+
/// @param {String} encapsulation Whether to emit styles for view encapsulation. Values are:
5153
/// * `on` - works for `Emulated`, `Native`, and `ShadowDom`
5254
/// * `off` - works for `None`
5355
/// * `any` - works for all encapsulation modes by emitting the CSS twice (default).

src/cdk/overlay/_index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $overlay-backdrop-color: rgba(0, 0, 0, 0.32) !default;
1212
$backdrop-animation-duration: 400ms !default;
1313
$backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
1414

15-
15+
/// Emits structural styles required for cdk/overlay to function.
1616
@mixin overlay() {
1717
.cdk-overlay-container, .cdk-global-overlay-wrapper {
1818
// Disable events from being captured on the overlay container.

src/material/core/theming/_theming.scss

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ $_emitted-color: () !default;
2020
$_emitted-typography: () !default;
2121
$_emitted-density: () !default;
2222

23-
// For a given hue in a palette, return the contrast color from the map of contrast palettes.
24-
// @param $palette
25-
// @param $hue
23+
/// For a given hue in a palette, return the contrast color from the map of contrast palettes.
24+
/// @param {Map} $palette The palette from which to extract a color.
25+
/// @param {String | Number} $hue The hue for which to get a contrast color.
26+
/// @returns {Color} The contrast color for the given palette and hue.
2627
@function get-contrast-color-from-palette($palette, $hue) {
2728
@return map.get(map.get($palette, contrast), $hue);
2829
}
2930

3031

31-
// Creates a map of hues to colors for a theme. This is used to define a theme palette in terms
32-
// of the Material Design hues.
33-
// @param $base-palette
34-
// @param $default
35-
// @param $lighter
36-
// @param $darker
37-
// @param $text
32+
/// Creates a map of hues to colors for a theme. This is used to define a theme palette in terms
33+
/// of the Material Design hues.
34+
/// @param {Map} $base-palette Map of hue keys to color values for the basis for this palette.
35+
/// @param {String | Number} $default Default hue for this palette.
36+
/// @param {String | Number} $lighter "lighter" hue for this palette.
37+
/// @param {String | Number} $darker "darker" hue for this palette.
38+
/// @param {String | Number} $text "text" hue for this palette.
39+
/// @returns {Map} A complete Angular Material theming palette.
3840
@function define-palette($base-palette, $default: 500, $lighter: 100, $darker: 700,
3941
$text: $default) {
4042
$result: map.merge($base-palette, (
@@ -59,14 +61,15 @@ $_emitted-density: () !default;
5961
}
6062

6163

62-
// Gets a color from a theme palette (the output of mat-palette).
63-
// The hue can be one of the standard values (500, A400, etc.), one of the three preconfigured
64-
// hues (default, lighter, darker), or any of the aforementioned prefixed with "-contrast".
65-
//
66-
// @param $palette The theme palette (output of mat-palette).
67-
// @param $hue The hue from the palette to use. If this is a value between 0 and 1, it will
68-
// be treated as opacity.
69-
// @param $opacity The alpha channel value for the color.
64+
/// Gets a color from a theme palette (the output of mat-palette).
65+
/// The hue can be one of the standard values (500, A400, etc.), one of the three preconfigured
66+
/// hues (default, lighter, darker), or any of the aforementioned prefixed with "-contrast".
67+
///
68+
/// @param {Map} $palette The palette from which to extract a color.
69+
/// @param {String | Number} $hue The hue from the palette to use. If this is a value between 0
70+
// and 1, it will be treated as opacity.
71+
/// @param {Number} $opacity The alpha channel value for the color.
72+
/// @returns {Color} The color for the given palette, hue, and opacity.
7073
@function get-color-from-palette($palette, $hue: default, $opacity: null) {
7174
// If hueKey is a number between zero and one, then it actually contains an
7275
// opacity value, so recall this function with the default hue and that given opacity.
@@ -130,9 +133,12 @@ $_emitted-density: () !default;
130133
);
131134
}
132135

133-
// Creates a container object for a light theme to be given to individual component theme mixins.
134-
// TODO: Remove legacy API and rename `$primary` to `$config`. Currently it cannot be renamed
136+
// TODO: Remove legacy API and rename `$primary` below to `$config`. Currently it cannot be renamed
135137
// as it would break existing apps that set the parameter by name.
138+
139+
/// Creates a container object for a light theme to be given to individual component theme mixins.
140+
/// @param {Map} $primary The theme configuration object.
141+
/// @returns {Map} A complete Angular Material theme map.
136142
@function define-light-theme($primary, $accent: null, $warn: define-palette(palette.$red-palette)) {
137143
// This function creates a container object for the individual component theme mixins. Consumers
138144
// can construct such an object by calling this function, or by building the object manually.
@@ -167,9 +173,12 @@ $_emitted-density: () !default;
167173
@return private-create-backwards-compatibility-theme(_mat-validate-theme($result));
168174
}
169175

170-
// Creates a container object for a dark theme to be given to individual component theme mixins.
171-
// TODO: Remove legacy API and rename `$primary` to `$config`. Currently it cannot be renamed
176+
// TODO: Remove legacy API and rename below `$primary` to `$config`. Currently it cannot be renamed
172177
// as it would break existing apps that set the parameter by name.
178+
179+
/// Creates a container object for a dark theme to be given to individual component theme mixins.
180+
/// @param {Map} $primary The theme configuration object.
181+
/// @returns {Map} A complete Angular Material theme map.
173182
@function define-dark-theme($primary, $accent: null, $warn: define-palette(palette.$red-palette)) {
174183
// This function creates a container object for the individual component theme mixins. Consumers
175184
// can construct such an object by calling this function, or by building the object manually.
@@ -205,6 +214,10 @@ $_emitted-density: () !default;
205214
}
206215

207216
/// Gets the color configuration from the given theme or configuration.
217+
/// @param {Map} $theme The theme map returned from `define-light-theme` or `define-dark-theme`.
218+
/// @param {Map} $default The default value returned if the given `$theme` does not include a
219+
/// `color` configuration.
220+
/// @returns {Map} Color configuration for a theme.
208221
@function get-color-config($theme, $default: null) {
209222
// If a configuration has been passed, return the config directly.
210223
@if not private-is-theme-object($theme) {
@@ -225,6 +238,11 @@ $_emitted-density: () !default;
225238
}
226239

227240
/// Gets the density configuration from the given theme or configuration.
241+
/// @param {Map} $theme-or-config The theme map returned from `define-light-theme` or
242+
/// `define-dark-theme`.
243+
/// @param {Map} $default The default value returned if the given `$theme` does not include a
244+
/// `density` configuration.
245+
/// @returns {Map} Density configuration for a theme.
228246
@function get-density-config($theme-or-config, $default: 0) {
229247
// If a configuration has been passed, return the config directly.
230248
@if not private-is-theme-object($theme-or-config) {
@@ -240,6 +258,11 @@ $_emitted-density: () !default;
240258

241259
/// Gets the typography configuration from the given theme or configuration.
242260
/// For backwards compatibility, typography is not included by default.
261+
/// @param {Map} $theme-or-config The theme map returned from `define-light-theme` or
262+
/// `define-dark-theme`.
263+
/// @param {Map} $default The default value returned if the given `$theme` does not include a
264+
/// `typography` configuration.
265+
/// @returns {Map} Typography configuration for a theme.
243266
@function get-typography-config($theme-or-config, $default: null) {
244267
// If a configuration has been passed, return the config directly.
245268
@if not private-is-theme-object($theme-or-config) {

src/material/core/typography/_typography-utils.scss

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
@use 'sass:map';
22
@use 'sass:meta';
33
@use 'sass:string';
4+
5+
46
// Utility for fetching a nested value from a typography config.
57
@function _mat-get-type-value($config, $level, $name) {
68
@return map.get(map.get($config, $level), $name);
79
}
810

9-
// Gets the font size for a level inside a typography config.
11+
/// Gets the font size for a level inside a typography config.
12+
/// @param {Map} $config A typography config.
13+
/// @param {Map} $level A typography level.
1014
@function font-size($config, $level) {
1115
@return _mat-get-type-value($config, $level, font-size);
1216
}
1317

14-
// Gets the line height for a level inside a typography config.
18+
/// Gets the line height for a level inside a typography config.
19+
/// @param {Map} $config A typography config.
20+
/// @param {Map} $level A typography level.
1521
@function line-height($config, $level) {
1622
@return _mat-get-type-value($config, $level, line-height);
1723
}
1824

19-
// Gets the font weight for a level inside a typography config.
25+
/// Gets the font weight for a level inside a typography config.
26+
/// @param {Map} $config A typography config.
27+
/// @param {Map} $level A typography level.
2028
@function font-weight($config, $level) {
2129
@return _mat-get-type-value($config, $level, font-weight);
2230
}
2331

24-
// Gets the letter spacing for a level inside a typography config.
32+
/// Gets the letter spacing for a level inside a typography config.
33+
/// @param {Map} $config A typography config.
34+
/// @param {Map} $level A typography level.
2535
@function letter-spacing($config, $level) {
2636
@return _mat-get-type-value($config, $level, letter-spacing);
2737
}
2838

29-
// Gets the font-family from a typography config and removes the quotes around it.
39+
/// Gets the font-family from a typography config and removes the quotes around it.
40+
/// @param {Map} $config A typography config.
41+
/// @param {Map} $level A typography level.
3042
@function font-family($config, $level: null) {
3143
$font-family: map.get($config, font-family);
3244

@@ -38,8 +50,13 @@
3850
@return if(meta.type-of($font-family) == string, string.unquote($font-family), $font-family);
3951
}
4052

41-
// Outputs the shorthand `font` CSS property, based on a set of typography values. Falls back to
42-
// the individual properties if a value that isn't allowed in the shorthand is passed in.
53+
/// Outputs the shorthand `font` CSS property, based on a set of typography values. Falls back to
54+
/// the individual properties if a value that isn't allowed in the shorthand is passed in.
55+
/// @param {String} $font-size The font-size value.
56+
/// @param {String | Number} $font-weight The font-weight value.
57+
/// @param {String | Number} $line-height The line-height value.
58+
/// @param {String} $font-family The font-family value.
59+
/// @returns {String} The `font` shorthand value combining the given parts.
4360
@mixin font-shorthand($font-size, $font-weight, $line-height, $font-family) {
4461
// If any of the values are set to `inherit`, we can't use the shorthand
4562
// so we fall back to passing in the individual properties.
@@ -65,7 +82,9 @@
6582
}
6683
}
6784

68-
// Converts a typography level into CSS styles.
85+
/// Emits CSS styles for the given typography level.
86+
/// @param {Map} $config A typography config.
87+
/// @param {Map} $level A typography level.
6988
@mixin typography-level($config, $level) {
7089
$font-size: font-size($config, $level);
7190
$font-weight: font-weight($config, $level);

src/material/core/typography/_typography.scss

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
@use 'typography-utils';
33
@use '../theming/theming';
44

5-
// Represents a typography level from the Material design spec.
5+
/// Defines a typography level from the Material Design spec.
6+
/// @param {String} $font-size The font-size for this level.
7+
/// @param {String | Number} $line-height The line-height for this level.
8+
/// @param {String | Number} $font-weight The font-weight for this level.
9+
/// @param {String} $font-family The font-family for this level.
10+
/// @param {String} $letter-spacing The letter-spacing for this level.
11+
/// @returns {Map} A map representing the definition of this typpographic level.
612
@function define-typography-level(
713
$font-size,
814
$line-height: $font-size,
@@ -19,10 +25,27 @@
1925
);
2026
}
2127

22-
// Represents a collection of typography levels.
23-
// Defaults come from https://material.io/guidelines/style/typography.html
24-
// Note: The spec doesn't mention letter spacing. The values here come from
25-
// eyeballing it until it looked exactly like the spec examples.
28+
/// Defines a collection of typography levels to configure typography for an application.
29+
/// Any level not specified defaults to the values defined in the Material Design specification:
30+
/// https://material.io/guidelines/style/typography.html.
31+
///
32+
/// Note that the Material Design specification does not describe explicit letter-spacing values.
33+
/// The values here come from reverse engineering the Material Design examples.
34+
/// @param {String} $font-family Default font-family for levels that don't specify font-family.
35+
/// @param {Map} $display-4 Configuration for the "display-4" typographic level.
36+
/// @param {Map} $display-3 Configuration for the "display-3" typographic level.
37+
/// @param {Map} $display-2 Configuration for the "display-2" typographic level.
38+
/// @param {Map} $display-1 Configuration for the "display-1" typographic level.
39+
/// @param {Map} $headline Configuration for the "headline" typographic level.
40+
/// @param {Map} $title Configuration for the "title" typographic level.
41+
/// @param {Map} $subheading-2 Configuration for the "subheading-2" typographic level.
42+
/// @param {Map} $subheading-1 Configuration for the "subheading-1" typographic level.
43+
/// @param {Map} $body-2 Configuration for the "body-2" typographic level.
44+
/// @param {Map} $body-1 Configuration for the "body-1" typographic level.
45+
/// @param {Map} $caption Configuration for the "caption" typographic level.
46+
/// @param {Map} $button Configuration for the "button" typographic level.
47+
/// @param {Map} $input Configuration for the "input" typographic level.
48+
/// @returns {Map} A typography config for the application.
2649
@function define-typography-config(
2750
$font-family: 'Roboto, "Helvetica Neue", sans-serif',
2851
$display-4: define-typography-level(112px, 112px, 300, $letter-spacing: -0.05em),
@@ -148,8 +171,12 @@
148171
@return $config;
149172
}
150173

151-
// Adds the base typography styles, based on a config.
152-
// stylelint-disable-next-line material/theme-mixin-api
174+
// stylelint-disable material/theme-mixin-api
175+
176+
/// Emits baseline typographic styles based on a given config.
177+
/// @param {Map} $config-or-theme A typography config for an entire theme.
178+
/// @param {String} $selector Ancestor selector under which native elements, such as h1, will
179+
/// be styled.
153180
@mixin typography-hierarchy($config-or-theme, $selector: '.mat-typography') {
154181
$config: private-typography-to-2014-config(theming.get-typography-config($config-or-theme));
155182

@@ -236,3 +263,5 @@
236263
margin: 0 0 64px;
237264
}
238265
}
266+
267+
// stylelint-enable material/theme-mixin-api

0 commit comments

Comments
 (0)