Shards React
Documentation
The FormRadio
component is a wrapper over Bootstrap's custom radio component.
Select your favorite fruit:
import React from "react";
import { FormRadio } from "shards-react";
export default class FormRadioExample extends React.Component {
constructor(props) {
super(props);
this.state = {
selectedFruit: null
};
this.changeFruit = this.changeFruit.bind(this);
}
changeFruit(fruit) {
this.setState({
selectedFruit: fruit
});
}
render() {
return (
<div>
<p className="mb-2">Select your favorite fruit:</p>
<FormRadio
name="fruit"
checked={this.state.selectedFruit === "orange"}
onChange={() => {
this.changeFruit("orange");
}}
>
Orange
</FormRadio>
<FormRadio
name="fruit"
checked={this.state.selectedFruit === "lemon"}
onChange={() => {
this.changeFruit("lemon");
}}
>
Lemon
</FormRadio>
<FormRadio
name="fruit"
checked={this.state.selectedFruit === "kiwi"}
onChange={() => {
this.changeFruit("kiwi");
}}
>
Kiwi
</FormRadio>
<span>
<strong>Selected fruit:</strong>{" "}
<span>{this.state.selectedFruit || "none"}</span>
</span>
</div>
);
}
}
Radios can also be displayed inline using the inline
prop.
Select your favorite sport:
import React from "react";
import { FormRadio } from "shards-react";
export default class FormRadioExample extends React.Component {
constructor(props) {
super(props);
this.state = {
selectedSport: null
};
this.changeSport = this.changeSport.bind(this);
}
changeSport(sport) {
this.setState({
selectedSport: sport
});
}
render() {
return (
<div>
<div>
<p className="mb-2">Select your favorite sport:</p>
<FormRadio
inline
name="sport"
checked={this.state.selectedSport === "basketball"}
onChange={() => {
this.changeSport("basketball");
}}
>
Basketball
</FormRadio>
<FormRadio
inline
name="sport"
checked={this.state.selectedSport === "football"}
onChange={() => {
this.changeSport("football");
}}
>
Football
</FormRadio>
<FormRadio
inline
name="sport"
checked={this.state.selectedSport === "tennis"}
onChange={() => {
this.changeSport("tennis");
}}
>
Tennis
</FormRadio>
</div>
<span>
<strong>Selected sport:</strong>{" "}
<span>{this.state.selectedSport || "none"}</span>
</span>
</div>
);
}
}
The following props are available for the Form Radio
component.
Prop | Description | Type | Default | Required |
---|---|---|---|---|
className | The class name. | String | - | No |
children | The children. | Node | - | No |
inline | Whether it is inline, or not. | Bool | - | No |
valid | Whether it is valid, or not. | Bool | - | No |
onChange | The function that should run on change. | Func | () => {} | No |
invalid | Whether it is invalid, or not. | Bool | - | No |
innerRef | The inner ref. | Object Func String | - | No |