bolt.diy/app/components/ui/Tooltip.tsx

40 lines
1.1 KiB
TypeScript
Raw Normal View History

import React from 'react';
import * as Tooltip from '@radix-ui/react-tooltip';
2024-11-22 22:29:16 +00:00
import type { ReactNode } from 'react';
2024-11-22 09:51:52 +00:00
interface ToolTipProps {
2024-11-22 22:29:16 +00:00
tooltip: string;
2024-11-22 09:51:52 +00:00
children: ReactNode | ReactNode[];
2024-11-22 22:29:16 +00:00
sideOffset?: number;
className?: string;
arrowClassName?: string;
tooltipStyle?: any; //TODO better type
2024-11-22 09:51:52 +00:00
}
2024-11-22 22:29:16 +00:00
const WithTooltip = ({
tooltip,
children,
sideOffset = 5,
className = '',
arrowClassName = '',
tooltipStyle = {},
}: ToolTipProps) => {
return (
<Tooltip.Root>
2024-11-22 22:29:16 +00:00
<Tooltip.Trigger asChild>{children}</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content
className={`bg-bolt-elements-tooltip-background text-bolt-elements-textPrimary px-3 py-2 rounded-lg text-sm shadow-lg ${className}`}
sideOffset={sideOffset}
2024-11-22 22:29:16 +00:00
style={{ zIndex: 2000, backgroundColor: 'white', ...tooltipStyle }}
>
{tooltip}
<Tooltip.Arrow className={`fill-bolt-elements-tooltip-background ${arrowClassName}`} />
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
);
};
export default WithTooltip;