🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

storybook-addon-code

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storybook-addon-code

A storybook addon that display any type of code highlighted with Prismjs

0.1.4
latest
Source
npm
Version published
Weekly downloads
55
-11.29%
Maintainers
1
Weekly downloads
 
Created
Source

storybook-addon-code

React Storybook code addon

A Storybook addon enabling to show off code samples in the Storybook panel for your stories in Storybook.

Getting Started

npm i --save-dev storybook-addon-code

Usage

Create a file called addons.js in your storybook config.

Add following content to it:

import * as CodeAddon from '../src/register';
CodeAddon.setTabs(
    [{ label: 'Sass', type: 'sass' }, {label: 'TypeScript', type: 'typescript'}]
);

setTab function accept and object like {label: 'Sass', type:'sass'} or if you want to have multiple tabs you can pass an array with multiple objects. The label will pe displayed in the Storybook panel.

Then write your stories like this:

import { storiesOf } from '@storybook/react';
import withCode from 'storybook-addon-code';
import Button from './Button';

const styleFile = require('raw-loader!./style.scss');
const typescriptFile  = require('./test.tsx');

storiesOf('Button', module)
  .addDecorator(withCode(typescriptFile, 'typescript'))
  .addDecorator(withCode(styleFile, 'sass'))
  .add('with text', () =>
      <Button onClick={action('clicked')}>Hello Button</Button>
    )

Available list of format's for withCode function

  • clike (withCode(YourCFile, 'clike'))
  • css (withCode(YourCssFile, 'css'))
  • html (withCode(YourHtmlFile, 'html'))
  • js | javascript (withCode(YourJavascriptFile, 'js'))
  • markup (withCode(YourMarkupFile, 'js'))
  • mathml (withCode(YourMatHmlFile, 'mathml'))
  • sass (withCode(YourSassFile, 'sass'))
  • svg (withCode(YourSvgFile, 'svg'))
  • ts (withCode(YourTsFile, 'ts'))
  • typescript (withCode(YourTypescriptFile, 'typescript'))
  • xml (withCode(YourXmlFile, 'xml'))

Have a look at this example stories to learn more about the withCode API

Keywords

addon

FAQs

Package last updated on 09 Nov 2018

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