Skip to content

Commit

Permalink
Merge pull request #269 from lanniuniu/develop
Browse files Browse the repository at this point in the history
fix: 兼容ie grid组件 增加属性row-gap
  • Loading branch information
chaishi authored Jan 19, 2022
2 parents 692b38a + d56aaf4 commit 95e9997
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/grid/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ import Vue, { VNode } from 'vue';
import isObject from 'lodash/isObject';
import { prefix } from '../config';
import props from './row-props';
import { ClassName } from '../common';
import { ClassName, Styles } from '../common';
import { calcSize } from '../utils/responsive';
import { TdRowProps } from './type';
import { getIEVersion } from '../utils/helper';

const name = `${prefix}-row`;

export interface RowHTMLTagAttributes {
class: ClassName;
style: Styles;
attrs?: {
'row-gap'?: number;
}
}

export default Vue.extend({
name: 'TRow',

Expand Down Expand Up @@ -53,7 +62,7 @@ export default Vue.extend({
this.size = calcSize(window.innerWidth);
},

calcRowStyle(gutter: TdRowProps['gutter'], currentSize: string): object {
calcRowStyle(gutter: TdRowProps['gutter'], currentSize: string): Styles {
const rowStyle = {};
if (typeof gutter === 'number') {
Object.assign(rowStyle, {
Expand Down Expand Up @@ -96,13 +105,39 @@ export default Vue.extend({
}
return rowStyle;
},

rowGap(gutter: TdRowProps['gutter'], currentSize: string): number {
let rowGap;
if (Array.isArray(gutter) && gutter.length) {
if (typeof gutter[1] === 'number') {
[, rowGap] = gutter;
}
if (isObject(gutter[1]) && gutter[1][currentSize] !== undefined) {
rowGap = gutter[1][currentSize];
}
} else if (isObject(gutter) && gutter[currentSize]) {
if (Array.isArray(gutter[currentSize]) && gutter[currentSize].length) {
[, rowGap] = gutter[currentSize];
}
}
return rowGap;
},
},

render(): VNode {
const { tag, classes } = this;

const rowStyle = this.calcRowStyle(this.gutter, this.size);

return <tag class={classes} style={rowStyle}>{this.$slots.default}</tag>;
const attributes: RowHTMLTagAttributes = {
class: classes,
style: rowStyle,
attrs: {},
};
if (getIEVersion() <= 9) {
const rowGap = this.rowGap(this.gutter, this.size);
attributes.attrs['row-gap'] = rowGap;
}
return <tag {...attributes}>{this.$slots.default}</tag>;
},
});

0 comments on commit 95e9997

Please sign in to comment.