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

Fixed positioning of tooltips and improved the UI. #409

Open
wants to merge 2 commits into
base: develop
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
2 changes: 1 addition & 1 deletion packages/react/src/components/ChatHeader/ChatHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ const ChatHeader = ({
<Menu options={menuOptions} />
) : (
<>
<Tooltip text="Maximize" position="bottom">
<Tooltip text="Maximize" position="bottom" X="-25%" Y="30%">
<ActionButton
onClick={() => {
setFullScreen((prev) => !prev);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const ChatInputFormattingToolbar = ({ messageRef, inputRef }) => {
</>
)}
{formatter.map((item, index) => (
<Tooltip text={item.name} position="top" key={index}>
<Tooltip text={item.name} position="top" key={index} X="-17%">
<ActionButton
square
disabled={isRecordingMessage}
Expand All @@ -142,10 +142,10 @@ const ChatInputFormattingToolbar = ({ messageRef, inputRef }) => {
</ActionButton>
</Tooltip>
))}
<Tooltip text="Audio Message" position="top">
<Tooltip text="Audio Message" position="top" X="-35%">
<AudioMessageRecorder />
</Tooltip>
<Tooltip text="Video Message" position="top">
<Tooltip text="Video Message" position="top" X="-35%">
<VideoMessageRecorder />
</Tooltip>
<ActionButton
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/components/Message/MessageToolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const MessageToolbox = ({
onClick={() => handleStarMessage(message)}
/>
</Tooltip>

<Tooltip text="Add reaction" position="top">
<ActionButton
ghost
Expand Down Expand Up @@ -173,6 +174,7 @@ export const MessageToolbox = ({
</Tooltip>
</>
)}

<Tooltip text="Report" position="top">
<ActionButton
ghost
Expand Down
37 changes: 19 additions & 18 deletions packages/react/src/components/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React, { useState } from 'react';

const Tooltip = ({ children, text, position }) => {
const Tooltip = ({ children, text, position, X, Y }) => {
const [isTooltipVisible, setTooltipVisible] = useState(false);

let touchTimer;
const tooltipStyle = {
position: 'absolute',
left: '64%',
transform: 'translateX(-50%) ',
backgroundColor: 'rgba(97, 97, 97, 1)',
backgroundColor: 'black',
color: 'white',
padding: '4px',
padding: '4.5px',
borderRadius: '3px',
boxShadow: '0 2px 10px rgba(0, 0, 0, 0.2)',
zIndex: 9999,
fontSize: '12.5px',
boxShadow: '0 2px 10px rgba(0, 0, 0, 0.4)',
zIndex: 999,
fontSize: '13.8px',
whiteSpace: 'nowrap',
fontFamily: 'sans-serif',
left: '64%',
transform: 'translateX(-50%) ',
};

const tooltipArrowStyle = {
Expand All @@ -25,35 +25,36 @@ const Tooltip = ({ children, text, position }) => {
marginLeft: '-5px',
borderWidth: '6px',
borderStyle: 'solid',
borderColor: 'rgba(97, 97, 97, 1) transparent transparent transparent',
borderColor: 'black transparent transparent transparent',
zIndex: 999,
};

// Add more positions according to your needs and modify tooltipStyle and tooltipArrowStyle accordingly

if (position === 'top') {
tooltipStyle.top = 'calc(-100% - 10px)'; // avoid overlaying the element
tooltipStyle.top = '-2.3rem';
tooltipArrowStyle.top = '100%';
tooltipArrowStyle.transform = 'translateX(-50%)';
} else if (position === 'bottom') {
tooltipStyle.top = '100%';
tooltipStyle.transform = 'translateY(45%) translateX(-55%)';
tooltipArrowStyle.bottom = '100%';
tooltipArrowStyle.transform = 'translateX(-50%) rotate(180deg)';
tooltipArrowStyle.transform = 'rotate(180deg)';
}

const handleMouseEnter = () => {
setTooltipVisible(true);
touchTimer = setTimeout(() => {
setTooltipVisible(true);
}, 300);
};

const handleMouseLeave = () => {
clearTimeout(touchTimer);
setTooltipVisible(false);
};

let touchTimer;

const handleTouchStart = () => {
touchTimer = setTimeout(() => {
setTooltipVisible(true);
}, 500);
}, 400);
};

const handleTouchEnd = () => {
Expand Down
Loading