Skip to content
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

Add CRA React15 example to test back-compat #6475

Merged
merged 24 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bc62ea3
Add CRA React15 example to test back-compat
shilman Apr 10, 2019
df9ca73
Merge branch 'next' into tech/example-for-cra15-support
ndelangen Apr 26, 2019
3ee51c5
FIX tests
ndelangen Apr 26, 2019
322e3c4
FIX versions
ndelangen Apr 26, 2019
9470a6d
REFACTOR lib/theming to make creating themes work for react15
ndelangen Apr 26, 2019
9ec6265
REFACTOR lib/router to make creating themes work for react15
ndelangen Apr 26, 2019
1c12e8c
REFACTOR addon/links to make creating themes work for react15
ndelangen Apr 26, 2019
532d8cc
CHANGE config to make creating themes work for react15 example
ndelangen Apr 26, 2019
a95991d
CHANGE documentation for theming to ensure react15 compat
ndelangen Apr 26, 2019
fbcfdb9
Merge branch 'next' into tech/example-for-cra15-support
ndelangen Apr 27, 2019
f09fa53
FIX tests
ndelangen Apr 27, 2019
d0066cf
FIX now building for this new example
ndelangen Apr 27, 2019
1b2ffe3
Merge branch 'next' into tech/example-for-cra15-support
Hypnosphi May 5, 2019
5225324
Merge branch 'next' into tech/example-for-cra15-support
ndelangen May 6, 2019
06386b3
FIX build example in official storybook
ndelangen May 6, 2019
13a4523
CHANGE visibility component of router to not use theming package
ndelangen May 6, 2019
93d3759
FIX versions
ndelangen May 6, 2019
1db8d22
FIX lockfile
ndelangen May 6, 2019
0aa590f
Merge branch 'next' into tech/example-for-cra15-support
ndelangen May 7, 2019
724e011
Merge branch 'next' into tech/example-for-cra15-support
ndelangen May 7, 2019
3ae04b4
Merge branch 'next' into tech/example-for-cra15-support
ndelangen May 7, 2019
22e87a7
Merge branch 'next' into tech/example-for-cra15-support
ndelangen May 7, 2019
2ee7293
FIX lockfile
ndelangen May 7, 2019
d3cbdda
Merge branch 'next' into tech/example-for-cra15-support
ndelangen May 7, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ jobs:
command: |
cd examples/preact-kitchen-sink
yarn build-storybook
- run:
name: Build cra react15
command: |
cd examples/cra-react15
yarn build-storybook
- run:
name: Build official-storybook
command: |
Expand Down Expand Up @@ -186,6 +191,11 @@ jobs:
command: |
cd examples/preact-kitchen-sink
yarn storybook --smoke-test --quiet
- run:
name: Run cra reac15 (smoke test)
command: |
cd examples/cra-react15
yarn storybook --smoke-test --quiet
native-smoke-tests:
<<: *defaults
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import jetbrains.buildServer.configs.kotlin.v2017_2.failureConditions.failOnMetr
enum class StorybookApp(val appName: String, val exampleDir: String, val merged: Boolean = true) {
CRA("CRA", "cra-kitchen-sink"),
CRA_TS("CRA TS", "cra-ts-kitchen-sink"),
CRA_REACT15("CRA REACT15", "cra-react15"),
VUE("Vue", "vue-kitchen-sink"),
ANGULAR("Angular", "angular-cli"),
POLYMER("Polymer", "polymer-cli"),
Expand Down
2 changes: 1 addition & 1 deletion addons/links/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { document } from 'global';
import qs from 'qs';
import addons from '@storybook/addons';
import { SELECT_STORY, STORY_CHANGED } from '@storybook/core-events';
import { toId } from '@storybook/router';
import { toId } from '@storybook/router/utils';

interface Params {
kind: string;
Expand Down
8 changes: 4 additions & 4 deletions docs/src/pages/configurations/theming/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ As the simplest example example, you can tell Storybook to use the "dark" theme

```js
import { addParameters } from '@storybook/react';
import { themes } from '@storybook/theming';
import { themes } from '@storybook/theming/create';

// Option defaults.
addParameters({
Expand Down Expand Up @@ -47,14 +47,14 @@ Read on for more on how to create your own theme.

## Create a theme quickstart

The easiest way to customize Storybook is to generate a new theme using the `create()` function from `storybook/theming`. This function includes shorthands for the most common theme variables. Here's how to use it:
The easiest way to customize Storybook is to generate a new theme using the `create()` function from `storybook/theming/create`. This function includes shorthands for the most common theme variables. Here's how to use it:

First create a new file in `.storybook` called `yourTheme.js`.

Next paste the code below and tweak the variables.

```ts
import { create } from '@storybook/theming';
import { create } from '@storybook/theming/create';

export default create({
base: 'light',
Expand Down Expand Up @@ -110,7 +110,7 @@ The `storybook/theming` package is built using TypeScript, so this should help c
Many theme variables are optional, the `base` property is NOT. This is a perfectly valid theme:

```ts
import { create } from '@storybook/theming';
import { create } from '@storybook/theming/create';

export default create({
base: 'light',
Expand Down
3 changes: 3 additions & 0 deletions examples/cra-react15/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env", "react"]
}
2 changes: 2 additions & 0 deletions examples/cra-react15/.storybook/addons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@storybook/addon-actions/register';
import '@storybook/addon-links/register';
14 changes: 14 additions & 0 deletions examples/cra-react15/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { configure, addParameters } from '@storybook/react';
import { create } from '@storybook/theming/create';

function loadStories() {
require('../src/stories');
}

addParameters({
options: {
theme: create({ colorPrimary: 'hotpink', colorSecondary: 'orangered' }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think you should comment out the theme to stop this from breaking next? Will still make it much easier to test

Copy link
Member Author

@shilman shilman Apr 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmeasday Unfortunately it still breaks even if I comment that out, I think due to #6435

},
});

configure(loadStories, module);
1 change: 1 addition & 0 deletions examples/cra-react15/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a [Create React App](https://github.com/facebookincubator/create-react-app) that uses an old version of CRA and an old version of React (15.4.x). It's not meant to be exhaustive but rather to make sure we don't break legacy support.
28 changes: 28 additions & 0 deletions examples/cra-react15/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "cra-react15",
"version": "0.1.0",
"private": true,
"dependencies": {
"babel-loader": "7",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-scripts": "1.1.5",
"global": "^4.3.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 9009 -s public",
"build-storybook": "build-storybook -s public"
},
"devDependencies": {
"@storybook/addon-actions": "5.1.0-alpha.35",
"@storybook/addon-links": "5.1.0-alpha.35",
"@storybook/theming": "5.1.0-alpha.35",
"@storybook/react": "5.1.0-alpha.35",
"babel-core": "6",
"babel-runtime": "6"
}
}
Binary file added examples/cra-react15/public/favicon.ico
Binary file not shown.
40 changes: 40 additions & 0 deletions examples/cra-react15/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
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>
15 changes: 15 additions & 0 deletions examples/cra-react15/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
32 changes: 32 additions & 0 deletions examples/cra-react15/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.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-title {
font-size: 1.5em;
}

.App-intro {
font-size: large;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
22 changes: 22 additions & 0 deletions examples/cra-react15/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable react/prefer-stateless-function */
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>
);
}
}

export default App;
10 changes: 10 additions & 0 deletions examples/cra-react15/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { document } from 'global';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
5 changes: 5 additions & 0 deletions examples/cra-react15/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
7 changes: 7 additions & 0 deletions examples/cra-react15/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import { document } from 'global';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));
7 changes: 7 additions & 0 deletions examples/cra-react15/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions examples/cra-react15/src/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { linkTo } from '@storybook/addon-links';

import { Button, Welcome } from '@storybook/react/demo';

storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);

storiesOf('Button', module)
.add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)
.add('with some emoji', () => (
<Button onClick={action('clicked')}>
<span role="img" aria-label="so cool">
😀 😎 👍 💯
</span>
</Button>
));
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ exports[`Storyshots App|acceptance cra-kitchen-sink 1`] = `
/>
`;

exports[`Storyshots App|acceptance cra-react15 1`] = `
<iframe
src="cra-react15/index.html"
style="border:0;position:absolute;top:0;left:0;width:100vw;height:100vh"
title="cra-react15"
/>
`;

exports[`Storyshots App|acceptance cra-ts-kitchen-sink 1`] = `
<iframe
src="cra-ts-kitchen-sink/index.html"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const style = {
'html-kitchen-sink',
'riot-kitchen-sink',
'preact-kitchen-sink',
'cra-react15',
].forEach(name => {
chapter.add(name, () => <iframe style={style} title={name} src={`${name}/index.html`} />, {
chromatic: { delay: 2000 },
Expand Down
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ module.exports = {
'/dist/',
'addon-jest.test.js',
'/cli/test/',
'/examples/cra-kitchen-sink/src/App.test.js',
'/examples/cra-ts-kitchen-sink/src/components/',
'/examples/cra-kitchen-sink/src/*',
'/examples/cra-react15/src/*',
'/examples/cra-ts-kitchen-sink/src/components/*',
'/examples/angular-cli/src/app/*',
],
collectCoverage: false,
Expand Down
33 changes: 33 additions & 0 deletions lib/router/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
interface StoryData {
viewMode?: string;
storyId?: string;
}
interface SeparatorOptions {
rootSeparator: string | RegExp;
groupSeparator: string | RegExp;
}
export declare const knownNonViewModesRegex: RegExp;
export declare const sanitize: (string: string) => string;
export declare const toId: (kind: string, name: string) => string;
export declare const parsePath: (path?: string) => StoryData;
interface Query {
[key: string]: any;
}
export declare const queryFromString: (s: string) => Query;
export declare const queryFromLocation: (location: { search: string }) => Query;
export declare const stringifyQuery: (query: Query) => any;
export declare const getMatch: (
current: string,
target: string,
startsWith?: boolean
) => {
path: string;
};
export declare const parseKind: (
kind: string,
{ rootSeparator, groupSeparator }: SeparatorOptions
) => {
root: string;
groups: string[];
};
export {};
1 change: 1 addition & 0 deletions lib/theming/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/create');
Loading