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 angular support: Storybook for Angular #1474

Merged
merged 80 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
99435cf
Angular (2+) support (#269)
alterx Jul 14, 2017
63a6e3f
Removing @storybook/angular dep as it doesn't exist
alterx Jul 14, 2017
b9a9557
Update example deps
shilman Jul 14, 2017
efc2c2f
Updating README
alterx Jul 14, 2017
3f0cbc9
SYNC dependencies
ndelangen Jul 20, 2017
7ba1e4d
Clarifying strategy used to render dynamic components in angular
alterx Jul 20, 2017
7ae3f1d
Fixing issues with duplicate types introduced by recent changes
alterx Jul 20, 2017
ca35200
Testing add-ons
alterx Jul 20, 2017
edbba98
Update README.md
ndelangen Jul 23, 2017
a8e8ed4
Enabling support for components with separate templates/css
alterx Jul 25, 2017
5c7a851
Update `getstorybook` CLI
alterx Jul 28, 2017
0633526
Adding clearer examples for Notes and Actions add-ons
alterx Jul 31, 2017
aec73db
Removing unneded deps and updating deps versions
alterx Aug 1, 2017
a01752e
Adding angular to the cli generator
alterx Aug 1, 2017
ede5c0e
Laying the foundation to fix the `knobs` add-on for angular
alterx Aug 1, 2017
fe1abbc
Adding else clausle for stories not sent by the `knobs` add-on
alterx Aug 1, 2017
c05e530
Updating angular version to latest beta and fixing errors regarding `…
alterx Aug 11, 2017
b3e8d0a
Removing ts lint errors for jasmine
alterx Aug 11, 2017
8f0f80c
FIX lerna.json
ndelangen Aug 18, 2017
a7740b9
REVERT changes on cra-kitchen-sink stories/index
ndelangen Aug 18, 2017
7c93bf6
Merge branch 'release/3.3' into 269-angular-support
ndelangen Aug 24, 2017
e56ad15
FIX
ndelangen Aug 24, 2017
5113ad4
Merge branch 'release/3.3' into 269-angular-support
ndelangen Aug 25, 2017
f9114ad
Experimenting with knobs addon.
alterx Aug 30, 2017
1f16881
Cleaning up angular app on each story load
alterx Aug 31, 2017
1a8dbdd
Merge branch 'release/3.3' into 269-angular-support
ndelangen Sep 6, 2017
45fa5c1
Knobs addon and Angular app refactor
alterx Sep 6, 2017
de73aac
Merge branch '269-angular-support' of github.com:storybooks/storybook…
alterx Sep 6, 2017
8b01192
Updating package.json versions to match other apps
alterx Sep 6, 2017
eb9fe3c
Merge branch 'release/3.3' into 269-angular-support
ndelangen Sep 9, 2017
ab30934
trying to fix after yarn workspaces change
ndelangen Sep 9, 2017
ff7f049
Merge branch 'release/3.3' into 269-angular-support
ndelangen Sep 9, 2017
4874d44
ADD storybook bins for angular
ndelangen Sep 9, 2017
2efdf04
Merge branch 'release/3.3' into 269-angular-support
ndelangen Sep 12, 2017
a867018
SYNC versions && FIX
ndelangen Sep 12, 2017
cad98bb
Merge branch '269-angular-support' of github.com:storybooks/storybook…
alterx Sep 12, 2017
e596022
Adding changes removed by last commit
alterx Sep 12, 2017
c56b98c
Update README.md
ndelangen Sep 12, 2017
a6bf185
REMOVE angular knobs from old-style import
ndelangen Sep 12, 2017
fea7587
UPDATE angular readme
ndelangen Sep 12, 2017
ac84319
CLEANUP angular default addons.js
ndelangen Sep 12, 2017
8727989
CLEANUP angular client/index.js
ndelangen Sep 12, 2017
6695d95
CLEANUP && FIX unit test
ndelangen Sep 12, 2017
31d24dc
Allowing custom elements inside an angular component
alterx Sep 12, 2017
aa1e6b1
CHANGE webpack setup to be aligned with other apps
ndelangen Sep 12, 2017
82f4ce0
Merge branch '269-angular-support' of github.com:storybooks/storybook…
ndelangen Sep 12, 2017
ca710db
Update index.md
ndelangen Sep 12, 2017
b05d6d8
Fixing the styles example
alterx Sep 12, 2017
3616ac3
Fixing bug in which HRM reload would cause a duplicate component henc…
alterx Sep 12, 2017
fdc260c
Merge branch '269-angular-support' of github.com:storybooks/storybook…
alterx Sep 12, 2017
8e041e9
ADD build-test and smoke-test for angular example
ndelangen Sep 12, 2017
72f75e3
FIX build-storybook for angular
ndelangen Sep 13, 2017
56bd3f7
Merge branch 'release/3.3' into 269-angular-support
ndelangen Sep 13, 2017
f0d4984
Update index.md
ndelangen Sep 13, 2017
4ec19da
FIX smoke tests for angular
ndelangen Sep 13, 2017
274c6da
FIX angular detection for CLI
ndelangen Sep 13, 2017
f652ca1
ADD test for angular CLI
ndelangen Sep 13, 2017
8137d67
Debouncing render calls
alterx Sep 14, 2017
c52330b
Unused onClick handler in button example
alterx Sep 14, 2017
3d8eb0f
Updating to latest Angular 5 beta
alterx Sep 14, 2017
0ae971f
Actually, button component is used several times, adding onClick palc…
alterx Sep 14, 2017
dc140b0
Merge remote-tracking branch 'upstream/release/3.3' into 269-angular-…
Hypnosphi Sep 15, 2017
087bb19
Update CLI snapshot
Hypnosphi Sep 15, 2017
10e5304
Skip smoke tests for angular-cli
Hypnosphi Sep 15, 2017
a380fc0
Merge branch 'release/3.3' into 269-angular-support
Hypnosphi Sep 15, 2017
8fd1a24
Turn smoke tests back on for angular-cli fixture
Hypnosphi Sep 15, 2017
a8d2021
Merge branch 'release/3.3' into 269-angular-support
ndelangen Sep 22, 2017
217ec79
Merge branch 'release/3.3' of github.com:storybooks/storybook into 26…
alterx Oct 6, 2017
a8e81c2
Updating yarn.lock file
alterx Oct 6, 2017
8cb2599
Fixing protractor and typescript issues with cli tests
alterx Oct 14, 2017
64b7d3d
Bumping @storybook/* versions
alterx Oct 14, 2017
a554bc9
Updating template and snapshot version
alterx Oct 14, 2017
9becf40
Mocking @storybook/angular version for the time being
alterx Oct 14, 2017
854ec24
Add @storybook/cli to list of cli internal deps
Hypnosphi Oct 14, 2017
d453498
Update CLI snapshot
Hypnosphi Oct 14, 2017
b95b58c
Updating react version to 16
alterx Oct 16, 2017
72ca746
Upgrade to react16
shilman Oct 16, 2017
a9d9130
Merge branch '269-angular-support' of github.com:storybooks/storybook…
alterx Oct 16, 2017
a927c43
Knobs addon: helpers shouldn't be a ts file
alterx Oct 16, 2017
5f3fa62
Removing unused typescript deps
alterx Oct 16, 2017
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
8 changes: 7 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ jobs:
cd examples/vue-kitchen-sink
yarn build-storybook
yarn storybook --smoke-test
- run:
name: "Build angular kitchen-sink"
command: |
cd examples/angular-cli
yarn build-storybook
yarn storybook --smoke-test
example-react-native:
<<: *defaults
steps:
Expand Down Expand Up @@ -219,4 +225,4 @@ workflows:
# requires:
# - lint
# - unit-test
# - docs
# - docs
7 changes: 7 additions & 0 deletions addons/knobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ stories.add('as dynamic variables', () => {
> import { storiesOf } from '@storybook/react-native';
> import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/react';
> ```
>
> In the case of Angular, use these imports:
>
> ```js
> import { storiesOf } from '@storybook/angular';
> import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/angular';
> ```

You can see your Knobs in a Storybook panel as shown below.

Expand Down
1 change: 1 addition & 0 deletions addons/knobs/angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/angular');
3 changes: 2 additions & 1 deletion addons/knobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"storybook": "start-storybook -p 9010"
},
"dependencies": {
"@angular/core": "^5.0.0-beta.7",
"@storybook/addons": "^3.3.0-alpha.2",
"babel-runtime": "^6.26.0",
"deep-equal": "^1.0.1",
Expand All @@ -35,7 +36,7 @@
"react": "^16.0.0",
"react-dom": "^16.0.0",
"style-loader": "^0.19.0",
"typescript": "^2.2.2",
"typescript": "^2.4.0",
"typescript-definition-tester": "^0.0.5",
"vue": "^2.4.2"
},
Expand Down
110 changes: 110 additions & 0 deletions addons/knobs/src/angular/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/* eslint no-underscore-dangle: 0 */

