1/**
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',
17      link: (scope, element, attrs) => {
18        const file = attrs.file || attrs.ngFile;
19        if (file === undefined) {
20          console.log('File name not provided for <icon> directive.')
21          return;
22        }
23        const svg = require(`../../assets/icons/${file}`);
24        element.html(svg);
25        element.addClass('icon');
26      }
27    };
28  })
29})(window.angular);