Skip to content

Commit 58597e1

Browse files
committed
Improve demo and update tests (#43, #38)
1 parent 181e9a0 commit 58597e1

File tree

3 files changed

+78
-25
lines changed

3 files changed

+78
-25
lines changed

cypress/e2e/test.cy.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ describe('Integration Tests', () => {
1111
})
1212

1313
it('Displays colored toast', () => {
14-
cy.get('[data-btn=green]')
14+
cy.get('[data-btn=coloredToast]')
1515
.click()
1616
.get('._toastItem')
17-
.should('have.css', 'background-color', 'rgb(72, 187, 120)')
17+
.should('have.css', 'background-color', 'rgba(72, 187, 120, 0.9)')
1818
.get('._toastBtn')
1919
.click()
2020
})
@@ -325,4 +325,17 @@ describe('Integration Tests', () => {
325325
.get('._toastBtn')
326326
.click()
327327
})
328+
329+
it('Can change dismiss button char', () => {
330+
cy.get('[data-btn=customDismissButton]')
331+
.click()
332+
.get('._toastBtn')
333+
.then(($els) => {
334+
const win = $els[0].ownerDocument.defaultView
335+
const computed = win.getComputedStyle($els[0], 'after')
336+
const val = computed.getPropertyValue('content')
337+
expect(val).to.eq('"x"')
338+
})
339+
.click()
340+
})
328341
})

