Yoshie Muranaka | c86ce3c | 2019-06-05 12:30:30 -0500 | [diff] [blame] | 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 | */ |
| 11 | window.angular && ((angular) => { |
| 12 | 'use-strict'; |
| 13 | |
| 14 | angular.module('app.common.directives').directive('icon', () => { |
| 15 | return { |
Yoshie Muranaka | bb68879 | 2019-08-12 09:31:52 -0500 | [diff] [blame] | 16 | restrict: 'E', |
| 17 | link: (scope, element, attrs) => { |
| 18 | const file = attrs.file || attrs.ngFile; |
Yoshie Muranaka | c86ce3c | 2019-06-05 12:30:30 -0500 | [diff] [blame] | 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 | } |
Yoshie Muranaka | bb68879 | 2019-08-12 09:31:52 -0500 | [diff] [blame] | 27 | }; |
Yoshie Muranaka | c86ce3c | 2019-06-05 12:30:30 -0500 | [diff] [blame] | 28 | }) |
| 29 | })(window.angular); |