feat: update descriptions

pull/2415/head
tangjinzhou 2020-06-11 23:07:48 +08:00
parent e5924d5ded
commit 237d55aa3e
4 changed files with 22 additions and 34 deletions

View File

@ -102,7 +102,7 @@ const getOptionProps = instance => {
Object.keys(instance.$props).forEach(k => { Object.keys(instance.$props).forEach(k => {
const v = instance.$props[k]; const v = instance.$props[k];
if (v !== undefined || k in props) { if (v !== undefined || k in props) {
res[k] = v; res[k] = k in props ? props[k] : v;
} }
}); });
} else if (isVNode(instance) && typeof instance.type === 'object') { } else if (isVNode(instance) && typeof instance.type === 'object') {
@ -111,7 +111,7 @@ const getOptionProps = instance => {
Object.keys(allProps).forEach(k => { Object.keys(allProps).forEach(k => {
const v = allProps[k].default; const v = allProps[k].default;
if (v !== undefined || k in props) { if (v !== undefined || k in props) {
res[k] = v; res[k] = k in props ? props[k] : v;
} }
}); });
} }

View File

@ -1,29 +1,13 @@
import PropTypes from '../_util/vue-types';
import { getOptionProps } from '../_util/props-util'; import { getOptionProps } from '../_util/props-util';
const ColProps = {
child: PropTypes.any,
bordered: PropTypes.bool,
colon: PropTypes.bool,
type: PropTypes.oneOf(['label', 'content']),
layout: PropTypes.oneOf(['horizontal', 'vertical']),
};
const Col = (_, { attrs }) => { const Col = (_, { attrs }) => {
// props: { const { child = {}, bordered, colon, type, layout, colKey: key } = attrs;
// child: PropTypes.any,
// bordered: PropTypes.bool,
// colon: PropTypes.bool,
// type: PropTypes.oneOf(['label', 'content']),
// layout: PropTypes.oneOf(['horizontal', 'vertical']),
// }
const { child, bordered, colon, type, layout } = attrs;
const { prefixCls, span = 1 } = getOptionProps(child); const { prefixCls, span = 1 } = getOptionProps(child);
const { key, children = {} } = child || {}; const { children = {} } = child;
const label = children.label && children.label(); const label = children.label && children.label();
const defaultSlot = children.default && children.default(); const defaultSlot = children.default && children.default();
const someLabelProps = { const labelProps = {
class: [ class: [
`${prefixCls}-item-label`, `${prefixCls}-item-label`,
{ {
@ -35,12 +19,12 @@ const Col = (_, { attrs }) => {
}; };
if (layout === 'vertical') { if (layout === 'vertical') {
someLabelProps.colSpan = span * 2 - 1; labelProps.colSpan = span * 2 - 1;
} }
if (bordered) { if (bordered) {
if (type === 'label') { if (type === 'label') {
return <th {...someLabelProps}>{label}</th>; return <th {...labelProps}>{label}</th>;
} }
return ( return (
<td class={`${prefixCls}-item-content`} key={`${key}-content`} colSpan={span * 2 - 1}> <td class={`${prefixCls}-item-content`} key={`${key}-content`} colSpan={span * 2 - 1}>
@ -71,7 +55,7 @@ const Col = (_, { attrs }) => {
} }
return ( return (
<td colSpan={span} class={`${prefixCls}-item`}> <td colSpan={span} class={`${prefixCls}-item`}>
<span {...someLabelProps}>{label}</span> <span {...labelProps}>{label}</span>
<span class={`${prefixCls}-item-content`} key={`${key}-content`}> <span class={`${prefixCls}-item-content`} key={`${key}-content`}>
{defaultSlot} {defaultSlot}
</span> </span>

View File

@ -1,10 +1,15 @@
import { inject, isVNode, cloneVNode } from 'vue'; import { inject, cloneVNode } from 'vue';
import warning from '../_util/warning'; import warning from '../_util/warning';
import ResponsiveObserve, { responsiveArray } from '../_util/responsiveObserve'; import ResponsiveObserve, { responsiveArray } from '../_util/responsiveObserve';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
import Col from './Col'; import Col from './Col';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { initDefaultProps, getOptionProps, getComponent } from '../_util/props-util'; import {
initDefaultProps,
getOptionProps,
getComponent,
isValidElement,
} from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin'; import BaseMixin from '../_util/BaseMixin';
export const DescriptionsItemProps = { export const DescriptionsItemProps = {
@ -65,9 +70,7 @@ const generateChildrenRows = (children, column) => {
if (lastItem) { if (lastItem) {
lastSpanSame = !itemProps.span || itemProps.span === leftSpans; lastSpanSame = !itemProps.span || itemProps.span === leftSpans;
itemNode = cloneVNode(itemNode, { itemNode = cloneVNode(itemNode, {
props: { span: leftSpans,
span: leftSpans,
},
}); });
} }
@ -145,6 +148,7 @@ const Descriptions = {
colon={colon} colon={colon}
type={type} type={type}
key={`${type}-${colItem.key || idx}`} key={`${type}-${colItem.key || idx}`}
colKey={`${type}-${colItem.key || idx}`}
layout={layout} layout={layout}
/> />
); );
@ -201,7 +205,7 @@ const Descriptions = {
layout = 'horizontal', layout = 'horizontal',
colon = true, colon = true,
} = this.$props; } = this.$props;
const title = getComponent(this, 'title') || null; const title = getComponent(this, 'title');
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('descriptions', customizePrefixCls); const prefixCls = getPrefixCls('descriptions', customizePrefixCls);
@ -209,11 +213,9 @@ const Descriptions = {
const children = this.$slots.default && this.$slots.default(); const children = this.$slots.default && this.$slots.default();
const cloneChildren = toArray(children) const cloneChildren = toArray(children)
.map(child => { .map(child => {
if (isVNode(child)) { if (isValidElement(child)) {
return cloneVNode(child, { return cloneVNode(child, {
props: { prefixCls,
prefixCls,
},
}); });
} }
return null; return null;

View File

@ -20,6 +20,7 @@ import Timeline from 'ant-design-vue/timeline';
import Col from 'ant-design-vue/col'; import Col from 'ant-design-vue/col';
import Row from 'ant-design-vue/row'; import Row from 'ant-design-vue/row';
import Tooltip from 'ant-design-vue/tooltip'; import Tooltip from 'ant-design-vue/tooltip';
import Descriptions from 'ant-design-vue/descriptions';
import 'ant-design-vue/style.js'; import 'ant-design-vue/style.js';
createApp(App) createApp(App)
@ -42,4 +43,5 @@ createApp(App)
.use(Col) .use(Col)
.use(Row) .use(Row)
.use(Tooltip) .use(Tooltip)
.use(Descriptions)
.mount('#app'); .mount('#app');