-
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.
- Loading branch information
Renurose
committed
Aug 14, 2024
1 parent
82ab65c
commit 6a8ffcd
Showing
4 changed files
with
61 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,8 @@ | ||
import { render } from '@testing-library/react'; | ||
import { Tooltip } from './Tooltip'; | ||
|
||
describe('<Tooltip />', () =>{ | ||
it('renders the tooltip component', () => { | ||
const { getByText } = render( <Tooltip text="Hover over me" tooltip="Tooltip text" /> ); expect(getByText('Hover over me')).toBeInTheDocument(); }); | ||
Check failure on line 6 in src/components/Tooltip/Tooltip.test.tsx GitHub Actions / tests-and-file-checks
|
||
}); | ||
|
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> | ||
); | ||
|