mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Improve Get Key inputs
This commit is contained in:
2 files changed
+26
-17
No files matched your search
@@ -2,8 +2,13 @@ import * as React from "react"
|
|||||||
import { Eye, EyeOff } from "lucide-react"
|
import { Eye, EyeOff } from "lucide-react"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
const PasswordInput = React.forwardRef<HTMLInputElement, React.InputHTMLAttributes<HTMLInputElement>>(
|
interface PasswordInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||||
({ className, ...props }, ref) => {
|
/** Whether to show the visibility toggle button. Defaults to true. */
|
||||||
|
showToggle?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PasswordInput = React.forwardRef<HTMLInputElement, PasswordInputProps>(
|
||||||
|
({ className, showToggle = true, ...props }, ref) => {
|
||||||
const [showPassword, setShowPassword] = React.useState(false)
|
const [showPassword, setShowPassword] = React.useState(false)
|
||||||
const [isFocused, setIsFocused] = React.useState(false)
|
const [isFocused, setIsFocused] = React.useState(false)
|
||||||
|
|
||||||
@@ -12,7 +17,8 @@ const PasswordInput = React.forwardRef<HTMLInputElement, React.InputHTMLAttribut
|
|||||||
<input
|
<input
|
||||||
type={showPassword ? "text" : "password"}
|
type={showPassword ? "text" : "password"}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 pr-10 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||||
|
showToggle && "pr-10",
|
||||||
isFocused && "ring-2 ring-ring ring-offset-2"
|
isFocused && "ring-2 ring-ring ring-offset-2"
|
||||||
)}
|
)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
@@ -26,19 +32,21 @@ const PasswordInput = React.forwardRef<HTMLInputElement, React.InputHTMLAttribut
|
|||||||
}}
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
<button
|
{showToggle && (
|
||||||
type="button"
|
<button
|
||||||
onClick={() => setShowPassword(!showPassword)}
|
type="button"
|
||||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground focus:outline-none disabled:cursor-not-allowed disabled:opacity-50"
|
onClick={() => setShowPassword(!showPassword)}
|
||||||
disabled={props.disabled}
|
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground focus:outline-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
aria-label={showPassword ? "Hide password" : "Show password"}
|
disabled={props.disabled}
|
||||||
>
|
aria-label={showPassword ? "Hide password" : "Show password"}
|
||||||
{showPassword ? (
|
>
|
||||||
<EyeOff className="h-4 w-4" />
|
{showPassword ? (
|
||||||
) : (
|
<EyeOff className="h-4 w-4" />
|
||||||
<Eye className="h-4 w-4" />
|
) : (
|
||||||
)}
|
<Eye className="h-4 w-4" />
|
||||||
</button>
|
)}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -808,11 +808,12 @@ export function DeploySettings() {
|
|||||||
handleAddPresetProvider(preset);
|
handleAddPresetProvider(preset);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
showToggle={!!presetApiKeys[preset.id]}
|
||||||
/>
|
/>
|
||||||
{preset.apiKeyURL && !presetApiKeys[preset.id] && (
|
{preset.apiKeyURL && !presetApiKeys[preset.id] && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="absolute right-11 top-1/2 -translate-y-1/2 inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors rounded-md hover:bg-muted"
|
className="absolute right-3 top-1/2 -translate-y-1/2 inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors rounded-md hover:bg-muted"
|
||||||
onClick={() => window.open(preset.apiKeyURL, '_blank')}
|
onClick={() => window.open(preset.apiKeyURL, '_blank')}
|
||||||
>
|
>
|
||||||
Get Key
|
Get Key
|
||||||
|
|||||||
Reference in new issue
Block a user