forked from Dshield-xyz/Dshield
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.tsx
More file actions
45 lines (42 loc) · 1.21 KB
/
Copy pathInput.tsx
File metadata and controls
45 lines (42 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { forwardRef, useId } from "react";
import { cn } from "@/lib/cn";
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
label?: string;
/** Helper text rendered under the field. Accepts rich content. */
hint?: React.ReactNode;
/** Render value in a monospace font (addresses, hashes, amounts). */
mono?: boolean;
}
export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
{ className, label, hint, mono, id, ...props },
ref,
) {
const generatedId = useId();
const inputId = id ?? generatedId;
const hintId = `${inputId}-hint`;
return (
<div>
{label && (
<label htmlFor={inputId} className="mb-1.5 block text-xs text-zinc-500">
{label}
</label>
)}
<input
ref={ref}
id={inputId}
aria-describedby={hint ? hintId : undefined}
className={cn(
"aurora-field w-full rounded-xl p-3 text-sm text-zinc-200 placeholder-zinc-600 outline-none",
mono && "font-mono text-xs",
className,
)}
{...props}
/>
{hint && (
<p id={hintId} className="mt-1.5 text-xs text-zinc-600">
{hint}
</p>
)}
</div>
);
});