diff --git a/packages/devui-vue/devui/notification/index.ts b/packages/devui-vue/devui/notification/index.ts new file mode 100644 index 0000000000..b39bd22007 --- /dev/null +++ b/packages/devui-vue/devui/notification/index.ts @@ -0,0 +1,16 @@ +import type { App } from 'vue'; +import Notification from './src/notification'; +import NotificationService from './src/notification-service'; +export * from './src/notification-types'; + +export { Notification, NotificationService }; + +export default { + title: 'Notification 全局通知', + category: '反馈', + status: '100%', + install(app: App): void { + app.component(Notification.name, Notification); + app.config.globalProperties.$notificationService = NotificationService; + }, +}; diff --git a/packages/devui-vue/devui/notification/src/notification-icon-close.tsx b/packages/devui-vue/devui/notification/src/notification-icon-close.tsx new file mode 100644 index 0000000000..9c316db469 --- /dev/null +++ b/packages/devui-vue/devui/notification/src/notification-icon-close.tsx @@ -0,0 +1,13 @@ +import { defineComponent } from 'vue'; +import { Icon } from '../../icon'; + +export default defineComponent({ + emits: ['click'], + setup(props, { emit }) { + return () => ( +
+ ); + }, +}); diff --git a/packages/devui-vue/devui/notification/src/notification-image.tsx b/packages/devui-vue/devui/notification/src/notification-image.tsx new file mode 100644 index 0000000000..ee44c231e1 --- /dev/null +++ b/packages/devui-vue/devui/notification/src/notification-image.tsx @@ -0,0 +1,28 @@ +import { computed, defineComponent, toRefs } from 'vue'; +import type { PropType } from 'vue'; +import { NotificationType } from './notification-types'; +import { Icon } from '../../icon'; + +export default defineComponent({ + props: { + type: { + type: String as PropType${msg.info}
` - } - } - }) - await nextTick(); - expect(wrapper.find('.devui-toast-message').text()).toBe('info
'); - }) - it('toast has detail', async() => { - const wrapper = mount(Toast, { - props: { - value: [ - { - severity: 'success', - detail : 'detail' - } - ] - } - }); - await nextTick(); - expect(wrapper.find('.devui-toast-message').text()).toBe('detail'); - }) - }) - - describe('toast type', () => { - it('toast should be success', async () => { - const wrapper = mount(Toast, { - props: { - value: [ - { - severity: 'success' - } - ] - } - }); - await nextTick(); - expect(wrapper.find('.devui-toast-message-success').exists()).toBe(true); - }); - it('toast should be common', async() => { - const wrapper = mount(Toast, { - props: { - value: [ - { - severity: 'common' - } - ] - } - }); - await nextTick(); - expect(wrapper.find('.devui-toast-message-common').exists()).toBe(true); - }) - it('toast should be info', async() => { - const wrapper = mount(Toast, { - props: { - value: [ - { - severity: 'info' - } - ] - } - }); - await nextTick(); - expect(wrapper.find('.devui-toast-message-info').exists()).toBe(true); - }) - it('toast should be error', async() => { - const wrapper = mount(Toast, { - props: { - value: [ - { - severity: 'error' - } - ] - } - }); - await nextTick(); - expect(wrapper.find('.devui-toast-message-error').exists()).toBe(true); - }) - it('toast should be warning', async() => { - const wrapper = mount(Toast, { - props: { - value: [ - { - severity: 'warning' - } - ] - } - }) - await nextTick(); - expect(wrapper.find('.devui-toast-message-warning').exists()).toBe(true); - }) - }) - - describe('toast life and sticky', () => { - const value = [ - { - severity: 'success', - summary: 'summary' - } - ]; - beforeEach(() => { - jest.useFakeTimers(); - }) - it('has life, should close after 5000ms', async() => { - const wrapper = mount(Toast, { - props: { - value: value, - life: 5000 - } - }) - jest.advanceTimersToNextTimer(3000); - await nextTick(); - expect(wrapper.find('.devui-toast-item-container')).toBeTruthy(); - jest.advanceTimersToNextTimer(2000); - await nextTick(); - expect(wrapper.find('.devui-toast-item-container').exists()).toBeFalsy(); - }) - it('has life and sticky, not dismiss should close', async() => { - const wrapper = mount(Toast, { - props:{ - value: value, - life: 5000, - sticky: true - } - }) - jest.advanceTimersByTime(3000); - await nextTick(); - expect(wrapper.find('.devui-toast-item-container').exists()).toBe(true); - jest.advanceTimersByTime(2000); - await nextTick(); - expect(wrapper.find('.devui-toast-item-container').exists()).toBe(true); - await wrapper.find('.devui-toast-icon-close').trigger('click'); - jest.advanceTimersByTime(300); - await nextTick(); - expect(wrapper.find('.devui-toast-item-container').exists()).toBe(false); - }) - }) - - describe('toast single and global life mode', () => { - beforeEach(() => { - jest.useFakeTimers(); - }) - it('dismiss by global life mode', async() => { - const wrapper = mount(Toast,{ - props: { - value: [ - { severity: 'success', life: 3000, summary: 'success' }, - { severity: 'info', life: 5000, summary: 'info'}, - { severity: 'error',summary: 'error' } - ], - lifeMode: 'global' - } - }) - await nextTick(); - expect(wrapper.find('.devui-toast-message-success')).toBeTruthy(); - expect(wrapper.find('.devui-toast-message-info')).toBeTruthy(); - expect(wrapper.find('.devui-toast-message-error')).toBeTruthy(); - jest.advanceTimersByTime(5300); - await nextTick(); - expect(wrapper.find('.devui-toast-message-success').exists()).toBeFalsy(); - expect(wrapper.find('.devui-toast-message-info').exists()).toBeFalsy(); - expect(wrapper.find('.devui-toast-message-error').exists()).toBeFalsy(); - expect(wrapper.find('.devui-toast').text()).toBe(''); - }) - it('dismiss by singel life mode', async() => { - const wrapper = mount(Toast, { - props: { - value: [ - { life: 3000, severity: 'info', summary: 'info', detail: 'info content' }, - { life: 6000, severity: 'success', summary: 'success', detail: 'success content' } - ], - lifeMode: 'single' - } - }) - await nextTick(); - expect(wrapper.find('.devui-toast-message-info').exists()).toBe(true); - expect(wrapper.find('.devui-toast-message-success').exists()).toBe(true); - jest.advanceTimersByTime(3300); - await nextTick(); - expect(wrapper.find('.devui-toast-message-info').exists()).toBe(false); - expect(wrapper.find('.devui-toast-message-success').exists()).toBe(true); - jest.advanceTimersByTime(3000); - await nextTick(); - expect(wrapper.find('.devui-toast-message-info').exists()).toBe(false); - expect(wrapper.find('.devui-toast-message-success').exists()).toBe(false); - jest.runAllTimers(); - await nextTick(); - expect(wrapper.find('.devui-toast').text()).toBe(''); - }) - //TODO: mouseenter 没起作用 - describe('toast multiple', () => { - beforeEach(() => { - jest.useFakeTimers(); - }) - it('mouse over not dismiss, mouse out dismiss', async() => { - const wrapper = mount(Toast, { - props: { - value: [ - { severity: 'info', summary: 'info', detail: 'info content' }, - { severity: 'success', summary: 'success', detail: 'success content' } - ], - life: 5000 - } - }) - await nextTick(); - expect(wrapper.find('.devui-toast-message-info').exists()).toBe(true); - expect(wrapper.find('.devui-toast-message-success').exists()).toBe(true); - await wrapper.findAll('.devui-toast-item-container')[0].trigger('mouseenter'); - jest.advanceTimersByTime(5000); - await nextTick(); - expect(wrapper.find('.devui-toast-message-info').exists()).toBe(true); - await wrapper.find('.devui-toast-message-info').trigger('mouseleave'); - jest.runAllTimers(); - await nextTick(); - expect(wrapper.find('.devui-toast-item-container').exists()).toBe(false); - }) - }) - - describe('toast styleClass and style', () => { - it('add styleclass and style', async() => { - const wrapper = mount(Toast, { - props: { - value: [ - { severity: 'info', summary: 'info', detail: 'info content' } - ], - styleClass: 'myClass', - style: { - color: 'rgb(255, 255, 255)' - } - } - }) - await nextTick(); - expect(wrapper.find('.devui-toast').classes()).toContain('myClass'); - expect(wrapper.find('.devui-toast').attributes('style')).toBe('z-index: 1076; color: rgb(255, 255, 255);'); - }) - }) - }) -}) \ No newline at end of file diff --git a/packages/devui-vue/devui/toast/index.ts b/packages/devui-vue/devui/toast/index.ts deleted file mode 100644 index 705ee20d4a..0000000000 --- a/packages/devui-vue/devui/toast/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { App } from 'vue' -import Toast from './src/toast' -import ToastService from './src/toast-service' - -Toast.install = function(app: App) { - app.component(Toast.name, Toast) -} - -export { Toast, ToastService } - -export default { - title: 'Toast 全局提示', - category: '反馈', - status: '100%', - install(app: App): void { - app.use(Toast as any) - app.config.globalProperties.$toastService = ToastService - } -} diff --git a/packages/devui-vue/devui/toast/src/hooks/use-toast-constant.ts b/packages/devui-vue/devui/toast/src/hooks/use-toast-constant.ts deleted file mode 100644 index af0627dec1..0000000000 --- a/packages/devui-vue/devui/toast/src/hooks/use-toast-constant.ts +++ /dev/null @@ -1,11 +0,0 @@ -export function useToastConstant() { - const ANIMATION_NAME = 'slide-in' - const ANIMATION_TIME = 300 - const ID_PREFIX = 'toast-message' - - return { - ANIMATION_TIME, - ANIMATION_NAME, - ID_PREFIX - } as const -} diff --git a/packages/devui-vue/devui/toast/src/hooks/use-toast-event.ts b/packages/devui-vue/devui/toast/src/hooks/use-toast-event.ts deleted file mode 100644 index 45c7f16fa9..0000000000 --- a/packages/devui-vue/devui/toast/src/hooks/use-toast-event.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { getCurrentInstance } from 'vue' -import { Message } from '../toast-types' -import { useToastConstant } from './use-toast-constant' - -const { ANIMATION_TIME } = useToastConstant() - -export function useToastEvent() { - const ctx = getCurrentInstance() - - function onCloseEvent(msg: Message) { - ctx.emit('closeEvent', msg) - } - - function onValueChange(msgs: Message[]) { - ctx.emit('valueChange', msgs) - } - - function onHidden() { - setTimeout(() => (ctx.attrs.onHidden as () => void)?.(), ANIMATION_TIME) - } - - return { onCloseEvent, onValueChange, onHidden } -} diff --git a/packages/devui-vue/devui/toast/src/hooks/use-toast-helper.ts b/packages/devui-vue/devui/toast/src/hooks/use-toast-helper.ts deleted file mode 100644 index a6cd71720b..0000000000 --- a/packages/devui-vue/devui/toast/src/hooks/use-toast-helper.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Message } from '../toast-types' - -export function useToastHelper() { - function severityDelay(msg: Message) { - switch (msg.severity) { - case 'warning': - case 'error': - return 10e3 - default: - return 5e3 - } - } - - return { severityDelay } -} diff --git a/packages/devui-vue/devui/toast/src/hooks/use-toast-z-index.ts b/packages/devui-vue/devui/toast/src/hooks/use-toast-z-index.ts deleted file mode 100644 index 22e2519012..0000000000 --- a/packages/devui-vue/devui/toast/src/hooks/use-toast-z-index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export let toastZIndex = 1060 - -export function toastIncrease() { - toastZIndex++ -} diff --git a/packages/devui-vue/devui/toast/src/toast-icon-close.tsx b/packages/devui-vue/devui/toast/src/toast-icon-close.tsx deleted file mode 100644 index 6ded5f19fb..0000000000 --- a/packages/devui-vue/devui/toast/src/toast-icon-close.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { defineComponent, PropType } from 'vue' -import { Icon } from '../../icon' - -export default defineComponent({ - name: 'DToastIconClose', - props: { - prefixCls: String, - onClick: Function as PropType<(e: MouseEvent) => void> - }, - emits: ['click'], - render() { - const { prefixCls, $emit } = this - - const wrapperCls = `${prefixCls}-icon-close` - - return ( -