fyndiq-component-input
A set of Input components for Fyndiq
Installation
The component can be installed through NPM:
npm i -S fyndiq-component-input
<Input />
This component is just a wrapper around the <input />
DOM element. It provides some default styling as well as a debouncing feature out of the box.
Usage
// Normal usage<Input onChange= console />// Pass some regular <input /> props<Inputplaceholder="My placeholder"type="number"value=thisstatemyInputValue/>// Use the built-in debouncer// 500ms of debounce, by default<Input debouncedOnChange= console />// Show a textarea<Input component=<textarea /> />
API
The component Input
has the following customizable props:
Name | Type | Description | Default value |
---|---|---|---|
className | String | classname to pass to the root element | '' |
onChange | Function | Callback called everytime the input changes | () => {} |
component | React element | Component to render | <input /> |
disabled | Boolean | Disables the input | false |
debouncedOnChange | Function | Debounced onChange handler | null |
debounceWait | Number | Timeout until which the debounced handler is called, in ms | 500 |
inputRef | Function | Accesses the ref of the input element. Allows to do advanced things like calling .blur() or .focus() |
null |
Any other prop will be passed directly to the underlying <input />
element (value
, defaultValue
, placeholder
, onFocus
, onBlur
...)
<Presets />
The Presets component allows the user to choose among some default values.
Usage
// Normal usage<PresetsonChange= consolepresets='Value 1' 'Value 2' 'Value 3'/>
API
The component Presets
has the following customizable props:
Name | Type | Description | Default value |
---|---|---|---|
input | Input Element | Allows to customize the underlying Input element (placeholder, ...). |
<Input /> |
value | String | Sets the current value of the input | '' |
presets | Array of string | Available presets | [] |
onChange | Function | onChange handler | () => {} |
<InvisibleInput />
This input has no styles applied to it and looks invisible until hovered and focused. Works great with data forms where the data is not supposed to be changed except in some edge-cases.
Usage
// Normal usage<InvisibleInputvalue=currentValueonChange= console/>
API
The component InvisibleInput
has the following customizable props:
Name | Type | Description | Default value |
---|---|---|---|
className | String | classname to pass to the root element | '' |
onChange | Function | onChange handler | () => {} |
value | String | Sets the current value of the input | '' |
<SearchInput />
Provides a search-looking input. Bundled with a debouncer
Usage
// Normal usage<SearchInput onChange= console />// Collapsible (works great in webpage headers)<SearchInput collapsible/>// Customize the Input element<SearchInputinput=<Input placeholder="Search the universe" />/>// Use the Input debouncer<SearchInput debouncedOnChange= console />
API
The component SearchInput
has the following customizable props:
Name | Type | Description | Default value |
---|---|---|---|
className | String | classname to pass to the root element | '' |
value | String | Sets the current value of the input | '' |
input | Input Element | Customize the default input element | <Input placeholder="Search" type="search" /> |
size | m or s |
Customize the width of the search input | m |
collapsible | Boolean | Adds a collapsible behavior to the input field | false |
emptyAfterSearch | Boolean | If true, the search field is emptied after a search | false |
onSearch | Function | Handler called when the user presses "enter" | () => {} |
debouncedOnChange | Function | Debounced onChange handler | null |