UNPKG

storybook-addon-aem-style-system

Version:
120 lines (78 loc) 3.99 kB
# Storybook Addon aem-style-system This addon will pull aem style from policy ### Development scripts - `npm run start` runs babel in watch mode and starts Storybook - `npm run build` build and package your addon code #### Globalized packages Storybook provides a predefined set of packages that are available in the manager UI and the preview UI. In the final bundle of your addon, these packages should not be included. Instead, the imports should stay in place, allowing Storybook to replace those imports with the actual packages during the Storybook build process. The list of packages differs between the manager and the preview, which is why there is a slight difference between `managerEntries` and `previewEntries`. Most notably, `react` and `react-dom` are prebundled in the manager but not in the preview. This means that your manager entries can use React to build UI without bundling it or having a direct reference to it. Therefore, it is safe to have React as a `devDependency` even though you are using it in production. _Requiring React as a peer dependency would unnecessarily force your users to install React._ An exception to this rule is if you are using React to inject UI into the preview, which does not come prebundled with React. In such cases, you need to move `react` and `react-dom` to a peer dependency. However, we generally advise against this pattern since it would limit the usage of your addon to React-based Storybooks. ### Sample documentation template ````md # My Addon ## Installation First, install the package. ```sh npm install --save-dev storybook-addon-aem-style-system ``` Then, register it as an addon in `.storybook/main.js`. ```js // .storybook/main.ts // Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite) import type { StorybookConfig } from '@storybook/your-framework'; const config: StorybookConfig = { // ...rest of config addons: [ '@storybook/addon-essentials' 'my-addon', // 👈 register the addon here ], }; export default config; ``` ## Usage The primary way to use this addon is to define the `exampleParameter` parameter. You can do this the component level, as below, to affect all stories in the file, or you can do it for a single story. ```js // Button.stories.ts // Replace your-framework with the name of your framework import type { Meta } from '@storybook/your-framework'; import { Button } from './Button'; const meta: Meta<typeof Button> = { component: Button, parameters: { myAddon: { exampleParameter: true, // See API section below for available parameters } } }; export default meta; ``` ## Release Management ### Setup This project is configured to use [auto](https://github.com/intuit/auto) for release management. It generates a changelog and pushes it to both GitHub and npm. Therefore, you need to configure access to both: - [`NPM_TOKEN`](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-access-tokens) Create a token with both _Read and Publish_ permissions. - [`GH_TOKEN`](https://github.com/settings/tokens) Create a token with the `repo` scope. Then open your `package.json` and edit the following fields: - `name` - `author` - `repository` #### Local To use `auto` locally create a `.env` file at the root of your project and add your tokens to it: ```bash GH_TOKEN=<value you just got from GitHub> NPM_TOKEN=<value you just got from npm> ``` #### GitHub Actions This template comes with GitHub actions already set up to publish your addon anytime someone pushes to your repository. Go to `Settings > Secrets`, click `New repository secret`, and add your `NPM_TOKEN`. ### Creating a release To create a release locally you can run the following command, otherwise the GitHub action will make the release for you. ```sh npm run release ``` That will: - Build and package the addon code - Bump the version - Push a release to GitHub and npm - Push a changelog to GitHub