Skip to content

Commit 773e8d6

Browse files
gitstart-twentyThiagomn1v1b3m
authored andcommitted
chore: Add ui/tooltip stories (twentyhq#966)
* Add ui/tooltip stories Co-authored-by: Thiago Nascimbeni <[email protected]> * Add requested changes Co-authored-by: v1b3m <[email protected]> Co-authored-by: Thiago Nascimbeni <[email protected]> * Fix linting Co-authored-by: v1b3m <[email protected]> Co-authored-by: Thiago Nascimbeni <[email protected]> --------- Co-authored-by: Thiago Nascimbeni <[email protected]> Co-authored-by: v1b3m <[email protected]>
1 parent 82f0270 commit 773e8d6

File tree

5 files changed

+95
-1
lines changed

5 files changed

+95
-1
lines changed

front/src/modules/ui/tooltip/AppTooltip.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { Tooltip } from 'react-tooltip';
22
import styled from '@emotion/styled';
33

4+
export enum TooltipPosition {
5+
Top = 'top',
6+
Left = 'left',
7+
Right = 'right',
8+
Bottom = 'bottom',
9+
}
10+
411
export const AppTooltip = styled(Tooltip)`
512
background-color: ${({ theme }) => theme.background.primary};
613
box-shadow: ${({ theme }) => theme.boxShadow.light};

front/src/modules/ui/tooltip/OverflowingTextWithTooltip.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function OverflowingTextWithTooltip({
5555
return (
5656
<>
5757
<StyledOverflowingText
58+
data-testid="tooltip"
5859
ref={textRef}
5960
id={textElementId}
6061
cursorPointer={isTitleOverflowing}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import { userEvent, within } from '@storybook/testing-library';
3+
4+
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
5+
6+
import { OverflowingTextWithTooltip } from '../OverflowingTextWithTooltip';
7+
8+
const placeholderText =
9+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi tellus diam, rhoncus nec consequat quis, dapibus quis massa. Praesent tincidunt augue at ex bibendum, non finibus augue faucibus. In at gravida orci. Nulla facilisi. Proin ut augue ut nisi pellentesque tristique. Proin sodales libero id turpis tincidunt posuere.';
10+
11+
const meta: Meta<typeof OverflowingTextWithTooltip> = {
12+
title: 'UI/Tooltip/OverflowingTextWithTooltip',
13+
component: OverflowingTextWithTooltip,
14+
};
15+
16+
export default meta;
17+
type Story = StoryObj<typeof OverflowingTextWithTooltip>;
18+
19+
export const Default: Story = {
20+
args: {
21+
text: placeholderText,
22+
},
23+
decorators: [ComponentDecorator],
24+
play: async ({ canvasElement }) => {
25+
const canvas = within(canvasElement);
26+
const tooltip = await canvas.findByTestId('tooltip');
27+
userEvent.hover(tooltip);
28+
},
29+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
3+
import { CatalogDecorator } from '~/testing/decorators/CatalogDecorator';
4+
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
5+
6+
import { AppTooltip as Tooltip, TooltipPosition } from '../AppTooltip';
7+
8+
const meta: Meta<typeof Tooltip> = {
9+
title: 'UI/Tooltip/Tooltip',
10+
component: Tooltip,
11+
};
12+
13+
export default meta;
14+
type Story = StoryObj<typeof Tooltip>;
15+
16+
export const Default: Story = {
17+
args: {
18+
place: TooltipPosition.Bottom,
19+
content: 'Tooltip Test',
20+
isOpen: true,
21+
anchorSelect: '#hover-text',
22+
},
23+
decorators: [ComponentDecorator],
24+
render: (args) => (
25+
<>
26+
<p id="hover-text" data-testid="tooltip">
27+
Hover me!
28+
</p>
29+
<Tooltip {...args} />
30+
</>
31+
),
32+
};
33+
34+
export const Catalog: Story = {
35+
args: { isOpen: true, content: 'Tooltip Test' },
36+
play: async ({ canvasElement }) => {
37+
Object.values(TooltipPosition).forEach((position) => {
38+
const element = canvasElement.querySelector(
39+
`#${position}`,
40+
) as HTMLElement;
41+
element.style.margin = '75px';
42+
});
43+
},
44+
parameters: {
45+
catalog: [
46+
{
47+
name: 'anchorSelect',
48+
values: Object.values(TooltipPosition),
49+
props: (anchorSelect: TooltipPosition) => ({
50+
anchorSelect: `#${anchorSelect}`,
51+
place: anchorSelect,
52+
}),
53+
},
54+
],
55+
},
56+
decorators: [CatalogDecorator],
57+
};

front/src/testing/decorators/CatalogDecorator.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const CatalogDecorator: Decorator = (Story, context) => {
9696
<RowTitle>{variable2.labels?.(value2) || value2}</RowTitle>
9797
)}
9898
{variable1.values.map((value1: string) => (
99-
<ElementContainer key={value1}>
99+
<ElementContainer key={value1} id={value1}>
100100
{(variable1.labels?.(value1) || value1) && (
101101
<ElementTitle>
102102
{variable1.labels?.(value1) || value1}

0 commit comments

Comments
 (0)