2023-04-14 16:38:08 +02:00
|
|
|
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;
|
2023-04-20 14:56:39 +02:00
|
|
|
compact?: boolean | undefined;
|
|
|
|
|
className?: string | undefined;
|
2023-04-14 16:38:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type Props = FieldProps & PropsWithChildren;
|
|
|
|
|
|
|
|
|
|
export const Field = ({
|
|
|
|
|
children,
|
|
|
|
|
state = "default",
|
|
|
|
|
text,
|
|
|
|
|
rightText,
|
|
|
|
|
fullWidth,
|
2023-04-20 14:56:39 +02:00
|
|
|
compact,
|
|
|
|
|
className,
|
2023-04-14 16:38:08 +02:00
|
|
|
}: Props) => {
|
|
|
|
|
return (
|
|
|
|
|
<div
|
2023-04-20 14:56:39 +02:00
|
|
|
className={classNames("c__field", "c__field--" + state, className, {
|
2023-04-14 16:38:08 +02:00
|
|
|
"c__field--full-width": fullWidth,
|
2023-04-20 14:56:39 +02:00
|
|
|
"c__field--compact": compact,
|
2023-04-14 16:38:08 +02:00
|
|
|
})}
|
|
|
|
|
>
|
|
|
|
|
{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>
|
|
|
|
|
);
|
|
|
|
|
};
|