Skip to content

Commit 06a852d

Browse files
committed
Document snackbars
Closes #499
1 parent 99b245f commit 06a852d

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Snackbar
2+
3+
Snackbars show short notifications about user interactions at the bottom of the screen.
4+
5+
## Success Snackbar
6+
7+
Success snackbars indicate that an action initiated by the user has been successfully completed.
8+
The message disappears automatically after 3 seconds.
9+
10+
### Examples
11+
12+
Display the success snackbar with the standard message:
13+
14+
```ts
15+
import { showDefaultSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
16+
17+
showDefaultSuccessSnackbar();
18+
```
19+
20+
Display the success snackbar with your a custom message:
21+
22+
```ts
23+
import { showSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
24+
import { getPhrase } from "WoltLabSuite/Core/Language";
25+
26+
showSuccessSnackbar(getPhrase('custom.success.message'));
27+
```
28+
29+
Use an event to perform an action after the snackbar has been closed:
30+
31+
```ts
32+
import { showDefaultSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
33+
34+
showDefaultSuccessSnackbar().addEventListener("snackbar:close", () => {
35+
// perform an action
36+
});
37+
```
38+
39+
## Progress Snackbar
40+
41+
Progress snackbars show the progress of an action that was initiated by the user and is executed in several individual steps.
42+
Once the action has been completed, a progress snackbar automatically becomes a success snackbar.
43+
44+
### Examples
45+
46+
```ts
47+
import { showProgressSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
48+
49+
const snackbar = showProgressSnackbar('label', 10);
50+
51+
for (let i = 0; i < 10; i++) {
52+
// perform one step of an action
53+
54+
snackbar.setIteration(i + 1);
55+
}
56+
57+
snackbar.markAsDone();
58+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ nav:
7070
- 'Notices': 'javascript/components_notice.md'
7171
- 'Pagination': 'javascript/components_pagination.md'
7272
- 'RPC API': 'javascript/components_rpc_api.md'
73+
- 'Snackbar': 'javascript/components_snackbar.md'
7374
- 'Toggle Button': 'javascript/components_toggle_button.md'
7475
- 'New API':
7576
- 'Writing a module': 'javascript/new-api_writing-a-module.md'

0 commit comments

Comments
 (0)