UNPKG

@xgovformbuilder/govuk-react-jsx

Version:

> This package is no longer maintained and will not receive updates bringing it beyond govuk-frontend 4.0.1. If you are using this in your project the simplest way forward is to copy and paste the components from here into your project allowing you to kee

80 lines (71 loc) 3.16 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["caption", "captionClassName", "className", "firstCellIsHeader", "head", "rows"], _excluded2 = ["className", "format", "children", "reactListKey"], _excluded3 = ["className", "children", "format", "reactListKey"]; import React from 'react'; function Table(props) { var caption = props.caption, captionClassName = props.captionClassName, className = props.className, firstCellIsHeader = props.firstCellIsHeader, head = props.head, rows = props.rows, attributes = _objectWithoutProperties(props, _excluded); var captionComponent; var headComponent; if (caption) { captionComponent = /*#__PURE__*/React.createElement("caption", { className: "govuk-table__caption ".concat(captionClassName || '') }, caption); } if (head) { headComponent = /*#__PURE__*/React.createElement("thead", { className: "govuk-table__head" }, /*#__PURE__*/React.createElement("tr", { className: "govuk-table__row" }, head.map(function (item, index) { var itemClassName = item.className, itemFormat = item.format, itemChildren = item.children, reactListKey = item.reactListKey, itemAttributes = _objectWithoutProperties(item, _excluded2); return /*#__PURE__*/React.createElement("th", _extends({ key: reactListKey || index, scope: "col", className: "govuk-table__header ".concat(itemFormat ? "govuk-table__header--".concat(itemFormat) : '', " ").concat(itemClassName || '') }, itemAttributes), itemChildren); }))); } var filteredRows = rows ? rows.filter(function (row) { return row.cells; }) : []; return /*#__PURE__*/React.createElement("table", _extends({ className: "govuk-table ".concat(className || '') }, attributes), captionComponent, headComponent, /*#__PURE__*/React.createElement("tbody", { className: "govuk-table__body" }, filteredRows.map(function (row, rowIndex) { return /*#__PURE__*/React.createElement("tr", { key: row.reactListKey || rowIndex, className: "govuk-table__row" }, row.cells.map(function (cell, cellIndex) { var cellClassName = cell.className, cellChildren = cell.children, cellFormat = cell.format, reactListKey = cell.reactListKey, cellAttributes = _objectWithoutProperties(cell, _excluded3); if (cellIndex === 0 && firstCellIsHeader) { return /*#__PURE__*/React.createElement("th", _extends({ key: reactListKey || cellIndex, scope: "row", className: "govuk-table__header ".concat(cellClassName || '') }, cellAttributes), cellChildren); } return /*#__PURE__*/React.createElement("td", _extends({ key: cell.reactListKey || cellIndex, className: "govuk-table__cell ".concat(cellClassName || '', " ").concat(cellFormat ? "govuk-table__cell--".concat(cellFormat) : '') }, cellAttributes), cellChildren); })); }))); } export { Table };