import { Component, SimpleChange, ChangeDetectorRef } from '@angular/core';

const getComponentMetadata = ({ component, props = {} }) => {
if (!component || typeof component !== 'function') throw new Error('No valid component provided');

const componentMeta = component.__annotations__[0] || component.annotations[0];
const propsMeta = component.__prop__metadata__ || component.propMetadata || {};
const paramsMetadata = component.__parameters__ || component.parameters || [];
return {
component,
props,
componentMeta,
propsMeta,
params: paramsMetadata,
};
};

const getAnnotatedComponent = ({ componentMeta, component, params, knobStore, channel }) => {
const NewComponent = function NewComponent(cd, ...args) {
component.call(this, ...args);
this.cd = cd;
this.knobChanged = this.knobChanged.bind(this);
this.setPaneKnobs = this.setPaneKnobs.bind(this);
};
NewComponent.prototype = Object.create(component.prototype);
NewComponent.__annotations__ = [new Component(componentMeta)];
NewComponent.__parameters__ = [[ChangeDetectorRef], ...params];

NewComponent.prototype.constructor = NewComponent;
NewComponent.prototype.ngOnInit = function onInit() {
if (component.prototype.ngOnInit) {
component.prototype.ngOnInit();
}

channel.on('addon:knobs:knobChange', this.knobChanged);
knobStore.subscribe(this.setPaneKnobs);
this.setPaneKnobs();
};

NewComponent.prototype.ngOnDestroy = function onDestroy() {
if (component.prototype.ngOnDestroy) {
component.prototype.ngOnDestroy();
}

channel.removeListener('addon:knobs:knobChange', this.knobChanged);
knobStore.unsubscribe(this.setPaneKnobs);
};

NewComponent.prototype.ngOnChanges = function onChanges(changes) {
if (component.prototype.ngOnChanges) {
component.prototype.ngOnChanges(changes);
}
};

NewComponent.prototype.setPaneKnobs = function setPaneKnobs(timestamp = +new Date()) {
channel.emit('addon:knobs:setKnobs', {
knobs: knobStore.getAll(),
timestamp,
});
};

NewComponent.prototype.knobChanged = function knobChanged(change) {
const { name, value } = change;
const knobOptions = knobStore.get(name);
const oldValue = knobOptions.value;
knobOptions.value = value;
knobStore.markAllUnused();
const lowercasedName = name.toLocaleLowerCase();
this[lowercasedName] = value;
this.cd.detectChanges();
this.ngOnChanges({
[lowercasedName]: new SimpleChange(oldValue, value, false),
});
};

return NewComponent;
};

