Skip to content

Commit

Permalink
Merge branch 'master' into optimize-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
danielduan authored Feb 20, 2018
2 parents 92236d1 + 3ad0ef8 commit 4eeb9cd
Show file tree
Hide file tree
Showing 42 changed files with 822 additions and 174 deletions.
1 change: 1 addition & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exemptLabels:
- 'do not merge'
- 'needs review'
- 'high priority'
- dependencies:update

# Label to use when marking an issue as stale
staleLabel: inactive
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Storybook comes with a lot of [addons](https://storybook.js.org/addons/introduct
- [Supported Frameworks](#supported-frameworks)
- [Sub Projects](#sub-projects)
- [Addons](#addons)
- [Live Examples](#live-examples) 💪
- [Contributing](#contributing)
- [Development scripts](#development-scripts)
- [Backers](#backers)
Expand Down Expand Up @@ -91,6 +92,21 @@ For additional help, join us [in our Slack](https://now-examples-slackin-rrirkqo

See [Addon / Framework Support Table](ADDONS_SUPPORT.md)

## Live Examples

### 3.4.alpha
> Note, this is an Alpha version. Some of the features still might not be released
- [React Official](https://storybooks-official.netlify.com)
- [Vue](https://storybooks-vue.netlify.com/)
- [Angular](https://storybooks-angular.netlify.com/)
- [Polymer](https://storybooks-polymer.netlify.com/)

### 3.3
- [React Official](https://release-3-3--storybooks-official.netlify.com)
- [Vue](https://release-3-3--storybooks-vue.netlify.com/)
- [Angular](https://release-3-3--storybooks-angular.netlify.com/)

## Contributing

We welcome contributions to Storybook!
Expand Down
7 changes: 7 additions & 0 deletions addons/jest/src/components/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ const createSubgroup = (acc, item, i, list) => {

// on last iteration inject at detected injectionpoint, and group
if (i === list.length - 1) {
// Provide a "safety net" when Jest returns a partially recognized "group"
// (recognized by acc.startTrigger but acc.endTrigger was never found) and
// it's the only group in output for a test result. In that case, acc.list
// will be empty, so return whatever was found, even if it will be unstyled
// and prevent next createSubgroup calls from throwing due to empty lists.
acc.list.push(null);

return acc.list.reduce((eacc, el, ei) => {
switch (true) {
case acc.injectionPoint === 0 && ei === 0: {
Expand Down
26 changes: 24 additions & 2 deletions addons/storysource/src/StoryPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import { EVENT_ID } from './';

registerLanguage('jsx', jsx);

const styles = {
selections: {
backgroundColor: 'rgba(255, 242, 60, 0.2)',
},
panel: {
width: '100%',
},
};

export default class StoryPanel extends Component {
constructor(props) {
super(props);
Expand All @@ -23,9 +32,20 @@ export default class StoryPanel extends Component {
});
});

this.setSelectedStoryRef = this.setSelectedStoryRef.bind(this);
this.lineRenderer = this.lineRenderer.bind(this);
}

componentDidUpdate() {
if (this.selectedStoryRef) {
this.selectedStoryRef.scrollIntoView();
}
}

setSelectedStoryRef(ref) {
this.selectedStoryRef = ref;
}

createPart(rows, stylesheet, useInlineStyles) {
return rows.map((node, i) =>
createElement({
Expand All @@ -51,7 +71,9 @@ export default class StoryPanel extends Component {
return (
<span>
{start}
<div style={{ backgroundColor: 'rgba(255, 242, 60, 0.2)' }}>{selected}</div>
<div ref={this.setSelectedStoryRef} style={styles.selections}>
{selected}
</div>
{end}
</span>
);
Expand All @@ -67,7 +89,7 @@ export default class StoryPanel extends Component {
showLineNumbers="true"
style={darcula}
renderer={this.lineRenderer}
customStyle={{ width: '100%' }}
customStyle={styles.panel}
>
{this.state.source}
</SyntaxHighlighter>
Expand Down
1 change: 1 addition & 0 deletions app/angular/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NgModuleMetadata, ICollection } from './dist/client/preview/angular/types';
export { moduleMetadata } from './dist/client/preview/angular/decorators';

export interface IStorybookStory {
name: string;
Expand Down
4 changes: 2 additions & 2 deletions app/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"css-loader": "^0.28.9",
"dotenv-webpack": "^1.5.4",
"express": "^4.15.3",
"file-loader": "^1.1.6",
"file-loader": "^1.1.7",
"find-cache-dir": "^1.0.0",
"global": "^4.3.2",
"html-loader": "^0.5.5",
Expand Down Expand Up @@ -88,7 +88,7 @@
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"codelyzer": "^4.1.0",
"mock-fs": "^4.3.0",
"nodemon": "^1.15.0",
"nodemon": "^1.15.1",
"typescript": "^2.7.2"
},
"peerDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions app/angular/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { storiesOf, setAddon, addDecorator, configure, getStorybook } from './preview';

export { moduleMetadata } from './preview/angular/decorators';
99 changes: 99 additions & 0 deletions app/angular/src/client/preview/angular/decorators.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { moduleMetadata } from './decorators';
import { addDecorator, storiesOf, clearDecorators, getStorybook } from '..';

class MockModule {}
class MockModuleTwo {}
class MockService {}
class MockComponent {}

describe('moduleMetadata', () => {
it('should add metadata to a story without it', () => {
const result = moduleMetadata({
imports: [MockModule],
providers: [MockService],
})(() => ({
component: MockComponent,
}));

expect(result).toEqual({
component: MockComponent,
moduleMetadata: {
declarations: [],
entryComponents: [],
imports: [MockModule],
schemas: [],
providers: [MockService],
},
});
});

it('should combine with individual metadata on a story', () => {
const result = moduleMetadata({
imports: [MockModule],
})(() => ({
component: MockComponent,
moduleMetadata: {
imports: [MockModuleTwo],
providers: [MockService],
},
}));

expect(result).toEqual({
component: MockComponent,
moduleMetadata: {
declarations: [],
entryComponents: [],
imports: [MockModule, MockModuleTwo],
schemas: [],
providers: [MockService],
},
});
});

it('should return the original metadata if passed null', () => {
const result = moduleMetadata(null)(() => ({
component: MockComponent,
moduleMetadata: {
providers: [MockService],
},
}));

expect(result).toEqual({
component: MockComponent,
moduleMetadata: {
declarations: [],
entryComponents: [],
imports: [],
schemas: [],
providers: [MockService],
},
});
});

it('should work when added globally', () => {
const metadata = {
declarations: [MockComponent],
providers: [MockService],
entryComponents: [MockComponent],
imports: [MockModule],
};

addDecorator(moduleMetadata(metadata));

storiesOf('Test', module).add('Default', () => ({
component: MockComponent,
}));

const [storybook] = getStorybook();

expect(storybook.stories[0].render().moduleMetadata).toEqual({
declarations: [MockComponent],
providers: [MockService],
entryComponents: [MockComponent],
imports: [MockModule],
schemas: [],
});

clearDecorators();
});
});
21 changes: 21 additions & 0 deletions app/angular/src/client/preview/angular/decorators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NgModuleMetadata } from './types';

export const moduleMetadata = (metadata: Partial<NgModuleMetadata>) => (storyFn: () => any) => {
const story = storyFn();
const storyMetadata = story.moduleMetadata || {};
metadata = metadata || {};

return {
...story,
moduleMetadata: {
declarations: [...(metadata.declarations || []), ...(storyMetadata.declarations || [])],
entryComponents: [
...(metadata.entryComponents || []),
...(storyMetadata.entryComponents || []),
],
imports: [...(metadata.imports || []), ...(storyMetadata.imports || [])],
schemas: [...(metadata.schemas || []), ...(storyMetadata.schemas || [])],
providers: [...(metadata.providers || []), ...(storyMetadata.providers || [])],
},
};
};
6 changes: 6 additions & 0 deletions app/angular/src/client/preview/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function storiesOf(kind: string, module: NodeModule): IApi;
export function setAddon(addon: any): void;
export function addDecorator(decorator: any): IApi;
export function configure(loaders: () => NodeRequire, module: NodeModule): void;
export function getStorybook(): IStoribookSection[];
export function clearDecorators(): void;
4 changes: 2 additions & 2 deletions app/polymer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"css-loader": "^0.28.9",
"dotenv-webpack": "^1.5.4",
"express": "^4.16.2",
"file-loader": "^1.1.6",
"file-loader": "^1.1.7",
"find-cache-dir": "^1.0.0",
"global": "^4.3.2",
"html-webpack-plugin": "^2.30.1",
Expand All @@ -79,6 +79,6 @@
},
"devDependencies": {
"babel-cli": "^6.26.0",
"nodemon": "^1.15.0"
"nodemon": "^1.15.1"
}
}
2 changes: 1 addition & 1 deletion app/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"commander": "^2.14.1",
"css-loader": "^0.28.9",
"express": "^4.16.2",
"file-loader": "^1.1.6",
"file-loader": "^1.1.7",
"find-cache-dir": "^1.0.0",
"global": "^4.3.2",
"html-webpack-plugin": "^2.30.1",
Expand Down
4 changes: 2 additions & 2 deletions app/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"css-loader": "^0.28.9",
"dotenv-webpack": "^1.5.4",
"express": "^4.16.2",
"file-loader": "^1.1.6",
"file-loader": "^1.1.7",
"find-cache-dir": "^1.0.0",
"glamor": "^2.20.40",
"glamorous": "^4.11.6",
Expand All @@ -78,7 +78,7 @@
"webpack": "^3.11.0"
},
"devDependencies": {
"nodemon": "^1.15.0"
"nodemon": "^1.15.1"
},
"peerDependencies": {
"babel-core": "^6.26.0 || ^7.0.0-0",
Expand Down
4 changes: 2 additions & 2 deletions app/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"css-loader": "^0.28.9",
"dotenv-webpack": "^1.5.4",
"express": "^4.16.2",
"file-loader": "^1.1.6",
"file-loader": "^1.1.7",
"find-cache-dir": "^1.0.0",
"global": "^4.3.2",
"html-loader": "^0.5.5",
Expand All @@ -76,7 +76,7 @@
"webpack": "^3.11.0"
},
"devDependencies": {
"nodemon": "^1.15.0",
"nodemon": "^1.15.1",
"vue": "^2.5.13",
"vue-loader": "^13.7.1",
"vue-template-compiler": "^2.5.13"
Expand Down
2 changes: 1 addition & 1 deletion dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ collectors:
versions: "L.Y.Y"
settings:
batch_mode: true
# batch_bootstrap: true
batch_bootstrap: true
bootstrap_command: yarn --ignore-scripts --ignore-engines --silent
github_labels:
- dependencies:update
Expand Down
1 change: 1 addition & 0 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
'/basics/exporting-storybook/',
'/basics/faq/',
'/basics/community/',
'/basics/live-examples/',
],
configurations: [
'/configurations/default-config/',
Expand Down
8 changes: 4 additions & 4 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
"bootstrap": "^3.3.7",
"gatsby": "^1.9.202",
"gatsby-link": "^1.6.37",
"gatsby-plugin-sharp": "^1.6.30",
"gatsby-plugin-sharp": "^1.6.31",
"gatsby-remark-autolink-headers": "^1.4.12",
"gatsby-remark-copy-linked-files": "^1.5.27",
"gatsby-remark-images": "^1.5.46",
"gatsby-remark-images": "^1.5.47",
"gatsby-remark-smartypants": "^1.4.11",
"gatsby-source-filesystem": "^1.5.20",
"gatsby-transformer-remark": "^1.7.32",
"gatsby-transformer-remark": "^1.7.33",
"gh-pages": "^1.1.0",
"global": "^4.3.2",
"highlight.js": "^9.12.0",
"lodash": "^4.17.5",
"marked": "^0.3.14",
"marked": "^0.3.15",
"prop-types": "^15.6.0",
"react": "^15.6.1",
"react-document-title": "^2.0.3",
Expand Down
3 changes: 3 additions & 0 deletions docs/src/components/Homepage/MainLinks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class MainLinks extends React.Component {
<li>
<Link to="/basics/writing-stories/">Writing stories</Link>
</li>
<li>
<Link to="/basics/live-examples/">Live Examples</Link>
</li>
</ul>
</div>

Expand Down
Loading

0 comments on commit 4eeb9cd

Please sign in to comment.