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

react-simple-radio-group

v0.1.4

Published

A React mixin for linking form fields to a deep structure of data within the component's state.

Downloads

15

Readme

react-radio-group

clone form react-radio

fix bugs for urgency use

now only radio type will trigger change event

A carefully crafted radio-group for React

Install

$ npm install react-simple-radio-group

Usage

var RadioGroup = require('react-radio')

var colors = [
    {
        value: 'red',
        label: 'Red color',
        style: {
            color: 'red'
        }
    },
    'blue',
    'orange'
]

function onChange(value, event){
    console.log('checked ', value)
}

//uncontrolled
<RadioGroup
    name="colors"
    defaultValue={'red'}
    items={colors}
    onChange={onChange}
/>

var COLOR = 'red'
//controlled
<RadioGroup name="colors" value={COLOR} items={colors} onChange={onChange} />

<RadioGroup name="colors" value={'red'} onChange={onChange}>
    <input type="radio" value="blue" />blue
    <input type="radio" value="red" />red
</RadioGroup>

Props

  • name: String - the name to be set to all radios in the group

  • value/defaultValue - the value that should be checked in the group (controlled/uncontrolled)

  • labelStyle - a style for the radio label

  • inputStyle - a style for the radio input

  • checkedLabelStyle - a style for the checked radio label

  • checkedInputStyle - a style for the checked radio input

  • onChange: Function(value, event) - the function to be calle when the radio group value changes. NOTE: first param sent to this function is the new value, not the event object, as usual

  • renderRadio: Function(props, index, arr) - you can customize how each radio item is rendered in the group using this function. NOTE: it is called with 3 params, so not intended to be directly used with a React factory.

Example:

   //NOT LIKE THIS
   <RadioGroup renderRadio={React.DOM.label} />

   //BUT like this
   function renderRadio(props, index, arr){
       return <label {...props} />
   }

   <RadioGroup renderRadio={renderRadio} />

   //or
   function renderRadio(props, index, arr){
       if (index < arr.length - 1){
           props.style.borderBottom = '1px solid blue'
       }
       props.style.display = 'block'
       //we can skip returning something
       //if we only want to modify props/styles
   }

If the renderRadio function returns undefined, we assume you just wanted to modify the props before rendering, which is ok, so we fallback to the default implementation: <label {...props}/>

  • items: Array

    The items prop can be an array of strings/objects or mixed. If an array of strings, the strings will be used as both value and label. If objects, item.value will be used as a value, and item.label as a string:

    Example:

        var items = [
            {label: 'Green', value: 'green'},
            {label: 'Blueish', value: 'blue'},
            {value: 'red'} //'red' will be used as both value and label
        ]
    
        //or
        var items = ['green', 'blue', 'red']

    If an array item is an object, besides value and label, it can also have a style property and a checkedStyle property.

    var items = [
        'red',
        {
            label: 'Blue',
            value: 'blue',
            style: { color: 'blue'},
            checkedStyle: { color: 'blue', background: 'red'}
        }
    ]
  • children - if the component specifies children, the radio group children will not be generated from items, but will be what you specify in the children prop

If you have a ref to the react-radio component, you can also call group.getValue() to get the current value of the radio group.

Contributing

  • Fork this Repo first
  • Clone your Repo
  • Install dependencies by $ npm install
  • Checkout a feature branch
  • Feel free to add your features
  • Make sure your features are fully tested
  • Publish your local branch, Open a pull request
  • Enjoy hacking <3

MIT license

Copyright (c) 2015 [object Object]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


docor built upon love by docor v0.3.0