diff --git a/components/drawer/index.jsx b/components/drawer/index.jsx index 56c7f959a..8425cbdad 100644 --- a/components/drawer/index.jsx +++ b/components/drawer/index.jsx @@ -4,6 +4,7 @@ import PropTypes from '../_util/vue-types'; import BaseMixin from '../_util/BaseMixin'; import Icon from '../icon'; import { getComponentFromProp, getOptionProps } from '../_util/props-util'; +import { ConfigConsumerProps } from '../config-provider'; const Drawer = { name: 'ADrawer', @@ -20,7 +21,7 @@ const Drawer = { width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).def(256), height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).def(256), zIndex: PropTypes.number, - prefixCls: PropTypes.string.def('ant-drawer'), + prefixCls: PropTypes.string, placement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']).def('right'), level: PropTypes.any.def(null), wrapClassName: PropTypes.string, // not use class like react, vue will add class to root dom @@ -28,7 +29,7 @@ const Drawer = { }, mixins: [BaseMixin], data() { - this.destoryClose = false; + this.destroyClose = false; this.preVisible = this.$props.visible; return { _push: false, @@ -38,6 +39,7 @@ const Drawer = { parentDrawer: { default: () => null, }, + configProvider: { default: () => ({}) }, }, provide() { return { @@ -79,18 +81,18 @@ const Drawer = { _push: false, }); }, - onDestoryTransitionEnd() { - const isDestroyOnClose = this.getDestoryOnClose(); + onDestroyTransitionEnd() { + const isDestroyOnClose = this.getDestroyOnClose(); if (!isDestroyOnClose) { return; } if (!this.visible) { - this.destoryClose = true; + this.destroyClose = true; this.$forceUpdate(); } }, - getDestoryOnClose() { + getDestroyOnClose() { return this.destroyOnClose && !this.visible; }, // get drawar push width or height @@ -102,13 +104,47 @@ const Drawer = { return `translateY(${placement === 'top' ? 180 : -180}px)`; } }, + getRcDrawerStyle() { + const { zIndex, placement, maskStyle, wrapStyle } = this.$props; + const { _push: push } = this.$data; + return { + ...maskStyle, + zIndex, + transform: push ? this.getPushTransform(placement) : undefined, + ...wrapStyle, + }; + }, + renderHeader(prefixCls) { + const { closable } = this.$props; + const title = getComponentFromProp(this, 'title'); + if (!title && !closable) { + return null; + } + + const headerClassName = title ? `${prefixCls}-header` : `${prefixCls}-header-no-title`; + return ( +
+ {title &&
{title}
} + {closable ? this.renderCloseIcon(prefixCls) : null} +
+ ); + }, + renderCloseIcon(prefixCls) { + return ( + + ); + }, // render drawer body dom - renderBody() { - if (this.destoryClose && !this.visible) { + renderBody(prefixCls) { + if (this.destroyClose && !this.visible) { return null; } - this.destoryClose = false; - const { placement } = this.$props; + this.destroyClose = false; + const { + placement, + } = this.$props; const containerStyle = placement === 'left' || placement === 'right' @@ -118,63 +154,34 @@ const Drawer = { } : {}; - const isDestroyOnClose = this.getDestoryOnClose(); + const isDestroyOnClose = this.getDestroyOnClose(); if (isDestroyOnClose) { // Increase the opacity transition, delete children after closing. containerStyle.opacity = 0; containerStyle.transition = 'opacity .3s'; } - const { prefixCls, closable } = this.$props; - const title = getComponentFromProp(this, 'title'); - // is have header dom - let header; - if (title) { - header = ( -
-
{title}
-
- ); - } - // is have closer button - let closer; - if (closable) { - closer = ( - - ); - } return (
- {header} - {closer} + {this.renderHeader(prefixCls)}
{this.$slots.default}
); }, - getRcDrawerStyle() { - const { zIndex, placement, maskStyle, wrapStyle } = this.$props; - const { _push: push } = this.$data; - return { - ...maskStyle, - zIndex, - transform: push ? this.getPushTransform(placement) : undefined, - ...wrapStyle, - }; - }, }, render() { const props = getOptionProps(this); - const { width, height, visible, placement, wrapClassName, ...rest } = props; + const { + prefixCls: customizePrefixCls, + width, height, visible, + placement, wrapClassName, ...rest + } = props; const haveMask = rest.mask ? '' : 'no-mask'; const offsetStyle = {}; if (placement === 'left' || placement === 'right') { @@ -183,11 +190,15 @@ const Drawer = { offsetStyle.height = typeof height === 'number' ? `${height}px` : height; } const handler = getComponentFromProp(this, 'handle') || false; + const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls; + const prefixCls = getPrefixCls('drawer', customizePrefixCls); + const vcDrawerProps = { props: { ...rest, handler, ...offsetStyle, + prefixCls, open: visible, showMask: props.mask, placement, @@ -202,7 +213,7 @@ const Drawer = { ...this.$listeners, }, }; - return {this.renderBody()}; + return {this.renderBody(prefixCls)}; }, }; diff --git a/components/drawer/style/index.js b/components/drawer/style/index.js index 416ec0177..3a3ab0de5 100644 --- a/components/drawer/style/index.js +++ b/components/drawer/style/index.js @@ -1,5 +1,2 @@ import '../../style/index.less'; import './index.less'; - -// style dependencies -import '../../button/style';