Skip to content

Commit 65f3425

Browse files
committed
add simple table
1 parent dbfac1f commit 65f3425

File tree

4 files changed

+136
-15
lines changed

4 files changed

+136
-15
lines changed

src/blocks/helpers/table-row.vue

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<tr class="notion-simple-table-row">
3+
<td v-for="(cell, key, index) in row.value.properties" :key="key" class="notion-simple-table-data" :style="isColumnStyle(rowIndex) || isRowStyle(index) ? headerStyle : null">
4+
<div class="notion-simple-table-cell">
5+
<div class="notion-simple-table-cell-text">
6+
<NotionTextRenderer :text="cell" v-bind="pass" />
7+
</div>
8+
</div>
9+
</td>
10+
</tr>
11+
</template>
12+
13+
<script>
14+
import Blockable, { blockComputed } from "@/lib/blockable";
15+
import NotionTextRenderer from "@/blocks/helpers/text-renderer";
16+
export default {
17+
extends: Blockable,
18+
name: "NotionTableRow",
19+
props: {
20+
row: {
21+
type: Object
22+
},
23+
hasColumnHeader: {
24+
type: Boolean,
25+
default: false
26+
},
27+
hasRowHeader: {
28+
type: Boolean,
29+
default: false
30+
},
31+
rowIndex: {
32+
type: Number,
33+
}
34+
},
35+
components: {
36+
NotionTextRenderer
37+
},
38+
computed: {
39+
...blockComputed,
40+
headerStyle() {
41+
return {
42+
'background': 'rgb(247, 246, 243)',
43+
'font-weight': 500
44+
}
45+
}
46+
},
47+
methods: {
48+
isColumnStyle(index) {
49+
return this.hasColumnHeader && index === 0
50+
},
51+
isRowStyle(index) {
52+
return this.hasRowHeader && index === 0
53+
}
54+
}
55+
}
56+
</script>

src/blocks/table.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div>
3+
<table class="notion-simple-table">
4+
<tbody>
5+
<NotionTableRow v-for="(row, index) in rows" :key="row.value.id" :row="row" :rowIndex="index" :hasColumnHeader="hasColumnHeader" :hasRowHeader="hasRowHeader" v-bind="pass" />
6+
</tbody>
7+
</table>
8+
</div>
9+
</template>
10+
11+
<script>
12+
import Blockable, { blockComputed } from "@/lib/blockable";
13+
import NotionTableRow from "@/blocks/helpers/table-row";
14+
15+
export default {
16+
extends: Blockable,
17+
name: "NotionTable",
18+
components: {
19+
NotionTableRow
20+
},
21+
computed: {
22+
...blockComputed,
23+
rows() {
24+
return this.value.content.map(id => this.blockMap[id])
25+
},
26+
hasColumnHeader() {
27+
return this.value.format.table_block_column_header
28+
},
29+
hasRowHeader() {
30+
return this.value.format.table_block_row_header
31+
}
32+
},
33+
};
34+
</script>

src/components/block.vue

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,34 @@
2727
<slot />
2828
</NotionList>
2929
<NotionFigure
30-
v-else-if="isType(['image', 'embed', 'figma', 'video'])"
30+
v-else-if="isType(['image', 'embed', 'figma', 'video', 'audio'])"
3131
v-bind="pass"
3232
/>
33+
<NotionTable v-else-if="isType('table')" v-bind="pass" />
3334
<hr v-else-if="isType('divider')" class="notion-hr" />
3435
<div v-else-if="todo && visible">todo: {{ type }}<slot /></div>
3536
<!-- todo: maybe add message on !production if block type unsupported -->
3637
<!-- <div v-else-if="visible"><slot /></div> -->
3738
</template>
3839

3940
<script>
40-
import Blockable from "@/lib/blockable";
41-
import NotionBookmark from "@/blocks/bookmark";
42-
import NotionCallout from "@/blocks/callout";
43-
import NotionCode from "@/blocks/code";
44-
import NotionColumn from "@/blocks/column";
45-
import NotionFigure from "@/blocks/helpers/figure";
46-
import NotionList from "@/blocks/list";
47-
import NotionPage from "@/blocks/page";
48-
import NotionHeader from "@/blocks/header";
49-
import NotionText from "@/blocks/text";
50-
import NotionToggle from "@/blocks/toggle";
51-
import NotionQuote from "@/blocks/quote";
41+
import Blockable from '@/lib/blockable'
42+
import NotionBookmark from '@/blocks/bookmark'
43+
import NotionCallout from '@/blocks/callout'
44+
import NotionCode from '@/blocks/code'
45+
import NotionColumn from '@/blocks/column'
46+
import NotionFigure from '@/blocks/helpers/figure'
47+
import NotionList from '@/blocks/list'
48+
import NotionPage from '@/blocks/page'
49+
import NotionHeader from '@/blocks/header'
50+
import NotionText from '@/blocks/text'
51+
import NotionToggle from '@/blocks/toggle'
52+
import NotionQuote from '@/blocks/quote'
53+
import NotionTable from '@/blocks/table'
5254
5355
export default {
5456
extends: Blockable,
55-
name: "NotionBlock",
57+
name: 'NotionBlock',
5658
components: {
5759
NotionBookmark,
5860
NotionCallout,
@@ -65,6 +67,7 @@ export default {
6567
NotionText,
6668
NotionToggle,
6769
NotionQuote,
70+
NotionTable,
6871
},
69-
};
72+
}
7073
</script>

src/styles.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,3 +686,31 @@ img.notion-nav-icon {
686686
margin: 0 2px;
687687
color: rgba(55, 53, 47, 0.4);
688688
}
689+
690+
.notion-simple-table {
691+
border-collapse: collapse;
692+
border-spacing: 0;
693+
}
694+
695+
.notion-simple-table-data {
696+
color: inherit;
697+
fill: inherit;
698+
border: 1px solid rgb(233, 233, 231);
699+
position: relative;
700+
vertical-align: top;
701+
min-width: 178px;
702+
max-width: 178px;
703+
min-height: 32px;
704+
}
705+
706+
.notion-simple-table-cell-text {
707+
max-width: 100%;
708+
width: 100%;
709+
white-space: pre-wrap;
710+
word-break: break-word;
711+
caret-color: transparent;
712+
padding: 7px 9px;
713+
background-color: transparent;
714+
font-size: 14px;
715+
line-height: 20px;
716+
}

0 commit comments

Comments
 (0)