From 929b4005b088dab1074bb77be2f784f5a4241b11 Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Tue, 10 Oct 2023 18:51:15 +0100 Subject: [PATCH] Use button macro inside other components --- .../components/button/button.stories.js | 3 ++ .../components/button/macro-options.json | 12 ++++++ .../components/button/template.njk | 7 +++- .../components/footer/template.njk | 12 ++++-- .../components/pagination/template.njk | 40 ++++++++++++++----- tasks/test-fixtures.js | 12 ++++-- 6 files changed, 66 insertions(+), 20 deletions(-) diff --git a/src/nationalarchives/components/button/button.stories.js b/src/nationalarchives/components/button/button.stories.js index 473d6831..c3f1497a 100644 --- a/src/nationalarchives/components/button/button.stories.js +++ b/src/nationalarchives/components/button/button.stories.js @@ -11,6 +11,7 @@ const argTypes = { small: { control: "boolean" }, plain: { control: "boolean" }, iconOnly: { control: "boolean" }, + iconOnlyOnMobile: { control: "boolean" }, buttonElement: { control: "boolean" }, classes: { control: "text" }, attributes: { control: "object" }, @@ -37,6 +38,7 @@ const Template = ({ small, plain, iconOnly, + iconOnlyOnMobile, buttonElement, classes, attributes, @@ -52,6 +54,7 @@ const Template = ({ small, plain, iconOnly, + iconOnlyOnMobile, buttonElement, classes, attributes, diff --git a/src/nationalarchives/components/button/macro-options.json b/src/nationalarchives/components/button/macro-options.json index 8d232262..44b34d60 100644 --- a/src/nationalarchives/components/button/macro-options.json +++ b/src/nationalarchives/components/button/macro-options.json @@ -47,6 +47,18 @@ "required": false, "description": "" }, + { + "name": "iconOnly", + "type": "boolean", + "required": false, + "description": "" + }, + { + "name": "iconOnlyOnMobile", + "type": "boolean", + "required": false, + "description": "" + }, { "name": "buttonElement", "type": "boolean", diff --git a/src/nationalarchives/components/button/template.njk b/src/nationalarchives/components/button/template.njk index 8d93de4f..4726bd4a 100644 --- a/src/nationalarchives/components/button/template.njk +++ b/src/nationalarchives/components/button/template.njk @@ -11,11 +11,14 @@ {%- if params.iconOnly -%} {%- set buttonClasses = buttonClasses.concat('tna-button--icon-only') -%} {%- endif -%} +{%- if params.iconOnlyOnMobile -%} + {%- set buttonClasses = buttonClasses.concat('tna-button--icon-only-mobile') -%} +{%- endif -%} <{{ 'button' if params.buttonElement else 'a' }}{%- if not params.buttonElement %} href="{{ params.href }}"{%- endif %} class="tna-button {{ buttonClasses | join(' ') }}"{%- if not params.buttonElement %} role="button"{%- endif -%}{%- if params.title %} title="{{ params.title }}"{% endif %}{% for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}> {%- if params.brandIcon %} - + {%- elseif params.icon %} - + {%- endif %} {{ params.text }} diff --git a/src/nationalarchives/components/footer/template.njk b/src/nationalarchives/components/footer/template.njk index f506684b..cdb3916f 100644 --- a/src/nationalarchives/components/footer/template.njk +++ b/src/nationalarchives/components/footer/template.njk @@ -1,3 +1,5 @@ +{% from "nationalarchives/components/button/macro.njk" import tnaButton %} + {%- set containerClasses = [params.classes] if params.classes else [] -%}