@justeattakeaway/pie-avatar 0.3.0 → 0.4.0
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/custom-elements.json +28 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +45 -31
- package/dist/react.d.ts +14 -2
- package/package.json +2 -2
- package/src/avatar.scss +16 -3
- package/src/defs.ts +7 -1
- package/src/index.ts +20 -5
package/custom-elements.json
CHANGED
|
@@ -70,6 +70,14 @@
|
|
|
70
70
|
},
|
|
71
71
|
"privacy": "public"
|
|
72
72
|
},
|
|
73
|
+
{
|
|
74
|
+
"kind": "field",
|
|
75
|
+
"name": "src",
|
|
76
|
+
"type": {
|
|
77
|
+
"text": "AvatarProps['src']"
|
|
78
|
+
},
|
|
79
|
+
"privacy": "public"
|
|
80
|
+
},
|
|
73
81
|
{
|
|
74
82
|
"kind": "method",
|
|
75
83
|
"name": "getInitials",
|
|
@@ -117,7 +125,26 @@
|
|
|
117
125
|
"text": "TemplateResult"
|
|
118
126
|
}
|
|
119
127
|
},
|
|
120
|
-
"description": "Renders the icon
|
|
128
|
+
"description": "Renders the user icon."
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"kind": "method",
|
|
132
|
+
"name": "renderImage",
|
|
133
|
+
"privacy": "private",
|
|
134
|
+
"return": {
|
|
135
|
+
"type": {
|
|
136
|
+
"text": "TemplateResult"
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"parameters": [
|
|
140
|
+
{
|
|
141
|
+
"name": "imgSrc",
|
|
142
|
+
"type": {
|
|
143
|
+
"text": "string"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
"description": "Renders an image.\nWe assign an empty string to the alt attribute for a11y clarity as it explicitly declares the image as decorative"
|
|
121
148
|
},
|
|
122
149
|
{
|
|
123
150
|
"kind": "field",
|
package/dist/index.d.ts
CHANGED
|
@@ -14,9 +14,13 @@ export declare interface AvatarProps {
|
|
|
14
14
|
* What HTML element the avatar should be such as button, a or div.
|
|
15
15
|
*/
|
|
16
16
|
tag: typeof tags[number];
|
|
17
|
+
/**
|
|
18
|
+
* The src attribute for the avatar image. When provided, displays an image instead of initials.
|
|
19
|
+
*/
|
|
20
|
+
src?: string;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
export declare type DefaultProps = ComponentDefaultProps<AvatarProps, keyof Omit<AvatarProps, 'label'>>;
|
|
23
|
+
export declare type DefaultProps = ComponentDefaultProps<AvatarProps, keyof Omit<AvatarProps, 'label' | 'src'>>;
|
|
20
24
|
|
|
21
25
|
export declare const defaultProps: DefaultProps;
|
|
22
26
|
|
|
@@ -31,6 +35,7 @@ export declare type Initials = {
|
|
|
31
35
|
export declare class PieAvatar extends PieAvatar_base implements AvatarProps {
|
|
32
36
|
tag: "a" | "button" | "div";
|
|
33
37
|
label: AvatarProps['label'];
|
|
38
|
+
src: AvatarProps['src'];
|
|
34
39
|
/**
|
|
35
40
|
* Attempts to extract initials from the label string.
|
|
36
41
|
* If the label is not provided or is invalid, it returns null.
|
|
@@ -45,11 +50,18 @@ export declare class PieAvatar extends PieAvatar_base implements AvatarProps {
|
|
|
45
50
|
*/
|
|
46
51
|
private renderInitials;
|
|
47
52
|
/**
|
|
48
|
-
* Renders the icon
|
|
53
|
+
* Renders the user icon.
|
|
49
54
|
*
|
|
50
55
|
* @private
|
|
51
56
|
*/
|
|
52
57
|
private renderIcon;
|
|
58
|
+
/**
|
|
59
|
+
* Renders an image.
|
|
60
|
+
* We assign an empty string to the alt attribute for a11y clarity as it explicitly declares the image as decorative
|
|
61
|
+
*
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
private renderImage;
|
|
53
65
|
/**
|
|
54
66
|
* Renders the inner content of the avatar such as initials, an icon or an image.
|
|
55
67
|
* It is a getter because the value is computed based on properties
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { LitElement as h, html as
|
|
2
|
-
import { RtlMixin as
|
|
1
|
+
import { LitElement as h, html as s, unsafeCSS as g } from "lit";
|
|
2
|
+
import { RtlMixin as f, validPropertyValues as b, safeCustomElement as m } from "@justeattakeaway/pie-webc-core";
|
|
3
3
|
import "@justeattakeaway/pie-icons-webc/dist/IconUser.js";
|
|
4
|
-
import { property as
|
|
4
|
+
import { property as v } from "lit/decorators.js";
|
|
5
5
|
const o = class o extends h {
|
|
6
6
|
willUpdate() {
|
|
7
7
|
this.getAttribute("v") || this.setAttribute("v", o.v);
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
|
-
o.v = "0.
|
|
11
|
-
let
|
|
12
|
-
const
|
|
10
|
+
o.v = "0.4.0";
|
|
11
|
+
let p = o;
|
|
12
|
+
const y = "*,*:after,*:before{box-sizing:inherit}:host{display:block;--avatar-size: 32px}.c-avatar-visuallyHidden{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.c-avatar{display:flex;justify-content:center;align-items:center;font-size:calc(var(--dt-font-body-s-size) * 1px);background-color:var(--dt-color-container-inverse);color:var(--dt-color-content-interactive-primary);width:var(--avatar-size);height:var(--avatar-size);border-radius:var(--dt-radius-rounded-e);overflow:hidden}.c-avatar--image{width:100%;height:100%;object-fit:cover}.c-avatar--button{border:none;font-family:inherit}", x = ["a", "button", "div"], u = {
|
|
13
13
|
tag: "div"
|
|
14
14
|
};
|
|
15
|
-
var w = Object.defineProperty,
|
|
16
|
-
for (var
|
|
17
|
-
(
|
|
18
|
-
return i &&
|
|
15
|
+
var w = Object.defineProperty, I = Object.getOwnPropertyDescriptor, l = (t, a, r, i) => {
|
|
16
|
+
for (var e = i > 1 ? void 0 : i ? I(a, r) : a, d = t.length - 1, c; d >= 0; d--)
|
|
17
|
+
(c = t[d]) && (e = (i ? c(a, r, e) : c(e)) || e);
|
|
18
|
+
return i && e && w(a, r, e), e;
|
|
19
19
|
};
|
|
20
|
-
const
|
|
21
|
-
let
|
|
20
|
+
const S = "pie-avatar";
|
|
21
|
+
let n = class extends f(p) {
|
|
22
22
|
constructor() {
|
|
23
|
-
super(...arguments), this.tag =
|
|
23
|
+
super(...arguments), this.tag = u.tag;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Attempts to extract initials from the label string.
|
|
@@ -48,18 +48,27 @@ let s = class extends g(d) {
|
|
|
48
48
|
* @private
|
|
49
49
|
*/
|
|
50
50
|
renderInitials(t) {
|
|
51
|
-
return
|
|
51
|
+
return s`
|
|
52
52
|
<span aria-hidden="true" data-test-id="pie-avatar-initials-visual">${t.visual}</span>
|
|
53
53
|
<span class="c-avatar-visuallyHidden" data-test-id="pie-avatar-initials-screenreader">${t.screenreader}</span>
|
|
54
54
|
`;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* Renders the icon
|
|
57
|
+
* Renders the user icon.
|
|
58
58
|
*
|
|
59
59
|
* @private
|
|
60
60
|
*/
|
|
61
61
|
renderIcon() {
|
|
62
|
-
return
|
|
62
|
+
return s`<icon-user size="s" aria-hidden="true" data-test-id="pie-avatar-icon"></icon-user>`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Renders an image.
|
|
66
|
+
* We assign an empty string to the alt attribute for a11y clarity as it explicitly declares the image as decorative
|
|
67
|
+
*
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
renderImage(t) {
|
|
71
|
+
return s`<img class="c-avatar--image" src="${t}" data-test-id="pie-avatar-image" alt=""/>`;
|
|
63
72
|
}
|
|
64
73
|
/**
|
|
65
74
|
* Renders the inner content of the avatar such as initials, an icon or an image.
|
|
@@ -68,6 +77,8 @@ let s = class extends g(d) {
|
|
|
68
77
|
* @private
|
|
69
78
|
*/
|
|
70
79
|
get avatarContent() {
|
|
80
|
+
if (this.src)
|
|
81
|
+
return this.renderImage(this.src);
|
|
71
82
|
if (this.label) {
|
|
72
83
|
const t = this.getInitials(this.label);
|
|
73
84
|
if (t)
|
|
@@ -82,26 +93,29 @@ let s = class extends g(d) {
|
|
|
82
93
|
* @private
|
|
83
94
|
*/
|
|
84
95
|
renderAvatarWrapper(t) {
|
|
85
|
-
const { tag:
|
|
86
|
-
return
|
|
96
|
+
const { tag: a } = this;
|
|
97
|
+
return a === "button" ? s`<button data-test-id="pie-avatar-button" class="c-avatar c-avatar--button">${t}</button>` : a === "a" ? s`<a data-test-id="pie-avatar-anchor" class="c-avatar">${t}</a>` : s`<div class="c-avatar" data-test-id="pie-avatar-div" ?aria-hidden="${this.src}">${t}</div>`;
|
|
87
98
|
}
|
|
88
99
|
render() {
|
|
89
100
|
return this.renderAvatarWrapper(this.avatarContent);
|
|
90
101
|
}
|
|
91
102
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
b(
|
|
96
|
-
],
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
],
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
],
|
|
103
|
+
n.styles = g(y);
|
|
104
|
+
l([
|
|
105
|
+
v({ type: String }),
|
|
106
|
+
b(S, x, u.tag)
|
|
107
|
+
], n.prototype, "tag", 2);
|
|
108
|
+
l([
|
|
109
|
+
v({ type: String })
|
|
110
|
+
], n.prototype, "label", 2);
|
|
111
|
+
l([
|
|
112
|
+
v({ type: String })
|
|
113
|
+
], n.prototype, "src", 2);
|
|
114
|
+
n = l([
|
|
115
|
+
m("pie-avatar")
|
|
116
|
+
], n);
|
|
103
117
|
export {
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
n as PieAvatar,
|
|
119
|
+
u as defaultProps,
|
|
106
120
|
x as tags
|
|
107
121
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -15,9 +15,13 @@ export declare interface AvatarProps {
|
|
|
15
15
|
* What HTML element the avatar should be such as button, a or div.
|
|
16
16
|
*/
|
|
17
17
|
tag: typeof tags[number];
|
|
18
|
+
/**
|
|
19
|
+
* The src attribute for the avatar image. When provided, displays an image instead of initials.
|
|
20
|
+
*/
|
|
21
|
+
src?: string;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
export declare type DefaultProps = ComponentDefaultProps<AvatarProps, keyof Omit<AvatarProps, 'label'>>;
|
|
24
|
+
export declare type DefaultProps = ComponentDefaultProps<AvatarProps, keyof Omit<AvatarProps, 'label' | 'src'>>;
|
|
21
25
|
|
|
22
26
|
export declare const defaultProps: DefaultProps;
|
|
23
27
|
|
|
@@ -34,6 +38,7 @@ export declare const PieAvatar: React_2.ForwardRefExoticComponent<React_2.PropsW
|
|
|
34
38
|
declare class PieAvatar_2 extends PieAvatar_base implements AvatarProps {
|
|
35
39
|
tag: "a" | "button" | "div";
|
|
36
40
|
label: AvatarProps['label'];
|
|
41
|
+
src: AvatarProps['src'];
|
|
37
42
|
/**
|
|
38
43
|
* Attempts to extract initials from the label string.
|
|
39
44
|
* If the label is not provided or is invalid, it returns null.
|
|
@@ -48,11 +53,18 @@ declare class PieAvatar_2 extends PieAvatar_base implements AvatarProps {
|
|
|
48
53
|
*/
|
|
49
54
|
private renderInitials;
|
|
50
55
|
/**
|
|
51
|
-
* Renders the icon
|
|
56
|
+
* Renders the user icon.
|
|
52
57
|
*
|
|
53
58
|
* @private
|
|
54
59
|
*/
|
|
55
60
|
private renderIcon;
|
|
61
|
+
/**
|
|
62
|
+
* Renders an image.
|
|
63
|
+
* We assign an empty string to the alt attribute for a11y clarity as it explicitly declares the image as decorative
|
|
64
|
+
*
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
private renderImage;
|
|
56
68
|
/**
|
|
57
69
|
* Renders the inner content of the avatar such as initials, an icon or an image.
|
|
58
70
|
* It is a getter because the value is computed based on properties
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-avatar",
|
|
3
3
|
"description": "PIE Design System Avatar built using Web Components",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@custom-elements-manifest/analyzer": "0.9.0",
|
|
36
36
|
"@justeattakeaway/pie-components-config": "0.21.0",
|
|
37
|
-
"@justeattakeaway/pie-css": "0.
|
|
37
|
+
"@justeattakeaway/pie-css": "0.20.0",
|
|
38
38
|
"@justeattakeaway/pie-monorepo-utils": "0.7.0",
|
|
39
39
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
40
40
|
},
|
package/src/avatar.scss
CHANGED
|
@@ -4,21 +4,34 @@
|
|
|
4
4
|
// Note: For consistency sake, the recommended display should be either
|
|
5
5
|
// "block" or "inline-block", otherwise it can be ommited for floating elements
|
|
6
6
|
display: block;
|
|
7
|
+
|
|
8
|
+
--avatar-size: 32px;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
.c-avatar-visuallyHidden {
|
|
10
12
|
@include p.visually-hidden;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
.c-avatar
|
|
15
|
+
.c-avatar {
|
|
14
16
|
display: flex;
|
|
15
17
|
justify-content: center;
|
|
16
18
|
align-items: center;
|
|
17
19
|
@include p.font-size(--dt-font-body-s-size);
|
|
18
20
|
background-color: var(--dt-color-container-inverse);
|
|
19
21
|
color: var(--dt-color-content-interactive-primary);
|
|
20
|
-
width:
|
|
21
|
-
height:
|
|
22
|
+
width: var(--avatar-size);
|
|
23
|
+
height: var(--avatar-size);
|
|
22
24
|
border-radius:var(--dt-radius-rounded-e);
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
}
|
|
23
27
|
|
|
28
|
+
.c-avatar--image {
|
|
29
|
+
width: 100%;
|
|
30
|
+
height: 100%;
|
|
31
|
+
object-fit: cover;
|
|
24
32
|
}
|
|
33
|
+
|
|
34
|
+
.c-avatar--button {
|
|
35
|
+
border: none;
|
|
36
|
+
font-family: inherit;
|
|
37
|
+
}
|
package/src/defs.ts
CHANGED
|
@@ -7,14 +7,20 @@ export interface AvatarProps {
|
|
|
7
7
|
* Label for the username that will be turned into initials inside the avatar, if provided.
|
|
8
8
|
*/
|
|
9
9
|
label?: string;
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* What HTML element the avatar should be such as button, a or div.
|
|
12
13
|
*/
|
|
13
14
|
tag: typeof tags[number];
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* The src attribute for the avatar image. When provided, displays an image instead of initials.
|
|
18
|
+
*/
|
|
19
|
+
src?: string;
|
|
20
|
+
|
|
15
21
|
}
|
|
16
22
|
|
|
17
|
-
export type DefaultProps = ComponentDefaultProps<AvatarProps, keyof Omit<AvatarProps, 'label'>>;
|
|
23
|
+
export type DefaultProps = ComponentDefaultProps<AvatarProps, keyof Omit<AvatarProps, 'label' | 'src'>>;
|
|
18
24
|
export const defaultProps: DefaultProps = {
|
|
19
25
|
tag: 'div',
|
|
20
26
|
};
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,9 @@ export class PieAvatar extends RtlMixin(PieElement) implements AvatarProps {
|
|
|
29
29
|
@property({ type: String })
|
|
30
30
|
public label: AvatarProps['label'];
|
|
31
31
|
|
|
32
|
+
@property({ type: String })
|
|
33
|
+
public src: AvatarProps['src'];
|
|
34
|
+
|
|
32
35
|
/**
|
|
33
36
|
* Attempts to extract initials from the label string.
|
|
34
37
|
* If the label is not provided or is invalid, it returns null.
|
|
@@ -70,7 +73,7 @@ export class PieAvatar extends RtlMixin(PieElement) implements AvatarProps {
|
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
/**
|
|
73
|
-
* Renders the icon
|
|
76
|
+
* Renders the user icon.
|
|
74
77
|
*
|
|
75
78
|
* @private
|
|
76
79
|
*/
|
|
@@ -78,6 +81,16 @@ export class PieAvatar extends RtlMixin(PieElement) implements AvatarProps {
|
|
|
78
81
|
return html`<icon-user size="s" aria-hidden="true" data-test-id="pie-avatar-icon"></icon-user>`;
|
|
79
82
|
}
|
|
80
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Renders an image.
|
|
86
|
+
* We assign an empty string to the alt attribute for a11y clarity as it explicitly declares the image as decorative
|
|
87
|
+
*
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
private renderImage (imgSrc: string): TemplateResult {
|
|
91
|
+
return html`<img class="c-avatar--image" src="${imgSrc}" data-test-id="pie-avatar-image" alt=""/>`;
|
|
92
|
+
}
|
|
93
|
+
|
|
81
94
|
/**
|
|
82
95
|
* Renders the inner content of the avatar such as initials, an icon or an image.
|
|
83
96
|
* It is a getter because the value is computed based on properties
|
|
@@ -85,7 +98,9 @@ export class PieAvatar extends RtlMixin(PieElement) implements AvatarProps {
|
|
|
85
98
|
* @private
|
|
86
99
|
*/
|
|
87
100
|
private get avatarContent (): TemplateResult {
|
|
88
|
-
|
|
101
|
+
if (this.src) {
|
|
102
|
+
return this.renderImage(this.src);
|
|
103
|
+
}
|
|
89
104
|
|
|
90
105
|
if (this.label) {
|
|
91
106
|
const initials = this.getInitials(this.label);
|
|
@@ -107,14 +122,14 @@ export class PieAvatar extends RtlMixin(PieElement) implements AvatarProps {
|
|
|
107
122
|
const { tag } = this;
|
|
108
123
|
|
|
109
124
|
if (tag === 'button') {
|
|
110
|
-
return html`<button data-test-id="pie-avatar-button">${content}</button>`;
|
|
125
|
+
return html`<button data-test-id="pie-avatar-button" class="c-avatar c-avatar--button">${content}</button>`;
|
|
111
126
|
}
|
|
112
127
|
|
|
113
128
|
if (tag === 'a') {
|
|
114
|
-
return html`<a data-test-id="pie-avatar-anchor">${content}</a>`;
|
|
129
|
+
return html`<a data-test-id="pie-avatar-anchor" class="c-avatar">${content}</a>`;
|
|
115
130
|
}
|
|
116
131
|
|
|
117
|
-
return html`<div class="c-avatar
|
|
132
|
+
return html`<div class="c-avatar" data-test-id="pie-avatar-div" ?aria-hidden="${this.src}">${content}</div>`;
|
|
118
133
|
}
|
|
119
134
|
|
|
120
135
|
render () {
|