Skip to content

Commit

Permalink
Start of EuiAvatarGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
cchaos committed Mar 5, 2019
1 parent e79fa28 commit ae9e3bd
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src-docs/src/views/avatar/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
EuiAvatar,
EuiSpacer,
EuiTitle,
EuiAvatarGroup,
} from '../../../../src/components';

export default () => (
Expand All @@ -28,5 +29,14 @@ export default () => (
 
<EuiAvatar size="xl" name="Cat" imageUrl="https://source.unsplash.com/64x64/?cat" />


<EuiAvatarGroup
avatars={[
<EuiAvatar key="1" name="Rafael"/>,
<EuiAvatar key="2" name="Donatello" />,
<EuiAvatar key="3" name="Leornardo" color="#BD10E0" />,
<EuiAvatar key="4" name="Michaelangelo" />
]}
/>
</div>
);
51 changes: 51 additions & 0 deletions src/components/avatar/__snapshots__/avatar_group.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiAvatarGroup is rendered 1`] = `
<div
aria-label="aria-label"
class="euiAvatarGroup testClass1 testClass2"
data-test-subj="test subject string"
>
<div
aria-label="Rafael"
class="euiAvatar euiAvatar--m euiAvatar--user"
style="background-image:none;background-color:#F98510;color:#000000"
title="Rafael"
>
<span
aria-hidden="true"
>
R
</span>
</div>
<div
aria-label="Donatello"
class="euiAvatar euiAvatar--m euiAvatar--user"
style="background-image:none;background-color:#920000;color:#FFFFFF"
title="Donatello"
>
<span
aria-hidden="true"
>
D
</span>
</div>
<div
aria-label="Leornardo"
class="euiAvatar euiAvatar--m euiAvatar--user"
style="background-image:none;background-color:#BD10E0;color:#FFFFFF"
title="Leornardo"
>
<span
aria-hidden="true"
>
L
</span>
</div>
<span
class="euiAvatarGroup__more"
>
+1
</span>
</div>
`;
14 changes: 14 additions & 0 deletions src/components/avatar/_avatar_group.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.euiAvatarGroup {
vertical-align: baseline;

> .euiAvatar:not(:first-of-type) {
margin-left: ($euiSizeXS * -1);
box-shadow: 0 0 0 1px $euiColorGhost;
}
}

.euiAvatarGroup__more {
@include euiFontSizeS;
font-weight: $euiFontWeightMedium;
margin-left: $euiSizeXS;
}
1 change: 1 addition & 0 deletions src/components/avatar/_index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import 'avatar';
@import 'avatar_group';
24 changes: 24 additions & 0 deletions src/components/avatar/avatar_group.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';

import { EuiAvatar } from './avatar';
import { EuiAvatarGroup } from './avatar_group';

describe('EuiAvatarGroup', () => {
test('is rendered', () => {
const component = render(
<EuiAvatarGroup
avatars={[
<EuiAvatar key="1" name="Rafael" />,
<EuiAvatar key="2" name="Donatello" />,
<EuiAvatar key="3" name="Leornardo" color="#BD10E0" />,
<EuiAvatar key="4" name="Michaelangelo" />,
]}
{...requiredProps}
/>
);

expect(component).toMatchSnapshot();
});
});
43 changes: 43 additions & 0 deletions src/components/avatar/avatar_group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { HTMLAttributes, ReactNode } from 'react';
import { CommonProps } from '../common';
import classNames from 'classnames';
// import { EuiAvatar } from './avatar';

export type EuiAvatarGroupProps = HTMLAttributes<HTMLDivElement> &
CommonProps & {
/**
* Array of avatars
*/
avatars: ReactNode[];
/**
* How many avatars to show before displaying the more text
*/
maxLength?: number;
};

export const EuiAvatarGroup: React.FunctionComponent<EuiAvatarGroupProps> = ({
className,
avatars,
maxLength = 3,
...rest
}) => {
const classes = classNames('euiAvatarGroup', className);

const visibleChildren = avatars.slice(0, maxLength).map(avatar => avatar);

let moreNode;
if (avatars.length > maxLength) {
moreNode = (
<span className="euiAvatarGroup__more">
+{avatars.length - maxLength}
</span>
);
}

return (
<div className={classes} {...rest}>
{visibleChildren}
{moreNode}
</div>
);
};
1 change: 1 addition & 0 deletions src/components/avatar/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { EuiAvatar } from './avatar';
export { EuiAvatarGroup } from './avatar_group';
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export {

export {
EuiAvatar,
EuiAvatarGroup,
} from './avatar';

export {
Expand Down

0 comments on commit ae9e3bd

Please sign in to comment.