Skip to content

Commit

Permalink
reuseable tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
Mridul2820 committed Jan 22, 2022
1 parent c8cf654 commit 5659208
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
22 changes: 2 additions & 20 deletions components/graphs/ContributionGraph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { LineChart, Line, Tooltip, YAxis, XAxis, ResponsiveContainer, CartesianGrid } from 'recharts';
import CustomTooltip from '../reuse/CustomTooltip';

const ContributionGraph = ({ weeks,username }) => {
let contributions = []
Expand All @@ -20,25 +21,6 @@ const ContributionGraph = ({ weeks,username }) => {
36 + presentDay
);

const CustomTooltip = ({ active, payload, label }) => {
if (active && payload && payload.length) {
return (
<div className="custom-tooltip backdrop-blur-sm shadow-sm bg-slate-50 p-2">
<p className="intro font-semibold">
{`Contribution : ${payload[0].value}`}
</p>

<p className="label">
{`Date : ${label}`}
</p>

</div>
);
}

return null;
};

const tickDate = value => {
const roundVal = new Date(value).getDate();

Expand All @@ -63,7 +45,7 @@ const ContributionGraph = ({ weeks,username }) => {
>
<CartesianGrid/>
<Tooltip
content={<CustomTooltip />}
content={<CustomTooltip customLabel1="Date" customLabel2="Contribution" />}
/>
<XAxis
dataKey="date"
Expand Down
2 changes: 1 addition & 1 deletion components/graphs/MostForked.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const MostForked = ({ repos }) => {
width={24}
tickFormatter={tickFork}
/>
<Tooltip content={<CustomTooltip />} />
<Tooltip content={<CustomTooltip customLabel1="Repository" customLabel2="Fork Count" />} />
<Bar dataKey="forkCount" fill="#8884d8" />
</BarChart>
</ResponsiveContainer>
Expand Down
2 changes: 1 addition & 1 deletion components/graphs/MostStar.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const MostStar = ({ repos }) => {
width={24}
tickFormatter={tickFork}
/>
<Tooltip content={<CustomTooltip />} />
<Tooltip content={<CustomTooltip customLabel1="Repository" customLabel2="Star Count" />} />

<Bar dataKey="stargazerCount" fill="#82ca9d" />
</BarChart>
Expand Down
8 changes: 4 additions & 4 deletions components/reuse/CustomTooltip.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react';

const CustomTooltip = ({ active, payload }) => {
const CustomTooltip = ({ active, payload, customLabel1, customLabel2, label }) => {

if (active && payload && payload.length) {
return (
<div className="custom-tooltip backdrop-blur-sm shadow-sm bg-slate-50 p-2">
<p className="flex gap-3">
<span>Repository : </span>
<span className="font-semibold">{payload[0].payload.name}</span>
<span>{customLabel1} : </span>
<span className="font-semibold">{label}</span>
</p>

<p className="flex gap-3">
<span>Star Count : </span>
<span>{customLabel2} : </span>
<span className="font-semibold">{payload[0].value}</span>
</p>
</div>
Expand Down

1 comment on commit 5659208

@vercel
Copy link

@vercel vercel bot commented on 5659208 Jan 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.