-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.tsx
More file actions
80 lines (76 loc) · 2.09 KB
/
input.tsx
File metadata and controls
80 lines (76 loc) · 2.09 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as React from 'react'
import type z4 from 'zod/v4'
import type { InputProps, InputVariantEnum } from '../types'
import { cn } from '../utils'
import { Container } from './container'
import { Label } from './label'
import { RequiredIndicator } from './required-indicator'
import { Text } from './text'
const inputVariantClasses: Record<z4.infer<typeof InputVariantEnum>, string> = {
ghost: '',
primary: 'border focus-visible:ring-2 focus-visible:ring-accent'
}
const Input = React.forwardRef<HTMLInputElement, InputProps>(
(
{
id,
variant = 'primary',
defaultValue,
label,
description,
placeholder,
required,
type = 'text',
value,
onChange,
maxLength,
disabled,
autoFocus = false,
onKeyDown,
step = 1,
max,
min,
className
},
ref
) => {
return (
<Container gap="sm" overflow="visible" className={cn('', className)}>
{label && <Label htmlFor={id}>{label}</Label>}
{/* TODO: remove className in container */}
<Container className="relative" width="full">
<input
ref={ref}
id={id}
type={type}
className={cn(
'flex h-9 w-full rounded-default bg-background px-3 py-2 text-sm transition-colors file:border-0 file:bg-transparent file:font-medium file:text-foreground file:text-sm placeholder:opacity-60 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50',
inputVariantClasses[variant]
)}
required={required}
placeholder={placeholder}
defaultValue={defaultValue}
value={value}
onChange={onChange}
disabled={disabled}
maxLength={maxLength}
// biome-ignore lint/a11y/noAutofocus: autoFocus is intentionally allowed here to support chat and form UX where immediate input focus is desired.
autoFocus={autoFocus}
onKeyDown={onKeyDown}
step={step}
min={min}
max={max}
/>
{required && <RequiredIndicator />}
</Container>
{description && (
<Text size="xs" variant="tertiary">
{description}
</Text>
)}
</Container>
)
}
)
Input.displayName = 'Input'
export { Input }