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

chore: Add ui/tooltip stories #966

Merged
merged 4 commits into from
Jul 28, 2023
Merged
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
7 changes: 7 additions & 0 deletions front/src/modules/ui/tooltip/AppTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Tooltip } from 'react-tooltip';
import styled from '@emotion/styled';

export enum TooltipPosition {
Top = 'top',
Left = 'left',
Right = 'right',
Bottom = 'bottom',
}

export const AppTooltip = styled(Tooltip)`
background-color: ${({ theme }) => theme.background.primary};
box-shadow: ${({ theme }) => theme.boxShadow.light};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function OverflowingTextWithTooltip({
return (
<>
<StyledOverflowingText
data-testid="tooltip"
ref={textRef}
id={textElementId}
cursorPointer={isTitleOverflowing}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Meta, StoryObj } from '@storybook/react';
import { userEvent, within } from '@storybook/testing-library';

import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';

import { OverflowingTextWithTooltip } from '../OverflowingTextWithTooltip';

const placeholderText =
'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.';

const meta: Meta<typeof OverflowingTextWithTooltip> = {
title: 'UI/Tooltip/OverflowingTextWithTooltip',
component: OverflowingTextWithTooltip,
};

export default meta;
type Story = StoryObj<typeof OverflowingTextWithTooltip>;

export const Default: Story = {
args: {
text: placeholderText,
},
decorators: [ComponentDecorator],
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const tooltip = await canvas.findByTestId('tooltip');
userEvent.hover(tooltip);
},
};
57 changes: 57 additions & 0 deletions front/src/modules/ui/tooltip/__stories__/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Meta, StoryObj } from '@storybook/react';

import { CatalogDecorator } from '~/testing/decorators/CatalogDecorator';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';

import { AppTooltip as Tooltip, TooltipPosition } from '../AppTooltip';

const meta: Meta<typeof Tooltip> = {
title: 'UI/Tooltip/Tooltip',
component: Tooltip,
};

export default meta;
type Story = StoryObj<typeof Tooltip>;

export const Default: Story = {
args: {
place: TooltipPosition.Bottom,
content: 'Tooltip Test',
isOpen: true,
anchorSelect: '#hover-text',
charlesBochet marked this conversation as resolved.
Show resolved Hide resolved
},
decorators: [ComponentDecorator],
render: (args) => (
<>
<p id="hover-text" data-testid="tooltip">
Hover me!
</p>
<Tooltip {...args} />
</>
),
};

export const Catalog: Story = {
args: { isOpen: true, content: 'Tooltip Test' },
play: async ({ canvasElement }) => {
Object.values(TooltipPosition).forEach((position) => {
const element = canvasElement.querySelector(
`#${position}`,
) as HTMLElement;
element.style.margin = '75px';
});
},
parameters: {
catalog: [
{
name: 'anchorSelect',
values: Object.values(TooltipPosition),
props: (anchorSelect: TooltipPosition) => ({
anchorSelect: `#${anchorSelect}`,
place: anchorSelect,
}),
},
],
},
decorators: [CatalogDecorator],
};
2 changes: 1 addition & 1 deletion front/src/testing/decorators/CatalogDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const CatalogDecorator: Decorator = (Story, context) => {
<RowTitle>{variable2.labels?.(value2) || value2}</RowTitle>
)}
{variable1.values.map((value1: string) => (
<ElementContainer key={value1}>
<ElementContainer key={value1} id={value1}>
{(variable1.labels?.(value1) || value1) && (
<ElementTitle>
{variable1.labels?.(value1) || value1}
Expand Down