feat(message): tusimple theme danger type

This commit is contained in:
07akioni 2021-02-11 21:58:31 +08:00
parent 47b481d002
commit 3f56b7f1ae
5 changed files with 44 additions and 7 deletions

View File

@ -1,2 +1,7 @@
export { default as NMessagePrivider } from './src/MessageProvider'
export { useMessage } from './src/use-message'
export type {
MessageOptions,
MessageApiInjection,
MessageReactive
} from './src/MessageProvider'

View File

@ -23,11 +23,11 @@ export interface MessageOptions {
}
export interface MessageApiInjection {
info: (content: string, options: MessageOptions) => void
success: (content: string, options: MessageOptions) => void
warning: (content: string, options: MessageOptions) => void
error: (content: string, options: MessageOptions) => void
loading: (content: string, options: MessageOptions) => void
info: (content: string, options: MessageOptions) => MessageReactive
success: (content: string, options: MessageOptions) => MessageReactive
warning: (content: string, options: MessageOptions) => MessageReactive
error: (content: string, options: MessageOptions) => MessageReactive
loading: (content: string, options: MessageOptions) => MessageReactive
}
export interface MessageReactive {

View File

@ -1,6 +1,9 @@
import { inject } from 'vue'
import { throwError } from '../../_utils'
import type { MessageApiInjection } from './MessageProvider'
export function useMessage (): MessageApiInjection | undefined {
return inject<MessageApiInjection>('message')
export function useMessage (): MessageApiInjection {
const api = inject<MessageApiInjection>('message')
if (api === undefined) { throwError('use-message', 'No out <n-message-provider /> founded.') }
return api
}

View File

@ -1,2 +1,3 @@
export { default as TsConfigProvider } from './ts-config-provider'
export { useDialog } from './use-ts-dialog'
export { useMessage } from './use-ts-message'

View File

@ -0,0 +1,28 @@
import {
useMessage as _useMessage,
MessageOptions,
MessageReactive,
MessageApiInjection
} from 'naive-ui'
import { icons } from './icons'
export interface ExtendedApi {
danger: (content: string, options: MessageOptions) => MessageReactive
}
export type TsMessageApi = MessageApiInjection & ExtendedApi
function useMessage (): TsMessageApi {
const messageApi = _useMessage()
const extendedApi: ExtendedApi = {
danger: (content: string, options: MessageOptions) => {
return messageApi.error(content, {
...options,
icon: icons.warning
})
}
}
return Object.assign(extendedApi, messageApi)
}
export { useMessage }