2023-02-16 22:39:57 +00:00
|
|
|
import type { ReactElement, ReactNode, Ref } from "react";
|
|
|
|
import React, { forwardRef, useCallback, useId, useState } from "react";
|
|
|
|
import type { FieldValues, SubmitHandler, UseFormReturn } from "react-hook-form";
|
|
|
|
import { FormProvider, useFormContext } from "react-hook-form";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
|
|
|
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
|
2023-01-23 23:08:01 +00:00
|
|
|
import { Alert, showToast, Skeleton, Tooltip, UnstyledSelect } from "../../..";
|
2023-04-12 15:26:31 +00:00
|
|
|
import { Eye, EyeOff, X } from "../../icon";
|
2022-11-04 15:40:46 +00:00
|
|
|
import { HintsOrErrors } from "./HintOrErrors";
|
|
|
|
import { Label } from "./Label";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
2022-11-28 11:20:49 +00:00
|
|
|
type InputProps = JSX.IntrinsicElements["input"] & { isFullWidth?: boolean };
|
2022-07-23 00:39:50 +00:00
|
|
|
|
2022-11-28 11:20:49 +00:00
|
|
|
export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
|
|
|
|
{ isFullWidth = true, ...props },
|
|
|
|
ref
|
|
|
|
) {
|
2022-07-23 00:39:50 +00:00
|
|
|
return (
|
|
|
|
<input
|
|
|
|
{...props}
|
|
|
|
ref={ref}
|
|
|
|
className={classNames(
|
2023-04-13 02:10:23 +00:00
|
|
|
"hover:border-emphasis border-default bg-default placeholder:text-muted text-emphasis disabled:hover:border-default min-h-9 disabled:bg-subtle mb-2 block rounded-md border py-2 px-3 text-sm focus:border-neutral-300 focus:outline-none focus:ring-2 focus:ring-neutral-800 focus:ring-offset-1 disabled:cursor-not-allowed",
|
2022-11-28 11:20:49 +00:00
|
|
|
isFullWidth && "w-full",
|
2022-07-23 00:39:50 +00:00
|
|
|
props.className
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export function InputLeading(props: JSX.IntrinsicElements["div"]) {
|
|
|
|
return (
|
2023-04-05 18:14:46 +00:00
|
|
|
<span className="bg-muted border-default text-subtle inline-flex flex-shrink-0 items-center rounded-l-sm border px-3 ltr:border-r-0 rtl:border-l-0 sm:text-sm">
|
2022-07-23 00:39:50 +00:00
|
|
|
{props.children}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
type InputFieldProps = {
|
|
|
|
label?: ReactNode;
|
2023-04-13 02:10:23 +00:00
|
|
|
LockedIcon?: React.ReactNode;
|
2022-07-23 00:39:50 +00:00
|
|
|
hint?: ReactNode;
|
2022-07-29 13:23:54 +00:00
|
|
|
hintErrors?: string[];
|
2022-07-23 00:39:50 +00:00
|
|
|
addOnLeading?: ReactNode;
|
|
|
|
addOnSuffix?: ReactNode;
|
2022-11-28 11:20:49 +00:00
|
|
|
inputIsFullWidth?: boolean;
|
2022-07-23 00:39:50 +00:00
|
|
|
addOnFilled?: boolean;
|
2022-11-30 20:51:44 +00:00
|
|
|
addOnClassname?: string;
|
2022-07-23 00:39:50 +00:00
|
|
|
error?: string;
|
|
|
|
labelSrOnly?: boolean;
|
|
|
|
containerClassName?: string;
|
2022-08-03 16:59:40 +00:00
|
|
|
t?: (key: string) => string;
|
2022-07-23 00:39:50 +00:00
|
|
|
} & React.ComponentProps<typeof Input> & {
|
|
|
|
labelProps?: React.ComponentProps<typeof Label>;
|
2022-09-12 19:07:52 +00:00
|
|
|
labelClassName?: string;
|
2022-07-23 00:39:50 +00:00
|
|
|
};
|
|
|
|
|
2022-10-05 14:22:06 +00:00
|
|
|
type AddonProps = {
|
|
|
|
children: React.ReactNode;
|
|
|
|
isFilled?: boolean;
|
|
|
|
className?: string;
|
|
|
|
error?: boolean;
|
|
|
|
};
|
|
|
|
|
2022-11-30 20:51:44 +00:00
|
|
|
const Addon = ({ isFilled, children, className, error }: AddonProps) => (
|
2022-10-05 14:22:06 +00:00
|
|
|
<div
|
2022-11-30 20:51:44 +00:00
|
|
|
className={classNames(
|
2023-04-13 02:10:23 +00:00
|
|
|
"addon-wrapper border-default min-h-9 border px-3",
|
2023-04-05 18:14:46 +00:00
|
|
|
isFilled && "bg-subtle",
|
2022-11-30 20:51:44 +00:00
|
|
|
className
|
|
|
|
)}>
|
2023-04-05 18:14:46 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
2023-04-13 02:10:23 +00:00
|
|
|
"min-h-9 flex flex-col justify-center text-sm",
|
2023-04-05 18:14:46 +00:00
|
|
|
error ? "text-error" : "text-default"
|
|
|
|
)}>
|
2023-04-13 02:10:23 +00:00
|
|
|
<span className="flex whitespace-nowrap">{children}</span>
|
2022-10-05 14:22:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2022-11-04 15:40:46 +00:00
|
|
|
export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function InputField(props, ref) {
|
2022-07-23 00:39:50 +00:00
|
|
|
const id = useId();
|
2022-09-29 16:19:03 +00:00
|
|
|
const { t: _t, isLocaleReady, i18n } = useLocale();
|
2022-08-03 16:59:40 +00:00
|
|
|
const t = props.t || _t;
|
2022-09-02 19:00:41 +00:00
|
|
|
const name = props.name || "";
|
2022-07-23 00:39:50 +00:00
|
|
|
const {
|
2022-09-02 19:00:41 +00:00
|
|
|
label = t(name),
|
2022-07-23 00:39:50 +00:00
|
|
|
labelProps,
|
2022-09-12 19:07:52 +00:00
|
|
|
labelClassName,
|
2023-04-13 02:10:23 +00:00
|
|
|
disabled,
|
|
|
|
LockedIcon,
|
2022-09-29 16:19:03 +00:00
|
|
|
placeholder = isLocaleReady && i18n.exists(name + "_placeholder") ? t(name + "_placeholder") : "",
|
2022-07-23 00:39:50 +00:00
|
|
|
className,
|
|
|
|
addOnLeading,
|
|
|
|
addOnSuffix,
|
|
|
|
addOnFilled = true,
|
2022-11-30 20:51:44 +00:00
|
|
|
addOnClassname,
|
2022-11-28 11:20:49 +00:00
|
|
|
inputIsFullWidth,
|
2022-07-23 00:39:50 +00:00
|
|
|
hint,
|
2022-11-30 20:51:44 +00:00
|
|
|
type,
|
2022-07-29 13:23:54 +00:00
|
|
|
hintErrors,
|
2022-07-23 00:39:50 +00:00
|
|
|
labelSrOnly,
|
|
|
|
containerClassName,
|
2022-12-07 21:47:02 +00:00
|
|
|
readOnly,
|
2022-08-03 16:59:40 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
t: __t,
|
2022-07-23 00:39:50 +00:00
|
|
|
...passThrough
|
|
|
|
} = props;
|
|
|
|
|
2022-11-30 20:51:44 +00:00
|
|
|
const [inputValue, setInputValue] = useState<string>("");
|
|
|
|
|
2022-07-23 00:39:50 +00:00
|
|
|
return (
|
|
|
|
<div className={classNames(containerClassName)}>
|
2022-09-02 19:00:41 +00:00
|
|
|
{!!name && (
|
2022-09-21 16:01:47 +00:00
|
|
|
<Skeleton
|
|
|
|
as={Label}
|
2022-07-23 00:39:50 +00:00
|
|
|
htmlFor={id}
|
2022-09-21 16:01:47 +00:00
|
|
|
loadingClassName="w-16"
|
2022-07-23 00:39:50 +00:00
|
|
|
{...labelProps}
|
2023-04-05 18:14:46 +00:00
|
|
|
className={classNames(labelClassName, labelSrOnly && "sr-only", props.error && "text-error")}>
|
2022-07-23 00:39:50 +00:00
|
|
|
{label}
|
2023-04-13 02:10:23 +00:00
|
|
|
{LockedIcon}
|
2022-09-21 16:01:47 +00:00
|
|
|
</Skeleton>
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
|
|
|
{addOnLeading || addOnSuffix ? (
|
2023-04-16 19:35:17 +00:00
|
|
|
<div
|
|
|
|
dir="ltr"
|
|
|
|
className="group relative mb-1 flex items-center rounded-md focus-within:outline-none focus-within:ring-2 focus-within:ring-neutral-800 focus-within:ring-offset-1">
|
2022-10-05 14:22:06 +00:00
|
|
|
{addOnLeading && (
|
2023-04-16 19:35:17 +00:00
|
|
|
<Addon isFilled={addOnFilled} className={classNames("rounded-l-md border-r-0", addOnClassname)}>
|
2022-10-05 14:22:06 +00:00
|
|
|
{addOnLeading}
|
|
|
|
</Addon>
|
|
|
|
)}
|
2022-07-23 00:39:50 +00:00
|
|
|
<Input
|
|
|
|
id={id}
|
2022-12-05 13:28:21 +00:00
|
|
|
type={type}
|
2022-09-29 16:19:03 +00:00
|
|
|
placeholder={placeholder}
|
2022-11-28 11:20:49 +00:00
|
|
|
isFullWidth={inputIsFullWidth}
|
2022-07-23 00:39:50 +00:00
|
|
|
className={classNames(
|
|
|
|
className,
|
2023-04-13 02:10:23 +00:00
|
|
|
"disabled:bg-muted disabled:hover:border-subtle disabled:cursor-not-allowed",
|
2023-04-16 19:35:17 +00:00
|
|
|
addOnLeading && "rounded-l-none",
|
|
|
|
addOnSuffix && "rounded-r-none",
|
2022-11-30 20:51:44 +00:00
|
|
|
type === "search" && "pr-8",
|
2022-07-23 00:39:50 +00:00
|
|
|
"!my-0 !ring-0"
|
|
|
|
)}
|
2022-12-07 21:47:02 +00:00
|
|
|
{...passThrough}
|
2022-12-09 17:10:54 +00:00
|
|
|
{...(type == "search" && {
|
|
|
|
onChange: (e) => {
|
|
|
|
setInputValue(e.target.value);
|
|
|
|
props.onChange && props.onChange(e);
|
|
|
|
},
|
|
|
|
value: inputValue,
|
|
|
|
})}
|
2023-04-13 02:10:23 +00:00
|
|
|
disabled={readOnly || disabled}
|
2022-07-23 00:39:50 +00:00
|
|
|
ref={ref}
|
|
|
|
/>
|
2022-10-05 14:22:06 +00:00
|
|
|
{addOnSuffix && (
|
2023-01-04 07:38:45 +00:00
|
|
|
<Addon
|
|
|
|
isFilled={addOnFilled}
|
|
|
|
className={classNames(
|
|
|
|
"ltr:rounded-r-md ltr:border-l-0 rtl:rounded-l-md rtl:border-r-0",
|
|
|
|
addOnClassname
|
|
|
|
)}>
|
2022-10-05 14:22:06 +00:00
|
|
|
{addOnSuffix}
|
|
|
|
</Addon>
|
|
|
|
)}
|
2022-11-30 20:51:44 +00:00
|
|
|
{type === "search" && inputValue?.toString().length > 0 && (
|
2023-04-12 15:26:31 +00:00
|
|
|
<X
|
2023-04-05 18:14:46 +00:00
|
|
|
className="text-subtle absolute top-2.5 h-4 w-4 cursor-pointer ltr:right-2 rtl:left-2"
|
2022-11-30 20:51:44 +00:00
|
|
|
onClick={(e) => {
|
|
|
|
setInputValue("");
|
|
|
|
props.onChange && props.onChange(e as unknown as React.ChangeEvent<HTMLInputElement>);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2022-07-23 00:39:50 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
2022-11-28 11:20:49 +00:00
|
|
|
<Input
|
|
|
|
id={id}
|
2022-12-05 13:28:21 +00:00
|
|
|
type={type}
|
2022-11-28 11:20:49 +00:00
|
|
|
placeholder={placeholder}
|
2023-04-13 02:10:23 +00:00
|
|
|
className={classNames(
|
|
|
|
className,
|
|
|
|
"disabled:bg-muted disabled:hover:border-subtle disabled:cursor-not-allowed"
|
|
|
|
)}
|
2022-11-28 11:20:49 +00:00
|
|
|
{...passThrough}
|
2023-03-02 18:15:28 +00:00
|
|
|
readOnly={readOnly}
|
2022-11-28 11:20:49 +00:00
|
|
|
ref={ref}
|
|
|
|
isFullWidth={inputIsFullWidth}
|
2023-04-13 02:10:23 +00:00
|
|
|
disabled={readOnly || disabled}
|
2022-11-28 11:20:49 +00:00
|
|
|
/>
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
2022-09-02 19:00:41 +00:00
|
|
|
<HintsOrErrors hintErrors={hintErrors} fieldName={name} t={t} />
|
2023-04-05 18:14:46 +00:00
|
|
|
{hint && <div className="text-default mt-2 flex items-center text-sm">{hint}</div>}
|
2022-07-23 00:39:50 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export const TextField = forwardRef<HTMLInputElement, InputFieldProps>(function TextField(props, ref) {
|
|
|
|
return <InputField ref={ref} {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
export const PasswordField = forwardRef<HTMLInputElement, InputFieldProps>(function PasswordField(
|
|
|
|
props,
|
|
|
|
ref
|
|
|
|
) {
|
2022-10-03 19:52:57 +00:00
|
|
|
const { t } = useLocale();
|
2022-09-13 16:35:14 +00:00
|
|
|
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
|
|
|
|
const toggleIsPasswordVisible = useCallback(
|
|
|
|
() => setIsPasswordVisible(!isPasswordVisible),
|
|
|
|
[isPasswordVisible, setIsPasswordVisible]
|
|
|
|
);
|
|
|
|
const textLabel = isPasswordVisible ? t("hide_password") : t("show_password");
|
2022-10-03 19:52:57 +00:00
|
|
|
|
2022-09-13 16:35:14 +00:00
|
|
|
return (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="[&_.group:hover_.addon-wrapper]:border-emphasis relative [&_.group:focus-within_.addon-wrapper]:border-neutral-300">
|
2022-09-13 16:35:14 +00:00
|
|
|
<InputField
|
2022-10-03 19:52:57 +00:00
|
|
|
type={isPasswordVisible ? "text" : "password"}
|
2022-10-04 09:20:21 +00:00
|
|
|
placeholder={props.placeholder || "•••••••••••••"}
|
2022-09-13 16:35:14 +00:00
|
|
|
ref={ref}
|
|
|
|
{...props}
|
2023-01-04 07:38:45 +00:00
|
|
|
className={classNames("mb-0 ltr:border-r-0 ltr:pr-10 rtl:border-l-0 rtl:pl-10", props.className)}
|
2022-10-03 19:52:57 +00:00
|
|
|
addOnFilled={false}
|
|
|
|
addOnSuffix={
|
|
|
|
<Tooltip content={textLabel}>
|
|
|
|
<button
|
2023-04-05 18:14:46 +00:00
|
|
|
className="text-emphasis absolute bottom-0 h-9 ltr:right-3 rtl:left-3"
|
2022-10-03 19:52:57 +00:00
|
|
|
type="button"
|
|
|
|
onClick={() => toggleIsPasswordVisible()}>
|
|
|
|
{isPasswordVisible ? (
|
2023-04-12 15:26:31 +00:00
|
|
|
<EyeOff className="h-4 stroke-[2.5px]" />
|
2022-10-03 19:52:57 +00:00
|
|
|
) : (
|
2023-04-12 15:26:31 +00:00
|
|
|
<Eye className="h-4 stroke-[2.5px]" />
|
2022-10-03 19:52:57 +00:00
|
|
|
)}
|
|
|
|
<span className="sr-only">{textLabel}</span>
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
}
|
2022-09-13 16:35:14 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2022-07-23 00:39:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export const EmailInput = forwardRef<HTMLInputElement, InputFieldProps>(function EmailInput(props, ref) {
|
|
|
|
return (
|
|
|
|
<Input
|
|
|
|
ref={ref}
|
|
|
|
type="email"
|
|
|
|
autoCapitalize="none"
|
|
|
|
autoComplete="email"
|
|
|
|
autoCorrect="off"
|
|
|
|
inputMode="email"
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export const EmailField = forwardRef<HTMLInputElement, InputFieldProps>(function EmailField(props, ref) {
|
|
|
|
return (
|
|
|
|
<InputField
|
|
|
|
ref={ref}
|
|
|
|
type="email"
|
|
|
|
autoCapitalize="none"
|
|
|
|
autoComplete="email"
|
|
|
|
autoCorrect="off"
|
|
|
|
inputMode="email"
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-09-02 19:00:41 +00:00
|
|
|
type TextAreaProps = JSX.IntrinsicElements["textarea"];
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(function TextAreaInput(props, ref) {
|
|
|
|
return (
|
|
|
|
<textarea
|
|
|
|
ref={ref}
|
|
|
|
{...props}
|
|
|
|
className={classNames(
|
2023-04-10 16:12:15 +00:00
|
|
|
"hover:border-emphasis border-default bg-default placeholder:text-muted text-emphasis disabled:hover:border-default mb-2 block w-full rounded-md border py-2 px-3 text-sm focus:border-neutral-300 focus:outline-none focus:ring-2 focus:ring-neutral-800 focus:ring-offset-1 disabled:cursor-not-allowed",
|
2022-07-23 00:39:50 +00:00
|
|
|
props.className
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
type TextAreaFieldProps = {
|
|
|
|
label?: ReactNode;
|
2022-08-03 16:59:40 +00:00
|
|
|
t?: (key: string) => string;
|
2022-07-23 00:39:50 +00:00
|
|
|
} & React.ComponentProps<typeof TextArea> & {
|
2022-09-02 19:00:41 +00:00
|
|
|
name: string;
|
2022-07-23 00:39:50 +00:00
|
|
|
labelProps?: React.ComponentProps<typeof Label>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const TextAreaField = forwardRef<HTMLTextAreaElement, TextAreaFieldProps>(function TextField(
|
|
|
|
props,
|
|
|
|
ref
|
|
|
|
) {
|
|
|
|
const id = useId();
|
2022-08-03 16:59:40 +00:00
|
|
|
const { t: _t } = useLocale();
|
|
|
|
const t = props.t || _t;
|
2022-07-23 00:39:50 +00:00
|
|
|
const methods = useFormContext();
|
|
|
|
const {
|
|
|
|
label = t(props.name as string),
|
|
|
|
labelProps,
|
|
|
|
/** Prevents displaying untranslated placeholder keys */
|
|
|
|
placeholder = t(props.name + "_placeholder") !== props.name + "_placeholder"
|
|
|
|
? t(props.name + "_placeholder")
|
|
|
|
: "",
|
|
|
|
...passThrough
|
|
|
|
} = props;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{!!props.name && (
|
|
|
|
<Label htmlFor={id} {...labelProps}>
|
|
|
|
{label}
|
|
|
|
</Label>
|
|
|
|
)}
|
|
|
|
<TextArea ref={ref} placeholder={placeholder} {...passThrough} />
|
2022-08-17 17:38:21 +00:00
|
|
|
{methods?.formState?.errors[props.name]?.message && (
|
|
|
|
<Alert
|
|
|
|
className="mt-1"
|
|
|
|
severity="error"
|
2022-11-04 15:40:46 +00:00
|
|
|
message={<>{methods.formState.errors[props.name]?.message}</>}
|
2022-08-17 17:38:21 +00:00
|
|
|
/>
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
type FormProps<T extends object> = { form: UseFormReturn<T>; handleSubmit: SubmitHandler<T> } & Omit<
|
|
|
|
JSX.IntrinsicElements["form"],
|
|
|
|
"onSubmit"
|
|
|
|
>;
|
|
|
|
|
|
|
|
const PlainForm = <T extends FieldValues>(props: FormProps<T>, ref: Ref<HTMLFormElement>) => {
|
|
|
|
const { form, handleSubmit, ...passThrough } = props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FormProvider {...form}>
|
|
|
|
<form
|
|
|
|
ref={ref}
|
|
|
|
onSubmit={(event) => {
|
|
|
|
event.preventDefault();
|
2022-08-24 20:18:42 +00:00
|
|
|
event.stopPropagation();
|
2023-03-27 18:58:46 +00:00
|
|
|
|
|
|
|
if (form.formState?.errors?.apiError) {
|
|
|
|
form.clearErrors("root");
|
|
|
|
}
|
|
|
|
|
2022-07-23 00:39:50 +00:00
|
|
|
form
|
|
|
|
.handleSubmit(handleSubmit)(event)
|
|
|
|
.catch((err) => {
|
2023-03-02 18:15:28 +00:00
|
|
|
// FIXME: Booking Pages don't have toast, so this error is never shown
|
2022-07-23 00:39:50 +00:00
|
|
|
showToast(`${getErrorFromUnknown(err).message}`, "error");
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
{...passThrough}>
|
2022-11-16 13:41:40 +00:00
|
|
|
{props.children}
|
2022-07-23 00:39:50 +00:00
|
|
|
</form>
|
|
|
|
</FormProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Form = forwardRef(PlainForm) as <T extends FieldValues>(
|
|
|
|
p: FormProps<T> & { ref?: Ref<HTMLFormElement> }
|
|
|
|
) => ReactElement;
|
|
|
|
|
|
|
|
export function FieldsetLegend(props: JSX.IntrinsicElements["legend"]) {
|
|
|
|
return (
|
2023-04-05 18:14:46 +00:00
|
|
|
<legend {...props} className={classNames("text-default text-sm font-medium", props.className)}>
|
2022-07-23 00:39:50 +00:00
|
|
|
{props.children}
|
|
|
|
</legend>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function InputGroupBox(props: JSX.IntrinsicElements["div"]) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
{...props}
|
2023-04-05 18:14:46 +00:00
|
|
|
className={classNames("bg-default border-default space-y-2 rounded-sm border p-2", props.className)}>
|
2022-07-23 00:39:50 +00:00
|
|
|
{props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2022-11-28 11:20:49 +00:00
|
|
|
|
|
|
|
export const InputFieldWithSelect = forwardRef<
|
|
|
|
HTMLInputElement,
|
|
|
|
InputFieldProps & { selectProps: typeof UnstyledSelect }
|
|
|
|
>(function EmailField(props, ref) {
|
|
|
|
return (
|
|
|
|
<InputField
|
|
|
|
ref={ref}
|
|
|
|
{...props}
|
|
|
|
inputIsFullWidth={false}
|
2022-11-30 20:51:44 +00:00
|
|
|
addOnClassname="!px-0"
|
2022-11-28 11:20:49 +00:00
|
|
|
addOnSuffix={<UnstyledSelect {...props.selectProps} />}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2023-04-13 18:26:13 +00:00
|
|
|
|
|
|
|
export const NumberInput = forwardRef<HTMLInputElement, InputFieldProps>(function NumberInput(props, ref) {
|
|
|
|
return (
|
|
|
|
<Input
|
|
|
|
ref={ref}
|
|
|
|
type="number"
|
|
|
|
autoCapitalize="none"
|
|
|
|
autoComplete="numeric"
|
|
|
|
autoCorrect="off"
|
|
|
|
inputMode="numeric"
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|