Merge branch 'next' of github.com:storybookjs/storybook into jeppe/sb-734-add-eslint-rule-to-enforce-ts-expect

This commit is contained in:
Jeppe Reinhold 2022-09-15 13:27:55 +02:00
commit 965fc5a655
149 changed files with 974 additions and 793 deletions

View File

@ -151,7 +151,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 15
parallelism: 14
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'

View File

@ -147,7 +147,7 @@ Then run `yarn cypress open` if you want to see the tests run in the UI, or `yar
The best way to help figure out an issue you are having is to produce a minimal reproduction against the `main` branch.
A good way to do that is using the example `cra-kitchen-sink` app embedded in this repository:
A good way to do that is using the example `official-storybook` app embedded in this repository:
```sh
# Download and build this repository:
@ -157,7 +157,7 @@ yarn
yarn bootstrap --core
# make changes to try and reproduce the problem, such as adding components + stories
cd examples/cra-kitchen-sink
cd examples/official-storybook
yarn storybook
# see if you can see the problem, if so, commit it:

1
code/.gitignore vendored
View File

@ -21,7 +21,6 @@ package-lock.json
storybook-static
integration/__image_snapshots__/__diff_output__
.jest-test-results.json
/examples/cra-kitchen-sink/src/__image_snapshots__/__diff_output__/
lib/*.jar
lib/**/dll
/false

View File

@ -58,7 +58,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -31,7 +31,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -58,7 +58,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -53,7 +53,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -45,7 +45,7 @@
"!__testfixtures__"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -29,7 +29,7 @@
"README.md"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -33,7 +33,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -54,7 +54,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -55,7 +55,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -59,7 +59,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -57,7 +57,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -60,7 +60,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -31,7 +31,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -53,7 +53,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -55,7 +55,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -4,40 +4,29 @@ import { BrowserTestingModule } from '@angular/platform-browser/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [BrowserTestingModule],
declarations: [AppComponent],
}).compileComponents();
})
);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [BrowserTestingModule],
declarations: [AppComponent],
}).compileComponents();
}));
it(
'should create the app',
waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
})
);
it('should create the app', waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(
`should have as title 'app'`,
waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app');
})
);
it(`should have as title 'app'`, waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app');
}));
it(
'should render title in a h1 tag',
waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
})
);
it('should render title in a h1 tag', waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
}));
});

View File

@ -1,3 +0,0 @@
DISABLE_ESLINT_PLUGIN=true
SKIP_PREFLIGHT_CHECK=true
NODE_PATH=src

View File

@ -1,52 +0,0 @@
import type { StorybookConfig } from '@storybook/react-webpack5';
const path = require('path');
const mainConfig: StorybookConfig = {
stories: ['../src/stories/**/*.stories.@(ts|tsx|js|jsx|mdx)'],
logLevel: 'debug',
addons: [
'@storybook/preset-create-react-app',
{
name: '@storybook/addon-docs/preset',
options: {
configureJSX: true,
},
},
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/addon-backgrounds',
'@storybook/addon-a11y',
'@storybook/addon-jest',
'@storybook/addon-highlight',
],
// add monorepo root as a valid directory to import modules from
webpackFinal: (config) => {
const resolvePlugins = config.resolve?.plugins;
if (Array.isArray(resolvePlugins)) {
resolvePlugins.forEach((p) => {
// @ts-expect-error (Converted from ts-ignore)
const appSrcs = p.appSrcs as unknown as string[];
if (Array.isArray(appSrcs)) {
appSrcs.push(path.join(__dirname, '..', '..', '..'));
}
});
}
return config;
},
core: {
disableTelemetry: true,
channelOptions: { allowFunction: false, maxDepth: 10 },
},
staticDirs: ['../public'],
features: {
buildStoriesJson: true,
breakingChangesV7: true,
},
framework: {
name: '@storybook/react-webpack5',
options: { fastRefresh: true },
},
};
module.exports = mainConfig;

