/*
Copyright 2022-2024 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import {
type ChangeEvent,
type FC,
type ForwardedRef,
forwardRef,
type ReactNode,
useId,
type JSX,
} from "react";
import classNames from "classnames";
import styles from "./Input.module.css";
import CheckIcon from "../icons/Check.svg?react";
import { TranslatedError } from "../TranslatedError";
interface FieldRowProps {
children: ReactNode;
rightAlign?: boolean;
className?: string;
}
export function FieldRow({
children,
rightAlign,
className,
}: FieldRowProps): JSX.Element {
return (
{children}
);
}
interface FieldProps {
children: ReactNode;
className?: string;
}
function Field({ children, className }: FieldProps): JSX.Element {
return {children}
;
}
interface InputFieldProps {
label?: string;
type: string;
prefix?: string;
suffix?: string;
id?: string;
checked?: boolean;
className?: string;
description?: string | ReactNode;
disabled?: boolean;
required?: boolean;
// this is a hack. Those variables should be part of `HTMLAttributes | HTMLAttributes`
// but extending from this union type does not work
name?: string;
autoComplete?: string;
autoCorrect?: string;
autoCapitalize?: string;
value?: string;
defaultValue?: string;
placeholder?: string;
defaultChecked?: boolean;
min?: number;
onChange?: (event: ChangeEvent) => void;
}
export const InputField = forwardRef<
HTMLInputElement | HTMLTextAreaElement,
InputFieldProps
>(
(
{
id,
label,
className,
type,
checked,
prefix,
suffix,
description,
disabled,
min,
...rest
},
ref,
) => {
const descriptionId = useId();
return (
{prefix && {prefix}}
{type === "textarea" ? (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
);
},
);
InputField.displayName = "InputField";
interface ErrorMessageProps {
error: Error;
}
export const ErrorMessage: FC = ({ error }) => (
{error instanceof TranslatedError ? error.translatedMessage : error.message}
);