2023-01-04 13:30:46 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
|
2022-09-02 19:00:41 +00:00
|
|
|
import { classNames } from "@calcom/lib";
|
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { BadgeProps } from "../..";
|
|
|
|
import { Badge } from "../..";
|
2023-01-10 15:39:29 +00:00
|
|
|
import { Divider } from "../divider";
|
2023-06-05 05:51:19 +00:00
|
|
|
import { ArrowDown, ArrowUp, Trash2 } from "../icon";
|
2022-09-02 19:00:41 +00:00
|
|
|
|
|
|
|
type Action = { check: () => boolean; fn: () => void };
|
|
|
|
export default function FormCard({
|
|
|
|
children,
|
|
|
|
label,
|
|
|
|
deleteField,
|
|
|
|
moveUp,
|
|
|
|
moveDown,
|
|
|
|
className,
|
2023-01-04 13:30:46 +00:00
|
|
|
badge,
|
2022-09-02 19:00:41 +00:00
|
|
|
...restProps
|
|
|
|
}: {
|
|
|
|
children: React.ReactNode;
|
2023-01-04 13:30:46 +00:00
|
|
|
label?: React.ReactNode;
|
2022-09-02 19:00:41 +00:00
|
|
|
deleteField?: Action | null;
|
|
|
|
moveUp?: Action | null;
|
|
|
|
moveDown?: Action | null;
|
|
|
|
className?: string;
|
2023-01-04 13:30:46 +00:00
|
|
|
badge?: { text: string; href?: string; variant: BadgeProps["variant"] } | null;
|
2022-09-02 19:00:41 +00:00
|
|
|
} & JSX.IntrinsicElements["div"]) {
|
2022-09-20 11:37:46 +00:00
|
|
|
className = classNames(
|
|
|
|
className,
|
2023-04-05 18:14:46 +00:00
|
|
|
"flex items-center group relative w-full rounded-md p-4 border border-subtle"
|
2022-09-20 11:37:46 +00:00
|
|
|
);
|
2022-09-02 19:00:41 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={className} {...restProps}>
|
|
|
|
<div>
|
|
|
|
{moveUp?.check() ? (
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-04-05 18:14:46 +00:00
|
|
|
className="bg-default text-muted hover:text-emphasis invisible absolute left-0 -ml-[13px] -mt-10 flex h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:border-transparent hover:shadow group-hover:visible group-hover:scale-100 "
|
2022-09-02 19:00:41 +00:00
|
|
|
onClick={() => moveUp?.fn()}>
|
2023-04-12 15:26:31 +00:00
|
|
|
<ArrowUp />
|
2022-09-02 19:00:41 +00:00
|
|
|
</button>
|
|
|
|
) : null}
|
|
|
|
{moveDown?.check() ? (
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-04-05 18:14:46 +00:00
|
|
|
className="bg-default text-muted hover:text-emphasis invisible absolute left-0 -ml-[13px] -mt-2 flex h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:border-transparent hover:shadow group-hover:visible group-hover:scale-100"
|
2022-09-02 19:00:41 +00:00
|
|
|
onClick={() => moveDown?.fn()}>
|
2023-04-12 15:26:31 +00:00
|
|
|
<ArrowDown />
|
2022-09-02 19:00:41 +00:00
|
|
|
</button>
|
|
|
|
) : null}
|
|
|
|
</div>
|
2022-09-20 11:37:46 +00:00
|
|
|
<div className="w-full">
|
|
|
|
<div className="flex items-center justify-between">
|
2023-01-04 13:30:46 +00:00
|
|
|
<div>
|
2023-04-12 12:15:08 +00:00
|
|
|
<span className="text-emphasis text-sm font-semibold">{label}</span>
|
2023-01-04 13:30:46 +00:00
|
|
|
{badge && (
|
|
|
|
<Badge className="ml-2" variant={badge.variant}>
|
2023-01-06 12:13:56 +00:00
|
|
|
{badge.href ? <Link href={badge.href}>{badge.text}</Link> : badge.text}
|
2023-01-04 13:30:46 +00:00
|
|
|
</Badge>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-09-20 11:37:46 +00:00
|
|
|
{deleteField?.check() ? (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
|
|
|
deleteField?.fn();
|
|
|
|
}}
|
|
|
|
color="secondary">
|
2023-06-05 05:51:19 +00:00
|
|
|
<Trash2 className="text-default h-4 w-4" />
|
2022-09-20 11:37:46 +00:00
|
|
|
</button>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
<Divider className="mt-3 mb-6" />
|
|
|
|
{children}
|
2022-09-02 19:00:41 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|