View File

@ -1,14 +0,0 @@
import { create } from '@storybook/theming/create';
import { addons } from '@storybook/addons';
addons.setConfig({
isFullscreen: false,
showAddonsPanel: true,
panelPosition: 'right',
theme: create({
base: 'light',
brandTitle: 'CRA Kitchen Sink',
brandUrl: 'https://github.com/storybookjs/storybook/tree/master/examples/cra-kitchen-sink',
gridCellSize: 12,
}),
});

View File

@ -1,11 +0,0 @@
export const parameters = {
options: {
storySort: (a, b) =>
a.title === b.title ? 0 : a.id.localeCompare(b.id, undefined, { numeric: true }),
},
docs: {
source: {
excludeDecorators: true,
},
},
};

View File

@ -1,46 +0,0 @@
{
"name": "cra-kitchen-sink",
"version": "7.0.0-alpha.33",
"private": true,
"scripts": {
"build": "react-scripts build",
"build-storybook": "storybook build",
"eject": "react-scripts eject",
"start": "react-scripts start",
"storybook": "storybook dev -p 9010 --no-manager-cache",
"test": "react-scripts test --env=jsdom"
},
"dependencies": {
"@storybook/client-logger": "7.0.0-alpha.33",
"global": "^4.4.0",
"prop-types": "^15.7.2",
"react": "16.14.0",
"react-dom": "16.14.0",
"react-lifecycles-compat": "^3.0.4",
"react-scripts": "^5.0.1"
},
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
"@storybook/addon-a11y": "7.0.0-alpha.33",
"@storybook/addon-actions": "7.0.0-alpha.33",
"@storybook/addon-backgrounds": "7.0.0-alpha.33",
"@storybook/addon-docs": "7.0.0-alpha.33",
"@storybook/addon-highlight": "7.0.0-alpha.33",
"@storybook/addon-jest": "7.0.0-alpha.33",
"@storybook/addon-links": "7.0.0-alpha.33",
"@storybook/addon-storyshots": "7.0.0-alpha.33",
"@storybook/addons": "7.0.0-alpha.33",
"@storybook/builder-webpack5": "7.0.0-alpha.33",
"@storybook/preset-create-react-app": "^4.1.0",
"@storybook/react": "7.0.0-alpha.33",
"@storybook/react-webpack5": "7.0.0-alpha.33",
"@storybook/theming": "7.0.0-alpha.33",
"storybook": "7.0.0-alpha.33",
"webpack": "5"
},
"storybook": {
"chromatic": {
"projectToken": "tg55gajmdt"
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1,28 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<!--
Notice the use of %PUBLIC_URL% in the tag 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>
<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`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>

View File

@ -1,30 +0,0 @@
@import './base.css';
.App {
text-align: center;
}
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}
.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}
.App-intro {
font-size: large;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

View File

@ -1,17 +0,0 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
const App = () => (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>
);
export default App;

View File

@ -1,9 +0,0 @@
:root {
background: rgba(232, 232, 232, 1);
background: radial-gradient(
ellipse at center,
rgba(255, 255, 255, 1) 11%,
rgba(232, 232, 232, 1) 100%
);
height: 100%;
}

View File

@ -1,40 +0,0 @@
import React from 'react';
import PropTypes from 'prop-types';
const Container = ({ children, title, age, isAmazing }) => (
<div title={title}>
{children}
{isAmazing ? '!!!' : ''}
{age.isOld ? <div>age = {age.value}</div> : null}
</div>
);
Container.propTypes = {
/**
* The nodes to be rendered in the button
*
* Example value:
*
* ```
* <h1>Node 1</h1>
* <h2>Node 2</h2>
* ```
*/
children: PropTypes.node.isRequired,
/** Show exclamation marks */
isAmazing: PropTypes.bool,
/** Show age prop */
age: PropTypes.shape({
isOld: PropTypes.bool,
value: PropTypes.number,
}),
/** Main title */
title: PropTypes.string,
};
Container.defaultProps = {
isAmazing: false,
age: { isOld: false, value: 0 },
title: 'the best container ever',
};
export default Container;

View File

@ -1,12 +0,0 @@
import React from 'react';
export const FastRefreshExample = () => {
const [value, setValue] = React.useState('abc');
return (
<>
<input value={value} onChange={(event) => setValue(event.target.value)} />
<p>Change the input value then this text in the component file.</p>
<p>The state of the input should be kept.</p>
</>
);
};

View File

@ -1,53 +0,0 @@
import React, { Component } from 'react';
import { polyfill } from 'react-lifecycles-compat';
import { logger } from '@storybook/client-logger';
function log(name) {
logger.info(`LifecycleLogger: ${name}`);
}
// A component that logs its lifecycle so we can check that things happen
// the right number of times (i.e. we are using React properly)
class LifecycleLogger extends Component {
constructor() {
super();
log('constructor');
this.state = {};
}
componentDidMount() {
log('componentDidMount');
}
// deepscan-disable-next-line
getSnapshotBeforeUpdate() {
// deepscan-disable-next-line
log('getSnapshotBeforeUpdate');
}
componentDidUpdate() {
log('componentDidUpdate');
}
componentDidCatch() {
log('componentDidCatch');
}
componentWillUnmount() {
log('componentWillUnmount');
}
render() {
log('render');
return <div>Lifecycle methods are logged to the console</div>;
}
}
LifecycleLogger.getDerivedStateFromProps = () => {
log('getDerivedStateFromProps');
return null;
};
polyfill(LifecycleLogger);
export default LifecycleLogger;

View File

@ -1,34 +0,0 @@
import React from 'react';
const styles = {
border: '1px solid #eee',
borderRadius: 3,
backgroundColor: '#FFFFFF',
cursor: 'pointer',
fontSize: 15,
padding: '3px 10px',
margin: 10,
};
// eslint-disable-next-line react/prop-types
export const Button = ({ children, onClick }) => (
<button onClick={onClick} style={styles} type="button">
{children}
</button>
);
Button.displayName = 'Button';
Button.defaultProps = {
onClick: () => {},
};
// eslint-disable-next-line react/prop-types
export const Welcome = ({ showApp }) => (
<button type="button" onClick={showApp}>
Welcome
</button>
);
Welcome.displayName = 'Welcome';
Welcome.defaultProps = {
showApp: () => {},
};

View File

@ -1,5 +0,0 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}

View File

@ -1,10 +0,0 @@
import React from 'react';
import ReactDOM from 'react-dom';
import global from 'global';
import App from './App';
import './index.css';
const { document } = global;
ReactDOM.render(<App />, document.getElementById('root'));

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -1,16 +0,0 @@
// FIXME: svgr issue @igor-dv
import React from 'react';
import App from '../App';
export default {
title: 'App',
parameters: {
layout: 'fullscreen',
},
};
export const FullApp = () => <App />;
FullApp.storyName = 'full app';

View File

@ -1,8 +0,0 @@
import React from 'react';
import LifecycleLogger from '../components/LifecycleLogger';
export default {
title: 'Lifecycle',
};
export const Logging = () => <LifecycleLogger />;

View File

@ -1,27 +0,0 @@
import React from 'react';
import { Button } from '../components/react-demo';
export default {
title: 'Button',
component: Button,
};
export const Story1 = () => <Button>Hello Button</Button>;
Story1.storyName = 'with text';
Story1.parameters = {
options: { selectedPanel: 'storybook/actions/panel' },
};
export const Story2 = () => (
<Button>
<span role="img" aria-label="yolo">
😀 😎 👍 💯
</span>
</Button>
);
Story2.storyName = 'with some emoji';
Story2.parameters = {
options: { selectedPanel: 'storybook/actions/panel' },
};

View File

@ -1,9 +0,0 @@
import React from 'react';
import { FastRefreshExample } from '../components/FastRefreshExample';
export default {
title: 'React Fast Refresh',
component: FastRefreshExample,
};
export const Default = () => <FastRefreshExample />;

View File

@ -1,19 +0,0 @@
import React from 'react';
import { forceReRender } from '@storybook/react';
import { Button } from '../components/react-demo';
let count = 0;
const increment = () => {
count += 1;
forceReRender();
};
export default {
title: 'Force ReRender',
};
export const DefaultView = () => (
<Button type="button" onClick={increment}>
Click me to increment: {count}
</Button>
);

View File

@ -1,9 +0,0 @@
import React from 'react';
import { Button } from '../components/react-demo';
export default {
title: 'Some really long story kind description',
};
export const Story1 = () => <Button>Hello Button</Button>;
Story1.storyName = 'with text';

View File

@ -1,14 +0,0 @@
import { Story, Meta, ArgsTable } from '@storybook/addon-docs';
import Container from '../components/Container'
<Meta title="Docs/Test" component={Container} />
<Story name="NewStory123">
<Container>
<h1>Hello</h1>
</Container>
</Story>
## Arguments
<ArgsTable story="NewStory123" />

View File

@ -1,10 +0,0 @@
import React from 'react';
import { Welcome } from '../components/react-demo';
export default {
title: 'Welcome',
component: Welcome,
};
export const Story1 = () => <Welcome showApp={() => {}} />;
Story1.title = 'to Storybook';

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -26,7 +26,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -46,7 +46,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -46,7 +46,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -47,7 +47,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -47,7 +47,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -46,7 +46,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -47,7 +47,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -47,7 +47,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -46,7 +46,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -47,7 +47,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -46,7 +46,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -48,7 +48,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -27,7 +27,6 @@ module.exports = {
projects: [
'<rootDir>',
// '<rootDir>/app/angular',
// '<rootDir>/examples/cra-kitchen-sink',
// '<rootDir>/examples/cra-ts-kitchen-sink',
// '<rootDir>/examples/html-kitchen-sink',
// '<rootDir>/examples/svelte-kitchen-sink',

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -28,7 +28,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -37,7 +37,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -14,7 +14,7 @@
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -29,7 +29,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -38,7 +38,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -21,7 +21,7 @@
"license": "MIT",
"bin": "./index.js",
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -24,7 +24,7 @@
"storybook": "./index.js"
},
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -36,7 +36,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts",
"test": "jest test/**/*.test.js"
},

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -38,7 +38,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -31,7 +31,7 @@
"!__testfixtures__"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -47,7 +47,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -1,19 +1,6 @@
import global from 'global';
import { ZoomElement } from './ZoomElement';
import { ZoomIFrame } from './ZoomIFrame';
const { window: globalWindow } = global;
export const browserSupportsCssZoom = (): boolean => {
try {
return (
globalWindow.document.implementation.createHTMLDocument('').body.style.zoom !== undefined
);
} catch (error) {
return false;
}
};
export const Zoom = {
Element: ZoomElement,
IFrame: ZoomIFrame,

View File

@ -1,9 +1,20 @@
import React, { ReactElement, useEffect, useRef, useState } from 'react';
/* global MutationObserver */
import React, {
ReactElement,
useEffect,
useRef,
useState,
useMemo,
RefObject,
useCallback,
} from 'react';
import { styled } from '@storybook/theming';
import { browserSupportsCssZoom } from './browserSupportsCssZoom';
const hasBrowserSupportForCssZoom = browserSupportsCssZoom();
const ZoomElementWrapper = styled.div<{ scale: number; height: number }>(({ scale = 1, height }) =>
browserSupportsCssZoom()
hasBrowserSupportForCssZoom
? {
'> *': {
zoom: 1 / scale,
@ -15,6 +26,35 @@ const ZoomElementWrapper = styled.div<{ scale: number; height: number }>(({ scal
transform: `scale(${1 / scale})`,
}
);
const useMutationObserver = ({
element,
options = {},
callback,
}: {
element: RefObject<Element>;
options: MutationObserverInit;
callback: MutationCallback;
}): void => {
const observer = useMemo(
() =>
new MutationObserver((mutationRecord, mutationObserver) => {
callback(mutationRecord, mutationObserver);
}),
[callback]
);
useEffect(() => {
if (element?.current) {
observer.observe(element.current, options);
}
return () => observer.disconnect();
}, [element, observer, options]);
};
const mutationObserverOptions = { subtree: true, childList: true };
type ZoomProps = {
scale: number;
children: ReactElement | ReactElement[];
@ -24,15 +64,28 @@ export function ZoomElement({ scale, children }: ZoomProps) {
const componentWrapperRef = useRef<HTMLDivElement>(null);
const [height, setHeight] = useState(0);
const handleMutations = useCallback(() => {
setHeight(componentWrapperRef.current.getBoundingClientRect().height);
}, []);
useEffect(() => {
if (componentWrapperRef.current) {
setHeight(componentWrapperRef.current.getBoundingClientRect().height);
}
}, [scale, componentWrapperRef.current]);
useMutationObserver({
element: componentWrapperRef,
options: mutationObserverOptions,
callback: handleMutations,
});
return (
<ZoomElementWrapper scale={scale} height={height}>
<div ref={componentWrapperRef} className="innerZoomElementWrapper">
<div
ref={hasBrowserSupportForCssZoom ? null : componentWrapperRef}
className="innerZoomElementWrapper"
>
{children}
</div>
</ZoomElementWrapper>

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -42,7 +42,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -8,8 +8,11 @@ export const useProgressReporting = async (
): Promise<{ handler: any; modulesCount: number }> => {
let value = 0;
let totalModules: number;
let reportProgress: (progress?: { value?: number; message: string; modules?: any }) => void =
() => {};
let reportProgress: (progress?: {
value?: number;
message: string;
modules?: any;
}) => void = () => {};
router.get('/progress', (request: Request, response: Response) => {
let closed = false;

View File

@ -38,7 +38,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"devDependencies": {

View File

@ -29,7 +29,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -38,7 +38,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -20,9 +20,17 @@
},
"license": "MIT",
"sideEffects": false,
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./package.json": "./package.json"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"README.md",
@ -30,8 +38,8 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@types/npmlog": "^4.1.2",
@ -46,5 +54,10 @@
"publishConfig": {
"access": "public"
},
"bundler": {
"entries": [
"./src/index.ts"
]
},
"gitHead": "5da5b0fabd04cc5cd5771e8242a960f05d03234a"
}

View File

@ -31,7 +31,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"devDependencies": {

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -43,7 +43,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -31,7 +31,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -17,8 +17,10 @@ export type ComposedStoryPlayContext = Partial<StoryContext> & Pick<StoryContext
export type ComposedStoryPlayFn = (context: ComposedStoryPlayContext) => Promise<void> | void;
export type StoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> =
AnnotatedStoryFn<TFramework, TArgs> & { play: ComposedStoryPlayFn };
export type StoryFn<
TFramework extends AnyFramework = AnyFramework,
TArgs = Args
> = AnnotatedStoryFn<TFramework, TArgs> & { play: ComposedStoryPlayFn };
export type ComposedStory<TFramework extends AnyFramework = AnyFramework, TArgs = Args> =
| StoryFn<TFramework, TArgs>

View File

@ -30,7 +30,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {

View File

@ -43,7 +43,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -48,7 +48,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"devDependencies": {

View File

@ -46,7 +46,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -46,7 +46,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -67,7 +67,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -51,7 +51,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -61,7 +61,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

View File

@ -56,7 +56,7 @@
"*.d.ts"
],
"scripts": {
"check": "tsc --noEmit",
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {

Some files were not shown because too many files have changed in this diff Show More