Skip to content

Commit

Permalink
feat: tool tip component
Browse files Browse the repository at this point in the history
  • Loading branch information
deepumandal committed Aug 4, 2024
1 parent 7b24a66 commit 9e0d2ba
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.417.0",
Expand Down
58 changes: 58 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Checkbox,
Typography,
ContextMenu,
Tooltip,
} from "@Components/ui";

const App = () => (
Expand Down Expand Up @@ -170,6 +171,17 @@ const App = () => (
<ContextMenu.Item>hello</ContextMenu.Item>
</ContextMenu.Content>
</ContextMenu>

<Flex asElement="section" className="w-full">
<Tooltip.Provider>
<Tooltip>
<Tooltip.Trigger asChild>
<Button variant="outline">Hover me</Button>
</Tooltip.Trigger>
<Tooltip.Content>Tooltip content</Tooltip.Content>
</Tooltip>
</Tooltip.Provider>
</Flex>
</Container>
);

Expand Down
38 changes: 38 additions & 0 deletions src/components/ui/ToolTip/ToolTip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from "react";
import { cn } from "@Utils/className";

interface TooltipProps extends TooltipPrimitive.TooltipProps {
Trigger?: typeof TooltipTrigger;
Content?: typeof TooltipContent;
Provider?: typeof TooltipProvider;
}

const Tooltip = ({ children, ...rest }: TooltipProps) => (
<TooltipPrimitive.Root {...rest}>{children}</TooltipPrimitive.Root>
);

const TooltipProvider = TooltipPrimitive.Provider;
const TooltipTrigger = TooltipPrimitive.Trigger;

const TooltipContent = forwardRef<
ElementRef<typeof TooltipPrimitive.Content>,
ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 overflow-hidden rounded-md border bg-white px-3 py-1.5 text-sm text-text shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className
)}
{...props}
/>
));
TooltipContent.displayName = TooltipPrimitive.Content.displayName;

Tooltip.Trigger = TooltipTrigger;
Tooltip.Content = TooltipContent;
Tooltip.Provider = TooltipProvider;

export { Tooltip };
1 change: 1 addition & 0 deletions src/components/ui/ToolTip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ToolTip";
1 change: 1 addition & 0 deletions src/components/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export { Badge } from "./Badge";
export { Breadcrumb } from "./Breadcrumb";
export { Checkbox } from "./CheckBox";
export { ContextMenu } from "./ContextMenu";
export { Tooltip } from "./ToolTip";

0 comments on commit 9e0d2ba

Please sign in to comment.