Skip to content

Commit

Permalink
Add tooltips to message toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreytheCoder committed Mar 4, 2024
1 parent da8b930 commit 71fdad0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 47 deletions.
115 changes: 69 additions & 46 deletions packages/react/src/components/Message/MessageToolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Modal } from '../Modal';
import { Icon } from '../Icon';
import { Button } from '../Button';
import { parseEmoji } from '../../lib/emoji';
import { Tooltip } from '../Tooltip';

const MessageToolboxWrapperCss = css`
display: none;
Expand Down Expand Up @@ -88,30 +89,44 @@ export const MessageToolbox = ({
{...props}
>
{!isThreadMessage ? (
<Tooltip text="Reply in thread" position="top">
<ActionButton
ghost
size="small"
icon="thread"
onClick={handleOpenThread(message)}
/>
</Tooltip>
) : null}
<Tooltip
text={
message.starred &&
message.starred.find((u) => u._id === authenticatedUserId)
? 'Remove star'
: 'Star'
}
position="top"
>
<ActionButton
ghost
size="small"
icon="thread"
onClick={handleOpenThread(message)}
icon={`${
message.starred &&
message.starred.find((u) => u._id === authenticatedUserId)
? 'star-filled'
: 'star'
}`}
onClick={() => handleStarMessage(message)}
/>
) : null}
<ActionButton
ghost
size="small"
icon={`${
message.starred &&
message.starred.find((u) => u._id === authenticatedUserId)
? 'star-filled'
: 'star'
}`}
onClick={() => handleStarMessage(message)}
/>
<ActionButton
ghost
size="small"
icon="emoji"
onClick={() => setEmojiOpen(true)}
/>
</Tooltip>
<Tooltip text="Add reaction" position="top">
<ActionButton
ghost
size="small"
icon="emoji"
onClick={() => setEmojiOpen(true)}
/>
</Tooltip>
<Popup
modal
open={isEmojiOpen}
Expand All @@ -127,38 +142,46 @@ export const MessageToolbox = ({
/>
</Popup>
{!isThreadMessage && (
<ActionButton
ghost
size="small"
icon={`${message.pinned ? 'pin-filled' : 'pin'}`}
onClick={() => handlePinMessage(message)}
/>
)}
{message.u._id === authenticatedUserId && (
<>
<ActionButton
ghost={!isEditing}
color={isEditing ? 'secondary' : 'default'}
size="small"
icon="edit"
onClick={() => handleEditMessage(message)}
/>
<Tooltip text={message.pinned ? 'Unpin' : 'Pin'} position="top">
<ActionButton
ghost
size="small"
icon="trash"
color="error"
onClick={() => handleClickDelete(message)}
icon={`${message.pinned ? 'pin-filled' : 'pin'}`}
onClick={() => handlePinMessage(message)}
/>
</Tooltip>
)}
{message.u._id === authenticatedUserId && (
<>
<Tooltip text="Edit" position="top">
<ActionButton
ghost={!isEditing}
color={isEditing ? 'secondary' : 'default'}
size="small"
icon="edit"
onClick={() => handleEditMessage(message)}
/>
</Tooltip>
<Tooltip text="Delete" position="top">
<ActionButton
ghost
size="small"
icon="trash"
color="error"
onClick={() => handleClickDelete(message)}
/>
</Tooltip>
</>
)}
<ActionButton
ghost
size="small"
icon="report"
color="error"
onClick={() => handlerReportMessage(message)}
/>
<Tooltip text="Report" position="top">
<ActionButton
ghost
size="small"
icon="report"
color="error"
onClick={() => handlerReportMessage(message)}
/>
</Tooltip>
</Box>
</Box>
{showDeleteModal && (
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Tooltip = ({ children, text, position }) => {
// Add more positions according to your needs and modify tooltipStyle and tooltipArrowStyle accordingly

if (position === 'top') {
tooltipStyle.top = '-100%';
tooltipStyle.top = 'calc(-100% - 10px)'; // avoid overlaying the element
tooltipArrowStyle.top = '100%';
tooltipArrowStyle.transform = 'translateX(-50%)';
} else if (position === 'bottom') {
Expand Down

0 comments on commit 71fdad0

Please sign in to comment.