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

84 lines (72 loc) 3.78 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["children", "visuallyHiddenText", "className", "href", "to"], _excluded2 = ["reactListKey"], _excluded3 = ["className", "rows"]; import React from 'react'; import { Link } from '../../../utils/Link'; function ActionLink(props) { var children = props.children, visuallyHiddenText = props.visuallyHiddenText, className = props.className, href = props.href, to = props.to, attributes = _objectWithoutProperties(props, _excluded); var contents = /*#__PURE__*/React.createElement(React.Fragment, null, children, visuallyHiddenText && /*#__PURE__*/React.createElement("span", { className: "govuk-visually-hidden" }, visuallyHiddenText)); return /*#__PURE__*/React.createElement(Link, _extends({ className: "govuk-link ".concat(className || ''), to: to, href: href }, attributes), contents); } function actions(row) { var _row$actions, _row$actions2; var actionLinks = (_row$actions = row.actions) === null || _row$actions === void 0 ? void 0 : _row$actions.items.map(function (action, index) { var reactListKey = action.reactListKey, actionAttributes = _objectWithoutProperties(action, _excluded2); return /*#__PURE__*/React.createElement(ActionLink, _extends({ key: reactListKey || index }, actionAttributes)); }); if ((_row$actions2 = row.actions) !== null && _row$actions2 !== void 0 && _row$actions2.items.length) { return /*#__PURE__*/React.createElement("dd", { className: "govuk-summary-list__actions ".concat(row.actions.className || '') }, row.actions.items.length === 1 ? actionLinks : /*#__PURE__*/React.createElement("ul", { className: "govuk-summary-list__actions-list" }, actionLinks.map(function (actionLink) { return /*#__PURE__*/React.createElement("li", { key: actionLink.key, className: "govuk-summary-list__actions-list-item" }, actionLink); }))); } return null; } function SummaryList(props) { var className = props.className, rows = props.rows, attributes = _objectWithoutProperties(props, _excluded3); var filteredRows = rows ? rows.filter(function (row) { return row; }) : []; var anyRowHasActions = filteredRows.some(function (item) { var _item$actions; return ((_item$actions = item.actions) === null || _item$actions === void 0 ? void 0 : _item$actions.items.length) > 0 === true; }); return /*#__PURE__*/React.createElement("dl", _extends({ className: "govuk-summary-list ".concat(className || '') }, attributes), filteredRows.map(function (row, index) { var _row$actions3, _row$key, _row$key2, _row$value, _row$value2; return /*#__PURE__*/React.createElement("div", { key: row.reactListKey || index, className: "govuk-summary-list__row ".concat(anyRowHasActions && !((_row$actions3 = row.actions) !== null && _row$actions3 !== void 0 && _row$actions3.items) ? 'govuk-summary-list__row--no-actions' : '', " ").concat(row.className || '') }, /*#__PURE__*/React.createElement("dt", { className: "govuk-summary-list__key ".concat(((_row$key = row.key) === null || _row$key === void 0 ? void 0 : _row$key.className) || '') }, (_row$key2 = row.key) === null || _row$key2 === void 0 ? void 0 : _row$key2.children), /*#__PURE__*/React.createElement("dd", { className: "govuk-summary-list__value ".concat(((_row$value = row.value) === null || _row$value === void 0 ? void 0 : _row$value.className) || '') }, (_row$value2 = row.value) === null || _row$value2 === void 0 ? void 0 : _row$value2.children), actions(row)); })); } export { SummaryList };