A component which displays a set of buttons, only one of which can be active at a time. Can be used in 'controlled mode' (by setting the value
prop) or uncontrolled.
Usage
import { SegmentedControl } from 'nr1'
Examples
Basic
<SegmentedControl onChange={(evt, value) => console.log(evt, value)}> <SegmentedControlItem value="one" label="One" /> <SegmentedControlItem value="two" label="Two" /> <SegmentedControlItem disabled value="three" label="Three" /> <SegmentedControlItem value="four" label="Four" /></SegmentedControl>
With some hints
<SegmentedControl onChange={(evt, value) => console.log(evt, value)}> <SegmentedControlItem value="one" label="One" /> <SegmentedControlItem value="two" label="Two" /> <SegmentedControlItem hint="The third item" disabled value="three" label="Three" /> <SegmentedControlItem hint="The fourth item" value="four" label="Four" /></SegmentedControl>
Controlled
class TestComponent extends React.Component { constructor(props) { super(props);
this.state = { value: 'one', }; }
render() { return ( <SegmentedControl value={this.state.value} onChange={(evt, value) => this.setState({ value })} > <SegmentedControlItem value="one" label="One" /> <SegmentedControlItem value="two" label="Two" /> <SegmentedControlItem disabled value="three" label="Three" /> <SegmentedControlItem value="four" label="Four" /> </SegmentedControl> ); }}
With icons
class TestComponent extends React.Component { constructor(props) { super(props);
this.state = { value: 'one', }; }
render() { return ( <SegmentedControl value={this.state.value} onChange={(evt, value) => this.setState({ value })} > <SegmentedControlItem label="One" value="one" iconType={ SegmentedControlItem.ICON_TYPE.HARDWARE_AND_SOFTWARE__SOFTWARE__CODE } /> <SegmentedControlItem label="Two" value="two" iconType={ SegmentedControlItem.ICON_TYPE.INTERFACE__OPERATIONS__FILTER } /> <SegmentedControlItem label="Three" value="three" iconType={SegmentedControlItem.ICON_TYPE.INTERFACE__SIGN__NUMBER} /> </SegmentedControl> ); }}
Icons only with some hints
class TestComponent extends React.Component { constructor(props) { super(props);
this.state = { value: 'one', }; }
render() { return ( <SegmentedControl type={SegmentedControl.TYPE.ICONS_ONLY} value={this.state.value} onChange={(evt, value) => this.setState({ value })} > <SegmentedControlItem label="One" value="one" iconType={ SegmentedControlItem.ICON_TYPE.HARDWARE_AND_SOFTWARE__SOFTWARE__CODE } /> <SegmentedControlItem label="Two" value="two" iconType={ SegmentedControlItem.ICON_TYPE.INTERFACE__OPERATIONS__FILTER } hint="The second item." /> <SegmentedControlItem label="Three" value="three" iconType={SegmentedControlItem.ICON_TYPE.INTERFACE__SIGN__NUMBER} hint="The third item." /> </SegmentedControl> ); }}
Props
string | Provide a descriptive label for this control, e.g. "Theme selector". |
REQUIREDnode | An array of maximum 5 |
string | Appends class names to the component.Should be used only for positioning and spacing purposes. |
function | Called whenever a function ( |
enum[] | Spacing property. Spacing is defined as a tuple of zero to four values, which follow the same conventions as CSS properties like <Array of |
object | Inline style for custom styling.Should be used only for positioning and spacing purposes. |
string | Adds a |
enum | Set this to <One of |
any | Set the currently-selected option in the control by updating this prop. |