@justeattakeaway/pie-avatar 0.2.0 → 0.3.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/README.md +6 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.js +19 -18
- package/dist/react.d.ts +4 -1
- package/package.json +2 -1
- package/src/avatar.scss +0 -7
- package/src/defs.ts +2 -2
- package/src/index.ts +3 -1
package/README.md
CHANGED
|
@@ -30,9 +30,12 @@ Ideally, you should install the component using the **`@justeattakeaway/pie-webc
|
|
|
30
30
|
## Documentation
|
|
31
31
|
|
|
32
32
|
### Properties
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
|
|
34
|
+
| Prop | Options | Description | Default |
|
|
35
|
+
|------|---------|-------------|---------|
|
|
36
|
+
| `src` | — | The src attribute for the underlying image tag. | `""` |
|
|
37
|
+
| `tag` | "button", "a", "div" | Which HTML element to use when rendering the avatar.| `div` |
|
|
38
|
+
| `label` | - | User or company name that will be rendered as initials inside the avatar.| `""` |
|
|
36
39
|
|
|
37
40
|
### Slots
|
|
38
41
|
| Slot | Description |
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,13 @@ import { RTLInterface } from '@justeattakeaway/pie-webc-core';
|
|
|
6
6
|
import { TemplateResult } from 'lit';
|
|
7
7
|
|
|
8
8
|
export declare interface AvatarProps {
|
|
9
|
-
label?: string;
|
|
10
9
|
/**
|
|
11
10
|
* Label for the username that will be turned into initials inside the avatar, if provided.
|
|
12
11
|
*/
|
|
12
|
+
label?: string;
|
|
13
|
+
/**
|
|
14
|
+
* What HTML element the avatar should be such as button, a or div.
|
|
15
|
+
*/
|
|
13
16
|
tag: typeof tags[number];
|
|
14
17
|
}
|
|
15
18
|
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { LitElement as h, html as n, unsafeCSS as f } from "lit";
|
|
2
2
|
import { RtlMixin as g, validPropertyValues as b, safeCustomElement as y } from "@justeattakeaway/pie-webc-core";
|
|
3
|
-
import
|
|
3
|
+
import "@justeattakeaway/pie-icons-webc/dist/IconUser.js";
|
|
4
|
+
import { property as u } from "lit/decorators.js";
|
|
4
5
|
const o = class o extends h {
|
|
5
6
|
willUpdate() {
|
|
6
7
|
this.getAttribute("v") || this.setAttribute("v", o.v);
|
|
7
8
|
}
|
|
8
9
|
};
|
|
9
|
-
o.v = "0.
|
|
10
|
+
o.v = "0.3.0";
|
|
10
11
|
let d = o;
|
|
11
|
-
const m = "*,*:after,*:before{box-sizing:inherit}:host{display:block}.c-avatar-visuallyHidden{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.c-avatar-content{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:32px;height:32px;border-radius:var(--dt-radius-rounded-e)}
|
|
12
|
+
const m = "*,*:after,*:before{box-sizing:inherit}:host{display:block}.c-avatar-visuallyHidden{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.c-avatar-content{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:32px;height:32px;border-radius:var(--dt-radius-rounded-e)}", x = ["a", "button", "div"], v = {
|
|
12
13
|
tag: "div"
|
|
13
14
|
};
|
|
14
|
-
var w = Object.defineProperty,
|
|
15
|
-
for (var
|
|
16
|
-
(p = t[l]) && (
|
|
17
|
-
return i &&
|
|
15
|
+
var w = Object.defineProperty, S = Object.getOwnPropertyDescriptor, c = (t, e, r, i) => {
|
|
16
|
+
for (var a = i > 1 ? void 0 : i ? S(e, r) : e, l = t.length - 1, p; l >= 0; l--)
|
|
17
|
+
(p = t[l]) && (a = (i ? p(e, r, a) : p(a)) || a);
|
|
18
|
+
return i && a && w(e, r, a), a;
|
|
18
19
|
};
|
|
19
|
-
const
|
|
20
|
+
const C = "pie-avatar";
|
|
20
21
|
let s = class extends g(d) {
|
|
21
22
|
constructor() {
|
|
22
|
-
super(...arguments), this.tag =
|
|
23
|
+
super(...arguments), this.tag = v.tag;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Attempts to extract initials from the label string.
|
|
@@ -31,10 +32,10 @@ let s = class extends g(d) {
|
|
|
31
32
|
try {
|
|
32
33
|
if (!t || typeof t != "string" || t.trim().length === 0)
|
|
33
34
|
return null;
|
|
34
|
-
const
|
|
35
|
-
return
|
|
36
|
-
visual:
|
|
37
|
-
screenreader:
|
|
35
|
+
const r = t.trim().replace(/-/g, " ").split(/\s+/).slice(0, 2).map((i) => i[0].toUpperCase());
|
|
36
|
+
return r.length === 0 ? null : {
|
|
37
|
+
visual: r.join(""),
|
|
38
|
+
screenreader: r.join(", ")
|
|
38
39
|
// joins the two words by comma so initials are correctly pronounced by screenreaders
|
|
39
40
|
};
|
|
40
41
|
} catch {
|
|
@@ -58,7 +59,7 @@ let s = class extends g(d) {
|
|
|
58
59
|
* @private
|
|
59
60
|
*/
|
|
60
61
|
renderIcon() {
|
|
61
|
-
return n`<
|
|
62
|
+
return n`<icon-user size="s" aria-hidden="true" data-test-id="pie-avatar-icon"></icon-user>`;
|
|
62
63
|
}
|
|
63
64
|
/**
|
|
64
65
|
* Renders the inner content of the avatar such as initials, an icon or an image.
|
|
@@ -90,17 +91,17 @@ let s = class extends g(d) {
|
|
|
90
91
|
};
|
|
91
92
|
s.styles = f(m);
|
|
92
93
|
c([
|
|
93
|
-
|
|
94
|
-
b(
|
|
94
|
+
u({ type: String }),
|
|
95
|
+
b(C, x, v.tag)
|
|
95
96
|
], s.prototype, "tag", 2);
|
|
96
97
|
c([
|
|
97
|
-
|
|
98
|
+
u({ type: String })
|
|
98
99
|
], s.prototype, "label", 2);
|
|
99
100
|
s = c([
|
|
100
101
|
y("pie-avatar")
|
|
101
102
|
], s);
|
|
102
103
|
export {
|
|
103
104
|
s as PieAvatar,
|
|
104
|
-
|
|
105
|
+
v as defaultProps,
|
|
105
106
|
x as tags
|
|
106
107
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -7,10 +7,13 @@ import { RTLInterface } from '@justeattakeaway/pie-webc-core';
|
|
|
7
7
|
import { TemplateResult } from 'lit';
|
|
8
8
|
|
|
9
9
|
export declare interface AvatarProps {
|
|
10
|
-
label?: string;
|
|
11
10
|
/**
|
|
12
11
|
* Label for the username that will be turned into initials inside the avatar, if provided.
|
|
13
12
|
*/
|
|
13
|
+
label?: string;
|
|
14
|
+
/**
|
|
15
|
+
* What HTML element the avatar should be such as button, a or div.
|
|
16
|
+
*/
|
|
14
17
|
tag: typeof tags[number];
|
|
15
18
|
}
|
|
16
19
|
|
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.3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"@justeattakeaway/pie-icons-webc": "1.14.2",
|
|
42
43
|
"@justeattakeaway/pie-webc-core": "1.1.0"
|
|
43
44
|
},
|
|
44
45
|
"volta": {
|
package/src/avatar.scss
CHANGED
package/src/defs.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
|
3
3
|
export const tags = ['a', 'button', 'div'] as const;
|
|
4
4
|
|
|
5
5
|
export interface AvatarProps {
|
|
6
|
-
label?: string;
|
|
7
6
|
/**
|
|
8
7
|
* Label for the username that will be turned into initials inside the avatar, if provided.
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
label?: string;
|
|
11
10
|
/**
|
|
12
11
|
* What HTML element the avatar should be such as button, a or div.
|
|
13
12
|
*/
|
|
13
|
+
tag: typeof tags[number];
|
|
14
14
|
|
|
15
15
|
}
|
|
16
16
|
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
} from 'lit';
|
|
4
4
|
import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
|
|
5
5
|
import { RtlMixin, safeCustomElement, validPropertyValues } from '@justeattakeaway/pie-webc-core';
|
|
6
|
+
import '@justeattakeaway/pie-icons-webc/dist/IconUser.js';
|
|
6
7
|
|
|
7
8
|
import { property } from 'lit/decorators.js';
|
|
8
9
|
import styles from './avatar.scss?inline';
|
|
@@ -18,6 +19,7 @@ const componentSelector = 'pie-avatar';
|
|
|
18
19
|
/**
|
|
19
20
|
* @tagname pie-avatar
|
|
20
21
|
*/
|
|
22
|
+
|
|
21
23
|
@safeCustomElement('pie-avatar')
|
|
22
24
|
export class PieAvatar extends RtlMixin(PieElement) implements AvatarProps {
|
|
23
25
|
@property({ type: String })
|
|
@@ -73,7 +75,7 @@ export class PieAvatar extends RtlMixin(PieElement) implements AvatarProps {
|
|
|
73
75
|
* @private
|
|
74
76
|
*/
|
|
75
77
|
private renderIcon (): TemplateResult {
|
|
76
|
-
return html`<
|
|
78
|
+
return html`<icon-user size="s" aria-hidden="true" data-test-id="pie-avatar-icon"></icon-user>`;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
/**
|