-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathalert-inline.js
72 lines (66 loc) · 2.24 KB
/
alert-inline.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { later } from '@ember/runloop';
import { tracked } from '@glimmer/tracking';
import { assert } from '@ember/debug';
/**
* @deprecated
* @module AlertInline
* This component renders a compact Hds::Alert that displays a loading icon if the
* `@message` arg changes and then re-renders the updated `@message` text.
* (Example: submitting a form and displaying the number of errors because on re-submit the number may change)
*
* @example
* <AlertInline @type="danger" @message="There are 2 errors with this form."/>
*
* * use Hds::Alert @type="compact" for displaying alert messages instead
* <Hds::Alert @type="compact" @color="critical" as |A|>
* <A.Title>Error</A.Title>
* <A.Description>Something is not right</A.Description>
* </Hds::Alert>
*
* @param {string} type - color getter maps type to the Hds::Alert @color
* @param {string} color - Styles alert color and icon, can be one of: critical, warning, success, highlight, neutral
* @param {string} message - The message to display within the alert.
*/
export default class AlertInlineComponent extends Component {
@tracked isRefreshing = false;
constructor() {
super(...arguments);
assert('@type arg is deprecated, pass @color="critical" instead', this.args.type !== 'critical');
if (this.args.color) {
const possibleColors = ['critical', 'warning', 'success', 'highlight', 'neutral'];
assert(
`${this.args.color} is not a valid color. @color must be one of: ${possibleColors.join(', ')}`,
possibleColors.includes(this.args.color)
);
}
}
get color() {
if (this.args.color) return this.args.color;
// @type arg is deprecated, this is for backward compatibility of old implementation
switch (this.args.type) {
case 'danger':
return 'critical';
case 'success':
return 'success';
case 'warning':
return 'warning';
case 'info':
return 'highlight';
default:
return 'neutral';
}
}
@action
refresh() {
this.isRefreshing = true;
later(() => {
this.isRefreshing = false;
}, 200);
}
}