font-icon.scss 6.3 KB

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