Skip to content

Commit

Permalink
chore: Add tooltip functionality to GraphData component in playground
Browse files Browse the repository at this point in the history
  • Loading branch information
HasanYahya101 committed Jun 7, 2024
1 parent c858454 commit 1c5294f
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 1 deletion.
150 changes: 150 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tooltip": "^1.0.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"cmdk": "^1.0.0",
Expand Down
30 changes: 29 additions & 1 deletion src/components/component/playground.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import { ResponsiveLine } from "@nivo/line";
import { Checkbox } from "@/components/ui/checkbox";
import { Dialog } from "@/components/ui/dialog";
import { DialogTrigger, DialogContent, DialogDescription, DialogClose, DialogTitle } from "@/components/ui/dialog";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip"


function roundTo(num, decimalPlaces) {
var factor = Math.pow(10, decimalPlaces);
Expand Down Expand Up @@ -86,6 +93,8 @@ function GraphData({ check, testData, setTestData, setCheck }) {
const [fiftyTwoWeekHigh, setFiftyTwoWeekHigh] = useState("NULL");
const [fiftyTwoWeekLow, setFiftyTwoWeekLow] = useState("NULL");

const [companydescription, setCompanyDescription] = useState("NULL");

const [month1, setMonth1] = useState('');
const [month2, setMonth2] = useState('');
const [month3, setMonth3] = useState('');
Expand Down Expand Up @@ -167,6 +176,8 @@ function GraphData({ check, testData, setTestData, setCheck }) {
const quoteType = JSONResponse.quoteType;
const priceData = JSONResponse.price;
const summarydetail = JSONResponse.summaryDetail;
const summaryProfile = JSONResponse.summaryProfile;
setCompanyDescription(summaryProfile.longBusinessSummary);

setLongName(quoteType.longName);
setSymbol(quoteType.symbol);
Expand Down Expand Up @@ -295,7 +306,24 @@ function GraphData({ check, testData, setTestData, setCheck }) {
</span>
</div>
</div>
<ChevronRightIcon className="w-5 h-5 text-gray-500 dark:text-gray-400" />
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button variant="outline" className="p-2 rounded-md"
>
<ChevronRightIcon className="w-5 h-5 text-gray-500 dark:text-gray-400" />
</Button>
</TooltipTrigger>
<TooltipContent>
<h1 className="text-lg font-semibold p-4">{longName}</h1>
<div className="text-sm text-gray-500 dark:text-gray-400 max-w-[90vh] p-4 max-h-[40vh] overflow-y-auto"
style={{ scrollbarWidth: "none" }}
>
{companydescription}
</div>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</CardHeader>
<CardContent>
<div className="grid gap-4">
Expand Down
26 changes: 26 additions & 0 deletions src/components/ui/tooltip.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use client"

import * as React from "react"
import * as TooltipPrimitive from "@radix-ui/react-tooltip"

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

const TooltipProvider = TooltipPrimitive.Provider

const Tooltip = TooltipPrimitive.Root

const TooltipTrigger = TooltipPrimitive.Trigger

const TooltipContent = React.forwardRef(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground 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

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }

0 comments on commit 1c5294f

Please sign in to comment.