summaryrefslogtreecommitdiffstats
path: root/app/common/directives/icon-provider.js
blob: bee615082c743b10621d5aec43538eb309646058 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
 * Directive to inline an svg icon
 *
 * To use–add an <icon> directive with a file attribute with
 * a value that corresponds to the desired svg file to inline
 * from the icons directory.
 *
 * Example: <icon file="icon-export.svg"></icon>
 *
 */
window.angular && ((angular) => {
  'use-strict';

  angular.module('app.common.directives').directive('icon', () => {
    return {
      restrict: 'E',
      link: (scope, element, attrs) => {
        const file = attrs.file || attrs.ngFile;
        if (file === undefined) {
          console.log('File name not provided for <icon> directive.')
          return;
        }
        const svg = require(`../../assets/icons/${file}`);
        element.html(svg);
        element.addClass('icon');
      }
    };
  })
})(window.angular);
OpenPOWER on IntegriCloud