-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Renurose <renurose24022gmail.com> Co-authored-by: ben-AI-cybersec <[email protected]>
- Loading branch information
1 parent
be69429
commit b6a6592
Showing
4 changed files
with
70 additions
and
0 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,15 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { Tooltip } from './Tooltip'; | ||
|
||
const meta: Meta<typeof Tooltip> = { title: 'Components/Tooltip', component: Tooltip, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Tooltip>; | ||
|
||
const defaultProps = { text: 'Hover over me', tooltip: 'This is a tooltip', | ||
}; | ||
|
||
export const Default: Story = { args: { ...defaultProps, }, | ||
}; | ||
|
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,27 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const TooltipContainer = styled.div` | ||
position: relative; | ||
display: inline-block; | ||
`; | ||
|
||
export const TooltipText = styled.div` | ||
visibility: hidden; | ||
width: 120px; | ||
background-color: ${({ theme }) => theme?.colors?.tooltipBg || '#555'}; | ||
color: ${({ theme }) => theme?.colors?.tooltipText || '#fff'}; | ||
text-align: center; | ||
padding: ${({ theme }) => theme?.spacing?.xs || '5px'}; | ||
border-radius: ${({ theme }) => theme?.borderRadius?.sm || '6px'}; | ||
position: absolute; | ||
z-index: 1; | ||
bottom: 20%; | ||
left: 50%; | ||
margin-left: -60px; | ||
opacity: 0; | ||
transition: opacity 0.3s; | ||
${TooltipContainer}:hover & { | ||
visibility: visible; | ||
opacity: 1; | ||
} | ||
`; |
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,17 @@ | ||
import { render } from '@testing-library/react'; | ||
import { Tooltip } from './Tooltip'; | ||
import { axe } from 'jest-axe'; | ||
|
||
describe('<Tooltip />', () => { | ||
it('renders the tooltip component', () => { | ||
const { getByText } = render(<Tooltip text="Hover over me" tooltip="Tooltip text" />); | ||
expect(getByText('Hover over me')).toBeInTheDocument(); | ||
}); | ||
|
||
it('has no accessibility violations', async () => { | ||
const { container } = render(<Tooltip text="Hover over me" tooltip="Tooltip text" />); | ||
const results = await axe(container); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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,11 @@ | ||
import { FC } from 'react'; | ||
import { TooltipContainer, TooltipText } from './Tooltip.style'; | ||
|
||
type TooltipProps = { | ||
text: string; | ||
tooltip: string; | ||
}; | ||
|
||
export const Tooltip: FC<TooltipProps> = ({ text, tooltip }) => ( <TooltipContainer> {text} <TooltipText>{tooltip}</TooltipText> </TooltipContainer> | ||
); | ||
|