const resetKnobs = (knobStore, channel) => {
knobStore.reset();
channel.emit('addon:knobs:setKnobs', {
knobs: knobStore.getAll(),
timestamp: false,
});
};

export function prepareComponent({ getStory, context, channel, knobStore }) {
resetKnobs(knobStore, channel);
const { component, componentMeta, props, propsMeta, params } = getComponentMetadata(
getStory(context)
);

if (!componentMeta) throw new Error('No component metadata available');

const AnnotatedComponent = getAnnotatedComponent({
componentMeta,
component,
params,
knobStore,
channel,
});

return {
component: AnnotatedComponent,
props,
propsMeta,
};
}
27 changes: 27 additions & 0 deletions addons/knobs/src/angular/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import addons from '@storybook/addons';

import { prepareComponent } from './helpers';

import { knob, text, boolean, number, color, object, array, date, select, manager } from '../base';

export { knob, text, boolean, number, color, object, array, date, select };

export const angularHandler = (channel, knobStore) => getStory => context =>
prepareComponent({ getStory, context, channel, knobStore });

function wrapperKnobs(options) {
const channel = addons.getChannel();
manager.setChannel(channel);

if (options) channel.emit('addon:knobs:setOptions', options);

return angularHandler(channel, manager.knobStore);
}

export function withKnobs(storyFn, context) {
return wrapperKnobs()(storyFn)(context);
}

