forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUncontrolled.js
More file actions
56 lines (45 loc) · 1.43 KB
/
Copy pathUncontrolled.js
File metadata and controls
56 lines (45 loc) · 1.43 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
import React from 'react';
import Alert from './Alert';
import ButtonDropdown from './ButtonDropdown';
import Dropdown from './Dropdown';
import NavDropdown from './NavDropdown';
import Tooltip from './Tooltip';
const { Component } = React;
const components = {
UncontrolledAlert: Alert,
UncontrolledButtonDropdown: ButtonDropdown,
UncontrolledDropdown: Dropdown,
UncontrolledNavDropdown: NavDropdown,
UncontrolledTooltip: Tooltip,
};
Object.keys(components).forEach((key) => {
const Tag = components[key];
const defaultValue = Tag === Alert;
class Uncontrolled extends Component {
constructor(props) {
super(props);
this.state = { isOpen: defaultValue };
this.toggle = this.toggle.bind(this);
}
toggle() {
this.setState({ isOpen: !this.state.isOpen });
}
render() {
return <Tag isOpen={this.state.isOpen} toggle={this.toggle} {...this.props} />;
}
}
Uncontrolled.displayName = key;
components[key] = Uncontrolled;
});
const UncontrolledAlert = components.UncontrolledAlert;
const UncontrolledButtonDropdown = components.UncontrolledButtonDropdown;
const UncontrolledDropdown = components.UncontrolledDropdown;
const UncontrolledNavDropdown = components.UncontrolledNavDropdown;
const UncontrolledTooltip = components.UncontrolledTooltip;
export {
UncontrolledAlert,
UncontrolledButtonDropdown,
UncontrolledDropdown,
UncontrolledNavDropdown,
UncontrolledTooltip,
};