mirror of
https://github.com/khairul169/code-share.git
synced 2025-04-29 00:59:37 +07:00
35 lines
745 B
TypeScript
35 lines
745 B
TypeScript
import React from "react";
|
|
import { cn } from "~/lib/utils";
|
|
|
|
export type FormFieldProps = {
|
|
id?: string;
|
|
label?: string;
|
|
error?: string;
|
|
};
|
|
|
|
type Props = FormFieldProps & {
|
|
children?: React.ReactNode;
|
|
className?: string;
|
|
};
|
|
|
|
const FormField = ({ id, label, error, children, className }: Props) => {
|
|
return (
|
|
<div className={cn("form-field", className)}>
|
|
{label ? <FormLabel htmlFor={id}>{label}</FormLabel> : null}
|
|
|
|
{children}
|
|
|
|
{error ? <p className="text-sm mt-1 text-red-500">{error}</p> : null}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const FormLabel = ({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<"label">) => (
|
|
<label className={cn("text-sm block mb-2", className)} {...props} />
|
|
);
|
|
|
|
export default FormField;
|