-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add time variation to tooltip component * feat: create tooltip variation - time duration to close * feat: add tooltip variation, mode time
- Loading branch information
1 parent
df654ad
commit 20a23ab
Showing
8 changed files
with
355 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { Button, Tooltip, TooltipTimeProps } from '@droz-js/visu' | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import { Question } from 'phosphor-react' | ||
|
||
const meta: Meta<TooltipTimeProps> = { | ||
title: 'Tooltip/Time', | ||
component: Tooltip.Time, | ||
argTypes: { | ||
children: { | ||
control: 'none', | ||
description: 'Trigger do Tooltip.', | ||
table: { | ||
type: { | ||
summary: 'React.ReactNode', | ||
}, | ||
}, | ||
}, | ||
content: { | ||
control: 'text', | ||
description: 'Define o conteúdo exibido no Tooltip.', | ||
table: { | ||
type: { summary: 'React.ReactNode' }, | ||
}, | ||
type: { name: 'string', required: false }, | ||
}, | ||
defaultOpen: { | ||
control: 'boolean', | ||
description: 'Define se o Tooltip deve iniciar aberto ou fechado.', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
defaultValue: { summary: 'false' }, | ||
}, | ||
type: { name: 'boolean', required: false }, | ||
}, | ||
closeTime: { | ||
control: 'number', | ||
description: 'Define o tempo em milissegundos para fechar o conteúdo do Tooltip.', | ||
table: { | ||
type: { summary: 'number' }, | ||
defaultValue: { summary: '2000' }, | ||
}, | ||
type: { name: 'number', required: false }, | ||
}, | ||
open: { | ||
control: 'boolean', | ||
description: 'Define se o conteúdo do Tooltip está visível ou não.', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
defaultValue: { summary: 'false' }, | ||
}, | ||
type: { name: 'boolean', required: false }, | ||
}, | ||
side: { | ||
control: { type: 'inline-radio' }, | ||
description: 'Define o local em que o componente irá aparecer, relativo ao trigger.', | ||
options: ['bottom', 'left', 'right', 'top'], | ||
table: { | ||
type: { | ||
summary: ['bottom', 'left', 'right', 'top'].join('|'), | ||
}, | ||
defaultValue: { summary: 'bottom' }, | ||
}, | ||
type: { name: 'string', required: false }, | ||
}, | ||
onOpenChange: { | ||
control: 'none', | ||
description: 'Callback executado quando o estado de `open` é alterado.', | ||
table: { | ||
type: { summary: 'function' }, | ||
}, | ||
type: { name: 'function', required: false }, | ||
}, | ||
|
||
/** | ||
* @deprecated - Deprecated props will be removed in the next major version. | ||
*/ | ||
text: { | ||
control: 'none', | ||
name: 'text (deprecated)', | ||
description: '<s>Define o valor em texto do componente.</s> (deprecated) - Use a propriedade `content`.', | ||
table: { | ||
type: { summary: 'text' }, | ||
}, | ||
type: { name: 'string', required: false }, | ||
}, | ||
}, | ||
args: { | ||
children: '', | ||
content: 'Texto do tooltip', | ||
defaultOpen: false, | ||
closeTime: 2000, | ||
open: false, | ||
side: 'bottom', | ||
}, | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/cUmiZr1GhrB9HsRCuOJ0S2/%5BDroz-Nexo%5D-Library?type=design&node-id=3107-18351&t=NDiO1Vda4DCr6uFV-0', | ||
allowFullscreen: true, | ||
}, | ||
}, | ||
} | ||
|
||
export default meta | ||
type TooltipTimeStory = StoryObj<TooltipTimeProps> | ||
|
||
export const ComTexto: TooltipTimeStory = { | ||
name: 'Com texto', | ||
render: (args) => { | ||
return ( | ||
<Tooltip.Time {...args}> | ||
<Question size={24} /> | ||
</Tooltip.Time> | ||
) | ||
}, | ||
} | ||
|
||
export const ComReactNode: TooltipTimeStory = { | ||
name: 'Com ReactNode', | ||
args: { | ||
content: ( | ||
<> | ||
<p>Texto do tooltip</p> | ||
<Button.Root>Button do tooltip</Button.Root> | ||
</> | ||
), | ||
}, | ||
argTypes: { | ||
content: { | ||
control: 'none', | ||
}, | ||
}, | ||
render: (args) => { | ||
return ( | ||
<Tooltip.Time {...args}> | ||
<Question size={24} /> | ||
</Tooltip.Time> | ||
) | ||
}, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { Tooltip } from '@library' | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
// Testes limitados por conta do Radix | ||
describe('TooltipTime tests', () => { | ||
it('Should render a TooltipTime element', () => { | ||
render( | ||
<Tooltip.Time content="Text1"> | ||
<div data-testid="element">Hello</div> | ||
</Tooltip.Time>, | ||
) | ||
const element = screen.getByTestId('element') | ||
|
||
expect(element).toBeInTheDocument() | ||
}) | ||
|
||
it('Should render a text with the prop "content"', async () => { | ||
const user = userEvent.setup() | ||
|
||
render( | ||
<Tooltip.Time content="Text1"> | ||
<div data-testid="element">Hello</div> | ||
</Tooltip.Time>, | ||
) | ||
const element = screen.getByTestId('element') | ||
await user.click(element) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('tooltip')).toHaveTextContent('Text1') | ||
}) | ||
}) | ||
|
||
it('Should render a ReactNode content with the prop "content"', async () => { | ||
const user = userEvent.setup() | ||
|
||
render( | ||
<Tooltip.Time content={<span data-testid="content">Text1</span>}> | ||
<div data-testid="element">Hello</div> | ||
</Tooltip.Time>, | ||
) | ||
const element = screen.getByTestId('element') | ||
await user.click(element) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('tooltip')).toContainHTML('<span data-testid="content">Text1</span>') | ||
}) | ||
}) | ||
|
||
it('Should render content when trigger gets a click', async () => { | ||
render( | ||
<Tooltip.Time content={<span data-testid="content">Text1</span>}> | ||
<div data-testid="element">Hello</div> | ||
</Tooltip.Time>, | ||
) | ||
const element = screen.getByTestId('element') | ||
fireEvent.click(element) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('tooltip')).toContainHTML('<span data-testid="content">Text1</span>') | ||
}) | ||
}) | ||
|
||
it('Should execute "onOpenChange" when "open" value changes', async () => { | ||
const onOpenChange = jest.fn() | ||
console.log(onOpenChange) | ||
render( | ||
<Tooltip.Time content={<span data-testid="content">Text1</span>} onOpenChange={onOpenChange}> | ||
<div data-testid="element">Hello</div> | ||
</Tooltip.Time>, | ||
) | ||
const element = screen.getByTestId('element') | ||
fireEvent.click(element) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('tooltip')).toContainHTML('<span data-testid="content">Text1</span>') | ||
expect(onOpenChange).toBeCalledTimes(1) | ||
expect(onOpenChange).toBeCalledWith(true) | ||
}) | ||
}) | ||
|
||
/** | ||
* @deprecated - Teste para uma propriedade deprecated | ||
*/ | ||
it('Should render a text with the prop "text"', async () => { | ||
const user = userEvent.setup() | ||
|
||
render( | ||
<Tooltip.Time text="Text1"> | ||
<div data-testid="element">Hello</div> | ||
</Tooltip.Time>, | ||
) | ||
const element = screen.getByTestId('element') | ||
await user.click(element) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('tooltip')).toHaveTextContent('Text1') | ||
}) | ||
}) | ||
|
||
it('Should close the tooltip after the specified closeTime', async () => { | ||
const closeTime = 3500 // Tempo de fechamento em milissegundos | ||
|
||
render( | ||
<Tooltip.Time content={<span data-testid="content">Text1</span>} closeTime={closeTime}> | ||
<div data-testid="element">Hello</div> | ||
</Tooltip.Time>, | ||
) | ||
const element = screen.getByTestId('element') | ||
fireEvent.click(element) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('tooltip')).toContainHTML('<span data-testid="content">Text1</span>') | ||
setTimeout(() => { | ||
expect(screen.queryByRole('tooltip')).toBeNull() | ||
}, closeTime + 100) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.