_icon-button.scss 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // Copyright 2021 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/dom/dom';
  25. @use '@material/feature-targeting/feature-targeting';
  26. @use '@material/focus-ring/focus-ring';
  27. @use '@material/ripple/ripple';
  28. @use '@material/ripple/ripple-theme';
  29. @use '@material/touch-target/mixins' as touch-target-mixins;
  30. @use './icon-button-theme';
  31. @mixin core-styles($query: feature-targeting.all()) {
  32. @include without-ripple($query);
  33. @include ripple($query);
  34. }
  35. @mixin static-styles($query: feature-targeting.all()) {
  36. $feat-structure: feature-targeting.create-target($query, structure);
  37. // postcss-bem-linter: define icon-button
  38. .mdc-icon-button {
  39. @include feature-targeting.targets($feat-structure) {
  40. display: inline-block;
  41. position: relative;
  42. box-sizing: border-box;
  43. border: none;
  44. outline: none;
  45. background-color: transparent;
  46. fill: currentColor;
  47. color: inherit;
  48. text-decoration: none;
  49. cursor: pointer;
  50. user-select: none;
  51. z-index: 0; // Added to render above the container in IE11 tests.
  52. overflow: visible; // Added to fix IE11 touch target tests.
  53. }
  54. .mdc-icon-button__touch {
  55. @include touch-target-mixins.touch-target(
  56. $set-width: true,
  57. $query: $query
  58. );
  59. }
  60. @include ripple-theme.focus {
  61. .mdc-icon-button__focus-ring {
  62. @include dom.forced-colors-mode($exclude-ie11: true) {
  63. @include feature-targeting.targets($feat-structure) {
  64. display: block;
  65. }
  66. }
  67. }
  68. }
  69. @include if-disabled_ {
  70. @include feature-targeting.targets($feat-structure) {
  71. cursor: default;
  72. pointer-events: none;
  73. }
  74. }
  75. &[hidden] {
  76. @include feature-targeting.targets($feat-structure) {
  77. display: none;
  78. }
  79. }
  80. }
  81. .mdc-icon-button--display-flex {
  82. @include feature-targeting.targets($feat-structure) {
  83. align-items: center;
  84. display: inline-flex;
  85. justify-content: center;
  86. }
  87. }
  88. .mdc-icon-button__focus-ring {
  89. @include focus-ring.focus-ring(
  90. $query: $query,
  91. $container-outer-padding-vertical: 0,
  92. $container-outer-padding-horizontal: 0
  93. );
  94. @include feature-targeting.targets($feat-structure) {
  95. display: none;
  96. }
  97. }
  98. .mdc-icon-button__icon {
  99. @include feature-targeting.targets($feat-structure) {
  100. display: inline-block;
  101. }
  102. &.mdc-icon-button__icon--on {
  103. @include feature-targeting.targets($feat-structure) {
  104. display: none;
  105. }
  106. }
  107. }
  108. .mdc-icon-button--on {
  109. .mdc-icon-button__icon {
  110. @include feature-targeting.targets($feat-structure) {
  111. display: none;
  112. }
  113. &.mdc-icon-button__icon--on {
  114. @include feature-targeting.targets($feat-structure) {
  115. display: inline-block;
  116. }
  117. }
  118. }
  119. }
  120. // postcss-bem-linter: end
  121. .mdc-icon-button__link {
  122. @include feature-targeting.targets($feat-structure) {
  123. height: 100%;
  124. left: 0;
  125. outline: none;
  126. position: absolute;
  127. top: 0;
  128. width: 100%;
  129. }
  130. }
  131. }
  132. @mixin without-ripple($query: feature-targeting.all()) {
  133. $feat-structure: feature-targeting.create-target($query, structure);
  134. .mdc-icon-button {
  135. @include feature-targeting.targets($feat-structure) {
  136. font-size: icon-button-theme.$icon-size;
  137. }
  138. @include icon-button-theme.density(0, $query: $query);
  139. @include icon-button-theme.disabled-ink-color(
  140. text-disabled-on-light,
  141. $query: $query
  142. );
  143. svg,
  144. img {
  145. @include feature-targeting.targets($feat-structure) {
  146. width: icon-button-theme.$icon-size;
  147. height: icon-button-theme.$icon-size;
  148. }
  149. }
  150. }
  151. @include static-styles($query: $query);
  152. }
  153. @mixin ripple($query: feature-targeting.all()) {
  154. @include ripple.common($query); // COPYBARA_COMMENT_THIS_LINE
  155. .mdc-icon-button {
  156. @include ripple.surface(
  157. $query: $query,
  158. $ripple-target: icon-button-theme.$ripple-target
  159. );
  160. @include ripple.radius-unbounded(
  161. $query: $query,
  162. $ripple-target: icon-button-theme.$ripple-target
  163. );
  164. @include ripple-theme.states(
  165. $query: $query,
  166. $ripple-target: icon-button-theme.$ripple-target
  167. );
  168. &:disabled {
  169. @include ripple-theme.states-opacities(
  170. (
  171. hover: 0,
  172. focus: 0,
  173. press: 0,
  174. ),
  175. $ripple-target: icon-button-theme.$ripple-target,
  176. $query: $query
  177. );
  178. }
  179. .mdc-icon-button__ripple {
  180. $feat-structure: feature-targeting.create-target($query, structure);
  181. @include feature-targeting.targets($feat-structure) {
  182. height: 100%;
  183. left: 0px;
  184. pointer-events: none;
  185. position: absolute;
  186. top: 0px;
  187. width: 100%;
  188. z-index: -1;
  189. }
  190. }
  191. }
  192. }
  193. ///
  194. /// Helps style the icon button in its disabled state.
  195. /// @access private
  196. ///
  197. @mixin if-disabled_ {
  198. &:disabled {
  199. @content;
  200. }
  201. }