Scheduling infrastructure for absolutely everyone.
refactor: extract PanelCard from ChartCard for reusability (#23360)
Eunjae Leecdcc04c8ff62
diff --git a/packages/features/insights/components/ChartCard.tsx b/packages/features/insights/components/ChartCard.tsxindex 63ca947923d..b32833ee482 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<LegendItem>;legendSize?: LegendSize;- children: React.ReactNode;+ children: ReactNode;}) {+ const legendComponent = legend && legend.length > 0 ? <Legend items={legend} size={legendSize} /> : null;+return (- <div className="bg-muted group relative flex w-full flex-col items-center rounded-2xl px-1 pb-1">- <div className="flex h-11 w-full shrink-0 items-center justify-between gap-2 px-4">- {typeof title === "string" ? (- <h2 className="text-emphasis mr-4 shrink-0 text-sm font-semibold">{title}</h2>- ) : (- title- )}- <div className="no-scrollbar flex items-center gap-2 overflow-x-auto">- {legend && legend.length > 0 && <Legend items={legend} size={legendSize} />}- {cta && (- <Button className="shrink-0" color="secondary" onClick={cta.onClick}>- {cta.label}- </Button>- )}- </div>- </div>- <div className="bg-default border-muted w-full grow gap-3 rounded-xl border">- {subtitle && (- <h3 className="text-subtle border-muted border-b p-3 text-sm font-medium leading-none">- {subtitle}- </h3>- )}- {children}- </div>- </div>+ <PanelCard title={title} subtitle={subtitle} cta={cta} headerContent={legendComponent}>+ {children}+ </PanelCard>);}diff --git a/packages/ui/components/card/PanelCard.tsx b/packages/ui/components/card/PanelCard.tsxnew file mode 100644index 00000000000..1339d7d949c--- /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 (+ <div className="bg-muted group relative flex w-full flex-col items-center rounded-2xl px-1 pb-1">+ <div className="flex h-11 w-full shrink-0 items-center justify-between gap-2 px-4">+ {typeof title === "string" ? (+ <h2 className="text-emphasis mr-4 shrink-0 text-sm font-semibold">{title}</h2>+ ) : (+ title+ )}+ <div className="no-scrollbar flex items-center gap-2 overflow-x-auto">+ {headerContent}+ {cta && (+ <Button className="shrink-0" color="secondary" onClick={cta.onClick}>+ {cta.label}+ </Button>+ )}+ </div>+ </div>+ <div className="bg-default border-muted w-full grow gap-3 rounded-xl border">+ {subtitle && (+ <h3 className="text-subtle border-muted border-b p-3 text-sm font-medium leading-none">+ {subtitle}+ </h3>+ )}+ {children}+ </div>+ </div>+ );+}diff --git a/packages/ui/components/card/index.ts b/packages/ui/components/card/index.tsindex 3412abfa93b..b733fadda4e 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";