mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 21:11:53 +00:00
73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import type { ChangeEvent } from "react";
|
|
|
|
import { Field, FieldError, FieldLabel } from "@/components/shadcn/field/field";
|
|
import { Input } from "@/components/shadcn/input/input";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
interface CustomServerInputProps {
|
|
name: string;
|
|
label?: string;
|
|
labelPlacement?: "inside" | "outside";
|
|
variant?: "flat" | "bordered" | "underlined" | "faded";
|
|
type?: string;
|
|
placeholder?: string;
|
|
isRequired?: boolean;
|
|
isInvalid?: boolean;
|
|
errorMessage?: string;
|
|
value?: string;
|
|
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
}
|
|
|
|
/**
|
|
* Custom input component that is used to display a server input without useForm hook.
|
|
*/
|
|
export const CustomServerInput = ({
|
|
name,
|
|
type = "text",
|
|
label,
|
|
labelPlacement = "outside",
|
|
placeholder,
|
|
variant = "bordered",
|
|
isRequired = false,
|
|
isInvalid = false,
|
|
errorMessage,
|
|
value,
|
|
onChange,
|
|
}: CustomServerInputProps) => {
|
|
void variant;
|
|
|
|
return (
|
|
<Field>
|
|
{label && (
|
|
<FieldLabel
|
|
htmlFor={name}
|
|
className={cn(
|
|
labelPlacement === "inside" && "font-light tracking-tight",
|
|
)}
|
|
>
|
|
{label}
|
|
{isRequired && <span className="text-text-error-primary">*</span>}
|
|
</FieldLabel>
|
|
)}
|
|
<Input
|
|
id={name}
|
|
name={name}
|
|
type={type}
|
|
placeholder={placeholder}
|
|
required={isRequired}
|
|
aria-invalid={isInvalid || undefined}
|
|
className={cn(
|
|
"text-text-neutral-secondary",
|
|
isInvalid &&
|
|
"border-border-error focus:border-border-error focus:ring-border-error",
|
|
)}
|
|
value={value}
|
|
onChange={onChange}
|
|
/>
|
|
{isInvalid && errorMessage && <FieldError>{errorMessage}</FieldError>}
|
|
</Field>
|
|
);
|
|
};
|