Skip to content

Commit 0f508af

Browse files
statusColorType added.
1 parent 9e6dc33 commit 0f508af

5 files changed

Lines changed: 42 additions & 24 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import { ChatItem } from 'react-chat-elements'
9191
| onClick | none | function | ChatItem on click |
9292
| onContextMenu | none | function | ChatItem on context menu |
9393
| statusColor | none | color | ChatItem status color |
94+
| statusColorType | badge | string | ChatItem status color type (encircle, badge) |
9495
| statusText | none | color | ChatItem status text |
9596
| lazyLoadingImage | none | image path | lazy loading image |
9697

@@ -522,4 +523,4 @@ import { SpotifyMessage } from 'react-chat-elements'
522523
| view | list | string | spotify view type (list or coverart) |
523524
| data | {} | object | message data |
524525
| width | 300 | int | spotify embed width |
525-
| height | 380 | int | spotify embed height |
526+
| height | 380 | int | spotify embed height |

example/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export class App extends Component {
127127
avatar: `data:image/png;base64,${this.photo()}`,
128128
avatarFlexible: true,
129129
statusColor: 'lightgreen',
130+
statusColorType: parseInt(Math.random() * 100 % 2) === 1 ? 'encircle' : undefined,
130131
alt: loremIpsum({ count: 2, units: 'words' }),
131132
title: loremIpsum({ count: 2, units: 'words' }),
132133
date: new Date(),

src/Avatar/Avatar.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
display: flex;
44
justify-content: center;
55
align-items: center;
6-
box-sizing: border-box;
7-
position: relative;
86
}
97

108
.rce-avatar-container .rce-avatar {
@@ -72,3 +70,8 @@
7270
.rce-avatar-lazy {
7371
animation: avatarLazy normal 2s infinite ease-in-out;
7472
}
73+
74+
.rce-avatar-container.rce-citem-avatar-encircle-status {
75+
box-sizing: border-box;
76+
position: relative;
77+
}

src/ChatItem/ChatItem.css

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,10 @@
33
display: block;
44
overflow: hidden;
55
min-width: 240px;
6-
position: relative;
76
}
87

9-
.rce-container-citem::after {
10-
content: "";
11-
width: 85%;
12-
height: 1px;
13-
background: #f1f1f1;
14-
margin: auto;
15-
position: absolute;
16-
left: 0;
17-
right: 0;
18-
bottom: 0;
19-
}
20-
21-
.rce-container-citem:last-of-type::after {
22-
opacity: 0;
8+
.rce-container-citem.rce-citem-status-encircle {
9+
position: relative;
2310
}
2411

2512
.rce-citem {
@@ -40,14 +27,27 @@
4027
}
4128

4229
.rce-citem-avatar {
43-
padding: 0 13px 0 13px;
30+
position: relative;
31+
padding: 0 15px 0 15px;
4432
justify-content: center;
4533
display: flex;
4634
align-items: center;
4735
}
4836

4937
.rce-citem-status {
38+
width: 20px;
39+
height: 20px;
40+
bottom: 10px;
41+
right: 10px;
5042
position: absolute;
43+
border-radius: 100%;
44+
display: flex;
45+
align-items: center;
46+
justify-content: center;
47+
background: #ccc;
48+
}
49+
50+
.rce-citem-avatar.rce-citem-status-encircle .rce-citem-status {
5151
left:0;
5252
right:0;
5353
top: 0;
@@ -56,9 +56,6 @@
5656
height: 100%;
5757
background: transparent;
5858
margin: auto;
59-
display: flex;
60-
align-items: center;
61-
justify-content: center;
6259
border-radius: 100%;
6360
}
6461

@@ -83,6 +80,7 @@
8380
display: flex;
8481
justify-content: center;
8582
padding-right: 15px;
83+
border-bottom: 1px solid rgba(0,0,0,.05);
8684
overflow: hidden;
8785
}
8886

src/ChatItem/ChatItem.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,34 @@ import classNames from 'classnames';
1212
export class ChatItem extends Component {
1313

1414
render() {
15+
const statusColorType = this.props.statusColorType;
16+
1517
return (
1618
<div
1719
className={classNames('rce-container-citem', this.props.className)}
1820
onClick={this.props.onClick}
1921
onContextMenu={this.props.onContextMenu}>
2022
<div className="rce-citem">
21-
<div className="rce-citem-avatar">
23+
<div className={classNames(
24+
"rce-citem-avatar",
25+
{
26+
'rce-citem-status-encircle': statusColorType === 'encircle',
27+
}
28+
)}>
2229
<Avatar
2330
src={this.props.avatar}
2431
alt={this.props.alt}
32+
className={statusColorType === 'encircle' ? 'rce-citem-avatar-encircle-status' : ''}
2533
size="large"
2634
sideElement={
2735
this.props.statusColor &&
28-
<span className='rce-citem-status' style={{boxShadow: `inset 0 0 0 2px ${this.props.statusColor}, inset 0 0 0 5px #FFFFFF`}}>
36+
<span
37+
className='rce-citem-status'
38+
style={statusColorType === 'encircle' ? {
39+
boxShadow: `inset 0 0 0 2px ${this.props.statusColor}, inset 0 0 0 5px #FFFFFF`
40+
} : {
41+
backgroundColor: this.props.statusColor,
42+
}}>
2943
{this.props.statusText}
3044
</span>
3145
}
@@ -80,6 +94,7 @@ ChatItem.defaultProps = {
8094
date: new Date(),
8195
unread: 0,
8296
statusColor: null,
97+
statusColorType: 'badge',
8398
statusText: null,
8499
dateString: null,
85100
lazyLoadingImage: undefined,

0 commit comments

Comments
 (0)