@ilokesto/toast 1.0.0
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.ko.md +209 -0
- package/README.md +209 -0
- package/dist/components/ToastBar.d.ts +12 -0
- package/dist/components/ToastBar.js +39 -0
- package/dist/components/ToastProvider.d.ts +3 -0
- package/dist/components/ToastProvider.js +16 -0
- package/dist/components/Toaster.d.ts +2 -0
- package/dist/components/Toaster.js +175 -0
- package/dist/components/icons.d.ts +14 -0
- package/dist/components/icons.js +83 -0
- package/dist/core/createToastRuntime.d.ts +2 -0
- package/dist/core/createToastRuntime.js +247 -0
- package/dist/core/createToastStore.d.ts +2 -0
- package/dist/core/createToastStore.js +126 -0
- package/dist/core/registry.d.ts +5 -0
- package/dist/core/registry.js +18 -0
- package/dist/core/toast.d.ts +2 -0
- package/dist/core/toast.js +41 -0
- package/dist/core/utils.d.ts +11 -0
- package/dist/core/utils.js +33 -0
- package/dist/hooks/useToastItems.d.ts +2 -0
- package/dist/hooks/useToastItems.js +4 -0
- package/dist/hooks/useToaster.d.ts +2 -0
- package/dist/hooks/useToaster.js +31 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +7 -0
- package/dist/types/toast.d.ts +137 -0
- package/dist/types/toast.js +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
+
export type ToastId = string;
|
|
3
|
+
export type ToasterId = string;
|
|
4
|
+
export type ToastType = "blank" | "success" | "error" | "loading" | "custom";
|
|
5
|
+
export type ToastStatus = "visible" | "closing";
|
|
6
|
+
export type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
7
|
+
export type ToastTransport = "inline" | "top-layer";
|
|
8
|
+
export type Renderable = ReactNode;
|
|
9
|
+
export type ValueOrFunction<TValue, TArg> = TValue | ((arg: TArg) => TValue);
|
|
10
|
+
export interface ToastAriaProps {
|
|
11
|
+
readonly role: "status" | "alert";
|
|
12
|
+
readonly "aria-live": "polite" | "assertive";
|
|
13
|
+
readonly "aria-atomic"?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface IconTheme {
|
|
16
|
+
readonly primary: string;
|
|
17
|
+
readonly secondary: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ToastItem {
|
|
20
|
+
readonly id: ToastId;
|
|
21
|
+
readonly type: ToastType;
|
|
22
|
+
readonly message: Renderable;
|
|
23
|
+
readonly status: ToastStatus;
|
|
24
|
+
readonly createdAt: number;
|
|
25
|
+
readonly toasterId: ToasterId;
|
|
26
|
+
readonly duration: number;
|
|
27
|
+
readonly position: ToastPosition;
|
|
28
|
+
readonly height: number | null;
|
|
29
|
+
readonly pauseDuration: number;
|
|
30
|
+
readonly pausedAt: number | null;
|
|
31
|
+
readonly ariaProps: ToastAriaProps;
|
|
32
|
+
readonly style?: CSSProperties;
|
|
33
|
+
readonly className?: string;
|
|
34
|
+
readonly icon?: ReactNode;
|
|
35
|
+
readonly iconTheme?: IconTheme;
|
|
36
|
+
readonly removeDelay?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface ToastState {
|
|
39
|
+
readonly items: ReadonlyArray<ToastItem>;
|
|
40
|
+
readonly pausedAt: number | null;
|
|
41
|
+
}
|
|
42
|
+
export interface ToastOptions {
|
|
43
|
+
readonly id?: ToastId;
|
|
44
|
+
readonly toasterId?: ToasterId;
|
|
45
|
+
readonly duration?: number;
|
|
46
|
+
readonly position?: ToastPosition;
|
|
47
|
+
readonly ariaProps?: ToastAriaProps;
|
|
48
|
+
readonly style?: CSSProperties;
|
|
49
|
+
readonly className?: string;
|
|
50
|
+
readonly icon?: ReactNode;
|
|
51
|
+
readonly iconTheme?: IconTheme;
|
|
52
|
+
readonly removeDelay?: number;
|
|
53
|
+
}
|
|
54
|
+
export interface DefaultToastOptions extends ToastOptions {
|
|
55
|
+
readonly success?: ToastOptions;
|
|
56
|
+
readonly error?: ToastOptions;
|
|
57
|
+
readonly loading?: ToastOptions;
|
|
58
|
+
readonly blank?: ToastOptions;
|
|
59
|
+
readonly custom?: ToastOptions;
|
|
60
|
+
}
|
|
61
|
+
export interface ToastOffsetOptions {
|
|
62
|
+
readonly reverseOrder?: boolean;
|
|
63
|
+
readonly gutter?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface PromiseToastMessages<TData> {
|
|
66
|
+
readonly loading: Renderable;
|
|
67
|
+
readonly success: ValueOrFunction<Renderable, TData>;
|
|
68
|
+
readonly error: ValueOrFunction<Renderable, unknown>;
|
|
69
|
+
}
|
|
70
|
+
export interface ToastStoreApi {
|
|
71
|
+
add(item: ToastItem): void;
|
|
72
|
+
update(id: ToastId, patch: Partial<Omit<ToastItem, "id" | "toasterId" | "createdAt">>): void;
|
|
73
|
+
dismiss(id?: ToastId): void;
|
|
74
|
+
remove(id?: ToastId): void;
|
|
75
|
+
clear(): void;
|
|
76
|
+
updateHeight(id: ToastId, height: number): void;
|
|
77
|
+
startPause(): void;
|
|
78
|
+
endPause(): void;
|
|
79
|
+
subscribe(listener: () => void): () => void;
|
|
80
|
+
getSnapshot(): ReadonlyArray<ToastItem>;
|
|
81
|
+
getInitialSnapshot(): ReadonlyArray<ToastItem>;
|
|
82
|
+
}
|
|
83
|
+
export interface ToastRuntimeApi {
|
|
84
|
+
readonly toasterId: ToasterId;
|
|
85
|
+
addToast(type: ToastType, message: Renderable, options?: ToastOptions): ToastId;
|
|
86
|
+
configureView(config: {
|
|
87
|
+
limit: number;
|
|
88
|
+
position: ToastPosition;
|
|
89
|
+
toastOptions?: DefaultToastOptions;
|
|
90
|
+
}): void;
|
|
91
|
+
promiseToast<TData>(promise: Promise<TData> | (() => Promise<TData>), messages: PromiseToastMessages<TData>, options?: ToastOptions): Promise<TData>;
|
|
92
|
+
dismiss(id?: ToastId): void;
|
|
93
|
+
remove(id?: ToastId): void;
|
|
94
|
+
clear(): void;
|
|
95
|
+
updateHeight(id: ToastId, height: number): void;
|
|
96
|
+
getRawSnapshot(): ReadonlyArray<ToastItem>;
|
|
97
|
+
startPause(): void;
|
|
98
|
+
endPause(): void;
|
|
99
|
+
subscribe(listener: () => void): () => void;
|
|
100
|
+
getSnapshot(): ReadonlyArray<ToastItem>;
|
|
101
|
+
getInitialSnapshot(): ReadonlyArray<ToastItem>;
|
|
102
|
+
}
|
|
103
|
+
export interface ToastRowHelpers {
|
|
104
|
+
readonly dismiss: () => void;
|
|
105
|
+
readonly remove: () => void;
|
|
106
|
+
}
|
|
107
|
+
export interface ToasterProps {
|
|
108
|
+
readonly toasterId?: ToasterId;
|
|
109
|
+
readonly position?: ToastPosition;
|
|
110
|
+
readonly transport?: ToastTransport;
|
|
111
|
+
readonly limit?: number;
|
|
112
|
+
readonly reverseOrder?: boolean;
|
|
113
|
+
readonly gutter?: number;
|
|
114
|
+
readonly containerStyle?: CSSProperties;
|
|
115
|
+
readonly containerClassName?: string;
|
|
116
|
+
readonly toastOptions?: DefaultToastOptions;
|
|
117
|
+
readonly children?: (item: ToastItem, helpers: ToastRowHelpers) => ReactNode;
|
|
118
|
+
}
|
|
119
|
+
export interface ToastFacade {
|
|
120
|
+
(message: Renderable, options?: ToastOptions): ToastId;
|
|
121
|
+
success(message: Renderable, options?: ToastOptions): ToastId;
|
|
122
|
+
error(message: Renderable, options?: ToastOptions): ToastId;
|
|
123
|
+
loading(message: Renderable, options?: ToastOptions): ToastId;
|
|
124
|
+
custom(message: Renderable, options?: ToastOptions): ToastId;
|
|
125
|
+
promise<TData>(promise: Promise<TData> | (() => Promise<TData>), messages: PromiseToastMessages<TData>, options?: ToastOptions): Promise<TData>;
|
|
126
|
+
dismiss(id?: ToastId, toasterId?: ToasterId): void;
|
|
127
|
+
remove(id?: ToastId, toasterId?: ToasterId): void;
|
|
128
|
+
}
|
|
129
|
+
export interface UseToasterResult {
|
|
130
|
+
readonly toasts: ReadonlyArray<ToastItem>;
|
|
131
|
+
readonly handlers: {
|
|
132
|
+
updateHeight: (id: ToastId, height: number) => void;
|
|
133
|
+
startPause: () => void;
|
|
134
|
+
endPause: () => void;
|
|
135
|
+
calculateOffset: (toast: ToastItem, options?: ToastOffsetOptions) => number;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ilokesto/toast",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/ilokesto/toast"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://ilokesto.ayden94.com/en/toast",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"module": "dist/index.js",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"toast",
|
|
23
|
+
"notification",
|
|
24
|
+
"react",
|
|
25
|
+
"overlay",
|
|
26
|
+
"hooks"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"author": "Jeong Jinho <wpfekdml@me.com>",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@ilokesto/store": "1.1.1",
|
|
35
|
+
"@ilokesto/overlay": "1.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "18.2.0",
|
|
39
|
+
"react-dom": "18.2.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^22.19.1",
|
|
43
|
+
"@types/react": "^19.1.6",
|
|
44
|
+
"@types/react-dom": "^19.1.6",
|
|
45
|
+
"typescript": "^6.0.2"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "rm -rf dist && tsc"
|
|
49
|
+
}
|
|
50
|
+
}
|