show/hide api keys with button
This commit is contained in:
parent
c2f6a5fb86
commit
07f97eb12a
3 changed files with 26 additions and 5 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { Eye, EyeOff } from "lucide-react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
|
@ -12,6 +13,11 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||||
const [hasValue, setHasValue] = React.useState(
|
const [hasValue, setHasValue] = React.useState(
|
||||||
Boolean(props.value || props.defaultValue),
|
Boolean(props.value || props.defaultValue),
|
||||||
);
|
);
|
||||||
|
const [showPassword, setShowPassword] = React.useState(false);
|
||||||
|
|
||||||
|
const handleTogglePassword = () => {
|
||||||
|
setShowPassword(!showPassword);
|
||||||
|
};
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setHasValue(e.target.value.length > 0);
|
setHasValue(e.target.value.length > 0);
|
||||||
|
|
@ -23,8 +29,8 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||||
return (
|
return (
|
||||||
<label
|
<label
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative block h-fit w-full text-sm",
|
"relative block h-fit w-full text-sm group",
|
||||||
icon ? className : ""
|
icon ? className : "",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{icon && (
|
{icon && (
|
||||||
|
|
@ -34,17 +40,30 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||||
)}
|
)}
|
||||||
<input
|
<input
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
type={type}
|
type={type === "password" && showPassword ? "text" : type}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
className={cn(
|
className={cn(
|
||||||
"primary-input !placeholder-transparent",
|
"primary-input !placeholder-transparent",
|
||||||
icon && "pl-9",
|
icon && "pl-9",
|
||||||
icon ? inputClassName : className
|
icon ? inputClassName : className,
|
||||||
)}
|
)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...props}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
|
{type === "password" && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="absolute top-1/2 opacity-0 group-hover:opacity-100 hover:text-primary transition-all right-3 transform -translate-y-1/2 text-sm text-muted-foreground"
|
||||||
|
onClick={handleTogglePassword}
|
||||||
|
>
|
||||||
|
{showPassword ? (
|
||||||
|
<Eye className="w-4" />
|
||||||
|
) : (
|
||||||
|
<EyeOff className="w-4" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"pointer-events-none absolute top-1/2 -translate-y-1/2 pl-px text-placeholder-foreground font-mono",
|
"pointer-events-none absolute top-1/2 -translate-y-1/2 pl-px text-placeholder-foreground font-mono",
|
||||||
|
|
@ -56,7 +75,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
Input.displayName = "Input";
|
Input.displayName = "Input";
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ export function IBMOnboarding({
|
||||||
label="IBM API key"
|
label="IBM API key"
|
||||||
helperText="The API key for your watsonx.ai account."
|
helperText="The API key for your watsonx.ai account."
|
||||||
id="api-key"
|
id="api-key"
|
||||||
|
type="password"
|
||||||
required
|
required
|
||||||
placeholder="your-api-key"
|
placeholder="your-api-key"
|
||||||
value={apiKey}
|
value={apiKey}
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ export function OpenAIOnboarding({
|
||||||
label="OpenAI API key"
|
label="OpenAI API key"
|
||||||
helperText="The API key for your OpenAI account."
|
helperText="The API key for your OpenAI account."
|
||||||
id="api-key"
|
id="api-key"
|
||||||
|
type="password"
|
||||||
required
|
required
|
||||||
placeholder="sk-..."
|
placeholder="sk-..."
|
||||||
value={apiKey}
|
value={apiKey}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue