-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
928e657
commit 630dee7
Showing
9 changed files
with
197 additions
and
31 deletions.
There are no files selected for viewing
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,74 @@ | ||
@import "../../scss/variables"; | ||
|
||
$icon-size-large: 22px; | ||
$icon-size-small: 16px; | ||
|
||
$tooltip-spacing: 10px; | ||
|
||
.tooltip { | ||
overflow: visible; | ||
z-index: 10; | ||
position: relative; | ||
transform: translateY(4px); | ||
margin-left: 5px; | ||
display: inline-block; | ||
width: $icon-size-large; | ||
height: $icon-size-large; | ||
|
||
@include breakpoint("small") { | ||
width: $icon-size-small; | ||
height: $icon-size-small; | ||
} | ||
} | ||
|
||
.tooltip-button, | ||
.tooltip-text { | ||
display: block; | ||
} | ||
|
||
.tooltip-button { | ||
opacity: .5; | ||
z-index: 0; | ||
width: $icon-size-large; | ||
height: $icon-size-large; | ||
background: url("../../../public/images/icons/tooltip.svg") center center no-repeat transparent; | ||
background-size: contain; | ||
|
||
@include breakpoint("small") { | ||
width: $icon-size-small; | ||
height: $icon-size-small; | ||
} | ||
} | ||
|
||
.tooltip-button:hover, | ||
.tooltip-button-active { | ||
opacity: 1; | ||
} | ||
|
||
$easing-in: 0.6s $global-transition-ease-out-expo; | ||
$easing-out: 0.6s $global-transition-ease-in-expo; | ||
|
||
.tooltip-text { | ||
pointer-events: none; | ||
z-index: 10; | ||
opacity: 0; | ||
position: absolute; | ||
left: -$tooltip-spacing; | ||
bottom: calc(100% + $tooltip-spacing); | ||
padding: 10px; | ||
width: 200px; | ||
font-size: 14px; | ||
line-height: 20px; | ||
text-align: left; | ||
border-radius: 5px; | ||
box-shadow: 0 0 5px rgba($global-color-body, .3); | ||
background: $global-color-background; | ||
transform: translateY(20%); | ||
transition: opacity $easing-in, transform $easing-in; | ||
} | ||
|
||
.tooltip-text-active { | ||
pointer-events: all; | ||
opacity: 1; | ||
transform: translateY(0%); | ||
} |
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,22 @@ | ||
import '@testing-library/jest-dom'; | ||
|
||
import { render } from '@testing-library/react'; | ||
import { axe, toHaveNoViolations } from 'jest-axe'; | ||
|
||
import Tooltip from './Tooltip'; | ||
|
||
beforeAll(() => { | ||
expect.extend(toHaveNoViolations); | ||
}); | ||
|
||
it('Passes accessibility with default props', async () => { | ||
const { container } = render( | ||
<Tooltip | ||
text="mocked tooltip" | ||
/>, | ||
); | ||
|
||
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,46 @@ | ||
/* eslint-disable react/require-default-props */ | ||
/* istanbul ignore file */ | ||
|
||
import { useState } from 'react'; | ||
|
||
import styles from './Tooltip.module.scss'; | ||
|
||
export interface TooltipProps { | ||
text: string, | ||
} | ||
|
||
const Tooltip = ({ | ||
text, | ||
}: TooltipProps) => { | ||
const [open, setOpen] = useState<boolean>(false); | ||
|
||
const textClasses = [styles['tooltip-text']]; | ||
const buttonClasses = [styles['tooltip-button']]; | ||
if (open) { | ||
buttonClasses.push(styles['tooltip-button-active']); | ||
textClasses.push(styles['tooltip-text-active']); | ||
} | ||
|
||
return ( | ||
<span | ||
className={styles.tooltip} | ||
onMouseEnter={() => setOpen(true)} | ||
onMouseLeave={() => setOpen(false)} | ||
> | ||
<button | ||
type="button" | ||
className={buttonClasses.join(' ')} | ||
onKeyDown={() => {}} | ||
title="Tooltip" | ||
aria-label="Tooltip" | ||
aria-expanded={open} | ||
tabIndex={0} | ||
/> | ||
<span className={textClasses.join(' ')}> | ||
{text} | ||
</span> | ||
</span> | ||
); | ||
}; | ||
|
||
export default Tooltip; |
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