Skip to content

Commit

Permalink
feat(core): composables split useNoti & useNotiProvide
Browse files Browse the repository at this point in the history
  • Loading branch information
Rock070 committed Aug 22, 2023
1 parent 17b06e9 commit db0e453
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"name": "@vue3-noti/core",
"version": "1.0.0",
"description": "",

"source": "src/main.ts",
"author": "",

"license": "ISC",
"keywords": [],
"exports": {
Expand All @@ -21,5 +19,8 @@
"scripts": {
"clean": "rimraf dist",
"build": "rimraf dist && rollup -c"
},
"dependencies": {
"@vueuse/core": "^10.3.0"
}
}
15 changes: 15 additions & 0 deletions packages/core/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module.exports = [
* Bundle an index.esm for global import.
*/
{
globals: {
vue: 'Vue',
},
name: '@vue3-noti',
format: 'esm',
dir: 'dist',
Expand All @@ -49,6 +52,9 @@ module.exports = [
],
output: [
{
globals: {
vue: 'Vue',
},
name: '@vue3-noti',
format: 'cjs',
dir: 'dist',
Expand All @@ -61,13 +67,18 @@ module.exports = [
{
input: source,
external: ['vue', '@vueuse/core'], // External dependencies that are not bundled

plugins: [
typescript({
clean: true,
}),
],
output: [
{
globals: {
'vue': 'Vue',
'@vueuse/core': '@vueuse/core',
},
name: '@vue3-noti',
format: 'umd',
dir: 'dist',
Expand All @@ -79,10 +90,14 @@ module.exports = [
// d.ts for types
{
input: source,
external: ['vue', '@vueuse/core'], // External dependencies that are not bundled
output: [{
name: '@vue3-noti',
format: 'es',
dir: 'dist',
globals: {
vue: 'Vue',
},
entryFileNames: 'index.d.ts',
}],
plugins: [dts()],
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/composables/useNoti.ts
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
}
22 changes: 22 additions & 0 deletions packages/core/src/composables/useNotiProvide.ts
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,
}
}
11 changes: 11 additions & 0 deletions packages/core/src/constant.ts
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')
2 changes: 2 additions & 0 deletions packages/core/src/main.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './composables/useNoti'
export * from './composables/useNotiProvide'
export * from './types'
54 changes: 54 additions & 0 deletions packages/core/src/types.ts
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>
}
24 changes: 24 additions & 0 deletions packages/core/tsconfig.json
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"
]
}
2 changes: 1 addition & 1 deletion playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"moduleResolution": "node",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
Expand Down
50 changes: 49 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db0e453

Please sign in to comment.