# @ampproject/storybook-addon

> Storybook addon for building and testing AMP components

Latest version **1.1.10** (published 2022-02-15) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @ampproject/storybook-addon
pnpm add @ampproject/storybook-addon
yarn add @ampproject/storybook-addon
bun add @ampproject/storybook-addon
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.10 |
| Published | 2022-02-15 |
| First published | 2020-08-25 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 36.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | The AMP HTML Authors |
| Maintainers | ampproject-admin, kristoferbaxter, jridgewell, choumx, amp-toolbox, fstanis, erwinmombay, samouri, caroqliu, rsimha, dvoytenko, patrickkettner, alanorozco, kdwan, ampprojectbot, esth |

## Links

- npm: https://www.npmjs.com/package/@ampproject/storybook-addon
- Repository: https://github.com/ampproject/storybook-addon-amp
- Issues: https://github.com/ampproject/storybook-addon-amp/issues
- npm.io page: https://npm.io/package/@ampproject/storybook-addon

## Dependencies (4)

- [preact](https://npm.io/package/preact.md) 10.6.5
- [react-dom](https://npm.io/package/react-dom.md) 17.0.2
- [@storybook/client-api](https://npm.io/package/@storybook/client-api.md) 6.4.19
- [preact-render-to-string](https://npm.io/package/preact-render-to-string.md) 5.1.19

## Recent versions

- 1.1.10 (latest) — 2022-02-15
- 1.1.9 — 2021-04-01
- 1.1.8 — 2021-04-01
- 1.1.7 — 2021-03-17
- 1.1.6 — 2020-11-13
- 1.1.5 — 2020-11-05
- 1.1.4 — 2020-10-28
- 1.1.3 — 2020-09-25
- 1.1.2 — 2020-09-22
- 1.1.1 — 2020-08-25
- 1.1.0 — 2020-08-25

## README

# @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:

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

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

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

## Writing storybooks

An AMP story uses `withAmp` decorator:

```js
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](https://amp.dev/documentation/components/amp-script/#calculating-the-script-hash).

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

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

---
_Source: https://npm.io/package/@ampproject/storybook-addon · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
