-
Notifications
You must be signed in to change notification settings - Fork 0
/
Input.tsx
34 lines (29 loc) · 880 Bytes
/
Input.tsx
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
import type { ChangeEvent } from 'react'
import styles from './Input.module.css'
type InputProps = {
onChange?: (text: string) => void
placeholder?: string
/** Should show spinner */
isLoading?: boolean
}
function buildOnChangeHandler(onChange: InputProps['onChange']) {
if (!onChange) {
return
}
return function (event: ChangeEvent<HTMLInputElement>) {
onChange(event.target.value)
}
}
export function Input({ placeholder, isLoading, onChange }: InputProps) {
return (
<div className={styles.input}>
<input
className={styles.control}
placeholder={placeholder}
type="text"
onChange={buildOnChangeHandler(onChange)}
/>
{isLoading && (<span aria-label='Loading' className={styles.spinner} />)}
</div>
)
}