2021-08-19 17:49:45 -07:00
|
|
|
import React, { forwardRef } from "react";
|
|
|
|
import classNames from "classnames";
|
|
|
|
import styles from "./Input.module.css";
|
2022-01-05 17:27:01 -08:00
|
|
|
import { ReactComponent as CheckIcon } from "../icons/Check.svg";
|
2021-08-19 17:49:45 -07:00
|
|
|
|
|
|
|
export function FieldRow({ children, rightAlign, className, ...rest }) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
styles.fieldRow,
|
|
|
|
{ [styles.rightAlign]: rightAlign },
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function Field({ children, className, ...rest }) {
|
|
|
|
return <div className={classNames(styles.field, className)}>{children}</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const InputField = forwardRef(
|
2021-12-16 16:43:35 -08:00
|
|
|
(
|
|
|
|
{ id, label, className, type, checked, prefix, suffix, disabled, ...rest },
|
|
|
|
ref
|
|
|
|
) => {
|
2021-08-19 17:49:45 -07:00
|
|
|
return (
|
2021-09-03 15:45:07 -07:00
|
|
|
<Field
|
|
|
|
className={classNames(
|
|
|
|
type === "checkbox" ? styles.checkboxField : styles.inputField,
|
2021-12-16 16:43:35 -08:00
|
|
|
{
|
|
|
|
[styles.prefix]: !!prefix,
|
|
|
|
[styles.disabled]: disabled,
|
|
|
|
},
|
2021-09-03 15:45:07 -07:00
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
2021-12-15 10:54:01 -08:00
|
|
|
{prefix && <span>{prefix}</span>}
|
2022-02-23 16:07:14 -08:00
|
|
|
{type === "textarea" ? (
|
|
|
|
<textarea
|
|
|
|
id={id}
|
|
|
|
{...rest}
|
|
|
|
ref={ref}
|
|
|
|
type={type}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<input
|
|
|
|
id={id}
|
|
|
|
{...rest}
|
|
|
|
ref={ref}
|
|
|
|
type={type}
|
|
|
|
checked={checked}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2021-09-03 15:45:07 -07:00
|
|
|
<label htmlFor={id}>
|
|
|
|
{type === "checkbox" && (
|
|
|
|
<div className={styles.checkbox}>
|
|
|
|
<CheckIcon />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{label}
|
|
|
|
</label>
|
2021-12-15 10:54:01 -08:00
|
|
|
{suffix && <span>{suffix}</span>}
|
2021-08-19 17:49:45 -07:00
|
|
|
</Field>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-08-20 16:23:12 -07:00
|
|
|
export function ErrorMessage({ children }) {
|
|
|
|
return <p className={styles.errorMessage}>{children}</p>;
|
|
|
|
}
|