forked from CredenceOrg/Credence-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelect.tsx
More file actions
47 lines (44 loc) · 1.07 KB
/
Copy pathSelect.tsx
File metadata and controls
47 lines (44 loc) · 1.07 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
import './controls.css'
interface SelectProps {
id?: string
value: string
onChange: (v: string) => void
options: { value: string; label: string }[]
ariaLabel?: string
disabled?: boolean
isLoading?: boolean
error?: string
}
export default function Select({
id,
value,
onChange,
options,
ariaLabel,
disabled,
isLoading,
error,
}: SelectProps) {
const isDisabled = disabled || isLoading
const isInvalid = !!error
return (
<div className={`control-select-wrapper ${isLoading ? 'control-select-wrapper--loading' : ''}`}>
<select
id={id}
className={`control-select ${isInvalid ? 'control-select--error' : ''}`}
value={value}
aria-label={ariaLabel}
aria-invalid={isInvalid}
disabled={isDisabled}
onChange={(e) => onChange(e.target.value)}
>
{options.map((o) => (
<option key={o.value} value={o.value}>
{o.label}
</option>
))}
</select>
{isLoading && <div className="control-select-spinner" aria-hidden="true" />}
</div>
)
}