1
1
import { withPluginApi } from " discourse/lib/plugin-api" ;
2
- import { iconNode } from "discourse-common/lib/icon-library " ;
2
+ import icon from " discourse-common/helpers/d-icon " ;
3
3
import { dasherize } from " @ember/string" ;
4
4
import isValidUrl from " ../lib/isValidUrl" ;
5
- import { h } from "virtual-dom" ;
6
5
7
- function buildIcon ( icon ) {
8
- if ( isValidUrl ( icon ) ) {
9
- return h (
10
- "img" ,
11
- {
12
- attributes : {
13
- src : icon ,
14
- } ,
15
- } ,
16
- ""
17
- ) ;
6
+ function buildIcon (iconNameOrImageUrl , title ) {
7
+ if (isValidUrl (iconNameOrImageUrl)) {
8
+ return <template >
9
+ <img src =" {{iconNameOrImageUrl }} " aria-hidden =" true" />
10
+ <span class =" sr-only" >{{title }} </span >
11
+ </template >
18
12
} else {
19
- return iconNode ( icon . toLowerCase ( ) ) ;
13
+ return < template > {{ icon iconNameOrImageUrl label = title }} </ template >
20
14
}
21
15
}
22
16
@@ -30,32 +24,31 @@ export default {
30
24
splitLinks .forEach ((link , index , links ) => {
31
25
const fragments = link .split (" ," ).map ((fragment ) => fragment .trim ());
32
26
const title = fragments[0 ];
33
- const icon = buildIcon ( fragments [ 1 ] ) ;
27
+ const iconTemplate = buildIcon (fragments[1 ], title );
34
28
const href = fragments[2 ];
35
29
const className = ` header-icon-${ dasherize (fragments[0 ])} ` ;
36
30
const viewClass = fragments[3 ].toLowerCase ();
37
31
const target = fragments[4 ].toLowerCase () === " blank" ? " _blank" : " " ;
38
32
const rel = target ? " noopener" : " " ;
39
33
const isLastLink =
40
- link === links [ links . length - 1 ] ? ".last-custom-icon" : "" ;
41
- const selector = `li.custom-header-icon-link.${ className } .${ viewClass } ${ isLastLink } ` ;
34
+ link === links[links .length - 1 ] ? " last-custom-icon" : " " ;
42
35
43
- api . decorateWidget ( "header-icons:before" , ( helper ) => {
44
- return helper . h ( selector , [
45
- helper . h (
46
- "a.icon.btn-flat" ,
47
- {
48
- href ,
49
- title ,
50
- target ,
51
- attributes : {
52
- rel ,
53
- } ,
54
- } ,
55
- icon
56
- ) ,
57
- ] ) ;
58
- } ) ;
36
+ const iconComponent = < template >
37
+ < li class = " custom-header-icon-link {{ className }} {{ viewClass }} {{ isLastLink }} " >
38
+ < a class = " icon btn-flat "
39
+ href = {{ href }}
40
+ title = {{ title }}
41
+ target = {{ target }}
42
+ rel = {{ rel }}
43
+ >
44
+ {{ iconTemplate }}
45
+ </ a >
46
+ </ li >
47
+ </ template >
48
+
49
+ const beforeIcon = [ ' chat ' , ' search ' , ' hamburger ' , ' user-menu ' ]
50
+
51
+ api . headerIcons . add (title, iconComponent, { before : beforeIcon })
59
52
});
60
53
} catch (error) {
61
54
// eslint-disable-next-line no-console
0 commit comments