Created namespace for form controls

This commit is contained in:
Alejandro Celaya
2022-03-05 14:43:43 +01:00
parent ec403d7b1f
commit 0993b43c79
8 changed files with 7 additions and 9 deletions

View File

@@ -0,0 +1,36 @@
import { FC, useRef } from 'react';
import { v4 as uuid } from 'uuid';
import { InputType } from 'reactstrap/types/lib/Input';
import { FormGroup } from 'reactstrap';
export interface FormGroupContainerProps {
value: string;
onChange: (newValue: string) => void;
id?: string;
type?: InputType;
required?: boolean;
placeholder?: string;
className?: string;
labelClassName?: string;
}
export const FormGroupContainer: FC<FormGroupContainerProps> = (
{ children, value, onChange, id, type, required, placeholder, className, labelClassName },
) => {
const forId = useRef<string>(id ?? uuid());
return (
<FormGroup className={className ?? ''}>
{children && <label htmlFor={forId.current} className={labelClassName ?? ''}>{children}:</label>}
<input
className="form-control"
type={type ?? 'text'}
id={forId.current}
value={value}
required={required ?? true}
placeholder={placeholder}
onChange={(e) => onChange(e.target.value)}
/>
</FormGroup>
);
};

View File

@@ -0,0 +1,3 @@
import { FC } from 'react';
export const FormText: FC = ({ children }) => <small className="form-text text-muted d-block">{children}</small>;