_radio-theme.scss 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. @use '../core/style/sass-utils';
  2. @use '../core/theming/theming';
  3. @use '../core/theming/inspection';
  4. @use '../core/theming/validation';
  5. @use '../core/tokens/token-utils';
  6. @use '../core/typography/typography';
  7. @use '../core/tokens/m2/mdc/radio' as tokens-mdc-radio;
  8. @use '../core/tokens/m2/mat/radio' as tokens-mat-radio;
  9. /// Outputs base theme styles (styles not dependent on the color, typography, or density settings)
  10. /// for the mat-radio.
  11. /// @param {Map} $theme The theme to generate base styles for.
  12. @mixin base($theme) {
  13. @if inspection.get-theme-version($theme) == 1 {
  14. @include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
  15. } @else {
  16. @include sass-utils.current-selector-or-root() {
  17. @include token-utils.create-token-values(
  18. tokens-mdc-radio.$prefix,
  19. tokens-mdc-radio.get-unthemable-tokens()
  20. );
  21. @include token-utils.create-token-values(
  22. tokens-mat-radio.$prefix,
  23. tokens-mat-radio.get-unthemable-tokens()
  24. );
  25. }
  26. }
  27. }
  28. /// Outputs color theme styles for the mat-radio.
  29. /// @param {Map} $theme The theme to generate color styles for.
  30. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  31. /// $color-variant: The color variant to use for the radio button: primary, secondary, tertiary,
  32. /// or error (If not specified, default primary color will be used).
  33. @mixin color($theme, $options...) {
  34. @if inspection.get-theme-version($theme) == 1 {
  35. @include _theme-from-tokens(inspection.get-theme-tokens($theme, color), $options...);
  36. } @else {
  37. .mat-mdc-radio-button {
  38. &.mat-primary {
  39. @include token-utils.create-token-values(
  40. tokens-mdc-radio.$prefix,
  41. tokens-mdc-radio.get-color-tokens($theme, primary)
  42. );
  43. @include token-utils.create-token-values(
  44. tokens-mat-radio.$prefix,
  45. tokens-mat-radio.get-color-tokens($theme, primary)
  46. );
  47. }
  48. &.mat-accent {
  49. @include token-utils.create-token-values(
  50. tokens-mdc-radio.$prefix,
  51. tokens-mdc-radio.get-color-tokens($theme)
  52. );
  53. @include token-utils.create-token-values(
  54. tokens-mat-radio.$prefix,
  55. tokens-mat-radio.get-color-tokens($theme)
  56. );
  57. }
  58. &.mat-warn {
  59. @include token-utils.create-token-values(
  60. tokens-mdc-radio.$prefix,
  61. tokens-mdc-radio.get-color-tokens($theme, warn)
  62. );
  63. @include token-utils.create-token-values(
  64. tokens-mat-radio.$prefix,
  65. tokens-mat-radio.get-color-tokens($theme, warn)
  66. );
  67. }
  68. }
  69. }
  70. }
  71. /// Outputs typography theme styles for the mat-radio.
  72. /// @param {Map} $theme The theme to generate typography styles for.
  73. @mixin typography($theme) {
  74. @if inspection.get-theme-version($theme) == 1 {
  75. @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
  76. } @else {
  77. @include sass-utils.current-selector-or-root() {
  78. @include token-utils.create-token-values(
  79. tokens-mdc-radio.$prefix,
  80. tokens-mdc-radio.get-typography-tokens($theme)
  81. );
  82. @include token-utils.create-token-values(
  83. tokens-mat-radio.$prefix,
  84. tokens-mat-radio.get-typography-tokens($theme)
  85. );
  86. }
  87. }
  88. }
  89. /// Outputs typography theme styles for the mat-radio.
  90. /// @param {Map} $theme The theme to generate density styles for.
  91. @mixin density($theme) {
  92. @if inspection.get-theme-version($theme) == 1 {
  93. @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
  94. } @else {
  95. $density-scale: inspection.get-theme-density($theme);
  96. @include sass-utils.current-selector-or-root() {
  97. @include token-utils.create-token-values(
  98. tokens-mdc-radio.$prefix,
  99. tokens-mdc-radio.get-density-tokens($theme)
  100. );
  101. @include token-utils.create-token-values(
  102. tokens-mat-radio.$prefix,
  103. tokens-mat-radio.get-density-tokens($theme)
  104. );
  105. }
  106. }
  107. }
  108. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  109. @function _define-overrides() {
  110. @return (
  111. (
  112. namespace: tokens-mdc-radio.$prefix,
  113. tokens: tokens-mdc-radio.get-token-slots(),
  114. ),
  115. (
  116. namespace: tokens-mat-radio.$prefix,
  117. tokens: tokens-mat-radio.get-token-slots(),
  118. ),
  119. );
  120. }
  121. /// Outputs the CSS variable values for the given tokens.
  122. /// @param {Map} $tokens The token values to emit.
  123. @mixin overrides($tokens: ()) {
  124. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  125. }
  126. /// Outputs all (base, color, typography, and density) theme styles for the mat-radio.
  127. /// @param {Map} $theme The theme to generate styles for.
  128. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  129. /// $color-variant: The color variant to use for the radio button: primary, secondary, tertiary,
  130. /// or error (If not specified, default primary color will be used).
  131. @mixin theme($theme, $options...) {
  132. @include theming.private-check-duplicate-theme-styles($theme, 'mat-radio') {
  133. @if inspection.get-theme-version($theme) == 1 {
  134. @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
  135. } @else {
  136. @include base($theme);
  137. @if inspection.theme-has($theme, color) {
  138. @include color($theme);
  139. }
  140. @if inspection.theme-has($theme, density) {
  141. @include density($theme);
  142. }
  143. @if inspection.theme-has($theme, typography) {
  144. @include typography($theme);
  145. }
  146. }
  147. }
  148. }
  149. @mixin _theme-from-tokens($tokens, $options...) {
  150. @include validation.selector-defined(
  151. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  152. );
  153. $mdc-radio-tokens: token-utils.get-tokens-for($tokens, tokens-mdc-radio.$prefix, $options...);
  154. $mat-radio-tokens: token-utils.get-tokens-for($tokens, tokens-mat-radio.$prefix, $options...);
  155. @include token-utils.create-token-values(tokens-mdc-radio.$prefix, $mdc-radio-tokens);
  156. @include token-utils.create-token-values(tokens-mat-radio.$prefix, $mat-radio-tokens);
  157. }