summaryrefslogtreecommitdiffstats
path: root/app/common/directives/icon-provider.js
blob: 5554fddd89cb1d2a07211aa7c617a9ba7e3bc032 (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
/**
 * 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;
        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