@aquera/nile-elements 0.1.7 → 0.1.9
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 +9 -0
- package/demo/index.html +0 -10
- package/demo/variables.css +1 -1
- package/dist/nile-accordion/nile-accordian.test.cjs.js +1 -1
- package/dist/nile-accordion/nile-accordian.test.cjs.js.map +1 -1
- package/dist/nile-accordion/nile-accordian.test.esm.js +1 -1
- package/dist/nile-accordion/nile-accordion.cjs.js +1 -1
- package/dist/nile-accordion/nile-accordion.cjs.js.map +1 -1
- package/dist/nile-accordion/nile-accordion.css.cjs.js +1 -1
- package/dist/nile-accordion/nile-accordion.css.cjs.js.map +1 -1
- package/dist/nile-accordion/nile-accordion.css.esm.js +54 -23
- package/dist/nile-accordion/nile-accordion.esm.js +9 -8
- 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/nile-avatar/nile-avatar.test.cjs.js +1 -1
- package/dist/nile-avatar/nile-avatar.test.cjs.js.map +1 -1
- package/dist/nile-avatar/nile-avatar.test.esm.js +11 -1
- package/dist/nile-code-editor/nile-code-editor.css.cjs.js +1 -1
- package/dist/nile-code-editor/nile-code-editor.css.cjs.js.map +1 -1
- package/dist/nile-code-editor/nile-code-editor.css.esm.js +3 -3
- package/dist/src/nile-accordion/nile-accordian.test.js +24 -29
- package/dist/src/nile-accordion/nile-accordian.test.js.map +1 -1
- package/dist/src/nile-accordion/nile-accordion.css.js +53 -22
- package/dist/src/nile-accordion/nile-accordion.css.js.map +1 -1
- package/dist/src/nile-accordion/nile-accordion.d.ts +31 -16
- package/dist/src/nile-accordion/nile-accordion.js +68 -34
- package/dist/src/nile-accordion/nile-accordion.js.map +1 -1
- 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/src/nile-avatar/nile-avatar.test.d.ts +1 -0
- package/dist/src/nile-avatar/nile-avatar.test.js +64 -30
- package/dist/src/nile-avatar/nile-avatar.test.js.map +1 -1
- package/dist/src/nile-code-editor/nile-code-editor.css.js +3 -3
- package/dist/src/nile-code-editor/nile-code-editor.css.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-accordion/nile-accordian.test.ts +30 -57
- package/src/nile-accordion/nile-accordion.css.ts +53 -22
- package/src/nile-accordion/nile-accordion.ts +61 -33
- package/src/nile-avatar/nile-avatar.css.ts +2 -0
- package/src/nile-avatar/nile-avatar.test.ts +84 -33
- package/src/nile-avatar/nile-avatar.ts +79 -72
- package/src/nile-code-editor/nile-code-editor.css.ts +3 -3
- package/vscode-html-custom-data.json +143 -85
@@ -1,65 +1,116 @@
|
|
1
1
|
import { html, fixture, expect } from '@open-wc/testing';
|
2
2
|
import './nile-avatar';
|
3
|
-
import
|
3
|
+
import '../nile-icon'
|
4
|
+
import { NileAvatar } from './nile-avatar';
|
5
|
+
const wait=(ms:number=50000)=>new Promise(resolve => setTimeout(resolve, ms))
|
6
|
+
|
4
7
|
|
5
8
|
describe('NileAvatar', () => {
|
6
|
-
it('should display an image when the src is provided', async () => {
|
7
|
-
const el = await fixture<NileAvatar>(
|
9
|
+
it('should display an image when the src is provided and variant is "image"', async () => {
|
10
|
+
const el = await fixture<NileAvatar>(
|
11
|
+
html`<nile-avatar src="https://example.com/avatar.png" variant="image"></nile-avatar>`
|
12
|
+
);
|
8
13
|
const img = el.shadowRoot!.querySelector('img');
|
9
14
|
expect(img).to.exist;
|
10
15
|
expect(img!.getAttribute('src')).to.equal('https://example.com/avatar.png');
|
11
16
|
});
|
12
17
|
|
13
|
-
it('should
|
14
|
-
const el = await fixture<NileAvatar>(
|
18
|
+
it('should fall back to text initials when image fails to load and variant is "text"', async () => {
|
19
|
+
const el = await fixture<NileAvatar>(
|
20
|
+
html`<nile-avatar name="John Doe" variant="image" src="https://example.com/avatar.png"></nile-avatar>`
|
21
|
+
);
|
15
22
|
const img = el.shadowRoot!.querySelector('img');
|
16
23
|
img!.dispatchEvent(new Event('error'));
|
17
24
|
await el.updateComplete;
|
25
|
+
const icon = el.shadowRoot!.querySelector('nile-icon');
|
26
|
+
expect(icon).to.exist;
|
27
|
+
expect(icon!.getAttribute('name')).to.equal('user');
|
28
|
+
});
|
29
|
+
|
30
|
+
it('should display initials when variant is "text" and name is provided', async () => {
|
31
|
+
const el = await fixture<NileAvatar>(
|
32
|
+
html`<nile-avatar name="John Doe" variant="text"></nile-avatar>`
|
33
|
+
);
|
18
34
|
const initialsDiv = el.shadowRoot!.querySelector('.text__avatar');
|
19
35
|
expect(initialsDiv).to.exist;
|
20
36
|
expect(initialsDiv!.textContent!.trim()).to.equal('JD');
|
21
37
|
});
|
22
38
|
|
23
|
-
it('should
|
24
|
-
const el = await fixture<NileAvatar>(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
expect(
|
30
|
-
expect(initialsDiv).to.have.style('color', 'rgb(0, 255, 0)');
|
39
|
+
it('should display an icon when variant is "icon"', async () => {
|
40
|
+
const el = await fixture<NileAvatar>(
|
41
|
+
html`<nile-avatar variant="icon" icon="user"></nile-avatar>`
|
42
|
+
);
|
43
|
+
const icon = el.shadowRoot!.querySelector('nile-icon');
|
44
|
+
expect(icon).to.exist;
|
45
|
+
expect(icon!.getAttribute('name')).to.equal('user');
|
31
46
|
});
|
32
47
|
|
33
48
|
it('should apply the appropriate size class based on the size property', async () => {
|
34
|
-
const el = await fixture<NileAvatar>(html`<nile-avatar size="
|
35
|
-
const
|
36
|
-
expect(
|
49
|
+
const el = await fixture<NileAvatar>(html`<nile-avatar size="lg"></nile-avatar>`);
|
50
|
+
const div = el.shadowRoot!.querySelector('.text__avatar') || el.shadowRoot!.querySelector('img');
|
51
|
+
expect(div).to.have.class('avatar__large');
|
37
52
|
});
|
38
53
|
|
39
|
-
it('should have rounded class when isRounded is true', async () => {
|
54
|
+
it('should have the rounded class when isRounded is true', async () => {
|
40
55
|
const el = await fixture<NileAvatar>(html`<nile-avatar isRounded></nile-avatar>`);
|
41
|
-
const
|
42
|
-
expect(
|
43
|
-
});
|
44
|
-
|
45
|
-
it('should display a default icon when image fails to load and no name is provided', async () => {
|
46
|
-
const el = await fixture<NileAvatar>(html`<nile-avatar></nile-avatar>`);
|
47
|
-
const img = el.shadowRoot!.querySelector('img');
|
48
|
-
img!.dispatchEvent(new Event('error'));
|
49
|
-
await el.updateComplete;
|
50
|
-
const defaultIcon = el.shadowRoot!.querySelector('nile-icon');
|
51
|
-
expect(defaultIcon).to.exist;
|
52
|
-
expect(defaultIcon!.getAttribute('name')).to.equal('user');
|
56
|
+
const div = el.shadowRoot!.querySelector('.text__avatar') || el.shadowRoot!.querySelector('img');
|
57
|
+
expect(div).to.have.class('avatar__rounded');
|
53
58
|
});
|
54
59
|
|
55
|
-
it('should reflect properties to attributes', async () => {
|
56
|
-
const el = await fixture<NileAvatar>(
|
60
|
+
it('should reflect properties to attributes correctly', async () => {
|
61
|
+
const el = await fixture<NileAvatar>(
|
62
|
+
html`<nile-avatar
|
63
|
+
src="https://example.com/avatar.png"
|
64
|
+
name="Jane Doe"
|
65
|
+
bg-color="#123456"
|
66
|
+
text-color="#654321"
|
67
|
+
border-color="#abcdef"
|
68
|
+
size="sm"
|
69
|
+
isRounded
|
70
|
+
variant="image"
|
71
|
+
icon="user"
|
72
|
+
></nile-avatar>`
|
73
|
+
);
|
57
74
|
expect(el.getAttribute('src')).to.equal('https://example.com/avatar.png');
|
58
75
|
expect(el.getAttribute('name')).to.equal('Jane Doe');
|
59
76
|
expect(el.getAttribute('bg-color')).to.equal('#123456');
|
60
77
|
expect(el.getAttribute('text-color')).to.equal('#654321');
|
61
78
|
expect(el.getAttribute('border-color')).to.equal('#abcdef');
|
62
|
-
expect(el.getAttribute('size')).to.equal('
|
79
|
+
expect(el.getAttribute('size')).to.equal('sm');
|
80
|
+
expect(el.getAttribute('variant')).to.equal('image');
|
81
|
+
expect(el.getAttribute('icon')).to.equal('user');
|
63
82
|
expect(el.hasAttribute('isRounded')).to.be.true;
|
64
83
|
});
|
65
|
-
|
84
|
+
|
85
|
+
it('should use provided background and text colors when bg-color and text-color are set', async () => {
|
86
|
+
const el = await fixture<NileAvatar>(
|
87
|
+
html`<nile-avatar name="John Doe" bg-color="#ff0000" text-color="#00ff00"></nile-avatar>`
|
88
|
+
);
|
89
|
+
const initialsDiv = el.shadowRoot!.querySelector('.text__avatar');
|
90
|
+
expect(initialsDiv).to.have.style('background-color', 'rgb(255, 0, 0)');
|
91
|
+
expect(initialsDiv).to.have.style('color', 'rgb(0, 255, 0)');
|
92
|
+
});
|
93
|
+
|
94
|
+
it('should display a default icon when variant is "icon" and icon is not provided', async () => {
|
95
|
+
const el = await fixture<NileAvatar>(html`<nile-avatar variant="icon"></nile-avatar>`);
|
96
|
+
const icon = el.shadowRoot!.querySelector('nile-icon');
|
97
|
+
expect(icon).to.exist;
|
98
|
+
expect(icon!.getAttribute('name')).to.equal('user');
|
99
|
+
});
|
100
|
+
|
101
|
+
it('should use the default initials if name is not provided and variant is "text"', async () => {
|
102
|
+
const el = await fixture<NileAvatar>(html`<nile-avatar variant="text"></nile-avatar>`);
|
103
|
+
const initialsDiv = el.shadowRoot!.querySelector('.text__avatar');
|
104
|
+
expect(initialsDiv).to.exist;
|
105
|
+
expect(initialsDiv!.textContent!.trim()).to.equal('');
|
106
|
+
});
|
107
|
+
|
108
|
+
it('should handle image error gracefully by switching to fallback content', async () => {
|
109
|
+
const el = await fixture<NileAvatar>(html`<nile-avatar variant="image" src="invalid_url"></nile-avatar>`);
|
110
|
+
const img = el.shadowRoot!.querySelector('img');
|
111
|
+
img!.dispatchEvent(new Event('error'));
|
112
|
+
await el.updateComplete;
|
113
|
+
const fallbackContent = el.shadowRoot!.querySelector('.text__avatar') || el.shadowRoot!.querySelector('nile-icon');
|
114
|
+
expect(fallbackContent).to.exist;
|
115
|
+
});
|
116
|
+
});
|
@@ -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 */
|
@@ -47,13 +47,13 @@ export const styles = css`
|
|
47
47
|
|
48
48
|
.code-editor__icon__container {
|
49
49
|
display: none;
|
50
|
+
cursor: pointer;
|
51
|
+
align-self: start;
|
52
|
+
padding: 5px 5px 0px 0px;
|
50
53
|
}
|
51
54
|
|
52
55
|
.code-mirror:hover > .code-editor__icon__container {
|
53
|
-
cursor: pointer;
|
54
56
|
display: flex;
|
55
|
-
align-self: start;
|
56
|
-
padding: 5px 5px 0px 0px;
|
57
57
|
}
|
58
58
|
`;
|
59
59
|
|