diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 89d95cee3c8f1f..20185cd16e9cf8 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -3580,6 +3580,8 @@ "free": "Free", "user_email": "User Email", "user_name": "User Name", + "expand_panel": "Expand Panel", + "collapse_panel": "Collapse Panel", "you_have_one_team": "You have one team", "consider_consolidating_one_team_org": "Consider setting up an organization to unify billing, admin tools, and analytics across your team.", "consider_consolidating_multi_team_org": "Consider setting up an organization to unify billing, admin tools, and analytics across your teams.", diff --git a/packages/features/insights/components/ChartCard.tsx b/packages/features/insights/components/ChartCard.tsx index 3e01ef4a16791b..58175d5d31b095 100644 --- a/packages/features/insights/components/ChartCard.tsx +++ b/packages/features/insights/components/ChartCard.tsx @@ -6,6 +6,8 @@ import classNames from "@calcom/ui/classNames"; import { PanelCard } from "@calcom/ui/components/card"; import { Tooltip } from "@calcom/ui/components/tooltip"; +type PanelCardProps = React.ComponentProps; + type LegendItem = { label: string; color: string; // hex format @@ -14,27 +16,16 @@ type LegendItem = { export type LegendSize = "sm" | "default"; export function ChartCard({ - title, - subtitle, - cta, legend, legendSize, enabledLegend, onSeriesToggle, - children, - className, - titleTooltip, -}: { - title: string | ReactNode; - subtitle?: string; - cta?: { label: string; onClick: () => void }; + ...panelCardProps +}: PanelCardProps & { legend?: Array; legendSize?: LegendSize; enabledLegend?: Array; onSeriesToggle?: (label: string) => void; - className?: string; - titleTooltip?: string; - children: ReactNode; }) { const legendComponent = legend && legend.length > 0 ? ( @@ -43,13 +34,18 @@ export function ChartCard({ return ( - {children} + {...panelCardProps} + headerContent={ + panelCardProps.headerContent ? ( +
+ {panelCardProps.headerContent} + {legendComponent} +
+ ) : ( + legendComponent + ) + }> + {panelCardProps.children}
); } diff --git a/packages/ui/components/card/PanelCard.tsx b/packages/ui/components/card/PanelCard.tsx index 93552042682a02..94477957d51708 100644 --- a/packages/ui/components/card/PanelCard.tsx +++ b/packages/ui/components/card/PanelCard.tsx @@ -1,8 +1,14 @@ +"use client"; + +import { useAutoAnimate } from "@formkit/auto-animate/react"; import type { ReactNode } from "react"; +import { useId, useState } from "react"; +import { useLocale } from "@calcom/lib/hooks/useLocale"; import classNames from "@calcom/ui/classNames"; import { InfoBadge } from "@calcom/ui/components/badge"; import { Button } from "@calcom/ui/components/button"; +import { Icon } from "@calcom/ui/components/icon"; export function PanelCard({ title, @@ -12,6 +18,8 @@ export function PanelCard({ className, titleTooltip, children, + collapsible = false, + defaultCollapsed = false, }: { title: string | ReactNode; subtitle?: string; @@ -20,22 +28,75 @@ export function PanelCard({ className?: string; titleTooltip?: string; children: ReactNode; + collapsible?: boolean; + defaultCollapsed?: boolean; }) { + const { t } = useLocale(); + const [isCollapsed, setIsCollapsed] = useState(defaultCollapsed); + const contentId = useId(); + const titleId = useId(); + const [animationParent] = useAutoAnimate(); + + const toggleCollapse = () => { + setIsCollapsed((prev) => !prev); + }; + + const isStringTitle = typeof title === "string"; + return (
- {typeof title === "string" ? ( -
-

{title}

- {titleTooltip && } -
- ) : ( - title - )} +
+ {collapsible && ( + + ) : ( + (title as string) + )} + + {titleTooltip && } +
+ ) : ( + title + )} +
{headerContent} {cta && ( @@ -45,14 +106,20 @@ export function PanelCard({ )}
-
- {subtitle && ( -

- {subtitle} -

- )} - {children} -
+ {!(isCollapsed && collapsible) && ( +
+ {subtitle && ( +

+ {subtitle} +

+ )} + {children} +
+ )} ); }