import { forwardRef, useId } from "react";
import { cn } from "~/utils/cn";
const CONTROL =
"w-full rounded-md border border-gray-700 bg-gray-900/80 px-3 text-sm text-gray-100 placeholder:text-gray-600 focus:border-accent-500 focus:ring-1 focus:ring-accent-500 focus:outline-none disabled:opacity-60";
type FieldShellProps = {
label: string;
hint?: string;
error?: string | null;
id: string;
children: React.ReactNode;
};
function FieldShell({ label, hint, error, id, children }: FieldShellProps) {
return (
{children}
{hint && !error &&
{hint}
}
{error && (
{error}
)}
);
}
type InputProps = Omit, "id"> & {
label: string;
hint?: string;
error?: string | null;
};
export const TextField = forwardRef(function TextField(
{ label, hint, error, className, ...rest },
ref,
) {
const id = useId();
return (
);
});
TextField.displayName = "TextField";
type TextAreaProps = Omit, "id"> & {
label: string;
hint?: string;
error?: string | null;
};
export const TextAreaField = forwardRef(function TextAreaField(
{ label, hint, error, className, ...rest },
ref,
) {
const id = useId();
return (
);
});
TextAreaField.displayName = "TextAreaField";
type SelectProps = Omit, "id"> & {
label: string;
hint?: string;
options: ReadonlyArray<{ value: string; label: string }>;
};
export const SelectField = forwardRef(function SelectField(
{ label, hint, options, className, ...rest },
ref,
) {
const id = useId();
return (
);
});
SelectField.displayName = "SelectField";
type CheckboxProps = Omit, "id" | "type"> & {
label: string;
hint?: string;
};
export const CheckboxField = forwardRef(function CheckboxField(
{ label, hint, ...rest },
ref,
) {
const id = useId();
return (
);
});
CheckboxField.displayName = "CheckboxField";
export function ErrorBanner({ message }: { message: string | null }) {
if (!message) return null;
return (
{message}
);
}
export const inputClass = CONTROL;