From da31348e6f64870bcd2d770ed6a3c963f878a388 Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Fri, 1 Mar 2024 18:05:03 +0000 Subject: [PATCH] Search filters (#94) * Initial draft of search filters * Extra attributes on search filter fields * Accessibility fixes to search filters * Remove some classes from compound filters * Fix missing data in fixtures * More updates to search filters * More updates to search filters * Add hover state to button * Add opened example --- .github/actions/prototype-kit-test/action.yml | 6 +- CHANGELOG.md | 8 +- src/nationalarchives/all.mjs | 9 + src/nationalarchives/components/_index.scss | 3 +- .../components/button/button.scss | 1 + .../components/checkboxes/checkboxes.njk | 12 + .../components/checkboxes/checkboxes.scss | 1 + .../components/checkboxes/fixtures.json | 4 +- .../components/checkboxes/template.njk | 9 +- .../compound-filters/compound-filters.scss | 2 + .../components/compound-filters/fixtures.json | 2 +- .../components/compound-filters/template.njk | 2 +- .../components/date-input/fixtures.json | 4 +- .../components/date-input/template.njk | 2 +- .../components/date-search/date-search.njk | 7 + .../components/date-search/fixtures.json | 4 +- .../components/date-search/template.njk | 7 +- .../components/filters/_index.scss | 1 - .../components/filters/fixtures.json | 50 ----- .../components/filters/macro.njk | 3 - .../components/filters/template.njk | 8 - .../components/quick-filters/_index.scss | 1 + .../components/quick-filters/fixtures.json | 51 +++++ .../macro-options.json | 4 +- .../components/quick-filters/macro.njk | 3 + .../quick-filters.scss} | 18 +- .../quick-filters.stories.js} | 4 +- .../components/quick-filters/template.njk | 8 + .../components/radios/fixtures.json | 4 +- .../components/radios/radios.njk | 12 + .../components/radios/template.njk | 15 +- .../components/search-field/fixtures.json | 2 +- .../components/search-field/search-field.scss | 2 +- .../components/search-field/template.njk | 2 +- .../components/search-filters/_index.scss | 1 + .../components/search-filters/fixtures.json | 16 ++ .../search-filters/macro-options.json | 39 ++++ .../components/search-filters/macro.njk | 3 + .../search-filters/search-filters.mjs | 67 ++++++ .../search-filters/search-filters.scss | 163 ++++++++++++++ .../search-filters/search-filters.stories.js | 207 ++++++++++++++++++ .../components/search-filters/template.njk | 107 +++++++++ .../components/select/fixtures.json | 2 +- .../components/select/select.scss | 2 +- .../components/select/template.njk | 2 +- .../components/text-input/fixtures.json | 4 +- .../components/text-input/template.njk | 10 +- .../components/text-input/text-input.njk | 10 + .../components/text-input/text-input.scss | 2 +- .../components/textarea/fixtures.json | 4 +- .../components/textarea/template.njk | 2 +- .../components/textarea/textarea.scss | 2 +- src/nationalarchives/tools/_a11y.scss | 4 +- src/nationalarchives/utilities/_forms.scss | 6 + .../utilities/_typography.scss | 2 + tasks/test-package.js | 3 +- 56 files changed, 799 insertions(+), 130 deletions(-) create mode 100644 src/nationalarchives/components/checkboxes/checkboxes.njk create mode 100644 src/nationalarchives/components/date-search/date-search.njk delete mode 100644 src/nationalarchives/components/filters/_index.scss delete mode 100644 src/nationalarchives/components/filters/fixtures.json delete mode 100644 src/nationalarchives/components/filters/macro.njk delete mode 100644 src/nationalarchives/components/filters/template.njk create mode 100644 src/nationalarchives/components/quick-filters/_index.scss create mode 100644 src/nationalarchives/components/quick-filters/fixtures.json rename src/nationalarchives/components/{filters => quick-filters}/macro-options.json (91%) create mode 100644 src/nationalarchives/components/quick-filters/macro.njk rename src/nationalarchives/components/{filters/filters.scss => quick-filters/quick-filters.scss} (70%) rename src/nationalarchives/components/{filters/filters.stories.js => quick-filters/quick-filters.stories.js} (95%) create mode 100644 src/nationalarchives/components/quick-filters/template.njk create mode 100644 src/nationalarchives/components/radios/radios.njk create mode 100644 src/nationalarchives/components/search-filters/_index.scss create mode 100644 src/nationalarchives/components/search-filters/fixtures.json create mode 100644 src/nationalarchives/components/search-filters/macro-options.json create mode 100644 src/nationalarchives/components/search-filters/macro.njk create mode 100644 src/nationalarchives/components/search-filters/search-filters.mjs create mode 100644 src/nationalarchives/components/search-filters/search-filters.scss create mode 100644 src/nationalarchives/components/search-filters/search-filters.stories.js create mode 100644 src/nationalarchives/components/search-filters/template.njk create mode 100644 src/nationalarchives/components/text-input/text-input.njk diff --git a/.github/actions/prototype-kit-test/action.yml b/.github/actions/prototype-kit-test/action.yml index a64de58e..93005ce0 100644 --- a/.github/actions/prototype-kit-test/action.yml +++ b/.github/actions/prototype-kit-test/action.yml @@ -45,7 +45,6 @@ runs: echo -e "{% from \"nationalarchives/components/date-search/macro.njk\" import tnaDateSearch %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/error-summary/macro.njk\" import tnaErrorSummary %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/featured-records/macro.njk\" import tnaFeaturedRecords %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && - echo -e "{% from \"nationalarchives/components/filters/macro.njk\" import tnaFilters %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/footer/macro.njk\" import tnaFooter %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/gallery/macro.njk\" import tnaGallery %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/global-header/macro.njk\" import tnaGlobalHeader %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && @@ -57,9 +56,11 @@ runs: echo -e "{% from \"nationalarchives/components/pagination/macro.njk\" import tnaPagination %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/phase-banner/macro.njk\" import tnaPhaseBanner %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/picture/macro.njk\" import tnaPicture %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && + echo -e "{% from \"nationalarchives/components/quick-filters/macro.njk\" import tnaQuickFilters %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/radios/macro.njk\" import tnaRadios %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/sensitive-image/macro.njk\" import tnaSensitiveImage %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/search-field/macro.njk\" import tnaSearchField %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && + echo -e "{% from \"nationalarchives/components/search-filters/macro.njk\" import tnaSearchFilters %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/select/macro.njk\" import tnaSelect %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/skip-link/macro.njk\" import tnaSkipLink %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && echo -e "{% from \"nationalarchives/components/tabs/macro.njk\" import tnaTabs %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html && @@ -79,7 +80,6 @@ runs: echo "{{ tnaDateSearch({}) }}" >> prototype/app/views/index.html && echo "{{ tnaErrorSummary({}) }}" >> prototype/app/views/index.html && echo "{{ tnaFeaturedRecords({}) }}" >> prototype/app/views/index.html && - echo "{{ tnaFilters({}) }}" >> prototype/app/views/index.html && echo "{{ tnaFooter({}) }}" >> prototype/app/views/index.html && echo "{{ tnaGallery({}) }}" >> prototype/app/views/index.html && echo "{{ tnaGlobalHeader({}) }}" >> prototype/app/views/index.html && @@ -91,9 +91,11 @@ runs: echo "{{ tnaPagination({}) }}" >> prototype/app/views/index.html && echo "{{ tnaPhaseBanner({}) }}" >> prototype/app/views/index.html && echo "{{ tnaPicture({}) }}" >> prototype/app/views/index.html && + echo "{{ tnaQuickFilters({}) }}" >> prototype/app/views/index.html && echo "{{ tnaRadios({}) }}" >> prototype/app/views/index.html && echo "{{ tnaSensitiveImage({}) }}" >> prototype/app/views/index.html && echo "{{ tnaSearchField({}) }}" >> prototype/app/views/index.html && + echo "{{ tnaSearchFilters({}) }}" >> prototype/app/views/index.html && echo "{{ tnaSelect({}) }}" >> prototype/app/views/index.html && echo "{{ tnaSkipLink({}) }}" >> prototype/app/views/index.html && echo "{{ tnaTabs({}) }}" >> prototype/app/views/index.html && diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e74fc5..6a935a09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Error summary component +- Initial idea for search filters - Allow structured data in breadcrumbs with `structuredData` ### Changed + +- `filters` are now `quick-filters` (and the Nunjucks has changed from `tnaFilters` to `tnaQuickFilters`) +- Borders size around inputs has been increased +- Removed `tna-ul tna-ul--plain` classes from compound filters + ### Deprecated ### Removed -- Removed the `tna-form__` prefix from form field IDs +- Removed the automatic `tna-form__` prefix from form field IDs ### Fixed ### Security diff --git a/src/nationalarchives/all.mjs b/src/nationalarchives/all.mjs index 23036153..9aa56ae8 100644 --- a/src/nationalarchives/all.mjs +++ b/src/nationalarchives/all.mjs @@ -5,6 +5,7 @@ import { Gallery } from "./components/gallery/gallery.mjs"; import { GlobalHeader } from "./components/global-header/global-header.mjs"; import { Header } from "./components/header/header.mjs"; import { Picture } from "./components/picture/picture.mjs"; +import { SearchFilters } from "./components/search-filters/search-filters.mjs"; import { SensitiveImage } from "./components/sensitive-image/sensitive-image.mjs"; import { SkipLink } from "./components/skip-link/skip-link.mjs"; import { Tabs } from "./components/tabs/tabs.mjs"; @@ -80,6 +81,13 @@ const initAll = (options) => { new Picture($picture); }); + const $searchFilters = $scope.querySelectorAll( + '[data-module="tna-search-filters"]', + ); + $searchFilters.forEach(($searchFilter) => { + new SearchFilters($searchFilter); + }); + const $sensitiveImages = $scope.querySelectorAll( '[data-module="tna-sensitive-image"]', ); @@ -108,6 +116,7 @@ export { GlobalHeader, Header, Picture, + SearchFilters, SensitiveImage, SkipLink, Tabs, diff --git a/src/nationalarchives/components/_index.scss b/src/nationalarchives/components/_index.scss index beec5bc6..c5725cdc 100644 --- a/src/nationalarchives/components/_index.scss +++ b/src/nationalarchives/components/_index.scss @@ -8,7 +8,6 @@ @use "date-search"; @use "error-summary"; @use "featured-records"; -@use "filters"; @use "footer"; @use "gallery"; @use "global-header"; @@ -20,9 +19,11 @@ @use "pagination"; @use "phase-banner"; @use "picture"; +@use "quick-filters"; @use "radios"; @use "sensitive-image"; @use "search-field"; +@use "search-filters"; @use "select"; @use "skip-link"; @use "tabs"; diff --git a/src/nationalarchives/components/button/button.scss b/src/nationalarchives/components/button/button.scss index 31040f8e..5913df2b 100644 --- a/src/nationalarchives/components/button/button.scss +++ b/src/nationalarchives/components/button/button.scss @@ -22,6 +22,7 @@ @include colour.colour-background("button-background"); @include colour.colour-border("button-background", 0.25rem); + // border-radius: 0.1px; cursor: pointer; diff --git a/src/nationalarchives/components/checkboxes/checkboxes.njk b/src/nationalarchives/components/checkboxes/checkboxes.njk new file mode 100644 index 00000000..751848b1 --- /dev/null +++ b/src/nationalarchives/components/checkboxes/checkboxes.njk @@ -0,0 +1,12 @@ +{% macro tnaCheckboxesElement(params, extraAttributes) %} +
+ {%- for item in params.items %} +
+ + +
+ {%- endfor %} +
+{% endmacro %} diff --git a/src/nationalarchives/components/checkboxes/checkboxes.scss b/src/nationalarchives/components/checkboxes/checkboxes.scss index 55c2eca4..0335a156 100644 --- a/src/nationalarchives/components/checkboxes/checkboxes.scss +++ b/src/nationalarchives/components/checkboxes/checkboxes.scss @@ -61,6 +61,7 @@ "input-border", forms.$form-field-border-width ); + border-radius: 0.1px; } &::after { diff --git a/src/nationalarchives/components/checkboxes/fixtures.json b/src/nationalarchives/components/checkboxes/fixtures.json index 9932f213..67c847d5 100644 --- a/src/nationalarchives/components/checkboxes/fixtures.json +++ b/src/nationalarchives/components/checkboxes/fixtures.json @@ -130,7 +130,7 @@ } ] }, - "html": "

