11import Table from './table' ;
22import * as $ from './utils/dom' ;
33
4- import { IconTable , IconTableWithHeadings , IconTableWithoutHeadings } from '@codexteam/icons' ;
5-
4+ import { IconTable , IconTableWithHeadings , IconTableWithoutHeadings , IconStretch , IconCollapse } from '@codexteam/icons' ;
65/**
76 * @typedef {object } TableData - configuration that the user can set for the table
87 * @property {number } rows - number of rows in the table
@@ -60,15 +59,17 @@ export default class TableBlock {
6059 *
6160 * @param {TableConstructor } init
6261 */
63- constructor ( { data, config, api, readOnly} ) {
62+ constructor ( { data, config, api, readOnly, block } ) {
6463 this . api = api ;
6564 this . readOnly = readOnly ;
6665 this . config = config ;
6766 this . data = {
6867 withHeadings : this . getConfig ( 'withHeadings' , false , data ) ,
68+ stretched : this . getConfig ( 'stretched' , false , data ) ,
6969 content : data && data . content ? data . content : [ ]
7070 } ;
7171 this . table = null ;
72+ this . block = block ;
7273 }
7374
7475 /**
@@ -130,6 +131,15 @@ export default class TableBlock {
130131 this . data . withHeadings = false ;
131132 this . table . setHeadingsSetting ( this . data . withHeadings ) ;
132133 }
134+ } , {
135+ label : this . data . stretched ? this . api . i18n . t ( 'Collapse' ) : this . api . i18n . t ( 'Stretch' ) ,
136+ icon : this . data . stretched ? IconCollapse : IconStretch ,
137+ closeOnActivate : true ,
138+ toggle : true ,
139+ onActivate : ( ) => {
140+ this . data . stretched = ! this . data . stretched ;
141+ this . block . stretched = this . data . stretched ;
142+ }
133143 }
134144 ] ;
135145 }
@@ -143,6 +153,7 @@ export default class TableBlock {
143153
144154 const result = {
145155 withHeadings : this . data . withHeadings ,
156+ stretched : this . data . stretched ,
146157 content : tableContent
147158 } ;
148159
0 commit comments