font-icon.scss 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * @class Global_CSS
  3. */
  4. @import 'font-icon.js';
  5. /**
  6. * Applies a font icon to an element.
  7. *
  8. * @param {list/string} $glyph
  9. * A unicode character to use as the icon, or a list specifying the character to use
  10. * followed by font-size, font-family, and degrees of rotation (90, 180, or 270).
  11. * All parameters in the list are optional except for glyph. For example, each of the
  12. * following is valid:
  13. *
  14. * Use the letter "A" as the icon, inherit the font-size from the parent element,
  15. * and use the default font-family specified by {@link Global_CSS#$font-icon-font-family}.
  16. *
  17. * .my-icon {
  18. * @include font-icon('\0041');
  19. * }
  20. *
  21. * Use the letter "A" as the icon with a font-size of 16px, and the default font-family
  22. *
  23. * .my-icon {
  24. * @include font-icon('\0041' 16px);
  25. * }
  26. *
  27. * Use the letter "A" as the icon, inherit font-size, and use FontAwesome as the font-family
  28. *
  29. * .my-icon {
  30. * @include font-icon('\0041' FontAwesome);
  31. * }
  32. *
  33. * Use the letter "A" as the icon, inherit font-size, use the default font-family, and rotate
  34. * the icon 90 degrees clockwise.
  35. *
  36. * .my-icon {
  37. * @include font-icon('\0041' 90);
  38. * }
  39. *
  40. * Use the letter "A" as the icon with a 16px font-size, and a FontAwesome as the font-family.
  41. *
  42. * .my-icon {
  43. * @include font-icon('\0041' 16px FontAwesome);
  44. * }
  45. *
  46. * Use the letter "A" as the icon with a 16px font-size, default font-family, and rotate
  47. * the icon 90 degrees clockwise.
  48. *
  49. * .my-icon {
  50. * @include font-icon('\0041' 16px 90);
  51. * }
  52. *
  53. * Use the letter "A" as the icon, inherit the font-size, use FontAwesome as the font-family,
  54. * and rotate the icon 90 degrees clockwise.
  55. *
  56. * .my-icon {
  57. * @include font-icon('\0041' FontAwesome 90);
  58. * }
  59. *
  60. * Use the letter "A" as the icon with a font-size of 16px, use FontAwesome as the font-family,
  61. * and rotate the icon 90 degrees clockwise.
  62. *
  63. * .my-icon {
  64. * @include font-icon('\0041' 16px FontAwesome 90);
  65. * }
  66. *
  67. * NOTE: Only numeric values with units are accepted for font-size, e.g. `16px` or `2em`.
  68. *
  69. * @param {boolean/string} [$pseudo=true]
  70. * By default this mixin generates a "before" pseudo element ruleset to contain the icon.
  71. * Set this parameter to "after" to use an after pseudo element. Set to `false` if you are
  72. * invoking the font-icon() mixin from within a pseudo element ruleset.
  73. *
  74. * @param {number} [$line-height=1]
  75. * Optional line-height to apply to the icon.
  76. * Pass `null` to avoid setting line-height and inherit from parent element.
  77. *
  78. * @param {color} $color
  79. * Optional color for the glyph.
  80. *
  81. * @param {boolean} [$style-pseudo=false]
  82. * By default, font and color styles are placed on the icon-containing element, not the
  83. * pseudo. This allows for easier customization of font-icons by users since many
  84. * font-icon generators also place the font styles on the containing element.
  85. * Set this to `true` to set font and color styles on the pseudo element instead. This
  86. * is necessary in cases where the icon-containing element is not exclusively dedicated
  87. * to containing the icon and may contain other text as well, for example, grid headers
  88. * and grid grouping headers.
  89. *
  90. * @private
  91. * @deprecated 6.5.0 This mixin is deprecated.
  92. */
  93. @mixin font-icon(
  94. $glyph,
  95. $pseudo: true,
  96. $line-height: 1,
  97. $color: null,
  98. $style-pseudo: false
  99. ) {
  100. $args: parseFontIconArgs($glyph);
  101. $char: nth($args, 1);
  102. $font-size: nth($args, 2);
  103. $font-family: nth($args, 3);
  104. @if $font-family == null {
  105. $font-family: $font-icon-font-family;
  106. }
  107. $angle: nth($args, 4);
  108. $rotation: null;
  109. $rotation-origin: 50% 50%;
  110. $ie-rotation: null;
  111. @if $angle != null {
  112. $rotation: rotate(#{$angle}deg);
  113. @if $angle == 90 {
  114. $ie-rotation: 1;
  115. } @else if $angle == 180 {
  116. $ie-rotation: 2;
  117. } @else if $angle == 270 {
  118. $ie-rotation: 3;
  119. }
  120. }
  121. @if $char != null {
  122. @if $pseudo == false {
  123. @include font-icon-pseudo-content($char, $rotation, $rotation-origin);
  124. @include font-icon-style($font-size, $line-height, $font-family, $color);
  125. } @else {
  126. @if not $style-pseudo {
  127. @include font-icon-style($font-size, $line-height, $font-family, $color);
  128. }
  129. @if $pseudo == before or $pseudo == true {
  130. &:before {
  131. @include font-icon-pseudo-content($char, $rotation, $rotation-origin);
  132. @if $style-pseudo {
  133. @include font-icon-style($font-size, $line-height, $font-family, $color);
  134. }
  135. }
  136. } @else if $pseudo == after {
  137. &:after {
  138. @include font-icon-pseudo-content($char, $rotation, $rotation-origin);
  139. @if $style-pseudo {
  140. @include font-icon-style($font-size, $line-height, $font-family, $color);
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. @mixin font-icon-style($font-size, $line-height, $font-family, $color) {
  148. @if $font-size != null {
  149. @if $line-height != null {
  150. font: #{$font-size}/#{$line-height} $font-family;
  151. } @else {
  152. // use separate properties for font-size and font-family so that line-height
  153. // will be preserved from prior font declarations
  154. font-size: $font-size;
  155. font-family: $font-family;
  156. }
  157. } @else {
  158. font-family: $font-family;
  159. line-height: $line-height;
  160. }
  161. color: $color;
  162. }
  163. @mixin font-icon-pseudo-content($char, $rotation, $rotation-origin) {
  164. content: $char;
  165. font-feature-settings: 'liga';
  166. @if $rotation != null {
  167. display: inline-block;
  168. -webkit-transform: $rotation;
  169. -webkit-transform-origin: $rotation-origin;
  170. transform: $rotation;
  171. transform-origin: $rotation-origin;
  172. }
  173. }