1
1
import { defineElement } from '@umbraco-ui/uui-base/lib/registration' ;
2
2
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils' ;
3
+ import { ifDefined } from 'lit/directives/if-defined.js' ;
3
4
import { UUIRefElement } from '@umbraco-ui/uui-ref/lib' ;
4
- import { css , html } from 'lit' ;
5
+ import { css , html , nothing } from 'lit' ;
5
6
import { property , state } from 'lit/decorators.js' ;
6
7
7
8
/**
@@ -36,6 +37,24 @@ export class UUIRefNodeElement extends UUIRefElement {
36
37
@property ( { type : String } )
37
38
detail = '' ;
38
39
40
+ /**
41
+ * Set an href, this will turns the name of the card into an anchor tag.
42
+ * @type {string }
43
+ * @attr
44
+ * @default undefined
45
+ */
46
+ @property ( { type : String } )
47
+ public href ?: string ;
48
+
49
+ /**
50
+ * Set an anchor tag target, only used when using href.
51
+ * @type {string }
52
+ * @attr
53
+ * @default undefined
54
+ */
55
+ @property ( { type : String } )
56
+ public target ?: '_blank' | '_parent' | '_self' | '_top' ;
57
+
39
58
@state ( )
40
59
private _iconSlotHasContent = false ;
41
60
@@ -48,7 +67,7 @@ export class UUIRefNodeElement extends UUIRefElement {
48
67
demandCustomElement ( this , 'uui-icon' ) ;
49
68
}
50
69
51
- private _onSlotIconChange ( event : Event ) {
70
+ #onSlotIconChange ( event : Event ) {
52
71
this . _iconSlotHasContent =
53
72
( event . target as HTMLSlotElement ) . assignedNodes ( { flatten : true } )
54
73
. length > 0 ;
@@ -60,11 +79,37 @@ export class UUIRefNodeElement extends UUIRefElement {
60
79
> </ small> ` ;
61
80
}
62
81
63
- private _renderFallbackIcon ( ) {
82
+ #renderFallbackIcon ( ) {
64
83
return html `<uui- icon .svg = "${ this . fallbackIcon } " > </ uui- icon> ` ;
65
84
}
66
85
67
- public render ( ) {
86
+ #renderContent( ) {
87
+ return html `
88
+ <span id= "icon" >
89
+ <slot name= "icon" @slotchange = ${ this . #onSlotIconChange} > </ slot>
90
+ ${ this . _iconSlotHasContent === false ? this . #renderFallbackIcon( ) : '' }
91
+ </ span>
92
+ <div id= "info" >
93
+ <div id= "name" > ${ this . name } </ div>
94
+ ${ this . renderDetail ( ) }
95
+ </ div>
96
+ ` ;
97
+ }
98
+
99
+ #renderLink( ) {
100
+ return html `<a
101
+ id= "open-part"
102
+ tabindex = ${ this . disabled ? ( nothing as any ) : '0' }
103
+ href= ${ ifDefined ( ! this . disabled ? this . href : undefined ) }
104
+ target= ${ ifDefined ( this . target || undefined ) }
105
+ rel= ${ ifDefined (
106
+ this . target === '_blank' ? 'noopener noreferrer' : undefined
107
+ ) } >
108
+ ${ this . #renderContent( ) }
109
+ </ a> ` ;
110
+ }
111
+
112
+ #renderButton( ) {
68
113
return html `
69
114
<butto n
70
115
type= "button"
@@ -73,17 +118,14 @@ export class UUIRefNodeElement extends UUIRefElement {
73
118
@click = ${ this . handleOpenClick }
74
119
@keydown = ${ this . handleOpenKeydown }
75
120
?dis abled= ${ this . disabled } >
76
- <span id= "icon" >
77
- <slot name= "icon" @slotchange = ${ this . _onSlotIconChange } > </ slot>
78
- ${ this . _iconSlotHasContent === false
79
- ? this . _renderFallbackIcon ( )
80
- : '' }
81
- </ span>
82
- <div id= "info" >
83
- <div id= "name" > ${ this . name } </ div>
84
- ${ this . renderDetail ( ) }
85
- </ div>
121
+ ${ this . #renderContent( ) }
86
122
</ butto n>
123
+ ` ;
124
+ }
125
+
126
+ public render ( ) {
127
+ return html `
128
+ ${ this . href ? this . #renderLink( ) : this . #renderButton( ) }
87
129
<!- - Select bor der must be right after # open-part -- >
88
130
<div id= "select-border" > </ div>
89
131
@@ -102,7 +144,10 @@ export class UUIRefNodeElement extends UUIRefElement {
102
144
}
103
145
104
146
# open-part {
147
+ text-decoration : none;
148
+ color : inherit;
105
149
align-self : stretch;
150
+ line-height : normal;
106
151
107
152
display : flex;
108
153
position : relative;
0 commit comments