All Downloads are FREE. Search and download functionalities are using the official Maven repository.

theme.keycloak.v2.account.resources.content.ContentAlert.js Maven / Gradle / Ivy

There is a newer version: 26.0.7
Show newest version
var _class;
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
/*
 * Copyright 2019 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import * as React from "../../keycloak.v2/web_modules/react.js";
import { Alert, AlertActionCloseButton, AlertGroup, AlertVariant } from "../../keycloak.v2/web_modules/@patternfly/react-core.js";
import { Msg } from "../widgets/Msg.js";
export class ContentAlert extends React.Component {
  constructor(props) {
    super(props);
    _defineProperty(this, "hideAlert", key => {
      this.setState({
        alerts: [...this.state.alerts.filter(el => el.key !== key)]
      });
    });
    _defineProperty(this, "getUniqueId", () => new Date().getTime());
    _defineProperty(this, "postAlert", (variant, message, params) => {
      const alerts = this.state.alerts;
      const key = this.getUniqueId();
      alerts.push({
        key,
        message: Msg.localize(message, params),
        variant
      });
      this.setState({
        alerts
      });
      if (variant !== AlertVariant.danger) {
        setTimeout(() => this.hideAlert(key), 8000);
      }
    });
    this.state = {
      alerts: []
    };
    ContentAlert.instance = this;
  }

  /**
   * @param message A literal text message or localization key.
   */
  static success(message, params) {
    ContentAlert.instance.postAlert(AlertVariant.success, message, params);
  }

  /**
   * @param message A literal text message or localization key.
   */
  static danger(message, params) {
    ContentAlert.instance.postAlert(AlertVariant.danger, message, params);
  }

  /**
   * @param message A literal text message or localization key.
   */
  static warning(message, params) {
    ContentAlert.instance.postAlert(AlertVariant.warning, message, params);
  }

  /**
   * @param message A literal text message or localization key.
   */
  static info(message, params) {
    ContentAlert.instance.postAlert(AlertVariant.info, message, params);
  }
  render() {
    return /*#__PURE__*/React.createElement(AlertGroup, {
      isToast: true,
      "aria-live": "assertive"
    }, this.state.alerts.map(({
      key,
      variant,
      message
    }) => /*#__PURE__*/React.createElement(Alert, {
      "aria-details": message,
      isLiveRegion: true,
      variant: variant,
      title: message,
      actionClose: /*#__PURE__*/React.createElement(AlertActionCloseButton, {
        title: message,
        variantLabel: `${variant} alert`,
        onClose: () => this.hideAlert(key)
      }),
      key: key
    })));
  }
}
_class = ContentAlert;
_defineProperty(ContentAlert, "instance", void 0);
//# sourceMappingURL=ContentAlert.js.map




© 2015 - 2025 Weber Informatics LLC | Privacy Policy