Skip to content

Commit

Permalink
chore: add new CustomTextArea component and use it for k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
paabloLC committed Nov 29, 2024
1 parent 2847ffd commit d5ac2c2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Control } from "react-hook-form";

import { CustomInput } from "@/components/ui/custom";
import { CustomTextarea } from "@/components/ui/custom";
import { KubernetesCredentials } from "@/types";

export const KubernetesCredentialsForm = ({
Expand All @@ -15,17 +15,17 @@ export const KubernetesCredentialsForm = ({
Connect via Credentials
</div>
<div className="py-2 text-default-500">
Please provide the information for your Kubernetes credentials.
Please provide the kubeconfig content for your Kubernetes credentials.
</div>
</div>
<CustomInput
<CustomTextarea
control={control}
name="kubeconfig_content"
type="text"
label="Kubeconfig Content"
labelPlacement="inside"
placeholder="Enter the Kubeconfig Content"
placeholder="Paste your Kubeconfig YAML content here"
variant="bordered"
minRows={10}
isRequired
isInvalid={!!control._formState.errors.kubeconfig_content}
/>
Expand Down
74 changes: 74 additions & 0 deletions ui/components/ui/custom/custom-textarea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"use client";

import { Textarea } from "@nextui-org/input";
import React from "react";
import { Control, FieldPath, FieldValues } from "react-hook-form";

import { FormControl, FormField, FormMessage } from "@/components/ui/form";

interface CustomTextareaProps<T extends FieldValues> {
control: Control<T>;
name: FieldPath<T>;
label?: string;
labelPlacement?: "inside" | "outside" | "outside-left";
variant?: "flat" | "bordered" | "underlined" | "faded";
size?: "sm" | "md" | "lg";
placeholder?: string;
defaultValue?: string;
isRequired?: boolean;
isInvalid?: boolean;
minRows?: number;
maxRows?: number;
fullWidth?: boolean;
disableAutosize?: boolean;
description?: React.ReactNode;
}

export const CustomTextarea = <T extends FieldValues>({
control,
name,
label = name,
labelPlacement = "inside",
placeholder,
variant = "flat",
size = "md",
defaultValue,
isRequired = false,
isInvalid = false,
minRows = 3,
maxRows = 8,
fullWidth = true,
disableAutosize = false,
description,
}: CustomTextareaProps<T>) => {
return (
<FormField
control={control}
name={name}
render={({ field }) => (
<>
<FormControl>
<Textarea
id={name}
label={label}
labelPlacement={labelPlacement}
placeholder={placeholder}
variant={variant}
size={size}
isInvalid={isInvalid}
isRequired={isRequired}
defaultValue={defaultValue}
minRows={minRows}
maxRows={maxRows}
fullWidth={fullWidth}
disableAutosize={disableAutosize}
description={description}
{...field}
/>
</FormControl>
<FormMessage className="text-system-error dark:text-system-error" />
</>
)}
/>
);
};
1 change: 1 addition & 0 deletions ui/components/ui/custom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "./custom-dropdown-filter";
export * from "./custom-input";
export * from "./custom-loader";
export * from "./custom-radio";
export * from "./custom-textarea";

0 comments on commit d5ac2c2

Please sign in to comment.