2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-25 18:22:36 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
import { later } from '@ember/runloop';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
2019-05-13 19:05:25 +00:00
|
|
|
import { messageTypes } from 'core/helpers/message-types';
|
2018-11-02 16:02:45 +00:00
|
|
|
|
2019-04-03 21:06:20 +00:00
|
|
|
/**
|
|
|
|
* @module AlertInline
|
|
|
|
* `AlertInline` components are used to inform users of important messages.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* <AlertInline @type="danger" @message="{{model.keyId}} is not a valid lease ID"/>
|
|
|
|
* ```
|
|
|
|
*
|
2022-09-09 01:06:05 +00:00
|
|
|
* @param {string} type=null - The alert type passed to the message-types helper.
|
|
|
|
* @param {string} [message=null] - The message to display within the alert.
|
|
|
|
* @param {boolean} [paddingTop=false] - Whether or not to add padding above component.
|
|
|
|
* @param {boolean} [isMarginless=false] - Whether or not to remove margin bottom below component.
|
|
|
|
* @param {boolean} [sizeSmall=false] - Whether or not to display a small font with padding below of alert message.
|
|
|
|
* @param {boolean} [mimicRefresh=false] - If true will display a loading icon when attributes change (e.g. when a form submits and the alert message changes).
|
2019-04-03 21:06:20 +00:00
|
|
|
*/
|
|
|
|
|
2022-05-25 18:22:36 +00:00
|
|
|
export default class AlertInlineComponent extends Component {
|
|
|
|
@tracked isRefreshing = false;
|
|
|
|
|
|
|
|
get mimicRefresh() {
|
|
|
|
return this.args.mimicRefresh || false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get paddingTop() {
|
|
|
|
return this.args.paddingTop ? ' padding-top' : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
get isMarginless() {
|
|
|
|
return this.args.isMarginless ? ' is-marginless' : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
get sizeSmall() {
|
|
|
|
return this.args.sizeSmall ? ' size-small' : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
get textClass() {
|
|
|
|
if (this.args.type === 'danger') {
|
|
|
|
return this.alertType.glyphClass;
|
2018-11-02 16:02:45 +00:00
|
|
|
}
|
2022-05-25 18:22:36 +00:00
|
|
|
return null;
|
|
|
|
}
|
2018-11-02 16:02:45 +00:00
|
|
|
|
2022-05-25 18:22:36 +00:00
|
|
|
get alertType() {
|
|
|
|
return messageTypes([this.args.type]);
|
|
|
|
}
|
2018-11-02 16:02:45 +00:00
|
|
|
|
2022-05-25 18:22:36 +00:00
|
|
|
@action
|
|
|
|
refresh() {
|
|
|
|
if (this.mimicRefresh) {
|
|
|
|
this.isRefreshing = true;
|
|
|
|
later(() => {
|
|
|
|
this.isRefreshing = false;
|
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|