-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Buy component touch ups (#1775)
Co-authored-by: Alissa Crane <[email protected]>
- Loading branch information
1 parent
a154ba1
commit 19d7524
Showing
11 changed files
with
136 additions
and
23 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
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
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
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,35 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { Tooltip } from './Tooltip'; | ||
|
||
describe('Tooltip', () => { | ||
it('renders the children', () => { | ||
render(<Tooltip content="Test Content" />); | ||
expect(screen.getByTestId('ockBuyApplePayInfo')).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows the content on mouse enter', () => { | ||
render(<Tooltip content="Test Content" />); | ||
const triggerElement = screen.getByTestId('ockBuyApplePayInfo'); | ||
|
||
fireEvent.mouseEnter(triggerElement); | ||
expect(screen.getByText('Test Content')).toBeInTheDocument(); | ||
}); | ||
|
||
it('hides the content on mouse leave', () => { | ||
render(<Tooltip content="Test Content" />); | ||
const triggerElement = screen.getByTestId('ockBuyApplePayInfo'); | ||
|
||
fireEvent.mouseEnter(triggerElement); | ||
fireEvent.mouseLeave(triggerElement); | ||
|
||
expect(screen.queryByText('Test Content')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('renders custom children if provided', () => { | ||
const CustomChild = <div>Custom Child</div>; | ||
render(<Tooltip content="Test Content">{CustomChild}</Tooltip>); | ||
|
||
expect(screen.getByText('Custom Child')).toBeInTheDocument(); | ||
}); | ||
}); |
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,47 @@ | ||
import { infoSvg } from '@/internal/svg/infoSvg'; | ||
import { background, border, cn, text } from '@/styles/theme'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
type TooltipReact = { | ||
children?: React.ReactNode; | ||
content: React.ReactNode; | ||
}; | ||
|
||
export function Tooltip({ children = infoSvg, content }: TooltipReact) { | ||
const [isOverlayVisible, setIsOverlayVisible] = useState(false); | ||
|
||
const showOverlay = useCallback(() => { | ||
setIsOverlayVisible(true); | ||
}, []); | ||
|
||
const hideOverlay = useCallback(() => { | ||
setIsOverlayVisible(false); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<div | ||
data-testid="ockBuyApplePayInfo" | ||
className={cn('h-2.5 w-2.5 cursor-pointer object-cover')} | ||
onMouseEnter={showOverlay} | ||
onMouseLeave={hideOverlay} | ||
> | ||
{children} | ||
</div> | ||
{isOverlayVisible && ( | ||
<div | ||
className={cn( | ||
'absolute top-0 right-0 flex translate-x-[100%] translate-y-[-100%]', | ||
'whitespace-nowrap p-2', | ||
border.radius, | ||
background.inverse, | ||
text.legal, | ||
border.lineDefault, | ||
)} | ||
> | ||
{content} | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |