Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/web/public/static/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
36 changes: 16 additions & 20 deletions packages/features/insights/components/ChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof PanelCard>;

type LegendItem = {
label: string;
color: string; // hex format
Expand All @@ -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<LegendItem>;
legendSize?: LegendSize;
enabledLegend?: Array<LegendItem>;
onSeriesToggle?: (label: string) => void;
className?: string;
titleTooltip?: string;
children: ReactNode;
}) {
const legendComponent =
legend && legend.length > 0 ? (
Expand All @@ -43,13 +34,18 @@ export function ChartCard({

return (
<PanelCard
title={title}
subtitle={subtitle}
cta={cta}
headerContent={legendComponent}
className={className}
titleTooltip={titleTooltip}>
{children}
{...panelCardProps}
headerContent={
panelCardProps.headerContent ? (
<div className="flex items-center gap-2">
{panelCardProps.headerContent}
{legendComponent}
</div>
) : (
legendComponent
)
}>
{panelCardProps.children}
</PanelCard>
);
}
Expand Down
101 changes: 84 additions & 17 deletions packages/ui/components/card/PanelCard.tsx
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can add the useAutoAnimate hook from formkit auto animate (we use this in loads of places)

To make this transition a bit smoother when toggling its a bit too snappy at the mooment.

Coderabbit suggestions here are pretty good.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can add the useAutoAnimate hook from formkit auto animate (we use this in loads of places)

To make this transition a bit smoother when toggling its a bit too snappy at the mooment.

Coderabbit suggestions here are pretty good.

Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -12,6 +18,8 @@ export function PanelCard({
className,
titleTooltip,
children,
collapsible = false,
defaultCollapsed = false,
}: {
title: string | ReactNode;
subtitle?: string;
Expand All @@ -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<HTMLDivElement>();

const toggleCollapse = () => {
setIsCollapsed((prev) => !prev);
};

const isStringTitle = typeof title === "string";

return (
<div
ref={animationParent}
className={classNames(
"bg-muted group relative flex w-full flex-col items-center rounded-2xl px-1 pb-1",
"bg-muted group relative flex w-full flex-col items-center rounded-2xl px-1",
!isCollapsed && "pb-1",
className
)}>
<div className="flex h-11 w-full shrink-0 items-center justify-between gap-2 px-4">
{typeof title === "string" ? (
<div className="mr-4 flex shrink-0 items-center gap-1">
<h2 className="text-emphasis shrink-0 text-sm font-semibold">{title}</h2>
{titleTooltip && <InfoBadge content={titleTooltip} />}
</div>
) : (
title
)}
<div className="flex shrink-0 items-center gap-1">
{collapsible && (
<Button
size="sm"
variant="icon"
color="minimal"
CustomStartIcon={
<Icon
name="chevron-up"
className={classNames(
"text-default h-4 w-4 transition-transform",
isCollapsed && "rotate-180"
)}
/>
}
onClick={toggleCollapse}
className="text-muted -ml-2"
aria-expanded={!isCollapsed}
aria-controls={contentId}
aria-label={isCollapsed ? t("expand_panel") : t("collapse_panel")}
/>
)}
{isStringTitle ? (
<div className="mr-4 flex shrink-0 items-center gap-1">
<h2 id={titleId} className="text-emphasis shrink-0 text-sm font-semibold">
{collapsible ? (
<button
type="button"
onClick={toggleCollapse}
className="text-left transition-opacity hover:opacity-80"
aria-expanded={!isCollapsed}
aria-controls={contentId}
aria-label={isCollapsed ? t("expand_panel") : t("collapse_panel")}>
{title as string}
</button>
) : (
(title as string)
)}
</h2>
{titleTooltip && <InfoBadge content={titleTooltip} />}
</div>
) : (
title
)}
</div>
<div className="no-scrollbar flex items-center gap-2 overflow-x-auto">
{headerContent}
{cta && (
Expand All @@ -45,14 +106,20 @@ export function PanelCard({
)}
</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>
{!(isCollapsed && collapsible) && (
<div
id={contentId}
role="region"
aria-labelledby={isStringTitle ? titleId : undefined}
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>
);
}
Loading