_button-base.scss 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. //
  2. // Copyright 2020 Google Inc.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. // stylelint-disable selector-class-pattern --
  23. // Selector '.mdc-*' should only be used in this project.
  24. @use '@material/elevation/elevation';
  25. @use '@material/elevation/elevation-theme';
  26. @use '@material/feature-targeting/feature-targeting';
  27. @use '@material/ripple/ripple-theme';
  28. @use '@material/rtl/rtl';
  29. @use '@material/dom/dom';
  30. @use '@material/touch-target/touch-target';
  31. @use '@material/focus-ring/focus-ring';
  32. @use '@material/typography/typography';
  33. @use './button-shared-theme';
  34. @mixin static-styles($query: feature-targeting.all()) {
  35. @include _static-styles-base($query: $query);
  36. @include _typography-styles($query: $query);
  37. }
  38. @mixin _static-styles-base($query: feature-targeting.all()) {
  39. $feat-structure: feature-targeting.create-target($query, structure);
  40. @include touch-target.wrapper($query); // COPYBARA_COMMENT_THIS_LINE
  41. // prettier-ignore
  42. @include elevation.overlay-common($query); // COPYBARA_COMMENT_THIS_LINE
  43. // postcss-bem-linter: define button
  44. .mdc-button {
  45. @include _root-structure($query);
  46. // The icon CSS class overrides styles defined in the .material-icons CSS
  47. // class, which is loaded separately so the order of CSS definitions is not
  48. // guaranteed. Therefore, increase specifity by nesting this class to ensure
  49. // overrides apply.
  50. .mdc-button__icon {
  51. @include feature-targeting.targets($feat-structure) {
  52. @include _icon-structure;
  53. }
  54. }
  55. .mdc-button__progress-indicator {
  56. @include feature-targeting.targets($feat-structure) {
  57. font-size: 0;
  58. position: absolute;
  59. @include rtl.ignore-next-line();
  60. transform: translate(-50%, -50%);
  61. top: 50%;
  62. @include rtl.ignore-next-line();
  63. left: 50%;
  64. line-height: initial;
  65. }
  66. }
  67. .mdc-button__label {
  68. @include feature-targeting.targets($feat-structure) {
  69. // Necessary such that label is stacked on top of ripple
  70. // (since ripple is a positioned element, non-positioned elements
  71. // appear under it).
  72. position: relative;
  73. }
  74. }
  75. .mdc-button__focus-ring {
  76. @include focus-ring.focus-ring($query: $query);
  77. @include feature-targeting.targets($feat-structure) {
  78. display: none;
  79. }
  80. }
  81. @include ripple-theme.focus {
  82. .mdc-button__focus-ring {
  83. @include dom.forced-colors-mode($exclude-ie11: true) {
  84. @include feature-targeting.targets($feat-structure) {
  85. display: block;
  86. }
  87. }
  88. }
  89. }
  90. .mdc-button__touch {
  91. @include touch-target.touch-target($query: $query);
  92. }
  93. }
  94. .mdc-button__label + .mdc-button__icon {
  95. @include feature-targeting.targets($feat-structure) {
  96. @include icon-trailing;
  97. }
  98. }
  99. svg.mdc-button__icon {
  100. @include feature-targeting.targets($feat-structure) {
  101. @include icon-svg;
  102. }
  103. }
  104. .mdc-button--touch {
  105. // Touch target doesn't change with height. It simply gets removed if
  106. // density (height) changes. Therefore, it is a static style.
  107. @include touch-target.margin(
  108. $component-height: button-shared-theme.$height,
  109. $query: $query
  110. );
  111. }
  112. // postcss-bem-linter: end
  113. }
  114. @mixin _typography-styles($query) {
  115. .mdc-button {
  116. // Exclude properties declared in theme styles.
  117. @include typography.typography(
  118. button,
  119. $exclude-props: (
  120. font-size,
  121. line-height,
  122. font-weight,
  123. letter-spacing,
  124. text-transform
  125. ),
  126. $query: $query
  127. );
  128. }
  129. }
  130. /// @deprecated Contains typography declarations now part of theme-styles.
  131. @mixin deprecated-static-styles-without-ripple(
  132. $query: feature-targeting.all()
  133. ) {
  134. @include _deprecated-typography-styles($query: $query);
  135. @include _static-styles-base($query: $query);
  136. }
  137. @mixin _deprecated-typography-styles($query) {
  138. .mdc-button {
  139. @include typography.typography(button, $query);
  140. }
  141. }
  142. @mixin deprecated-base($query) {
  143. @include base($query);
  144. }
  145. @mixin base($query) {
  146. @include typography.typography(button, $query);
  147. @include _root-structure($query: $query);
  148. }
  149. @mixin _root-structure($query) {
  150. $feat-structure: feature-targeting.create-target($query, structure);
  151. @include elevation-theme.overlay-surface-position($query: $query);
  152. @include elevation-theme.overlay-dimensions(100%, $query: $query);
  153. @include feature-targeting.targets($feat-structure) {
  154. display: inline-flex;
  155. // position: relative; already set in mdc-elevation-overlay-surface-position
  156. align-items: center;
  157. justify-content: center;
  158. box-sizing: border-box;
  159. min-width: 64px;
  160. border: none;
  161. outline: none;
  162. /* @alternate */
  163. line-height: inherit;
  164. user-select: none;
  165. -webkit-appearance: none;
  166. // Even though `visible` is the default, IE 11 computes the property as
  167. // `hidden` in some cases, unless it's explicitly defined here.
  168. overflow: visible;
  169. vertical-align: middle;
  170. background: transparent;
  171. }
  172. &::-moz-focus-inner {
  173. @include feature-targeting.targets($feat-structure) {
  174. padding: 0;
  175. border: 0;
  176. }
  177. }
  178. // postcss-bem-linter: ignore
  179. &:active {
  180. @include feature-targeting.targets($feat-structure) {
  181. outline: none;
  182. }
  183. }
  184. &:hover {
  185. @include feature-targeting.targets($feat-structure) {
  186. cursor: pointer;
  187. }
  188. }
  189. &:disabled {
  190. @include feature-targeting.targets($feat-structure) {
  191. cursor: default;
  192. pointer-events: none;
  193. }
  194. }
  195. &[hidden] {
  196. @include feature-targeting.targets($feat-structure) {
  197. display: none;
  198. }
  199. }
  200. }
  201. @mixin icon {
  202. @include _icon-structure;
  203. @include _icon-size(18px);
  204. }
  205. @mixin _icon-structure {
  206. @include rtl.reflexive-box(margin, right, 8px);
  207. display: inline-block;
  208. position: relative;
  209. vertical-align: top;
  210. }
  211. @mixin _icon-size($size-px) {
  212. $icon-size: typography.px-to-rem($size-px);
  213. font-size: $icon-size;
  214. height: $icon-size;
  215. width: $icon-size;
  216. }
  217. @mixin icon-trailing {
  218. @include rtl.reflexive-box(margin, left, 8px);
  219. }
  220. @mixin icon-svg {
  221. fill: currentColor;
  222. }
  223. @mixin icon-contained {
  224. @include rtl.reflexive-property(margin, -4px, 8px);
  225. }
  226. @mixin icon-contained-trailing {
  227. @include rtl.reflexive-property(margin, 8px, -4px);
  228. }
  229. @mixin raised-transition($query: feature-targeting.all()) {
  230. $feat-animation: feature-targeting.create-target($query, animation);
  231. @include feature-targeting.targets($feat-animation) {
  232. transition: elevation-theme.transition-value();
  233. }
  234. }
  235. /// @deprecated Private style mixin for partners; not available for public use.
  236. @mixin deprecated-icon {
  237. @include icon;
  238. }
  239. /// @deprecated Private style mixin for partners; not available for public use.
  240. @mixin deprecated-icon-trailing {
  241. @include icon-trailing;
  242. }
  243. /// @deprecated Private style mixin for partners; not available for public use.
  244. @mixin deprecated-icon-svg {
  245. @include icon-svg;
  246. }
  247. /// @deprecated Private style mixin for partners; not available for public use.
  248. @mixin deprecated-icon-contained {
  249. @include icon-contained;
  250. }
  251. /// @deprecated Private style mixin for partners; not available for public use.
  252. @mixin deprecated-icon-contained-trailing {
  253. @include icon-contained-trailing;
  254. }