-
Install
twigjs-loader
via npm.$ npm i -D twigjs-loader
-
Extend Storybook's Webpack config to use the Twig loader.
main.js:
module.exports = { stories: [ "../stories/**/*.stories.mdx", "../stories/**/*.stories.@(js|jsx|ts|tsx)", ], addons: [ "@storybook/addon-links", "@storybook/addon-essentials" ], webpackFinal: async (config, { configType }) => { config.module.rules.push({ test: /\.twig$/, use: "twigjs-loader", }); return config; }};
-
Write your stories by importing your Twig files. Example:
button.twig:
<button type="{{ type }}">{{ text }}</button>
button.stories.js:
import twigButton from "./button.twig"; export default { title: "Button", argTypes: { type: { control: { type: "inline-radio", options: ["button", "submit"], }, }, }, }; const Template = ({ text, type }) => twigButton({ text, type, }); export const DefaultButton = Template.bind({}); DefaultButton.args = { text: "Button", type: "button", };
Last active
August 4, 2023 11:25
-
-
Save renestalder/1eedfe9b7e8ef775c8a83369fb8351f4 to your computer and use it in GitHub Desktop.
Storybook 6 Twig Setup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment