import { forwardRef, ReactElement, ReactNode, Ref, useCallback, useId, useState } from "react"; import React from "react"; import { Eye, EyeOff } from "react-feather"; import { FieldValues, FormProvider, SubmitHandler, useFormContext, UseFormReturn } from "react-hook-form"; import classNames from "@calcom/lib/classNames"; import { getErrorFromUnknown } from "@calcom/lib/errors"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Skeleton, Tooltip, Alert, showToast } from "@calcom/ui/v2"; import { HintsOrErrors } from "./HintOrErrors"; import { Label } from "./Label"; type InputProps = JSX.IntrinsicElements["input"]; export const Input = forwardRef(function Input(props, ref) { return ( ); }); export function InputLeading(props: JSX.IntrinsicElements["div"]) { return ( {props.children} ); } type InputFieldProps = { label?: ReactNode; hint?: ReactNode; hintErrors?: string[]; addOnLeading?: ReactNode; addOnSuffix?: ReactNode; addOnFilled?: boolean; error?: string; labelSrOnly?: boolean; containerClassName?: string; t?: (key: string) => string; } & React.ComponentProps & { labelProps?: React.ComponentProps; labelClassName?: string; }; type AddonProps = { children: React.ReactNode; isFilled?: boolean; className?: string; error?: boolean; }; const Addon = ({ isFilled, children, className, error }: AddonProps) => (
{children}
); export const InputField = forwardRef(function InputField(props, ref) { const id = useId(); const { t: _t, isLocaleReady, i18n } = useLocale(); const t = props.t || _t; const name = props.name || ""; const { label = t(name), labelProps, labelClassName, placeholder = isLocaleReady && i18n.exists(name + "_placeholder") ? t(name + "_placeholder") : "", className, addOnLeading, addOnSuffix, addOnFilled = true, hint, hintErrors, labelSrOnly, containerClassName, // eslint-disable-next-line @typescript-eslint/no-unused-vars t: __t, ...passThrough } = props; return (
{!!name && ( {label} )} {addOnLeading || addOnSuffix ? (
{addOnLeading && ( {addOnLeading} )} {addOnSuffix && ( {addOnSuffix} )}
) : ( )} {hint &&
{hint}
}
); }); export const TextField = forwardRef(function TextField(props, ref) { return ; }); export const PasswordField = forwardRef(function PasswordField( props, ref ) { const { t } = useLocale(); const [isPasswordVisible, setIsPasswordVisible] = useState(false); const toggleIsPasswordVisible = useCallback( () => setIsPasswordVisible(!isPasswordVisible), [isPasswordVisible, setIsPasswordVisible] ); const textLabel = isPasswordVisible ? t("hide_password") : t("show_password"); return (
} />
); }); export const EmailInput = forwardRef(function EmailInput(props, ref) { return ( ); }); export const EmailField = forwardRef(function EmailField(props, ref) { return ( ); }); type TextAreaProps = JSX.IntrinsicElements["textarea"]; export const TextArea = forwardRef(function TextAreaInput(props, ref) { return (