(react) add generic Field component

This component will wrap most of form components in order to provide
them a generic state attribute along with texts below them.
This commit is contained in:
Nathan Vasse
2023-04-14 16:38:08 +02:00
committed by NathanVss
parent 6d195f6dad
commit 4f1168463f
8 changed files with 142 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import React, { PropsWithChildren } from "react";
import classNames from "classnames";
export type FieldState = "success" | "error" | "default";
export type FieldProps = {
state?: FieldState | undefined;
text?: string | undefined;
rightText?: string | undefined;
fullWidth?: boolean | undefined;
};
type Props = FieldProps & PropsWithChildren;
export const Field = ({
children,
state = "default",
text,
rightText,
fullWidth,
}: Props) => {
return (
<div
className={classNames("c__field", "c__field--" + state, {
"c__field--full-width": fullWidth,
})}
>
{children}
{(text || rightText) && (
<div className="c__field__footer">
<span className="c__field__text">{text}</span>
<span className="c__field__text__right">{rightText}</span>
</div>
)}
</div>
);
};