Skip to content

Commit

Permalink
Added more customizations to Avatar (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchaos authored Jun 6, 2018
1 parent 560abe4 commit 6d08912
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Added `resize` prop to `EuiTextArea` that defaults to ‘vertical’ (only height) ([#894](https://github.com/elastic/eui/pull/894))
- Added multiple style-only adjustments to `EuiFormControlLayout` buttons/icons ([#894](https://github.com/elastic/eui/pull/894))
- Shifted `readOnly` inputs to not have left padding unless it has an icon ([#894](https://github.com/elastic/eui/pull/894))
- Added more customization options to `EuiAvatar` ([#903](https://github.com/elastic/eui/pull/903))

**Bug fixes**

Expand Down
24 changes: 17 additions & 7 deletions src-docs/src/views/avatar/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@ import React from 'react';

import {
EuiAvatar,
EuiHorizontalRule,
EuiSpacer,
EuiTitle,
} from '../../../../src/components';

export default () => (
<div>
<EuiAvatar size="s" name="Rafael"/>
&emsp;
<EuiAvatar size="m" name="Donatello" />
<EuiAvatar size="l" name="Leornardo" />
&emsp;
<EuiAvatar size="l" name="Leornardo" color="#BD10E0" />
&emsp;
<EuiAvatar size="xl" name="Michaelangelo" />

<EuiHorizontalRule margin="l" />
<EuiSpacer />
<EuiTitle size="xs"><h3>With image</h3></EuiTitle>
<EuiSpacer />

<EuiAvatar size="s" name="Cat" imageUrl="https://source.unsplash.com/64x64/?cat" />
&emsp;
<EuiAvatar size="m" name="Cat" imageUrl="https://source.unsplash.com/64x64/?cat" />
&emsp;
<EuiAvatar size="l" name="Cat" imageUrl="https://source.unsplash.com/64x64/?cat" />
&emsp;
<EuiAvatar size="xl" name="Cat" imageUrl="https://source.unsplash.com/64x64/?cat" />

<EuiAvatar size="s" name="Cat" imageUrl="https://lorempixel.com/64/64/cats/" />
<EuiAvatar size="m" name="Cat" imageUrl="https://lorempixel.com/64/64/cats/" />
<EuiAvatar size="l" name="Cat" imageUrl="https://lorempixel.com/64/64/cats/" />
<EuiAvatar size="xl" name="Cat" imageUrl="https://lorempixel.com/64/64/cats/" />
</div>
);
46 changes: 40 additions & 6 deletions src-docs/src/views/avatar/avatar_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import Avatar from './avatar';
const avatarSource = require('!!raw-loader!./avatar');
const avatarHtml = renderToHtml(Avatar);

import AvatarInitials from './avatar_initials';
const avatarInitialsSource = require('!!raw-loader!./avatar_initials');
const avatarInitialsHtml = renderToHtml(AvatarInitials);

export const AvatarExample = {
title: 'Avatar',
sections: [{
Expand All @@ -26,14 +30,44 @@ export const AvatarExample = {
code: avatarHtml,
}],
text: (
<p>
The <EuiCode>Avatar</EuiCode> component creates a user icon. It will
accept <EuiCode>name</EuiCode> (required) and <EuiCode>image</EuiCode> props
and will configure the display and accessibility as needed. The background colors
come from the set of colors used for visualiations.
</p>
<div>
<p>
The <EuiCode>Avatar</EuiCode> component creates a user icon. It will
accept <EuiCode>name</EuiCode> (required) and <EuiCode>image</EuiCode> props
and will configure the display and accessibility as needed. By default, the background colors
come from the set of colors used for visualizations. Otherwise you can pass a
hex value to the <EuiCode>color</EuiCode> prop.
</p>
</div>
),
props: { EuiAvatar },
demo: <Avatar />,
},{
title: 'Initials',
source: [{
type: GuideSectionTypes.JS,
code: avatarInitialsSource,
}, {
type: GuideSectionTypes.HTML,
code: avatarInitialsHtml,
}],
text: (
<div>
<p>
The initials displayed in the avatar try to be smart based on the name prop.
If the name contains spaces, it will display the first character of each
word, <strong>always maxing out at 2 characters</strong>. You can customize this by
passing a combination of <EuiCode>initialsLength</EuiCode> and/or <EuiCode>initials</EuiCode> props.
However, the avatar will still always max out at 2 characters.
</p>
<h3>Types</h3>
<p>
The avatar <EuiCode>type</EuiCode>, which primarily defines the shape,
is keyworded and can be <EuiCode>&quot;user&quot;</EuiCode> (default)
or <EuiCode>&quot;space&quot;</EuiCode> (for workspaces).
</p>
</div>
),
demo: <AvatarInitials />,
}]
};
36 changes: 36 additions & 0 deletions src-docs/src/views/avatar/avatar_initials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';

import {
EuiAvatar,
EuiTitle,
EuiSpacer,
} from '../../../../src/components';

export default () => (
<div>

<EuiTitle size="xs"><h3>Single vs multi-word</h3></EuiTitle>
<EuiSpacer />

<EuiAvatar size="m" name="Single" />
&emsp;
<EuiAvatar size="m" name="Two Words" />
&emsp;
<EuiAvatar size="m" name="More Than Two Words" />
&emsp;
<EuiAvatar size="m" name="lowercase words"/>

<EuiSpacer />
<EuiTitle size="xs"><h4>Custom &amp; Spaces type</h4></EuiTitle>
<EuiSpacer />

<EuiAvatar size="m" type="space" name="Kibana" initialsLength={2} />
&emsp;
<EuiAvatar size="m" type="space" name="Leornardo Dude" initialsLength={1} />
&emsp;
<EuiAvatar size="m" type="space" name="Not provided" initials="?" />
&emsp;
<EuiAvatar size="m" type="space" name="Engineering Space" initials="En" initialsLength={2} />

</div>
);
95 changes: 81 additions & 14 deletions src/components/avatar/__snapshots__/avatar.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@
exports[`EuiAvatar is rendered 1`] = `
<div
aria-label="aria-label"
class="euiAvatar euiAvatar--m testClass1 testClass2"
class="euiAvatar euiAvatar--m euiAvatar--user testClass1 testClass2"
data-test-subj="test subject string"
style="background-image:none;background-color:#FEB6DB"
style="background-image:none;background-color:#FEB6DB;color:#000000"
title="name"
>
<span
aria-hidden="true"
>
n
</span>
</div>
`;

exports[`EuiAvatar props color is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--m euiAvatar--user"
style="background-image:none;background-color:#000;color:#FFFFFF"
title="name"
>
<span
aria-hidden="true"
Expand All @@ -18,16 +34,48 @@ exports[`EuiAvatar is rendered 1`] = `
exports[`EuiAvatar props imageUrl is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--m"
style="background-image:url(image url);background-color:#FEB6DB"
class="euiAvatar euiAvatar--m euiAvatar--user"
style="background-image:url(image url);background-color:#FEB6DB;color:#000000"
title="name"
/>
`;

exports[`EuiAvatar props initials is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--m euiAvatar--user"
style="background-image:none;background-color:#FEB6DB;color:#000000"
title="name"
>
<span
aria-hidden="true"
>
n
</span>
</div>
`;

exports[`EuiAvatar props initialsLength is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--m euiAvatar--user"
style="background-image:none;background-color:#FEB6DB;color:#000000"
title="name"
>
<span
aria-hidden="true"
>
na
</span>
</div>
`;

exports[`EuiAvatar props size l is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--l"
style="background-image:none;background-color:#FEB6DB"
class="euiAvatar euiAvatar--l euiAvatar--user"
style="background-image:none;background-color:#FEB6DB;color:#000000"
title="name"
>
<span
aria-hidden="true"
Expand All @@ -40,8 +88,9 @@ exports[`EuiAvatar props size l is rendered 1`] = `
exports[`EuiAvatar props size m is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--m"
style="background-image:none;background-color:#FEB6DB"
class="euiAvatar euiAvatar--m euiAvatar--user"
style="background-image:none;background-color:#FEB6DB;color:#000000"
title="name"
>
<span
aria-hidden="true"
Expand All @@ -54,8 +103,9 @@ exports[`EuiAvatar props size m is rendered 1`] = `
exports[`EuiAvatar props size none is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar"
style="background-image:none;background-color:#FEB6DB"
class="euiAvatar euiAvatar--user"
style="background-image:none;background-color:#FEB6DB;color:#000000"
title="name"
>
<span
aria-hidden="true"
Expand All @@ -68,8 +118,9 @@ exports[`EuiAvatar props size none is rendered 1`] = `
exports[`EuiAvatar props size s is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--s"
style="background-image:none;background-color:#FEB6DB"
class="euiAvatar euiAvatar--s euiAvatar--user"
style="background-image:none;background-color:#FEB6DB;color:#000000"
title="name"
>
<span
aria-hidden="true"
Expand All @@ -82,8 +133,24 @@ exports[`EuiAvatar props size s is rendered 1`] = `
exports[`EuiAvatar props size xl is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--xl"
style="background-image:none;background-color:#FEB6DB"
class="euiAvatar euiAvatar--xl euiAvatar--user"
style="background-image:none;background-color:#FEB6DB;color:#000000"
title="name"
>
<span
aria-hidden="true"
>
n
</span>
</div>
`;

exports[`EuiAvatar props type is rendered 1`] = `
<div
aria-label="name"
class="euiAvatar euiAvatar--m euiAvatar--space"
style="background-image:none;background-color:#FEB6DB;color:#000000"
title="name"
>
<span
aria-hidden="true"
Expand Down
59 changes: 33 additions & 26 deletions src/components/avatar/_avatar.scss
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
.euiAvatar {
@include innerBorder('dark', 50%);

border-radius: 50%;
display: inline-block;
background-size: cover;
color: $euiColorGhost;
text-align: center;
text-shadow: 1px 1px rgba(0,0,0,.2);
vertical-align: middle;
overflow-x: hidden;
cursor: default; // Make sure we don't get the text cursor
}

.euiAvatar--s {
width: $euiSizeL;
height: $euiSizeL;
line-height: $euiSizeL;
font-size: $euiSizeM;
.euiAvatar--user {
@include innerBorder('dark', 50%, .05);
border-radius: 50%;
}

.euiAvatar--m {
width: $euiSizeXL;
height: $euiSizeXL;
line-height: $euiSizeXL;
font-size: $euiSize;
.euiAvatar--space {
@include innerBorder('dark', $euiBorderRadius, .05);
border-radius: $euiBorderRadius;
}

.euiAvatar--l {
width: $euiSizeXXL;
height: $euiSizeXXL;
line-height: $euiSizeXXL;
font-size: $euiSizeL;
}
// Modifiers for sizing.
$avatarSizing: (
s: (
size: $euiSizeL,
font-size: $euiSizeM
),
m: (
size: $euiSizeXL,
font-size: $euiSize
),
l: (
size: $euiSizeXXL,
font-size: $euiSizeL
),
xl: (
size: ($euiSize * 4),
font-size: $euiSizeXL
),
);

.euiAvatar--xl {
width: $euiSize * 4;
height: $euiSize * 4;
line-height: $euiSize * 4;
font-size: $euiSizeXL;
@each $size, $map in $avatarSizing {
.euiAvatar--#{$size} {
@include size(map-get($map, 'size'));
line-height: map-get($map, 'size');
font-size: map-get($map, 'font-size');
}
}
Loading

0 comments on commit 6d08912

Please sign in to comment.