-
Notifications
You must be signed in to change notification settings - Fork 1
/
alert.html
129 lines (116 loc) · 5.47 KB
/
alert.html
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>alert</title>
<script type="module" src="https://js.arcgis.com/calcite-components/1.0.0-beta.91/calcite.esm.js"></script>
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/calcite-components/1.0.0-beta.91/calcite.css" />
<style>
h1 {
margin-bottom: 5rem;
}
li,
ol {
margin-bottom: 2rem;
}
calcite-button {
margin: 2rem;
}
body {
font-family: var(--calcite-sans-family);
font-size: var(--calcite-font-size-0);
color: var(--calcite-ui-text-1);
max-width: 1024px;
min-width: 280px;
width: 70vw;
padding: 0 var(--calcite-spacing-double);
margin: 0 auto;
background-color: var(--calcite-ui-background);
}
main {
padding-top: 5vh;
}
/* Theme Switcher */
#theme-label {
position: fixed;
top: 20px;
right: 20px;
z-index: 2;
background-color: var(--calcite-ui-background);
border: 1px solid;
border-color: var(--calcite-ui-border-1);
border-radius: var(--calcite-border-radius);
margin: 0;
padding: 10px;
}
#theme-label label {
margin: 0;
}
</style>
</head>
<body>
<main>
<h1><code>alert</code></h1>
<ol>
<li>Trigger each button to display a different alert.</li>
<li>The "fast", "medium", and "slow" duration alerts are time-specific. Each will dismiss on a set time with the fast duration dismissing the fastest and the slow duration dismissing the slowest.</li>
<li>The "no duration" alert will remain open unless a different button is trigger or the alert is dismissed by the user.</li>
</ol>
<!-- calcite-switch -->
<div id="theme-label">
<calcite-label layout="inline">
Toggle theme
<calcite-switch id="theme-switch"></calcite-switch>
</calcite-label>
</div>
<!-- 1. with label, auto-dismiss-duration: fast, color: red -->
<calcite-button label="Enable the fast duration alert" onkeypress="triggerAnimation(event, 'fast')" onclick="triggerAnimation(event, 'fast')">Fast duration</calcite-button>
<calcite-alert id="fast" label="Fast alert" auto-dismiss auto-dismiss-duration="fast" color="red" icon="exclamation-mark-triangle" intl-close="Close" scale="m">
<div slot="title">Fast dismiss alert</div>
<div slot="message">This message will disappear at a fast speed.</div>
</calcite-alert>
<!-- 2. no label, auto-dismiss-duration: medium, color: yellow -->
<calcite-button label="Enable the medium duration alert" onkeypress="triggerAnimation(event, 'medium')" onclick="triggerAnimation(event, 'medium')">Medium duration</calcite-button>
<calcite-alert id="medium" auto-dismiss auto-dismiss-duration="medium" color="yellow" icon="exclamation-mark-triangle" intl-close="Close" scale="m">
<div slot="title">Medium dismiss alert</div>
<div slot="message">This message will disappear at a medium speed.</div>
</calcite-alert>
<!-- 3. no label, auto-dismiss-duration: slow, color: green, scale: small -->
<calcite-button label="Enable the slow duration alert" onkeypress="triggerAnimation(event, 'slow')" onclick="triggerAnimation(event, 'slow')">Slow duration</calcite-button>
<calcite-alert id="slow" auto-dismiss auto-dismiss-duration="slow" color="green" icon="exclamation-mark-triangle" intl-close="Close" scale="s">
<div slot="title">Slow dismiss alert</div>
<div slot="message">This message will disappear at a slow speed.</div>
</calcite-alert>
<!-- 4. with label, user only dismissed, color: blue -->
<calcite-button label="Enable the alert with no duration, which closes only when accessing the close button." onkeypress="triggerAnimation(event, 'none')" onclick="triggerAnimation(event, 'none')">No duration</calcite-button>
<calcite-alert id="none" label="User dismissed alert" color="blue" icon="exclamation-mark-triangle" intl-close="Close" scale="m">
<div slot="title">No duration alert</div>
<div slot="message">This message will disappear when selecting a different duration, or when the user closes it. There is no time limit associated with this alert.</div>
</calcite-alert>
</main>
</body>
<script>
window.onload = () => {
// Theme Switcher
const themeSwitch = document.getElementById("theme-switch");
themeSwitch.addEventListener("calciteSwitchChange", () => {
document.body.classList.toggle("calcite-theme-dark");
});
};
// On button click, enable the calcite alert
const triggerAnimation = (event, animationName) => {
if (event.type === 'click' || event.type === 'keypress' && event.keyCode === '13' || event.type === 'keypress' && event.keyCode === '32') {
// Remove all active calcite alerts
document.querySelectorAll('calcite-alert').forEach(node => node.active = false)
// Activate selected calcite alert
const noticeEl = document.querySelector(`#${animationName}`);
const noticePreEl = document.querySelector(`#${animationName} pre`);
if (!noticeEl.hasAttribute("active")) {
noticeEl.setAttribute("active", "");
}
noticeEl.classList.add(`calcite-animate__${animationName}`);
}
};
</script>
</html>