blob: 5554fddd89cb1d2a07211aa7c617a9ba7e3bc032 [file] [log] [blame]
Yoshie Muranakac86ce3c2019-06-05 12:30:30 -05001/**
2 * Directive to inline an svg icon
3 *
4 * To use–add an <icon> directive with a file attribute with
5 * a value that corresponds to the desired svg file to inline
6 * from the icons directory.
7 *
8 * Example: <icon file="icon-export.svg"></icon>
9 *
10 */
11window.angular && ((angular) => {
12 'use-strict';
13
14 angular.module('app.common.directives').directive('icon', () => {
15 return {
16 restrict: 'E', link: (scope, element, attrs) => {
17 const file = attrs.file;
18 if (file === undefined) {
19 console.log('File name not provided for <icon> directive.')
20 return;
21 }
22 const svg = require(`../../assets/icons/${file}`);
23 element.html(svg);
24 element.addClass('icon');
25 }
26 }
27 })
28})(window.angular);