"use client"; import { cva } from "class-variance-authority"; import React, { forwardRef, useId, useState } from "react"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import classNames from "@calcom/ui/classNames"; import { Icon } from "../../icon"; import { HintsOrErrors } from "./HintOrErrors"; import { Label } from "./Label"; import type { InputFieldProps, InputProps } from "./types"; export const inputStyles = cva( [ // Base styles "rounded-[10px] border", "leading-none font-normal", // Colors "bg-default", "border-default", "text-default", "placeholder:text-muted", // States "hover:border-emphasis", "focus:ring-0", "focus:shadow-outline-gray-focused", // Disabled state "disabled:bg-subtle", "disabled:hover:border-default", "disabled:cursor-not-allowed", // Shadow "shadow-outline-gray-rested", // Transitions "transition", ], { variants: { size: { sm: "h-7 px-2 py-1 text-xs", md: "h-8 px-3 py-2 text-sm", }, }, defaultVariants: { size: "md", }, } ); export const Input = forwardRef(function Input( { isFullWidth = true, size = "md", className, ...props }, ref ) { return ( ); }); type AddonProps = { children: React.ReactNode; className?: string; error?: boolean; onClickAddon?: () => void; size?: "sm" | "md"; position?: "start" | "end"; }; const Addon = ({ children, className, error, onClickAddon, size = "md", position = "start" }: 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, disabled, LockedIcon, placeholder = isLocaleReady && i18n.exists(`${name}_placeholder`) ? t(`${name}_placeholder`) : "", className, addOnLeading, addOnSuffix, addOnClassname, inputIsFullWidth, hint, type, hintErrors, labelSrOnly, noLabel, containerClassName, readOnly, showAsteriskIndicator, onClickAddon, // eslint-disable-next-line @typescript-eslint/no-unused-vars t: __t, dataTestid, size, ...passThrough } = props; const [inputValue, setInputValue] = useState(""); return (
{!!name && !noLabel && ( )} {addOnLeading || addOnSuffix ? (
{addOnLeading && ( {addOnLeading} )} { setInputValue(e.target.value); props.onChange && props.onChange(e); }, value: inputValue, })} disabled={readOnly || disabled} ref={ref} /> {addOnSuffix && ( {addOnSuffix} )} {type === "search" && inputValue?.toString().length > 0 && ( { setInputValue(""); props.onChange && props.onChange(e as unknown as React.ChangeEvent); }} /> )}
) : ( )} {hint &&
{hint}
}
); }); export const TextField = forwardRef(function TextField(props, ref) { return ; });