docs/App.svelte

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
/*eslint no-useless-escape: "off"*/
2+
/* eslint no-useless-escape: "off" */
33
import { tick } from 'svelte'
44
import { SvelteToast, toast } from '../src'
55
import DummyComponent from './Dummy.svelte'
@@ -33,30 +33,21 @@ const buttons = [
3333
}
3434
},
3535
{
36-
name: 'GREEN',
36+
name: 'COLORED TOAST',
3737
code: `toast.push('Success!', {
3838
theme: {
39-
'--toastBackground': '#48BB78',
39+
'--toastColor': 'mintcream',
40+
'--toastBackground': 'rgba(72,187,120,0.9)',
4041
'--toastBarBackground': '#2F855A'
4142
}
4243
})`,
4344
run: () => {
4445
toast.push('Success!', {
45-
theme: { '--toastBackground': '#48BB78', '--toastBarBackground': '#2F855A' }
46-
})
47-
}
48-
},
49-
{
50-
name: 'RED',
51-
code: `toast.push('Danger!', {
52-
theme: {
53-
'--toastBackground': '#F56565',
54-
'--toastBarBackground': '#C53030'
55-
}
56-
})`,
57-
run: () => {
58-
toast.push('Danger!', {
59-
theme: { '--toastBackground': '#F56565', '--toastBarBackground': '#C53030' }
46+
theme: {
47+
'--toastColor': 'mintcream',
48+
'--toastBackground': 'rgba(72,187,120,0.9)',
49+
'--toastBarBackground': '#2F855A'
50+
}
6051
})
6152
}
6253
},
@@ -70,18 +61,43 @@ const buttons = [
7061
)
7162
}
7263
},
64+
{
65+
name: 'HIDE PROGRESS BAR',
66+
code: `toast.push('Hide the progress bar', {
67+
theme: {
68+
'--toastBarHeight': 0
69+
}
70+
})`,
71+
run: () => {
72+
toast.push('Hide the progress bar', {
73+
theme: {
74+
'--toastBarHeight': 0
75+
}
76+
})
77+
}
78+
},
7379
{
7480
name: 'LONG DURATION',
7581
code: `toast.push('Watching the paint dry...', { duration: 20000 })`,
7682
run: () => {
7783
toast.push('Watching the paint dry...', { duration: 20000 })
7884
}
7985
},
86+
{
87+
name: 'NO EXPIRY',
88+
code: `toast.push('Tap button to dismiss', {
89+
// Effectively disables autoclose when \`initial\`==\`next\`
90+
initial: 0
91+
})`,
92+
run: () => {
93+
toast.push('Tap button to dismiss', { initial: 0 })
94+
}
95+
},
8096
{
8197
name: 'NON-DISMISSABLE',
8298
code: `toast.push('Where the close btn?!?', {
99+
// Toast can only be dismissed programatically
83100
initial: 0,
84-
next: 0,
85101
dismissable: false
86102
})`,
87103
run: () => {
@@ -103,19 +119,25 @@ toast.pop(id)`,
103119
{
104120
name: 'FLIP PROGRESS BAR',
105121
code: `toast.push('Progress bar is flipped', {
122+
// Sets the bar to progress from 0 to 1 in 6s
106123
initial: 0,
107-
next: 1
124+
next: 1,
125+
duration: 6000
108126
})`,
109127
run: () => {
110-
toast.push('Progress bar is flipped', { initial: 0, next: 1 })
128+
toast.push('Progress bar is flipped', {
129+
initial: 0,
130+
next: 1,
131+
duration: 6000
132+
})
111133
}
112134
},
113135
{
114136
name: 'USE AS LOADING INDICATOR',
115137
code: `const sleep = t => new Promise(resolve => setTimeout(resolve, t))
116138
117139
const id = toast.push('Loading, please wait...', {
118-
duration: 300,
140+
duration: 300, // Each progress change takes 300ms
119141
initial: 0,
120142
next: 0,
121143
dismissable: false
@@ -342,6 +364,24 @@ toast.pop(0)`,
342364
}
343365
})
344366
}
367+
},
368+
{
369+
name: 'CUSTOM DISMISS BUTTON',
370+
code: `toast.push('Say cheese!', {
371+
theme: {
372+
'--toastBtnContent': \`url("data:image/svg+xml,...")\`
373+
}
374+
}`,
375+
run: () => {
376+
toast.push('Say cheese!', {
377+
theme: {
378+
// @ts-ignore
379+
'--toastBtnContent': window.Cypress
380+
? `'x'`
381+
: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1.5rem' height='1.5rem' fill='%23F1CB30' viewBox='0 0 512 512' xml:space='preserve'%3E%3Cpath d='M256,0C114.842,0,0,114.842,0,256s114.842,256,256,256s256-114.842,256-256S397.158,0,256,0z'/%3E%3Cg%3E%3Cpath style='fill:%2357575C;' d='M355.297,175.321c-8.161,0-16.167,3.305-21.938,9.092c-5.773,5.772-9.092,13.762-9.092,21.938 c0,8.163,3.32,16.168,9.092,21.94c5.772,5.772,13.777,9.09,21.938,9.09c8.161,0,16.167-3.32,21.938-9.09 c5.773-5.772,9.092-13.777,9.092-21.94c0-8.176-3.32-16.167-9.092-21.938C371.464,178.626,363.472,175.321,355.297,175.321z'/%3E%3Cpath style='fill:%2357575C;' d='M178.641,228.291c5.773-5.772,9.092-13.762,9.092-21.94c0-8.176-3.32-16.167-9.092-21.938 c-5.772-5.787-13.777-9.092-21.938-9.092c-8.161,0-16.167,3.305-21.938,9.092c-5.772,5.772-9.092,13.762-9.092,21.938 c0,8.176,3.32,16.168,9.092,21.94c5.772,5.786,13.777,9.09,21.938,9.09C164.864,237.382,172.87,234.077,178.641,228.291z'/%3E%3C/g%3E%3Cpath style='fill:%23DF6246;' d='M356.49,326.085c-3.603-8.696-12.088-14.367-21.501-14.367H256h-78.991 c-9.413,0-17.898,5.671-21.501,14.367c-3.601,8.696-1.61,18.708,5.046,25.363c25.495,25.493,59.392,39.534,95.446,39.534 s69.952-14.041,95.446-39.534C358.102,344.792,360.093,334.78,356.49,326.085z'/%3E%3Cpath style='fill:%23E69629;' d='M160.552,351.448c-6.656-6.654-8.647-16.665-5.046-25.363c3.603-8.696,12.088-14.367,21.501-14.367 H256V0C114.842,0,0,114.842,0,256s114.842,256,256,256V390.982C219.946,390.982,186.048,376.941,160.552,351.448z M125.673,206.352 c0-8.176,3.32-16.167,9.092-21.938c5.772-5.787,13.777-9.092,21.938-9.092c8.161,0,16.167,3.305,21.938,9.092 c5.773,5.772,9.092,13.762,9.092,21.938c0,8.176-3.32,16.168-9.092,21.94c-5.772,5.786-13.777,9.09-21.938,9.09 c-8.161,0-16.167-3.305-21.938-9.09C128.993,222.52,125.673,214.528,125.673,206.352z'/%3E%3Cpath style='fill:%23DD512A;' d='M177.009,311.718c-9.413,0-17.898,5.671-21.501,14.367c-3.601,8.696-1.61,18.708,5.046,25.363 c25.495,25.493,59.39,39.534,95.445,39.534v-79.264H177.009z'/%3E%3C/svg%3E")`
382+
}
383+
})
384+
}
345385
}
346386
]
347387

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h1 class="text-4xl text-center">svelte-toast</h1>
4848
</div>
4949
<p class="container px-2 mb-4">
5050
Simple, elegant, generic, flexible and performant toast notifications. Because a demo helps
51-
better than a thousand API docs, so here it is. Use in Vanilla JS (7kb gzipped) or as a Svelte
51+
better than a thousand API docs, so here it is. Use in Vanilla JS (8kb gzipped) or as a Svelte
5252
component.
5353
</p>
5454
</body>

0 commit comments

Comments
 (0)