forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropdownsPage.js
More file actions
209 lines (199 loc) · 6.7 KB
/
Copy pathDropdownsPage.js
File metadata and controls
209 lines (199 loc) · 6.7 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React from 'react';
import { Link } from 'react-router';
import { PrismCode } from 'react-prism';
import Helmet from 'react-helmet';
import {
Dropdown,
DropdownToggle,
DropdownItem,
DropdownMenu } from 'reactstrap';
import DropdownExample from '../examples/Dropdown';
import DropdownSizingExample from '../examples/DropdownSizing';
import CustomDropdownExample from '../examples/CustomDropdown';
import DropdownUncontrolledExample from '../examples/DropdownUncontrolled';
const DropdownExampleSource = require('!!raw!../examples/Dropdown');
const CustomDropdownExampleSource = require('!!raw!../examples/CustomDropdown');
const DropdownUncontrolledExampleSource = require('!!raw!../examples/DropdownUncontrolled');
export default class DropdownPage extends React.Component {
constructor(props) {
super(props);
this.toggleExample2 = this.toggle.bind(this);
this.state = {
example2: false
};
}
toggle() {
this.setState({
example2: !this.state.example2
});
}
render() {
return (
<div>
<Helmet title="Dropdowns" />
<h3>Dropdowns</h3>
<p>
The <code>Dropdown</code> component is used to pass the <code>isOpen</code> & <code>toggle</code> props via context to the following components: <code>DropdownToggle</code>, <code>DropdownMenu</code>. The <code>DropdownToggle</code> uses the <code>Button</code> component internally, meaning it also accepts all the props the <Link to="/components/buttons/">Button component</Link> accepts.
</p>
<div className="docs-example">
<DropdownExample />
</div>
<pre>
<PrismCode className="language-jsx">
{DropdownExampleSource}
</PrismCode>
</pre>
<h4>Properties</h4>
<pre>
<PrismCode className="language-jsx">
{`Dropdown.propTypes = {
disabled: PropTypes.bool,
dropup: PropTypes.bool,
group: PropTypes.bool,
isOpen: PropTypes.bool,
tag: PropTypes.string, // default: 'div'
toggle: PropTypes.func
};
DropdownToggle.propTypes = {
caret: PropTypes.bool,
color: PropTypes.string,
className: PropTypes.string,
disabled: PropTypes.bool,
onClick: PropTypes.func,
'data-toggle': PropTypes.string,
'aria-haspopup': PropTypes.bool,
// For DropdownToggle usage inside a Nav
nav: PropTypes.bool,
// Defaults to Button component
tag: PropTypes.any
};
DropdownMenu.propTypes = {
tag: PropTypes.string,
children: PropTypes.node.isRequired,
right: PropTypes.bool,
flip: PropTypes.bool, // default: true,
className: PropTypes.string,
cssModule: PropTypes.object,
};`}
</PrismCode>
</pre>
<h3>Alignment</h3>
<p>To align the <code>DropdownMenu</code> to the right, add a <code>right</code> prop to <code>Dropdown</code>.</p>
<div className="docs-example">
<div style={{ display: 'inline-block' }}>
<Dropdown isOpen={this.state.example2} toggle={this.toggleExample2}>
<DropdownToggle caret>
This dropdown's menu is right-aligned
</DropdownToggle>
<DropdownMenu right>
<DropdownItem header>Header</DropdownItem>
<DropdownItem disabled>Action</DropdownItem>
<DropdownItem>Another Action</DropdownItem>
<DropdownItem divider />
<DropdownItem>Another Action</DropdownItem>
</DropdownMenu>
</Dropdown>
</div>
</div>
<pre>
<PrismCode className="language-jsx">
{`<Dropdown isOpen={this.state.dropdownOpen} toggle={this.toggle}>
<DropdownToggle caret>
This dropdown's menu is right-aligned
</DropdownToggle>
<DropdownMenu right>
<DropdownItem header>Header</DropdownItem>
<DropdownItem disabled>Action</DropdownItem>
<DropdownItem>Another Action</DropdownItem>
<DropdownItem divider/>
<DropdownItem>Another Action</DropdownItem>
</DropdownMenu>
</Dropdown>`}
</PrismCode>
</pre>
<h3>Menu Headers</h3>
<pre>
<PrismCode className="language-jsx">
{'<DropdownItem header>Header</DropdownItem>'}
</PrismCode>
</pre>
<h3>Menu Dividers</h3>
<pre>
<PrismCode className="language-jsx">
{'<DropdownItem divider/>'}
</PrismCode>
</pre>
<h3>Menu Items</h3>
<pre>
<PrismCode className="language-jsx">
{'<DropdownItem>Action</DropdownItem>'}
</PrismCode>
</pre>
<h3>Disabled Menu Items</h3>
<pre>
<PrismCode className="language-jsx">
{'<DropdownItem disabled>Action</DropdownItem>'}
</PrismCode>
</pre>
<h3>Sizing</h3>
<div className="docs-example">
<div>
<DropdownSizingExample group size="lg" />
<DropdownSizingExample className="mt-1" />
<DropdownSizingExample className="mt-1" group size="sm" />
</div>
</div>
<pre>
<PrismCode className="language-jsx">
{`<Dropdown group isOpen={this.state.dropdownOpen} size="lg" toggle={this.toggle}>
<DropdownToggle caret>
Dropdown
</DropdownToggle>
<DropdownMenu>
...
</DropdownMenu>
</Dropdown>
<Dropdown isOpen={this.state.dropdownOpen} toggle={this.toggle}>
<DropdownToggle caret>
Dropdown
</DropdownToggle>
<DropdownMenu>
...
</DropdownMenu>
</Dropdown>
<Dropdown group isOpen={this.state.dropdownOpen} size="sm" toggle={this.toggle}>
<DropdownToggle caret>
Dropdown
</DropdownToggle>
<DropdownMenu>
...
</DropdownMenu>
</Dropdown>`}
</PrismCode>
</pre>
<h4>Custom Dropdown</h4>
<div className="docs-example">
<CustomDropdownExample />
</div>
<pre>
<PrismCode className="language-jsx">
{CustomDropdownExampleSource}
</PrismCode>
</pre>
<h3>Uncontrolled Dropdown</h3>
<p>
For the most basic use-case an uncontrolled component can provide the functionality wanted without the need to manage/control the state of the component. <code>UncontrolledDropdown</code> does not require <code>isOpen</code> nor <code>toggle</code> props to work. For the other Dropdown flavors, <code>ButtonDropdown</code>, <code>NavDropdown</code>, uncontrolled components have been made as well; <code>UncontrolledButtonDropdown</code>, <code>UncontrolledNavDropdown</code> respectfully.
</p>
<div className="docs-example">
<DropdownUncontrolledExample />
</div>
<pre>
<PrismCode className="language-jsx">
{DropdownUncontrolledExampleSource}
</PrismCode>
</pre>
</div>
);
}
}