Skip to content

Commit

Permalink
Added tooltip components
Browse files Browse the repository at this point in the history
  • Loading branch information
Renurose committed Aug 14, 2024
1 parent 82ab65c commit 6a8ffcd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/Tooltip/Tooltip.stories.ts
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, },
};

27 changes: 27 additions & 0 deletions src/components/Tooltip/Tooltip.style.ts
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;
}
`;
8 changes: 8 additions & 0 deletions src/components/Tooltip/Tooltip.test.tsx
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', () => {

Check failure on line 5 in src/components/Tooltip/Tooltip.test.tsx

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Expected indentation of 1 tab but found 0
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

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Expected indentation of 2 tabs but found 0

Check warning on line 6 in src/components/Tooltip/Tooltip.test.tsx

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
});

11 changes: 11 additions & 0 deletions src/components/Tooltip/Tooltip.tsx
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>
);

0 comments on commit 6a8ffcd

Please sign in to comment.