Skip to content

refactor(Modal): 重构Modal #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions packages/devui-vue/devui/modal/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import type { App } from 'vue'
import Modal from './src/modal'
import { ModalService } from './src/services/modal-service'
import { DialogService } from './src/services/dialog-service'
import { inBrowser } from '../shared/util/common-var'
import type { App } from 'vue';
import Modal from './src/modal';
import Header from './src/header';
import Body from './src/body';
import Footer from './src/footer';
import { ModalService } from './src/services/modal-service';
import { inBrowser } from '../shared/util/common-var';

Modal.install = function(app: App): void {
app.component(Modal.name, Modal)
}

export { Modal }
export { Modal };

export default {
title: 'Modal 弹窗',
category: '反馈',
status: '100%',
install(app: App): void {
app.use(Modal as any)
app.component(Modal.name, Modal);
app.component(Header.name, Header);
app.component(Body.name, Body);
app.component(Footer.name, Footer);

if (!inBrowser) {
return;
Expand All @@ -25,10 +26,9 @@ export default {
if (!anchorsContainer) {
anchorsContainer = document.createElement('div');
anchorsContainer.setAttribute('id', 'd-modal-anchors-container');
document.body.appendChild(anchorsContainer);
document.body.appendChild(anchorsContainer);
}
// 新增 modalService
app.provide(ModalService.token, new ModalService(anchorsContainer));
app.provide(DialogService.token, new DialogService(anchorsContainer));
}
}
},
};
8 changes: 8 additions & 0 deletions packages/devui-vue/devui/modal/src/body.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineComponent } from 'vue';

export default defineComponent({
name: 'DModalBody',
setup(props, { slots }) {
return () => <div class='devui-modal-body'>{slots.default?.()}</div>;
},
});
95 changes: 0 additions & 95 deletions packages/devui-vue/devui/modal/src/dialog-types.ts

This file was deleted.

135 changes: 0 additions & 135 deletions packages/devui-vue/devui/modal/src/dialog.tsx

This file was deleted.

8 changes: 8 additions & 0 deletions packages/devui-vue/devui/modal/src/footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineComponent } from 'vue';

export default defineComponent({
name: 'DModalFooter',
setup(props, { slots }) {
return () => <div class='devui-modal-footer'>{slots.default?.()}</div>;
},
});
8 changes: 8 additions & 0 deletions packages/devui-vue/devui/modal/src/header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineComponent } from 'vue';

export default defineComponent({
name: 'DModalHeader',
setup(props, { slots }) {
return () => <div class='devui-modal-header'>{slots.default?.()}</div>;
},
});
75 changes: 17 additions & 58 deletions packages/devui-vue/devui/modal/src/modal-types.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,31 @@
import type { PropType, ExtractPropTypes } from 'vue'
import type { PropType, ExtractPropTypes } from 'vue';

export const modalProps = {
// id: {
// type: String,
// required: true
// },
width: {
type: String,
default: '300px'
},
maxHeight: {
type: String,
},

zIndex: {
type: Number,
default: 1050
},
backdropZIndex: {
type: Number,
default: 1049
},

placement: {
type: String as PropType<'center' | 'top' | 'bottom'>,
default: 'center'
},
offsetX: {
type: String,
default: '0px'
modelValue: {
type: Boolean,
default: false,
},

offsetY: {
title: {
type: String,
default: '0px'
default: '',
},

showAnimation: {
lockScroll: {
type: Boolean,
default: true
default: true,
},
backdropCloseable: {
closeOnClickOverlay: {
type: Boolean,
default: true
default: true,
},
bodyScrollable: {
type: Boolean,
default: true
beforeClose: {
type: Function as PropType<(done: () => void) => void>,
},
};

escapeable: {
type: Boolean,
default: true
},
export type EmitName = 'update:modelValue';

onClose: {
type: Function as PropType<() => void>,
},
beforeHidden: {
type: [Object, Function] as PropType<Promise<boolean> | (() => boolean | Promise<boolean>)>
},
export type EmitEventFn = (event: EmitName, result?: boolean) => void;

modelValue: {
type: Boolean,
},
'onUpdate:modelValue': {
type: Function as PropType<(value: boolean) => void>
}
} as const
export type UseModalFn = { handleVisibleChange: (val: boolean) => void };

export type ModalProps = ExtractPropTypes<typeof modalProps>
export type ModalProps = ExtractPropTypes<typeof modalProps>;
Loading