1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
8 |
|
9 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
10 |
|
11 | var _react = require('react');
|
12 |
|
13 | var _react2 = _interopRequireDefault(_react);
|
14 |
|
15 | var _classnames = require('classnames');
|
16 |
|
17 | var _classnames2 = _interopRequireDefault(_classnames);
|
18 |
|
19 | var _utils = require('./utils');
|
20 |
|
21 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
22 |
|
23 | function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
24 |
|
25 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
26 |
|
27 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
28 |
|
29 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
30 |
|
31 | var propTypes = {
|
32 | children: _react.PropTypes.node,
|
33 | disabled: _react.PropTypes.bool,
|
34 | divider: _react.PropTypes.bool,
|
35 | tag: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.string]),
|
36 | header: _react.PropTypes.bool,
|
37 | onClick: _react.PropTypes.func,
|
38 | className: _react.PropTypes.string,
|
39 | cssModule: _react.PropTypes.object
|
40 | };
|
41 |
|
42 | var contextTypes = {
|
43 | toggle: _react.PropTypes.func
|
44 | };
|
45 |
|
46 | var defaultProps = {
|
47 | tag: 'button'
|
48 | };
|
49 |
|
50 | var DropdownItem = function (_React$Component) {
|
51 | _inherits(DropdownItem, _React$Component);
|
52 |
|
53 | function DropdownItem(props) {
|
54 | _classCallCheck(this, DropdownItem);
|
55 |
|
56 | var _this = _possibleConstructorReturn(this, (DropdownItem.__proto__ || Object.getPrototypeOf(DropdownItem)).call(this, props));
|
57 |
|
58 | _this.onClick = _this.onClick.bind(_this);
|
59 | _this.getTabIndex = _this.getTabIndex.bind(_this);
|
60 | return _this;
|
61 | }
|
62 |
|
63 | _createClass(DropdownItem, [{
|
64 | key: 'onClick',
|
65 | value: function onClick(e) {
|
66 | if (this.props.disabled || this.props.header || this.props.divider) {
|
67 | e.preventDefault();
|
68 | return;
|
69 | }
|
70 |
|
71 | if (this.props.onClick) {
|
72 | this.props.onClick(e);
|
73 | }
|
74 |
|
75 | this.context.toggle();
|
76 | }
|
77 | }, {
|
78 | key: 'getTabIndex',
|
79 | value: function getTabIndex() {
|
80 | if (this.props.disabled || this.props.header || this.props.divider) {
|
81 | return '-1';
|
82 | }
|
83 |
|
84 | return '0';
|
85 | }
|
86 | }, {
|
87 | key: 'render',
|
88 | value: function render() {
|
89 | var tabIndex = this.getTabIndex();
|
90 |
|
91 | var _props = this.props,
|
92 | className = _props.className,
|
93 | cssModule = _props.cssModule,
|
94 | divider = _props.divider,
|
95 | Tag = _props.tag,
|
96 | header = _props.header,
|
97 | props = _objectWithoutProperties(_props, ['className', 'cssModule', 'divider', 'tag', 'header']);
|
98 |
|
99 | var classes = (0, _utils.mapToCssModules)((0, _classnames2.default)(className, {
|
100 | disabled: props.disabled,
|
101 | 'dropdown-item': !divider && !header,
|
102 | 'dropdown-header': header,
|
103 | 'dropdown-divider': divider
|
104 | }), cssModule);
|
105 |
|
106 | if (Tag === 'button') {
|
107 | if (header) {
|
108 | Tag = 'h6';
|
109 | } else if (divider) {
|
110 | Tag = 'div';
|
111 | }
|
112 | }
|
113 |
|
114 | return _react2.default.createElement(Tag, _extends({}, props, {
|
115 | tabIndex: tabIndex,
|
116 | className: classes,
|
117 | onClick: this.onClick
|
118 | }));
|
119 | }
|
120 | }]);
|
121 |
|
122 | return DropdownItem;
|
123 | }(_react2.default.Component);
|
124 |
|
125 | DropdownItem.propTypes = propTypes;
|
126 | DropdownItem.defaultProps = defaultProps;
|
127 | DropdownItem.contextTypes = contextTypes;
|
128 |
|
129 | exports.default = DropdownItem; |
\ | No newline at end of file |