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

@saidatom/storybook-addon-code

v1.0.0

Published

A Storybook addon that extracts and displays syntax-highlighted source code. Fork of the @whitespace-se/storybook-addon-code addon.

Readme

Storybook Addon Code

This addon for Storybook allows you to display the source code for your components. It uses highlight.js for syntax highlighting. Available languages are listed here.

NOTE: This addon can only be used with the new Component Story Format (CSF) introduced in Storybook 5.2.

Getting Started

npm i --save-dev @whitespace/storybook-addon-code

Register addon

Create a file called addons.js in your storybook config and add the following content:

import registerAddonCode from '@whitespace/storybook-addon-code/register';

registerAddonCode({
  tabs: [
    { label: 'Twig', lang: 'twig' },
    { label: 'Sass', lang: 'scss' },
    { label: 'JavaScript', lang: 'javascript', matchFiles: 'js' },
  ],
});

tabs should be an array with objects for each tab you want to add to the addon panel. Each object can contain these properties:

  • label: The displayed label on the tab.
  • lang: The language as defined by highlight.js. Available languages are listed here
  • matchFiles: Optional. Defaults to the same value as lang. Can be a string representing the file extension for files that should be included. Can also be a regular expression to test the filename against. Can also be function that receives the filename and returns true or false.

Add the Webpack loader

Update or create webpack.config.js inside your .storybook directory by adding require.resolve('@whitespace/storybook-addon-code/loader') as a pre-loader to .stories.js files as shown below.

module.exports = async ({ config, mode }) => {
  // ...

  config.module.rules.push({
    test: /\.stories\.jsx?$/,
    loaders: [
      /*
      This loader should be first in the list unless you
      want tranfromations from other loaders to affect
      what’s shown in the code tabs
      */
      require.resolve('@whitespace/storybook-addon-code/loader'),
      // ...
    ],
    enforce: 'pre',
  });

  // ...

  // Return the altered config
  return config;
};

Usage

The imported files inside the .stories.js file that matches the registered tabs will be extracted automatically. Install and use null-loader to include files that are not required by the actual stories file.

import Component from './button.twig';
import '!!null-loader!./button.scss';

export default {
  title: 'Example button',
};

export const withUrl = () =>
  Component({
    text: 'Lorem ipsum',
    url: '#',
  });

export const withoutUrl = () =>
  Component({
    text: 'Lorem ipsum',
  });