Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
react-radio-button
Advanced tools
Readme
This react component is a div based radio button group. Simple to use and access.
How to install:
npm install react-radio-button
Example:
Usage:
import React, { Component, PropTypes } from 'react';
import RadioButtonGroup from 'react-radio-button';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
selectedValue: undefined,
radioOptions: [
{ value: 'CreditCard', text: 'Credit Card' },
{ value: 'DebitCard', text: 'Debit Card'}
]
};
}
handleSelection(value) {
this.setState({selectedValue: value});
}
render() {
return (
<div className="container">
<div className="row">
<div className="col-xs-12">
<h2> Welcome for the radio button example</h2>
</div>
<div className="col-xs-12">
<RadioButtonGroup listOfItems={this.state.radioOptions} selectedItemCallback={(value) => this.handleSelection(value)}/>
</div>
<div className="col-xs-12">
<h4>Selected radio button: <i>{this.state.selectedValue}</i></h4>
</div>
</div>
</div>
);
}
}
###props to the <RadioButtonGroup listOfItems={<items>} selectedItemCallback={callbck} />
###listOfItems (PropTypes.array):
The items that need to appear on the radio items, is in the format (array):
javascript radioOptions: [ { value: 'CreditCard', text: 'Credit Card' }, { value: 'DebitCard', text: 'Debit Card'} ]
where,
value
is the value we get on radio button selection
text
is the display of the radio button
###selectedItemCallback (PropTypes.func)
The callback that is invoked when a radio button is clicked (function):
(value) => handleSelection(value)
where,
handleSelection(value) { //value is the selected value, like "CreditCard" or "DebitCard"
this.setState({selectedValue: value});
}
##Customing button colors (The default colors are shown below):
Add these to your custom css file and should be ideally changing the color for which ever color scheme you use.
###With not selected state:
.not-checked {
background-color: #ffffff !important;
border-color: #ccc !important;
}
###With selected state:
.checked {
background-color: #7d9c47 !important;
}
.radio-button-item > input[type="radio"]:checked+span:after {
background-color: #426C2A !important;
}
.radio-button-item > input[type="radio"]:checked+span+span{
color: #fff !important;
}
###On hover, the color to change:
.radio-button-item:hover .radio-dot:before {
border-color: #bdde85 !important;
}
.radio-button-item:hover .radio-dot:after {
background-color: #bef65b !important;
}
Once added to a custom css file (example: test.css), do import the same as:
import React, { Component, PropTypes } from 'react';
import RadioButtonGroup from '~/components/RadioButtonGroup';
import './test.css' // Relative path
FAQs
A react radio button component with an additional pinch of CSS applied.
The npm package react-radio-button receives a total of 5 weekly downloads. As such, react-radio-button popularity was classified as not popular.
We found that react-radio-button demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.