//// /// @group Icons //// <% // This is a template for generating SASS for our icon font. // It generates: // - A SASS map of icon name -> codepoint // - A function for getting a codepoint from a name // - A mixin // - A BEM style class for each icon %> /* Generated by grunt-webfont */ <% // See https://css-tricks.com/snippets/css/using-font-face/#article-header-id-0 // for cross-browser font face rule %> $${ fontBaseName }-no-cache: random(999999999); /// Base path for loading font files /// Override this in your application if your path differs. /// E.g. if you want to replace it off a CDN you could change this to 'http://cdn.com/fonts/' $nice-font-base-path: '${ relativeFontPath }' !default; @font-face { font-family: "${ fontFamilyName }"; font-style: normal; font-weight: normal; src: ${ fontSrc1.replace(new RegExp(hash + "\"", "g"), "\" + $" + fontBaseName + "-no-cache").replace(/"\/fonts\//g, "$nice-font-base-path + \"") }; src: ${ fontSrc2.replace(new RegExp(hash + "\"", "g"), "\" + $" + fontBaseName + "-no-cache").replace(/"\/fonts\//g, "$nice-font-base-path + \"").replace(new RegExp(hash + "#", "g"), "\" + $" + fontBaseName + "-no-cache + \"#") }; } /// Map of icon name to codepoint. /// This map avoids the use of 'magic strings' for codepoints throught SASS code. The map is usually not used directly - use the nice-icon function/mixin instead. /// Please note - the values for codepoints are not fixed and may change each time the font is re-generated. <% _.forEach(glyphs, function(glyph, index) { %>/// @prop {string} ${ glyph } [${ codepoints[index] }] - <% }); %> $nice-icons: ( <% _.forEach(glyphs, function(glyph, index) { %>${ glyph }: "${ codepoints[index] }"<% if (index < glyphs.length - 1) { %>, <% } %><% }); %> ) !default; /// Base styles required for an icon including font family etc /// @example /// .test { /// @icnlude icon-base; /// /// &:before { /// content: nice-icon(search); /// } /// } @mixin icon-base { display: inline-block; font-family: '${ fontFamilyName }'; font-style: normal; font-weight: normal; line-height: 1; speak: none; text-decoration: inherit; text-rendering: auto; text-transform: none; vertical-align: baseline; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } /// Applies the required styles for the given icon /// including the codepoint. /// @param {string} $icon - The name of the icon /// @throws Error when the given icon doesn't exist /// @example /// .search-icon { /// @include nice-icon(search); /// } @mixin nice-icon($icon) { @if map-has-key($nice-icons, $icon) { @include icon-base; content: nice-icon($icon); } @else { @error 'Icons with name #{ $icon } could not be found in the $nice-icons map'; } } /// Function for getting the codepoint for a given icon, for use /// within the `content` property of psuedo elements. /// @example /// .test { /// @icnlude icon-base; /// /// &:before { /// content: nice-icon(search); /// } /// } @function nice-icon($icon) { @if map-has-key($nice-icons, $icon) { $icon-code: map-get($nice-icons, $icon); @return unquote('\'\\#{ $icon-code }\''); } @else { @error 'Icons with name #{ $icon } could not be found in the $nice-icons map'; } } /// Class for rendering an icon. /// Use with a named modifier for an icon. /// @example /// .icon { @include icon-base; &:before { display: block; } @each $icon, $code in $nice-icons { &--#{ $icon }:before { content: nice-icon($icon); } } }