File tree 3 files changed +20
-12
lines changed 3 files changed +20
-12
lines changed Original file line number Diff line number Diff line change 3
3
<div>
4
4
<h1>Toast</h1>
5
5
<div>
6
- <button class="ui button" id="info-toast">Show Info Toast</button>
7
- <button class="ui button" id="warning-toast">Show Warning Toast</button>
8
- <button class="ui button" id="error-toast">Show Error Toast</button>
6
+ <button class="ui button toast-test-button" data-toast-level="info" data-toast-message="test info">Show Info Toast</button>
7
+ <button class="ui button toast-test-button" data-toast-level="warning" data-toast-message="test warning">Show Warning Toast</button>
8
+ <button class="ui button toast-test-button" data-toast-level="error" data-toast-message="test error">Show Error Toast</button>
9
+ <button class="ui button toast-test-button" data-toast-level="error" data-toast-message="test error (another)">Show Error Toast (another)</button>
9
10
</div>
10
11
</div>
11
12
Original file line number Diff line number Diff line change 35
35
align-items : center;
36
36
}
37
37
38
+ .toast-icon svg {
39
+ width : 30px ;
40
+ }
41
+
38
42
.toast-duplicate-number ::before {
39
43
content : "(" ;
40
44
}
Original file line number Diff line number Diff line change 1
1
import { showInfoToast , showWarningToast , showErrorToast } from '../modules/toast.js' ;
2
2
3
- document . querySelector ( '#info-toast' ) . addEventListener ( 'click' , ( ) => {
4
- showInfoToast ( 'success 😀' ) ;
5
- } ) ;
6
- document . querySelector ( '#warning-toast' ) . addEventListener ( 'click' , ( ) => {
7
- showWarningToast ( 'warning 😐' ) ;
8
- } ) ;
9
- document . querySelector ( '#error-toast' ) . addEventListener ( 'click' , ( ) => {
10
- showErrorToast ( 'error 🙁' ) ;
11
- } ) ;
3
+ function initDevtestToast ( ) {
4
+ const levelMap = { info : showInfoToast , warning : showWarningToast , error : showErrorToast } ;
5
+ for ( const el of document . querySelectorAll ( '.toast-test-button' ) ) {
6
+ el . addEventListener ( 'click' , ( ) => {
7
+ const level = el . getAttribute ( 'data-toast-level' ) ;
8
+ const message = el . getAttribute ( 'data-toast-message' ) ;
9
+ levelMap [ level ] ( message ) ;
10
+ } ) ;
11
+ }
12
+ }
13
+
14
+ initDevtestToast ( ) ;
You can’t perform that action at this time.
0 commit comments