-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
171 additions
and
80 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
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
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,22 +1,43 @@ | ||
import { TransformOptions } from '@babel/core'; | ||
import { Configuration } from 'webpack'; | ||
|
||
export function babel(config: TransformOptions) { | ||
// Ensure plugins are defined or fallback to an array to avoid empty values. | ||
const babelConfigPlugins = config.plugins || []; | ||
|
||
const extraPlugins = [ | ||
[ | ||
require.resolve('babel-plugin-react-docgen'), | ||
export function babel( | ||
config: TransformOptions, | ||
{ typescript: { docgen = 'react-docgen-typescript' } } = { typescript: {} } | ||
) { | ||
return { | ||
...config, | ||
overrides: [ | ||
{ | ||
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES', | ||
test: docgen === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/, | ||
plugins: [ | ||
[ | ||
require.resolve('babel-plugin-react-docgen'), | ||
{ | ||
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES', | ||
}, | ||
], | ||
], | ||
}, | ||
], | ||
]; | ||
}; | ||
} | ||
|
||
// If `babelConfigPlugins` is not an `Array`, calling `concat` will inject it | ||
// as a single value, if it is an `Array` it will spread. | ||
export function webpackFinal( | ||
config: Configuration, | ||
{ typescript: { docgen = 'react-docgen-typescript' } } = { typescript: {} } | ||
) { | ||
if (docgen !== 'react-docgen-typescript') return config; | ||
return { | ||
...config, | ||
plugins: [].concat(babelConfigPlugins, extraPlugins), | ||
module: { | ||
...config.module, | ||
rules: [ | ||
...config.module.rules, | ||
{ | ||
loader: require.resolve('react-docgen-typescript-loader'), | ||
}, | ||
], | ||
}, | ||
}; | ||
} |
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
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 @@ | ||
# Storybook TS example | ||
|
||
This Storybook demonstrates support for TypeScript in Storybook without additional configuration. |
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,7 @@ | ||
module.exports = { | ||
stories: ['./src/*.stories.*'], | ||
typescript: { | ||
check: true, | ||
checkOptions: {}, | ||
}, | ||
}; |
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,19 @@ | ||
{ | ||
"name": "@storybook/example-react-ts", | ||
"version": "6.0.0-beta.7", | ||
"private": true, | ||
"scripts": { | ||
"build-storybook": "cross-env STORYBOOK_DISPLAY_WARNING=true DISPLAY_WARNING=true build-storybook -c ./", | ||
"debug": "cross-env NODE_OPTIONS=--inspect-brk STORYBOOK_DISPLAY_WARNING=true DISPLAY_WARNING=true start-storybook -p 9011 -c ./ --no-dll", | ||
"storybook": "cross-env STORYBOOK_DISPLAY_WARNING=true DISPLAY_WARNING=true start-storybook -p 9011 -c ./ --no-dll" | ||
}, | ||
"dependencies": { | ||
"@storybook/react": "6.0.0-beta.7", | ||
"@types/react": "^16.9.35", | ||
"@types/react-dom": "^16.9.8", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1", | ||
"typescript": "^3.9.2", | ||
"webpack": "^4.43.0" | ||
} | ||
} |
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,6 @@ | ||
import React from 'react'; | ||
import { Button } from './button'; | ||
|
||
export default { component: Button, title: 'Examples / Button' }; | ||
|
||
export const SimpleButton = () => <Button label="Click me" />; |
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,7 @@ | ||
import React, { FC, ButtonHTMLAttributes } from 'react'; | ||
|
||
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
label: string; | ||
} | ||
|
||
export const Button = ({ label }: ButtonProps) => <button type="button">{label}</button>; |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"skipLibCheck": true, | ||
"jsx": "preserve", | ||
"esModuleInterop": true, | ||
"strict": true | ||
}, | ||
"include": ["src/*"] | ||
} |
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
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,8 @@ | ||
/** | ||
* Returns true if the framework can use the base TS config. | ||
* @param {string} framework | ||
*/ | ||
export const useBaseTsSupport = (framework) => { | ||
// These packages both have their own TS implementation. | ||
return !['vue', 'angular'].includes(framework); | ||
}; |
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
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
Oops, something went wrong.