react-strawberry-toast 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/dist/headless.d.mts +53 -0
- package/dist/headless.d.ts +53 -0
- package/dist/headless.js +1 -0
- package/dist/headless.mjs +1 -0
- package/dist/index.css +1 -0
- package/dist/index.d.mts +85 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/package.json +76 -0
- package/src/components/condition.tsx +27 -0
- package/src/components/if.tsx +27 -0
- package/src/components/toast-container.tsx +153 -0
- package/src/components/toast-default.tsx +96 -0
- package/src/components/toast.tsx +84 -0
- package/src/constants/index.ts +8 -0
- package/src/core/headless-toast.ts +49 -0
- package/src/core/store.ts +34 -0
- package/src/core/toast-handler.ts +108 -0
- package/src/core/toast.ts +98 -0
- package/src/global.d.ts +6 -0
- package/src/headless.ts +3 -0
- package/src/hooks/use-toasts.ts +11 -0
- package/src/index.ts +3 -0
- package/src/styles/index.scss +86 -0
- package/src/types/index.ts +48 -0
- package/src/types/utils.ts +1 -0
- package/src/utils/generate-id.ts +4 -0
- package/src/utils/get-animation.ts +10 -0
- package/src/utils/get-direction.ts +19 -0
- package/src/vite.env.d.ts +1 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
$react-strawberry-toast-namespace: 'react-strawberry-toast';
|
|
2
|
+
|
|
3
|
+
@keyframes l3 {
|
|
4
|
+
to {
|
|
5
|
+
transform: rotate(1turn);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@keyframes react-strawberry-toast_fade-in {
|
|
10
|
+
from {
|
|
11
|
+
transform: translateY(-100%);
|
|
12
|
+
opacity: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
to {
|
|
16
|
+
transform: translateY(0);
|
|
17
|
+
opacity: 1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@keyframes react-strawberry-toast_fade-out {
|
|
22
|
+
from {
|
|
23
|
+
transform: translateY(0);
|
|
24
|
+
opacity: 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
to {
|
|
28
|
+
transform: translateY(-100%);
|
|
29
|
+
opacity: 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@keyframes react-strawberry-toast_fade-in-reverse {
|
|
34
|
+
from {
|
|
35
|
+
transform: translateY(100%);
|
|
36
|
+
opacity: 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
to {
|
|
40
|
+
transform: translateY(0);
|
|
41
|
+
opacity: 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@keyframes react-strawberry-toast_fade-out-reverse {
|
|
46
|
+
from {
|
|
47
|
+
transform: translateY(0);
|
|
48
|
+
opacity: 1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
to {
|
|
52
|
+
transform: translateY(100%);
|
|
53
|
+
opacity: 0;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.#{$react-strawberry-toast-namespace}__fade-in {
|
|
58
|
+
animation: react-strawberry-toast_fade-in 0.3s ease-out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.#{$react-strawberry-toast-namespace}__fade-out {
|
|
62
|
+
animation: react-strawberry-toast_fade-out 0.3s ease-out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.#{$react-strawberry-toast-namespace}__fade-in-reverse {
|
|
66
|
+
animation: react-strawberry-toast_fade-in-reverse 0.3s ease-out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.#{$react-strawberry-toast-namespace}__fade-out-reverse {
|
|
70
|
+
animation: react-strawberry-toast_fade-out-reverse 0.3s ease-out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.#{$react-strawberry-toast-namespace}__loading {
|
|
74
|
+
width: 15px;
|
|
75
|
+
padding: 3px;
|
|
76
|
+
aspect-ratio: 1;
|
|
77
|
+
border-radius: 50%;
|
|
78
|
+
background: #6b6875;
|
|
79
|
+
--_m: conic-gradient(#0000 10%, #000),
|
|
80
|
+
linear-gradient(#000 0 0) content-box;
|
|
81
|
+
-webkit-mask: var(--_m);
|
|
82
|
+
mask: var(--_m);
|
|
83
|
+
-webkit-mask-composite: source-out;
|
|
84
|
+
mask-composite: subtract;
|
|
85
|
+
animation: l3 1s infinite linear;
|
|
86
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { RequiredExcept } from './utils';
|
|
3
|
+
|
|
4
|
+
export type Position =
|
|
5
|
+
| 'bottom-left'
|
|
6
|
+
| 'bottom-center'
|
|
7
|
+
| 'bottom-right'
|
|
8
|
+
| 'top-left'
|
|
9
|
+
| 'top-center'
|
|
10
|
+
| 'top-right';
|
|
11
|
+
|
|
12
|
+
export type ToastType = 'default' | 'custom' | 'success' | 'error' | 'loading' | 'warn';
|
|
13
|
+
|
|
14
|
+
export interface BaseOptions {
|
|
15
|
+
toastId?: string;
|
|
16
|
+
timeOut?: number;
|
|
17
|
+
removeTimeOut?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ToastBaseState {
|
|
20
|
+
toastId: string;
|
|
21
|
+
data: ReactNode;
|
|
22
|
+
isVisible: boolean;
|
|
23
|
+
createdAt: number;
|
|
24
|
+
pausedAt?: number;
|
|
25
|
+
updated?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Options extends BaseOptions {
|
|
29
|
+
position?: Position;
|
|
30
|
+
containerId?: string;
|
|
31
|
+
pauseOnHover?: boolean;
|
|
32
|
+
toastType?: ToastType;
|
|
33
|
+
}
|
|
34
|
+
interface ToastDataCallback {
|
|
35
|
+
close: () => void;
|
|
36
|
+
immediatelyClose: () => void;
|
|
37
|
+
isVisible: boolean;
|
|
38
|
+
icons: Record<Exclude<ToastType, 'default' | 'custom'>, ReactNode>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ToastState = ToastBaseState & BaseOptions;
|
|
42
|
+
|
|
43
|
+
export type ToastDataWithCallback = (props: ToastDataCallback) => ReactNode;
|
|
44
|
+
|
|
45
|
+
export type NonHeadlessToastState = RequiredExcept<Options, 'containerId' | 'position'> &
|
|
46
|
+
Omit<ToastState, 'data'> & {
|
|
47
|
+
data: ToastDataWithCallback | ReactNode;
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type RequiredExcept<T, K extends keyof T> = Required<Omit<T, K>> & Pick<T, K>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { STYLE_NAMESPACE } from '../constants';
|
|
2
|
+
import { Position } from '../types';
|
|
3
|
+
|
|
4
|
+
export const getAnimation = ({ isVisible, position }: { isVisible: boolean; position: Position }) => {
|
|
5
|
+
if (isVisible) {
|
|
6
|
+
return /top/i.test(position) ? `${STYLE_NAMESPACE}__fade-in` : `${STYLE_NAMESPACE}__fade-in-reverse`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return /bottom/i.test(position) ? `${STYLE_NAMESPACE}__fade-out-reverse` : `${STYLE_NAMESPACE}__fade-out`;
|
|
10
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Position } from '../types';
|
|
2
|
+
|
|
3
|
+
export const getDirection = ({
|
|
4
|
+
position,
|
|
5
|
+
reverse = false,
|
|
6
|
+
}: {
|
|
7
|
+
position: Position;
|
|
8
|
+
reverse: boolean;
|
|
9
|
+
}): 'column-reverse' | 'column' => {
|
|
10
|
+
if (/top/i.test(position)) {
|
|
11
|
+
return reverse ? 'column-reverse': 'column';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (/bottom/i.test(position)) {
|
|
15
|
+
return reverse ? 'column': 'column-reverse';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return 'column';
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite-plugin-svgr/client" />
|