import classNames from 'classnames'; import { JsxChildren } from 'dom-renderer'; import { FC, WebCellProps } from 'web-cell'; import { uniqueID } from 'web-utility'; export type FormGroupProps = WebCellProps; export const FormGroup: FC = ({ children, ...props }) => (
{children}
); export type FormLabelProps = WebCellProps; export const FormLabel: FC = ({ className = '', children, ...props }) => ( ); export interface FloatingLabelProps extends FormLabelProps { label: string; } export const FloatingLabel: FC = ({ className = '', style, label, children, ...props }) => (
{children}
); export interface InputGroupProps extends WebCellProps { size?: 'sm' | 'lg'; } export const InputGroup: FC = ({ className = '', size, children, ...props }) => (
{children}
); export const InputGroupText: FC> = ({ className = '', children, ...props }) => ( {children} ); export type FormControlTag = 'input' | 'textarea' | 'select'; export type FormControlProps = WebCellProps & Omit & { as?: T; htmlSize?: number; size?: 'sm' | 'lg'; plaintext?: boolean; }; export const FormControl = ({ as: Tag = 'input' as T, className = '', htmlSize, size, plaintext, ...props }: FormControlProps) => ( ).readOnly && plaintext && `form-control-plaintext`, (props as FormControlProps<'input'>).type === 'color' && `form-control-color`, className )} {...props} size={htmlSize} /> ); export interface FormCheckProps extends WebCellProps { type: 'radio' | 'checkbox' | 'switch'; inline?: boolean; reverse?: boolean; label?: JsxChildren; } export const FormCheck: FC = ({ id = uniqueID(), className = '', style, title, type, inline, reverse, label, ...props }) => (
{label && ( )}
); export type FormFieldProps = FormGroupProps & FormLabelProps & FormControlProps & { label?: string; labelFloat?: boolean; }; export const FormField = ({ className, label, labelFloat, ...props }: FormFieldProps) => { label ||= props.title || (props as FormControlProps<'input'>).placeholder; const field = )} />; return labelFloat ? ( {field} ) : ( {label} {field} ); };