Skip to content

Commit 55f759b

Browse files
author
emregudur
committed
some issues fixed, new feature added to chatlist: customStatusComponents
1 parent 5ace70d commit 55f759b

10 files changed

Lines changed: 1966 additions & 1927 deletions

File tree

example/components/ChatListExample.tsx

Lines changed: 30 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
import Identicon from 'identicon.js'
22
import loremIpsum from 'lorem-ipsum'
33
import React, { useEffect, useState } from 'react'
4-
import { FaSquare } from 'react-icons/fa'
5-
import { MdOutlineMoreVert } from 'react-icons/md'
4+
import { BsListTask } from 'react-icons/bs'
65
import ChatList from '../../src/ChatList/ChatList'
7-
import Dropdown from '../../src/Dropdown/Dropdown'
86
import SideBar from '../../src/SideBar/SideBar'
7+
import { IChatItemProps } from '../../src/type'
8+
9+
function Test(params: any) {
10+
return (
11+
<div className='rce-citem-body--bottom-status-icon' onClick={() => console.log('clicked')}>
12+
<span
13+
style={{
14+
'fontSize': '10px',
15+
'position': 'absolute',
16+
'padding': '2px',
17+
'right': '-12px',
18+
'top': '-6px',
19+
'background': 'red',
20+
'color': 'white',
21+
'borderRadius': '100%',
22+
'width': '12px',
23+
'height': '12px',
24+
'textAlign': 'center',
25+
}}
26+
>
27+
{Math.ceil(Math.random() * 9) + 1}
28+
</span>
29+
<BsListTask />
30+
</div>
31+
)
32+
}
933

1034
function ChatListExample() {
1135
const photo = (size: number) => {
@@ -15,7 +39,7 @@ function ChatListExample() {
1539
}).toString()
1640
}
1741

18-
const [chatListAray, setChatListAray] = useState([
42+
const [chatListAray, setChatListAray] = useState<IChatItemProps[]>([
1943
{
2044
id: String(Math.random()),
2145
avatar: `data:image/png;base64,${photo(20)}`,
@@ -30,50 +54,7 @@ function ChatListExample() {
3054
muted: Math.floor((Math.random() * 10) % 2) === 1,
3155
showMute: Math.floor((Math.random() * 10) % 2) === 1,
3256
showVideoCall: Math.floor((Math.random() * 10) % 2) === 1,
33-
dropdownMenu: (
34-
<Dropdown
35-
onSelect={() => {}}
36-
animationPosition='norteast'
37-
title='Dropdown Title'
38-
buttonProps={{
39-
type: 'transparent',
40-
color: '#cecece',
41-
icon: {
42-
component: <MdOutlineMoreVert />,
43-
size: 24,
44-
},
45-
}}
46-
items={[
47-
{
48-
icon: {
49-
component: <FaSquare />,
50-
float: 'left',
51-
color: 'red',
52-
size: 22,
53-
},
54-
text: 'Menu Item',
55-
},
56-
{
57-
icon: {
58-
component: <FaSquare />,
59-
float: 'left',
60-
color: 'purple',
61-
size: 22,
62-
},
63-
text: 'Menu Item',
64-
},
65-
{
66-
icon: {
67-
component: <FaSquare />,
68-
float: 'left',
69-
color: 'yellow',
70-
size: 22,
71-
},
72-
text: 'Menu Item',
73-
},
74-
]}
75-
/>
76-
),
57+
customStatusComponents: [Test],
7758
},
7859
])
7960

@@ -95,50 +76,7 @@ function ChatListExample() {
9576
muted: Math.floor((Math.random() * 10) % 2) === 1,
9677
showMute: Math.floor((Math.random() * 10) % 2) === 1,
9778
showVideoCall: Math.floor((Math.random() * 10) % 2) === 1,
98-
dropdownMenu: (
99-
<Dropdown
100-
onSelect={() => {}}
101-
animationPosition='norteast'
102-
title='Dropdown Title'
103-
buttonProps={{
104-
type: 'transparent',
105-
color: '#cecece',
106-
icon: {
107-
component: <MdOutlineMoreVert />,
108-
size: 24,
109-
},
110-
}}
111-
items={[
112-
{
113-
icon: {
114-
component: <FaSquare />,
115-
float: 'left',
116-
color: 'red',
117-
size: 22,
118-
},
119-
text: 'Menu Item',
120-
},
121-
{
122-
icon: {
123-
component: <FaSquare />,
124-
float: 'left',
125-
color: 'purple',
126-
size: 22,
127-
},
128-
text: 'Menu Item',
129-
},
130-
{
131-
icon: {
132-
component: <FaSquare />,
133-
float: 'left',
134-
color: 'yellow',
135-
size: 22,
136-
},
137-
text: 'Menu Item',
138-
},
139-
]}
140-
/>
141-
),
79+
customStatusComponents: [Test],
14280
},
14381
])
14482
}, [chatListAray])

