πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Sign inDemoInstall
Socket

react-styled-radio

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-styled-radio

Radio button component for React built with styled-components < πŸ’…>

0.0.1
latest
Source
npm
Version published
Weekly downloads
14
7.69%
Maintainers
1
Weekly downloads
Β 
Created
Source

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

Props

The RadioGroup component accepts the following props.

PropTypeDefaultDescription: Options
verticalbooleanfalseDisplay radios vertically
onChangefunctionnullFunction to run when value changes

The Radio component accepts the following props.

PropTypeDefaultDescription: Options
smallbooleanfalseButton size
largebooleanfalseButton size
handleChangefunctionnullFunction 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.

PropTypeDefault
inputBgstring#20232A
inputBorderstring#292C34
inputColorstring#212529
inputPlacestring#6B757C
inputOutlinestring#007BFF
inputLabelstring#212529

There are two ways to use the theme object.

  • 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>
);
...
  • 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

ClassDescription
.radio__groupRadio group wrapper
.radio__buttonRadio button wrapper
.radio__textRadio button label

Development

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

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

Shoutouts

License

MIT Β© alexcasche

Keywords

react

FAQs

Package last updated on 17 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts