diff options
Diffstat (limited to 'app/common/directives/icon-provider.js')
-rw-r--r-- | app/common/directives/icon-provider.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/common/directives/icon-provider.js b/app/common/directives/icon-provider.js new file mode 100644 index 0000000..5554fdd --- /dev/null +++ b/app/common/directives/icon-provider.js @@ -0,0 +1,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);
\ No newline at end of file |