1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _react = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _reactOutsideClickHandler = _interopRequireDefault(require("react-outside-click-handler"));
|
11 |
|
12 | var _Transition = _interopRequireDefault(require("react-transition-group/Transition"));
|
13 |
|
14 | var _Button = _interopRequireDefault(require("./Button"));
|
15 |
|
16 | var _Icon = _interopRequireDefault(require("./Icon"));
|
17 |
|
18 | var _withStyles = require("../helpers/withStyles");
|
19 |
|
20 | var _reactWithStyles = require("react-with-styles");
|
21 |
|
22 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
23 |
|
24 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25 |
|
26 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
27 |
|
28 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
29 |
|
30 | function _extends() { _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; }; return _extends.apply(this, arguments); }
|
31 |
|
32 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
33 |
|
34 | 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); } }
|
35 |
|
36 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
37 |
|
38 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
39 |
|
40 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
41 |
|
42 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
43 |
|
44 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
45 |
|
46 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
47 |
|
48 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
49 |
|
50 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
51 |
|
52 | var dropdownPropTypes = _objectSpread({}, _reactWithStyles.withStylesPropTypes, {
|
53 | disabled: _propTypes.default.bool,
|
54 | loading: _propTypes.default.bool,
|
55 | fullWidth: _propTypes.default.bool,
|
56 | block: _propTypes.default.bool,
|
57 | combo: _propTypes.default.bool,
|
58 | compact: _propTypes.default.bool,
|
59 | icon: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]),
|
60 | inverse: _propTypes.default.bool,
|
61 | mono: _propTypes.default.bool,
|
62 | noBorder: _propTypes.default.bool,
|
63 | noSpacing: _propTypes.default.bool,
|
64 | shade: _propTypes.default.bool,
|
65 | soft: _propTypes.default.bool,
|
66 | primary: _propTypes.default.bool,
|
67 | rectangular: _propTypes.default.bool,
|
68 | secondary: _propTypes.default.bool,
|
69 | short: _propTypes.default.bool,
|
70 | transparent: _propTypes.default.bool,
|
71 | children: _propTypes.default.node,
|
72 | button: _propTypes.default.bool,
|
73 | label: _propTypes.default.string,
|
74 | only: _propTypes.default.bool,
|
75 | relative: _propTypes.default.bool,
|
76 | left: _propTypes.default.bool,
|
77 | options: _propTypes.default.arrayOf(_propTypes.default.object),
|
78 | onSelectOption: _propTypes.default.func,
|
79 | closeOnSelect: _propTypes.default.bool
|
80 | });
|
81 |
|
82 | var dropdownMenuPropTypes = _objectSpread({}, _reactWithStyles.withStylesPropTypes, {
|
83 | children: _propTypes.default.any.isRequired,
|
84 | left: _propTypes.default.bool,
|
85 | isOpen: _propTypes.default.bool,
|
86 | insideAButton: _propTypes.default.bool
|
87 | });
|
88 |
|
89 | var dropdownDefaultProps = {
|
90 | options: []
|
91 | };
|
92 |
|
93 | var Dropdown =
|
94 |
|
95 | function (_Component) {
|
96 | _inherits(Dropdown, _Component);
|
97 |
|
98 | function Dropdown(props) {
|
99 | var _this;
|
100 |
|
101 | _classCallCheck(this, Dropdown);
|
102 |
|
103 | _this = _possibleConstructorReturn(this, _getPrototypeOf(Dropdown).call(this, props));
|
104 | _this.state = {
|
105 | isOpen: false,
|
106 | closedByOutsideClick: false
|
107 | };
|
108 | return _this;
|
109 | }
|
110 |
|
111 | _createClass(Dropdown, [{
|
112 | key: "toggleMenu",
|
113 | value: function toggleMenu() {
|
114 | this.setState(function (_ref) {
|
115 | var isOpen = _ref.isOpen,
|
116 | closedByOutsideClick = _ref.closedByOutsideClick;
|
117 | return closedByOutsideClick && !isOpen ? {
|
118 | closedByOutsideClick: false
|
119 | } : {
|
120 | isOpen: !isOpen
|
121 | };
|
122 | });
|
123 | }
|
124 | }, {
|
125 | key: "onClickOutsideMenu",
|
126 | value: function onClickOutsideMenu() {
|
127 | this.setState(function (state) {
|
128 | return {
|
129 | isOpen: false,
|
130 | closedByOutsideClick: state.isOpen
|
131 | };
|
132 | });
|
133 | }
|
134 | }, {
|
135 | key: "onSelectOption",
|
136 | value: function onSelectOption(option) {
|
137 | this.props.onSelectOption && this.props.onSelectOption(option);
|
138 | this.props.closeOnSelect && this.toggleMenu();
|
139 | }
|
140 | }, {
|
141 | key: "render",
|
142 | value: function render() {
|
143 | var _this2 = this;
|
144 |
|
145 | var _this$props = this.props,
|
146 | styles = _this$props.styles,
|
147 | button = _this$props.button,
|
148 | label = _this$props.label,
|
149 | children = _this$props.children,
|
150 | only = _this$props.only,
|
151 | relative = _this$props.relative,
|
152 | left = _this$props.left,
|
153 | options = _this$props.options,
|
154 | disabled = _this$props.disabled,
|
155 | loading = _this$props.loading,
|
156 | fullWidth = _this$props.fullWidth,
|
157 | block = _this$props.block,
|
158 | combo = _this$props.combo,
|
159 | compact = _this$props.compact,
|
160 | icon = _this$props.icon,
|
161 | inverse = _this$props.inverse,
|
162 | mono = _this$props.mono,
|
163 | noBorder = _this$props.noBorder,
|
164 | noSpacing = _this$props.noSpacing,
|
165 | shade = _this$props.shade,
|
166 | soft = _this$props.soft,
|
167 | shimmer = _this$props.shimmer,
|
168 | primary = _this$props.primary,
|
169 | rectangular = _this$props.rectangular,
|
170 | secondary = _this$props.secondary,
|
171 | short = _this$props.short,
|
172 | transparent = _this$props.transparent;
|
173 | return _react.default.createElement("div", (0, _withStyles.css)(styles.dropdown__container, button && styles.dropdown__container_asAButton, noSpacing && styles.dropdown__container_noSpacing, !combo && (button || only || relative) && styles.dropdown__container_relative), button ? _react.default.createElement(_Button.default, _extends({
|
174 | noSpacing: true,
|
175 | disabled: disabled,
|
176 | loading: loading,
|
177 | shimmer: shimmer,
|
178 | fullWidth: fullWidth,
|
179 | block: block,
|
180 | compact: compact,
|
181 | inverse: inverse,
|
182 | mono: mono,
|
183 | noBorder: noBorder,
|
184 | soft: soft,
|
185 | primary: primary,
|
186 | rectangular: rectangular,
|
187 | secondary: secondary,
|
188 | shade: shade,
|
189 | short: short,
|
190 | transparent: transparent,
|
191 | type: "button",
|
192 | onClick: function onClick() {
|
193 | return _this2.toggleMenu();
|
194 | }
|
195 | }, (0, _withStyles.css)(styles.dropdown, styles.dropdown_asAButton)), label, icon ? typeof label === 'string' ? _react.default.createElement(_Icon.default, {
|
196 | name: icon,
|
197 | primary: true,
|
198 | smaller: true,
|
199 | noPadding: true
|
200 | }) : icon : _react.default.createElement("svg", _extends({}, (0, _withStyles.css)(styles.dropdown__arrow, label && styles.dropdown__arrow_leftMarged, mono && styles.dropdown__arrow_mono, (soft || inverse || transparent) && styles.dropdown__arrow_primary, secondary && styles.dropdown__arrow_secondary), {
|
201 | xmlns: "http://www.w3.org/2000/svg",
|
202 | viewBox: "0 0 10.4 6.3"
|
203 | }), _react.default.createElement("path", {
|
204 | d: "M5.2,6.3A.91.91,0,0,1,4.5,6L.3,1.8A1,1,0,0,1,.3.4,1,1,0,0,1,1.7.4L5.2,3.9,8.7.3a1,1,0,0,1,1.4,0,1,1,0,0,1,0,1.4L5.9,6a4.88,4.88,0,0,1-.7.3Z"
|
205 | }))) : _react.default.createElement("button", _extends({
|
206 | type: "button",
|
207 | onClick: function onClick() {
|
208 | return _this2.toggleMenu();
|
209 | }
|
210 | }, (0, _withStyles.css)(styles.dropdown, only && styles.dropdown_only)), _react.default.createElement("svg", _extends({}, (0, _withStyles.css)(styles.dropdown__arrow, mono && styles.dropdown__arrow_mono, (soft || inverse || transparent || primary) && styles.dropdown__arrow_primary, secondary && styles.dropdown__arrow_secondary), {
|
211 | xmlns: "http://www.w3.org/2000/svg",
|
212 | viewBox: "0 0 10.4 6.3"
|
213 | }), _react.default.createElement("path", {
|
214 | d: "M5.2,6.3A.91.91,0,0,1,4.5,6L.3,1.8A1,1,0,0,1,.3.4,1,1,0,0,1,1.7.4L5.2,3.9,8.7.3a1,1,0,0,1,1.4,0,1,1,0,0,1,0,1.4L5.9,6a4.88,4.88,0,0,1-.7.3Z"
|
215 | }))), _react.default.createElement(DropdownMenuWithStyles, {
|
216 | isOpen: this.state.isOpen,
|
217 | onClickOutside: function onClickOutside() {
|
218 | return _this2.onClickOutsideMenu();
|
219 | },
|
220 | left: left,
|
221 | insideAButton: button,
|
222 | combo: combo
|
223 | }, children ? children : _react.default.createElement("ul", (0, _withStyles.css)(styles.dropdown__list), options.map(function (option) {
|
224 | return _react.default.createElement("li", _extends({
|
225 | key: option.value
|
226 | }, (0, _withStyles.css)(styles.dropdown__list__item)), _react.default.createElement(_Button.default, {
|
227 | short: true,
|
228 | compact: true,
|
229 | inverse: true,
|
230 | noSpacing: true,
|
231 | block: true,
|
232 | onClick: function onClick() {
|
233 | return _this2.onSelectOption(option);
|
234 | }
|
235 | }, option.label));
|
236 | }))));
|
237 | }
|
238 | }]);
|
239 |
|
240 | return Dropdown;
|
241 | }(_react.Component);
|
242 |
|
243 | var DropdownMenu =
|
244 |
|
245 | function (_Component2) {
|
246 | _inherits(DropdownMenu, _Component2);
|
247 |
|
248 | function DropdownMenu() {
|
249 | _classCallCheck(this, DropdownMenu);
|
250 |
|
251 | return _possibleConstructorReturn(this, _getPrototypeOf(DropdownMenu).apply(this, arguments));
|
252 | }
|
253 |
|
254 | _createClass(DropdownMenu, [{
|
255 | key: "render",
|
256 | value: function render() {
|
257 | var _this$props2 = this.props,
|
258 | children = _this$props2.children,
|
259 | combo = _this$props2.combo,
|
260 | left = _this$props2.left,
|
261 | isOpen = _this$props2.isOpen,
|
262 | insideAButton = _this$props2.insideAButton,
|
263 | styles = _this$props2.styles,
|
264 | onClickOutside = _this$props2.onClickOutside;
|
265 | return _react.default.createElement(_reactOutsideClickHandler.default, {
|
266 | onOutsideClick: function onOutsideClick() {
|
267 | return onClickOutside();
|
268 | }
|
269 | }, _react.default.createElement(_Transition.default, {
|
270 | in: isOpen,
|
271 | timeout: 300,
|
272 | mountOnEnter: true,
|
273 | unmountOnExit: true,
|
274 | onEnter: function onEnter(node) {
|
275 | return node.scrollTop;
|
276 | }
|
277 | }, function (state) {
|
278 | return _react.default.createElement("div", (0, _withStyles.css)(styles.dropdownMenu, !combo && insideAButton && styles.dropdownMenu_insideAButton, left ? styles.dropdownMenu_left : styles.dropdownMenu_right, (state === 'entering' || state === 'entered') && styles.dropdownMenu_entering, (state === 'exiting' || state === 'exited') && styles.dropdownMenu_exiting), children);
|
279 | }));
|
280 | }
|
281 | }]);
|
282 |
|
283 | return DropdownMenu;
|
284 | }(_react.Component);
|
285 |
|
286 | Dropdown.propTypes = dropdownPropTypes;
|
287 | Dropdown.defaultProps = dropdownDefaultProps;
|
288 | DropdownMenu.propTypes = dropdownMenuPropTypes;
|
289 | var DropDownWithStyles = (0, _withStyles.withStyles)(function (_ref2) {
|
290 | var color = _ref2.color,
|
291 | units = _ref2.units;
|
292 | return {
|
293 | dropdown: {
|
294 | minWidth: units(1.5),
|
295 | minHeight: units(1.5),
|
296 | display: 'flex',
|
297 | alignItems: 'center',
|
298 | justifyContent: 'center',
|
299 | outline: 'none',
|
300 | cursor: 'pointer',
|
301 | borderWidth: 0,
|
302 | background: color.transparent
|
303 | },
|
304 | dropdown_asAButton: {
|
305 | margin: 0
|
306 | },
|
307 | dropdown_only: {
|
308 | minWidth: units(2.5),
|
309 | height: units(2.5)
|
310 | },
|
311 | dropdown__arrow: {
|
312 | width: units(.5),
|
313 | fill: color.white
|
314 | },
|
315 | dropdown__arrow_leftMarged: {
|
316 | marginLeft: units(.75)
|
317 | },
|
318 | dropdown__arrow_rightMarged: {
|
319 | marginRight: units(.75)
|
320 | },
|
321 | dropdown__arrow_mono: {
|
322 | fill: color.black
|
323 | },
|
324 | dropdown__arrow_primary: {
|
325 | fill: color.primary
|
326 | },
|
327 | dropdown__arrow_secondary: {
|
328 | fill: color.secondary
|
329 | },
|
330 | dropdown_disabled: {
|
331 | opacity: .5,
|
332 | pointerEvents: 'none'
|
333 | },
|
334 | dropdown__container: {
|
335 | display: 'inline-block',
|
336 | boxSizing: 'border-box'
|
337 | },
|
338 | dropdown__container_relative: {
|
339 | position: 'relative'
|
340 | },
|
341 | dropdown__container_asAButton: {
|
342 | marginTop: 0,
|
343 | marginBottom: units(.5)
|
344 | },
|
345 | dropdown__container_noSpacing: {
|
346 | marginBottom: 0
|
347 | },
|
348 | dropdown__list: {
|
349 | margin: 0,
|
350 | padding: 0,
|
351 | listStyle: 'none'
|
352 | },
|
353 | dropdown__list__item: {}
|
354 | };
|
355 | })(Dropdown);
|
356 | var DropdownMenuWithStyles = (0, _withStyles.withStyles)(function (_ref3) {
|
357 | var color = _ref3.color,
|
358 | units = _ref3.units,
|
359 | radius = _ref3.radius;
|
360 | return {
|
361 | dropdownMenu: {
|
362 | position: 'absolute',
|
363 | marginTop: units(.25),
|
364 | top: '100%',
|
365 | backgroundColor: color.white,
|
366 | boxShadow: "0 ".concat(units(0.5), " ").concat(units(0.75), " ").concat(units(-0.45), " ").concat(color.shadow),
|
367 | padding: units(0.5),
|
368 | borderRadius: radius,
|
369 | borderWidth: 1,
|
370 | borderStyle: 'solid',
|
371 | borderColor: color.blueGrayLight,
|
372 | zIndex: 50,
|
373 | opacity: 0.01,
|
374 | transform: 'translate(0, -10%)',
|
375 | transition: 'opacity 200ms ease-out, transform 300ms ease-out'
|
376 | },
|
377 | dropdownMenu_left: {
|
378 | left: 0
|
379 | },
|
380 | dropdownMenu_right: {
|
381 | right: 0
|
382 | },
|
383 | dropdownMenu_insideAButton: {
|
384 | marginRight: units(0.125),
|
385 | marginLeft: units(0.125)
|
386 | },
|
387 |
|
388 | dropdownMenu_entering: {
|
389 | opacity: 1,
|
390 | transform: 'translate(0, 0)',
|
391 | transition: 'opacity 200ms ease-out, transform 300ms ease-out'
|
392 | },
|
393 | dropdownMenu_exiting: {
|
394 | opacity: 0.01,
|
395 | transform: 'translate(0, -10%)',
|
396 | transition: 'opacity 200ms ease-out, transform 300ms ease-out'
|
397 | }
|
398 | };
|
399 | }, {
|
400 | flushBefore: true
|
401 | })(DropdownMenu);
|
402 | var _default = DropDownWithStyles;
|
403 | exports.default = _default; |
\ | No newline at end of file |