Skip to content

Commit cdcc04c

Browse files
eunjae-leedevin-ai-integration[bot]Udit-takkar
authored
refactor: extract PanelCard from ChartCard for reusability (calcom#23360)
* feat: extract PanelCard from ChartCard for reusability - Create base PanelCard and PanelCardItem components in UI package - Refactor ChartCard to use PanelCard as foundation while keeping legend functionality - Add headerActions prop to PanelCard for extensibility - Maintain backward compatibility for existing ChartCard usage - Export PanelCard and PanelCardItem from UI card components Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * chore: update yarn.lock after dependency resolution Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * refactor: rename prop from actions to headerContent - Rename 'actions' prop to 'headerContent' in PanelCard component - Update ChartCard to use new 'headerContent' prop name - More accurate naming since content can be text or other elements, not just buttons Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * clean up * revert yarn.lock * fix type error * type fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
1 parent 740a1c9 commit cdcc04c

3 files changed

Lines changed: 54 additions & 28 deletions

File tree

packages/features/insights/components/ChartCard.tsx

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { Fragment, type ReactNode } from "react";
44

55
import classNames from "@calcom/ui/classNames";
6-
import { Button } from "@calcom/ui/components/button";
6+
import { PanelCard } from "@calcom/ui/components/card";
77
import { Tooltip } from "@calcom/ui/components/tooltip";
88

99
type LegendItem = {
@@ -21,39 +21,19 @@ export function ChartCard({
2121
legendSize,
2222
children,
2323
}: {
24-
title: string | React.ReactNode;
24+
title: string | ReactNode;
2525
subtitle?: string;
2626
cta?: { label: string; onClick: () => void };
2727
legend?: Array<LegendItem>;
2828
legendSize?: LegendSize;
29-
children: React.ReactNode;
29+
children: ReactNode;
3030
}) {
31+
const legendComponent = legend && legend.length > 0 ? <Legend items={legend} size={legendSize} /> : null;
32+
3133
return (
32-
<div className="bg-muted group relative flex w-full flex-col items-center rounded-2xl px-1 pb-1">
33-
<div className="flex h-11 w-full shrink-0 items-center justify-between gap-2 px-4">
34-
{typeof title === "string" ? (
35-
<h2 className="text-emphasis mr-4 shrink-0 text-sm font-semibold">{title}</h2>
36-
) : (
37-
title
38-
)}
39-
<div className="no-scrollbar flex items-center gap-2 overflow-x-auto">
40-
{legend && legend.length > 0 && <Legend items={legend} size={legendSize} />}
41-
{cta && (
42-
<Button className="shrink-0" color="secondary" onClick={cta.onClick}>
43-
{cta.label}
44-
</Button>
45-
)}
46-
</div>
47-
</div>
48-
<div className="bg-default border-muted w-full grow gap-3 rounded-xl border">
49-
{subtitle && (
50-
<h3 className="text-subtle border-muted border-b p-3 text-sm font-medium leading-none">
51-
{subtitle}
52-
</h3>
53-
)}
54-
{children}
55-
</div>
56-
</div>
34+
<PanelCard title={title} subtitle={subtitle} cta={cta} headerContent={legendComponent}>
35+
{children}
36+
</PanelCard>
5737
);
5838
}
5939

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { ReactNode } from "react";
2+
3+
import { Button } from "@calcom/ui/components/button";
4+
5+
export function PanelCard({
6+
title,
7+
subtitle,
8+
cta,
9+
headerContent,
10+
children,
11+
}: {
12+
title: string | ReactNode;
13+
subtitle?: string;
14+
cta?: { label: string; onClick: () => void };
15+
headerContent?: ReactNode;
16+
children: ReactNode;
17+
}) {
18+
return (
19+
<div className="bg-muted group relative flex w-full flex-col items-center rounded-2xl px-1 pb-1">
20+
<div className="flex h-11 w-full shrink-0 items-center justify-between gap-2 px-4">
21+
{typeof title === "string" ? (
22+
<h2 className="text-emphasis mr-4 shrink-0 text-sm font-semibold">{title}</h2>
23+
) : (
24+
title
25+
)}
26+
<div className="no-scrollbar flex items-center gap-2 overflow-x-auto">
27+
{headerContent}
28+
{cta && (
29+
<Button className="shrink-0" color="secondary" onClick={cta.onClick}>
30+
{cta.label}
31+
</Button>
32+
)}
33+
</div>
34+
</div>
35+
<div className="bg-default border-muted w-full grow gap-3 rounded-xl border">
36+
{subtitle && (
37+
<h3 className="text-subtle border-muted border-b p-3 text-sm font-medium leading-none">
38+
{subtitle}
39+
</h3>
40+
)}
41+
{children}
42+
</div>
43+
</div>
44+
);
45+
}

packages/ui/components/card/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { default as Card } from "./Card";
22
export type { BaseCardProps } from "./Card";
33
export { StepCard } from "./StepCard";
44
export { default as FormCard } from "./FormCard";
5+
export { PanelCard } from "./PanelCard";

0 commit comments

Comments
 (0)