-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade react and dependent package and changed the type names
- Loading branch information
Showing
5 changed files
with
84 additions
and
98 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,42 @@ | ||
import { contentTypes, callbackFuncTypes, ToastOptionsInterface } from './types/react-tiny-toast'; | ||
import { | ||
Content, | ||
callbackFuncTypes, | ||
ToastOptionsInterface, | ||
} from "./types/react-tiny-toast"; | ||
|
||
const defaultOptions: ToastOptionsInterface = { | ||
delay: 0, | ||
timeout: 2000, | ||
position: "top-center" | ||
} | ||
export const toastManager = (function() { | ||
position: "top-center", | ||
}; | ||
export const toastManager = (function () { | ||
let callbackFn: callbackFuncTypes; | ||
const manager = { | ||
subscribe(callback: callbackFuncTypes): void { | ||
callbackFn = callback; | ||
}, | ||
add(content: contentTypes, options: ToastOptionsInterface) { | ||
add(content: Content, options: ToastOptionsInterface) { | ||
const mergedOptions = { ...defaultOptions, ...options }; | ||
const timeoutId = window.setTimeout(() => { | ||
callbackFn('ADD', content, {...mergedOptions, id: timeoutId}); | ||
callbackFn("ADD", content, { ...mergedOptions, id: timeoutId }); | ||
}, mergedOptions.delay); | ||
return timeoutId; | ||
}, | ||
remove(id: number) { | ||
callbackFn('REMOVE', null, { id }) | ||
callbackFn("REMOVE", null, { id }); | ||
return true; | ||
} | ||
} | ||
}, | ||
}; | ||
return manager; | ||
})(); | ||
|
||
const toast = { | ||
show: (content: contentTypes, options: ToastOptionsInterface) => { | ||
return toastManager.add(content, options) | ||
show: (content: Content, options: ToastOptionsInterface) => { | ||
return toastManager.add(content, options); | ||
}, | ||
remove: (id: number) => { | ||
return toastManager.remove(id) | ||
} | ||
} | ||
return toastManager.remove(id); | ||
}, | ||
}; | ||
|
||
export default toast; | ||
export default toast; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
|
||
import { ReactChild, ReactNode } from "react"; | ||
import { POSITIONS, VARIANTS, ACTIONS } from ".."; | ||
import toast from '../toast'; | ||
import ToastContainer from '../ToastContainer'; | ||
import toast from "../toast"; | ||
import ToastContainer from "../ToastContainer"; | ||
|
||
export type variantTypes = typeof VARIANTS[keyof typeof VARIANTS]; | ||
export type positionTypes = typeof POSITIONS[keyof typeof POSITIONS]; | ||
export type actionTypes = typeof ACTIONS[keyof typeof ACTIONS]; | ||
export type contentTypes = ReactChild | ReactNode | null; | ||
export type Variant = (typeof VARIANTS)[keyof typeof VARIANTS]; | ||
export type Position = (typeof POSITIONS)[keyof typeof POSITIONS]; | ||
export type Action = (typeof ACTIONS)[keyof typeof ACTIONS]; | ||
export type Content = ReactChild | ReactNode | null; | ||
export interface ToastOptionsInterface { | ||
delay?: number; | ||
timeout?: number; | ||
position?: positionTypes; | ||
position?: Position; | ||
pause?: boolean; | ||
className?: string; | ||
variant?: variantTypes; | ||
variant?: Variant; | ||
uniqueCode?: string | number; | ||
} | ||
|
||
export interface optionTypes extends ToastOptionsInterface { | ||
export interface Options extends ToastOptionsInterface { | ||
id: number; | ||
key?: string; | ||
} | ||
|
||
export type callbackFuncTypes = ( | ||
type: actionTypes, | ||
content: contentTypes, | ||
options: optionTypes | ||
) => void | ||
type: Action, | ||
content: Content, | ||
options: Options | ||
) => void; | ||
|
||
export { VARIANTS, POSITIONS, ACTIONS, toast, ToastContainer }; | ||
export { VARIANTS, POSITIONS, ACTIONS, toast, ToastContainer }; |