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 _templateObject = _taggedTemplateLiteral(['\n border-radius: 0 0 0.28571429rem 0.28571429rem;\n background: #fff;\n margin: 0 0 0;\n box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.08);\n border: 1px solid rgba(34, 36, 38, 0.15);\n z-index: 1000000000;\n'], ['\n border-radius: 0 0 0.28571429rem 0.28571429rem;\n background: #fff;\n margin: 0 0 0;\n box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.08);\n border: 1px solid rgba(34, 36, 38, 0.15);\n z-index: 1000000000;\n']),
|
12 | _templateObject2 = _taggedTemplateLiteral(['\n padding: 0.5em 1.2em;\n cursor: pointer;\n color: #555;\n &:hover {\n background-color: #eee;\n }\n'], ['\n padding: 0.5em 1.2em;\n cursor: pointer;\n color: #555;\n &:hover {\n background-color: #eee;\n }\n']);
|
13 |
|
14 | var _react = require('react');
|
15 |
|
16 | var _react2 = _interopRequireDefault(_react);
|
17 |
|
18 | var _reactPopper = require('react-popper');
|
19 |
|
20 | var _semanticUiReact = require('semantic-ui-react');
|
21 |
|
22 | var _styledComponents = require('styled-components');
|
23 |
|
24 | var _styledComponents2 = _interopRequireDefault(_styledComponents);
|
25 |
|
26 | var _propTypes = require('prop-types');
|
27 |
|
28 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
29 |
|
30 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31 |
|
32 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
33 |
|
34 | 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; }
|
35 |
|
36 | 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; }
|
37 |
|
38 | function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
39 |
|
40 | 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; }
|
41 |
|
42 | var renderDefaultButton = function renderDefaultButton(_ref) {
|
43 | var ref = _ref.ref,
|
44 | text = _ref.text,
|
45 | buttonProps = _objectWithoutProperties(_ref, ['ref', 'text']);
|
46 |
|
47 | return _react2.default.createElement(
|
48 | _semanticUiReact.Ref,
|
49 | { innerRef: ref },
|
50 | _react2.default.createElement(
|
51 | _semanticUiReact.Button,
|
52 | buttonProps,
|
53 | text
|
54 | )
|
55 | );
|
56 | };
|
57 |
|
58 | var ListContainer = _styledComponents2.default.div(_templateObject);
|
59 | var ListItem = _styledComponents2.default.div(_templateObject2);
|
60 |
|
61 | var MenuDropdown = function (_React$Component) {
|
62 | _inherits(MenuDropdown, _React$Component);
|
63 |
|
64 | function MenuDropdown() {
|
65 | var _ref2;
|
66 |
|
67 | var _temp, _this, _ret;
|
68 |
|
69 | _classCallCheck(this, MenuDropdown);
|
70 |
|
71 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
72 | args[_key] = arguments[_key];
|
73 | }
|
74 |
|
75 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref2 = MenuDropdown.__proto__ || Object.getPrototypeOf(MenuDropdown)).call.apply(_ref2, [this].concat(args))), _this), _this.state = { visible: _this.props.popedByDefault === true }, _this.renderList = function (_ref3) {
|
76 | var ref = _ref3.ref,
|
77 | style = _ref3.style,
|
78 | placement = _ref3.placement,
|
79 | options = _ref3.options,
|
80 | optionClicked = _ref3.optionClicked,
|
81 | children = _ref3.children;
|
82 | return _react2.default.createElement(
|
83 | ListContainer,
|
84 | {
|
85 | onMouseEnter: _this.mouseEnteredMenu,
|
86 | onMouseLeave: _this.mouseLeftMenu,
|
87 | innerRef: ref,
|
88 | style: style,
|
89 | 'data-placement': placement,
|
90 | onClick: _this.hide
|
91 | },
|
92 | typeof children === 'function' ? children() : children != null ? children : options.map(function (_ref4) {
|
93 | var text = _ref4.text,
|
94 | value = _ref4.value,
|
95 | key = _ref4.key;
|
96 | return _react2.default.createElement(
|
97 | ListItem,
|
98 | { value: value, onClick: optionClicked, key: key || text },
|
99 | text
|
100 | );
|
101 | })
|
102 | );
|
103 | }, _this.mouseLeftMenu = function () {
|
104 | _this.leftMenu = true;
|
105 | setTimeout(function () {
|
106 | return _this.leftMenu && _this.hide();
|
107 | }, 400);
|
108 | }, _this.mouseEnteredMenu = function () {
|
109 | _this.leftMenu = false;
|
110 | }, _this.clicked = function (e) {
|
111 | _this.setState(function (_ref5) {
|
112 | var visible = _ref5.visible;
|
113 | return { visible: !visible };
|
114 | });
|
115 | }, _this.optionClicked = function (e) {
|
116 | if (e.target && e.target.getAttribute && _this.props.onOptionSelected) {
|
117 | _this.props.onOptionSelected(e.target.getAttribute('value'));
|
118 | } else if (_this.props.onOptionSelected) {
|
119 | _this.props.onOptionSelected(e);
|
120 | }
|
121 | _this.setState({ visible: false });
|
122 | }, _this.hide = function () {
|
123 | return _this.setState({ visible: false });
|
124 | }, _this.getButtonProps = function (_ref6) {
|
125 | var _ref7 = _ref6.ref,
|
126 | rest = _objectWithoutProperties(_ref6, ['ref']);
|
127 |
|
128 | return _extends({}, rest, {
|
129 | ref: function ref(n) {
|
130 | _this.button = n;
|
131 | _ref7(n);
|
132 | }
|
133 | });
|
134 | }, _temp), _possibleConstructorReturn(_this, _ret);
|
135 | }
|
136 |
|
137 | _createClass(MenuDropdown, [{
|
138 | key: 'componentDidMount',
|
139 | value: function componentDidMount() {
|
140 | this.leftMenu = true;
|
141 | }
|
142 | }, {
|
143 | key: 'componentWillUnmount',
|
144 | value: function componentWillUnmount() {
|
145 | this.setState({ visible: false });
|
146 | }
|
147 | }, {
|
148 | key: 'render',
|
149 | value: function render() {
|
150 | var _this2 = this;
|
151 |
|
152 | var _props = this.props,
|
153 | renderButton = _props.renderButton,
|
154 | popperPlacement = _props.popperPlacement,
|
155 | buttonProps = _props.buttonProps,
|
156 | listProps = _props.listProps,
|
157 | options = _props.options,
|
158 | className = _props.className,
|
159 | style = _props.style,
|
160 | children = _props.children;
|
161 | var visible = this.state.visible;
|
162 |
|
163 | console.log('visible is: ', visible);
|
164 |
|
165 | return _react2.default.createElement(
|
166 | _reactPopper.Manager,
|
167 | null,
|
168 | _react2.default.createElement(
|
169 | _reactPopper.Reference,
|
170 | null,
|
171 | function (props) {
|
172 | return renderButton(_this2.getButtonProps(_extends({}, props, buttonProps, {
|
173 | onClick: _this2.clicked,
|
174 | className: className,
|
175 | style: style
|
176 | })));
|
177 | }
|
178 | ),
|
179 | !visible ? null : _react2.default.createElement(
|
180 | _reactPopper.Popper,
|
181 | { placement: popperPlacement },
|
182 | function (props) {
|
183 | return _this2.renderList(_extends({}, props, listProps, {
|
184 | options: options,
|
185 | optionClicked: _this2.optionClicked,
|
186 | children: children
|
187 | }));
|
188 | }
|
189 | )
|
190 | );
|
191 | }
|
192 | }]);
|
193 |
|
194 | return MenuDropdown;
|
195 | }(_react2.default.Component);
|
196 |
|
197 | MenuDropdown.propTypes = {
|
198 |
|
199 | renderButton: _propTypes2.default.func,
|
200 | popperPlacement: _propTypes2.default.string,
|
201 | buttonProps: _propTypes2.default.object,
|
202 | listProps: _propTypes2.default.object,
|
203 | options: _propTypes2.default.array,
|
204 | onOptionSelected: _propTypes2.default.func,
|
205 | popedByDefault: _propTypes2.default.bool,
|
206 | className: _propTypes2.default.string,
|
207 | style: _propTypes2.default.object
|
208 | };
|
209 | MenuDropdown.defaultProps = {
|
210 | renderButton: renderDefaultButton,
|
211 | popperPlacement: 'bottom-end',
|
212 | buttonProps: { text: 'Actions', primary: true },
|
213 | listProps: {}
|
214 | };
|
215 | exports.default = MenuDropdown;
|
216 |
|
\ | No newline at end of file |