Skip to content

Commit 99bf5c7

Browse files
committed
Added avatar item functionality, demo, and lumo styles.
1 parent 47dd238 commit 99bf5c7

File tree

4 files changed

+108
-22
lines changed

4 files changed

+108
-22
lines changed

.eslintrc.json

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
"sourceType": "module",
1212
"allowImportExportEverywhere": true
1313
},
14-
"globals": {
15-
"vis": false
16-
},
1714
"rules": {
1815
"max-len": ["error", { "code": 120 }]
1916
}

demo/index.html

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<demo-snippet>
2020
<template>
2121
<vcf-avatar-item></vcf-avatar-item>
22+
<vcf-avatar-item name="John Doe"></vcf-avatar-item>
23+
<vcf-avatar-item name="John Doe" abbr="ST"></vcf-avatar-item>
24+
<vcf-avatar-item>
25+
<img src="https://randomuser.me/api/portraits/women/5.jpg">
26+
</vcf-avatar-item>
2227
</template>
2328
</demo-snippet>
2429
</div>

src/vcf-avatar-item.js

+92-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,78 @@
1+
/* eslint-disable max-len */
12
import { html, PolymerElement } from '@polymer/polymer/polymer-element';
2-
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin';
3-
import { ElementMixin } from '@vaadin/vaadin-element-mixin';
43

5-
class VcfAvatarItem extends ElementMixin(ThemableMixin(PolymerElement)) {
4+
class VcfAvatarItem extends PolymerElement {
65
static get template() {
76
return html`
87
<style>
98
:host {
9+
display: inline-flex;
10+
align-items: center;
11+
justify-content: center;
12+
width: var(--lumo-size-s);
13+
height: var(--lumo-size-s);
14+
border-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-transform: uppercase;
21+
vertical-align: middle;
22+
line-height: 1;
23+
}
24+
25+
::slotted(img) {
26+
max-width: 100%;
27+
}
28+
29+
svg {
1030
display: block;
1131
}
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+
}
1256
</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>
1376
`;
1477
}
1578

@@ -22,11 +85,33 @@ class VcfAvatarItem extends ElementMixin(ThemableMixin(PolymerElement)) {
2285
}
2386

2487
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+
}
26111
}
27112

28-
connectedCallback() {
29-
super.connectedCallback();
113+
_getAbbr(name) {
114+
return this.abbr || name.match(/\b\S/g).join('');
30115
}
31116
}
32117

@@ -35,6 +120,7 @@ customElements.define(VcfAvatarItem.is, VcfAvatarItem);
35120
/**
36121
* @namespace Vaadin
37122
*/
123+
window.Vaadin = window.Vaadin || {};
38124
window.Vaadin.VcfAvatarItem = VcfAvatarItem;
39125

40126
if (window.Vaadin.runIfDevelopmentMode) {

theme/lumo/vcf-avatar-item-styles.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import styleModule from '../../src/util/style-module';
21
import '@vaadin/vaadin-lumo-styles/color';
32
import '@vaadin/vaadin-lumo-styles/sizing';
4-
import '@vaadin/vaadin-lumo-styles/spacing';
5-
import '@vaadin/vaadin-lumo-styles/style';
63
import '@vaadin/vaadin-lumo-styles/typography';
74

8-
styleModule({
9-
themeFor: 'vcf-avatar-item',
10-
themeName: 'vcf-avatar-item-lumo',
11-
include: 'lumo-color lumo-typography',
12-
styles: `
13-
:host {
14-
border: 1px solid var(--lumo-contrast-10pct);
15-
}
16-
`
17-
});
5+
const theme = document.createElement('dom-module');
6+
theme.id = 'vcf-avatar-item-lumo';
7+
theme.setAttribute('theme-for', 'vcf-avatar-item');
8+
theme.innerHTML = `
9+
<template>
10+
<style include="lumo-color lumo-sizing lumo-typography">
11+
:host {}
12+
</style>
13+
</template>
14+
`;
15+
theme.register(theme.id);

0 commit comments

Comments
 (0)