This repository has been archived on 2024-11-11. You can view files and clone it, but cannot push or open issues or pull requests.
react-component-form/example/components/design/Input.tsx

38 lines
1.1 KiB
TypeScript
Raw Normal View History

import classNames from "clsx"
2022-08-26 20:19:31 +02:00
import { FormState } from "./FormState"
2022-08-26 20:19:31 +02:00
export interface InputProps extends React.ComponentPropsWithRef<"input"> {
2022-08-26 20:19:31 +02:00
label: string
error?: string
className?: string
}
export const Input: React.FC<InputProps> = (props) => {
const { label, name, className, error, ...rest } = props
return (
<div className="flex flex-col">
<div className={classNames("mt-6 mb-2 flex justify-between", className)}>
<label className="pl-1" htmlFor={name}>
2022-08-26 20:19:31 +02:00
{label}
</label>
</div>
<div className="relative mt-0">
2022-08-26 20:19:31 +02:00
<input
className="h-11 w-full rounded-lg border border-transparent bg-[#f1f1f1] px-3 font-paragraph leading-10 text-[#2a2a2a] caret-green-600 focus:border focus:shadow-green focus:outline-none"
2022-08-26 20:19:31 +02:00
{...rest}
id={name}
name={name}
data-cy={`input-${name ?? "name"}`}
2022-08-26 23:47:48 +02:00
/>
<FormState
id={`error-${name ?? "input"}`}
state={error == null ? "idle" : "error"}
2022-08-26 23:47:48 +02:00
message={error}
2022-08-26 20:19:31 +02:00
/>
</div>
</div>
)
}