Coder Social home page Coder Social logo

storybook-addon-amp's Introduction

@ampproject/storybook-addon

The storybook AMP addon allows rendering of AMP content inside the Storybook environment.

@ampproject/storybook-addon allows switching between three AMP modes: Module (v0.js), No-module (v0.mjs) and Bento. It also allows switching between development mode (locally hosted v0.js) and production mode (CDN hosted v0.js).

Getting Started

First, add the @ampproject/storybook-addon to your project:

npm install --save-dev @ampproject/storybook-addon

Second, register the @ampproject/storybook-addon to your config (.storybook/main.js):

module.exports = {
  addons: ['@ampproject/storybook-addon'],
};

Writing storybooks

An AMP story uses withAmp decorator:

import {h} from 'preact';
import {storiesOf} from '@storybook/preact';
import {withAmp} from '@ampproject/storybook-addon';

export default {
  title: 'amp-carousel',
  decorators: [withAmp],
  parameters: {
    extensions: [{name: 'amp-carousel', version: '0.2'}]},
  },
};

export const Default = () => {
  return (
    <amp-base-carousel width="440" height="225">
      {['lightcoral', 'peachpuff', 'lavender'].map((color) => (
        <div key={color}>{color}</div>
      ))}
    </amp-base-carousel>
  );
};

The following parameters can be specified:

  1. extensions: [{name, version}] - a list of extensions to be installed.
  2. experiments: [string] - a list of experiments to enabled.

amp-script hashes

Inline scripts used by amp-script require a <meta name="amp-script-src"> tag that includes their content hash.

This addon generates the script hash for stories that need it. The following works without writing the respective <meta> tag:

export const UsingInlineScript = () => (
  <>
    <amp-script script="hello" nodom></amp-script>
    <script id="hello" type="text/plain" target="amp-script">
      {`console.log('Hello');`}
    </script>
  </>
);

storybook-addon-amp's People

Contributors

alanorozco avatar renovate-bot avatar rsimha avatar wassgha avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.