export function withKnobsOptions(options = {}) {
return (storyFn, context) => wrapperKnobs(options)(storyFn)(context);
}
2 changes: 2 additions & 0 deletions addons/knobs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noImplicitAny": false,
"sourceMap": false,
"lib": [
Expand Down
3 changes: 3 additions & 0 deletions app/angular/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env", "stage-0", "react"]
}
3 changes: 3 additions & 0 deletions app/angular/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docs
src
.babelrc
34 changes: 34 additions & 0 deletions app/angular/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Storybook for Angular

Storybook for Angular is a UI development environment for your React components.
With it, you can visualize different states of your UI components and develop them interactively.

[![Greenkeeper badge](https://badges.greenkeeper.io/storybooks/storybook.svg)](https://greenkeeper.io/)
[![Build Status on CircleCI](https://circleci.com/gh/storybooks/storybook.svg?style=shield)](https://circleci.com/gh/storybooks/storybook)
[![CodeFactor](https://www.codefactor.io/repository/github/storybooks/storybook/badge)](https://www.codefactor.io/repository/github/storybooks/storybook)
[![Known Vulnerabilities](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847/badge.svg)](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847)
[![BCH compliance](https://bettercodehub.com/edge/badge/storybooks/storybook)](https://bettercodehub.com/results/storybooks/storybook) [![codecov](https://codecov.io/gh/storybooks/storybook/branch/master/graph/badge.svg)](https://codecov.io/gh/storybooks/storybook)
[![Storybook Slack](https://now-examples-slackin-nqnzoygycp.now.sh/badge.svg)](https://now-examples-slackin-nqnzoygycp.now.sh/)
[![Backers on Open Collective](https://opencollective.com/storybook/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/storybook/sponsors/badge.svg)](#sponsors)

* * *

Storybook runs outside of your app.
So you can develop UI components in isolation without worrying about app specific dependencies and requirements.

![Storybook Screenshot](https://github.com/storybooks/storybook/blob/master/app/react/docs/demo.gif)

## Getting Started

```sh
npm i -g @storybook/cli
cd my-angular-app
getstorybook
```

For more information visit: [storybook.js.org](https://storybook.js.org)

* * *

Storybook also comes with a lot of [addons](https://storybook.js.org/addons/introduction) and a great API to customize as you wish.
You can also build a [static version](https://storybook.js.org/basics/exporting-storybook) of your storybook and deploy it anywhere you want.
Empty file added app/angular/addons.js
Empty file.
3 changes: 3 additions & 0 deletions app/angular/bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../dist/server/build');
3 changes: 3 additions & 0 deletions app/angular/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../dist/server');
5 changes: 5 additions & 0 deletions app/angular/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable global-require */
module.exports = {
Welcome: require('./dist/demo/welcome.component.ts').default,
Button: require('./dist/demo/button.component.ts').default,
};
Binary file added app/angular/docs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/angular/docs/react_storybook_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/angular/docs/storybooks_io_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions app/angular/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"name": "@storybook/angular",
"version": "3.3.0-alpha.0",
"description": "Storybook for Anglar: Develop Angular Components in isolation with Hot Reloading.",
"homepage": "https://github.com/storybooks/storybook/tree/master/apps/angular",
"bugs": {
"url": "https://github.com/storybooks/storybook/issues"
},
"license": "MIT",
"main": "dist/client/index.js",
"bin": {
"build-storybook": "./bin/build.js",
"start-storybook": "./bin/index.js",
"storybook-server": "./bin/index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/storybooks/storybook.git"
},
"scripts": {
"dev": "DEV_BUILD=1 nodemon -e js,ts --watch ./src --exec 'npm run prepublish'",
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@angular/common": "^5.0.0-beta.7",
"@angular/compiler": "^5.0.0-beta.7",
"@angular/core": "^5.0.0-beta.7",
"@angular/platform-browser": "^5.0.0-beta.7",
"@angular/platform-browser-dynamic": "^5.0.0-beta.7",
"@storybook/addon-actions": "^3.3.0-alpha.2",
"@storybook/addon-links": "^3.3.0-alpha.2",
"@storybook/addons": "^3.3.0-alpha.2",
"@storybook/channel-postmessage": "^3.3.0-alpha.2",
"@storybook/ui": "^3.3.0-alpha.2",
"airbnb-js-shims": "^1.1.1",
"angular2-template-loader": "^0.6.2",
"autoprefixer": "^7.1.1",
"babel-core": "^6.26.0",
"babel-loader": "^7.0.0",
"babel-plugin-react-docgen": "^1.6.0",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"babel-preset-react-app": "^3.0.0",
"babel-preset-stage-0": "^6.24.1",
"babel-runtime": "^6.23.0",
"case-sensitive-paths-webpack-plugin": "^2.0.0",
"chalk": "^2.1.0",
"commander": "^2.11.0",
"common-tags": "^1.4.0",
"configstore": "^3.1.0",
"core-js": "^2.4.1",
"css-loader": "^0.28.1",
"express": "^4.15.3",
"file-loader": "^0.11.1",
"find-cache-dir": "^1.0.0",
"global": "^4.3.2",
"html-webpack-plugin": "^2.30.1",
"json-loader": "^0.5.4",
"json-stringify-safe": "^5.0.1",
"json5": "^0.5.1",
"lodash.pick": "^4.4.0",
"postcss-flexbugs-fixes": "^3.0.0",
"postcss-loader": "^2.0.5",
"prop-types": "^15.5.10",
"qs": "^6.4.0",
"raw-loader": "^0.5.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-modal": "^2.2.4",
"redux": "^3.6.0",
"request": "^2.81.0",
"rxjs": "^5.4.2",
"serve-favicon": "^2.4.3",
"shelljs": "^0.7.8",
"style-loader": "^0.17.0",
"ts-loader": "^2.2.2",
"url-loader": "^0.5.8",
"util-deprecate": "^1.0.2",
"uuid": "^3.1.0",
"webpack": "^2.5.1 || ^3.0.0",
"webpack-dev-middleware": "^1.10.2",
"webpack-hot-middleware": "^2.18.0",
"zone.js": "^0.8.14"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-decorators": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"codelyzer": "^3.1.2",
"mock-fs": "^4.3.0",
"nodemon": "^1.12.0",
"typescript": "^2.4.0"
}
}
7 changes: 7 additions & 0 deletions app/angular/src/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as previewApi from './preview';

export const storiesOf = previewApi.storiesOf;
export const setAddon = previewApi.setAddon;
export const addDecorator = previewApi.addDecorator;
export const configure = previewApi.configure;
export const getStorybook = previewApi.getStorybook;
6 changes: 6 additions & 0 deletions app/angular/src/client/manager/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { document } from 'global';
import renderStorybookUI from '@storybook/ui';
import Provider from './provider';

const rootEl = document.getElementById('root');
renderStorybookUI(rootEl, new Provider());
Loading