UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

248 lines (246 loc) • 8.27 kB
/** * DevExtreme (cjs/__internal/ui/speed_dial_action/speed_dial_item.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _click = require("../../../common/core/events/click"); var _events_engine = _interopRequireDefault(require("../../../common/core/events/core/events_engine")); var _index = require("../../../common/core/events/utils/index"); var _renderer = _interopRequireDefault(require("../../../core/renderer")); var _icon = require("../../../core/utils/icon"); var _themes = require("../../../ui/themes"); var _ink_ripple = require("../../core/utils/ink_ripple"); var _overlay = _interopRequireDefault(require("../../ui/overlay/overlay")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const FAB_CLASS = "dx-fa-button"; const FAB_ICON_CLASS = "dx-fa-button-icon"; const FAB_LABEL_CLASS = "dx-fa-button-label"; const FAB_LABEL_WRAPPER_CLASS = "dx-fa-button-label-wrapper"; const FAB_CONTENT_REVERSE_CLASS = "dx-fa-button-content-reverse"; const OVERLAY_CONTENT_SELECTOR = ".dx-overlay-content"; class SpeedDialItem extends _overlay.default { _getDefaultOptions() { return Object.assign({}, super._getDefaultOptions(), { shading: false, useInkRipple: false, callOverlayRenderShading: false, width: "auto", zIndex: 1500, _observeContentResize: false }) } _defaultOptionsRules() { return super._defaultOptionsRules().concat([{ device: () => (0, _themes.isMaterial)((0, _themes.current)()), options: { useInkRipple: true } }]) } _moveToContainer() { this._$wrapper.appendTo(this.$element()); this._$content.appendTo(this._$wrapper) } _render() { this.$element().addClass(FAB_CLASS); this._renderIcon(); this._renderLabel(); super._render(); const { useInkRipple: useInkRipple } = this.option(); if (useInkRipple) { this._renderInkRipple() } this._renderClick() } _renderLabel() { if (this._$label) { this._$label.remove() } const { label: label } = this.option(); if (!label) { this._$label = null; return } const $element = (0, _renderer.default)("<div>").addClass(FAB_LABEL_CLASS); const $wrapper = (0, _renderer.default)("<div>").addClass(FAB_LABEL_WRAPPER_CLASS); const $content = this.$content(); if ($content) { this._$label = $wrapper.prependTo($content).append($element.text(label)); const { parentPosition: parentPosition } = this.option(); $content.toggleClass(FAB_CONTENT_REVERSE_CLASS, this._isPositionLeft(parentPosition)) } } _isPositionLeft(position) { let currentLocation = ""; if (position) { if ("string" === typeof position) { currentLocation = position } else if ("function" !== typeof position && position.at) { const { at: at } = position; if ("string" !== typeof at && at.x) { currentLocation = at.x } else if ("string" === typeof at) { currentLocation = at } } } return "left" === currentLocation.split(" ")[0] } _renderButtonIcon($element, icon, iconClass) { null === $element || void 0 === $element || $element.remove(); const $updatedElement = (0, _renderer.default)("<div>").addClass(iconClass); const $iconElement = (0, _icon.getImageContainer)(icon); if ($iconElement) { $updatedElement.append($iconElement) } const $content = this.$content(); if ($content) { $updatedElement.appendTo($content) } return $updatedElement } _renderIcon() { this._$icon = this._renderButtonIcon(this._$icon, this._options.silent("icon"), FAB_ICON_CLASS) } _renderWrapper() { if (this._options.silent("callOverlayRenderShading")) { super._renderWrapper() } } _getVisibleActions(actions) { const { actions: ownActions } = this.option(); const currentActions = actions ?? ownActions ?? []; return currentActions.filter(action => { const { visible: visible = false } = action.option(); return visible }) } _getActionComponent() { const visibleActions = this._getVisibleActions(); if (1 === visibleActions.length) { return visibleActions[0] } const { actionComponent: actionComponent, actions: actions = [] } = this.option(); return actionComponent ?? actions[0] } _initContentReadyAction() { this._contentReadyAction = this._getActionComponent()._createActionByOption("onContentReady", { excludeValidators: ["disabled", "readOnly"] }) } _fireContentReadyAction() { var _this$_contentReadyAc; null === (_this$_contentReadyAc = this._contentReadyAction) || void 0 === _this$_contentReadyAc || _this$_contentReadyAc.call(this, { actionElement: this.$element() }) } _updateZIndexStackPosition() { const { zIndex: zIndex } = this.option(); this._$wrapper.css("zIndex", zIndex); this._$content.css("zIndex", zIndex) } _setClickAction() { const eventName = (0, _index.addNamespace)(_click.name, this.NAME); const overlayContent = this.$element().find(".dx-overlay-content"); _events_engine.default.off(overlayContent, eventName); _events_engine.default.on(overlayContent, eventName, e => { const clickActionArgs = { event: e, actionElement: this.element(), element: this._getActionComponent().$element() }; this._clickAction(clickActionArgs) }) } _defaultActionArgs() { return { component: this._getActionComponent() } } _renderClick() { this._clickAction = this._getActionComponent()._createActionByOption("onClick"); this._setClickAction() } _renderInkRipple() { this._inkRipple = (0, _ink_ripple.render)() } _getInkRippleContainer() { return this._$icon } _toggleActiveState($element, value, event) { super._toggleActiveState($element, value, event); if (!this._inkRipple) { return } const config = { element: this._getInkRippleContainer(), event: event }; if (value) { this._inkRipple.showWave(config) } else { this._inkRipple.hideWave(config) } } _optionChanged(args) { const { name: name, value: value, previousValue: previousValue } = args; switch (name) { case "icon": this._renderIcon(); break; case "onClick": this._renderClick(); break; case "label": this._renderLabel(); break; case "visible": this._currentVisible = previousValue; if (value) { this._show() } else { this._hide() } break; case "useInkRipple": this._render(); break; default: super._optionChanged(args) } } } var _default = exports.default = SpeedDialItem;