-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
import { Component } from "solid-js"; | ||
import { Component, JSX, createSignal } from "solid-js"; | ||
|
||
interface InputProps { | ||
type InputProps = JSX.InputHTMLAttributes<HTMLInputElement> & { | ||
debounce?: number; | ||
className?: string; | ||
value: string; | ||
onChange: (value: string) => void; | ||
placeholder?: string; | ||
type?: string; | ||
} | ||
}; | ||
|
||
export const Input: Component<InputProps> = ({ className, debounce = 0, onInput, value: initialValue = "", ...props }) => { | ||
let timeoutId: number; | ||
const [value, setValue] = createSignal(initialValue as string); | ||
|
||
const handleInput: JSX.EventHandler<HTMLInputElement, InputEvent> = (e) => { | ||
const target = e.currentTarget; | ||
setValue(target.value); | ||
|
||
if (debounce > 0) { | ||
clearTimeout(timeoutId); | ||
timeoutId = setTimeout(() => { | ||
// @ts-ignore | ||
onInput?.(e); | ||
}, debounce); | ||
} else { | ||
// @ts-ignore | ||
onInput?.(e); | ||
} | ||
}; | ||
|
||
export const Input: Component<InputProps> = (props) => { | ||
return ( | ||
<div | ||
class={`${ | ||
props.className ? props.className : "" | ||
className ? className : "" | ||
} group flex items-center justify-between rounded-md border border-gray-300 p-1 px-1.5 text-sm focus-within:border-indigo-500 dark:border-dark-light dark:bg-dark-light`} | ||
> | ||
<input | ||
type={props.type || "text"} | ||
value={props.value} | ||
onChange={(e) => props.onChange(e.currentTarget.value)} | ||
placeholder={props.placeholder} | ||
{...props} | ||
onInput={handleInput} | ||
value={value()} | ||
class="w-full appearance-none bg-transparent text-sm focus:outline-none focus:ring-0 dark:text-white" | ||
/> | ||
</div> | ||
); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters