feat: update drawer
parent
3642b09db8
commit
8cbd2c0035
|
@ -1 +1 @@
|
||||||
Subproject commit f3b049411f17e556d8795f40d41bfadb471ae630
|
Subproject commit adbfcd30aeb6c125defa35102ed659f1be03c672
|
|
@ -122,7 +122,16 @@ const getOptionProps = instance => {
|
||||||
const { $props = {} } = instance;
|
const { $props = {} } = instance;
|
||||||
return filterProps($props);
|
return filterProps($props);
|
||||||
};
|
};
|
||||||
|
const getComponent = (instance, prop, options = instance, execute = true) => {
|
||||||
|
const temp = instance[prop];
|
||||||
|
if (temp !== undefined) {
|
||||||
|
return typeof temp === 'function' && execute ? temp(options) : temp;
|
||||||
|
} else {
|
||||||
|
let com = instance.$slots[prop] || null;
|
||||||
|
com = execute && com ? com(options) : com;
|
||||||
|
return Array.isArray(com) && com.length === 1 ? com[0] : com;
|
||||||
|
}
|
||||||
|
};
|
||||||
const getComponentFromProp = (instance, prop, options = instance, execute = true) => {
|
const getComponentFromProp = (instance, prop, options = instance, execute = true) => {
|
||||||
if (instance.$createElement) {
|
if (instance.$createElement) {
|
||||||
const h = instance.$createElement;
|
const h = instance.$createElement;
|
||||||
|
@ -218,6 +227,9 @@ export function getEvents(child) {
|
||||||
// }
|
// }
|
||||||
// return { ...events };
|
// return { ...events };
|
||||||
}
|
}
|
||||||
|
export function getEvent(child, event) {
|
||||||
|
return child.props && child.props[event];
|
||||||
|
}
|
||||||
|
|
||||||
// 获取 xxx.native 或者 原生标签 事件
|
// 获取 xxx.native 或者 原生标签 事件
|
||||||
export function getDataEvents(child) {
|
export function getDataEvents(child) {
|
||||||
|
@ -338,6 +350,7 @@ export {
|
||||||
hasProp,
|
hasProp,
|
||||||
filterProps,
|
filterProps,
|
||||||
getOptionProps,
|
getOptionProps,
|
||||||
|
getComponent,
|
||||||
getComponentFromProp,
|
getComponentFromProp,
|
||||||
getSlotOptions,
|
getSlotOptions,
|
||||||
slotHasProp,
|
slotHasProp,
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { reactive, provide } from 'vue';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { getComponentFromProp } from '../_util/props-util';
|
import { getComponentFromProp } from '../_util/props-util';
|
||||||
import defaultRenderEmpty from './renderEmpty';
|
import defaultRenderEmpty from './renderEmpty';
|
||||||
import Base from '../base';
|
|
||||||
import LocaleProvider, { ANT_MARK } from '../locale-provider';
|
import LocaleProvider, { ANT_MARK } from '../locale-provider';
|
||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
|
|
||||||
|
@ -85,9 +84,8 @@ export const ConfigConsumerProps = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
ConfigProvider.install = function(Vue) {
|
ConfigProvider.install = function(app) {
|
||||||
Vue.use(Base);
|
app.component(ConfigProvider.name, ConfigProvider);
|
||||||
Vue.component(ConfigProvider.name, ConfigProvider);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ConfigProvider;
|
export default ConfigProvider;
|
||||||
|
|
|
@ -5,12 +5,12 @@ import VcDrawer from '../vc-drawer/src';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
|
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
|
||||||
import { getComponentFromProp, getOptionProps, getListeners } from '../_util/props-util';
|
import { getComponent, getOptionProps } from '../_util/props-util';
|
||||||
import { ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
import Base from '../base';
|
|
||||||
|
|
||||||
const Drawer = {
|
const Drawer = {
|
||||||
name: 'ADrawer',
|
name: 'ADrawer',
|
||||||
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
closable: PropTypes.bool.def(true),
|
closable: PropTypes.bool.def(true),
|
||||||
destroyOnClose: PropTypes.bool,
|
destroyOnClose: PropTypes.bool,
|
||||||
|
@ -145,9 +145,7 @@ const Drawer = {
|
||||||
},
|
},
|
||||||
renderHeader(prefixCls) {
|
renderHeader(prefixCls) {
|
||||||
const { closable, headerStyle } = this.$props;
|
const { closable, headerStyle } = this.$props;
|
||||||
// TODO
|
const title = getComponent(this, 'title');
|
||||||
// const title = getComponentFromProp(this, 'title');
|
|
||||||
const title = null;
|
|
||||||
if (!title && !closable) {
|
if (!title && !closable) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -220,13 +218,12 @@ const Drawer = {
|
||||||
} else {
|
} else {
|
||||||
offsetStyle.height = typeof height === 'number' ? `${height}px` : height;
|
offsetStyle.height = typeof height === 'number' ? `${height}px` : height;
|
||||||
}
|
}
|
||||||
// TODO
|
const handler = getComponent(this, 'handle') || false;
|
||||||
// const handler = getComponentFromProp(this, 'handle') || false;
|
|
||||||
const handler = false;
|
|
||||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||||
const prefixCls = getPrefixCls('drawer', customizePrefixCls);
|
const prefixCls = getPrefixCls('drawer', customizePrefixCls);
|
||||||
|
|
||||||
const vcDrawerProps = {
|
const vcDrawerProps = {
|
||||||
|
...this.$attrs,
|
||||||
...omit(rest, [
|
...omit(rest, [
|
||||||
'closable',
|
'closable',
|
||||||
'destroyOnClose',
|
'destroyOnClose',
|
||||||
|
@ -256,22 +253,12 @@ const Drawer = {
|
||||||
}),
|
}),
|
||||||
wrapStyle: this.getRcDrawerStyle(),
|
wrapStyle: this.getRcDrawerStyle(),
|
||||||
};
|
};
|
||||||
return (
|
return <VcDrawer {...vcDrawerProps}>{this.renderBody(prefixCls)}</VcDrawer>;
|
||||||
<VcDrawer
|
|
||||||
{...vcDrawerProps}
|
|
||||||
on={{
|
|
||||||
...getListeners(this), //TODO
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{this.renderBody(prefixCls)}
|
|
||||||
</VcDrawer>
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Drawer.install = function(app) {
|
Drawer.install = function(app) {
|
||||||
app.use(Base);
|
|
||||||
app.component(Drawer.name, Drawer);
|
app.component(Drawer.name, Drawer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,7 @@ import classnames from 'classnames';
|
||||||
import { cloneVNode, withDirectives, Teleport, nextTick } from 'vue';
|
import { cloneVNode, withDirectives, Teleport, nextTick } from 'vue';
|
||||||
import antRef from '../../_util/ant-ref';
|
import antRef from '../../_util/ant-ref';
|
||||||
import BaseMixin from '../../_util/BaseMixin';
|
import BaseMixin from '../../_util/BaseMixin';
|
||||||
import { initDefaultProps, getEvents, getListeners, getSlot } from '../../_util/props-util';
|
import { initDefaultProps, getSlot } from '../../_util/props-util';
|
||||||
// import { cloneElement } from '../../_util/vnode';
|
|
||||||
import getScrollBarSize from '../../_util/getScrollBarSize';
|
import getScrollBarSize from '../../_util/getScrollBarSize';
|
||||||
import { IDrawerProps } from './IDrawerPropTypes';
|
import { IDrawerProps } from './IDrawerPropTypes';
|
||||||
import KeyCode from '../../_util/KeyCode';
|
import KeyCode from '../../_util/KeyCode';
|
||||||
|
@ -16,7 +15,6 @@ import {
|
||||||
transformArguments,
|
transformArguments,
|
||||||
isNumeric,
|
isNumeric,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
// import Portal from '../../_util/Portal';
|
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
|
@ -27,9 +25,10 @@ const windowIsUndefined = !(
|
||||||
window.document.createElement
|
window.document.createElement
|
||||||
);
|
);
|
||||||
|
|
||||||
// Vue.use(ref, { name: 'ant-ref' });
|
|
||||||
const Drawer = {
|
const Drawer = {
|
||||||
|
name: 'Drawer',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
|
inheritAttrs: false,
|
||||||
directives: { 'ant-ref': antRef },
|
directives: { 'ant-ref': antRef },
|
||||||
props: initDefaultProps(IDrawerProps, {
|
props: initDefaultProps(IDrawerProps, {
|
||||||
prefixCls: 'drawer',
|
prefixCls: 'drawer',
|
||||||
|
@ -63,6 +62,9 @@ const Drawer = {
|
||||||
this.preProps = { ...this.$props };
|
this.preProps = { ...this.$props };
|
||||||
return {
|
return {
|
||||||
sOpen: open,
|
sOpen: open,
|
||||||
|
isOpenChange: undefined,
|
||||||
|
passive: undefined,
|
||||||
|
container: undefined,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -363,11 +365,9 @@ const Drawer = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO
|
const { onChange } = this.$attrs;
|
||||||
// const { change } = getListeners(this);
|
if (onChange && this.isOpenChange && this.sFirstEnter) {
|
||||||
const change = false;
|
onChange(open);
|
||||||
if (change && this.isOpenChange && this.sFirstEnter) {
|
|
||||||
change(open);
|
|
||||||
this.isOpenChange = false;
|
this.isOpenChange = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -385,12 +385,14 @@ const Drawer = {
|
||||||
keyboard,
|
keyboard,
|
||||||
maskClosable,
|
maskClosable,
|
||||||
} = this.$props;
|
} = this.$props;
|
||||||
|
const { class: cls, style } = this.$attrs;
|
||||||
const children = getSlot(this);
|
const children = getSlot(this);
|
||||||
const wrapperClassname = classnames(prefixCls, {
|
const wrapperClassname = classnames(prefixCls, {
|
||||||
[`${prefixCls}-${placement}`]: true,
|
[`${prefixCls}-${placement}`]: true,
|
||||||
[`${prefixCls}-open`]: open,
|
[`${prefixCls}-open`]: open,
|
||||||
[className]: !!className,
|
[className]: !!className,
|
||||||
'no-mask': !showMask,
|
'no-mask': !showMask,
|
||||||
|
[cls]: true,
|
||||||
});
|
});
|
||||||
const isOpenChange = this.isOpenChange;
|
const isOpenChange = this.isOpenChange;
|
||||||
const isHorizontal = placement === 'left' || placement === 'right';
|
const isHorizontal = placement === 'left' || placement === 'right';
|
||||||
|
@ -409,13 +411,13 @@ const Drawer = {
|
||||||
let handlerChildren;
|
let handlerChildren;
|
||||||
if (handler !== false) {
|
if (handler !== false) {
|
||||||
const handlerDefalut = (
|
const handlerDefalut = (
|
||||||
<div class="drawer-handle">
|
<div class="drawer-handle" onClick={() => {}}>
|
||||||
<i class="drawer-handle-icon" />
|
<i class="drawer-handle-icon" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
const { handler: handlerSlot } = this;
|
const { handler: handlerSlot } = this;
|
||||||
const handlerSlotVnode = handlerSlot || handlerDefalut;
|
const handlerSlotVnode = handlerSlot || handlerDefalut;
|
||||||
const { onclick: handleIconClick } = getEvents(handlerSlotVnode);
|
const handleIconClick = handlerSlotVnode.props && handlerSlotVnode.props.onClick;
|
||||||
handlerChildren = withDirectives(
|
handlerChildren = withDirectives(
|
||||||
cloneVNode(handlerSlotVnode, {
|
cloneVNode(handlerSlotVnode, {
|
||||||
onClick: e => {
|
onClick: e => {
|
||||||
|
@ -445,7 +447,7 @@ const Drawer = {
|
||||||
// ],
|
// ],
|
||||||
onTransitionend: this.onWrapperTransitionEnd,
|
onTransitionend: this.onWrapperTransitionEnd,
|
||||||
onKeydown: open && keyboard ? this.onKeyDown : noop,
|
onKeydown: open && keyboard ? this.onKeyDown : noop,
|
||||||
style: wrapStyle,
|
style: { ...wrapStyle, ...style },
|
||||||
};
|
};
|
||||||
// const directivesMaskDom = [
|
// const directivesMaskDom = [
|
||||||
// {
|
// {
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<a-button type="primary" @click="showDrawer">Open</a-button>
|
<a-button type="primary" @click="showDrawer">
|
||||||
|
Open
|
||||||
|
</a-button>
|
||||||
<a-drawer
|
<a-drawer
|
||||||
title="Multi-level drawer"
|
title="Multi-level drawer"
|
||||||
width="520"
|
width="520"
|
||||||
:closable="false"
|
:closable="false"
|
||||||
:visible="visible"
|
:visible="visible"
|
||||||
|
style="color: red"
|
||||||
@close="onClose"
|
@close="onClose"
|
||||||
>
|
>
|
||||||
<a-button type="primary" @click="showChildrenDrawer">Two-level drawer</a-button>
|
<template v-slot:handle>
|
||||||
|
<a-button @click="() => {}">
|
||||||
|
hahah
|
||||||
|
</a-button>
|
||||||
|
</template>
|
||||||
|
<a-button type="primary" @click="showChildrenDrawer">
|
||||||
|
Two-level drawer
|
||||||
|
</a-button>
|
||||||
<a-drawer
|
<a-drawer
|
||||||
title="Two-level Drawer"
|
title="Two-level Drawer"
|
||||||
width="320"
|
width="320"
|
||||||
|
@ -16,7 +26,9 @@
|
||||||
:visible="childrenDrawer"
|
:visible="childrenDrawer"
|
||||||
@close="onChildrenDrawerClose"
|
@close="onChildrenDrawerClose"
|
||||||
>
|
>
|
||||||
<a-button type="primary" @click="showChildrenDrawer">This is two-level drawer</a-button>
|
<a-button type="primary" @click="showChildrenDrawer">
|
||||||
|
This is two-level drawer
|
||||||
|
</a-button>
|
||||||
</a-drawer>
|
</a-drawer>
|
||||||
<div
|
<div
|
||||||
:style="{
|
:style="{
|
||||||
|
@ -32,8 +44,12 @@
|
||||||
boxSizing: 'border-box',
|
boxSizing: 'border-box',
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<a-button style="marginRight: 8px" @click="onClose">Cancel</a-button>
|
<a-button style="marginRight: 8px" @click="onClose">
|
||||||
<a-button type="primary" @click="onClose">Submit</a-button>
|
Cancel
|
||||||
|
</a-button>
|
||||||
|
<a-button type="primary" @click="onClose">
|
||||||
|
Submit
|
||||||
|
</a-button>
|
||||||
</div>
|
</div>
|
||||||
</a-drawer>
|
</a-drawer>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue