File size: 3,525 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
/* eslint-disable no-console */
import { PureComponent } from 'react';
import SegmentedControl from '../';
import SimplifiedSegmentedControl from '../simplified';
class SegmentedControlDemo extends PureComponent {
static displayName = 'SegmentedControl';
static defaultProps = {
options: [
{ value: 'all', label: 'All' },
{ value: 'unread', label: 'Unread' },
{ value: 'comments', label: 'Comments' },
{ value: 'follows', label: 'Follows' },
{ value: 'likes', label: 'Likes' },
],
};
state = {
childSelected: 'all',
compact: false,
};
toggleCompact = () => {
this.setState( { compact: ! this.state.compact } );
};
render() {
const controlDemoStyles = { maxWidth: 386 };
return (
<div>
<button className="docs__design-toggle button" onClick={ this.toggleCompact }>
{ this.state.compact ? 'Normal' : 'Compact' }
</button>
<h3>Items passed as options prop</h3>
<SimplifiedSegmentedControl
options={ this.props.options }
onSelect={ this.selectSegment }
style={ controlDemoStyles }
compact={ this.state.compact }
/>
<h3 style={ { marginTop: 20 } }>Primary version</h3>
<SegmentedControl
selectedText={ this.state.childSelected }
style={ controlDemoStyles }
primary
compact={ this.state.compact }
>
<SegmentedControl.Item
selected={ this.state.childSelected === 'all' }
onClick={ this.selectChildSegment.bind( this, 'all' ) }
>
All
</SegmentedControl.Item>
<SegmentedControl.Item
selected={ this.state.childSelected === 'unread' }
onClick={ this.selectChildSegment.bind( this, 'unread' ) }
>
Unread
</SegmentedControl.Item>
<SegmentedControl.Item
selected={ this.state.childSelected === 'comments' }
onClick={ this.selectChildSegment.bind( this, 'comments' ) }
>
Comments
</SegmentedControl.Item>
<SegmentedControl.Item
selected={ this.state.childSelected === 'follows' }
onClick={ this.selectChildSegment.bind( this, 'follows' ) }
>
Follows
</SegmentedControl.Item>
<SegmentedControl.Item
selected={ this.state.childSelected === 'likes' }
onClick={ this.selectChildSegment.bind( this, 'likes' ) }
>
Likes
</SegmentedControl.Item>
</SegmentedControl>
<h3 style={ { marginTop: 20 } }>Three items</h3>
<SegmentedControl
compact={ this.state.compact }
selectedText={ this.state.childSelected }
style={ { maxWidth: 280 } }
>
<SegmentedControl.Item
selected={ this.state.childSelected === 'all' }
onClick={ this.selectChildSegment.bind( this, 'all' ) }
>
All
</SegmentedControl.Item>
<SegmentedControl.Item
selected={ this.state.childSelected === 'unread' }
onClick={ this.selectChildSegment.bind( this, 'unread' ) }
>
Unread
</SegmentedControl.Item>
<SegmentedControl.Item
selected={ this.state.childSelected === 'comments' }
onClick={ this.selectChildSegment.bind( this, 'comments' ) }
>
Comments
</SegmentedControl.Item>
</SegmentedControl>
</div>
);
}
selectChildSegment = ( childSelected, event ) => {
event.preventDefault();
this.setState( {
childSelected: childSelected,
} );
console.log( 'Segmented Control (selected):', childSelected );
};
selectSegment = ( option ) => {
console.log( 'Segmented Control (selected):', option );
};
}
export default SegmentedControlDemo;
|