-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addon essentials #9019
Merged
Merged
Addon essentials #9019
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ef00c53
Addon-essentials: Proof of concept
shilman fd3c02e
Merge branch 'fix/8864-preset-as-a-fn' into 5731-addon-essentials-pre…
shilman a26ff8f
Merge branch 'next' into 5731-addon-essentials-preset-function
shilman e242612
Essentials first draft
shilman 246ffa6
Warn if addon-essentials detects an addon already installed
shilman 599ed92
Fix node typings
shilman 08579e0
Fix linting
shilman a595ac2
Merge branch 'next' into 5731-addon-essentials-preset-function
shilman 34d1b8f
Addon-essentials: Disable addons (rather than reconfigure)
shilman c00f4b8
Merge branch 'next' into 5731-addon-essentials-preset-function
shilman 50fdbe8
Update cra-ts-essneitals to triconfig
shilman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,54 @@ | ||
# Storybook Essentials | ||
|
||
Storybook Essentials is a curated collection of addons to bring out the best of Storybook. | ||
|
||
Each addon is documented and maintained by the core team and will be upgraded alongside Storybook as the platform evolves. We will also do our best to maintain [framework support](https://github.com/storybookjs/storybook/blob/master/ADDONS_SUPPORT.md) for all of the officially supported frameworks. | ||
|
||
## Contents | ||
|
||
Storybook essentials includes the following addons. Addons can be disabled and re-configured as [described below](#configuration): | ||
|
||
- [Actions](https://github.com/storybookjs/storybook/tree/next/addons/actions) | ||
- [Backgrounds](https://github.com/storybookjs/storybook/tree/next/addons/backgrounds) | ||
- [Knobs](https://github.com/storybookjs/storybook/tree/next/addons/knobs) | ||
- [Links](https://github.com/storybookjs/storybook/tree/next/addons/links) | ||
- [Viewport](https://github.com/storybookjs/storybook/tree/next/addons/viewport) | ||
|
||
## Installation | ||
|
||
You can add Essentials to your project with: | ||
|
||
``` | ||
npm install --save-dev @storybook/addon-essentials | ||
``` | ||
|
||
And then add the following line to your `.storybook/main.js`: | ||
|
||
```js | ||
module.exports = { | ||
presets: ['@storybook/addon-essentials'], | ||
}; | ||
``` | ||
|
||
## Configuration | ||
|
||
Essentials is "zero config." That means that comes with a recommended configuration out of the box. | ||
|
||
If you want to reconfigure an addon, simply install that addon per that addon's installation instructions and configure it as normal. Essentials scans your project's `package.json` on startup and if detects one of its addons is already installed, it will skip that addon's configuration entirely. | ||
|
||
## Disabling addons | ||
|
||
Yuu can disable any of Essential's addons using the following configuration scheme in `.storybook/main.js`: | ||
|
||
```js | ||
module.exports = { | ||
presets: [{ | ||
name: '@storybook/addon-essentials'], | ||
options: { | ||
<addon-key>: false, | ||
} | ||
}] | ||
}; | ||
``` | ||
|
||
Valid addon keys include: `actions`, `backgrounds`, `knobs`, `links`, `viewport` |
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,52 @@ | ||
{ | ||
"name": "@storybook/addon-essentials", | ||
"version": "5.3.0-beta.16", | ||
"description": "Curated addons to bring out the best of Storybook", | ||
"keywords": [ | ||
"addon", | ||
"essentials", | ||
"storybook" | ||
], | ||
"homepage": "https://github.com/storybookjs/storybook/tree/master/addons/essentials", | ||
"bugs": { | ||
"url": "https://github.com/storybookjs/storybook/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/storybookjs/storybook.git", | ||
"directory": "addons/essentials" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"dist/**/*", | ||
"README.md" | ||
], | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"prepare": "node ../../scripts/prepare.js" | ||
}, | ||
"dependencies": { | ||
"@storybook/addon-actions": "5.3.0-beta.16", | ||
"@storybook/addon-backgrounds": "5.3.0-beta.16", | ||
"@storybook/addon-docs": "5.3.0-beta.16", | ||
"@storybook/addon-knobs": "5.3.0-beta.16", | ||
"@storybook/addon-links": "5.3.0-beta.16", | ||
"@storybook/addon-viewport": "5.3.0-beta.16", | ||
"@storybook/addons": "5.3.0-beta.16", | ||
"@storybook/api": "5.3.0-beta.16", | ||
"@storybook/node-logger": "5.3.0-beta.16", | ||
"ts-dedent": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.11" | ||
}, | ||
"peerDependencies": { | ||
"babel-loader": "^8.0.0", | ||
"react": "^16.8.0", | ||
"react-is": "^16.8.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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,45 @@ | ||
import fs from 'fs'; | ||
import { logger } from '@storybook/node-logger'; | ||
|
||
type PresetOptions = { | ||
actions?: any; | ||
backgrounds?: any; | ||
docs?: any; | ||
knobs?: any; | ||
links?: any; | ||
viewport?: any; | ||
}; | ||
|
||
let packageJson: any = {}; | ||
if (fs.existsSync('./package.json')) { | ||
try { | ||
packageJson = JSON.parse(fs.readFileSync('./package.json').toString()); | ||
} catch (err) { | ||
logger.error(`Error reading package.json: ${err.message}`); | ||
} | ||
} | ||
|
||
const isInstalled = (addon: string) => { | ||
const { dependencies, devDependencies } = packageJson; | ||
return (dependencies && dependencies[addon]) || (devDependencies && devDependencies[addon]); | ||
}; | ||
|
||
const makeAddon = (key: string) => `@storybook/addon-${key}`; | ||
|
||
export function presets(options: PresetOptions = {}) { | ||
const presetAddons = ['docs', 'knobs'] | ||
.filter(key => (options as any)[key] !== false) | ||
.map(key => makeAddon(key)) | ||
.filter(addon => !isInstalled(addon)) | ||
.map(addon => `${addon}/preset`); | ||
return presetAddons; | ||
} | ||
|
||
export function addons(entry: any[] = [], options: PresetOptions = {}) { | ||
const registerAddons = ['actions', 'backgrounds', 'links', 'viewport'] | ||
.filter(key => (options as any)[key] !== false) | ||
.map(key => makeAddon(key)) | ||
.filter(addon => !isInstalled(addon)) | ||
.map(addon => `${addon}/register`); | ||
return [...entry, ...registerAddons]; | ||
} |
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 @@ | ||
declare module 'fs'; |
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,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"types": ["webpack-env", "jest"] | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["src/**.test.ts"] | ||
} |
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/preset'); |
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,4 @@ | ||
import { addDecorator } from '@storybook/client-api'; | ||
import { withKnobs } from '../index'; | ||
|
||
addDecorator(withKnobs); |
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,15 @@ | ||
type KnobsOptions = { | ||
addDecorator?: boolean; | ||
}; | ||
|
||
export function addons(entry: any[] = [], options: any) { | ||
return [...entry, require.resolve('../register')]; | ||
} | ||
|
||
export function config(entry: any[] = [], { addDecorator = true }: KnobsOptions = {}) { | ||
const knobsConfig = []; | ||
if (addDecorator) { | ||
knobsConfig.push(require.resolve('./addDecorator')); | ||
} | ||
return [...entry, ...knobsConfig]; | ||
} |
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,4 @@ | ||
import { configure } from '@storybook/react'; | ||
|
||
// automatically import all files ending in *.stories.(tsx|jsx) | ||
configure(require.context('../src/stories', true, /\.stories\.[tj]sx?$/), module); | ||
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,9 @@ | ||
module.exports = [ | ||
'@storybook/preset-create-react-app', | ||
{ | ||
name: '@storybook/addon-essentials', | ||
options: { | ||
backgrounds: false, | ||
}, | ||
}, | ||
]; |
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 @@ | ||
Demonstrate `@storybook/addon-essentials` default configuration with CRA / 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,44 @@ | ||
{ | ||
"name": "cra-ts-essentials", | ||
"version": "5.3.0-beta.16", | ||
"private": true, | ||
"scripts": { | ||
"build": "react-scripts build", | ||
"build-storybook": "build-storybook -s public", | ||
"eject": "react-scripts eject", | ||
"start": "react-scripts start", | ||
"storybook": "start-storybook -p 9009 -s public", | ||
"test": "react-scripts test" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"eslintConfig": { | ||
"extends": "react-app" | ||
}, | ||
"dependencies": { | ||
"@types/jest": "24.0.22", | ||
"@types/node": "12.12.6", | ||
"@types/react": "16.9.11", | ||
"@types/react-dom": "16.9.4", | ||
"react": "^16.11.0", | ||
"react-dom": "^16.11.0", | ||
"react-scripts": "3.2.0", | ||
"typescript": "3.7.2" | ||
}, | ||
"devDependencies": { | ||
"@storybook/addon-essentials": "5.3.0-beta.16", | ||
"@storybook/addons": "5.3.0-beta.16", | ||
"@storybook/preset-create-react-app": "^1.2.0", | ||
"@storybook/react": "5.3.0-beta.16" | ||
} | ||
} |
Binary file not shown.
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,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta | ||
name="description" | ||
content="Web site created using create-react-app" | ||
/> | ||
<link rel="apple-touch-icon" href="logo192.png" /> | ||
<!-- | ||
manifest.json provides metadata used when your web app is installed on a | ||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
|
||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>React App</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
|
||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
|
||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,25 @@ | ||
{ | ||
"short_name": "React App", | ||
"name": "Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
}, | ||
{ | ||
"src": "logo192.png", | ||
"type": "image/png", | ||
"sizes": "192x192" | ||
}, | ||
{ | ||
"src": "logo512.png", | ||
"type": "image/png", | ||
"sizes": "512x512" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
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,2 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * |
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,22 @@ | ||
.App { | ||
text-align: center; | ||
} | ||
|
||
.App-logo { | ||
height: 40vmin; | ||
} | ||
|
||
.App-header { | ||
background-color: #282c34; | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: calc(10px + 2vmin); | ||
color: white; | ||
} | ||
|
||
.App-link { | ||
color: #09d3ac; | ||
} |
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,9 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<App />, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); |
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,26 @@ | ||
import React from 'react'; | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
|
||
const App: React.FC = () => { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.tsx</code> and save to reload. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do a triconfig setup?