diff --git a/src/data-table/index.jsx b/src/data-table/index.jsx index c3bef4f..5da451c 100644 --- a/src/data-table/index.jsx +++ b/src/data-table/index.jsx @@ -6,95 +6,92 @@ import HeaderPadding from './header-padding.jsx'; import RowHeader from './row-header.jsx'; import { injectSeparators } from '../utilities'; -class DataTable extends React.PureComponent { - render () { - const { data, general, qlik, renderData, styling } = this.props; - const { - headers: { - dimension1, - measurements - }, - matrix - } = data; +const DataTable = ({ data, general, qlik, renderData, styling }) => { + const { + headers: { + dimension1, + measurements + }, + matrix + } = data; - return ( -
- - - {dimension1.map((dimensionEntry, dimensionIndex) => { - const rowHeaderText = dimensionEntry.displayValue || ''; - if (rowHeaderText === '-') { - return null; - } - const styleBuilder = new StyleBuilder(styling); - if (styling.hasCustomFileStyle) { - styleBuilder.parseCustomFileStyle(rowHeaderText); - } else { - styleBuilder.applyStandardAttributes(dimensionIndex); - styleBuilder.applyCustomStyle({ - fontSize: `${14 + styling.options.fontSizeAdjustment}px` - }); - } - const rowStyle = { - fontFamily: styling.options.fontFamily, - width: '230px', - ...styleBuilder.getStyle() - }; + return ( +
+
+ + {dimension1.map((dimensionEntry, dimensionIndex) => { + const rowHeaderText = dimensionEntry.displayValue || ''; + if (rowHeaderText === '-') { + return null; + } + const styleBuilder = new StyleBuilder(styling); + if (styling.hasCustomFileStyle) { + styleBuilder.parseCustomFileStyle(rowHeaderText); + } else { + styleBuilder.applyStandardAttributes(dimensionIndex); + styleBuilder.applyCustomStyle({ + fontSize: `${14 + styling.options.fontSizeAdjustment}px` + }); + } + const rowStyle = { + fontFamily: styling.options.fontFamily, + width: '230px', + ...styleBuilder.getStyle() + }; - return ( - - - {renderData && injectSeparators( - matrix[dimensionIndex], - styling.useSeparatorColumns, - { atEvery: measurements.length } - ).map((measurementData, index) => { - if (measurementData.isSeparator) { - const separatorStyle = { - color: 'white', - fontFamily: styling.options.fontFamily, - fontSize: `${12 + styling.options.fontSizeAdjustment}px` - }; + return ( + + + {renderData && injectSeparators( + matrix[dimensionIndex], + styling.useSeparatorColumns, + { atEvery: measurements.length } + ).map((measurementData, index) => { + if (measurementData.isSeparator) { + const separatorStyle = { + color: 'white', + fontFamily: styling.options.fontFamily, + fontSize: `${12 + styling.options.fontSizeAdjustment}px` + }; - return ( - - ); - } - const { dimension1: dimension1Info, dimension2, measurement } = measurementData.parents; - const id = `${dimension1Info.elementNumber}-${dimension2 && dimension2.elementNumber}-${measurement.header}`; return ( - + ); - })} - - ); - })} - -
- * - + * +
-
- ); - } -} + } + const { dimension1: dimension1Info, dimension2, measurement } = measurementData.parents; + const id = `${dimension1Info.elementNumber}-${dimension2 && dimension2.elementNumber}-${measurement.header}`; + return ( + + ); + })} + + ); + })} + + + + ); +}; DataTable.defaultProps = { renderData: true diff --git a/src/headers-table/index.jsx b/src/headers-table/index.jsx index 3ed75bb..8ca4bb4 100644 --- a/src/headers-table/index.jsx +++ b/src/headers-table/index.jsx @@ -5,52 +5,84 @@ import ColumnHeader from './column-header.jsx'; import MeasurementColumnHeader from './measurement-column-header.jsx'; import { injectSeparators } from '../utilities'; -class HeadersTable extends React.Component { - render () { - const { data, general, qlik, styling } = this.props; - const baseCSS = { - backgroundColor: styling.headerOptions.colorSchema, - color: styling.headerOptions.textColor, - fontFamily: styling.options.fontFamily, - textAlign: styling.headerOptions.alignment - }; +const HeadersTable = ({ data, general, qlik, styling }) => { + const baseCSS = { + backgroundColor: styling.headerOptions.colorSchema, + color: styling.headerOptions.textColor, + fontFamily: styling.options.fontFamily, + textAlign: styling.headerOptions.alignment + }; - const { - dimension1, - dimension2, - measurements - } = data.headers; + const { + dimension1, + dimension2, + measurements + } = data.headers; - const hasSecondDimension = dimension2.length > 0; + const hasSecondDimension = dimension2.length > 0; - return ( -
- - - - +
+ + + + {!hasSecondDimension && measurements.map(measurementEntry => ( + - {!hasSecondDimension && measurements.map(measurementEntry => ( - { + if (entry.isSeparator) { + const separatorStyle = { + color: 'white', + fontFamily: styling.options.fontFamily, + fontSize: `${13 + styling.headerOptions.fontSizeAdjustment}px` + }; + + return ( + + ); + } + return ( + - ))} - {hasSecondDimension && injectSeparators(dimension2, styling.useSeparatorColumns).map((entry, index) => { - if (entry.isSeparator) { + ); + })} + + {hasSecondDimension && ( + + {injectSeparators(dimension2, styling.useSeparatorColumns).map((dimensionEntry, index) => { + if (dimensionEntry.isSeparator) { const separatorStyle = { color: 'white', fontFamily: styling.options.fontFamily, - fontSize: `${13 + styling.headerOptions.fontSizeAdjustment}px` + fontSize: `${12 + styling.headerOptions.fontSizeAdjustment}px` }; return ( @@ -63,62 +95,25 @@ class HeadersTable extends React.Component { ); } - return ( - ( + - ); + )); })} - {hasSecondDimension && ( - - {injectSeparators(dimension2, styling.useSeparatorColumns).map((dimensionEntry, index) => { - if (dimensionEntry.isSeparator) { - const separatorStyle = { - color: 'white', - fontFamily: styling.options.fontFamily, - fontSize: `${12 + styling.headerOptions.fontSizeAdjustment}px` - }; - - return ( - - ); - } - return measurements.map(measurementEntry => ( - - )); - })} - - )} - -
+ * +
- * -
-
- ); - } -} - -// const HeadersTable = ({ data, general, qlik, styling }) => { -// }; + )} + + + + ); +}; HeadersTable.propTypes = { data: PropTypes.shape({