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

segmented-control

v0.2.1

Published

๐Ÿ’… A good-lookin' segmented control React component

Downloads

3,517

Readme

.

npm version

<SegmentedControl> โ€“ a good-lookin' segmented control React component

<SegmentedControlWithoutStyles> - a version that doesn't import the stylesheet (if <SegmentedControl> doesn't work in your build systemโ€”eg Next.js)

<FormsySegmentedControl> โ€“ a version for Formsy

UX background

In iOS, a segmented control is usually used to display different views (the equivalent of tabs in material design). However, segmented controls are increasingly being used in lieu of plain radio buttons or select inputs (dropdowns, or material menus). See for instance the designer lukew's recommendations:

Other good choices are radio groups, like this Ionic component, or a button list, as used in the Yo or Thumbtack apps, that looks the same, except on click, instead of seeing a checkmark, you're taken to the next screen.

A similar component in material design is the toggle button.

Component

Demo: lorensr.me/segmented-control

two three disabled formsy

Usage

npm install --save segmented-control

Plain

<SegmentedControl> props:

  • className: PropTypes.string: optional custom className for the container in addition to the default segmented-control class.
  • name: PropTypes.string.isRequired: name of the radio <input>s. Also the attribute included in the first argument of Formsy's onSubmit.
  • options: PropTypes.array.isRequired: Maximum length 10, each element an object of the form:
    • label: display text
    • value: value passed to setValue and Formsy's onSubmit
    • default: true: one object must have this
    • disabled: true: optional
  • style: PropTypes.object: common styles are width and color
  • setValue: PropTypes.func: callback on input change, passed the value string. Called once initially with the default value on mount.
import { SegmentedControl } from 'segmented-control'

<SegmentedControl
  name="oneDisabled"
  options={[
    { label: "One", value: "one", disabled: true },
    { label: "Two", value: "two" },
    { label: "Three", value: "three", default: true },
    { label: "Four", value: "four" }
  ]}
  setValue={newValue => this.doSomething(newValue)}
  style={{ width: 400, color: '#ab47bc' }} // purple400
  />

Without styles

As above, but with a different import statement:

import SegmentedControlWithoutStyles from 'segmented-control/SegmentedControlWithoutStyles'

Formsy

<FormsySegmentedControl> has the same props, but includes Formsy.Mixin and calls Formsy's setValue, so that the value is included in onSubmit (see the event triggered by submitting the demo form). In the example below, the first arg of onSubmit would be {exampleInput: 'two'}:

import Formsy from 'formsy-react'
import Button from '@material-ui/core/Button'
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider'
import { FormsySegmentedControl } from 'segmented-control'

<MuiThemeProvider>
  <Formsy.Form
    onValidSubmit={this.onSubmit}
    >
    <FormsySegmentedControl
      name="exampleInput"
      options={[
        { label: "One", value: "one" },
        { label: "Two", value: "two", default: true },
        { label: "Three", value: "three" }
      ]}
      style={{ width: 300, color: 'rgb(0, 188, 212)' }} // match default material-ui primary teal
      />
    <Button
      variant="contained"
      type="submit"
      label="submit formsy form"
      style={{
        display: 'block',
        width: 200,
        margin: "20px auto"
      }}
      primary
    >
      Submit
    </Button>
  </Formsy.Form>
</MuiThemeProvider>

Development

git clone [email protected]:lorensr/segmented-control.git
npm install
npm start

http://localhost:9009

Credits