import { Form } from '@inertiajs/react';
import type { ComponentProps, ReactNode } from 'react';
import { useState } from 'react';
import InputError from '@/components/input-error';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { Label } from '@/components/ui/label';
import { cn } from '@/lib/utils';
import type { RouteFormDefinition } from '@/wayfinder';
const controlClasses =
'border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 w-full min-w-0 rounded-md border bg-transparent px-3 py-2 text-base shadow-xs outline-none focus-visible:ring-[3px] disabled:opacity-50 md:text-sm';
export function PageHeader({
title,
description,
action,
}: {
title: string;
description?: string;
action?: ReactNode;
}) {
return (
{title}
{description && (
{description}
)}
{action}
);
}
export function FormField({
id,
label,
error,
className,
children,
}: {
id: string;
label: string;
error?: string;
className?: string;
children: ReactNode;
}) {
return (
{children}
);
}
export function NativeSelect({
options,
className,
...props
}: ComponentProps<'select'> & {
options: ReadonlyArray<{ value: string; label: string }>;
}) {
return (
);
}
export function Textarea({ className, ...props }: ComponentProps<'textarea'>) {
return (
);
}
type Errors = Partial>;
/**
* A dialog holding a create/edit form; it closes itself once the server
* accepts the submission.
*/
export function FormDialog({
trigger,
title,
description,
form,
submitLabel = 'Simpan',
className,
children,
}: {
trigger: ReactNode;
title: string;
description?: string;
form: RouteFormDefinition<'get' | 'post'>;
submitLabel?: string;
className?: string;
children: (errors: Errors) => ReactNode;
}) {
const [open, setOpen] = useState(false);
return (
);
}
/** Asks for confirmation before sending a delete request. */
export function ConfirmDelete({
trigger,
title,
description,
form,
}: {
trigger: ReactNode;
title: string;
description: string;
form: RouteFormDefinition<'get' | 'post'>;
}) {
const [open, setOpen] = useState(false);
return (
);
}