Skip to content

Commit

Permalink
feat(material/theming): Add APIs to get density info from theme
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Aug 14, 2023
1 parent f52e979 commit e608f5f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/material/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,5 @@ list-density, list-base;

// New theming APIs, currently in development:
@forward './core/theming/inspection' as private-* show private-get-theme-version,
private-get-theme-type, private-get-theme-color, private-get-theme-typography;
private-get-theme-type, private-get-theme-color, private-get-theme-typography,
private-get-theme-density;
12 changes: 12 additions & 0 deletions src/material/core/theming/_inspection.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
@return map.get($theme, $_internals, typography-tokens, (mdc, typography), $token-name);
}

/// Gets the density scale from a theme object.
/// @param {Map} $theme The theme
/// @return {Number} The density scale.
@function get-theme-density($theme) {
$err: _validate-theme-object($theme);
@if $err {
// TODO(mmalerba): implement for old style theme objects.
@error #{'get-theme-density does not support legacy theme objects.'};
}
@return map.get($theme, $_internals, density-scale);
}

/// Gets the set of tokens from the given theme, limited to those affected by the requested theming
/// systems.
/// @param {Map} $theme The theme to get tokens from.
Expand Down
13 changes: 12 additions & 1 deletion src/material/core/theming/tests/theming-inspection-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,20 @@ describe('theming inspection api', () => {
transpile(`
$theme: ${defineM3Theme()};
div {
font: mat.private-get-theme-typography($theme, body-small, text-transform);
text-transform: mat.private-get-theme-typography($theme, body-small, text-transform);
}
`),
).toThrowError(/Valid typography properties are:.*Got: text-transform/);
});

it('should get density scale', () => {
expect(
transpile(`
$theme: ${defineM3Theme()};
div {
--density-scale: #{mat.private-get-theme-density($theme)};
}
`),
).toMatch('--density-scale: 0;');
});
});

0 comments on commit e608f5f

Please sign in to comment.