123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- @use '../core/theming/theming';
- @use '../core/theming/inspection';
- @use '../core/theming/validation';
- @use '../core/tokens/token-utils';
- @use '../core/typography/typography';
- @use '../core/tokens/m2/mdc/filled-button' as tokens-mdc-filled-button;
- @use '../core/tokens/m2/mat/filled-button' as tokens-mat-filled-button;
- @use '../core/tokens/m2/mdc/outlined-button' as tokens-mdc-outlined-button;
- @use '../core/tokens/m2/mat/outlined-button' as tokens-mat-outlined-button;
- @use '../core/tokens/m2/mdc/protected-button' as tokens-mdc-protected-button;
- @use '../core/tokens/m2/mat/protected-button' as tokens-mat-protected-button;
- @use '../core/tokens/m2/mdc/text-button' as tokens-mdc-text-button;
- @use '../core/tokens/m2/mat/text-button' as tokens-mat-text-button;
- @use '../core/style/sass-utils';
- @mixin _text-button-variant($theme, $palette) {
- $mdc-tokens: if(
- $palette,
- tokens-mdc-text-button.private-get-color-palette-color-tokens($theme, $palette),
- tokens-mdc-text-button.get-color-tokens($theme)
- );
- $mat-tokens: if(
- $palette,
- tokens-mat-text-button.private-get-color-palette-color-tokens($theme, $palette),
- tokens-mat-text-button.get-color-tokens($theme)
- );
- @include token-utils.create-token-values(tokens-mdc-text-button.$prefix, $mdc-tokens);
- @include token-utils.create-token-values(tokens-mat-text-button.$prefix, $mat-tokens);
- }
- @mixin _filled-button-variant($theme, $palette) {
- $mdc-tokens: if(
- $palette,
- tokens-mdc-filled-button.private-get-color-palette-color-tokens($theme, $palette),
- tokens-mdc-filled-button.get-color-tokens($theme)
- );
- $mat-tokens: if(
- $palette,
- tokens-mat-filled-button.private-get-color-palette-color-tokens($theme, $palette),
- tokens-mat-filled-button.get-color-tokens($theme)
- );
- @include token-utils.create-token-values(tokens-mdc-filled-button.$prefix, $mdc-tokens);
- @include token-utils.create-token-values(tokens-mat-filled-button.$prefix, $mat-tokens);
- }
- @mixin _protected-button-variant($theme, $palette) {
- $mdc-tokens: if(
- $palette,
- tokens-mdc-protected-button.private-get-color-palette-color-tokens($theme, $palette),
- tokens-mdc-protected-button.get-color-tokens($theme)
- );
- $mat-tokens: if(
- $palette,
- tokens-mat-protected-button.private-get-color-palette-color-tokens($theme, $palette),
- tokens-mat-protected-button.get-color-tokens($theme)
- );
- @include token-utils.create-token-values(tokens-mdc-protected-button.$prefix, $mdc-tokens);
- @include token-utils.create-token-values(tokens-mat-protected-button.$prefix, $mat-tokens);
- }
- @mixin _outlined-button-variant($theme, $palette) {
- $mdc-tokens: if(
- $palette,
- tokens-mdc-outlined-button.private-get-color-palette-color-tokens($theme, $palette),
- tokens-mdc-outlined-button.get-color-tokens($theme)
- );
- $mat-tokens: if(
- $palette,
- tokens-mat-outlined-button.private-get-color-palette-color-tokens($theme, $palette),
- tokens-mat-outlined-button.get-color-tokens($theme)
- );
- @include token-utils.create-token-values(tokens-mdc-outlined-button.$prefix, $mdc-tokens);
- @include token-utils.create-token-values(tokens-mat-outlined-button.$prefix, $mat-tokens);
- }
- @mixin _theme-from-tokens($tokens, $options...) {
- @include validation.selector-defined(
- 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
- );
- $mdc-text-button-tokens: token-utils.get-tokens-for(
- $tokens,
- tokens-mdc-text-button.$prefix,
- $options...
- );
- $mdc-protected-button-tokens: token-utils.get-tokens-for(
- $tokens,
- tokens-mdc-protected-button.$prefix,
- $options...
- );
- $mdc-filled-button-tokens: token-utils.get-tokens-for(
- $tokens,
- tokens-mdc-filled-button.$prefix,
- $options...
- );
- $mdc-outlined-button-tokens: token-utils.get-tokens-for(
- $tokens,
- tokens-mdc-outlined-button.$prefix,
- $options...
- );
- $mat-text-button-tokens: token-utils.get-tokens-for(
- $tokens,
- tokens-mat-text-button.$prefix,
- $options...
- );
- $mat-protected-button-tokens: token-utils.get-tokens-for(
- $tokens,
- tokens-mat-protected-button.$prefix,
- $options...
- );
- $mat-filled-button-tokens: token-utils.get-tokens-for(
- $tokens,
- tokens-mat-filled-button.$prefix,
- $options...
- );
- $mat-outlined-button-tokens: token-utils.get-tokens-for(
- $tokens,
- tokens-mat-outlined-button.$prefix,
- $options...
- );
- @include token-utils.create-token-values(tokens-mdc-text-button.$prefix, $mdc-text-button-tokens);
- @include token-utils.create-token-values(
- tokens-mdc-protected-button.$prefix,
- $mdc-protected-button-tokens
- );
- @include token-utils.create-token-values(
- tokens-mdc-filled-button.$prefix,
- $mdc-filled-button-tokens
- );
- @include token-utils.create-token-values(
- tokens-mdc-outlined-button.$prefix,
- $mdc-outlined-button-tokens
- );
- @include token-utils.create-token-values(tokens-mat-text-button.$prefix, $mat-text-button-tokens);
- @include token-utils.create-token-values(
- tokens-mat-protected-button.$prefix,
- $mat-protected-button-tokens
- );
- @include token-utils.create-token-values(
- tokens-mat-filled-button.$prefix,
- $mat-filled-button-tokens
- );
- @include token-utils.create-token-values(
- tokens-mat-outlined-button.$prefix,
- $mat-outlined-button-tokens
- );
- }
- /// Outputs base theme styles (styles not dependent on the color, typography, or density settings)
- /// for the mat-button.
- /// @param {Map} $theme The theme to generate base styles for.
- @mixin base($theme) {
- @if inspection.get-theme-version($theme) == 1 {
- @include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
- } @else {
- @include sass-utils.current-selector-or-root() {
- @include token-utils.create-token-values(
- tokens-mdc-text-button.$prefix,
- tokens-mdc-text-button.get-unthemable-tokens()
- );
- @include token-utils.create-token-values(
- tokens-mdc-filled-button.$prefix,
- tokens-mdc-filled-button.get-unthemable-tokens()
- );
- @include token-utils.create-token-values(
- tokens-mdc-protected-button.$prefix,
- tokens-mdc-protected-button.get-unthemable-tokens()
- );
- @include token-utils.create-token-values(
- tokens-mdc-outlined-button.$prefix,
- tokens-mdc-outlined-button.get-unthemable-tokens()
- );
- @include token-utils.create-token-values(
- tokens-mat-text-button.$prefix,
- tokens-mat-text-button.get-unthemable-tokens()
- );
- @include token-utils.create-token-values(
- tokens-mat-filled-button.$prefix,
- tokens-mat-filled-button.get-unthemable-tokens()
- );
- @include token-utils.create-token-values(
- tokens-mat-protected-button.$prefix,
- tokens-mat-protected-button.get-unthemable-tokens()
- );
- @include token-utils.create-token-values(
- tokens-mat-outlined-button.$prefix,
- tokens-mat-outlined-button.get-unthemable-tokens()
- );
- }
- }
- }
- /// Outputs color theme styles for the mat-button.
- /// @param {Map} $theme The theme to generate color styles for.
- /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
- /// $color-variant: The color variant to use for the button: primary, secondary, tertiary,
- /// or error (If not specified, default primary color will be used).
- @mixin color($theme, $options...) {
- @if inspection.get-theme-version($theme) == 1 {
- @include _theme-from-tokens(inspection.get-theme-tokens($theme, color), $options...);
- } @else {
- @include sass-utils.current-selector-or-root() {
- @include _text-button-variant($theme, null);
- @include _filled-button-variant($theme, null);
- @include _protected-button-variant($theme, null);
- @include _outlined-button-variant($theme, null);
- }
- .mat-mdc-button {
- &.mat-primary {
- @include _text-button-variant($theme, primary);
- }
- &.mat-accent {
- @include _text-button-variant($theme, accent);
- }
- &.mat-warn {
- @include _text-button-variant($theme, warn);
- }
- }
- .mat-mdc-unelevated-button {
- &.mat-primary {
- @include _filled-button-variant($theme, primary);
- }
- &.mat-accent {
- @include _filled-button-variant($theme, accent);
- }
- &.mat-warn {
- @include _filled-button-variant($theme, warn);
- }
- }
- .mat-mdc-raised-button {
- &.mat-primary {
- @include _protected-button-variant($theme, primary);
- }
- &.mat-accent {
- @include _protected-button-variant($theme, accent);
- }
- &.mat-warn {
- @include _protected-button-variant($theme, warn);
- }
- }
- .mat-mdc-outlined-button {
- &.mat-primary {
- @include _outlined-button-variant($theme, primary);
- }
- &.mat-accent {
- @include _outlined-button-variant($theme, accent);
- }
- &.mat-warn {
- @include _outlined-button-variant($theme, warn);
- }
- }
- }
- }
- /// Outputs typography theme styles for the mat-button.
- /// @param {Map} $theme The theme to generate typography styles for.
- @mixin typography($theme) {
- @if inspection.get-theme-version($theme) == 1 {
- @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
- } @else {
- @include sass-utils.current-selector-or-root() {
- @include token-utils.create-token-values(
- tokens-mdc-text-button.$prefix,
- tokens-mdc-text-button.get-typography-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mdc-filled-button.$prefix,
- tokens-mdc-filled-button.get-typography-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mdc-protected-button.$prefix,
- tokens-mdc-protected-button.get-typography-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mdc-outlined-button.$prefix,
- tokens-mdc-outlined-button.get-typography-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mat-text-button.$prefix,
- tokens-mat-text-button.get-typography-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mat-filled-button.$prefix,
- tokens-mat-filled-button.get-typography-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mat-protected-button.$prefix,
- tokens-mat-protected-button.get-typography-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mat-outlined-button.$prefix,
- tokens-mat-outlined-button.get-typography-tokens($theme)
- );
- }
- }
- }
- /// Outputs density theme styles for the mat-button.
- /// @param {Map} $theme The theme to generate density styles for.
- @mixin density($theme) {
- @if inspection.get-theme-version($theme) == 1 {
- @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
- } @else {
- @include sass-utils.current-selector-or-root() {
- @include token-utils.create-token-values(
- tokens-mdc-text-button.$prefix,
- tokens-mdc-text-button.get-density-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mdc-filled-button.$prefix,
- tokens-mdc-filled-button.get-density-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mdc-protected-button.$prefix,
- tokens-mdc-protected-button.get-density-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mdc-outlined-button.$prefix,
- tokens-mdc-outlined-button.get-density-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mat-text-button.$prefix,
- tokens-mat-text-button.get-density-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mat-filled-button.$prefix,
- tokens-mat-filled-button.get-density-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mat-protected-button.$prefix,
- tokens-mat-protected-button.get-density-tokens($theme)
- );
- @include token-utils.create-token-values(
- tokens-mat-outlined-button.$prefix,
- tokens-mat-outlined-button.get-density-tokens($theme)
- );
- }
- }
- }
- /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
- @function _define-overrides() {
- $mdc-filled-button-tokens: tokens-mdc-filled-button.get-token-slots();
- $mat-filled-button-tokens: tokens-mat-filled-button.get-token-slots();
- $mdc-outlined-button-tokens: tokens-mdc-outlined-button.get-token-slots();
- $mat-outlined-button-tokens: tokens-mat-outlined-button.get-token-slots();
- $mdc-protected-button-tokens: tokens-mdc-protected-button.get-token-slots();
- $mat-protected-button-tokens: tokens-mat-protected-button.get-token-slots();
- $mdc-text-button-tokens: tokens-mdc-text-button.get-token-slots();
- $mat-text-button-tokens: tokens-mat-text-button.get-token-slots();
- @return (
- (
- namespace: tokens-mdc-filled-button.$prefix,
- tokens: $mdc-filled-button-tokens,
- prefix: 'filled-',
- ),
- (
- namespace: tokens-mat-filled-button.$prefix,
- tokens: $mat-filled-button-tokens,
- prefix: 'filled-',
- ),
- (
- namespace: tokens-mdc-outlined-button.$prefix,
- tokens: $mdc-outlined-button-tokens,
- prefix: 'outlined-',
- ),
- (
- namespace: tokens-mat-outlined-button.$prefix,
- tokens: $mat-outlined-button-tokens,
- prefix: 'outlined-',
- ),
- (
- namespace: tokens-mdc-protected-button.$prefix,
- tokens: $mdc-protected-button-tokens,
- prefix: 'protected-',
- ),
- (
- namespace: tokens-mat-protected-button.$prefix,
- tokens: $mat-protected-button-tokens,
- prefix: 'protected-',
- ),
- (
- namespace: tokens-mdc-text-button.$prefix,
- tokens: $mdc-text-button-tokens,
- prefix: 'text-',
- ),
- (
- namespace: tokens-mat-text-button.$prefix,
- tokens: $mat-text-button-tokens,
- prefix: 'text-',
- ),
- );
- }
- /// Outputs the CSS variable values for the given tokens.
- /// @param {Map} $tokens The token values to emit.
- @mixin overrides($tokens: ()) {
- @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
- }
- /// Outputs all (base, color, typography, and density) theme styles for the mat-button.
- /// @param {Map} $theme The theme to generate styles for.
- /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
- /// $color-variant: The color variant to use for the button: primary, secondary, tertiary,
- /// or error (If not specified, default primary color will be used).
- @mixin theme($theme, $options...) {
- @include theming.private-check-duplicate-theme-styles($theme, 'mat-button') {
- @if inspection.get-theme-version($theme) == 1 {
- @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
- } @else {
- @include base($theme);
- @if inspection.theme-has($theme, color) {
- @include color($theme);
- }
- @if inspection.theme-has($theme, density) {
- @include density($theme);
- }
- @if inspection.theme-has($theme, typography) {
- @include typography($theme);
- }
- }
- }
- }
|