_mixins.scss 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Copyright 2019 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. @use "@material/base/mixins" as base-mixins;
  23. @use "@material/feature-targeting/functions";
  24. @use "@material/feature-targeting/mixins" as feature-targeting-mixins;
  25. @use "./variables";
  26. /// Styles applied to the component's touch target wrapper element.
  27. @mixin wrapper($query: functions.all()) {
  28. $feat-structure: functions.create-target($query, structure);
  29. .mdc-touch-target-wrapper {
  30. @include feature-targeting-mixins.targets($feat-structure) {
  31. // Ensure that styles are only emitted once across all components that
  32. // have increased touch targets.
  33. @include base-mixins.emit-once("mdc-touch-target/wrapper") {
  34. // NOTE: Will change to `inline-block` in the future, but keeping as is
  35. // temporarily for backwards-compatibility.
  36. display: inline;
  37. }
  38. }
  39. }
  40. }
  41. /// Styles applied to the component's inner touch target element.
  42. /// By default, only sets the inner element height to the minimum touch target
  43. /// height ($mdc-touch-target-height).
  44. /// @param {Boolean} $set-width [false] - Sets the inner element width to the
  45. /// minimum touch target width ($mdc-touch-target-width).
  46. @mixin touch-target($set-width: false, $query: functions.all()) {
  47. $feat-structure: functions.create-target($query, structure);
  48. @include feature-targeting-mixins.targets($feat-structure) {
  49. position: absolute;
  50. top: 50%;
  51. right: 0;
  52. height: variables.$height;
  53. }
  54. @if $set-width {
  55. @include feature-targeting-mixins.targets($feat-structure) {
  56. /* @noflip */
  57. left: 50%;
  58. width: variables.$width;
  59. transform: translate(-50%, -50%);
  60. }
  61. } @else {
  62. @include feature-targeting-mixins.targets($feat-structure) {
  63. left: 0;
  64. transform: translateY(-50%);
  65. }
  66. }
  67. }
  68. /// Applies margin to the component with the increased touch target,
  69. /// to compensate for the touch target.
  70. @mixin margin($component-height, $component-width: null, $query: functions.all()) {
  71. $feat-structure: functions.create-target($query, structure);
  72. $vertical-margin-value: (variables.$height - $component-height) / 2;
  73. @include feature-targeting-mixins.targets($feat-structure) {
  74. margin-top: $vertical-margin-value;
  75. margin-bottom: $vertical-margin-value;
  76. }
  77. @if $component-width {
  78. $horizontal-margin-value: (variables.$width - $component-width) / 2;
  79. @include feature-targeting-mixins.targets($feat-structure) {
  80. margin-right: $horizontal-margin-value;
  81. margin-left: $horizontal-margin-value;
  82. }
  83. }
  84. }