_extended-fab-theme.scss 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. // Copyright 2016 Google Inc.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. // stylelint-disable selector-class-pattern --
  21. // Selector '.mdc-*' should only be used in this project.
  22. @use '@material/animation/functions' as animation-functions;
  23. @use '@material/elevation/elevation-theme';
  24. @use '@material/feature-targeting/feature-targeting';
  25. @use '@material/dom/mixins' as dom-mixins;
  26. @use '@material/ripple/ripple';
  27. @use '@material/ripple/ripple-theme';
  28. @use '@material/rtl/rtl';
  29. @use '@material/shape/mixins' as shape-mixins;
  30. @use '@material/shape/functions' as shape-functions;
  31. @use '@material/theme/css';
  32. @use '@material/theme/custom-properties';
  33. @use '@material/theme/keys';
  34. @use '@material/theme/replace';
  35. @use '@material/theme/state';
  36. @use '@material/theme/theme-color';
  37. @use '@material/theme/theme';
  38. @use '@material/tokens/resolvers';
  39. @use '@material/touch-target/mixins' as touch-target-mixins;
  40. @use '@material/typography/typography';
  41. @use './fab-theme';
  42. @use 'sass:math';
  43. @use 'sass:map';
  44. @use 'sass:list';
  45. $extended-icon-padding: 12px !default;
  46. $extended-label-padding: 20px !default;
  47. $extended-height: 48px !default;
  48. $extended-light-theme: (
  49. container-color: theme-color.$surface,
  50. container-elevation: 3,
  51. container-height: 56px,
  52. container-shadow-color: black,
  53. container-shape: 50%,
  54. container-surface-tint-layer-color: null,
  55. focus-container-elevation: null,
  56. focus-icon-color: null,
  57. focus-label-text-color: null,
  58. focus-outline-color: null,
  59. focus-outline-width: null,
  60. focus-state-layer-color: theme-color.$primary,
  61. focus-state-layer-opacity: null,
  62. hover-container-elevation: null,
  63. hover-icon-color: null,
  64. hover-label-text-color: null,
  65. hover-state-layer-color: theme-color.$primary,
  66. hover-state-layer-opacity: null,
  67. icon-color: null,
  68. icon-size: 36px,
  69. label-text-color: theme-color.$on-surface,
  70. label-text-font: typography.get-font(button),
  71. label-text-size: typography.get-size(button),
  72. label-text-tracking: typography.get-tracking(button),
  73. label-text-weight: typography.get-weight(button),
  74. lowered-container-elevation: null,
  75. lowered-focus-container-elevation: null,
  76. lowered-hover-container-elevation: null,
  77. lowered-pressed-container-elevation: null,
  78. pressed-container-elevation: null,
  79. pressed-icon-color: null,
  80. pressed-label-text-color: null,
  81. pressed-ripple-color: null,
  82. pressed-ripple-opacity: null,
  83. pressed-state-layer-color: theme-color.$primary,
  84. pressed-state-layer-opacity: null,
  85. );
  86. $custom-property-prefix: 'extended-fab';
  87. ///
  88. /// Applies the given theme as custom properties without any selectors.
  89. ///
  90. @mixin theme($theme, $resolvers: resolvers.$material) {
  91. @include theme.validate-theme($extended-light-theme, $theme);
  92. $resolved-theme: fab-theme.resolve-theme($theme, $resolvers);
  93. @include keys.declare-custom-properties(
  94. $resolved-theme,
  95. $prefix: $custom-property-prefix
  96. );
  97. }
  98. @mixin theme-styles($theme, $resolvers: resolvers.$material) {
  99. @include theme.validate-theme($extended-light-theme, $theme);
  100. $theme: keys.create-theme-properties(
  101. $theme,
  102. $prefix: $custom-property-prefix
  103. );
  104. @include fab-theme.base-theme-styles($theme, $resolvers: $resolvers);
  105. $container-shape: map.get($theme, container-shape);
  106. @if $container-shape {
  107. @include extended-shape-radius($container-shape);
  108. }
  109. @include _label-color(
  110. (
  111. default: map.get($theme, label-text-color),
  112. hover: map.get($theme, hover-label-text-color),
  113. focus: map.get($theme, focus-label-text-color),
  114. pressed: map.get($theme, pressed-label-text-color),
  115. )
  116. );
  117. @include _label-typography(
  118. (
  119. font: map.get($theme, label-text-font),
  120. size: map.get($theme, label-text-size),
  121. weight: map.get($theme, label-text-weight),
  122. tracking: map.get($theme, label-text-tracking),
  123. )
  124. );
  125. }
  126. @mixin extended-fluid($query: feature-targeting.all()) {
  127. $feat-structure: feature-targeting.create-target($query, structure);
  128. @include feature-targeting.targets($feat-structure) {
  129. width: 100%;
  130. }
  131. }
  132. @mixin extended-padding(
  133. $icon-padding,
  134. $label-padding,
  135. $focus-outline-width: null,
  136. $query: feature-targeting.all()
  137. ) {
  138. $feat-structure: feature-targeting.create-target($query, structure);
  139. @include extended-label-padding($label-padding, $query: $query);
  140. // Offsets the outer label padding by deducting it from icon padding.
  141. .mdc-fab__icon {
  142. @include feature-targeting.targets($feat-structure) {
  143. @include extended-icon-padding($icon-padding, $label-padding);
  144. }
  145. }
  146. // For Extended FAB with text label followed by icon.
  147. .mdc-fab__label + .mdc-fab__icon {
  148. @include feature-targeting.targets($feat-structure) {
  149. @include extended-icon-padding(
  150. $icon-padding,
  151. $label-padding,
  152. $is-icon-at-end: true
  153. );
  154. }
  155. }
  156. @if $focus-outline-width {
  157. @include fab-theme.focus-outline-width(
  158. $focus-outline-width,
  159. $padding: 0 $label-padding
  160. );
  161. }
  162. }
  163. @mixin extended-icon-padding(
  164. $icon-padding,
  165. $label-padding,
  166. $is-icon-at-end: false
  167. ) {
  168. $start: 'calc(icon - label)';
  169. $end: $icon-padding;
  170. @if $is-icon-at-end {
  171. $start: $icon-padding;
  172. $end: 'calc(icon - label)';
  173. }
  174. @include rtl.reflexive-property(
  175. margin,
  176. $start,
  177. $end,
  178. $replace: (icon: $icon-padding, label: $label-padding)
  179. );
  180. }
  181. @mixin extended-label-padding($label-padding, $query: feature-targeting.all()) {
  182. $feat-structure: feature-targeting.create-target($query, structure);
  183. @include feature-targeting.targets($feat-structure) {
  184. @include theme.property(padding-left, $label-padding, $gss: (noflip: true));
  185. @include theme.property(
  186. padding-right,
  187. $label-padding,
  188. $gss: (noflip: true)
  189. );
  190. }
  191. }
  192. @mixin extended-shape-radius(
  193. $radius,
  194. $rtl-reflexive: false,
  195. $query: feature-targeting.all()
  196. ) {
  197. // Extended FABs _do_ need a $component-height since they are not circular.
  198. // Percentage radii must be resolved.
  199. @include shape-mixins.radius(
  200. $radius,
  201. $rtl-reflexive,
  202. $component-height: $extended-height,
  203. $query: $query
  204. );
  205. #{fab-theme.$ripple-target} {
  206. @include shape-mixins.radius(
  207. $radius,
  208. $rtl-reflexive,
  209. $component-height: $extended-height,
  210. $query: $query
  211. );
  212. }
  213. }
  214. @mixin _label-color($color-or-map) {
  215. &:not(:disabled) {
  216. @include _set-label-color(state.get-default-state($color-or-map));
  217. &:hover {
  218. @include _set-label-color(state.get-hover-state($color-or-map));
  219. }
  220. &:focus {
  221. @include _set-label-color(state.get-focus-state($color-or-map));
  222. }
  223. &:active {
  224. @include _set-label-color(state.get-pressed-state($color-or-map));
  225. }
  226. }
  227. &:disabled {
  228. @include _set-label-color(state.get-disabled-state($color-or-map));
  229. }
  230. }
  231. @mixin _set-label-color($color) {
  232. .mdc-fab__label {
  233. @include theme.property(color, $color);
  234. }
  235. }
  236. @mixin _label-typography($typography-map) {
  237. @include theme.property(font-family, map.get($typography-map, font));
  238. @include theme.property(font-size, map.get($typography-map, size));
  239. @include theme.property(font-weight, map.get($typography-map, weight));
  240. @include theme.property(letter-spacing, map.get($typography-map, tracking));
  241. }