Open History to see the last commit
1import { createSignal } from 'solid-js'
2import { createStyles } from '../styles/use-styles'
3β
4interface InputProps {
5 label?: string
6 type?: 'text' | 'number' | 'password' | 'email'
7 value?: string
8 placeholder?: string
9 onChange?: (value: string) => void
10 description?: string
11}
12β
13export function Input(props: InputProps) {
14 const styles = createStyles()
15 const [val, setVal] = createSignal(props.value || '')
16β
17 const handleChange = (e: Event) => {
18 const value = (e.target as HTMLInputElement).value
19 setVal((prev) => (prev !== value ? value : prev))
20 props.onChange?.(value)
21 }
22β
23 return (
24 <div class={styles().inputContainer}>
25 <div class={styles().inputWrapper}>
26 {props.label && (
27 <label class={styles().inputLabel}>{props.label}</label>
28 )}
29 {props.description && (
30 <p class={styles().inputDescription}>{props.description}</p>
31 )}
32 <input
33 type={props.type || 'text'}
34 class={styles().input}
35 value={val()}
36 placeholder={props.placeholder}
37 onInput={handleChange}
38 />
39 </div>
40 </div>
41 )
42}