From 12dc281997914fe5ac7ac26559b65a1132813ca6 Mon Sep 17 00:00:00 2001 From: BogdanDanilescu <153850559+BogdanDanilescu@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:53:59 +0300 Subject: [PATCH] fix: add templates as static for storybook prod build (#199) --- examples/wagtail/core/jinja/home_page.jinja | 2 +- packages/html/storybook/.storybook/main.ts | 1 + .../html/storybook/.storybook/preview.tsx | 6 +- .../static/macros/footer/footer.html | 57 +++++++++++++++++++ .../static/macros/footer/helpers.html | 15 +++++ .../static/macros/header/header.html | 33 +++++++++++ .../static/macros/heading/heading.html | 44 ++++++++++++++ .../storybook/static/macros/link/link.html | 39 +++++++++++++ .../static/macros/paragraph/paragraph.html | 19 +++++++ 9 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 packages/html/storybook/static/macros/footer/footer.html create mode 100644 packages/html/storybook/static/macros/footer/helpers.html create mode 100644 packages/html/storybook/static/macros/header/header.html create mode 100644 packages/html/storybook/static/macros/heading/heading.html create mode 100644 packages/html/storybook/static/macros/link/link.html create mode 100644 packages/html/storybook/static/macros/paragraph/paragraph.html diff --git a/examples/wagtail/core/jinja/home_page.jinja b/examples/wagtail/core/jinja/home_page.jinja index 489afaf94..214915e81 100644 --- a/examples/wagtail/core/jinja/home_page.jinja +++ b/examples/wagtail/core/jinja/home_page.jinja @@ -2,7 +2,7 @@ {% from 'link/link.html' import govieLink %} {% from 'footer/footer.html' import govieFooter %} {% from 'heading/heading.html' import govieHeading %} -{% from 'paragraph/macro.html' import govieParagraph %} +{% from 'paragraph/paragraph.html' import govieParagraph %} {% from 'vars.jinja' import footerProps %} diff --git a/packages/html/storybook/.storybook/main.ts b/packages/html/storybook/.storybook/main.ts index 0c1a4dcf4..0978a7228 100644 --- a/packages/html/storybook/.storybook/main.ts +++ b/packages/html/storybook/.storybook/main.ts @@ -15,6 +15,7 @@ const config: StorybookConfig = { name: '@storybook/react-vite', options: {}, }, + staticDirs: ['../static'], async viteFinal(config, { configType }) { const { mergeConfig } = await import('vite'); diff --git a/packages/html/storybook/.storybook/preview.tsx b/packages/html/storybook/.storybook/preview.tsx index 0b367eb74..d0bd9e7ea 100644 --- a/packages/html/storybook/.storybook/preview.tsx +++ b/packages/html/storybook/.storybook/preview.tsx @@ -17,6 +17,8 @@ export const decorators = [ destroyGovIe(); initGovIe(); }, []); + const { args, parameters } = context; + parameters.macro.path = './macros'; const storyResult = Story(context); @@ -24,7 +26,8 @@ export const decorators = [ return
; } - return storyResult; + const renderedMacro = renderMacro(parameters.macro)(args); + return
; }, ]; @@ -53,6 +56,7 @@ const preview: Preview = { throw new Error('No name found in macro.'); } + parameters.macro.path = './macros'; const renderedMacro = renderMacro(parameters.macro)(args); const macroOptions = JSON.stringify(args, null, 2); diff --git a/packages/html/storybook/static/macros/footer/footer.html b/packages/html/storybook/static/macros/footer/footer.html new file mode 100644 index 000000000..d4858cf56 --- /dev/null +++ b/packages/html/storybook/static/macros/footer/footer.html @@ -0,0 +1,57 @@ +{% macro govieFooter(props) %} + +{% from 'heading/heading.html' import govieHeading %} +{% from 'footer/helpers.html' import hasTwoCols,hasTwoColsLinks, govieFooterLink %} + +
+ {# TODO: Use Container component #} +
+
+ {# secondary nav links #} +
+ {% if props.secondaryNavLinks %} + {% for linkObj in props.secondaryNavLinks %} +
+ {{ + govieHeading({ + "text": linkObj.heading, + "tag": "h2", + "size": "lg" + }) + }} +
    + {% for link in linkObj.links %} +
  • + {{ govieFooterLink({ + "href" : link.href, + "label" : link.label + }) + }} +
  • + {% endfor %} +
+
+ {% endfor %} + {% endif %} +
+ {# main links #} +
    + {% if props.links %} + {% for link in props.links %} +
  • + {{ govieFooterLink({ + "href" : link.href, + "label" : link.label + }) + }} +
  • + {% endfor %} + {% endif %} +
+
+ Gov IE Logo +
+
+
+
+{% endmacro %} diff --git a/packages/html/storybook/static/macros/footer/helpers.html b/packages/html/storybook/static/macros/footer/helpers.html new file mode 100644 index 000000000..2f5c37fac --- /dev/null +++ b/packages/html/storybook/static/macros/footer/helpers.html @@ -0,0 +1,15 @@ +{% macro hasTwoCols(twoCols) %} + {% if twoCols %} + sm:gi-col-span-2 + {% endif %} +{% endmacro %} + +{% macro hasTwoColsLinks(twoCols) %} + {% if twoCols %} + sm:gi-columns-2 + {% endif %} +{% endmacro %} + +{% macro govieFooterLink(props) %} + {{ props.label }} +{% endmacro %} \ No newline at end of file diff --git a/packages/html/storybook/static/macros/header/header.html b/packages/html/storybook/static/macros/header/header.html new file mode 100644 index 000000000..a0b1d7584 --- /dev/null +++ b/packages/html/storybook/static/macros/header/header.html @@ -0,0 +1,33 @@ +{% macro govieHeader(props) %} +
+
+
+

{{props.title}}

+
+ +
+
+
+
+ + + +
+
+
+
+{% endmacro %} diff --git a/packages/html/storybook/static/macros/heading/heading.html b/packages/html/storybook/static/macros/heading/heading.html new file mode 100644 index 000000000..f8b010933 --- /dev/null +++ b/packages/html/storybook/static/macros/heading/heading.html @@ -0,0 +1,44 @@ +{% macro govieHeading(props) %} + +{% macro caption(value='') %} +{% if value %} +{{value}} +{% endif %} +{% endmacro %} + +{% macro getClases(size) %} +{% if '2xs' in size %} +xs:gi-text-2xs md:gi-text-2xs xl:gi-text-2xs gi-font-bold +{% elif 'xs' in size %} +xs:gi-text-xs md:gi-text-xs xl:gi-text-xs gi-font-bold +{% elif 'sm' in size %} +xs:gi-text-sm md:gi-text-sm xl:gi-text-md gi-font-bold +{% elif 'md' in size %} +xs:gi-text-sm md:gi-text-md xl:gi-text-lg gi-font-bold +{% elif 'lg' in size %} +xs:gi-text-lg md:gi-text-xl xl:gi-text-2xl gi-font-bold +{% elif 'xl' in size %} +xs:gi-text-2xl md:gi-text-3xl xl:gi-text-4xl gi-font-bold +{% endif %} +{% endmacro %} + +{% if "h1" in props.tag %} +{{caption(props.caption)}}

{{props.text}}

+ +{% elif "h2" in props.tag %} +{{caption(props.caption)}}

{{props.text}}

+ +{% elif "h3" in props.tag %} +{{caption(props.caption)}}

{{props.text}}

+ +{% elif "h4" in props.tag %} +{{caption(props.caption)}}

{{props.text}}

+ +{% elif "h5" in props.tag %} +{{caption(props.caption)}}
{{props.text}}
+ +{% elif "h6" in props.tag %} +{{caption(props.caption)}}
{{props.text}}
+ +{% endif %} +{% endmacro %} \ No newline at end of file diff --git a/packages/html/storybook/static/macros/link/link.html b/packages/html/storybook/static/macros/link/link.html new file mode 100644 index 000000000..490c9b9bb --- /dev/null +++ b/packages/html/storybook/static/macros/link/link.html @@ -0,0 +1,39 @@ +{% macro govieLink(props) %} + {% macro getUnderlineClass(noUnderline) %} + {% if not noUnderline %} + gi-underline + gi-underline-offset-[0.1em] + focus:gi-no-underline + {% endif %} + {% endmacro %} + {% macro getVisitedClass(noVisited) %} + {% if noVisited %} + visited:gi-text-blue-700 + {% else %} + visited:gi-text-purple-700 + {% endif %} + {% endmacro %} + {% macro getExternalAttribute(isExternal) %} + {% if isExternal %} + rel="noreferrer noopener" target="_blank" + {% endif %} + {% endmacro %} + {{ props.label }} + +{% endmacro %} diff --git a/packages/html/storybook/static/macros/paragraph/paragraph.html b/packages/html/storybook/static/macros/paragraph/paragraph.html new file mode 100644 index 000000000..67c67b78d --- /dev/null +++ b/packages/html/storybook/static/macros/paragraph/paragraph.html @@ -0,0 +1,19 @@ +{% macro govieParagraph(props) %} + {% macro getSizeClass(size) %} + {% if size == 'lg' %} + xs:gi-text-lg md:gi-text-lg xl:gi-text-xl + {% elif size == 'md' %} + xs:gi-text-md md:gi-text-md xl:gi-text-lg + {% else %} + xs:gi-text-sm md:gi-text-sm xl:gi-text-md + {% endif %} + {% endmacro %} + + {% if props.as == 'p' %} +

{{ props.content }}

+ {% elif props.as == 'span' %} + {{ props.content }} + {% else %} +

{{ props.content }}

+ {% endif %} +{% endmacro %}