Files
DataStack/components/ui/Form.tsx
T

61 lines
1.7 KiB
TypeScript
Raw Normal View History

2026-10-23 11:43:49 -05:00
import { cn } from '@/lib/utils';
2026-10-23 19:56:38 -07:00
import React from 'react';
2026-10-23 11:43:49 -05:00
export const Form: React.FC<React.FormHTMLAttributes<HTMLFormElement>> = ({
className,
children,
...props
}) => (
2026-10-23 19:56:38 -07:00
<form className={cn('flex flex-col gap-5', className)} {...props}>
2026-10-23 11:43:49 -05:00
{children}
</form>
);
export const FormField: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
className,
children,
...props
}) => (
2026-10-23 19:56:38 -07:00
<div className={cn('flex flex-col gap-2 w-full', className)} {...props}>
2026-10-23 11:43:49 -05:00
{children}
</div>
);
export const FormRow: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
className,
children,
...props
}) => (
2026-10-23 19:56:38 -07:00
<div className={cn('grid grid-cols-1 sm:grid-cols-2 gap-4 w-full', className)} {...props}>
2026-10-23 11:43:49 -05:00
{children}
</div>
);
export const FormSwitch: React.FC<{
label: string;
checked: boolean;
onChange: (checked: boolean) => void;
description?: string;
disabled?: boolean;
}> = ({ label, checked, onChange, description, disabled = false }) => (
<label
className={cn(
2026-10-23 19:56:38 -07:00
'flex items-center justify-between gap-4 p-4 border border-[var(--border)] bg-[var(--bg-main)] cursor-pointer select-none transition-colors hover:bg-[var(--bg-hover)]',
2026-10-23 11:43:49 -05:00
disabled && 'opacity-50 cursor-not-allowed'
)}
>
<div className="flex flex-col">
2026-10-23 19:56:38 -07:00
<span className="text-[14px] font-medium text-[var(--text)]">{label}</span>
{description && <span className="text-[12px] text-[var(--text-muted)]">{description}</span>}
2026-10-23 11:43:49 -05:00
</div>
<input
type="checkbox"
checked={checked}
disabled={disabled}
onChange={(e) => onChange(e.target.checked)}
2026-10-23 19:56:38 -07:00
className="w-5 h-5 accent-[var(--accent)] cursor-pointer shrink-0"
2026-10-23 11:43:49 -05:00
/>
</label>
);
export default Form;