example/components/MessageListExample.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ function MessageListExample() {
112112
referance={messageListReferance}
113113
dataSource={messageListArray}
114114
lockable={true}
115-
downButton={false}
115+
downButton={true}
116116
downButtonBadge={10}
117117
sendMessagePreview={true}
118+
messageBoxStyles={{ backgroundColor: 'red' }}
119+
notchStyle={{ fill: 'red' }}
118120
/>
119121

120122
<div

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-chat-elements",
3-
"version": "12.0.5",
3+
"version": "12.0.6",
44
"description": "Reactjs chat components",
55
"author": "Avare Kodcu <abdurrahmaneker58@gmail.com>",
66
"main": "dist/main.js",

src/Avatar/Avatar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const Avatar: React.FC<IAvatarProps> = ({ type = 'default', size = 'default', la
5858
}
5959

6060
return (
61+
// @ts-ignore
6162
<div className={classNames('rce-avatar-container', type, size, props.className)}>
6263
{props.letterItem ? (
6364
<div className='rce-avatar-letter-background' style={{ backgroundColor: stringToColour(props.letterItem.id) }}>

src/ChatItem/ChatItem.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@
132132
background: red;
133133
}
134134

135+
.rce-citem-body--bottom-status-icon {
136+
position: relative;
137+
margin-left: 3px;
138+
width: 18px;
139+
height: 18px;
140+
align-items: center;
141+
justify-content: center;
142+
display: flex;
143+
}
144+
135145
.rce-citem-body--bottom-tools {
136146
align-items: center;
137147
justify-content: center;

src/ChatItem/ChatItem.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ const ChatItem: React.FC<IChatItemProps> = ({
7171
<div className='rce-citem' onDragOver={onDragOver} onDragEnter={onDragEnter} onDragLeave={onDragLeave} onDrop={onDrop}>
7272
{!!props.onDragComponent && onDrag && props.onDragComponent(props.id)}
7373
{((onDrag && !props.onDragComponent) || !onDrag) && [
74-
<div className={classNames('rce-citem-avatar', { 'rce-citem-status-encircle': statusColorType === 'encircle' })}>
74+
<div
75+
key={'avatar'}
76+
className={classNames('rce-citem-avatar', { 'rce-citem-status-encircle': statusColorType === 'encircle' })}
77+
>
7578
<Avatar
7679
src={props.avatar}
7780
alt={props.alt}
@@ -103,7 +106,7 @@ const ChatItem: React.FC<IChatItemProps> = ({
103106
type={classNames('circle', { 'flexible': avatarFlexible })}
104107
/>
105108
</div>,
106-
<div className='rce-citem-body'>
109+
<div key={'rce-citem-body'} className='rce-citem-body'>
107110
<div className='rce-citem-body--top'>
108111
<div className='rce-citem-body--top-title'>{props.title}</div>
109112
<div className='rce-citem-body--top-time'>{date && (props.dateString || format(date))}</div>
@@ -132,6 +135,7 @@ const ChatItem: React.FC<IChatItemProps> = ({
132135
)}
133136
</div>
134137
<div className='rce-citem-body--bottom-status'>{unread && unread > 0 ? <span>{unread}</span> : null}</div>
138+
{props.customStatusComponents !== undefined ? props.customStatusComponents.map(Item => <Item />) : null}
135139
</div>
136140
</div>,
137141
]}

src/MessageBox/MessageBox.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { format } from 'timeago.js'
2323
import classNames from 'classnames'
2424
import { MessageBoxType } from '../type'
2525

26-
const MessageBox: React.FC<MessageBoxType> = ({ focus = false, notch = true, ...props }) => {
26+
const MessageBox: React.FC<MessageBoxType> = ({ focus = false, notch = true, styles, ...props }) => {
2727
const prevProps = useRef(focus)
2828
const messageRef = useRef<HTMLDivElement>(null)
2929

@@ -53,6 +53,7 @@ const MessageBox: React.FC<MessageBoxType> = ({ focus = false, notch = true, ...
5353
<SystemMessage {...props} focus={focus} notch={notch} />
5454
) : (
5555
<div
56+
style={styles}
5657
className={classNames(
5758
positionCls,
5859
{ 'rce-mbox--clear-padding': thatAbsoluteTime },
@@ -187,6 +188,7 @@ const MessageBox: React.FC<MessageBoxType> = ({ focus = false, notch = true, ...
187188
{notch &&
188189
(props.position === 'right' ? (
189190
<svg
191+
style={props.notchStyle}
190192
className={classNames('rce-mbox-right-notch', { 'message-focus': focus })}
191193
xmlns='http://www.w3.org/2000/svg'
192194
viewBox='0 0 20 20'
@@ -196,6 +198,7 @@ const MessageBox: React.FC<MessageBoxType> = ({ focus = false, notch = true, ...
196198
) : (
197199
<div>
198200
<svg
201+
style={props.notchStyle}
199202
className={classNames('rce-mbox-left-notch', { 'message-focus': focus })}
200203
xmlns='http://www.w3.org/2000/svg'
201204
viewBox='0 0 20 20'

src/MessageList/MessageList.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const MessageList: FC<IMessageListProps> = ({
1111
referance = null,
1212
lockable = false,
1313
toBottomHeight = 300,
14-
downButton = true,
14+
downButton,
1515
...props
1616
}) => {
1717
const [scrollBottom, setScrollBottom] = useState(0)
@@ -165,13 +165,17 @@ const MessageList: FC<IMessageListProps> = ({
165165
onMeetingVideoLinkClick={props.onMeetingVideoLinkClick}
166166
onMeetingLinkClick={props.onMeetingLinkClick && ((e: React.MouseEvent<HTMLElement>) => onMeetingLinkClick(x, i, e))}
167167
actionButtons={props.actionButtons}
168+
styles={props.messageBoxStyles}
169+
notchStyle={props.notchStyle}
168170
/>
169171
))}
170172
</div>
171173
{downButton === true && _downButton && toBottomHeight !== '100%' && (
172174
<div className='rce-mlist-down-button' onClick={toBottom}>
173175
<FaChevronDown />
174-
{props.downButtonBadge > 0 && <span className='rce-mlist-down-button--badge'>{props.downButtonBadge.toString()}</span>}
176+
{props.downButtonBadge !== undefined ? (
177+
<span className='rce-mlist-down-button--badge'>{props.downButtonBadge.toString()}</span>
178+
) : null}
175179
</div>
176180
)}
177181
</div>

src/type.d.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface IChatItemProps {
5959
onDragLeave?: Function
6060
onDragComponent?: any
6161
letterItem?: ILetterItem
62+
customStatusComponents?: React.ElementType<any>[]
6263
}
6364

6465
/**
@@ -533,6 +534,8 @@ export interface IMessageBoxProps {
533534
onMeetingLinkClick?: React.MouseEventHandler
534535
onMeetingTitleClick?: React.MouseEventHandler
535536
onMeetingVideoLinkClick?: React.MouseEventHandler
537+
styles?: React.CSSProperties
538+
notchStyle?: React.CSSProperties
536539
}
537540

538541
/**
@@ -578,9 +581,9 @@ export interface IMessageListProps {
578581
actionButtons?: MeetingLinkActionButtons[]
579582
lockable: boolean
580583
toBottomHeight?: String | number
581-
downButton: boolean
582-
downButtonBadge: number
583-
sendMessagePreview: boolean
584+
downButton?: boolean
585+
downButtonBadge?: number
586+
sendMessagePreview?: boolean
584587
onScroll?: React.UIEventHandler
585588
onContextMenu?: MessageListEvent
586589
onDownButtonClick?: React.RefObject<HTMLButtonElement>
@@ -599,6 +602,8 @@ export interface IMessageListProps {
599602
onMeetingTitleClick?: React.MouseEventHandler
600603
onMeetingVideoLinkClick?: React.MouseEventHandler
601604
onMeetingLinkClick?: MessageListEvent
605+
messageBoxStyles?: React.CSSProperties
606+
notchStyle?: React.CSSProperties
602607
}
603608

604609
/**

0 commit comments

Comments
 (0)