Skip to content

Commit e588ce9

Browse files
committed
(opportunistic) Fix Avatar and BannerNotification; Add prop descriptions
1 parent ca1626d commit e588ce9

File tree

7 files changed

+56
-42
lines changed

7 files changed

+56
-42
lines changed

source/components/Avatar/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
44

5-
import AvatarImage from './AvatarImage';
65
import Badge from './Badge';
6+
import { getAvatarImage } from './utils';
77

88
import './styles.scss';
99

10-
const getAvatarImage = (href, alt, src) => {
11-
const avatarImage = <AvatarImage alt={alt} src={src} />;
12-
return href ? <a href={href}>{avatarImage}</a> : avatarImage;
13-
};
14-
1510
const Avatar = ({
1611
alt,
1712
badge,

source/components/Avatar/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
import AvatarImage from './AvatarImage';
4+
5+
// eslint-disable-next-line
6+
export function getAvatarImage(href, alt, src) {
7+
const avatarImage = <AvatarImage alt={alt} src={src} />;
8+
return href ? <a href={href}>{avatarImage}</a> : avatarImage;
9+
}

source/components/AvatarStack/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Defaults:
22
```js
3-
<AvatarStack
3+
<AvatarStack
44
avatars={[{ src: 'https://static.wikia.nocookie.net/438f6e23-1a0f-4351-a34d-6f8fa734a246', alt: 'Image', link: 'some://valid.url', badge: 'admin' }, { src: 'https://static.wikia.nocookie.net/438f6e23-1a0f-4351-a34d-6f8fa734a246', alt: 'Image', link: 'some://valid.url', badge: 'staff' }, { src: 'https://static.wikia.nocookie.net/fcdbab4c-8838-487e-89fd-5f0782974edf', alt: 'Image', link: 'some://valid.url', badge: 'vstf' }]}
55
/>
66
```
77

88
With maxStackSize
99

1010
```js
11-
<AvatarStack
11+
<AvatarStack
1212
avatars={[{ src: 'https://static.wikia.nocookie.net/438f6e23-1a0f-4351-a34d-6f8fa734a246', alt: 'Image', link: 'some://valid.url', badge: 'admin' }, { src: 'https://static.wikia.nocookie.net/438f6e23-1a0f-4351-a34d-6f8fa734a246', alt: 'Image', link: 'some://valid.url', badge: 'staff' }, { src: 'https://static.wikia.nocookie.net/fcdbab4c-8838-487e-89fd-5f0782974edf', alt: 'Image', link: 'some://valid.url', badge: 'vstf' }]}
1313
maxStackSize={2}
1414
/>
@@ -17,17 +17,17 @@ With maxStackSize
1717
With hidden overflow
1818

1919
```js
20-
<AvatarStack
20+
<AvatarStack
2121
avatars={[{ src: 'https://static.wikia.nocookie.net/438f6e23-1a0f-4351-a34d-6f8fa734a246', alt: 'Image', link: 'some://valid.url', badge: 'admin' }, { src: 'https://static.wikia.nocookie.net/438f6e23-1a0f-4351-a34d-6f8fa734a246', alt: 'Image', link: 'some://valid.url', badge: 'staff' }, { src: 'https://static.wikia.nocookie.net/fcdbab4c-8838-487e-89fd-5f0782974edf', alt: 'Image', link: 'some://valid.url', badge: 'vstf' }]}
2222
maxStackSize={2}
23-
hideOverflow={true}
23+
hideOverflow
2424
/>
2525
```
2626

2727
With overridden counter
2828

2929
```js
30-
<AvatarStack
30+
<AvatarStack
3131
avatars={[{ src: 'https://static.wikia.nocookie.net/438f6e23-1a0f-4351-a34d-6f8fa734a246', alt: 'Image', link: 'some://valid.url', badge: 'admin' }, { src: 'https://static.wikia.nocookie.net/438f6e23-1a0f-4351-a34d-6f8fa734a246', alt: 'Image', link: 'some://valid.url', badge: 'staff' }, { src: 'https://static.wikia.nocookie.net/fcdbab4c-8838-487e-89fd-5f0782974edf', alt: 'Image', link: 'some://valid.url', badge: 'vstf' }]}
3232
maxStackSize={2}
3333
overrideCount={6}

source/components/AvatarStack/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ const AvatarStack = ({ avatars, overrideCount, maxStackSize, hideOverflow, class
3232
};
3333

3434
AvatarStack.propTypes = {
35+
/* An array of `Avatar` props */
3536
avatars: PropTypes.arrayOf(PropTypes.shape()).isRequired,
37+
/* Additional class name */
3638
className: PropTypes.string,
39+
/* Flag to hide overflow */
3740
hideOverflow: PropTypes.bool,
41+
/* Max stack size */
3842
maxStackSize: PropTypes.number,
43+
/* If specified, it will be used instead of `avatars.length` */
3944
overrideCount: PropTypes.number,
4045
};
4146

source/components/BannerNotification/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ But it can be rendered with close buttton:
1010

1111
Or with extra HTML:
1212
```js
13-
<BannerNotification type={'alert'}onClose={() => alert('Click')}>
13+
<BannerNotification type={'alert'} onClose={() => alert('Click')}>
1414
This is a text <a href="http://example.com">with a link</a>
1515
</BannerNotification>
1616
```

source/components/BannerNotification/index.js

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,10 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import IconCloseTiny from '../../icons/IconCloseTiny';
5-
import IconAlertSmall from '../../icons/IconAlertSmall';
6-
import IconCheckmarkSmall from '../../icons/IconCheckmarkSmall';
7-
import IconErrorSmall from '../../icons/IconErrorSmall';
8-
import IconFlagSmall from '../../icons/IconFlagSmall';
95

10-
import './styles.scss';
11-
12-
function getIcon(type) {
13-
switch (type) {
14-
case ('alert'):
15-
return <IconErrorSmall className="wds-banner-notification__icon-mark" />;
16-
case ('warning'):
17-
return <IconAlertSmall className="wds-banner-notification__icon-mark" />;
18-
case ('success'):
19-
return <IconCheckmarkSmall className="wds-banner-notification__icon-mark" />;
20-
default:
21-
return <IconFlagSmall className="wds-banner-notification__icon-mark" />;
22-
}
23-
}
6+
import { getClassName, getIcon } from './utils';
247

25-
function getClassName(type) {
26-
switch (type) {
27-
case ('alert'):
28-
return 'wds-alert';
29-
case ('warning'):
30-
return 'wds-warning';
31-
case ('success'):
32-
return 'wds-success';
33-
default:
34-
return 'wds-message';
35-
}
36-
}
8+
import './styles.scss';
379

3810
/**
3911
* This is a single component used in `BannerNotifications` component.
@@ -48,6 +20,7 @@ const BannerNotification = ({
4820
</div>
4921
);
5022

23+
5124
BannerNotification.propTypes = {
5225
/** Children to display */
5326
children: PropTypes.node,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
3+
import IconAlertSmall from '../../icons/IconAlertSmall';
4+
import IconCheckmarkSmall from '../../icons/IconCheckmarkSmall';
5+
import IconErrorSmall from '../../icons/IconErrorSmall';
6+
import IconFlagSmall from '../../icons/IconFlagSmall';
7+
8+
export function getIcon(type) {
9+
switch (type) {
10+
case ('alert'):
11+
return <IconErrorSmall className="wds-banner-notification__icon-mark" />;
12+
case ('warning'):
13+
return <IconAlertSmall className="wds-banner-notification__icon-mark" />;
14+
case ('success'):
15+
return <IconCheckmarkSmall className="wds-banner-notification__icon-mark" />;
16+
default:
17+
return <IconFlagSmall className="wds-banner-notification__icon-mark" />;
18+
}
19+
}
20+
21+
export function getClassName(type) {
22+
switch (type) {
23+
case ('alert'):
24+
return 'wds-alert';
25+
case ('warning'):
26+
return 'wds-warning';
27+
case ('success'):
28+
return 'wds-success';
29+
default:
30+
return 'wds-message';
31+
}
32+
}

0 commit comments

Comments
 (0)