generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from j3rem1e/svelte-csf
Svelte CSF Stories
- Loading branch information
Showing
58 changed files
with
1,260 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
presets: ["@babel/preset-env", "@babel/preset-react"], | ||
} | ||
presets: ['@babel/preset-env', '@babel/preset-typescript'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
|
||
[*.{js,json,ts,svelte,html}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
dist | ||
build | ||
coverage | ||
node_modules | ||
*.d.ts | ||
!.remarkrc.js | ||
!.babelrc.js | ||
!.eslintrc.js | ||
!.eslintrc-markdown.js | ||
!.jest.config.js | ||
!.storybook | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['@storybook/eslint-config-storybook'], | ||
overrides: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
{} | ||
{ | ||
"printWidth": 100, | ||
"tabWidth": 2, | ||
"bracketSpacing": true, | ||
"trailingComma": "es5", | ||
"singleQuote": true, | ||
"arrowParens": "always" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
module.exports = { | ||
stories: [ | ||
"../stories/**/*.stories.mdx", | ||
"../stories/**/*.stories.@(js|jsx|ts|tsx)", | ||
"../stories/**/*.stories.svelte", | ||
], | ||
addons: [ | ||
"../preset.js", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-knobs", | ||
], | ||
addons: ["../preset.js"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"deepscan.enable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,50 @@ | ||
# Storybook Addon Kit | ||
# Svelte Story Format | ||
|
||
Simplify the creation of Storybook addons | ||
Allows to write your stories in svelte syntax. | ||
|
||
- 📝 Live-editing in development | ||
- ⚛️ React/JSX support | ||
- 📦 Transpiling and bundling with Babel | ||
- 🏷 Plugin metadata | ||
- 🚢 Release management with [Auto](https://github.com/intuit/auto) | ||
- 🧺 Boilerplate and sample code | ||
It supports: | ||
|
||
## Getting Started | ||
- args stories and stories without args ; | ||
- the "template" pattern for args stories, compatible with a svelte syntax ; | ||
- extractions of sources of the stories and compatible with addon-sources | ||
- decorators | ||
- knobs, actions, controls | ||
- storyshots (with a special jest transformation shipped under @storybook/addon-svelte-csf/jest-transform) | ||
|
||
Click the **Use this template** button to get started. | ||
## Example | ||
|
||
![](https://user-images.githubusercontent.com/42671/106809879-35b32000-663a-11eb-9cdc-89f178b5273f.gif) | ||
|
||
Clone your repository and install dependencies. | ||
|
||
```sh | ||
npm install | ||
``` | ||
<script> | ||
import { Meta, Story, Template } from '@storybook/addon-svelte-csf'; | ||
### Development scripts | ||
|
||
- `npm run start` runs babel in watch mode and starts Storybook | ||
- `npm run build` build and package your addon code | ||
|
||
## What's included? | ||
|
||
The addon code lives in `src`. It demonstrates all core addon related concepts. The three [UI paradigms](https://storybook.js.org/docs/react/addons/addon-types#ui-based-addons) | ||
|
||
- `src/Tool.js` | ||
- `src/Panel.js` | ||
- `src/Tab.js` | ||
|
||
Which, along with the addon itself, are registered in `src/preset/manager.js`. | ||
|
||
Managing State and interacting with a story: | ||
|
||
- `src/withGlobals.js` & `src/Tool.js` demonstrates how to use `useGlobals` to manage global state and modify the contents of a Story. | ||
- `src/withRoundTrip.js` & `src/Panel.js` demonstrates two-way communication using channels. | ||
- `src/Tab.js` demonstrates how to use `useParameter` to access the current story's parameters. | ||
|
||
Your addon might use one or more of these patterns. Feel free to delete unused code. Update `src/preset/manager.js` and `src/preset/preview.js` accordingly. | ||
|
||
Lastly, configure you addon name in `src/constants.js`. | ||
import Button from './Button.svelte'; | ||
### Metadata | ||
let count = 0; | ||
function handleClick() { | ||
count += 1; | ||
} | ||
</script> | ||
Storybook addons are listed in the [catalog](https://storybook.js.org/addons) and distributed via npm. The catalog is populated by querying npm's registry for Storybook-specific metadata in `package.json`. This project has been configured with sample data. Learn more about available options in the [Addon metadata docs](https://storybook.js.org/docs/react/addons/addon-catalog#addon-metadata). | ||
<Meta title="Button" component={Button}/> | ||
## Release management | ||
<Template let:args> | ||
<Button {...args} on:click={handleClick}> | ||
You clicked: {count} | ||
</Button> | ||
</Template> | ||
### Setup | ||
<Story name="Rounded" args={{rounded: true}}/> | ||
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: | ||
<Story name="Square" source args={{rounded: false}}/> | ||
- Authenticate using [`npm adduser`](https://docs.npmjs.com/cli/adduser.html) | ||
- Create an [access token](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-access-tokens). You’ll need a token with both _Read and Publish_ permissions. | ||
- Similarly, generate a [Github token](https://github.com/settings/tokens). This token will need the repo scope. | ||
|
||
Create a `.env` file at the root of your project and add both these tokens to it: | ||
|
||
``` | ||
GH_TOKEN=<value you just got from GitHub> | ||
NPM_TOKEN=<value you just got from npm> | ||
``` | ||
|
||
Lastly, **create labels on GitHub**. You’ll use these labels in the future when making changes to the package. | ||
|
||
``` | ||
npx auto create-labels | ||
<!-- Dynamic snippet should be disabled for this story --> | ||
<Story name="Button No Args"> | ||
<Button>Label</Button> | ||
</Story> | ||
``` | ||
|
||
If you check on GitHub, you’ll now see a set of labels that Auto would like you to use. Use these to tag future pull requests. | ||
|
||
### Creating a releasing | ||
|
||
```sh | ||
npm run release | ||
``` | ||
# Getting Started | ||
|
||
That will: | ||
1. Add '@storybook/addon-svelte-csf' to your dev dependencies | ||
2. In `.storybook/main.js`, add `*.stories.svelte` to the stories patterns | ||
|
||
- Build and package the addon code | ||
- Bump the version | ||
- Push a release to GitHub and npm | ||
- Push a changelog to GitHub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'file-stub'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/jest-transform'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
transform: { | ||
'^.+\\.[jt]s$': 'babel-jest', | ||
'^.+\\.stories\\.svelte$': '<rootDir>/src/jest-transform', | ||
'^.+\\.svelte$': 'svelte-jester', | ||
}, | ||
moduleNameMapper: { | ||
'!!raw-loader!.*': '<rootDir>/__mocks__/fileMock.js', | ||
}, | ||
moduleFileExtensions: ['js', 'ts', 'svelte', 'json'], | ||
testEnvironment: 'jest-environment-jsdom-thirteen', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require("./dist/preset") | ||
module.exports = require('./dist/preset'); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.