-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
203 lines (188 loc) · 5.98 KB
/
Copy pathindex.html
File metadata and controls
203 lines (188 loc) · 5.98 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'sha256-fgxmLOznNmVf4GAd24jy5Eiv/Rer+7sVLOBqnsVx0nY='; script-src 'self' 'sha256-cPRnZP+O4z5KsN+vdFstQwgKExGtoN98I3Gq+Tm1aSA='; object-src 'none'; base-uri 'self'; upgrade-insecure-requests;">
<meta name="referrer" content="no-referrer">
<title>5ive - UX Sample</title>
<style>
body {
font-family: system-ui, -apple-system, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f9fafb;
}
.container {
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
text-align: center;
}
/* Good UX: Clear focus styles for keyboard users */
button:focus-visible {
outline: 2px solid #2563eb;
outline-offset: 2px;
}
.btn {
background-color: #2563eb;
color: white;
padding: 0.5rem 1rem;
border-radius: 0.375rem;
border: none;
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s;
}
.btn:hover {
background-color: #1d4ed8;
}
.btn:active {
background-color: #1e40af;
}
.btn:disabled {
opacity: 0.7;
cursor: not-allowed;
}
.spinner {
display: inline-block;
width: 1em;
height: 1em;
border: 2px solid currentColor;
border-right-color: transparent;
border-radius: 50%;
animation: spin 0.75s linear infinite;
vertical-align: text-bottom;
margin-right: 0.5rem;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.feedback {
margin-top: 1rem;
min-height: 1.5rem; /* Prevents layout shift */
color: #15803d; /* green-700, good contrast on white */
font-weight: 500;
font-size: 0.9rem;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
.feedback.visible {
opacity: 1;
}
.success-icon {
color: #16a34a;
margin-right: 0.5rem;
font-size: 1.1rem;
}
.close-btn {
background: transparent;
border: none;
color: inherit;
margin-left: 0.5rem;
cursor: pointer;
padding: 0 0.25rem;
font-size: 1.2rem;
line-height: 1;
border-radius: 4px;
}
.close-btn:hover {
background-color: rgba(0, 0, 0, 0.05);
}
.feedback-content {
display: flex;
align-items: center;
}
</style>
</head>
<body>
<main class="container">
<h1>Welcome to 5ive</h1>
<p>Sample accessible button component:</p>
<!-- ✅ GOOD UX: Semantic button with proper labeling and focus handling -->
<button type="button" class="btn" id="action-btn">
Click Me (Accessible)
</button>
<div id="feedback" class="feedback" aria-live="polite"></div>
<p><small>Try navigating to this button using the 'Tab' key.</small></p>
</main>
<script>
const actionBtn = document.getElementById('action-btn');
const feedback = document.getElementById('feedback');
let feedbackTimeout;
actionBtn.addEventListener('click', () => {
// Clear any existing timeout
if (feedbackTimeout) clearTimeout(feedbackTimeout);
// Reset feedback visual state
feedback.classList.remove('visible');
feedback.textContent = '';
// Set loading state
// ✅ Sentinel: Avoid innerHTML to prevent XSS
const originalText = actionBtn.textContent;
actionBtn.disabled = true;
actionBtn.setAttribute('aria-busy', 'true');
actionBtn.textContent = '';
const spinner = document.createElement('span');
spinner.className = 'spinner';
spinner.setAttribute('aria-hidden', 'true');
actionBtn.appendChild(spinner);
actionBtn.appendChild(document.createTextNode('Loading...'));
// Simulate async operation
setTimeout(() => {
// Reset state
actionBtn.disabled = false;
actionBtn.removeAttribute('aria-busy');
actionBtn.textContent = originalText;
// Show success with icon and transition
// ✅ Sentinel: Using textContent and DOM methods instead of innerHTML
feedback.textContent = '';
const content = document.createElement('span');
content.className = 'feedback-content';
const icon = document.createElement('span');
icon.className = 'success-icon';
icon.setAttribute('aria-hidden', 'true');
icon.textContent = '✔';
content.appendChild(icon);
content.appendChild(document.createTextNode(' Action triggered successfully!'));
feedback.appendChild(content);
const closeBtn = document.createElement('button');
closeBtn.className = 'close-btn';
closeBtn.setAttribute('aria-label', 'Close notification');
closeBtn.textContent = '×';
closeBtn.onclick = () => {
if (feedbackTimeout) clearTimeout(feedbackTimeout);
feedback.classList.remove('visible');
setTimeout(() => {
if (!feedback.classList.contains('visible')) {
feedback.textContent = '';
}
}, 300);
};
feedback.appendChild(closeBtn);
// Trigger reflow/transition
requestAnimationFrame(() => {
feedback.classList.add('visible');
});
// Clear message after 5 seconds
feedbackTimeout = setTimeout(() => {
feedback.classList.remove('visible');
// Wait for transition to finish
setTimeout(() => {
if (!feedback.classList.contains('visible')) {
feedback.textContent = '';
}
}, 300);
}, 5000);
}, 1500);
});
</script>
</body>
</html>