blob: bee615082c743b10621d5aec43538eb309646058 [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 {
Yoshie Muranakabb688792019-08-12 09:31:52 -050016 restrict: 'E',
17 link: (scope, element, attrs) => {
18 const file = attrs.file || attrs.ngFile;
Yoshie Muranakac86ce3c2019-06-05 12:30:30 -050019 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 }
Yoshie Muranakabb688792019-08-12 09:31:52 -050027 };
Yoshie Muranakac86ce3c2019-06-05 12:30:30 -050028 })
29})(window.angular);