blob: 026b062695cf76e1bd173a4a69c438507d63f748 (
plain)
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
|
import { useCallback } from 'preact/hooks';
import type { Signal } from '@preact/signals';
import './TextInput.css';
export interface TextInputProps {
signal?: Signal<string>;
props: Record<string, any>;
}
const TextInput = ({ signal, ...props }: TextInputProps) => {
const onInputSignal = useCallback((event: InputEvent) => {
signal.value = event.target.value;
}, [signal]);
return (
<input
type="text"
{...props}
class={(props.class || '') + ' __TextInput'}
value={signal || props.value}
onInput={signal ? onInputSignal : props.onInput}
/>
);
};
export default TextInput;
|