Skip to content

Commit

Permalink
Merge pull request #50 from deepumandal/26-hovercard
Browse files Browse the repository at this point in the history
 feat: hover card added
  • Loading branch information
deepumandal authored Aug 4, 2024
2 parents 1d45b52 + 691dc59 commit ba83832
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-context-menu": "^2.2.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-hover-card": "^1.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
Expand Down
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

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

37 changes: 35 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Slash } from "lucide-react";
import { Slash, CalendarDays } from "lucide-react";
import { useState } from "react";
import { useTheme } from "@Components/hooks";
import {
Expand All @@ -15,6 +15,7 @@ import {
Typography,
ContextMenu,
Tooltip,
HoverCard,
} from "@Components/ui";

const App = () => (
Expand All @@ -23,7 +24,7 @@ const App = () => (
ScreenType="container"
fullHeight
border
className="p-20 flex items-center flex-col"
className="p-20 mb-40 flex items-center flex-col"
>
<Flex flexDirection="column" className="gap-10" alignItems="center">
<ThemeBtn />
Expand Down Expand Up @@ -182,6 +183,10 @@ const App = () => (
</Tooltip>
</Tooltip.Provider>
</Flex>

<Flex asElement="section" className="w-full">
<HoverCardDemo />
</Flex>
</Container>
);

Expand Down Expand Up @@ -222,6 +227,34 @@ const AreYouSure = () => {
);
};

export const HoverCardDemo = () => (
<HoverCard>
<HoverCard.Trigger asChild>
<Button variant="link">@nextjs</Button>
</HoverCard.Trigger>
<HoverCard.Content className="w-80">
<div className="flex justify-between space-x-4">
<Avatar>
<Avatar.Image src="https://github.com/vercel.png" />
<Avatar.Fallback>VC</Avatar.Fallback>
</Avatar>
<div className="space-y-1">
<h4 className="text-sm font-semibold">@nextjs</h4>
<p className="text-sm">
The React Framework – created and maintained by @vercel.
</p>
<div className="flex items-center pt-2">
<CalendarDays className="mr-2 h-4 w-4 opacity-70" />{" "}
<span className="text-xs text-muted-foreground">
Joined December 2021
</span>
</div>
</div>
</div>
</HoverCard.Content>
</HoverCard>
);

const ThemeBtn = () => {
const { setTheme } = useTheme();

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

interface HoverCardProps extends HoverCardPrimitive.HoverCardProps {
Trigger?: typeof HoverCardPrimitive.Trigger;
Content?: typeof HoverCardPrimitive.Content;
}

const HoverCard = ({ children }: HoverCardProps) => (
<HoverCardPrimitive.Root>{children}</HoverCardPrimitive.Root>
);

const HoverCardTrigger = HoverCardPrimitive.Trigger;

const HoverCardContent = forwardRef<
ElementRef<typeof HoverCardPrimitive.Content>,
ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
<HoverCardPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cn(
"z-50 w-64 rounded-md border bg-white p-4 text-text shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-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}
/>
));
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName;

HoverCard.Trigger = HoverCardTrigger;
HoverCard.Content = HoverCardContent;

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

0 comments on commit ba83832

Please sign in to comment.