Skip to content

Commit 76e1abd

Browse files
Avatar cmp flexible type added.
ChatItem avatarFlexible prop added.
1 parent f01b9fc commit 76e1abd

6 files changed

Lines changed: 70 additions & 19 deletions

File tree

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Reactjs chat elements
1313
9. [SideBar](#sidebar-component)
1414
10. [Navbar](#navbar-component)
1515
11. [Dropdown](#dropdown-component)
16+
12. [Avatar](#avatar)
1617

1718
## ChatItem Component
1819

@@ -34,6 +35,7 @@ import { ChatItem } from 'react-chat-elements'
3435
| prop | default | type | description |
3536
| ---- | ---- | ---- | ---- |
3637
| avatar | none | string | ChatItem avatar photo url |
38+
| avatarFlexible | false | boolean | flexible ChatItem avatar photo |
3739
| alt | none | string | ChatItem avatar photo alt text |
3840
| title | none | string | ChatItem title |
3941
| subtitle | none | string | ChatItem subtitle |
@@ -326,9 +328,9 @@ import { Navbar } from 'react-chat-elements'
326328
import { Dropdown } from 'react-chat-elements'
327329

328330
<Dropdown
329-
buttonProps={{
330-
text: 'Dropdown',
331-
}}
331+
buttonProps={{
332+
text: 'Dropdown',
333+
}}
332334
items={[
333335
'merhaba',
334336
'lorem',
@@ -348,3 +350,25 @@ import { Dropdown } from 'react-chat-elements'
348350
| items | none | array | dropdown items array |
349351
| onSelect | none | function | item on select |
350352
| buttonProps | none | object | button properties |
353+
354+
355+
## Avatar Component
356+
357+
```javascript
358+
import { Avatar } from 'react-chat-elements'
359+
360+
<Avatar
361+
src={'https://facebook.github.io/react/img/logo.svg'}
362+
alt={'logo'}
363+
size="large"
364+
type="circle flexible"/>
365+
```
366+
367+
#### Avatar props
368+
369+
| prop | default | type | description |
370+
| ---- | ---- | ---- | ---- |
371+
| src | none | image | image src |
372+
| alt | none | string | image alt description |
373+
| size | default | string | image size. default (25px), xsmall(30px), small(35px), medium(40px), large(45px), xlarge (55px) |
374+
| type | default | string | types: default, circle, rounded(border radius 5px), flexible |

example/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export class App extends Component {
7777
return {
7878
id: String(Math.random()),
7979
avatar: `data:image/png;base64,${this.photo()}`,
80+
avatarFlexible: true,
8081
alt: loremIpsum({ count: 2, units: 'words' }),
8182
title: loremIpsum({ count: 2, units: 'words' }),
8283
date: new Date(),

src/Avatar/Avatar.css

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,52 @@
1-
.rce-avatar.default{
1+
.rce-avatar-container {
2+
overflow: hidden;
3+
display: flex;
4+
justify-content: center;
5+
align-items: center;
6+
overflow: hidden;
7+
}
8+
9+
.rce-avatar-container.flexible .rce-avatar {
10+
height: auto !important;
11+
width: 100% !important;
12+
border-radius: unset !important;
13+
overflow: unset !important;
14+
}
15+
16+
.rce-avatar-container.default{
217
width: 25px;
318
height: 25px;
419
}
520

6-
.rce-avatar.rounded{
21+
.rce-avatar-container.rounded{
722
border-radius: 5px;
823
}
924

10-
.rce-avatar.circle{
25+
.rce-avatar-container.circle{
1126
border-radius: 100%;
1227
}
1328

14-
.rce-avatar.xsmall{
29+
.rce-avatar-container.xsmall{
1530
width: 30px;
1631
height: 30px;
1732
}
1833

19-
.rce-avatar.small{
34+
.rce-avatar-container.small{
2035
width: 35px;
2136
height: 35px;
2237
}
2338

24-
.rce-avatar.medium{
39+
.rce-avatar-container.medium{
2540
width: 40px;
2641
height: 40px;
2742
}
2843

29-
.rce-avatar.large{
44+
.rce-avatar-container.large{
3045
width: 45px;
3146
height: 45px;
3247
}
3348

34-
.rce-avatar.xlarge{
49+
.rce-avatar-container.xlarge{
3550
width: 55px;
3651
height: 55px;
37-
}
52+
}

src/Avatar/Avatar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const classNames = require('classnames');
66
export class Avatar extends Component {
77
render() {
88
return (
9-
<img alt={this.props.alt} src={this.props.src} className={classNames('rce-avatar', this.props.type, this.props.size, this.props.className)} />
9+
<div className={classNames('rce-avatar-container', this.props.type, this.props.size, this.props.className)}>
10+
<img alt={this.props.alt} src={this.props.src} className={'rce-avatar'} />
11+
</div>
1012
);
1113
}
1214
}
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Avatar component should render without issues 1`] = `
4-
<img
5-
alt=""
6-
className="rce-avatar default default"
7-
src=""
8-
/>
4+
<div
5+
className="rce-avatar-container default default"
6+
>
7+
<img
8+
alt=""
9+
className="rce-avatar"
10+
src=""
11+
/>
12+
</div>
913
`;

src/ChatItem/ChatItem.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ export class ChatItem extends Component {
1515
onClick={this.props.onClick}>
1616
<div className="rce-citem">
1717
<div className="rce-citem-avatar">
18-
<Avatar src={this.props.avatar} alt={this.props.alt} size="large" type="circle"/>
18+
<Avatar
19+
src={this.props.avatar}
20+
alt={this.props.alt}
21+
size="large"
22+
type={classNames('circle', {'flexible': this.props.avatarFlexible})}/>
1923
</div>
2024

2125
<div className="rce-citem-body">
@@ -50,6 +54,7 @@ ChatItem.defaultProps = {
5054
id: '',
5155
onClick: null,
5256
avatar: '',
57+
avatarFlexible: false,
5358
alt: '',
5459
title: '',
5560
subtitle: '',

0 commit comments

Comments
 (0)