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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-segment-control

v0.1.5

Published

1. `npm install react-segment-control` 2. Import the component into your project: ```import SegmentedControl from 'react-segment-control'```

Readme

Installation

  1. npm install react-segment-control
  2. Import the component into your project: import SegmentedControl from 'react-segment-control'

Available Scripts

In the project directory, you can run:

npm run storybook

Starts the storybook for this component

npm test

Launches the jest/enzyme tests

Usage

A simple example:

const options = [{ label: 'Option 1', value: 'option_1' }, { label: 'Option 2', value: 'option_2'}]
const handleSelect = val => console.log(val)

return <SegmentedControl options={options} onSelect={handleSelect} />

(Recommended) Options can have keys included, for better tracking in the loop

const options = [{ 
  label: 'True', 
  value: { flag: true },
  key: 'true_opt' 
}, { 
  label: 'False', 
  value: { flag: false },
  key: 'false_opt'
}]
const handleSelect = val => console.log(val)

return <SegmentedControl options={options} onSelect={handleSelect} />

Labelling can also be done with a labeller function that takes an option's value as input.

const options = [{ value: 1 }, { value: 2 }]
return <SegmentedControl options={options} labeller={value => `Option ${value}`}>

Options can be uncheckable using the uncheckable prop.

return <SegmentedControl options={options} uncheckable />

Individual options can be disabled by adding a disabled flag to an option.

const options = [{ label: 'Option 1', value: 'option_1', disabled: true }, { label: 'Option 2', value: 'option_2'}]
const handleSelect = val => console.log(val)

return <SegmentedControl options={options} onSelect={handleSelect} />

Options can be pre-selected in a variety of ways using the preselect prop.

const options = [{
  label: 'Option 1',
  value: 'option 1',
  key: 'opt_1'
}, {
  label: 'Option 2',
  value: 'option 2',
  key: 'opt_2'
}]

// preselect by array index of options
<SegmentedControl options={options} preselect={ {index: 1} }>

// preselect by key
<SegmentedControl options={options} preselect={ {key: 'opt_1'} }>

// preselect by value (this works for objects too, so long as their JSON.stringify results are the same)
<SegmentedControl options={options} preselect={ {value: 'option 1'} }>

// preselect by entire option (under the hood this tries key comparison if keys are provided, and value comparison as a fallback)
<SegmentedControl options={options} preselect={options[0]}>