Skip to content

Commit 1b8e9d8

Browse files
committed
add warning toast
1 parent f153397 commit 1b8e9d8

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

templates/devtest/gitea-ui.tmpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,18 @@
232232
<h1>Toast</h1>
233233
<div>
234234
<button class="ui button" id="info-toast">Show Info Toast</button>
235+
<button class="ui button" id="warning-toast">Show Warning Toast</button>
235236
<button class="ui button" id="error-toast">Show Error Toast</button>
236237
</div>
237238
<script>
238239
document.getElementById('info-toast').addEventListener('click', () => {
239-
window.giteaShowInfo('success :)');
240+
window.giteaShowInfo('success 😀');
241+
});
242+
document.getElementById('warning-toast').addEventListener('click', () => {
243+
window.giteaShowWarning('warning 😐');
240244
});
241245
document.getElementById('error-toast').addEventListener('click', () => {
242-
window.giteaShowError('error :(');
246+
window.giteaShowError('error 🙁');
243247
});
244248
</script>
245249
</div>

web_src/js/modules/toast.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const levels = {
77
background: 'var(--color-green)',
88
duration: 2000,
99
},
10+
warning: {
11+
icon: 'gitea-exclamation',
12+
background: 'var(--color-orange)',
13+
duration: -1, // needs to be clicked away
14+
},
1015
error: {
1116
icon: 'gitea-exclamation',
1217
background: 'var(--color-red)',
@@ -47,12 +52,17 @@ export async function showInfo(message, opts) {
4752
return await showToast(message, 'info', opts);
4853
}
4954

55+
export async function showWarning(message, opts) {
56+
return await showToast(message, 'warning', opts);
57+
}
58+
5059
export async function showError(message, opts) {
5160
return await showToast(message, 'error', opts);
5261
}
5362

5463
// export for devtest page in development
5564
if (process.env.NODE_ENV === 'development') {
5665
window.giteaShowInfo = showInfo;
66+
window.giteaShowWarning = showWarning;
5767
window.giteaShowError = showError;
5868
}

web_src/js/modules/toast.test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import {test, expect} from 'vitest';
2-
import {showInfo, showError} from './toast.js';
2+
import {showInfo, showError, showWarning} from './toast.js';
33

44
test('showInfo', async () => {
5-
await showInfo('success :)', {duration: -1});
5+
await showInfo('success 😀', {duration: -1});
6+
expect(document.querySelector('.toastify')).toBeTruthy();
7+
});
8+
9+
test('showWarning', async () => {
10+
await showWarning('success 😐', {duration: -1});
611
expect(document.querySelector('.toastify')).toBeTruthy();
712
});
813

914
test('showError', async () => {
10-
await showError('error :(', {duration: -1});
15+
await showError('error 🙁', {duration: -1});
1116
expect(document.querySelector('.toastify')).toBeTruthy();
1217
});

0 commit comments

Comments
 (0)