From cdcc04c8ff62cdea611bedbae522f28449ae6738 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Wed, 27 Aug 2025 11:18:44 +0200 Subject: [PATCH] refactor: extract PanelCard from ChartCard for reusability (#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 * chore: update yarn.lock after dependency resolution Co-Authored-By: eunjae@cal.com * 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 * 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> --- .../insights/components/ChartCard.tsx | 36 ++++----------- packages/ui/components/card/PanelCard.tsx | 45 +++++++++++++++++++ packages/ui/components/card/index.ts | 1 + 3 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 packages/ui/components/card/PanelCard.tsx diff --git a/packages/features/insights/components/ChartCard.tsx b/packages/features/insights/components/ChartCard.tsx index 63ca947923..b32833ee48 100644 --- a/packages/features/insights/components/ChartCard.tsx +++ b/packages/features/insights/components/ChartCard.tsx @@ -3,7 +3,7 @@ import { Fragment, type ReactNode } from "react"; import classNames from "@calcom/ui/classNames"; -import { Button } from "@calcom/ui/components/button"; +import { PanelCard } from "@calcom/ui/components/card"; import { Tooltip } from "@calcom/ui/components/tooltip"; type LegendItem = { @@ -21,39 +21,19 @@ export function ChartCard({ legendSize, children, }: { - title: string | React.ReactNode; + title: string | ReactNode; subtitle?: string; cta?: { label: string; onClick: () => void }; legend?: Array; legendSize?: LegendSize; - children: React.ReactNode; + children: ReactNode; }) { + const legendComponent = legend && legend.length > 0 ? : null; + return ( -
-
- {typeof title === "string" ? ( -

{title}

- ) : ( - title - )} -
- {legend && legend.length > 0 && } - {cta && ( - - )} -
-
-
- {subtitle && ( -

- {subtitle} -

- )} - {children} -
-
+ + {children} + ); } diff --git a/packages/ui/components/card/PanelCard.tsx b/packages/ui/components/card/PanelCard.tsx new file mode 100644 index 0000000000..1339d7d949 --- /dev/null +++ b/packages/ui/components/card/PanelCard.tsx @@ -0,0 +1,45 @@ +import type { ReactNode } from "react"; + +import { Button } from "@calcom/ui/components/button"; + +export function PanelCard({ + title, + subtitle, + cta, + headerContent, + children, +}: { + title: string | ReactNode; + subtitle?: string; + cta?: { label: string; onClick: () => void }; + headerContent?: ReactNode; + children: ReactNode; +}) { + return ( +
+
+ {typeof title === "string" ? ( +

{title}

+ ) : ( + title + )} +
+ {headerContent} + {cta && ( + + )} +
+
+
+ {subtitle && ( +

+ {subtitle} +

+ )} + {children} +
+
+ ); +} diff --git a/packages/ui/components/card/index.ts b/packages/ui/components/card/index.ts index 3412abfa93..b733fadda4 100644 --- a/packages/ui/components/card/index.ts +++ b/packages/ui/components/card/index.ts @@ -2,3 +2,4 @@ export { default as Card } from "./Card"; export type { BaseCardProps } from "./Card"; export { StepCard } from "./StepCard"; export { default as FormCard } from "./FormCard"; +export { PanelCard } from "./PanelCard";