From bc8c895b0ebe0c29f3f81884db988875102f4bd4 Mon Sep 17 00:00:00 2001 From: Rushikesh Tarapure <61598260+t007rushi@users.noreply.github.com> Date: Wed, 19 Jun 2024 20:07:44 +0530 Subject: [PATCH] Feat : Introduced Delay Options for Tooltip (#5766) Fixes https://github.com/twentyhq/twenty/issues/5727 --------- Co-authored-by: Rushikesh Tarapure Co-authored-by: Lucas Bordeau --- .../activities/comment/CommentHeader.tsx | 20 +------ .../timeline/components/TimelineActivity.tsx | 20 +------ .../components/RecordInlineCellContainer.tsx | 16 +----- .../components/ShowPageSummaryCard.tsx | 16 +----- .../src/display/tooltip/AppTooltip.tsx | 55 +++++++++++++------ .../tooltip/OverflowingTextWithTooltip.tsx | 4 +- .../tooltip/__stories__/Tooltip.stories.tsx | 52 +++++++++++++++++- .../contributors/PullRequestItem.tsx | 1 + 8 files changed, 97 insertions(+), 87 deletions(-) diff --git a/packages/twenty-front/src/modules/activities/comment/CommentHeader.tsx b/packages/twenty-front/src/modules/activities/comment/CommentHeader.tsx index 13ed1aa16352..9f87a81ebd39 100644 --- a/packages/twenty-front/src/modules/activities/comment/CommentHeader.tsx +++ b/packages/twenty-front/src/modules/activities/comment/CommentHeader.tsx @@ -1,6 +1,5 @@ -import { Tooltip } from 'react-tooltip'; import styled from '@emotion/styled'; -import { Avatar } from 'twenty-ui'; +import { AppTooltip, Avatar } from 'twenty-ui'; import { Comment } from '@/activities/types/Comment'; import { @@ -42,21 +41,6 @@ const StyledDate = styled.div` margin-left: ${({ theme }) => theme.spacing(1)}; `; -const StyledTooltip = styled(Tooltip)` - background-color: ${({ theme }) => theme.background.primary}; - - box-shadow: 0px 2px 4px 3px - ${({ theme }) => theme.background.transparent.light}; - - box-shadow: 2px 4px 16px 6px - ${({ theme }) => theme.background.transparent.light}; - - color: ${({ theme }) => theme.font.color.primary}; - - opacity: 1; - padding: 8px; -`; - type CommentHeaderProps = { comment: Pick; actionBar?: React.ReactNode; @@ -87,7 +71,7 @@ export const CommentHeader = ({ comment, actionBar }: CommentHeaderProps) => { {beautifiedCreatedAt} - theme.background.primary}; - - box-shadow: 0px 2px 4px 3px - ${({ theme }) => theme.background.transparent.light}; - - box-shadow: 2px 4px 16px 6px - ${({ theme }) => theme.background.transparent.light}; - - color: ${({ theme }) => theme.font.color.primary}; - - opacity: 1; - padding: ${({ theme }) => theme.spacing(2)}; -`; - const StyledTimelineItemContainer = styled.div<{ isGap?: boolean }>` align-items: center; align-self: stretch; @@ -217,7 +201,7 @@ export const TimelineActivity = ({ {beautifiedCreatedAt} - theme.background.primary}; - box-shadow: ${({ theme }) => theme.boxShadow.light}; - - color: ${({ theme }) => theme.font.color.primary}; - - font-size: ${({ theme }) => theme.font.size.sm}; - font-weight: ${({ theme }) => theme.font.weight.regular}; - padding: ${({ theme }) => theme.spacing(2)}; -`; - export const StyledSkeletonDiv = styled.div` height: 24px; `; @@ -141,7 +129,7 @@ export const RecordInlineCellContainer = ({ )} {/* TODO: Displaying Tooltips on the board is causing performance issues https://react-tooltip.com/docs/examples/render */} {!showLabel && !fieldDefinition?.disableTooltip && ( - theme.background.primary}; - box-shadow: ${({ theme }) => theme.boxShadow.light}; - - color: ${({ theme }) => theme.font.color.primary}; - - font-size: ${({ theme }) => theme.font.size.sm}; - font-weight: ${({ theme }) => theme.font.weight.regular}; - padding: ${({ theme }) => theme.spacing(2)}; -`; - const StyledAvatarWrapper = styled.div` cursor: pointer; `; @@ -153,7 +141,7 @@ export const ShowPageSummaryCard = ({ Added {beautifiedCreatedAt} )} - theme.blur.strong}; background-color: ${({ theme }) => RGBA(theme.color.gray80, 0.8)}; @@ -36,38 +42,51 @@ export type AppTooltipProps = { anchorSelect?: string; content?: string; children?: React.ReactNode; - delayHide?: number; offset?: number; noArrow?: boolean; isOpen?: boolean; place?: PlacesType; + delay?: TooltipDelay; positionStrategy?: PositionStrategy; + clickable?: boolean; }; export const AppTooltip = ({ anchorSelect, className, content, - delayHide, isOpen, noArrow, offset, + delay = TooltipDelay.mediumDelay, place, positionStrategy, children, -}: AppTooltipProps) => ( - -); + clickable, +}: AppTooltipProps) => { + const delayInMs = + delay === TooltipDelay.noDelay + ? 0 + : delay === TooltipDelay.shortDelay + ? 300 + : 500; + + return ( + + ); +}; diff --git a/packages/twenty-ui/src/display/tooltip/OverflowingTextWithTooltip.tsx b/packages/twenty-ui/src/display/tooltip/OverflowingTextWithTooltip.tsx index 0fbd883f5331..ed0580e9fd65 100644 --- a/packages/twenty-ui/src/display/tooltip/OverflowingTextWithTooltip.tsx +++ b/packages/twenty-ui/src/display/tooltip/OverflowingTextWithTooltip.tsx @@ -4,7 +4,7 @@ import { styled } from '@linaria/react'; import { THEME_COMMON } from '@ui/theme'; -import { AppTooltip } from './AppTooltip'; +import { AppTooltip, TooltipDelay } from './AppTooltip'; const spacing4 = THEME_COMMON.spacing(4); @@ -87,12 +87,12 @@ export const OverflowingTextWithTooltip = ({ {mutliline ?
{text}
: ''}
diff --git a/packages/twenty-ui/src/display/tooltip/__stories__/Tooltip.stories.tsx b/packages/twenty-ui/src/display/tooltip/__stories__/Tooltip.stories.tsx index 7ce9997ab049..3b46a1fc005b 100644 --- a/packages/twenty-ui/src/display/tooltip/__stories__/Tooltip.stories.tsx +++ b/packages/twenty-ui/src/display/tooltip/__stories__/Tooltip.stories.tsx @@ -6,7 +6,11 @@ import { ComponentDecorator, } from '@ui/testing'; -import { AppTooltip as Tooltip, TooltipPosition } from '../AppTooltip'; +import { + AppTooltip as Tooltip, + TooltipDelay, + TooltipPosition, +} from '../AppTooltip'; const meta: Meta = { title: 'UI/Display/Tooltip', @@ -19,6 +23,7 @@ type Story = StoryObj; export const Default: Story = { args: { place: TooltipPosition.Bottom, + delay: TooltipDelay.mediumDelay, content: 'Tooltip Test', isOpen: true, anchorSelect: '#hover-text', @@ -28,12 +33,13 @@ export const Default: Story = { anchorSelect, className, content, - delayHide, + delay, isOpen, noArrow, offset, place, positionStrategy, + clickable, }) => ( <>

@@ -44,12 +50,52 @@ export const Default: Story = { anchorSelect, className, content, - delayHide, + delay, isOpen, noArrow, offset, place, positionStrategy, + clickable, + }} + /> + + ), +}; + +export const Hoverable: Story = { + args: { + place: TooltipPosition.Bottom, + delay: TooltipDelay.mediumDelay, + content: 'Tooltip Test', + isOpen: true, + anchorSelect: '#hover-text', + }, + decorators: [ComponentDecorator], + render: ({ + anchorSelect, + className, + content, + delay, + noArrow, + offset, + place, + positionStrategy, + }) => ( + <> +

+ Hover me! +

+ diff --git a/packages/twenty-website/src/app/_components/contributors/PullRequestItem.tsx b/packages/twenty-website/src/app/_components/contributors/PullRequestItem.tsx index 617ed7c1778b..dd00e056219e 100644 --- a/packages/twenty-website/src/app/_components/contributors/PullRequestItem.tsx +++ b/packages/twenty-website/src/app/_components/contributors/PullRequestItem.tsx @@ -6,6 +6,7 @@ import { PullRequestIcon } from '@/app/_components/ui/icons/SvgIcons'; import { Theme } from '@/app/_components/ui/theme/theme'; import { formatIntoRelativeDate } from '@/shared-utils/formatIntoRelativeDate'; +// TODO: use twenty-ui Tooltip const StyledTooltip = styled(Tooltip)``; const Item = styled.div`