-
Notifications
You must be signed in to change notification settings - Fork 27
feat: adding an experimental tooltip component based on react-aria #531
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a5ebcb6
feat: adding an experimental tooltip component based on react-aria
lloydaf 7dacf0e
docs: adding more variants to the stories
lloydaf 4af8d87
fix: fixing the build
lloydaf 8f6e1e0
fix: removing the unwanted fragment
lloydaf 28c3ebd
chore: adding a basic test
lloydaf f6dc5c3
chore: merging main
lloydaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,19 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import { Chip } from '../Chip/Chip'; | ||
|
|
||
| import { Tooltip } from './Tooltip'; | ||
|
|
||
| describe('Experimental: Tooltip', () => { | ||
| it('should render the tooltip', () => { | ||
| const utils = render( | ||
| // isOpen is provided as true to avoid hovering troubles with userEvent | ||
| <Tooltip content="I am a tooltip" triggerProps={{ isOpen: true }}> | ||
| <Chip>Hover me</Chip> | ||
| </Tooltip> | ||
| ); | ||
| expect(utils.queryByRole('tooltip')).toBeInTheDocument(); | ||
| expect(utils.queryByText('I am a tooltip')).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or 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,40 @@ | ||
| import React from 'react'; | ||
| import { OverlayArrow, Tooltip as AriaTooltip, TooltipTrigger, Focusable } from 'react-aria-components'; | ||
|
|
||
| import type { TooltipProps as AriaTooltipProps, TooltipTriggerComponentProps } from 'react-aria-components'; | ||
|
|
||
| import './tooltip.css'; | ||
|
|
||
| interface TooltipProps { | ||
| children: any; | ||
lloydaf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| content: string; | ||
| hideArrow?: boolean; | ||
| customTrigger?: boolean; | ||
| tooltipProps?: Omit<AriaTooltipProps, 'children'>; | ||
| triggerProps?: Omit<TooltipTriggerComponentProps, 'children'>; | ||
| } | ||
|
|
||
| const Tooltip = ({ | ||
| children, | ||
| content, | ||
| triggerProps, | ||
| tooltipProps, | ||
| hideArrow = false, | ||
| customTrigger = false | ||
| }: TooltipProps) => ( | ||
| <TooltipTrigger {...triggerProps}> | ||
| {customTrigger ? <Focusable>{children}</Focusable> : children} | ||
| <AriaTooltip {...tooltipProps}> | ||
| {!hideArrow && ( | ||
| <OverlayArrow> | ||
| <svg width={8} height={8} viewBox="0 0 8 8"> | ||
| <path d="M0 0 L4 4 L8 0" /> | ||
| </svg> | ||
| </OverlayArrow> | ||
| )} | ||
| {content} | ||
| </AriaTooltip> | ||
| </TooltipTrigger> | ||
| ); | ||
|
|
||
| export { Tooltip, TooltipProps }; | ||
68 changes: 68 additions & 0 deletions
68
src/components/experimental/Tooltip/docs/Tooltip.stories.tsx
This file contains hidden or 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,68 @@ | ||
| import React from 'react'; | ||
| import { StoryObj, Meta } from '@storybook/react'; | ||
| import { Tooltip } from '../Tooltip'; | ||
| import { Chip } from '../../Chip/Chip'; | ||
|
|
||
| const meta: Meta = { | ||
| title: 'Experimental/Components/Tooltip', | ||
| component: Tooltip, | ||
| decorators: [ | ||
| (Story: React.FC): JSX.Element => ( | ||
| <div style={{ width: '150px' }}> | ||
| <Story /> | ||
| </div> | ||
| ) | ||
| ], | ||
| args: { | ||
| content: 'I am a tooltip', | ||
| children: <Chip>Hover me</Chip> | ||
| } | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof Tooltip>; | ||
|
|
||
| export const Default: Story = {}; | ||
|
|
||
| export const TooltipWithDelay: Story = { | ||
| args: { | ||
| triggerProps: { | ||
| delay: 2000 | ||
| }, | ||
| content: 'I show up after 2 seconds' | ||
| } | ||
| }; | ||
|
|
||
| export const TooltipWithCustomTrigger: Story = { | ||
| args: { | ||
| customTrigger: true, | ||
| children: <p>Hover over me, a non focusable element!</p>, | ||
| content: "I don't need a focusable element" | ||
| } | ||
| }; | ||
|
|
||
| export const TooltipWithBottomPlacement: Story = { | ||
| args: { | ||
| tooltipProps: { | ||
| placement: 'bottom' | ||
| }, | ||
| content: 'I am a bottom tooltip' | ||
| } | ||
| }; | ||
|
|
||
| export const TooltipWithoutArrow: Story = { | ||
| args: { | ||
| hideArrow: true, | ||
| content: 'I have no arrow' | ||
| } | ||
| }; | ||
|
|
||
| export const TooltipWithOffset: Story = { | ||
| args: { | ||
| tooltipProps: { | ||
| crossOffset: 50 | ||
| }, | ||
| content: 'I have an offset of 50px' | ||
| } | ||
| }; |
This file contains hidden or 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,53 @@ | ||
| .react-aria-Tooltip { | ||
| box-shadow: 0 8px 20px rgba(0 0 0 / 0.1); | ||
| border-radius: 4px; | ||
| background: var(--wave-exp-color-inverse-surface); | ||
| color: var(--wave-exp-color-inverse-on-surface); | ||
| forced-color-adjust: none; | ||
| outline: none; | ||
| padding: 2px 8px; | ||
| max-width: 150px; | ||
| /* fixes FF gap */ | ||
| transform: translate3d(0, 0, 0); | ||
| transition: transform 200ms, opacity 200ms; | ||
|
|
||
| &[data-entering], | ||
| &[data-exiting] { | ||
| transform: var(--origin); | ||
| opacity: 0; | ||
| } | ||
|
|
||
| &[data-placement='top'] { | ||
| margin-bottom: 8px; | ||
| --origin: translateY(4px); | ||
| } | ||
|
|
||
| &[data-placement='bottom'] { | ||
| margin-top: 8px; | ||
| --origin: translateY(-4px); | ||
| & .react-aria-OverlayArrow svg { | ||
| transform: rotate(180deg); | ||
| } | ||
| } | ||
|
|
||
| &[data-placement='right'] { | ||
| margin-left: 8px; | ||
| --origin: translateX(-4px); | ||
| & .react-aria-OverlayArrow svg { | ||
| transform: rotate(90deg); | ||
| } | ||
| } | ||
|
|
||
| &[data-placement='left'] { | ||
| margin-right: 8px; | ||
| --origin: translateX(4px); | ||
| & .react-aria-OverlayArrow svg { | ||
| transform: rotate(-90deg); | ||
| } | ||
| } | ||
|
|
||
| & .react-aria-OverlayArrow svg { | ||
| display: block; | ||
| fill: var(--wave-exp-color-inverse-surface); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.