1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var react_malibu_1 = require("@heroku/react-malibu");
|
14 | var classnames_1 = require("classnames");
|
15 | var React = require("react");
|
16 | var HKButton_1 = require("./HKButton");
|
17 | var Align;
|
18 | (function (Align) {
|
19 | Align["Left"] = "left";
|
20 | Align["Right"] = "right";
|
21 | })(Align = exports.Align || (exports.Align = {}));
|
22 | var HKDropdown = (function (_super) {
|
23 | __extends(HKDropdown, _super);
|
24 | function HKDropdown() {
|
25 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
26 | _this.state = {
|
27 | showDropdown: false,
|
28 | };
|
29 | _this.handleDropdown = function () { return _this.setState(function (prevState) { return ({ showDropdown: !prevState.showDropdown }); }); };
|
30 | _this.handleContentClick = function () { return _this.props.closeOnClick && _this.setState({ showDropdown: false }); };
|
31 | return _this;
|
32 | }
|
33 | HKDropdown.prototype.render = function () {
|
34 | var _a = this.props, align = _a.align, children = _a.children, className = _a.className, contentClassName = _a.contentClassName, disabled = _a.disabled, title = _a.title;
|
35 | var showDropdown = this.state.showDropdown;
|
36 | var alignDropdown = align ? "hk-dropdown--" + align : "hk-dropdown";
|
37 | return (React.createElement("div", { className: 'relative dib' },
|
38 | React.createElement(HKButton_1.default, { className: classnames_1.default({ ph1: !title }, className), type: HKButton_1.Type.Secondary, disabled: disabled, onClick: this.handleDropdown },
|
39 | title,
|
40 | React.createElement(react_malibu_1.MalibuIcon, { key: 'icon', name: 'caret-16', size: 16, fillClass: 'fill-purple', extraClasses: classnames_1.default({ pl1: title }) })),
|
41 | React.createElement("div", { onClick: this.handleContentClick }, showDropdown &&
|
42 | (React.createElement("ul", { className: classnames_1.default(alignDropdown, contentClassName) }, children)))));
|
43 | };
|
44 | HKDropdown.defaultProps = {
|
45 | closeOnClick: true,
|
46 | disabled: false,
|
47 | };
|
48 | return HKDropdown;
|
49 | }(React.Component));
|
50 | exports.default = HKDropdown;
|
51 |
|
\ | No newline at end of file |