Skip to content

Commit

Permalink
unifies info tooltips in single component
Browse files Browse the repository at this point in the history
  • Loading branch information
agnlez authored and Andrés González committed Nov 13, 2024
1 parent 4cc05fe commit 00839cc
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 92 deletions.
17 changes: 13 additions & 4 deletions client/src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as React from "react";

import * as DialogPrimitive from "@radix-ui/react-dialog";
import { Cross2Icon } from "@radix-ui/react-icons";
import { XIcon } from "lucide-react";

import { cn } from "@/lib/utils";

Expand Down Expand Up @@ -45,10 +45,10 @@ const DialogContent = React.forwardRef<
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<Cross2Icon className="h-4 w-4" />
<DialogClose className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<XIcon className="h-5 w-5 text-foreground hover:text-muted-foreground" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogClose>
</DialogPrimitive.Content>
</DialogPortal>
));
Expand Down Expand Up @@ -109,13 +109,22 @@ const DialogDescription = React.forwardRef<
));
DialogDescription.displayName = DialogPrimitive.Description.displayName;

const DialogContentContainer = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn("space-y-1.5 text-foreground", className)} {...props} />
);
DialogContentContainer.displayName = "DialogContentContainer";

export {
Dialog,
DialogPortal,
DialogOverlay,
DialogTrigger,
DialogClose,
DialogContent,
DialogContentContainer,
DialogHeader,
DialogFooter,
DialogTitle,
Expand Down
37 changes: 37 additions & 0 deletions client/src/components/ui/info-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { PropsWithChildren } from "react";
import * as React from "react";

import { InfoIcon } from "lucide-react";

import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogContentContainer,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";

export default function InfoButton({
title,
children,
}: PropsWithChildren<{
title?: string;
}>) {
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="ghost" className="h-5 w-5 p-0 hover:bg-transparent">
<InfoIcon className="h-7 w-7 text-foreground hover:text-muted-foreground" />
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
{title && <DialogTitle>{title}</DialogTitle>}
<DialogContentContainer>{children}</DialogContentContainer>
</DialogHeader>
</DialogContent>
</Dialog>
);
}
28 changes: 2 additions & 26 deletions client/src/components/ui/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@ import * as React from "react";

import * as LabelPrimitive from "@radix-ui/react-label";
import { cva, type VariantProps } from "class-variance-authority";
import { InfoIcon } from "lucide-react";

import { cn } from "@/lib/utils";

import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import InfoButton from "@/components/ui/info-button";

const labelVariants = cva(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
Expand All @@ -40,22 +31,7 @@ const Label = React.forwardRef<
className={cn(labelVariants(), className)}
{...props}
/>
<Dialog>
<DialogTrigger asChild>
<Button
variant="ghost"
className="group h-5 w-5 p-0 hover:bg-transparent"
>
<InfoIcon className="h-7 w-7 text-foreground hover:text-muted-foreground" />
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>{tooltip.title}</DialogTitle>
<DialogDescription>{tooltip.content}</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
<InfoButton title={tooltip.title}>{tooltip.content}</InfoButton>
</div>
);
}
Expand Down
32 changes: 30 additions & 2 deletions client/src/containers/projects/table/toolbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
import InfoDownloadProjectsTable from "@/containers/projects/table/toolbar/info-download";
import SearchProjectsTable from "@/containers/projects/table/toolbar/search";
import TabsProjectsTable from "@/containers/projects/table/toolbar/table-selector";

import InfoButton from "@/components/ui/info-button";

export default function ToolbarProjectsTable() {
return (
<div className="flex items-center justify-between px-5 py-3">
<SearchProjectsTable />
<TabsProjectsTable />
<InfoDownloadProjectsTable />
<div className="flex flex-1 items-center justify-end space-x-2">
<InfoButton>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
vehicula, nunc nec vehicula fermentum, nunc libero bibendum purus,
nec tincidunt libero nunc nec libero. Integer nec libero nec libero
tincidunt tincidunt. Sed vehicula, nunc nec vehicula fermentum, nunc
libero bibendum purus, nec tincidunt libero nunc nec libero. Integer
nec libero nec libero tincidunt tincidunt.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
vehicula, nunc nec vehicula fermentum, nunc libero bibendum purus,
nec tincidunt libero nunc nec libero. Integer nec libero nec libero
tincidunt tincidunt. Sed vehicula, nunc nec vehicula fermentum, nunc
libero bibendum purus, nec tincidunt libero nunc nec libero. Integer
nec libero nec libero tincidunt tincidunt.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
vehicula, nunc nec vehicula fermentum, nunc libero bibendum purus,
nec tincidunt libero nunc nec libero. Integer nec libero nec libero
tincidunt tincidunt. Sed vehicula, nunc nec vehicula fermentum, nunc
libero bibendum purus, nec tincidunt libero nunc nec libero. Integer
nec libero nec libero tincidunt tincidunt.
</p>
</InfoButton>
</div>
</div>
);
}

This file was deleted.

0 comments on commit 00839cc

Please sign in to comment.