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 %} + + +{% 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}}
+{{ props.content }}
+ {% elif props.as == 'span' %} + {{ props.content }} + {% else %} +{{ props.content }}
+ {% endif %} +{% endmacro %}