2021-08-20 00:49:45 +00:00
|
|
|
import React, { forwardRef } from "react";
|
|
|
|
import classNames from "classnames";
|
|
|
|
import styles from "./Input.module.css";
|
2021-09-03 22:45:07 +00:00
|
|
|
import { ReactComponent as CheckIcon } from "./icons/Check.svg";
|
2021-08-20 00:49:45 +00: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-09-03 22:45:07 +00:00
|
|
|
({ id, label, className, type, checked, ...rest }, ref) => {
|
2021-08-20 00:49:45 +00:00
|
|
|
return (
|
2021-09-03 22:45:07 +00:00
|
|
|
<Field
|
|
|
|
className={classNames(
|
|
|
|
type === "checkbox" ? styles.checkboxField : styles.inputField,
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<input id={id} {...rest} ref={ref} type={type} checked={checked} />
|
|
|
|
<label htmlFor={id}>
|
|
|
|
{type === "checkbox" && (
|
|
|
|
<div className={styles.checkbox}>
|
|
|
|
<CheckIcon />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{label}
|
|
|
|
</label>
|
2021-08-20 00:49:45 +00:00
|
|
|
</Field>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-08-20 23:23:12 +00:00
|
|
|
export function ErrorMessage({ children }) {
|
|
|
|
return <p className={styles.errorMessage}>{children}</p>;
|
|
|
|
}
|