Skip to content

Commit 2c8af37

Browse files
Th3-S1lenc3antony
andauthored
Add support for icons in notifications (beyonk-group#35)
feat: Add Icon Support feat: Add option to hide progress bar Co-authored-by: Antony Jones <ant@enzy.org>
1 parent 7d2e3b1 commit 2c8af37

File tree

5 files changed

+211
-43
lines changed

5 files changed

+211
-43
lines changed

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ You can call multiple types of notification:
4646
```js
4747
const options = {
4848
timeout: 3000, // milliseconds
49-
persist: false // automatic timeout (ignores above)
49+
persist: false, // automatic timeout (ignores above)
50+
showProgess: true, // Show (or Hide) the progress bar
51+
icon: null // Add svelte component to render an icon
5052
}
5153

5254
notifier.show('danger', message, options)
@@ -153,6 +155,25 @@ function someFunction () {
153155
</script>
154156
```
155157

158+
##### Show Progress:
159+
160+
You can show or hide the progress bar per message
161+
162+
```svelte
163+
<NotificationDisplay />
164+
165+
<button on:click={someFunction}>Show message</button>
166+
167+
<script>
168+
import { NotificationDisplay, notifier } from '@beyonk/svelte-notifications'
169+
170+
function someFunction () {
171+
notifier.success('Notifications work!', { showProgress: false }) // built in theme
172+
notifier.send('custom-theme', 'Notifications work!', { showProgress: true }) // custom theme
173+
}
174+
</script>
175+
```
176+
156177
##### Persist
157178

158179
You can make a message persist and never timeout, having a close button that the user can click to remove it.
@@ -172,6 +193,34 @@ function someFunction () {
172193
</script>
173194
```
174195

196+
##### Icons
197+
198+
You can include custom svelte components to render icons (or anything).
199+
200+
```svelte
201+
<NotificationDisplay />
202+
203+
<button on:click={someFunction}>Show message</button>
204+
205+
<script>
206+
import { NotificationDisplay, notifier } from '@beyonk/svelte-notifications'
207+
impoer Icon from 'somewhere/Icon.svelte'
208+
209+
function someFunction () {
210+
notifier.success('Notifications work!', { icon: Icon })
211+
}
212+
</script>
213+
214+
// Icon.svelte
215+
216+
<svg width="1em" height="1em" viewBox="0 0 36 36">
217+
<path
218+
fill="currentColor"
219+
d="M18 34a16 16 0 1 1 16-16a16 16 0 0 1-16 16Zm0-30a14 14 0 1 0 14 14A14 14 0 0 0 18 4Z"
220+
</path>
221+
</svg>
222+
```
223+
175224
## Credits
176225

177226
* Original code by [Antony Jones](https://github.com/antony)

pnpm-lock.yaml

Lines changed: 51 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/Icon.svelte

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- Example of an icon component -->
2+
<!-- Icon: times-circle-line -->
3+
<!-- Source: iconify -->
4+
<!-- URL: https://icon-sets.iconify.design/clarity/times-circle-line/ -->
5+
6+
<style>
7+
.demo-icon {
8+
font-size: 1.25rem;
9+
line-height: 1.5rem;
10+
padding-right: 0.25rem;
11+
}
12+
</style>
13+
14+
<div class="demo-icon">
15+
<svg
16+
xmlns="http://www.w3.org/2000/svg"
17+
xmlns:xlink="http://www.w3.org/1999/xlink"
18+
aria-hidden="true"
19+
role="img"
20+
width="1em"
21+
height="1em"
22+
preserveAspectRatio="xMidYMid meet"
23+
viewBox="0 0 36 36"
24+
>
25+
<path
26+
fill="currentColor"
27+
d="m19.61 18l4.86-4.86a1 1 0 0 0-1.41-1.41l-4.86 4.81l-4.89-4.89a1 1 0 0 0-1.41 1.41L16.78 18L12 22.72a1 1 0 1 0 1.41 1.41l4.77-4.77l4.74 4.74a1 1 0 0 0 1.41-1.41Z"
28+
class="clr-i-outline clr-i-outline-path-1">
29+
</path>
30+
<path
31+
fill="currentColor"
32+
d="M18 34a16 16 0 1 1 16-16a16 16 0 0 1-16 16Zm0-30a14 14 0 1 0 14 14A14 14 0 0 0 18 4Z"
33+
class="clr-i-outline clr-i-outline-path-2">
34+
</path>
35+
<path
36+
fill="none"
37+
d="M0 0h36v36H0z">
38+
</path>
39+
</svg>
40+
</div>

0 commit comments

Comments
 (0)