UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

126 lines (125 loc) 4.34 kB
/** * DevExtreme (esm/__internal/ui/informer/informer.js) * Version: 25.1.3 * Build date: Wed Jun 25 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import _extends from "@babel/runtime/helpers/esm/extends"; import registerComponent from "../../../core/component_registrator"; import $ from "../../../core/renderer"; import { getImageContainer } from "../../core/utils/m_icon"; import Widget from "../../core/widget/widget"; export const INFORMER_CLASS = "dx-informer"; const INFORMER_ERROR_CLASS = "dx-informer-error"; const INFORMER_INFO_CLASS = "dx-informer-info"; const INFORMER_ALIGNMENT_START_CLASS = "dx-informer-alignment-start"; const INFORMER_ALIGNMENT_CENTER_CLASS = "dx-informer-alignment-center"; const INFORMER_ALIGNMENT_END_CLASS = "dx-informer-alignment-end"; const INFORMER_BG_CLASS = "dx-informer-bg"; const INFORMER_TEXT_CLASS = "dx-informer-text"; const INFORMER_ICON_CLASS = "dx-informer-icon"; class Informer extends Widget { _getDefaultOptions() { return _extends({}, super._getDefaultOptions(), { contentAlignment: "center", icon: "", showBackground: true, text: "", type: "error" }) } _initMarkup() { const { showBackground: showBackground } = this.option(); this.$element().addClass("dx-informer"); this.$element().toggleClass("dx-informer-bg", showBackground); this._setAlignmentClass(); this._setTypeClass(); super._initMarkup(); this._renderIcon(); this._renderText() } _setAlignmentClass() { this.$element().removeClass("dx-informer-alignment-start").removeClass("dx-informer-alignment-center").removeClass("dx-informer-alignment-end"); const { contentAlignment: contentAlignment } = this.option(); switch (contentAlignment) { case "start": this.$element().addClass("dx-informer-alignment-start"); break; case "end": this.$element().addClass("dx-informer-alignment-end"); break; default: this.$element().addClass("dx-informer-alignment-center") } } _setTypeClass() { this.$element().removeClass("dx-informer-error").removeClass("dx-informer-info"); const { type: type } = this.option(); if ("info" === type) { this.$element().addClass("dx-informer-info") } else { this.$element().addClass("dx-informer-error") } } _renderIcon() { var _this$_$icon; null === (_this$_$icon = this._$icon) || void 0 === _this$_$icon || _this$_$icon.remove(); const { icon: icon } = this.option(); const $icon = getImageContainer(icon); if (!$icon) { return } this._$icon = $("<div>").addClass("dx-informer-icon").prependTo(this.$element()).append($icon) } _renderText() { const { text: text = "" } = this.option(); this._$text = $("<div>").addClass("dx-informer-text").appendTo(this.$element()).text(text) } _updateText() { const { text: text = "" } = this.option(); this._$text.text(text) } _optionChanged(args) { const { name: name, value: value } = args; switch (name) { case "icon": this._renderIcon(); break; case "contentAlignment": this._setAlignmentClass(); break; case "showBackground": this.$element().toggleClass("dx-informer-bg", value); break; case "text": this._updateText(); break; case "type": this._setTypeClass(); break; default: super._optionChanged(args) } } } registerComponent("dxInformer", Informer); export default Informer;