UNPKG

@enact/ui

Version:

A collection of simplified unstyled cross-platform UI components for Enact

65 lines (64 loc) 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.FloatingLayerContainer = void 0; var _Registry = _interopRequireDefault(require("@enact/core/internal/Registry")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var FloatingLayerContainer = exports.FloatingLayerContainer = /*#__PURE__*/function () { function FloatingLayerContainer(config) { var _this = this; _classCallCheck(this, FloatingLayerContainer); this.getFloatingLayer = function () { // FIXME: if a component that resides in the floating layer is rendered at the same time // as the floating layer, this.floatingLayer may not have been initialized yet since // componentDidMount runs inside-out. As a fallback, we search by id but this could // introduce issues (e.g. for duplicate layer ids). return _this.floatingLayer || typeof document !== 'undefined' && document.getElementById(_this.config.floatLayerId) || null; }; this.handleNotify = function (_ref) { var action = _ref.action; if (action === 'register') { _this.notifyMount(); } else if (action === 'closeAll') { _this.handleCloseAll(); } }; this.setFloatingLayer = function (node) { _this.floatingLayer = node; }; var floatLayerId = config.floatLayerId; this.registry = _Registry["default"].create(this.handleNotify); this.floatingLayer = null; this.config = { floatLayerId: floatLayerId }; } return _createClass(FloatingLayerContainer, [{ key: "load", value: function load() { this.notifyMount(); } }, { key: "handleCloseAll", value: function handleCloseAll() { this.registry.notify({ action: 'close' }); } }, { key: "notifyMount", value: function notifyMount() { this.registry.notify({ action: 'mount', floatingLayer: this.getFloatingLayer() }); } }]); }(); var _default = exports["default"] = FloatingLayerContainer;