2.5.0 • Published 7 years ago

fyndiq-component-input v2.5.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

fyndiq-component-input npm

A set of Input components for Fyndiq

Installation

The component can be installed through NPM:

npm i -S fyndiq-component-input

<Input />

Demo

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

import React from 'react'
import Input from 'fyndiq-component-input'

// Normal usage
<Input onChange={value => console.log(value)} />

// Pass some regular <input /> props
<Input
  placeholder="My placeholder"
  type="number"
  value={this.state.myInputValue}
/>

// Use the built-in debouncer
// 500ms of debounce, by default
<Input debouncedOnChange={value => console.log(value)} />

// Show a textarea
<Input component={<textarea />} />

API

The component Input has the following customizable props:

NameTypeDescriptionDefault value
classNameStringclassname to pass to the root element''
onChangeFunctionCallback called everytime the input changes() => {}
componentReact elementComponent to render<input />
 disabledBooleanDisables the inputfalse
debouncedOnChangeFunctionDebounced onChange handlernull
 debounceWait NumberTimeout until which the debounced handler is called, in ms 500
 inputRefFunctionAccesses 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 />

Demo

The Presets component allows the user to choose among some default values.

Usage

import React from 'react'
import { Presets } from 'fyndiq-component-input'

// Normal usage
<Presets
  onChange={value => console.log(value)}
  presets={['Value 1', 'Value 2', 'Value 3']}
/>

API

The component Presets has the following customizable props:

NameTypeDescriptionDefault value
inputInput ElementAllows to customize the underlying Input element (placeholder, ...).<Input />
 value StringSets the current value of the input ''
 presetsArray of stringAvailable presets[]
 onChange FunctiononChange handler() => {}

<InvisibleInput />

Demo

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

import React from 'react'
import { InvisibleInput } from 'fyndiq-component-input'

// Normal usage
<InvisibleInput
  value={currentValue}
  onChange={newValue => console.log(newValue)}
/>

API

The component InvisibleInput has the following customizable props:

NameTypeDescriptionDefault value
classNameStringclassname to pass to the root element''
 onChange FunctiononChange handler() => {}
 value StringSets the current value of the input ''

<SearchInput />

Demo

Provides a search-looking input. Bundled with a debouncer

Usage

import React from 'react'
import Input, { SearchInput } from 'fyndiq-component-input'

// Normal usage
<SearchInput onChange={newValue => console.log(newValue)} />

// Collapsible (works great in webpage headers)
<SearchInput collapsible/>

// Customize the Input element
<SearchInput
  input={<Input placeholder="Search the universe" />}
/>

// Use the Input debouncer
<SearchInput debouncedOnChange={value => console.log(value)} />

API

The component SearchInput has the following customizable props:

NameTypeDescriptionDefault value
classNameStringclassname to pass to the root element''
valueStringSets the current value of the input''
 input Input Element Customize the default input element <Input placeholder="Search" type="search" />
 sizem or sCustomize the width of the search input m
collapsible BooleanAdds a collapsible behavior to the input field false
emptyAfterSearch BooleanIf true, the search field is emptied after a search false
 onSearch FunctionHandler called when the user presses "enter"() => {}
 debouncedOnChangeFunctionDebounced onChange handler null
2.5.0

7 years ago

2.4.2

7 years ago

2.4.1

7 years ago

2.4.0

7 years ago

2.3.0

7 years ago

2.2.4

8 years ago

2.2.3

8 years ago

2.2.2

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago