Skip to content
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

feat(descriptions): make layout type to be multiple type #3252

Merged
merged 1 commit into from
Aug 2, 2024
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
5 changes: 1 addition & 4 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ export type HorizontalAlignEnum = 'left' | 'center' | 'right';

export type VerticalAlignEnum = 'top' | 'middle' | 'bottom';

export enum LayoutEnum {
VERTICAL = 'vertical',
HORIZONTAL = 'horizontal',
}
export type LayoutEnum = 'vertical' | 'horizontal';

export type ClassName = { [className: string]: any } | ClassName[] | string;

Expand Down
18 changes: 9 additions & 9 deletions src/descriptions/descriptions-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default defineComponent({
render() {
const props = this.$props;

const label = (node: TdDescriptionItem, layout: LayoutEnum = LayoutEnum.HORIZONTAL) => {
const label = (node: TdDescriptionItem, layout: LayoutEnum = 'horizontal') => {
const labelClass = [`${this.COMPONENT_NAME}__label`];

let label = null;
Expand All @@ -41,7 +41,7 @@ export default defineComponent({
const propsData: Record<string, any> = node.componentOptions.propsData || {};
span = propsData.span;
}
const labelSpan = layout === LayoutEnum.HORIZONTAL ? 1 : span;
const labelSpan = layout === 'horizontal' ? 1 : span;

return (
<td colspan={labelSpan} class={labelClass} {...{ style: this.descriptionsProps.labelStyle }}>
Expand All @@ -51,7 +51,7 @@ export default defineComponent({
);
};

const content = (node: TdDescriptionItem, layout: LayoutEnum = LayoutEnum.HORIZONTAL) => {
const content = (node: TdDescriptionItem, layout: LayoutEnum = 'horizontal') => {
const contentClass = [`${this.COMPONENT_NAME}__content`];

let content = null;
Expand All @@ -64,7 +64,7 @@ export default defineComponent({
const propsData: Record<string, any> = node.componentOptions.propsData || {};
span = propsData.span;
}
const contentSpan = span > 1 && layout === LayoutEnum.HORIZONTAL ? span * 2 - 1 : span;
const contentSpan = span > 1 && layout === 'horizontal' ? span * 2 - 1 : span;

return (
<td colspan={contentSpan} class={contentClass} {...{ style: this.descriptionsProps.contentStyle }}>
Expand All @@ -80,8 +80,8 @@ export default defineComponent({
const hh = (row: TdDescriptionItem[]) => <tr>{row.map((node) => [label(node), content(node)])}</tr>;

const hv = (row: TdDescriptionItem[]) => [
<tr>{row.map((node) => label(node, LayoutEnum.VERTICAL))}</tr>,
<tr>{row.map((node) => content(node, LayoutEnum.VERTICAL))}</tr>,
<tr>{row.map((node) => label(node, 'vertical'))}</tr>,
<tr>{row.map((node) => content(node, 'vertical'))}</tr>,
];

const vh = (row: TdDescriptionItem[]) => row.map((node) => (
Expand All @@ -94,13 +94,13 @@ export default defineComponent({
const vv = (row: TdDescriptionItem[]) => row.map((node) => [<tr>{label(node)}</tr>, <tr>{content(node)}</tr>]);

const renderRow = (row: TdDescriptionItem[]) => {
if (this.descriptionsProps.layout === LayoutEnum.HORIZONTAL) {
if (this.descriptionsProps.itemLayout === LayoutEnum.HORIZONTAL) {
if (this.descriptionsProps.layout === 'horizontal') {
if (this.descriptionsProps.itemLayout === 'horizontal') {
return hh(row);
}
return hv(row);
}
if (this.descriptionsProps.itemLayout === LayoutEnum.HORIZONTAL) {
if (this.descriptionsProps.itemLayout === 'horizontal') {
return vh(row);
}
return vv(row);
Expand Down
7 changes: 3 additions & 4 deletions src/descriptions/descriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import isNil from 'lodash/isNil';
import isArray from 'lodash/isArray';
import { defineComponent, provide, ref } from '@vue/composition-api';

import { LayoutEnum } from '../common';
import { useTNodeJSX } from '../hooks/tnode';
import { useChildComponentSlots } from '../hooks';
import { usePrefixClass } from '../hooks/useConfig';
Expand Down Expand Up @@ -71,12 +70,12 @@ export default defineComponent({
}
}

// 2. 判断布局,如果整体布局为 LayoutEnum.VERTICAL,那么直接返回即可。
if (layout === LayoutEnum.VERTICAL) {
// 2. 判断布局,如果整体布局为 'vertical',那么直接返回即可。
if (layout === 'vertical') {
return [items];
}

// 3. 布局为 LayoutEnum.HORIZONTAL 时,需要计算每一行的 item 个数
// 3. 布局为 'horizontal' 时,需要计算每一行的 item 个数
let temp: TdDescriptionItem[] = [];
let reset = column;

Expand Down
Loading