Categories

Select all that apply.

" + "html": "

Categories

Select all that apply.

" }, { "name": "checkboxes with an error", @@ -158,7 +158,7 @@ } ] }, - "html": "

Categories

Error: You must select a category

" + "html": "

Categories

Error: You must select a category

" }, { "name": "inline checkboxes", diff --git a/src/nationalarchives/components/checkboxes/template.njk b/src/nationalarchives/components/checkboxes/template.njk index da6b0038..c37e093a 100644 --- a/src/nationalarchives/components/checkboxes/template.njk +++ b/src/nationalarchives/components/checkboxes/template.njk @@ -1,9 +1,11 @@ +{% from "nationalarchives/components/checkboxes/checkboxes.njk" import tnaCheckboxesElement %} + {%- set containerClasses = [params.classes] if params.classes else [] -%} {%- if params.inline -%} {%- set containerClasses = containerClasses.concat('tna-form__group--inline') -%} {%- endif -%}
-
+
{{ params.label }} @@ -19,7 +21,8 @@ Error: {{ params.error.text }}

{%- endif %} -
+ {{ tnaCheckboxesElement(params) }} + {#
{%- for item in params.items %}
@@ -28,6 +31,6 @@
{%- endfor %} -
+
#}
diff --git a/src/nationalarchives/components/compound-filters/compound-filters.scss b/src/nationalarchives/components/compound-filters/compound-filters.scss index 08cf4ebf..981b3fe1 100644 --- a/src/nationalarchives/components/compound-filters/compound-filters.scss +++ b/src/nationalarchives/components/compound-filters/compound-filters.scss @@ -10,6 +10,8 @@ align-items: center; gap: 0.75rem 1rem; + list-style: none; + &__item { padding: 0 0.125rem 0 0.75rem; diff --git a/src/nationalarchives/components/compound-filters/fixtures.json b/src/nationalarchives/components/compound-filters/fixtures.json index 99de9fe9..ddf1c17b 100644 --- a/src/nationalarchives/components/compound-filters/fixtures.json +++ b/src/nationalarchives/components/compound-filters/fixtures.json @@ -39,7 +39,7 @@ } ] }, - "html": "" + "html": "" } ] } diff --git a/src/nationalarchives/components/compound-filters/template.njk b/src/nationalarchives/components/compound-filters/template.njk index c77e16e6..899c37b3 100644 --- a/src/nationalarchives/components/compound-filters/template.njk +++ b/src/nationalarchives/components/compound-filters/template.njk @@ -1,5 +1,5 @@ {%- set containerClasses = [params.classes] if params.classes else [] -%} -