npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

storybook-addon-twig

v0.1.13

Published

Twig source, code, and docs support for Storybook.

Downloads

1,131

Readme

storybook-addon-twig

CI License Storybook

Twig source and code highlighting for Storybook.

storybook-addon-twig adds a Twig panel for story-level source and patches Storybook Docs code blocks in the preview runtime so Twig MDX fences and explicit Twig Source blocks render through the same Twig highlighter.

Install

bun add -d storybook-addon-twig

[!NOTE] This package is designed for Storybook 10.

Register the addon:

// .storybook/main.ts
import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
  addons: [
    {
      name: 'storybook-addon-twig',
      options: {
        copy: true,
        docsCodeBlocks: true,
        showLineNumbers: true,
      },
    },
  ],
};

export default config;

Add source to a story:

export const Default = {
  parameters: {
    twig: {
      fileName: 'button.html.twig',
      source: "{% include 'button.html.twig' with { label: 'Save' } %}",
    },
  },
};

[!TIP] source is displayed exactly as provided. Pass formatted Twig when you want the panel and Docs output to preserve project formatting.

Generate source snippets from Twig include metadata:

import { buildTwigSourceParameters } from 'storybook-addon-twig/source';

export const Default = {
  parameters: {
    twig: buildTwigSourceParameters({
      template: 'Components/Atoms/Button/button.html.twig',
      args: {
        text: 'Save',
        type: 'primary',
      },
    }),
  },
};

This only builds the parameters.twig source object. Rendering the actual story still belongs to your Storybook framework or renderer integration.

Options

| Option | Default | Purpose | | ----------------- | ------- | ------------------------------------------------------------------ | | docsCodeBlocks | true | Enable preview-side Twig docs patching for Twig docs/source blocks | | panel | true | Register the dedicated Twig addon panel | | copy | true | Enable copy actions for addon-owned Twig code surfaces | | showLineNumbers | true | Show line numbers in addon-owned Twig code surfaces | | wrapLines | true | Wrap long lines in addon-owned Twig code surfaces |

With docsCodeBlocks: true, the addon owns Twig rendering for these Docs paths:

  • fenced MDX blocks such as ```twig and ```html.twig
  • explicit <Source language="twig" /> blocks
  • the optional Twig manager panel

Behavior Notes

  • The Twig addon panel and Docs code blocks are independent. You can disable the panel with panel: false and keep docs highlighting with docsCodeBlocks: true.
  • Storybook's Source block inside Canvas remains Storybook-owned unless you explicitly set a Twig language on the docs/source block.
  • The sync icon in the panel toolbar triggers a Storybook FORCE_RE_RENDER refresh for the current story.

Docs Behavior

Docs highlighting is automatic when the addon is registered and docsCodeBlocks is enabled.

The preview runtime watches Storybook's Docs code surfaces and replaces Twig-tagged blocks with addon-owned highlighted output. This is the same category of runtime approach used by addons such as @lukethacoder/storybook-addon-shiki, and it avoids relying on Storybook-internal docs component aliasing.

Migration Notes

  • patchDocsCodeBlocks is removed. Use docsCodeBlocks.
  • theme is not part of this addon's API.

Troubleshooting

If Storybook fails after upgrading this addon, clear optimize-deps/cache artifacts and restart:

rm -rf node_modules/.cache/storybook node_modules/.vite

Development

This repo is Bun-first:

bun install
bun run build
bun run check:package
bun run coverage
bun run lint
bun run format:check
cd sandbox && bun run build-storybook
bun run storybook

The sandbox Storybook lives in sandbox/ and resolves the parent addon package directly from its Storybook config.

Documentation

| Topic | Page | | --------------- | ---------------------------------------------- | | Configuration | docs/configuration.md | | Architecture | docs/architecture.md | | Sandbox | docs/sandbox.md | | Testing | docs/testing.md | | Release process | docs/release.md | | Contributing | CONTRIBUTING.md |

License

MIT