Skip to content

Commit a4293be

Browse files
committed
uui-avatar sizing update and others
1 parent b80e73f commit a4293be

File tree

6 files changed

+70
-39
lines changed

6 files changed

+70
-39
lines changed

packages/uui-avatar-group/lib/uui-avatar-group.story.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Story } from '@storybook/web-components';
22
import { html } from 'lit-html';
33
import '@umbraco-ui/uui-avatar-group/lib/index';
4+
import { GetRandomUmbracoWordOfWordCount } from '../../../storyhelpers/UmbracoWordGenerator';
45

56
export default {
67
title: 'Displays/Avatar Group',
@@ -17,10 +18,10 @@ export const AAAOverview: Story = props => html`
1718
'--uui-avatar-border-color'
1819
]};"
1920
.limit=${props.limit}>
20-
<uui-avatar title="First Last"></uui-avatar>
21-
<uui-avatar title="First Last"></uui-avatar>
22-
<uui-avatar title="First Last"></uui-avatar>
23-
<uui-avatar title="First Last"></uui-avatar>
21+
<uui-avatar title=${GetRandomUmbracoWordOfWordCount(2)}></uui-avatar>
22+
<uui-avatar title=${GetRandomUmbracoWordOfWordCount(2)}></uui-avatar>
23+
<uui-avatar title=${GetRandomUmbracoWordOfWordCount(2)}></uui-avatar>
24+
<uui-avatar title=${GetRandomUmbracoWordOfWordCount(2)}></uui-avatar>
2425
</uui-avatar-group>
2526
`;
2627
AAAOverview.args = { fontSize: 2, '--uui-avatar-border-color': 'white' };
@@ -32,10 +33,10 @@ AAAOverview.parameters = {
3233
docs: {
3334
source: {
3435
code: html`<uui-avatar-group>
35-
<uui-avatar title="First Last"></uui-avatar>
36-
<uui-avatar title="First Last"></uui-avatar>
37-
<uui-avatar title="First Last"></uui-avatar>
38-
<uui-avatar title="First Last"></uui-avatar>
36+
<uui-avatar title="Firstname Lastname"></uui-avatar>
37+
<uui-avatar title="Firstname Lastname"></uui-avatar>
38+
<uui-avatar title="Firstname Lastname"></uui-avatar>
39+
<uui-avatar title="Firstname Lastname"></uui-avatar>
3940
</uui-avatar-group>`.strings,
4041
},
4142
},
@@ -47,10 +48,10 @@ export const Limit: Story = ({ limit }) => html`
4748
<uui-avatar-group
4849
style="font-size: 2rem; --uui-avatar-border-color: white;"
4950
.limit=${limit}>
50-
<uui-avatar title="First Last"></uui-avatar>
51-
<uui-avatar title="First Last"></uui-avatar>
52-
<uui-avatar title="First Last"></uui-avatar>
53-
<uui-avatar title="First Last"></uui-avatar>
51+
<uui-avatar title=${GetRandomUmbracoWordOfWordCount(2)}></uui-avatar>
52+
<uui-avatar title=${GetRandomUmbracoWordOfWordCount(2)}></uui-avatar>
53+
<uui-avatar title=${GetRandomUmbracoWordOfWordCount(2)}></uui-avatar>
54+
<uui-avatar title=${GetRandomUmbracoWordOfWordCount(2)}></uui-avatar>
5455
</uui-avatar-group>
5556
`;
5657
Limit.args = { limit: 2 };
@@ -59,10 +60,10 @@ Limit.parameters = {
5960
docs: {
6061
source: {
6162
code: html`<uui-avatar-group limit="2">
62-
<uui-avatar title="First Last"></uui-avatar>
63-
<uui-avatar title="First Last"></uui-avatar>
64-
<uui-avatar title="First Last"></uui-avatar>
65-
<uui-avatar title="First Last"></uui-avatar>
63+
<uui-avatar title="Firstname Lastname"></uui-avatar>
64+
<uui-avatar title="Firstname Lastname"></uui-avatar>
65+
<uui-avatar title="Firstname Lastname"></uui-avatar>
66+
<uui-avatar title="Firstname Lastname"></uui-avatar>
6667
</uui-avatar-group>`.strings,
6768
},
6869
},

packages/uui-avatar/lib/uui-avatar.element.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ export class UUIAvatarElement extends LitElement {
1010
static styles = [
1111
css`
1212
:host {
13-
display: flex;
13+
display: inline-flex;
1414
align-items: center;
1515
justify-content: center;
1616
position: relative;
1717
overflow: hidden;
1818
border-radius: 50%;
19-
font-weight: bold;
20-
width: 2em;
21-
height: 2em;
19+
font-weight: 700;
20+
-webkit-font-smoothing: subpixel-antialiased;
21+
width: calc(2em + 4px);
22+
height: calc(2em + 4px);
2223
user-select: none;
2324
/* box-sizing: border-box; */
2425
@@ -73,7 +74,7 @@ export class UUIAvatarElement extends LitElement {
7374
* @attr
7475
* @default ''
7576
*/
76-
@property({ type: String })
77+
@property({ type: String, reflect: true })
7778
get title() {
7879
return this._title;
7980
}
@@ -88,13 +89,22 @@ export class UUIAvatarElement extends LitElement {
8889
@state()
8990
private initials = '';
9091

92+
connectedCallback() {
93+
super.connectedCallback();
94+
if (!this.title) {
95+
console.warn(this.tagName + ' needs a `title`', this);
96+
}
97+
}
98+
9199
private createInitials(title: string) {
92100
let initials = '';
93101

94-
const words = (title || '').split(' ');
95-
initials = words[0].substring(0, 1);
96-
if (words.length > 1) {
97-
initials += words[words.length - 1].substring(0, 1);
102+
if (title) {
103+
const words = title.match(/(\w+)/g) || [];
104+
initials = words[0].substring(0, 1);
105+
if (words.length > 1) {
106+
initials += words[words.length - 1].substring(0, 1);
107+
}
98108
}
99109
return initials.toUpperCase();
100110
}

packages/uui-avatar/lib/uui-avatar.story.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Story } from '@storybook/web-components';
22
import { html } from 'lit-html';
33
import '@umbraco-ui/uui-avatar/lib/index';
4+
import { GetRandomUmbracoWordOfWordCount } from '../../../storyhelpers/UmbracoWordGenerator';
45

56
export default {
67
title: 'Displays/Avatar',
78
id: 'uui-avatar',
89
component: 'uui-avatar',
910
args: {
10-
title: 'First Last',
11-
fontSize: 32,
11+
title: GetRandomUmbracoWordOfWordCount(2),
12+
fontSize: 12,
1213
},
1314
// argTypes: {
1415
// 'img-src': { table: { disable: true } },
@@ -47,7 +48,7 @@ AAAOverview.argTypes = {
4748
AAAOverview.parameters = {
4849
docs: {
4950
source: {
50-
code: `<uui-avatar title="First Last"></uui-avatar>`,
51+
code: `<uui-avatar title="Firstname Lastname"></uui-avatar>`,
5152
},
5253
},
5354
};
@@ -58,7 +59,7 @@ Picture.parameters = {
5859
controls: { include: ['imgSrc', 'imgSrcset', 'title'] },
5960
docs: {
6061
source: {
61-
code: `<uui-avatar src="..."></uui-avatar>`,
62+
code: `<uui-avatar src="..." title="Firstname Lastname"></uui-avatar>`,
6263
},
6364
},
6465
};
@@ -88,7 +89,26 @@ SlottedContent.parameters = {
8889
controls: { include: ['slot', 'overflow'] },
8990
docs: {
9091
source: {
91-
code: `<uui-avatar>overflow</uui-avatar>`,
92+
code: `<uui-avatar overflow title="overflow title">overflow content</uui-avatar>`,
93+
},
94+
},
95+
};
96+
97+
export const InlineWithText = (props: any) => html`
98+
<div>
99+
Text
100+
<uui-avatar
101+
title="Hello world"
102+
style="background-color: ${props.backgroundColor}; color: ${props.color}"
103+
>${props.slot}</uui-avatar
104+
>
105+
around
106+
</div>
107+
`;
108+
InlineWithText.parameters = {
109+
docs: {
110+
source: {
111+
code: `Text <uui-avatar title="Hello world">overflow</uui-avatar> around`,
92112
},
93113
},
94114
};

packages/uui-base/lib/mixins/LabelMixin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const LabelMixin = <T extends Constructor<LitElement>>(
3131
connectedCallback() {
3232
super.connectedCallback();
3333
if (!this.label) {
34-
console.warn(this.tagName + ' needs a `label`');
34+
console.warn(this.tagName + ' needs a `label`', this);
3535
}
3636
}
3737

src/components/uui-select-option/uui-select-option.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class UUISelectOptionElement extends LabelMixin('', LitElement) {
7979
if (!this.hasAttribute('aria-selected'))
8080
this.setAttribute('aria-selected', 'false');
8181
if (!this.value) {
82-
console.warn(this.tagName + ' needs a `value`');
82+
console.warn(this.tagName + ' needs a `value`', this);
8383
}
8484
}
8585

storyhelpers/UmbracoWordGenerator.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ export const UmbracoWords: Readonly<string[]> = [
1313
'Infinite Editing',
1414
'Umbraco Socks',
1515
'24 days in Umbraco',
16-
'FAF',
1716
'Spark',
1817
'Package Manifest Podcast',
1918
'Skrift.io',
2019
'UmbrCoach',
2120
'Slave & Eagle',
2221
'Community Teams',
2322
'IRememberBeingDirty',
24-
'GDPR',
25-
'Unicore',
2623
'Media Picker v3',
27-
'Marco',
2824
'Dependency Injection',
2925
'umbraCoffee',
3026
'Community Corner',
@@ -34,7 +30,6 @@ export const UmbracoWords: Readonly<string[]> = [
3430
'The Friendly CMS',
3531
'Block List Editor',
3632
'ImageSharp',
37-
'Smidge',
3833
'ContentService',
3934
'ContentFlow',
4035
'Package Migrations',
@@ -59,8 +54,6 @@ export const UmbracoWords: Readonly<string[]> = [
5954
'Section',
6055
'IUrlProvider',
6156
'The Friendly CMS',
62-
'Gulp',
63-
'End of life',
6457
'Long term support',
6558
'Code of conduct',
6659
'Surface Controller',
@@ -86,6 +79,13 @@ export const UmbracoWords: Readonly<string[]> = [
8679
export function GetRandomUmbracoWord(): string {
8780
return UmbracoWords[Math.floor(Math.random() * UmbracoWords.length)];
8881
}
82+
export function GetRandomUmbracoWordOfWordCount(wordCount: number): string {
83+
const dictionary = UmbracoWords.filter((x: string) => {
84+
const result = x.match(/(\w+)/g);
85+
return result ? result.length === wordCount : false;
86+
});
87+
return dictionary[Math.floor(Math.random() * dictionary.length)];
88+
}
8989
export function ArrayOfUmbracoWords(arrayLength: number): string[] {
9090
return [...Array(arrayLength)].map(() => GetRandomUmbracoWord());
9191
}

0 commit comments

Comments
 (0)