@@ -96,6 +96,13 @@ const TableHeaderStyle = {
9696 row: ' row' ,
9797};
9898
99+ const TableColumnAlignments = {
100+ left: ' left' ,
101+ right: ' right' ,
102+ center: ' center' ,
103+ unset: ' unset' ,
104+ };
105+
99106// The point after which a TabNavigator turns to vertical mode.
100107const TabNavigatorVerticalThreshold = 5 ;
101108
@@ -115,17 +122,22 @@ function renderNode(createElement, references) {
115122 ));
116123
117124 const renderTableCell = (
118- element, attrs, data, cellIndex, rowIndex, extendedData,
125+ element, attrs, data, cellIndex, rowIndex, extendedData, alignments,
119126 ) => {
120127 const { colspan , rowspan } = extendedData[` ${ rowIndex} _${ cellIndex} ` ] || {};
121128 // if either is `0`, then its spanned over and should not be rendered
122129 if (colspan === 0 || rowspan === 0 ) return null ;
123- return createElement (element, { attrs: { ... attrs, colspan, rowspan } }, (
130+ const align = alignments[cellIndex] || TableColumnAlignments .unset ;
131+ let classes = null ;
132+ if (align !== TableColumnAlignments .unset ) classes = ` ${ align} -cell` ;
133+ return createElement (element, { attrs: { ... attrs, colspan, rowspan }, class: classes }, (
124134 renderChildren (data)
125135 ));
126136 };
127137
128- const renderTableChildren = (rows , headerStyle = TableHeaderStyle .none , extendedData = {}) => {
138+ const renderTableChildren = (
139+ rows, headerStyle = TableHeaderStyle .none , extendedData = {}, alignments = [],
140+ ) => {
129141 // build the matrix for the array
130142 switch (headerStyle) {
131143 // thead with first row and th for each first row cell
@@ -135,14 +147,16 @@ function renderNode(createElement, references) {
135147 return [
136148 createElement (' thead' , {}, [
137149 createElement (' tr' , {}, firstRow .map ((cell , cellIndex ) => (
138- renderTableCell (' th' , { scope: ' col' }, cell, cellIndex, 0 , extendedData)
150+ renderTableCell (' th' , { scope: ' col' }, cell, cellIndex, 0 , extendedData, alignments )
139151 ))),
140152 ]),
141153 createElement (' tbody' , {}, otherRows .map (([firstCell , ... otherCells ], rowIndex ) => (
142154 createElement (' tr' , {}, [
143- renderTableCell (' th' , { scope: ' row' }, firstCell, 0 , rowIndex + 1 , extendedData),
155+ renderTableCell (
156+ ' th' , { scope: ' row' }, firstCell, 0 , rowIndex + 1 , extendedData, alignments,
157+ ),
144158 ... otherCells .map ((cell , cellIndex ) => (
145- renderTableCell (' td' , {}, cell, cellIndex + 1 , rowIndex + 1 , extendedData)
159+ renderTableCell (' td' , {}, cell, cellIndex + 1 , rowIndex + 1 , extendedData, alignments )
146160 )),
147161 ])
148162 ))),
@@ -153,9 +167,11 @@ function renderNode(createElement, references) {
153167 return [
154168 createElement (' tbody' , {}, rows .map (([firstCell , ... otherCells ], rowIndex ) => (
155169 createElement (' tr' , {}, [
156- renderTableCell (' th' , { scope: ' row' }, firstCell, 0 , rowIndex, extendedData),
170+ renderTableCell (
171+ ' th' , { scope: ' row' }, firstCell, 0 , rowIndex, extendedData, alignments,
172+ ),
157173 ... otherCells .map ((cell , cellIndex ) => (
158- renderTableCell (' td' , {}, cell, cellIndex + 1 , rowIndex, extendedData)
174+ renderTableCell (' td' , {}, cell, cellIndex + 1 , rowIndex, extendedData, alignments )
159175 )),
160176 ])
161177 ))),
@@ -167,12 +183,12 @@ function renderNode(createElement, references) {
167183 return [
168184 createElement (' thead' , {}, [
169185 createElement (' tr' , {}, firstRow .map ((cell , cellIndex ) => renderTableCell (
170- ' th' , { scope: ' col' }, cell, cellIndex, 0 , extendedData,
186+ ' th' , { scope: ' col' }, cell, cellIndex, 0 , extendedData, alignments,
171187 ))),
172188 ]),
173189 createElement (' tbody' , {}, otherRows .map ((row , rowIndex ) => (
174190 createElement (' tr' , {}, row .map ((cell , cellIndex ) => (
175- renderTableCell (' td' , {}, cell, cellIndex, rowIndex + 1 , extendedData)
191+ renderTableCell (' td' , {}, cell, cellIndex, rowIndex + 1 , extendedData, alignments )
176192 )))
177193 ))),
178194 ];
@@ -184,7 +200,7 @@ function renderNode(createElement, references) {
184200 rows .map ((row , rowIndex ) => (
185201 createElement (' tr' , {}, (
186202 row .map ((cell , cellIndex ) => (
187- renderTableCell (' td' , {}, cell, cellIndex, rowIndex, extendedData)
203+ renderTableCell (' td' , {}, cell, cellIndex, rowIndex, extendedData, alignments )
188204 ))
189205 ))
190206 ))
@@ -269,7 +285,7 @@ function renderNode(createElement, references) {
269285 spanned: !! node .extendedData ,
270286 },
271287 }, (
272- renderTableChildren (node .rows , node .header , node .extendedData )
288+ renderTableChildren (node .rows , node .header , node .extendedData , node . alignments )
273289 ));
274290 case BlockType .termList :
275291 return createElement (' dl' , {}, node .items .map (({ term, definition }) => [
@@ -417,7 +433,7 @@ function renderNode(createElement, references) {
417433
418434export default {
419435 name: ' ContentNode' ,
420- constants: { TableHeaderStyle },
436+ constants: { TableHeaderStyle, TableColumnAlignments },
421437 render : function render (createElement ) {
422438 // Dynamically map each content item and any children to their
423439 // corresponding components, and wrap the whole tree in a <div>
0 commit comments