File tree Expand file tree Collapse file tree 3 files changed +32
-21
lines changed
packages/gitbook/src/components/DocumentView/Table Expand file tree Collapse file tree 3 files changed +32
-21
lines changed Original file line number Diff line number Diff line change @@ -115,7 +115,6 @@ export async function RecordColumnValue<Tag extends React.ElementType = 'div'>(
115
115
return < Tag className = { tcls ( [ 'w-full' , verticalAlignment ] ) } > { '' } </ Tag > ;
116
116
}
117
117
118
- const alignment = getColumnAlignment ( definition ) ;
119
118
120
119
return (
121
120
< Blocks
@@ -130,9 +129,7 @@ export async function RecordColumnValue<Tag extends React.ElementType = 'div'>(
130
129
'lg:space-y-3' ,
131
130
'leading-normal' ,
132
131
verticalAlignment ,
133
- alignment === 'right' ? '[&_*]:text-right' : null ,
134
- alignment === 'center' ? '[&_*]:text-center' : null ,
135
- alignment === 'left' ? '[&_*]:text-left' : null ,
132
+ getColumnAlignment ( definition )
136
133
] }
137
134
context = { context }
138
135
blockStyle = { [ 'w-full' , 'max-w-[unset]' ] }
@@ -326,4 +323,4 @@ export async function RecordColumnValue<Tag extends React.ElementType = 'div'>(
326
323
default :
327
324
assertNever ( definition ) ;
328
325
}
329
- }
326
+ }
Original file line number Diff line number Diff line change @@ -42,16 +42,13 @@ export function ViewGrid(props: TableViewProps<DocumentTableViewGrid>) {
42
42
) }
43
43
>
44
44
< div role = "row" className = { tcls ( 'flex' , 'w-full' ) } >
45
- { view . columns . map ( ( column ) => {
46
- const alignment = getColumnAlignment ( block . data . definition [ column ] ) ;
47
- return (
48
- < div
49
- key = { column }
50
- role = "columnheader"
51
- className = { tcls (
45
+ { view . columns . map ( ( column ) => (
46
+ < div
47
+ key = { column }
48
+ role = "columnheader"
49
+ className = { tcls (
52
50
styles . columnHeader ,
53
- alignment === 'right' ? 'text-right' : null ,
54
- alignment === 'center' ? 'text-center' : null
51
+ getColumnAlignment ( block . data . definition [ column ] )
55
52
) }
56
53
style = { {
57
54
width : getColumnWidth ( {
@@ -63,11 +60,10 @@ export function ViewGrid(props: TableViewProps<DocumentTableViewGrid>) {
63
60
minWidth : columnWidths ?. [ column ] || '100px' ,
64
61
} }
65
62
title = { block . data . definition [ column ] . title }
66
- >
63
+ >
67
64
{ block . data . definition [ column ] . title }
68
- </ div >
69
- ) ;
70
- } ) }
65
+ </ div >
66
+ ) ) }
71
67
</ div >
72
68
</ div >
73
69
) }
Original file line number Diff line number Diff line change 1
1
import type { ContentRef , DocumentTableDefinition , DocumentTableRecord } from '@gitbook/api' ;
2
+ import assertNever from 'assert-never' ;
2
3
3
4
/**
4
5
* Get the value for a column in a record.
@@ -14,13 +15,30 @@ export function getRecordValue<T extends number | string | boolean | string[] |
14
15
/**
15
16
* Get the text alignment for a column.
16
17
*/
17
- export function getColumnAlignment ( column : DocumentTableDefinition ) : 'left' | 'right' | 'center' {
18
+ export function getColumnAlignment ( column : DocumentTableDefinition ) {
19
+
20
+ const defaultAlignment = '[&_*]:text-left' ;
21
+
18
22
if ( column . type === 'text' ) {
19
- return column . textAlignment ?? 'left' ;
23
+ switch ( column . textAlignment ) {
24
+ case undefined :
25
+ case 'left' :
26
+ return defaultAlignment ;
27
+ case 'center' :
28
+ return '[&_*]:text-center' ;
29
+ case 'right' :
30
+ return '[&_*]:text-right' ;
31
+ default :
32
+ assertNever ( column . textAlignment ) ;
33
+ }
20
34
}
21
- return 'left' ;
35
+
36
+ return defaultAlignment ;
22
37
}
23
38
39
+
40
+
41
+
24
42
/**
25
43
* Get the vertical alignment for a column.
26
44
*/
You can’t perform that action at this time.
0 commit comments