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

selectly

v0.5.0

Published

Build custom, accessible, select menus for React.

Downloads

1,047

Readme

Selectly

Build custom select menus in React. Provides a low level way to build the select menu you need.

Install

npm install selectly --save

bower install selectly --save

Example Usage

import { Select, Trigger, OptionList, Option, utils } from 'Selectly'
const { getToggledValues } = utils

class MultiSelect extends Component {
  constructor(props) {
    super(props)
    this.state = {
      defaultValue: 'Select a color',
      currentValues: []
    }
  }

  _handleChange(value) {
    this.setState({
      currentValues: getToggledValues(this.state.currentValues, value)
    })
  }

  render() {
    const { defaultValue, currentValues } = this.state
    return (
      <Select
        multiple
        onChange={value => this._handleChange(value)}
      >
        <Trigger>
          { currentValues.length > 0
            ? currentValues.join(', ')
            : defaultValue
          }
        </Trigger>
        <OptionList tag="ul" className="react-select-menu">
          <Option value="red">Red</Option>
          <Option value="green">Green</Option>
          <Option value="blue">Blue</Option>
        </OptionList>
      </Select>
    )
  }
}

Select Props

children: PropTypes.node.isRequired (Accepts 2 children)

The first child is used as the trigger and the second child is used as the options that will be displayed upon clicking the trigger.

multiple: PropTypes.bool

When true this allows multiple options to be selected.

disabled: PropTypes.bool

Puts the select menu in a disabled state.

autoWidth: PropTypes.bool

Determines if the options should be the same width as the trigger.

onChange: PropTypes.func

Callback when an option has been selected. Passes back the value that was selected.

React ARIA Components

Trigger, OptionList, and Option are exported directly from React ARIA

Utilities

buildOptionsLookup: (array options)

Returns a flat object to allow optgroup options to be accessed easier.

[
  { label: 'Dogs', optgroup: [
    { value: 'frenchy', label: 'French Bulldog' },
    { value: 'pit-bull', label: 'Pit Bull' }
  ]},
  { label: 'Cats', optgroup: [
    { value: 'munchkin', label: 'Munchkin' },
    { value: 'persian', label: 'Persian' }
  ]}
]

turns into

{
  'frenchy':  { value: 'frenchy', label: 'French Bulldog' },
  'pit-bull': { value: 'pit-bull', label: 'Pit Bull' },
  'munchkin': { value: 'munchkin', label: 'Munchkin' },
  'persian':  { value: 'persian', label: 'Persian' }
}

getAllValues: (object options)

Returns an array of all option values.

getToggledValues: (object prevValues, [array, string] nextValues)

Returns a new array of values either added or removed.

getCurrentOptions: (object options, [array, string] currentValue)

Returns an array of the current option or options.

isOptionSelected: ([array, string] currentValue, string value)

Determines if value exists in or matches currentValue. Returns true or false.

Run Example

clone repo

git clone [email protected]:souporserious/selectly.git

move into folder

cd ~/selectly

install dependencies

npm install

run dev mode

npm run dev

open your browser and visit: http://localhost:8080/