2015-05-21 16:02:42 +02:00
import React from 'react' ;
2015-05-20 14:48:57 +02:00
2015-06-02 13:42:17 +02:00
import { sumNumList } from '../utils/general_utils' ;
2015-05-20 16:44:45 +02:00
2015-05-20 14:48:57 +02:00
let TableColumnMixin = {
/ * *
* Generates the bootstrap grid column declarations automatically using
* the columnMap .
* /
2015-05-26 14:57:32 +02:00
calcColumnClasses ( list , i , numOfColumns ) {
2015-05-20 14:48:57 +02:00
let bootstrapClasses = [ 'col-xs-' , 'col-sm-' , 'col-md-' , 'col-lg-' ] ;
2015-05-20 16:10:02 +02:00
2015-05-21 16:02:42 +02:00
let listOfRowValues = list . map ( ( column ) => column . rowWidth ) ;
2015-06-02 13:42:17 +02:00
let numOfUsedColumns = sumNumList ( listOfRowValues ) ;
2015-05-20 14:48:57 +02:00
2015-05-26 14:57:32 +02:00
if ( numOfUsedColumns > numOfColumns ) {
throw new Error ( 'This table has only ' + numOfColumns + ' columns to assign. You defined ' + numOfUsedColumns + '. Change this in the columnMap you\'re passing to the table.' )
2015-05-20 16:10:02 +02:00
} else {
return bootstrapClasses . join ( listOfRowValues [ i ] + ' ' ) + listOfRowValues [ i ] ;
}
2015-05-20 14:48:57 +02:00
}
} ;
2015-05-20 16:44:45 +02:00
export default TableColumnMixin ;