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

Feat : Introduced Delay Options for Tooltip #5766

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
51 changes: 33 additions & 18 deletions packages/twenty-ui/src/display/tooltip/AppTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export enum TooltipPosition {
Bottom = 'bottom',
}

export enum TooltipDelay {
noDelay = '0ms',
shortDelay = '300ms',
mediumDelay = '500ms',
}

const StyledAppTooltip = styled(Tooltip)`
backdrop-filter: ${({ theme }) => theme.blur.strong};
background-color: ${({ theme }) => RGBA(theme.color.gray80, 0.8)};
Expand All @@ -36,38 +42,47 @@ export type AppTooltipProps = {
anchorSelect?: string;
content?: string;
children?: React.ReactNode;
delayHide?: number;
offset?: number;
noArrow?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the delay prop is optional and has a default value to avoid potential undefined errors.

isOpen?: boolean;
place?: PlacesType;
delay?: TooltipDelay;
positionStrategy?: PositionStrategy;
};

export const AppTooltip = ({
anchorSelect,
className,
content,
delayHide,
isOpen,
noArrow,
offset,
delay,
place,
positionStrategy,
children,
}: AppTooltipProps) => (
<StyledAppTooltip
{...{
anchorSelect,
className,
content,
delayHide,
isOpen,
noArrow,
offset,
place,
positionStrategy,
children,
}}
/>
);
}: AppTooltipProps) => {
const delayInMs =
delay === TooltipDelay.noDelay
? 0
: delay === TooltipDelay.shortDelay
? 300
: 500;

return (
<StyledAppTooltip
{...{
anchorSelect,
className,
content,
delayShow: delayInMs,
isOpen,
noArrow,
offset,
place,
positionStrategy,
children,
}}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Tooltip> = {
title: 'UI/Display/Tooltip',
Expand All @@ -19,6 +23,7 @@ type Story = StoryObj<typeof Tooltip>;
export const Default: Story = {
args: {
place: TooltipPosition.Bottom,
delay: TooltipDelay.mediumDelay,
content: 'Tooltip Test',
isOpen: true,
anchorSelect: '#hover-text',
Expand All @@ -28,7 +33,7 @@ export const Default: Story = {
anchorSelect,
className,
content,
delayHide,
delay,
isOpen,
noArrow,
offset,
Expand All @@ -44,7 +49,7 @@ export const Default: Story = {
anchorSelect,
className,
content,
delayHide,
delay,
isOpen,
noArrow,
offset,
Expand All @@ -56,6 +61,45 @@ export const Default: Story = {
),
};

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,
}) => (
<>
<p id="hover-text" data-testid="tooltip">
Hover me!
</p>
<Tooltip
{...{
anchorSelect,
className,
content,
delay,
noArrow,
offset,
place,
positionStrategy,
}}
/>
</>
),
};

export const Catalog: CatalogStory<Story, typeof Tooltip> = {
args: { isOpen: true, content: 'Tooltip Test' },
play: async ({ canvasElement }) => {
Expand Down
Loading