govuk-react-jsx
Version:
[](https://github.com/alphagov/govuk-frontend/releases/tag/v4.0.1) [ • 4.3 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SummaryList = SummaryList;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireDefault(require("react"));
var _Link = require("../../../utils/Link");
var _excluded = ["children", "visuallyHiddenText", "className", "href", "to"],
_excluded2 = ["reactListKey"],
_excluded3 = ["className", "rows"];
function ActionLink(props) {
var children = props.children,
visuallyHiddenText = props.visuallyHiddenText,
className = props.className,
href = props.href,
to = props.to,
attributes = (0, _objectWithoutProperties2["default"])(props, _excluded);
var contents = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, children, visuallyHiddenText && /*#__PURE__*/_react["default"].createElement("span", {
className: "govuk-visually-hidden"
}, visuallyHiddenText));
return /*#__PURE__*/_react["default"].createElement(_Link.Link, (0, _extends2["default"])({
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 = (0, _objectWithoutProperties2["default"])(action, _excluded2);
return /*#__PURE__*/_react["default"].createElement(ActionLink, (0, _extends2["default"])({
key: reactListKey || index
}, actionAttributes));
});
if ((_row$actions2 = row.actions) !== null && _row$actions2 !== void 0 && _row$actions2.items.length) {
return /*#__PURE__*/_react["default"].createElement("dd", {
className: "govuk-summary-list__actions ".concat(row.actions.className || '')
}, row.actions.items.length === 1 ? actionLinks : /*#__PURE__*/_react["default"].createElement("ul", {
className: "govuk-summary-list__actions-list"
}, actionLinks.map(function (actionLink) {
return /*#__PURE__*/_react["default"].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 = (0, _objectWithoutProperties2["default"])(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["default"].createElement("dl", (0, _extends2["default"])({
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["default"].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["default"].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["default"].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));
}));
}