@aquera/nile-elements 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/demo/variables.css +1 -1
- package/dist/nile-avatar/nile-avatar.cjs.js +1 -1
- package/dist/nile-avatar/nile-avatar.cjs.js.map +1 -1
- package/dist/nile-avatar/nile-avatar.css.cjs.js +1 -1
- package/dist/nile-avatar/nile-avatar.css.cjs.js.map +1 -1
- package/dist/nile-avatar/nile-avatar.css.esm.js +2 -0
- package/dist/nile-avatar/nile-avatar.esm.js +25 -19
- package/dist/src/nile-avatar/nile-avatar.css.js +2 -0
- package/dist/src/nile-avatar/nile-avatar.css.js.map +1 -1
- package/dist/src/nile-avatar/nile-avatar.d.ts +10 -9
- package/dist/src/nile-avatar/nile-avatar.js +78 -61
- package/dist/src/nile-avatar/nile-avatar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-avatar/nile-avatar.css.ts +2 -0
- package/src/nile-avatar/nile-avatar.ts +79 -72
- package/vscode-html-custom-data.json +61 -42
package/package.json
CHANGED
@@ -20,6 +20,7 @@ export const styles = css`
|
|
20
20
|
font-style: normal;
|
21
21
|
font-weight: 600;
|
22
22
|
color: var(--nile-colors-white-base);
|
23
|
+
border-radius: 4px;
|
23
24
|
text-transform: uppercase;
|
24
25
|
display: flex;
|
25
26
|
flex-direction: column;
|
@@ -31,6 +32,7 @@ export const styles = css`
|
|
31
32
|
.avatar {
|
32
33
|
box-sizing: border-box;
|
33
34
|
border: 0.5px solid var(--nile-colors-neutral-500);
|
35
|
+
border-radius: 4px;
|
34
36
|
background-position: 50% 50%;
|
35
37
|
background-size: cover;
|
36
38
|
background-repeat: no-repeat;
|
@@ -10,13 +10,13 @@ import {
|
|
10
10
|
html,
|
11
11
|
CSSResultArray,
|
12
12
|
TemplateResult,
|
13
|
+
nothing,
|
13
14
|
} from 'lit';
|
14
15
|
import { customElement, state, property } from 'lit/decorators.js';
|
15
16
|
import { classMap } from 'lit/directives/class-map.js';
|
16
17
|
|
17
18
|
import { styles } from './nile-avatar.css';
|
18
19
|
import NileElement from '../internal/nile-element';
|
19
|
-
import { string } from '../nile-icon/icons/svg';
|
20
20
|
|
21
21
|
/**
|
22
22
|
* Nile icon component.
|
@@ -37,49 +37,41 @@ export class NileAvatar extends NileElement {
|
|
37
37
|
/** Gives the url to the Avatar */
|
38
38
|
@property({ type: String, reflect: true }) src = '';
|
39
39
|
|
40
|
+
/** Gives the icon to the Avatar */
|
41
|
+
@property({ type: String, reflect: true }) variant:'icon' | 'image' | 'text' = 'text';
|
42
|
+
|
43
|
+
/** Gives the icon to the Avatar */
|
44
|
+
@property({ type: String, reflect: true }) icon = 'user';
|
45
|
+
|
40
46
|
/** Gives the default Image Letters to the Avatar */
|
41
|
-
@property({ type: String, reflect: true }) name = '';
|
47
|
+
@property({ type: String, reflect: true }) name: String = '';
|
42
48
|
|
43
49
|
/** Gives the default bg color to the Avatar */
|
44
|
-
@property({ type: String, reflect: true, attribute: 'bg-color' }) bgColor =
|
45
|
-
'';
|
50
|
+
@property({ type: String, reflect: true, attribute: 'bg-color' }) bgColor = '';
|
46
51
|
|
47
52
|
/** Gives the default text color to the Avatar */
|
48
|
-
@property({ type: String, reflect: true, attribute: 'text-color' })
|
49
|
-
textColor = '#fff';
|
53
|
+
@property({ type: String, reflect: true, attribute: 'text-color' }) textColor = '#fff';
|
50
54
|
|
51
55
|
/** Gives the default border color to the Avatar */
|
52
|
-
@property({ type: String, reflect: true, attribute: 'border-color' })
|
53
|
-
borderColor = 'rgba(0, 0, 0, 0.08)';
|
56
|
+
@property({ type: String, reflect: true, attribute: 'border-color' }) borderColor = '';
|
54
57
|
|
55
58
|
/** Size of the Avatar */
|
56
|
-
@property({ reflect: true }) size:
|
57
|
-
| 'small'
|
58
|
-
| 'medium'
|
59
|
-
| 'large'
|
60
|
-
| 'extralarge'
|
61
|
-
| '2xl' = 'medium';
|
59
|
+
@property({ reflect: true }) size: | 'sm' | 'md' | 'lg' | 'xl' | '2xl' = 'md';
|
62
60
|
|
63
61
|
/** Gives a border radius of 50% to the Avatar */
|
64
|
-
@property({ type: Boolean, reflect: true }) isRounded =
|
62
|
+
@property({ type: Boolean, reflect: true }) isRounded = true;
|
63
|
+
|
64
|
+
@state() private imageError = false;
|
65
65
|
|
66
66
|
/* #endregion */
|
67
67
|
|
68
68
|
/* #region Methods */
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
* @slot This is a slot test
|
73
|
-
*/
|
74
|
-
@state() private isDefaultAvatar = true;
|
75
|
-
|
76
|
-
@state() private defaultAvatarContent = html``;
|
77
|
-
|
78
|
-
private generateInitials(name: String): string {
|
79
|
-
if (!name) {
|
70
|
+
private generateInitials(): string {
|
71
|
+
if (!this.name) {
|
80
72
|
return '';
|
81
73
|
}
|
82
|
-
const nameParts = name
|
74
|
+
const nameParts = this.name
|
83
75
|
.split(' ')
|
84
76
|
.filter(part => part.length > 0)
|
85
77
|
.map(part => part.charAt(0).toUpperCase())
|
@@ -96,13 +88,13 @@ export class NileAvatar extends NileElement {
|
|
96
88
|
|
97
89
|
private getDefaultIconSize() {
|
98
90
|
switch (this.size) {
|
99
|
-
case '
|
91
|
+
case 'sm':
|
100
92
|
return '10';
|
101
|
-
case '
|
93
|
+
case 'md':
|
102
94
|
return '16';
|
103
|
-
case '
|
95
|
+
case 'lg':
|
104
96
|
return '20';
|
105
|
-
case '
|
97
|
+
case 'xl':
|
106
98
|
return '24';
|
107
99
|
case '2xl':
|
108
100
|
return '28';
|
@@ -111,17 +103,31 @@ export class NileAvatar extends NileElement {
|
|
111
103
|
}
|
112
104
|
}
|
113
105
|
|
114
|
-
|
115
|
-
|
116
|
-
|
106
|
+
public render(): TemplateResult {
|
107
|
+
if('image'==this.variant && !this.imageError){
|
108
|
+
return this.getImageContent()
|
109
|
+
}
|
110
|
+
else{
|
111
|
+
const defaultInitials = this.generateInitials();
|
112
|
+
if('text'==this.variant && defaultInitials){
|
113
|
+
return this.getContentWrapped(html`${defaultInitials}`,defaultInitials);
|
114
|
+
}
|
115
|
+
else{
|
116
|
+
return this.getContentWrapped(this.getIconContent(),defaultInitials)
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
117
120
|
|
118
|
-
|
121
|
+
getContentWrapped(content:TemplateResult,defaultInitials:string){
|
122
|
+
const variant__code = this.generateVariantCode(defaultInitials);
|
123
|
+
return html`
|
124
|
+
<div
|
119
125
|
class=${classMap({
|
120
126
|
text__avatar: true,
|
121
|
-
avatar__small: this.size === '
|
122
|
-
avatar__medium: this.size === '
|
123
|
-
avatar__large: this.size === '
|
124
|
-
avatar__extralarge: this.size === '
|
127
|
+
avatar__small: this.size === 'sm',
|
128
|
+
avatar__medium: this.size === 'md',
|
129
|
+
avatar__large: this.size === 'lg',
|
130
|
+
avatar__extralarge: this.size === 'xl',
|
125
131
|
avatar__2xl: this.size === '2xl',
|
126
132
|
avatar__rounded: this.isRounded,
|
127
133
|
variant__orange: variant__code === 0 && !this.bgColor,
|
@@ -130,44 +136,45 @@ export class NileAvatar extends NileElement {
|
|
130
136
|
variant__light_blue: variant__code === 3 && !this.bgColor,
|
131
137
|
variant__green: variant__code === 4 && !this.bgColor,
|
132
138
|
})}
|
133
|
-
|
134
|
-
|
135
|
-
|
139
|
+
part="avatar__content"
|
140
|
+
style="
|
141
|
+
background-color: ${this.bgColor};
|
142
|
+
color:${this.textColor};
|
143
|
+
border: 1px solid ${this.borderColor};
|
144
|
+
border-color:${defaultInitials ? `${this.borderColor}` : 'var(--nile-colors-neutral-500)'}"
|
136
145
|
>
|
137
|
-
${
|
138
|
-
|
139
|
-
: html`<nile-icon
|
140
|
-
name="user"
|
141
|
-
color="grey"
|
142
|
-
part="error__icon"
|
143
|
-
size="${this.getDefaultIconSize()}"
|
144
|
-
></nile-icon>`}
|
145
|
-
</div>`;
|
146
|
-
|
147
|
-
this.isDefaultAvatar = false;
|
146
|
+
${content}
|
147
|
+
</div>`
|
148
148
|
}
|
149
149
|
|
150
|
-
|
150
|
+
getIconContent(){
|
151
151
|
return html`
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
:
|
170
|
-
|
152
|
+
<nile-icon
|
153
|
+
name="${this.icon}"
|
154
|
+
color="${this.textColor && "#fff"!==this.textColor?this.textColor:'var(--nile-colors-dark-500)'}"
|
155
|
+
size="${this.getDefaultIconSize()}"
|
156
|
+
></nile-icon>`
|
157
|
+
}
|
158
|
+
|
159
|
+
getImageContent(){
|
160
|
+
return html`
|
161
|
+
<img
|
162
|
+
src="${this.src}"
|
163
|
+
class="avatar"
|
164
|
+
class=${classMap({
|
165
|
+
avatar: true,
|
166
|
+
avatar__small: this.size === 'sm',
|
167
|
+
avatar__medium: this.size === 'md',
|
168
|
+
avatar__large: this.size === 'lg',
|
169
|
+
avatar__extralarge: this.size === 'xl',
|
170
|
+
avatar__2xl: this.size === '2xl',
|
171
|
+
avatar__rounded: this.isRounded,
|
172
|
+
})}
|
173
|
+
part="avatar__image"
|
174
|
+
style=" background-image: url(${this.src}), linear-gradient(lightgray, lightgray);"
|
175
|
+
@error="${()=>this.imageError=true}"
|
176
|
+
@load="${()=>this.imageError=false}"
|
177
|
+
/>`
|
171
178
|
}
|
172
179
|
|
173
180
|
/* #endregion */
|