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-styled-radio

v0.0.1

Published

Radio button component for React built with styled-components < 💅>

Downloads

3

Readme

react-styled-radio

Radio button component for React built with styled-components < 💅>

NPM JavaScript Style Guide Travis

Install

npm install --save react-styled-radio
yarn add react-styled-radio

Usage

  • Import the RadioGroup & Radio components from module
  • Wrap the Radios inside the RadioGroup
  • Wrap the Radio components inside the RadioGroup
  • Set RadioGroup name prop
  • Set Radios value & label props
  • Pass in any other desired props (see props section)
import React, { Component } from 'react';
import { RadioGroup, Radio } from 'react-styled-radio';

class Example extends Component {
  render () {
    return (
      <RadioGroup horizontal name="gender">
        <Radio small value="male" label="male"/>
        <Radio small value="female" label="female"/>
      </RadioGroup>
    )
  }
}

Features

  • Only three peer depencies (react/prop-types/styled-components)
  • Easy to use BEM class hooks

Examples

  • Demo - https://alexcasche.github.io/react-styled-radio/

Props

The RadioGroup component accepts the following props.

| Prop | Type | Default | Description: Options | |-------------------|-------------|------------------|---------------------------| | vertical | boolean | false | Display radios vertically | | onChange | function | null | Function to run when value changes |

The Radio component accepts the following props.

| Prop | Type | Default | Description: Options | |-------------------|-------------|------------------|--------------------------| | small | boolean | false | Button size | | large | boolean | false | Button size | | handleChange | function | null | Function to run when value changes |

The handleChange prop is automatically passed the event object. See below example.


class Example extends Component {
  onChange = e => {
    console.log(e.target.value)
    /*  
      If the first radio is clicked this will log 'male'
      If the second radio is clicked this will log 'female' 
    */
  }
  render () {
    return (
      <RadioGroup horizontal name="gender" onChange={this.onChange}>
        <Radio small value="male" label="male"/>
        <Radio small value="female" label="female"/>
      </RadioGroup>
    )
  }
}

Theme

The theme object can be used to customize the look of the components, with the following values.

| Prop | Type | Default | |-------------------|-------------|------------------| | inputBg | string | #20232A | | inputBorder | string | #292C34 | | inputColor | string | #212529 | | inputPlace | string | #6B757C | | inputOutline | string | #007BFF | | inputLabel | string | #212529 |

There are two ways to use the theme object.

  1. Pass the theme to the styled-components ThemeProvider (recommended)
import { ThemeProvider } from 'styled-components';

...
return (
  <ThemeProvider theme={theme}>
    <RadioGroup horizontal name="gender" handleChange={this.handleChange}>
      <Radio small value="male" label="male"/>
      <Radio small value="female" label="female"/>
    </RadioGroup>
  </ThemeProvider>
);
...
  1. Pass the theme directly to the Radio components (not recommended)
...
return (
  <RadioGroup horizontal name="gender" handleChange={this.handleChange}>
    <Radio theme={theme} small value="male" label="male"/>
    <Radio theme={theme} small value="female" label="female"/>
  </RadioGroup>
);
...

Classes

| Class | Description | |------------------------|--------------------| | .radio__group | Radio group wrapper | | .radio__button | Radio button wrapper | | .radio__text | Radio button label |

Development

Follow these steps to setup a local development environment. Use yarn or npm - not both.

  1. Clone the repo from Github
git clone https://github.com/alexcasche/react-styled-radio
  1. Setup project & start rollup watch
npm install && npm start
yarn install && yarn add
  1. Setup react app & start dev server
cd example
npm install && npm start
yarn install && yarn start

Shoutouts

License

MIT © alexcasche