Skip to content

Commit cfaef6e

Browse files
better?
1 parent b9166de commit cfaef6e

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/components/presets/Table.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import VueContentLoading from '../VueContentLoading';
22

3-
const getXPos = column => 5 + ((column - 1) * 100) + ((column - 1) * 20);
4-
const getYPos = row => (row - 1) * 30;
5-
63
export default {
74
functional: true,
85

96
props: {
7+
header: {
8+
type: Boolean,
9+
required: false,
10+
default: true,
11+
},
12+
1013
rows: {
1114
type: Number,
1215
required: false,
1316
default: 5,
1417
},
1518

1619
columns: {
17-
type: Number,
20+
type: [
21+
Number, Array,
22+
],
1823
required: false,
1924
default: 4,
25+
validate: columns => typeof columns === 'number' || columns.filter(width => typeof width === 'number'),
2026
},
2127
},
2228

@@ -28,17 +34,26 @@ export default {
2834
rows,
2935
columns,
3036
} = props;
37+
const gutter = 3;
38+
const is_array = typeof columns === 'array';
39+
const length = is_array
40+
? columns.length
41+
: columns;
42+
const height = 5;
43+
const width = (100 - (length * gutter)) / length;
44+
const table = [
3145

32-
const table = [];
33-
const height = (rows * 30) - 20;
34-
const width = ((columns - 1) * 20) + 10 + (columns * 100);
46+
];
3547

36-
for (let row = 0; row <= rows; row++) {
37-
for (let column = 0; column <= columns; column++) {
38-
table.push(<rect x={getXPos(column)} y={getYPos(row)} rx="3" ry="3" width="100" height="10" />)
39-
}
48+
for (let row = 0; row < rows; row++) {
49+
for (let column = 0; column < length; column++) {
50+
const y = (height + gutter) * row;
51+
const x = column * (width + gutter);
4052

41-
table.push(<rect y={getYPos(row) + 20} width={width} height="1" />);
53+
table.push(
54+
<rect x={x} y={y} rx="2" ry="2" height={height} width={is_array ? columns[column] : width}></rect>
55+
);
56+
}
4257
}
4358

4459
return (
@@ -47,8 +62,8 @@ export default {
4762
props,
4863
attrs: data.attrs,
4964
}}
50-
width={width}
51-
height={height}
65+
width={100}
66+
height={((height + gutter) * length) - gutter}
5267
>
5368
{table}
5469
</VueContentLoading>

0 commit comments

Comments
 (0)