123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- define(['react', 'react-dom', './IconPickerComponent'], function (React, ReactDOM, IconPickerComponent) {
-
- var IconPicker = function () {
-
- function IconPicker(options) {
- _classCallCheck(this, IconPicker);
- this._icons = options.icons;
- this._containerNode = options.containerNode || document.body;
- this._onIconSelectedCallback = options.onIconSelected;
- this._onCloseCallback = options.onClose;
- this._flyoutHolderNode = null;
- this._handleIconSelected = this._handleIconSelected.bind(this);
- this.close = this.close.bind(this);
- }
-
- IconPicker.prototype.open = function open(triggerNode) {
- var _this = this;
- if (this.isOpen()) {
-
- return Promise.resolve();
- }
- return new Promise(function (resolve) {
- _this._flyoutHolderNode = document.createElement('div');
- _this._flyoutHolderNode.classList.add('flyout-holder');
- _this._containerNode.appendChild(_this._flyoutHolderNode);
- ReactDOM.render(React.createElement(IconPickerComponent, {
- icons: _this._icons,
- onIconSelected: _this._handleIconSelected,
- onClose: _this.close,
- orientation: 'bottomLeft',
- triggerNode: triggerNode,
- domNodeToAttachTo: _this._containerNode
- }), _this._flyoutHolderNode, function () {
- resolve();
- });
- });
- };
-
- IconPicker.prototype.isOpen = function isOpen() {
- return this._flyoutHolderNode != null;
- };
-
- IconPicker.prototype.close = function close() {
- if (this._onCloseCallback) {
- this._onCloseCallback();
- }
- this.destroy();
- };
-
- IconPicker.prototype.destroy = function destroy() {
- if (this._flyoutHolderNode) {
- ReactDOM.unmountComponentAtNode(this._flyoutHolderNode);
- this._containerNode.removeChild(this._flyoutHolderNode);
- this._flyoutHolderNode = null;
- }
- };
- IconPicker.prototype._handleIconSelected = function _handleIconSelected(icon) {
- if (this._onIconSelectedCallback) {
- this._onIconSelectedCallback(icon);
- }
- this.close();
- };
- return IconPicker;
- }();
- return IconPicker;
- });
|