Skip to content

Commit 20681b5

Browse files
committed
Rename option progress to next (sorry)
1 parent e915639 commit 20681b5

File tree

5 files changed

+51
-41
lines changed

5 files changed

+51
-41
lines changed

cypress/integration/test.spec.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,24 @@ describe('Integration Tests', () => {
6565
})
6666

6767
it('Dynamically update progress bar', () => {
68-
cy.window()
69-
.invoke('toast.push', 'Test', { duration: 1, initial: 0, progress: 0 })
70-
.then(id => {
68+
cy.window().invoke('toast.push', 'Test', { duration: 1, initial: 0, next: 0 })
69+
.then($id => {
70+
cy.get('._toastBar').then($bar => {
71+
expect($bar.val()).to.equal(0)
72+
cy.window().invoke('toast.set', $id, { next: 0.2 }).wait(50).then(() => {
73+
expect(parseFloat($bar.val())).to.equal(0.2)
74+
cy.get('._toastBtn').click()
75+
})
76+
})
77+
})
78+
})
79+
80+
it('Allows backward compatibility for `progress` key', () => {
81+
cy.window().invoke('toast.push', 'Test', { duration: 1, initial: 0, progress: 0 })
82+
.then($id => {
7183
cy.get('._toastBar').then($bar => {
7284
expect($bar.val()).to.equal(0)
73-
cy.window().invoke('toast.set', id, { progress: 0.2 }).wait(50).then(() => {
85+
cy.window().invoke('toast.set', $id, { progress: 0.2 }).wait(50).then(() => {
7486
expect(parseFloat($bar.val())).to.equal(0.2)
7587
cy.get('._toastBtn').click()
7688
})

docs/App.svelte

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ const buttons = [
7272
name: 'NON-DISMISSABLE',
7373
code: `toast.push('Where the close btn?!?', {
7474
initial: 0,
75-
progress: 0,
75+
next: 0,
7676
dismissable: false
7777
})`,
7878
run: () => {
79-
toast.push('Where the close btn?!?', { initial: 0, progress: 0, dismissable: false })
79+
toast.push('Where the close btn?!?', { initial: 0, dismissable: false })
8080
}
8181
},
8282
{
@@ -95,10 +95,10 @@ toast.pop(id)`,
9595
name: 'FLIP PROGRESS BAR',
9696
code: `toast.push('Progress bar is flipped', {
9797
initial: 0,
98-
progress: 1
98+
next: 1
9999
})`,
100100
run: () => {
101-
toast.push('Progress bar is flipped', { initial: 0, progress: 1 })
101+
toast.push('Progress bar is flipped', { initial: 0, next: 1 })
102102
}
103103
},
104104
{
@@ -108,32 +108,32 @@ toast.pop(id)`,
108108
const id = toast.push('Loading, please wait...', {
109109
duration: 300,
110110
initial: 0,
111-
progress: 0,
111+
next: 0,
112112
dismissable: false
113113
})
114114
115115
await sleep(500)
116-
toast.set(id, { progress: 0.1 })
116+
toast.set(id, { next: 0.1 })
117117
118118
await sleep(3000)
119-
toast.set(id, { progress: 0.7 })
119+
toast.set(id, { next: 0.7 })
120120
121121
await sleep(1000)
122-
toast.set(id, { msg: 'Just a bit more', progress: 0.8 })
122+
toast.set(id, { msg: 'Just a bit more', next: 0.8 })
123123
124124
await sleep(2000)
125-
toast.set(id, { progress: 1 })`,
125+
toast.set(id, { next: 1 })`,
126126
run: async () => {
127127
const sleep = t => new Promise(resolve => setTimeout(resolve, t))
128-
const id = toast.push('Loading, please wait...', { duration: 300, initial: 0, progress: 0, dismissable: false })
128+
const id = toast.push('Loading, please wait...', { duration: 300, initial: 0, dismissable: false })
129129
await sleep(500)
130-
toast.set(id, { progress: 0.1 })
130+
toast.set(id, { next: 0.1 })
131131
await sleep(3000)
132-
toast.set(id, { progress: 0.7 })
132+
toast.set(id, { next: 0.7 })
133133
await sleep(1000)
134-
toast.set(id, { msg: 'Just a bit more', progress: 0.8 })
134+
toast.set(id, { msg: 'Just a bit more', next: 0.8 })
135135
await sleep(2000)
136-
toast.set(id, { progress: 1 })
136+
toast.set(id, { next: 1 })
137137
}
138138
},
139139
{
@@ -244,17 +244,10 @@ toast.pop(0)`,
244244
})`,
245245
run: () => {
246246
toast.push({
247-
component: {
248-
src: DummyComponent,
249-
props: {
250-
title: 'A Dummy Cookie Component'
251-
}
252-
},
247+
component: { src: DummyComponent, props: { title: 'A Dummy Cookie Component' } },
253248
dismissable: false,
254249
initial: 0,
255-
theme: {
256-
'--toastMsgPadding': '0'
257-
}
250+
theme: { '--toastMsgPadding': '0' }
258251
})
259252
}
260253
}

src/ToastItem.svelte

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ import { toast } from './stores.js'
66
export let item
77
88
const progress = tweened(item.initial, { duration: item.duration, easing: linear })
9+
let prev = item.initial
910
10-
let prevProgress = item.initial
11-
12-
$: if (prevProgress !== item.progress) {
13-
if (item.progress === 1 || item.progress === 0) {
14-
progress.set(item.progress).then(() => toast.pop(item.id))
11+
$: if (prev !== item.next) {
12+
if (item.next === 1 || item.next === 0) {
13+
progress.set(item.next).then(() => toast.pop(item.id))
1514
} else {
16-
progress.set(item.progress)
15+
progress.set(item.next)
1716
}
18-
prevProgress = item.progress
17+
prev = item.next
18+
}
19+
20+
// `progress` has been renamed to `next`; shim included for backward compatibility, to remove in next major
21+
$: if (typeof item.progress !== 'undefined') {
22+
item.next = item.progress
1923
}
2024
</script>
2125

@@ -79,7 +83,7 @@ $: if (prevProgress !== item.progress) {
7983
<div class="_toastItem">
8084
<div class="_toastMsg" class:pe={item.component}>
8185
{#if item.component}
82-
<svelte:component this="{item.component.src}" {...item.component.props} toastId={item.id} />
86+
<svelte:component this={item.component.src} {...item.component.props} toastId={item.id} />
8387
{:else}
8488
{@html item.msg}
8589
{/if}

src/index.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ declare module '@zerodevx/svelte-toast'
88
* Default Toast Options
99
* ```typescript
1010
* {
11-
* duration: 4000, // duration of progress bar tween
12-
* dismissable: true, // allow dismiss with close button
11+
* duration: 4000, // duration of progress bar tween from previous to `next`
1312
* initial: 1, // initial progress bar value
14-
* progress: 0, // current progress
13+
* next: 0, // next progress value
14+
* dismissable: true, // allow dismiss with close button
1515
* reversed: false, // insert new toast to bottom of stack
1616
* intro: { x: 256 }, // toast intro fly animation settings
1717
* theme: {} // css var overrides
@@ -23,9 +23,10 @@ export interface SvelteToastOptions {
2323
target?: string
2424
msg?: string
2525
duration?: number
26-
dismissable?: boolean
2726
initial?: number
27+
next?: number
2828
progress?: number
29+
dismissable?: boolean
2930
reversed?: boolean
3031
intro?: FlyParams
3132
theme?: { [key: string]: string }

src/stores.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { writable } from 'svelte/store'
22

33
const defaults = {
44
duration: 4000,
5-
dismissable: true,
65
initial: 1,
7-
progress: 0,
6+
next: 0,
7+
dismissable: true,
88
reversed: false,
99
intro: { x: 256 },
1010
theme: {}

0 commit comments

Comments
 (0)