@aquera/nile-elements 0.1.6 → 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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent nile-elements following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "nile-elements",
6
- "version": "0.1.6",
6
+ "version": "0.1.8",
7
7
  "main": "dist/src/index.js",
8
8
  "type": "module",
9
9
  "module": "dist/src/index.js",
@@ -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 = false;
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
- * Render method
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 'small':
91
+ case 'sm':
100
92
  return '10';
101
- case 'medium':
93
+ case 'md':
102
94
  return '16';
103
- case 'large':
95
+ case 'lg':
104
96
  return '20';
105
- case 'extralarge':
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
- private handleImageError(event: Event): void {
115
- const defaultInitials = this.generateInitials(this.name);
116
- const variant__code = this.generateVariantCode(defaultInitials);
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
- this.defaultAvatarContent = html`<div
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 === 'small',
122
- avatar__medium: this.size === 'medium',
123
- avatar__large: this.size === 'large',
124
- avatar__extralarge: this.size === 'extralarge',
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
- style="background-color: ${this.bgColor};color:${this
134
- .textColor};border: 0.5px solid ${this.borderColor};
135
- border-color:${defaultInitials ? 'rgba(0, 0, 0, 0.08)' : '#C7CED4'}"
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
- ${defaultInitials
138
- ? defaultInitials
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
- public render(): TemplateResult {
150
+ getIconContent(){
151
151
  return html`
152
- ${this.isDefaultAvatar
153
- ? html` <img
154
- src="${this.src}"
155
- class="avatar"
156
- class=${classMap({
157
- avatar: true,
158
- avatar__small: this.size === 'small',
159
- avatar__medium: this.size === 'medium',
160
- avatar__large: this.size === 'large',
161
- avatar__extralarge: this.size === 'extralarge',
162
- avatar__2xl: this.size === '2xl',
163
- avatar__rounded: this.isRounded,
164
- })}
165
- style=" background-image: url(${this
166
- .src}), linear-gradient(lightgray, lightgray);"
167
- @error="${this.handleImageError}"
168
- />`
169
- : html`${this.defaultAvatarContent}`}
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 */