Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom buttons option to MessageBox #184

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion example/components/MessageListExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
textMessage,
videoMessage,
} from '../utils/MessageTypes'
import { MdInfo } from 'react-icons/md'

let clearRef = () => {}

Expand All @@ -29,6 +30,8 @@ function MessageListExample() {
const messageListReferance = useRef()
const inputReferance = useRef()

console.log(messageListArray)

const forceUpdate = useForceUpdate()

const addMessage = (data: number) => {
Expand Down Expand Up @@ -73,7 +76,21 @@ function MessageListExample() {
break
}

setMessageListArray([...messageListArray, randomMessage(Addmtype)])
const newMsg = randomMessage(Addmtype)

// add custom button
if (token() > 7) {
newMsg.customButtons = [
<div
onClick={() => {
console.log('custom button click')
}}
>
<MdInfo />
</div>,
]
}
setMessageListArray([...messageListArray, newMsg])
clearRef()
forceUpdate()
}
Expand Down
104 changes: 33 additions & 71 deletions src/MessageBox/MessageBox.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,57 @@
min-width: 300px;
}

.rce-mbox-forward {
width: 30px;
height: 30px;
border-radius: 20px;
background: #fff;
.rce-mbox-btn-list {
position: absolute;
/*display: none;*/
flex-direction: row;
align-self: center;
align-items: center;
justify-content: center;
box-shadow: 0 0 5px 0 rgba(164, 164, 164, 1);
cursor: pointer;
transition: all 0.3s ease;
top: 0;
bottom: 0;
margin: auto;
top: 50%;
}

.rce-mbox-forward-left {
display: flex;
opacity: 0;
visibility: hidden;
left: -50px;
.rce-mbox-btn-list-right {
left: -12px;
transform: translate(-100%, -50%);
}

.rce-mbox-forward-right {
display: flex;
opacity: 0;
visibility: hidden;
right: -50px;
.rce-mbox-btn-list-left {
right: -12px;
transform: translate(100%, -50%);
}

.rce-mbox-reply-btn-left {
display: flex;
opacity: 0;
visibility: hidden;
left: -85px;
.rce-mbox-btn-container {
display: inline-block;
width: 30px;
height: 30px;
margin-left: 3px;
margin-right: 3px;
}

.rce-mbox-reply-btn-right {
.rce-mbox-btn {
display: flex;
opacity: 0;
visibility: hidden;
right: -85px;
}

.rce-container-mbox:hover .rce-mbox-forward-left {
.rce-container-mbox:hover .rce-mbox-btn {
opacity: 1;
visibility: visible;
}

.rce-container-mbox:hover .rce-mbox-forward-right {
opacity: 1;
visibility: visible;
.rce-mbox-forward {
width: 30px;
height: 30px;
border-radius: 20px;
background: #fff;
position: absolute;
/*display: none;*/
flex-direction: row;
align-self: center;
align-items: center;
justify-content: center;
box-shadow: 0 0 5px 0 rgba(164, 164, 164, 1);
cursor: pointer;
transition: all 0.3s ease;
top: 0;
bottom: 0;
margin: auto;
}

.rce-mbox-remove {
Expand All @@ -81,40 +77,6 @@
margin: auto;
}

.rce-mbox-remove-left {
display: flex;
opacity: 0;
visibility: hidden;
left: -120px;
}

.rce-mbox-remove-right {
display: flex;
opacity: 0;
visibility: hidden;
right: -120px;
}

.rce-container-mbox:hover .rce-mbox-remove-left {
opacity: 1;
visibility: visible;
}

.rce-container-mbox:hover .rce-mbox-remove-right {
opacity: 1;
visibility: visible;
}

.rce-container-mbox:hover .rce-mbox-reply-btn-left {
opacity: 1;
visibility: visible;
}

.rce-container-mbox:hover .rce-mbox-reply-btn-right {
opacity: 1;
visibility: visible;
}

.rce-mbox {
position: relative;
background: white;
Expand Down
77 changes: 31 additions & 46 deletions src/MessageBox/MessageBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,58 +62,43 @@ const MessageBox: React.FC<MessageBoxType> = ({ focus = false, notch = true, sty
)}
>
<div className='rce-mbox-body' onContextMenu={props.onContextMenu}>
{!props.retracted && props.forwarded === true && (
{!props.retracted && (
<div
className={classNames(
'rce-mbox-forward',
{ 'rce-mbox-forward-right': props.position === 'left' },
{ 'rce-mbox-forward-left': props.position === 'right' }
'rce-mbox-btn-list',
{ 'rce-mbox-btn-list-left': props.position === 'left' },
{ 'rce-mbox-btn-list-right': props.position === 'right' }
)}
onClick={props.onForwardClick}
>
<RiShareForwardFill />
</div>
)}
{props.forwarded === true && (
<div className='rce-mbox-btn-container'>
<div className={classNames('rce-mbox-forward', 'rce-mbox-btn')} onClick={props.onForwardClick}>
<RiShareForwardFill />
</div>
</div>
)}

{!props.retracted && props.replyButton === true && (
<div
className={
props.forwarded !== true
? classNames(
'rce-mbox-forward',
{ 'rce-mbox-forward-right': props.position === 'left' },
{ 'rce-mbox-forward-left': props.position === 'right' }
)
: classNames(
'rce-mbox-forward',
{ 'rce-mbox-reply-btn-right': props.position === 'left' },
{ 'rce-mbox-reply-btn-left': props.position === 'right' }
)
}
onClick={props.onReplyClick}
>
<MdMessage />
</div>
)}
{props.replyButton === true && (
<div className='rce-mbox-btn-container'>
<div className={classNames('rce-mbox-forward', 'rce-mbox-btn')} onClick={props.onReplyClick}>
<MdMessage />
</div>
</div>
)}

{!props.retracted && props.removeButton === true && (
<div
className={
props.forwarded === true
? classNames(
'rce-mbox-remove',
{ 'rce-mbox-remove-right': props.position === 'left' },
{ 'rce-mbox-remove-left': props.position === 'right' }
)
: classNames(
'rce-mbox-forward',
{ 'rce-mbox-reply-btn-right': props.position === 'left' },
{ 'rce-mbox-reply-btn-left': props.position === 'right' }
)
}
onClick={props.onRemoveMessageClick}
>
<MdDelete />
{props.removeButton === true && (
<div className='rce-mbox-btn-container'>
<div className={classNames('rce-mbox-remove', 'rce-mbox-btn')} onClick={props.onRemoveMessageClick}>
<MdDelete />
</div>
</div>
)}
{!!props?.customButtons?.length &&
props.customButtons.map(btn => (
<div className='rce-mbox-btn-container'>
<div className={'rce-mbox-btn'}>{btn}</div>
</div>
))}
</div>
)}

Expand Down
3 changes: 2 additions & 1 deletion src/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { ReactNode } from 'react'

/**
* IChatItemProps Interface
Expand Down Expand Up @@ -169,6 +169,7 @@ export interface IMessage {
letterItem?: ILetterItem
reply?: IReplyMessage | any
type: string
customButtons?: Array<ReactNode>
}

/**
Expand Down
Loading