Skip to content

Commit e608f5f

Browse files
committed
feat(material/theming): Add APIs to get density info from theme
1 parent f52e979 commit e608f5f

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/material/_index.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,5 @@ list-density, list-base;
145145

146146
// New theming APIs, currently in development:
147147
@forward './core/theming/inspection' as private-* show private-get-theme-version,
148-
private-get-theme-type, private-get-theme-color, private-get-theme-typography;
148+
private-get-theme-type, private-get-theme-color, private-get-theme-typography,
149+
private-get-theme-density;

src/material/core/theming/_inspection.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
149149
@return map.get($theme, $_internals, typography-tokens, (mdc, typography), $token-name);
150150
}
151151

152+
/// Gets the density scale from a theme object.
153+
/// @param {Map} $theme The theme
154+
/// @return {Number} The density scale.
155+
@function get-theme-density($theme) {
156+
$err: _validate-theme-object($theme);
157+
@if $err {
158+
// TODO(mmalerba): implement for old style theme objects.
159+
@error #{'get-theme-density does not support legacy theme objects.'};
160+
}
161+
@return map.get($theme, $_internals, density-scale);
162+
}
163+
152164
/// Gets the set of tokens from the given theme, limited to those affected by the requested theming
153165
/// systems.
154166
/// @param {Map} $theme The theme to get tokens from.

src/material/core/theming/tests/theming-inspection-api.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,20 @@ describe('theming inspection api', () => {
259259
transpile(`
260260
$theme: ${defineM3Theme()};
261261
div {
262-
font: mat.private-get-theme-typography($theme, body-small, text-transform);
262+
text-transform: mat.private-get-theme-typography($theme, body-small, text-transform);
263263
}
264264
`),
265265
).toThrowError(/Valid typography properties are:.*Got: text-transform/);
266266
});
267+
268+
it('should get density scale', () => {
269+
expect(
270+
transpile(`
271+
$theme: ${defineM3Theme()};
272+
div {
273+
--density-scale: #{mat.private-get-theme-density($theme)};
274+
}
275+
`),
276+
).toMatch('--density-scale: 0;');
277+
});
267278
});

0 commit comments

Comments
 (0)