Skip to content

Commit

Permalink
feat(modal): add minHeight and height prop #156
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jan 2, 2021
1 parent 5c27353 commit 5091a87
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
12 changes: 1 addition & 11 deletions src/components/Form/src/BasicForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@
import type { AdvanceState } from './types/hooks';
import type { CSSProperties, Ref, WatchStopHandle } from 'vue';
import {
defineComponent,
reactive,
ref,
computed,
unref,
onMounted,
watch,
toRefs,
toRaw,
} from 'vue';
import { defineComponent, reactive, ref, computed, unref, onMounted, watch, toRefs } from 'vue';
import { Form, Row } from 'ant-design-vue';
import FormItem from './components/FormItem';
import FormAction from './components/FormAction.vue';
Expand Down
8 changes: 7 additions & 1 deletion src/components/Form/src/hooks/useFormValues.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isArray, isFunction, isObject, isString } from '/@/utils/is';
import moment from 'moment';
import { unref } from 'vue';
import { unref, nextTick } from 'vue';
import type { Ref, ComputedRef } from 'vue';
import type { FieldMapToTime, FormSchema } from '../types/form';
import { useModalContext } from '/@/components/Modal';

interface UseFormValuesContext {
transformDateFuncRef: Ref<Fn>;
Expand All @@ -18,6 +19,7 @@ export function useFormValues({
getSchema,
formModel,
}: UseFormValuesContext) {
const modalFn = useModalContext();
// Processing form values
function handleFormValues(values: Recordable) {
if (!isObject(values)) {
Expand Down Expand Up @@ -81,6 +83,10 @@ export function useFormValues({
}
});
defaultValueRef.value = obj;
nextTick(() => {
// Solve the problem of modal adaptive height calculation when the form is placed in the modal
modalFn?.redoModalHeight?.();
});
}

return { handleFormValues, initDefault };
Expand Down
2 changes: 2 additions & 0 deletions src/components/Modal/src/BasicModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
:fullScreen="fullScreenRef"
ref="modalWrapperRef"
:loading="getProps.loading"
:minHeight="getProps.minHeight"
:height="getProps.height"
:visible="visibleRef"
:modalFooterHeight="footer !== undefined && !footer ? 0 : undefined"
v-bind="omit(getProps.wrapperProps, 'visible')"
Expand Down
7 changes: 6 additions & 1 deletion src/components/Modal/src/components/ModalWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
modalHeaderHeight: propTypes.number.def(50),
modalFooterHeight: propTypes.number.def(54),
minHeight: propTypes.number.def(200),
height: propTypes.number,
footerOffset: propTypes.number.def(0),
visible: propTypes.bool,
fullScreen: propTypes.bool,
Expand Down Expand Up @@ -142,7 +143,11 @@
realHeightRef.value =
window.innerHeight - props.modalFooterHeight - props.modalHeaderHeight;
} else {
realHeightRef.value = realHeight > maxHeight ? maxHeight : realHeight + 16 + 30;
realHeightRef.value = props.height
? props.height
: realHeight > maxHeight
? maxHeight
: realHeight + 16 + 30;
}
emit('height-change', unref(realHeightRef));
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions src/components/Modal/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const { t } = useI18n();

export const modalProps = {
visible: propTypes.bool,
height: propTypes.number,
minHeight: propTypes.number,
// open drag
draggable: propTypes.bool.def(true),
centered: propTypes.bool,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Modal/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface ReturnInnerMethods extends ModalMethods {
export type UseModalInnerReturnType = [RegisterFn, ReturnInnerMethods];

export interface ModalProps {
minHeight?: number;
height?: number;
// 启用wrapper后 底部可以适当增加高度
wrapperFooterOffset?: number;
draggable?: boolean;
Expand Down Expand Up @@ -195,6 +197,7 @@ export interface ModalWrapperProps {
modalHeaderHeight: number;
modalFooterHeight: number;
minHeight: number;
height: number;
visible: boolean;
fullScreen: boolean;
useWrapper: boolean;
Expand Down

0 comments on commit 5091a87

Please sign in to comment.