New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@jls-digital/storybook-addon-code

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jls-digital/storybook-addon-code

This storybook addon provides the ability to display a panel on stories with any code you want. It's mostly a wrapper for [storybook's syntax highlighter](https://github.com/storybookjs/storybook/tree/main/code/ui/components/src/components/syntaxhighlight

1.0.4
latest
Source
npm
Version published
Weekly downloads
587
59.51%
Maintainers
2
Weekly downloads
 
Created
Source

storybook-addon-code

NPM npm install size

This storybook addon provides the ability to display a panel on stories with any code you want. It's mostly a wrapper for storybook's syntax highlighter , which is a wrapper for prism.js.

Screenshot of Addon

Installation

  • npm install --save-dev @jls-digital/storybook-addon-code
  • Add storybook-addon-code to your storybook's config
  • Add the sourceCode parameter to your stories
// .storybook/main.ts
const config: StorybookConfig = {
  addons: ['@jls-digital/storybook-addon-code'],
};

Usage

In your story files, you can now import code as string (with vite by using the '?raw' query parameter) and pass it to the sourceCode parameter. You can even import the file you're currently in:

// button.stories.ts
import rawStories from './button.stories?raw';
import rawComponent from './button?raw';
const meta: Meta<IButtonStory> = {
  parameters: {
    sourceCode: [
      { name: 'Component', code: rawComponent },
      { name: 'Stories', code: rawStories },
    ]
  },
  title: 'Components/Button',
}

Arguments

NameDescriptionValues
nameThe name of the sub tab. Default: index of tab.string
codeThe code to displaystring
languageThe language of the code that should be used for syntax highlighting. Default: typescript."jxextra", "jsx", "json", "yml", "md", "bash", "css", "html", "tsc", "typescript", "graphql"

FAQ

(Click on a question to see the answer.)

Q: When I add a new file to the list of source code, I get an error saying "The final argument passed to useMemo changed size between renders."

A: No worries, this is an issue with storybook's TabsState component. You can simply reload the page and it should work fine.

Q: Can I customize the order of my tabs?

A: Yes, the order is determined by the order of the array you pass to the sourceCode parameter.

Contributing

We encourage you to contribute to this project! Please check out the Contributing guide for guidelines about how to proceed and how to set up your dev environment. Join us!

License

Storybook-Addon-Code is released under the MIT License.

Keywords

storybook

FAQs

Package last updated on 20 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts