npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@afonso360/react-input-enhancements

v0.4.16

Published

Set of enhancements for input control (bootstrap-ready)

Downloads

16

Readme

react-input-enhancements

Set of enhancements for input control

The intention of creating this library was to bring input component out of the dropdown/autocomplete/whatever code, so it could be easily replaced with your custom component, and also to split independent functionality into different components, which could be combined with each other (still not quite sure it was worth it, though).

There are currently five components:

  1. <Autosize />
  2. <Autocomplete />
  3. <Dropdown />
  4. <Mask />
  5. <DatePicker />

All components accept function as a child, providing props as a first argument, which you should pass to your input component. If there is nothing else except input, it could be passed as a child directly (for simplicity).

<Combobox /> is a combination of Dropdown, Autosize and/or Autocomplete components.

Demo

http://alexkuz.github.io/react-input-enhancements/

Autosize

Autosize resizes component to fit it's content.

<Autosize defaultValue={value}
          minWidth={100}>
  {(inputProps, { width }) =>
    <input type='text' {...inputProps} />
  }
</Autosize>

Autosize Props

  • value string - Input value (for a controlled component)
  • defaultValue string - Initial value (for a uncontrolled component)
  • getInputElement function() - Optional callback that provides input DOM element
  • defaultWidth number - Minimum input width

Autocomplete

Autocomplete prompts a value based on provided options (see also react-autocomplete for the same behaviour)

<Autocomplete defaultValue={value}
              options={options}>
  {(inputProps, { matchingText, value }) =>
    <input type='text' {...inputProps} />
  }
</Autocomplete>

Autocomplete Props

  • value string - Input value (for a controlled component)
  • defaultValue string - Initial value (for a uncontrolled component)
  • getInputElement function - Optional callback that provides input DOM element
  • options array - Array of options that are used to predict a value

options is an array of strings or objects with a text or value string properties.

Dropdown

Dropdown shows a dropdown with a (optionally filtered) list of suitable options.

<Dropdown defaultValue={value}
          options={options}>
  {(inputProps, { textValue }) =>
    <input type='text' {...inputProps} />
  }
</Dropdown>

Dropdown Props

  • value string - Input value (for a controlled component)
  • defaultValue string - Initial value (for a uncontrolled component)
  • options array - Array of shown options
  • onRenderOption function(className, style, option) - Renders option in list
  • onRenderCaret function(className, style, isActive, children) - Renders a caret
  • onRenderList function(className, style, isActive, listShown, children, header) - Renders list of options
  • onRenderListHeader function(allCount, shownCount, staticCount) - Renders list header
  • dropdownClassName string - Dropdown root element class name
  • dropdownProps object - Custom props passed to dropdown root element
  • optionFilters array - List of option filters

options is an array of strings or objects with a shape:

  • value - "real" value of on option
  • text - text used as input value when option is selected
  • label - text or component rendered in list
  • static - option is never filtered out or sorted
  • disabled - option is not selectable

null option is rendered as a separator

optionFilters is an array of filters for options (for convenience). By default, these filters are used:

  • filters.filterByMatchingTextWithThreshold(20) - filters options by matching value, if options length is more than 20
  • filters.sortByMatchingText - sorting by matching value
  • filters.limitBy(100) - cuts options longer than 100
  • filters.notFoundMessage('No matches found') - shows option with 'No matches found' label if all options are filtered out
  • filters.filterRedudantSeparators - removes redudant separators (duplicated or at the begin/end of the list)

Mask

Mask formats input value.

<Mask defaultValue={value}
      pattern='0000-0000-0000-0000'>
  {(inputProps, { value }) =>
    <input type='text' {...inputProps} />
  }
</Mask>

Mask Props

  • value string - Input value (for a controlled component)
  • defaultValue string - Initial value (for a uncontrolled component)
  • getInputElement function() - Optional callback that provides input DOM element
  • pattern string - String formatting pattern. Only '0' (digit) or 'a' (letter) pattern chars are currently supported.
  • emptyChar string - Character used as an empty symbol (' ' by default)
  • placeholder string - If set, it is shown when unmaskedValue is empty
  • onUnmaskedValueChange function(text) - Fires when value is changed, providing unmasked value

DatePicker

DatePicker uses Mask to format date and shows calendar (react-date-picker by default) in popup.

<DatePicker defaultValue={moment(value).format('ddd DD/MM/YYYY')}
            placeholder={moment().format('ddd DD/MM/YYYY')}
            pattern='ddd DD/MM/YYYY'
            locale='en'>
  {(inputProps, { value }) =>
    <input type='text' {...inputProps} />
  }
</DatePicker>

DatePicker Props

  • value string - Input value (for a controlled component)
  • defaultValue string - Initial value (for a uncontrolled component)
  • pattern string - Date formatting pattern. For now, only these tokens are supported:
    • DD - day of month
    • MM - month
    • YYYY - year
    • ddd - day of week (not editable)
  • placeholder string - If set, it is shown when unmaskedValue is empty
  • locale string - Date locale
  • onRenderCalendar function(className, style, date, isActive, popupShown, onSelect, locale) - Returns calendar component shown in popup (react-date-picker by default)
  • onChange function(date) - Fires when date is selected, providing moment.js object

Combobox

Combobox combines Dropdown, Autosize and/or Autocomplete components.

<Combobox defaultValue={value}
          options={options}
          autosize
          autocomplete>
  {(inputProps, { matchingText, width }) =>
    <input type='text' {...inputProps} />
  }
</Combobox>

Autosize and Autocomlete are enabled with corresponding bool props, other properties are proxied to Dropdown component.

See demo for code examples.

Some other (probably better) implementations