1
+ /* eslint-disable max-len */
1
2
import { html , PolymerElement } from '@polymer/polymer/polymer-element' ;
2
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin' ;
3
- import { ElementMixin } from '@vaadin/vaadin-element-mixin' ;
4
3
5
- class VcfAvatarItem extends ElementMixin ( ThemableMixin ( PolymerElement ) ) {
4
+ class VcfAvatarItem extends PolymerElement {
6
5
static get template ( ) {
7
6
return html `
8
7
< style >
9
8
: host {
9
+ dis play: inline-flex;
10
+ align- items: center;
11
+ justify- content: center;
12
+ width: var(--lumo-size-s );
13
+ height: var(- - lumo- size-s);
14
+ bor der- radius: 50%;
15
+ overflow: hidden;
16
+ background- color : var(- - lumo- primary- color );
17
+ color : var(- - lumo- primary- contrast- color );
18
+ font- size: 50px;
19
+ font- weight: 500;
20
+ text- transfor m: uppercase;
21
+ vertical- align: middle;
22
+ line-height: 1;
23
+ }
24
+
25
+ ::slotted (img ) {
26
+ max-width : 100% ;
27
+ }
28
+
29
+ svg {
10
30
display : block;
11
31
}
32
+
33
+ .abbr {
34
+ font : inherit;
35
+ fill : currentColor;
36
+ width : 90% ;
37
+ height : 90% ;
38
+ padding : 5% ;
39
+ }
40
+
41
+ .icon {
42
+ fill : none;
43
+ stroke : currentColor;
44
+ width : 60% ;
45
+ height : 60% ;
46
+ padding : 20% ;
47
+ }
48
+
49
+ : host ([name ]) .icon {
50
+ display : none;
51
+ }
52
+
53
+ : host (: not ([name ])) .abbr {
54
+ display : none;
55
+ }
12
56
</ style >
57
+ < slot >
58
+ < svg viewBox ="-50 -50 100 100 " preserveAspectRatio ="xMidYMid meet " class ="abbr ">
59
+ < text dy ="0.3em " text-anchor ="middle "> </ text >
60
+ </ svg >
61
+ < svg viewBox ="0 0 32 32 " class ="icon ">
62
+ < path
63
+ d ="M26.6666 28V25.3333C26.6666 23.9188 26.1047 22.5623 25.1045 21.5621C24.1044 20.5619 22.7478 20 21.3333 20H10.6666C9.25216 20 7.8956 20.5619 6.89541 21.5621C5.89522 22.5623 5.33331 23.9188 5.33331 25.3333V28 "
64
+ stroke-width ="3 "
65
+ stroke-linecap ="round "
66
+ stroke-linejoin ="round "
67
+ />
68
+ < path
69
+ d ="M16 14.6667C18.9455 14.6667 21.3334 12.2789 21.3334 9.33333C21.3334 6.38781 18.9455 4 16 4C13.0545 4 10.6667 6.38781 10.6667 9.33333C10.6667 12.2789 13.0545 14.6667 16 14.6667Z "
70
+ stroke-width ="3 "
71
+ stroke-linecap ="round "
72
+ stroke-linejoin ="round "
73
+ />
74
+ </ svg >
75
+ </ slot >
13
76
` ;
14
77
}
15
78
@@ -22,11 +85,33 @@ class VcfAvatarItem extends ElementMixin(ThemableMixin(PolymerElement)) {
22
85
}
23
86
24
87
static get properties ( ) {
25
- return { } ;
88
+ return {
89
+ name : {
90
+ type : String ,
91
+ observer : 'nameChanged' ,
92
+ reflectToAttribute : true
93
+ } ,
94
+ abbr : {
95
+ type : String ,
96
+ observer : 'nameChanged'
97
+ }
98
+ } ;
99
+ }
100
+
101
+ nameChanged ( ) {
102
+ if ( this . abbr || this . name ) {
103
+ this . shadowRoot . querySelector ( 'svg text' ) . textContent = this . _getAbbr ( this . name ) ;
104
+ }
105
+
106
+ if ( this . name ) {
107
+ this . setAttribute ( 'title' , this . name ) ;
108
+ } else {
109
+ this . removeAttribute ( 'title' ) ;
110
+ }
26
111
}
27
112
28
- connectedCallback ( ) {
29
- super . connectedCallback ( ) ;
113
+ _getAbbr ( name ) {
114
+ return this . abbr || name . match ( / \b \S / g ) . join ( '' ) ;
30
115
}
31
116
}
32
117
@@ -35,6 +120,7 @@ customElements.define(VcfAvatarItem.is, VcfAvatarItem);
35
120
/**
36
121
* @namespace Vaadin
37
122
*/
123
+ window . Vaadin = window . Vaadin || { } ;
38
124
window . Vaadin . VcfAvatarItem = VcfAvatarItem ;
39
125
40
126
if ( window . Vaadin . runIfDevelopmentMode ) {
0 commit comments