generated from yandex-praktikum/client-server-template-with-vite
-
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.
Merge pull request #92 from MYiLA/feature/CYB-124-разработать-компоне…
…нт-тултипа CYB-124: разработать компонент тултипа
- Loading branch information
Showing
4 changed files
with
199 additions
and
30 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
103 changes: 103 additions & 0 deletions
103
packages/client/src/shared/ui/tooltip/tooltip.module.scss
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,103 @@ | ||
@import "@scss/_variables.scss"; | ||
|
||
.tooltip { | ||
&_wrapper { | ||
display: inline-block; | ||
position: relative; | ||
} | ||
|
||
&_tip { | ||
position: absolute; | ||
border-radius: 12px; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
padding: 8px; | ||
color: $color-black; | ||
font-size: 14px; | ||
font-family: sans-serif; | ||
line-height: 1; | ||
z-index: 100; | ||
white-space: nowrap; | ||
min-width: 250px; | ||
max-width: 300px; | ||
text-align: center; | ||
|
||
&::before { | ||
content: " "; | ||
left: 50%; | ||
border: solid transparent; | ||
height: 0; | ||
width: 0; | ||
position: absolute; | ||
pointer-events: none; | ||
border-width: 12px; | ||
margin-left: -6px; | ||
} | ||
|
||
&.neon { | ||
background: $player-blue; | ||
|
||
&::before { | ||
border-top-color: $player-blue; | ||
} | ||
} | ||
|
||
&.purple { | ||
background: $color-violet; | ||
|
||
&::before { | ||
border-top-color: $color-violet; | ||
} | ||
} | ||
|
||
span { | ||
width: 100%; | ||
white-space: normal; | ||
overflow-wrap: break-word; | ||
text-align: center; | ||
} | ||
|
||
&.top { | ||
top: -190%; | ||
|
||
&::before { | ||
top: 100%; | ||
border-width: 8px; | ||
} | ||
} | ||
|
||
&.right { | ||
left: calc(100% + 30px); | ||
top: 50%; | ||
transform: translateX(0) translateY(-50%); | ||
|
||
&::before { | ||
left: -14px; | ||
top: 50%; | ||
transform: translateX(0) translateY(-50%) rotate(90deg); | ||
} | ||
} | ||
|
||
&.bottom { | ||
bottom: -38px; | ||
|
||
&::before { | ||
bottom: 100%; | ||
} | ||
} | ||
|
||
&.left { | ||
left: auto; | ||
right: calc(100% + 30px); | ||
top: 50%; | ||
transform: translateX(0) translateY(-50%); | ||
|
||
&::before { | ||
left: auto; | ||
right: -12px; | ||
top: 50%; | ||
transform: translateX(0) translateY(-50%); | ||
} | ||
} | ||
} | ||
} |
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,57 @@ | ||
import { ReactElement, ReactNode, useState } from "react"; | ||
import { useTheme } from "@hooks/use-theme"; | ||
import { Theme } from "@config/constants"; | ||
import cn from "classnames"; | ||
import styles from "./tooltip.module.scss"; | ||
|
||
interface TooltipProps { | ||
direction: "top" | "left" | "right" | "bottom"; | ||
children: ReactNode; | ||
text: string; | ||
} | ||
|
||
export const Tooltip = ({ | ||
children, | ||
text, | ||
direction = "top", | ||
}: TooltipProps): ReactElement => { | ||
let timeout: NodeJS.Timeout; | ||
const [active, setActive] = useState(false); | ||
|
||
const themeName = useTheme(); | ||
|
||
const showTip = () => { | ||
timeout = setTimeout(() => { | ||
setActive(true); | ||
}, 200); | ||
}; | ||
|
||
const hideTip = () => { | ||
clearInterval(timeout); | ||
setActive(false); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={styles.tooltip_wrapper} | ||
onMouseEnter={showTip} | ||
onMouseLeave={hideTip} | ||
> | ||
{children} | ||
{active && ( | ||
<div | ||
className={cn(styles.tooltip_tip, { | ||
[styles.purple]: themeName === Theme.Purple, | ||
[styles.neon]: themeName === Theme.Neon, | ||
[styles.top]: direction === "top", | ||
[styles.bottom]: direction === "bottom", | ||
[styles.left]: direction === "left", | ||
[styles.right]: direction === "right", | ||
})} | ||
> | ||
<span>{text}</span> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |