-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): composables split useNoti & useNotiProvide
- Loading branch information
Showing
10 changed files
with
187 additions
and
6 deletions.
There are no files selected for viewing
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,4 +1,8 @@ | ||
import { inject } from 'vue' | ||
|
||
import { INJECT_KEY } from '../constant' | ||
|
||
export function useNoti() { | ||
// eslint-disable-next-line no-console | ||
console.log('useNoti run') | ||
const noti = inject(INJECT_KEY) | ||
return noti | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { provide, ref } from 'vue' | ||
import { useToggle } from '@vueuse/core' | ||
import { DEFAULT_SETTING, INJECT_KEY } from '../constant' | ||
|
||
export function useNotiProvide() { | ||
const notifications = ref('') | ||
const option = ref(DEFAULT_SETTING) | ||
const [isShow, toggleShow] = useToggle(false) | ||
|
||
provide(INJECT_KEY, { | ||
isShow, | ||
toggleShow, | ||
notifications, | ||
}) | ||
|
||
return { | ||
option, | ||
isShow, | ||
toggleShow, | ||
notifications, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { InjectionKey } from 'vue' | ||
import { NOTI_POSITION, NOTI_TYPE } from './types' | ||
import type { NotiContext } from './types' | ||
|
||
export const DEFAULT_SETTING = { | ||
type: NOTI_TYPE.SUCCESS, | ||
position: NOTI_POSITION.TOP_RIGHT, | ||
timeout: 3000, | ||
} | ||
|
||
export const INJECT_KEY: InjectionKey<NotiContext> = Symbol('noti') |
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 +1,3 @@ | ||
export * from './composables/useNoti' | ||
export * from './composables/useNotiProvide' | ||
export * from './types' |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { Ref } from 'vue' | ||
|
||
export enum NOTI_TYPE { | ||
SUCCESS = 'success', | ||
WARNING = 'warning', | ||
ERROR = 'error', | ||
INFO = 'info', | ||
} | ||
|
||
/** | ||
* An object containing constants for the position of notifications. | ||
*/ | ||
export const NOTI_POSITION = { | ||
/** | ||
* Notifications appear at the top right of the screen and slide in from the right. | ||
*/ | ||
TOP_RIGHT: 'top-right', | ||
|
||
/** | ||
* Notifications appear at the top left of the screen and slide in from the left. | ||
*/ | ||
TOP_LEFT: 'top-left', | ||
|
||
/** | ||
* Notifications appear at the bottom right of the screen and slide in from the right. | ||
*/ | ||
BOTTOM_RIGHT: 'bottom-right', | ||
|
||
/** | ||
* Notifications appear at the bottom left of the screen and slide in from the left. | ||
*/ | ||
BOTTOM_LEFT: 'bottom-left', | ||
|
||
/** | ||
* Notifications appear at the middle top of the screen and slide in from the top. | ||
*/ | ||
MIDDLE_TOP: 'middle-top', | ||
|
||
/** | ||
* Notifications appear at the middle left of the screen and slide in from the left. | ||
*/ | ||
MIDDLE_LEFT: 'middle-left', | ||
|
||
/** | ||
* Notifications appear at the middle right of the screen and slide in from the right. | ||
*/ | ||
MIDDLE_RIGHT: 'middle-right', | ||
} | ||
|
||
export interface NotiContext { | ||
isShow: Ref<boolean> | ||
toggleShow: (val?: boolean) => void | ||
notifications: Ref<string> | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"sourceMap": true, | ||
"module": "es2015", | ||
"target": "es2018", | ||
"moduleResolution": "node", | ||
"outDir": "./dist", | ||
"skipLibCheck": true, | ||
"declaration": true, | ||
"declarationMap": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src"], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.