"use client"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import classNames from "@calcom/ui/classNames"; import { InfoIcon } from "@coss/ui/icons"; import { cva } from "class-variance-authority"; import type React from "react"; import { forwardRef, useId, useState } from "react"; 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: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-all", ], { 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?: (e: React.MouseEvent) => void; size?: "sm" | "md"; position?: "start" | "end"; }; const Addon = ({ children, className, error, onClickAddon, size: _size = "md", position: _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, t: __t, dataTestid, size, ...passThrough } = props; const [inputValue, setInputValue] = useState(""); const handleFocusInput = (e: React.MouseEvent) => { e.currentTarget.parentElement?.querySelector("input")?.focus(); }; return (
{!!name && !noLabel && ( )} {addOnLeading || addOnSuffix ? (
{addOnLeading && ( {addOnLeading} )} { setInputValue(e.target.value); props.onChange?.(e); }, value: inputValue, })} disabled={readOnly || disabled} ref={ref} /> {addOnSuffix && ( { handleFocusInput(e); onClickAddon?.(e); }} className={classNames(addOnClassname)}> {addOnSuffix} )} {type === "search" && inputValue?.toString().length > 0 && ( { setInputValue(""); props.onChange?.(e as unknown as React.ChangeEvent); }} /> )}
) : ( )} {hint && (
{hint}
)}
); }); export const TextField = forwardRef(function TextField(props, ref) { return ; });