From fff5b402e5c381f9ad895a51a16433b9c79a5447 Mon Sep 17 00:00:00 2001 From: Matt Shaw Date: Wed, 6 Mar 2024 12:55:29 +0000 Subject: [PATCH 01/21] govuk-frontend 5.2 --- .github/workflows/python-package.yml | 2 +- CHANGELOG.md | 8 +++++++- README.md | 3 ++- setup.py | 2 +- tests/utils/test-entrypoint.sh | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index fa161cc9..7c2cf42e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -46,5 +46,5 @@ jobs: run: | (cd tests/utils && nohup python -m flask run --port 3000 &) wait-for-it localhost:3000 - ./govuk-frontend-diff http://localhost:3000 --govuk-frontend-version=v5.1.0 --exclude page-template --ci + ./govuk-frontend-diff http://localhost:3000 --govuk-frontend-version=v5.2.0 --exclude page-template --ci diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f870bd..dda8ea2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased](https://github.com/LandRegistry/govuk-frontend-jinja/compare/3.0.0...main) +## [Unreleased](https://github.com/LandRegistry/govuk-frontend-jinja/compare/3.1.0...main) + +## [3.1.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/3.1.0) - xx/03/2024 + +### Added + +- [GOV.UK Frontend v5.2.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.2.0) support ## [3.0.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/3.0.0) - 08/02/2024 diff --git a/README.md b/README.md index bdd13fe6..0b7d6d0c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # GOV.UK Frontend Jinja Macros [![PyPI version](https://badge.fury.io/py/govuk-frontend-jinja.svg)](https://pypi.org/project/govuk-frontend-jinja/) -![govuk-frontend 5.1.0](https://img.shields.io/badge/govuk--frontend%20version-5.1.0-005EA5?logo=gov.uk&style=flat) +![govuk-frontend 5.2.0](https://img.shields.io/badge/govuk--frontend%20version-5.2.0-005EA5?logo=gov.uk&style=flat) [![Python package](https://github.com/LandRegistry/govuk-frontend-jinja/actions/workflows/python-package.yml/badge.svg)](https://github.com/LandRegistry/govuk-frontend-jinja/actions/workflows/python-package.yml) **GOV.UK Frontend Jinja is a [community tool](https://design-system.service.gov.uk/community/resources-and-tools/) of the [GOV.UK Design System](https://design-system.service.gov.uk/). The Design System team is not responsible for it and cannot support you with using it. Contact the [maintainers](#contributors) directly if you need [help](#support) or you want to request a feature.** @@ -16,6 +16,7 @@ The following table shows the version of GOV.UK Frontend Jinja that you should u | GOV.UK Frontend Jinja Version | Target GOV.UK Frontend Version | | ----------------------------- | ------------------------------ | +| [3.1.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/3.1.0) | [5.2.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.2.0) | | [3.0.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/3.0.0) | [5.1.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.1.0) | | [2.8.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/2.8.0) | [4.8.0](https://github.com/alphagov/govuk-frontend/releases/tag/v4.8.0) | | [2.7.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/2.7.0) | [4.7.0](https://github.com/alphagov/govuk-frontend/releases/tag/v4.7.0) | diff --git a/setup.py b/setup.py index aec35771..c9857878 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setuptools.setup( name="govuk-frontend-jinja", - version="3.0.0", + version="3.1.0", author="Matt Shaw", author_email="matthew.shaw@landregistry.gov.uk", description="GOV.UK Frontend Jinja Macros", diff --git a/tests/utils/test-entrypoint.sh b/tests/utils/test-entrypoint.sh index 3746c8ab..621ba909 100755 --- a/tests/utils/test-entrypoint.sh +++ b/tests/utils/test-entrypoint.sh @@ -5,4 +5,4 @@ set -e flake8 . (cd tests/utils && nohup python -m flask run --port 3000 &) wait-for-it localhost:3000 -./govuk-frontend-diff http://localhost:3000 --govuk-frontend-version=v5.1.0 --exclude page-template --ci +./govuk-frontend-diff http://localhost:3000 --govuk-frontend-version=v5.2.0 --exclude page-template --ci From 9f80bcd181a951232cf3b85696f210eb190face2 Mon Sep 17 00:00:00 2001 From: Matt Shaw Date: Tue, 16 Apr 2024 14:25:49 +0100 Subject: [PATCH 02/21] govukAttributes macro --- .../templates/components/accordion/macro.html | 3 +- .../templates/components/back-link/macro.html | 6 +- .../components/breadcrumbs/macro.html | 12 +- .../templates/components/button/macro.html | 10 +- .../components/character-count/macro.html | 10 +- .../components/checkboxes/macro.html | 120 ++++++++------- .../components/cookie-banner/macro.html | 81 +++++----- .../components/date-input/macro.html | 27 ++-- .../templates/components/details/macro.html | 8 +- .../components/error-message/macro.html | 5 +- .../components/error-summary/macro.html | 7 +- .../components/exit-this-page/macro.html | 4 +- .../templates/components/fieldset/macro.html | 4 +- .../components/file-upload/macro.html | 20 ++- .../templates/components/footer/macro.html | 78 +++++----- .../templates/components/header/macro.html | 55 +++---- .../templates/components/hint/macro.html | 4 +- .../templates/components/input/macro.html | 26 +++- .../components/inset-text/macro.html | 6 +- .../templates/components/label/macro.html | 4 +- .../components/notification-banner/macro.html | 22 +-- .../components/pagination/macro.html | 141 ++++++++++-------- .../templates/components/panel/macro.html | 9 +- .../components/phase-banner/macro.html | 8 +- .../templates/components/radios/macro.html | 112 +++++++------- .../templates/components/select/macro.html | 34 +++-- .../templates/components/skip-link/macro.html | 5 +- .../components/summary-list/macro.html | 133 +++++++++-------- .../templates/components/table/macro.html | 74 +++++---- .../templates/components/tabs/macro.html | 58 ++++--- .../templates/components/tag/macro.html | 7 +- .../templates/components/task-list/macro.html | 56 ++++--- .../templates/components/textarea/macro.html | 20 ++- .../components/warning-text/macro.html | 5 +- .../templates/macros/attributes.html | 88 +++++++++++ govuk_frontend_jinja/templates/template.html | 5 +- 36 files changed, 752 insertions(+), 515 deletions(-) create mode 100644 govuk_frontend_jinja/templates/macros/attributes.html diff --git a/govuk_frontend_jinja/templates/components/accordion/macro.html b/govuk_frontend_jinja/templates/components/accordion/macro.html index b3b44d52..3fa1f2aa 100644 --- a/govuk_frontend_jinja/templates/components/accordion/macro.html +++ b/govuk_frontend_jinja/templates/components/accordion/macro.html @@ -1,4 +1,5 @@ {% macro govukAccordion(params) %} +{% from "govuk_frontend_jinja/macros/attributes.html" import govukAttributes %} {% from "govuk_frontend_jinja/macros/i18n.html" import govukI18nAttributes %} {%- macro _accordionItem(params, item, index) %} @@ -60,7 +61,7 @@ }) -}} {%- if params.rememberExpanded is not undefined %} data-remember-expanded="{{ params.rememberExpanded | escape | lower }}"{% endif %} - {%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}> + {{- govukAttributes(params.attributes) }}> {% for item in params['items'] %} {% if item %}{{ _accordionItem(params, item, loop.index) }}{% endif %} {% endfor %} diff --git a/govuk_frontend_jinja/templates/components/back-link/macro.html b/govuk_frontend_jinja/templates/components/back-link/macro.html index cac39ca9..f89e4e8e 100644 --- a/govuk_frontend_jinja/templates/components/back-link/macro.html +++ b/govuk_frontend_jinja/templates/components/back-link/macro.html @@ -1,4 +1,8 @@ {% macro govukBackLink(params) %} +{% from "govuk_frontend_jinja/macros/attributes.html" import govukAttributes -%} + {{ (params.html | safe if params.html else (params.text if params.text else 'Back')) }} + {{- govukAttributes(params.attributes) }}> + {{- params.html | safe if params.html else (params.text if params.text else "Back") -}} + {% endmacro %} diff --git a/govuk_frontend_jinja/templates/components/breadcrumbs/macro.html b/govuk_frontend_jinja/templates/components/breadcrumbs/macro.html index b1ddf544..1fc37155 100644 --- a/govuk_frontend_jinja/templates/components/breadcrumbs/macro.html +++ b/govuk_frontend_jinja/templates/components/breadcrumbs/macro.html @@ -1,21 +1,23 @@ {% macro govukBreadcrumbs(params) %} -{# Set classes for this component #} +{% from "govuk_frontend_jinja/macros/attributes.html" import govukAttributes %} + +{#- Set classes for this component #} {%- set classNames = "govuk-breadcrumbs" -%} {% if params.classes %} - {% set classNames = classNames + " " + params.classes %} + {% set classNames = classNames ~ " " ~ params.classes %} {% endif -%} {% if params.collapseOnMobile %} - {% set classNames = classNames + " govuk-breadcrumbs--collapse-on-mobile" %} + {% set classNames = classNames ~ " govuk-breadcrumbs--collapse-on-mobile" %} {% endif -%} -
+
    {% for item in params['items'] %} {% if item.href %}
  1. - + {{- item.html | safe if item.html else item.text -}}
  2. diff --git a/govuk_frontend_jinja/templates/components/button/macro.html b/govuk_frontend_jinja/templates/components/button/macro.html index 1680c2e3..12842b83 100644 --- a/govuk_frontend_jinja/templates/components/button/macro.html +++ b/govuk_frontend_jinja/templates/components/button/macro.html @@ -1,13 +1,15 @@ {% macro govukButton(params) %} -{# Set classes for this component #} +{% from "govuk_frontend_jinja/macros/attributes.html" import govukAttributes %} + +{#- Set classes for this component #} {%- set classNames = "govuk-button" -%} {%- if params.classes %} - {% set classNames = classNames + " " + params.classes %} + {% set classNames = classNames ~ " " ~ params.classes %} {% endif %} {%- if params.isStartButton %} - {% set classNames = classNames + " govuk-button--start" %} + {% set classNames = classNames ~ " govuk-button--start" %} {% endif %} {#- Determine type of element to use, if not explicitly set #} @@ -32,7 +34,7 @@ {#- Define common attributes that we can use across all element types #} -{%- set commonAttributes %} class="{{ classNames }}" data-module="govuk-button" {%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}{% if params.id %} id="{{ params.id }}"{% endif %}{% endset %} +{%- set commonAttributes %} class="{{ classNames }}" data-module="govuk-button" {{- govukAttributes(params.attributes) -}} {% if params.id %} id="{{ params.id }}"{% endif %}{% endset %} {#- Define common attributes we can use for both button and input types #} diff --git a/govuk_frontend_jinja/templates/components/character-count/macro.html b/govuk_frontend_jinja/templates/components/character-count/macro.html index 23e1a8d3..dc64e5ff 100644 --- a/govuk_frontend_jinja/templates/components/character-count/macro.html +++ b/govuk_frontend_jinja/templates/components/character-count/macro.html @@ -54,12 +54,12 @@ {{ govukTextarea({ 'id': params.id, 'name': params.name, - 'describedBy': params.id + '-info', + 'describedBy': params.id ~ '-info', 'rows': params.rows, 'spellcheck': params.spellcheck, 'value': params.value, 'formGroup': params.formGroup, - 'classes': 'govuk-js-character-count' + (' ' + params.classes if params.classes else ''), + 'classes': 'govuk-js-character-count' ~ (' ' ~ params.classes if params.classes else ''), 'label': { 'html': params.label.html, 'text': params.label.text, @@ -74,7 +74,7 @@ }) }} {%- set textareaDescriptionLength = params.maxwords or params.maxlength %} - {%- set textareaDescriptionText = params.textareaDescriptionText or 'You can enter up to %{count} ' + ('words' if params.maxwords else 'characters') %} + {%- set textareaDescriptionText = params.textareaDescriptionText or 'You can enter up to %{count} ' ~ ('words' if params.maxwords else 'characters') %} {#- If the limit is set in JavaScript, we won't be able to interpolate the message until JavaScript, so we only set a text if the `maxlength` or `maxwords` options @@ -82,8 +82,8 @@ #} {{ govukHint({ 'text': ((textareaDescriptionText) | replace('%{count}', textareaDescriptionLength) if not hasNoLimit), - 'id': params.id + '-info', - 'classes': 'govuk-character-count__message' + (' ' + params.countMessage.classes if params.countMessage and params.countMessage.classes else '') + 'id': params.id ~ '-info', + 'classes': 'govuk-character-count__message' ~ (' ' ~ params.countMessage.classes if params.countMessage and params.countMessage.classes else '') }) | trim | indent(2) }}
{% endmacro %} diff --git a/govuk_frontend_jinja/templates/components/checkboxes/macro.html b/govuk_frontend_jinja/templates/components/checkboxes/macro.html index a45d0dfb..074a574c 100644 --- a/govuk_frontend_jinja/templates/components/checkboxes/macro.html +++ b/govuk_frontend_jinja/templates/components/checkboxes/macro.html @@ -1,4 +1,5 @@ {% macro govukCheckboxes(params) %} +{% from "govuk_frontend_jinja/macros/attributes.html" import govukAttributes %} {% from "govuk_frontend_jinja/components/error-message/macro.html" import govukErrorMessage %} {% from "govuk_frontend_jinja/components/fieldset/macro.html" import govukFieldset %} {% from "govuk_frontend_jinja/components/hint/macro.html" import govukHint %} @@ -20,11 +21,58 @@ {#- fieldset is false by default -#} {% set hasFieldset = true if params.fieldset else false %} +{%- macro _checkboxItem(params, item, index) %} + {#- If the user explicitly sets an id, use this instead of the regular idPrefix -#} + {#- The first id should not have a number suffix so it's easy to link to from the error summary component -#} + {% set itemId = item.id if item.id else idPrefix ~ ("-" ~ index if index > 1 else "") %} + {% set itemName = item.name if item.name else params.name %} + {% set conditionalId = "conditional-" ~ itemId %} + {%- if item.divider %} +
{{ item.divider }}
+ {% else %} + {% set isChecked = item.checked | default((item.value in params.get('values', []) and item.checked != false) if params.values else false, true) %} + {% set hasHint = true if item.hint and (item.hint.text or item.hint.html) %} + {% set itemHintId = itemId ~ "-item-hint" if hasHint else "" %} + {% set itemDescribedBy = ns.describedBy if not hasFieldset else "" %} + {% set itemDescribedBy = (itemDescribedBy ~ " " ~ itemHintId) | trim %} +
+ + {{ govukLabel({ + 'html': item.html, + 'text': item.text, + 'classes': 'govuk-checkboxes__label' ~ (' ' ~ item.label.classes if item.label and item.label.classes else ''), + 'attributes': item.label.attributes if item.label, + 'for': itemId + }) | trim | indent(6) }} + {% if hasHint %} + {{ govukHint({ + 'id': itemHintId, + 'classes': 'govuk-checkboxes__hint' ~ (' ' ~ item.hint.classes if item.hint and item.hint.classes else ''), + 'attributes': item.hint.attributes if item.hint, + 'html': item.hint.html, + 'text': item.hint.text + }) | trim | indent(6) }} + {% endif %} +
+ {% if item.conditional and item.conditional.html %} +
+ {{ item.conditional.html | safe | trim | indent(6) }} +
+ {% endif %} + {% endif %} +{% endmacro -%} + {#- Capture the HTML so we can optionally nest it in a fieldset -#} {% set innerHtml %} {% if params.hint %} - {% set hintId = idPrefix + '-hint' %} - {% set ns.describedBy = ns.describedBy + ' ' + hintId if ns.describedBy else hintId %} + {% set hintId = idPrefix ~ '-hint' %} + {% set ns.describedBy = ns.describedBy ~ ' ' ~ hintId if ns.describedBy else hintId %} {{ govukHint({ 'id': hintId, 'classes': params.hint.classes, @@ -34,8 +82,8 @@ }) | trim | indent(2) }} {% endif %} {% if params.errorMessage %} - {% set errorId = idPrefix + '-error' %} - {% set ns.describedBy = ns.describedBy + ' ' + errorId if ns.describedBy else errorId %} + {% set errorId = idPrefix ~ '-error' %} + {% set ns.describedBy = ns.describedBy ~ ' ' ~ errorId if ns.describedBy else errorId %} {{ govukErrorMessage({ 'id': errorId, 'classes': params.errorMessage.classes, @@ -46,67 +94,23 @@ }) | trim | indent(2) }} {% endif %}
+ {{- govukAttributes(params.attributes) }} data-module="govuk-checkboxes"> + {% if params.formGroup and params.formGroup.beforeInputs %} + {{ params.formGroup.beforeInputs.html | safe | trim | indent(4) if params.formGroup.beforeInputs.html else params.formGroup.beforeInputs.text }} + {% endif %} {% for item in params['items'] %} {% if item %} - {#- If the user explicitly sets an id, use this instead of the regular idPrefix -#} - {%- if item.id -%} - {%- set id = item.id -%} - {%- else -%} - {#- The first id should not have a number suffix so it's easy to link to from the error summary component -#} - {%- if loop.first -%} - {%- set id = idPrefix %} - {% else %} - {%- set id = idPrefix + "-" ~ loop.index -%} - {%- endif -%} - {%- endif -%} - {% set name = item.name if item.name else params.name %} - {% set conditionalId = "conditional-" + id %} - {%- if item.divider %} -
{{ item.divider }}
- {%- else %} - {% set isChecked = item.checked | default((item.value in params.get('values', []) and item.checked != false) if params.values else false, true) %} - {% set hasHint = true if item.hint and (item.hint.text or item.hint.html) %} - {% set itemHintId = id + "-item-hint" if hasHint else "" %} - {% set itemDescribedBy = ns.describedBy if not hasFieldset else "" %} - {% set itemDescribedBy = (itemDescribedBy + " " + itemHintId) | trim %} -
- - {{ govukLabel({ - 'html': item.html, - 'text': item.text, - 'classes': 'govuk-checkboxes__label' + (' ' + item.label.classes if item.label and item.label.classes else ''), - 'attributes': item.label.attributes if item.label, - 'for': id - }) | trim | indent(6) }} - {% if hasHint %} - {{ govukHint({ - 'id': itemHintId, - 'classes': 'govuk-checkboxes__hint' + (' ' + item.hint.classes if item.hint.classes else ''), - 'attributes': item.hint.attributes, - 'html': item.hint.html, - 'text': item.hint.text - }) | trim | indent(6) }} - {% endif %} -
- {% if item.conditional and item.conditional.html %} -
- {{ item.conditional.html | safe }} -
- {% endif %} - {% endif %} + {{- _checkboxItem(params, item, loop.index) -}} {% endif %} {% endfor %} + {% if params.formGroup and params.formGroup.afterInputs %} + {{ params.formGroup.afterInputs.html | safe | trim | indent(4) if params.formGroup.afterInputs.html else params.formGroup.afterInputs.text }} + {% endif %}
{% endset -%} -
+
{% if hasFieldset %} {{ govukFieldset({ 'describedBy': ns.describedBy, diff --git a/govuk_frontend_jinja/templates/components/cookie-banner/macro.html b/govuk_frontend_jinja/templates/components/cookie-banner/macro.html index 18f67e6a..7bde52d2 100644 --- a/govuk_frontend_jinja/templates/components/cookie-banner/macro.html +++ b/govuk_frontend_jinja/templates/components/cookie-banner/macro.html @@ -1,66 +1,59 @@ {% macro govukCookieBanner (params) %} +{% from "govuk_frontend_jinja/macros/attributes.html" import govukAttributes %} {% from "govuk_frontend_jinja/components/button/macro.html" import govukButton -%}