generated from github/custom-element-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
123 lines (122 loc) · 5.06 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width user-scalable=no initial-scale=1.0 minimum-scale=1.0 maximum-scale=1.0">
<title>bs-toast-element demo</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>
<body>
<main class="container py-4 vstack gap-4">
<h1><bs-toast> element</h1>
<div>
<h3>Light</h3>
<pre class="bg-light text-dark">
<code>
openToast('Hello, world!', { color: 'dark', bgColor: 'light', delay: 5000 })
</code>
</pre>
<button type="button" class="btn btn-secondary" id="show-light">Show</button>
</div>
<div>
<h3>Success</h3>
<pre class="bg-light text-dark">
<code>
openToast('Hello, world!', { color: 'dark', bgColor: 'success', delay: 5000, opacity: 25 })
</code>
</pre>
<button type="button" class="btn btn-success" id="show-success">Show</button>
</div>
<div>
<h3>Danger</h3>
<pre class="bg-light text-dark">
<code>
openToast('Error!', { bgColor: 'danger', delay: 20000 })
</code>
</pre>
<button type="button" class="btn btn-danger" id="show-danger">Show</button>
</div>
<div>
<h3>Position</h3>
<pre class="bg-light text-dark">
<code>
openToast('Hello, world!', { color: 'white', bgColor: 'dark', delay: 1500, position: 'bottom-center' })
</code>
</pre>
<button type="button" class="btn btn-info" id="show-position">Show</button>
</div>
<div>
<h3>Custom content</h3>
<pre class="bg-light text-dark">
<code>
const content = document.createElement('div')
content.innerHTML = `
<div class="hstack align-items-start gap-2">
<img class="rounded-pill" src="https://placehold.jp/40/3d4070/ffffff/150x150.png?text=John" style="width: 32px; height: 32px;">
<div class="vstack gap-2">
<strong>John</strong>
<div class="text-muted">
Hello, world! This is a toast message.
Hello, world! This is a toast message.
Hello, world! This is a toast message.
</div>
<div class="hstack gap-2">
<button type="button" class="btn btn-sm btn-primary">Accept</button>
<button type="button" class="btn btn-sm btn-outline-secondary">Decline</button>
</div>
</div>
`
const hide = openToast(content, { color: 'dark', bgColor: 'light', delay: 20000, hideCloseButton: true })
content.addEventListener('click', (event) => {
if (event.target.matches('button')) {
hide()
}
})
</code>
</pre>
<button type="button" class="btn btn-secondary" id="show-custom">Show</button>
</div>
</main>
<script type="module">
// import { openToast } from 'https://cdn.skypack.dev/@sonicgarden/bs-toast-element'
import { openToast } from './src/index.ts'
document.querySelector('#show-light').addEventListener('click', () => {
openToast('Hello, world!', { color: 'dark', bgColor: 'light', delay: 5000 })
})
document.querySelector('#show-success').addEventListener('click', () => {
openToast('Hello, world!', { color: 'dark', bgColor: 'success', delay: 5000, opacity: 25 })
})
document.querySelector('#show-danger').addEventListener('click', () => {
openToast('Error!', { bgColor: 'danger', delay: 20000 })
})
document.querySelector('#show-position').addEventListener('click', () => {
openToast('Hello, world!', { color: 'white', bgColor: 'dark', delay: 1500, position: 'bottom-center' })
})
document.querySelector('#show-custom').addEventListener('click', () => {
const content = document.createElement('div')
content.innerHTML = `
<div class="hstack align-items-start gap-2">
<img class="rounded-pill" src="https://placehold.jp/40/3d4070/ffffff/150x150.png?text=John" style="width: 32px; height: 32px;">
<div class="vstack gap-2">
<strong>John</strong>
<div class="text-muted">
Hello, world! This is a toast message.
Hello, world! This is a toast message.
Hello, world! This is a toast message.
</div>
<div class="hstack gap-2">
<button type="button" class="btn btn-sm btn-primary">Accept</button>
<button type="button" class="btn btn-sm btn-outline-secondary">Decline</button>
</div>
</div>
`
const hide = openToast(content, { color: 'dark', bgColor: 'light', delay: 20000, hideCloseButton: true })
content.addEventListener('click', (event) => {
if (event.target.matches('button')) {
hide()
}
})
})
</script>
</body>
</html>