Merge pull request 'Tooltip - onHover - Tooltip text and children can be provided' (#58) from feature/tooltip into develop
Reviewed-on: http://85.143.176.51:3000/free-land/front-end/pulls/58
This commit is contained in:
commit
c18cea8c89
40
src/components/Tooltip.tsx
Normal file
40
src/components/Tooltip.tsx
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
|
export interface TooltipProps {
|
||||||
|
/**
|
||||||
|
* Tooltip text - can be string or another component
|
||||||
|
*/
|
||||||
|
tooltipMessage: ReactNode;
|
||||||
|
/**
|
||||||
|
* The targeted component
|
||||||
|
*/
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Tooltip = ({ tooltipMessage, children }: TooltipProps) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="group cursor-pointer relative focus:outline-none overflow-hidden
|
||||||
|
hover:overflow-visible"
|
||||||
|
>
|
||||||
|
{/* Tooltip will be shown under the component(children) when the children is onHover */}
|
||||||
|
{children}
|
||||||
|
{/* Creating the tooltip and give it a postion */}
|
||||||
|
<div
|
||||||
|
className="absolute left-1/2 -bottom-10 p-2 rounded transition-all duration-1000
|
||||||
|
bg-gray-900 text-white text-sm -translate-x-1/2 opacity-0 z-40
|
||||||
|
|
||||||
|
leading-none whitespace-no-wrap w-fit text-center
|
||||||
|
|
||||||
|
before:content-[''] before:absolute before:-top-1 before:left-1/2 before:-translate-x-1/2
|
||||||
|
before:w-3 before:h-3 before:bg-gray-900 before:rotate-45 before:rounded-sm
|
||||||
|
|
||||||
|
group-hover:opacity-100"
|
||||||
|
>
|
||||||
|
{tooltipMessage}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Tooltip;
|
Loading…
x
Reference in New Issue
Block a user