-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathApp.tsx
More file actions
124 lines (116 loc) · 3.5 KB
/
App.tsx
File metadata and controls
124 lines (116 loc) · 3.5 KB
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
124
import { Component, createEffect, createMemo, createSignal, onCleanup } from 'solid-js';
import toast, { Toaster } from '../../src';
const makePromise = (): Promise<string> => {
return new Promise((resolve, reject) => {
setTimeout(() => {
const toss = Math.random();
if (toss > 0.5) resolve('Successful!');
reject('Something went wrong!');
}, 2000);
});
};
const App: Component = () => {
const popBlank = () => toast('Blank Toast');
const popSuccess = () => toast.success('Success!', { duration: Infinity });
const popError = () => toast.error('Error!', { duration: Infinity });
const popLoading = () => toast.loading('Loading...');
const popPromise = () =>
toast.promise(makePromise(), {
loading: <span class="promise-txt">Loading Promise</span>,
success: (msg) => <span class="promise-txt">{msg}</span>,
error: (err) => <span class="promise-txt">{err}</span>,
});
const popCustom = () =>
toast.success('Add Custom Styles', {
iconTheme: {
primary: '#ea580c',
secondary: '#ffedd5',
},
className: 'border-2 border-orange-800',
style: {
color: '#c2410c',
background: '#ffedd5',
},
duration: Infinity,
});
const popTimer = () =>
toast.custom(
(t) => {
const [life, setLife] = createSignal(100);
createEffect(() => {
if (t.paused) return;
const interval = setInterval(() => {
console.log(t.paused);
setLife((l) => l - 0.5);
}, 10);
onCleanup(() => clearInterval(interval));
});
return (
<div class="bg-pink-100 shadow-md px-4 py-3 rounded overflow-hidden relative text-pink-700">
<div style={{ width: `${life()}%` }} class="bg-pink-200 h-full absolute top-0 left-0"></div>
<span class="relative">Timer In The Background</span>
</div>
);
},
{
duration: 2000,
unmountDelay: 1000,
}
);
const [toggle, setToggle] = createSignal(false);
const closeAll = () => toast.dismiss();
return (
<div class="px-6">
<Toaster
position="top-center"
toastOptions={{
iconTheme: toggle()
? {
primary: '#ea580c',
secondary: '#ffedd5',
}
: {
primary: '#5858ff',
secondary: '#ffedd5',
},
}}
/>
<button onClick={() => setToggle((t) => !t)}>Toggle Theme</button>
<h1>Solid Toast Examples</h1>
<div
style={{
display: 'flex',
'flex-direction': 'column',
'align-items': 'flex-start',
gap: '0.5rem',
}}
>
<button class={'blank'} onClick={popBlank}>
Blank Toast
</button>
<button class={'success'} onClick={popSuccess}>
Success Toast
</button>
<button class={'error'} onClick={popError}>
Error Toast
</button>
<button class={'loading'} onClick={popLoading}>
Loading Toast
</button>
<button class={'promise'} onClick={popPromise}>
Promise Toast
</button>
<button class={'custom'} onClick={popCustom}>
Custom Styles
</button>
<button class={'timer'} onClick={popTimer}>
Toast Timer
</button>
<button class={'close'} onClick={closeAll}>
Close all toasts
</button>
</div>
</div>
);
};
export default App;