"use client"; import Link from "next/link"; import { useState } from "react"; import classNames from "@calcom/ui/classNames"; import type { BadgeProps } from "../badge"; import { Badge } from "../badge"; import { Button } from "../button"; import { Dropdown, DropdownMenuTrigger, DropdownMenuContent, DropdownItem } from "../dropdown"; import { Input } from "../form/inputs/TextField"; import { Icon } from "../icon"; import type { IconName } from "../icon"; type Action = { check: () => boolean; fn: () => void; color?: "destructive" | "minimal"; disabled?: boolean }; type FormCardActionsProps = { deleteField?: Action | null; duplicateField?: Action | null; }; const FormCardActions = ({ deleteField, duplicateField }: FormCardActionsProps) => { type ActionItem = { label: string; icon: IconName; onClick: () => void; color: "destructive" | "minimal"; disabled?: boolean; }; const actions: ActionItem[] = [ duplicateField?.fn && { label: "Duplicate", icon: "copy", onClick: () => duplicateField.fn(), }, deleteField?.fn && { label: "Delete", icon: "trash", onClick: () => deleteField.fn(), color: deleteField.color ?? "minimal", disabled: deleteField.disabled, }, ].filter((action): action is ActionItem => !!action); if (actions.length === 0) return null; // If only one action, show a single icon button if (actions.length === 1) { const action = actions[0]; return ( {actions.map((action) => ( { e.preventDefault(); action.onClick(); }} disabled={action.disabled} color={action.color}> {action.label} ))} ); }; export default function FormCard({ children, label, isLabelEditable, onLabelChange, deleteField, duplicateField, moveUp, moveDown, className, badge, collapsible = true, leftIcon, ...restProps }: { children: React.ReactNode; label: React.ReactNode; isLabelEditable?: boolean; onLabelChange?: (label: string) => void; deleteField?: Action | null; duplicateField?: Action | null; moveUp?: Action | null; moveDown?: Action | null; className?: string; badge?: { text: string; href?: string; variant: BadgeProps["variant"] } | null; leftIcon?: IconName; collapsible?: boolean; } & JSX.IntrinsicElements["div"]) { className = classNames( "flex items-center group relative w-full rounded-2xl p-1 border border-subtle bg-muted mb-2", className ); const [isCollapsed, setIsCollapsed] = useState(false); const toggleFormCard = () => { setIsCollapsed((prev) => !prev); }; return (
{moveUp?.check() ? ( ) : null} {moveDown?.check() ? ( ) : null}
{leftIcon && (
)} {collapsible && (
{children}
); } export function FormCardBody({ children, className = "", ...props }: { children: React.ReactNode; className?: string; } & React.HTMLAttributes) { return (
{children}
); }