2.3.11 • Published 5 years ago

react-new-input v2.3.11

Weekly downloads
4
License
ISC
Repository
-
Last release
5 years ago

Demo with Storybook

https://brennemankyle.github.io/react-new-input/

Features

A robust multi-select that automatically uses Radios, Checkboxes, or a Switch if they'll fit on one line

  • Deterministic even with dynamic/live prop updates
  • Completely customizable: replace any internal component, styling, icon, text, or search filter by changing props
  • Automatically uses Radios, Checkboxes, or a Switch if it fits on one line (updates on live screen resizes)
  • Search using fuzzy matching: mossisippi > Mississippi, py > Pi. Powered by https://glench.github.io/fuzzyset.js/
  • Fully usable with only the Keyboard
  • Creatable options (managed by a prop not a separate component)
  • Selectable Option Groups (parent group can be selected)
  • Small npm package size
  • No Jquery
  • Modern browser support: Chrome, Safari, Edge, Firefox, iOS, Android
  • And much more!

Install

npm install react-new-input

// Example File
import React, { useState } from 'react'
import NewInput from 'react-new-input'

// With React Function/Hooks
let SomeHook = () => {
  const [selection, setSelection] = useState()
  let options = [
    {value: '1', label: 'Option 1'},
    {value: '2', label: 'Option 2'},
  ]

  return <NewInput
    name="example"
    selection={selection}
    onChange={(e) => setSelection(e.target.value)}
    options={options} />
}

// OR With React Component
class SomeComponent extends React.Component {
  constructor(props) {
    super(props)
    this.state = {selection}
    this.options = [
      {value: '1', label: 'Option 1'},
      {value: '2', label: 'Option 2'},
    ]
  }

  onChange(e) {
    this.setState({
      selection: e.target.value
    })
  }

  render() {
    return <NewInput
      name="example"
      selection={this.state.selection}
      onChange={this.onChange}
      options={this.options} />
  }
}

Comparison

NameBundle Size
react-new-inputgzip 21.1kB (https://bundlephobia.com/result?p=react-new-input)
react-select (competitor)gzip 26.1kb (https://bundlephobia.com/result?p=react-select)

Property Defaults

NameDefault Value
onChangeundefined
onBlurnoop
onFocusnoop
nameundefined
selection[]
options[]
placeholder'Select...'
multiplefalse
disabledfalse
creatablefalse
removabletrue
appendToBodyfalse
rightToLeftfalse
allowDuplicatestrue
alwaysReturnArrayfalse
filterOptionsfilterOptions
massageDataInmassageDataIn
massageDataOutmassageDataOut
optionKeys'value', 'label'
checkRadioMaxCount10
parseTostring
Text Props
text_placeholder''
text_noOptions'No Options'
text_create'Create'
Component Props
component_SelectSelect
component_CheckRadioCheckRadio
component_CheckBoxCheckBox
component_RadioRadio
component_SwitchSwitch
component_HtmlFieldDataHtmlFieldData
component_WrapperWrapper
component_SelectionSelection
component_SelectionListSelectionList
component_OptionListOptionList
component_OptionOption
component_SearchSearch
component_SelectionWrapperSelectionWrapper
component_OptionsWrapperOptionsWrapper
component_AppendToBodyOptionsWrapperAppendToBodyOptionsWrapper
component_StyledAppendToBodyOptionsWrapperStyledAppendToBodyOptionsWrapper
SVG Props
svg_CheckmarkCheckmark
svg_RemoveRemove
svg_ExpandExpand
Style Props
styles_fontSize'1em'
styles_borderRadius'.2em'
styles_paddingTop'.25em'
styles_paddingBottom'.25em'
styles_paddingLeft'.25em'
styles_paddingRight'.25em'
styles_selection_paddingTop'.2em'
styles_selection_paddingBottom'.2em'
styles_selection_paddingLeft'.4em'
styles_selection_paddingRight'.4em'
styles_selection_margin'.2em'
styles_option_paddingTop'.25em'
styles_option_paddingBottom'.25em'
styles_option_paddingLeft'.25em'
styles_option_paddingRight'.25em'
styles_checkRadio_borderWidth'2px'
styles_checkRadio_marginBetween'1em'
styles_checkRadio_labelMargin'.2em'
styles_checkRadio_paddingTop'.2em'
styles_checkRadio_paddingBottom'.2em'
styles_checkRadio_paddingLeft'.2em'
styles_checkRadio_paddingRight'.2em'
styles_search_size5
styles_icon_width'1em'
styles_colors_primary'black'
styles_colors_secondary'#C3C3C3'
styles_colors_highlight'lightblue'
styles_colors_warning'#FABAAC'
styles_colors_warningBold'#FA2222'
styles_colors_disabled'#ECECEC'
styles_colors_background'white'

Property Descriptions

NameDescription
onChangeEvent when selection changes
onBlurEvent when focus is lost
onFocusEvent when focus is gained
nameThe HTML name in the form
selectionThe currently selected items
optionsThe options to choose from
placeholderThe placeholder of the search field
multipleWhether multiple items can be selected
disabledWhether component is disabled
creatableWhether new selected items can be created
removableWhether selected items are removable
appendToBodyWhether options append to the body tag (can prevent options from being clipped)
rightToLeftWhether to show text from right to left instead
allowDuplicatesWhether duplicate selection items are allowed
alwaysReturnArrayAlways return an array from onChange, instead of only when multiple
filterOptionsThe function which filters options based on search text
massageDataInThe function that massages the props coming in
massageDataOutThe function massaging the selection returned from the onChange event
optionKeysThe name of the keys in an option object
checkRadioMaxCountThe maximum radio buttons allowed before rendering a Select instead
parseToparse value from onChange to a js type: string, number, int, float, boolean
Text Props
text_placeholderSame as placeholder with a more descriptive name
text_noOptionsThe text shown when there are no options
text_createThe text shown when a new selection can be created
Component Props
component_SelectMulti/Single select component
component_CheckRadioGroups checkbox and radio components
component_CheckBoxCheckbox component
component_RadioRadio button component
component_SwitchOn/Off switch component
component_HtmlFieldDataHidden component which keeps current selection in the HTML form
component_WrapperWraps the entire select component
component_SelectionComponent showing one selected item
component_SelectionListList of selected items
component_OptionListList of options
component_OptionComponent showing one option
component_SearchComponent responsable for the search text
component_SelectionWrapperDisplays everything for the Select except the options
component_OptionsWrapperWraps the OptionList
component_AppendToBodyOptionsWrapperAppends the OptionList to body tag
component_StyledAppendToBodyOptionsWrapperStyleable version of AppendToBodyOptionsWrapper wrapped inside of it
SVG Props
svg_CheckmarkThe checkmark image
svg_RemoveThe remove image
svg_Expandthe expand image
Style Props
styles_fontSizeControls the entire size of the component
styles_borderRadiusThe amount of curve of the border
styles_paddingTopThe padding top
styles_paddingBottomThe padding bottom
styles_paddingLeftThe padding left
styles_paddingRightThe padding right
styles_selection_paddingTopThe selection's padding top
styles_selection_paddingBottomThe selection's padding bottom
styles_selection_paddingLeftThe selection's padding left
styles_selection_paddingRightThe selection's padding right
styles_selection_marginThe selection's margin
styles_option_paddingTopThe option's padding top
styles_option_paddingBottomThe option's padding bottom
styles_option_paddingLeftThe option's padding left
styles_option_paddingRightThe option's padding right
styles_checkRadio_borderWidthThe border width for checkbox, radio, and switch
styles_checkRadio_marginBetweenThe margin between radios and checkboxes
styles_checkRadio_labelMarginThe margin between the label and it's radio/checkbox/switch
styles_checkRadio_paddingTopThe padding top for radio/checkbox/switch group
styles_checkRadio_paddingBottomThe padding bottom for radio/checkbox/switch group
styles_checkRadio_paddingLeftThe padding left for radio/checkbox/switch group
styles_checkRadio_paddingRightThe padding right for radio/checkbox/switch group
styles_search_sizeThe size of the search component
styles_icon_widthThe width of all icon/SVGs
styles_colors_primaryThe primary color used
styles_colors_secondaryThe secondary color used
styles_colors_highlightThe color of a highlighted option
styles_colors_warningThe color of remove selection background
styles_colors_warningBoldThe color of the remove selection icon
styles_colors_disabledThe color for disabled elements
styles_colors_backgroundThe background color used
2.3.11

5 years ago

2.3.10

5 years ago

2.3.9

5 years ago

2.3.8

5 years ago

2.3.7

5 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.7

5 years ago

2.2.6

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.0

5 years ago