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 marko support to storybooksJS #3504

Merged
merged 36 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
51d725a
marko branch that works...
Apr 7, 2018
6e6bc01
a marko template actually loadsgit add -A
Apr 12, 2018
8c5549e
add components in marko-cli
Apr 16, 2018
3807654
make knobs+actions work
Apr 28, 2018
bb20d63
Resolved merge conflict
Apr 28, 2018
d44022f
fix app/marko to point to 4.0.0-alpha.4, remove stuff thats not neede…
Apr 30, 2018
7a09fd3
remove unused references in files
Apr 30, 2018
26d71a0
fix lint errors for marko app
Apr 30, 2018
d09c83f
add postcss-loader options in js, some refactoring of stories
May 1, 2018
d99b440
review comments, use new showError framework
May 1, 2018
7a34592
Merge branch 'master' of github.com:storybooks/storybook into addmark…
May 1, 2018
621c62f
fix error message for marko component error
May 1, 2018
35b5e9b
Merge branch 'master' into addmarkosupport
nm123github May 1, 2018
727e14d
add info in ADDONS_SUPPORT.md
May 1, 2018
c85a9d7
Merge branch 'addmarkosupport' of github.com:nm123github/storybook in…
May 1, 2018
b0dd82c
update yarn
May 1, 2018
4e7018d
update app/marko version.
May 1, 2018
de43701
Fix the import of external md files for marko
May 2, 2018
04bdf98
Merge branch 'master' of github.com:storybooks/storybook into addmark…
May 2, 2018
2f4a45d
update logo and gif for marko app
May 2, 2018
732c6d4
Fix render order in preview for marko
May 2, 2018
d2859d2
Configure netlify
Hypnosphi May 5, 2018
067caf8
Configure hierarchy separator
Hypnosphi May 5, 2018
f00a369
Add CLI template
Hypnosphi May 5, 2018
46de88c
CLI: remove unused stuff
Hypnosphi May 5, 2018
1acf55f
register options addon
Hypnosphi May 5, 2018
d92851f
Add slow start guide
Hypnosphi May 5, 2018
cb6f795
Add live examples
Hypnosphi May 5, 2018
24bdcfc
remove No Preview story
May 5, 2018
ddb7bed
some refactoring and review comments..
May 6, 2018
e9df6b6
add storysource addon
May 6, 2018
d8e0673
Merge branch 'master' of github.com:storybooks/storybook into addmark…
May 7, 2018
554f4f1
Merge branch 'master' of github.com:storybooks/storybook into addmark…
May 7, 2018
d752981
Merge remote-tracking branch 'origin/master' into addmarkosupport
Hypnosphi May 7, 2018
55750a1
Merge branch 'addmarkosupport' of github.com:nm123github/storybook in…
May 7, 2018
d25429a
Re-generate lockfile
Hypnosphi May 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions ADDONS_SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
## Addon / Framework Support Table

| |[React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)|
| |[React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)| [Marko](app/marko)|
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|
|[a11y](addons/a11y) |+| | | | | |
|[actions](addons/actions) |+|+|+|+|+|+|
|[background](addons/background) |+| | | | |+|
|[centered](addons/centered) |+| |+| | |+|
|[events](addons/events) |+| | | | | |
|[graphql](addons/graphql) |+| | | | | |
|[info](addons/info) |+| | | | | |
|[jest](addons/jest) |+| | | | | |
|[knobs](addons/knobs) |+|+|+|+|+|+|
|[links](addons/links) |+|+|+|+|+|+|
|[notes](addons/notes) |+| |+|+|+|+|
|[options](addons/options) |+|+|+|+|+|+|
|[storyshots](addons/storyshots) |+|+|+|+| | |
|[storysource](addons/storysource)|+| |+|+|+|+|
|[viewport](addons/viewport) |+| |+|+|+|+|
|[a11y](addons/a11y) |+| | | | | | |
|[actions](addons/actions) |+|+|+|+|+|+|+|
|[background](addons/background) |+| | | | |+| |
|[centered](addons/centered) |+| |+| | |+| |
|[events](addons/events) |+| | | | | | |
|[graphql](addons/graphql) |+| | | | | | |
|[info](addons/info) |+| | | | | | |
|[jest](addons/jest) |+| | | | | | |
|[knobs](addons/knobs) |+|+|+|+|+|+|+|
|[links](addons/links) |+|+|+|+|+|+| |
|[notes](addons/notes) |+| |+|+|+|+| |
|[options](addons/options) |+|+|+|+|+|+|+|
|[storyshots](addons/storyshots) |+|+|+|+| | | |
|[storysource](addons/storysource)|+| |+|+|+|+| |
|[viewport](addons/viewport) |+| |+|+|+|+| |
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ For additional help, join us [in our Slack](https://now-examples-slackin-rrirkqo
- [Angular](app/angular)
- [Polymer](app/polymer) <sup>release candidate</sup>
- [Mithril](app/mithril) <sup>alpha</sup>
- [Marko](app/marko) <sup>alpha</sup>

### Sub Projects

Expand Down Expand Up @@ -110,6 +111,7 @@ See [Addon / Framework Support Table](ADDONS_SUPPORT.md)
- [Angular](https://storybooks-angular.netlify.com/)
- [Polymer](https://storybooks-polymer.netlify.com/)
- [Mithril](https://storybooks-mithril.netlify.com/)
- [Marko](https://storybooks-marko.netlify.com/)

### 3.4
- [React Official](https://release-3-4--storybooks-official.netlify.com)
Expand Down
1 change: 1 addition & 0 deletions addons/knobs/marko.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/marko');
70 changes: 70 additions & 0 deletions addons/knobs/src/marko/WrapStory.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class {

onCreate(input) {
this.props = input.props;
this.knobChanged = this.knobChanged.bind(this);
this.knobClicked = this.knobClicked.bind(this);
this.resetKnobs = this.resetKnobs.bind(this);
this.setPaneKnobs = this.setPaneKnobs.bind(this);
}

onMount() {
// Watch for changes in knob editor.
this.props.channel.on('addon:knobs:knobChange', this.knobChanged);
// Watch for clicks in knob editor.
this.props.channel.on('addon:knobs:knobClick', this.knobClicked);
// Watch for the reset event and reset knobs.
this.props.channel.on('addon:knobs:reset', this.resetKnobs);
// Watch for any change in the knobStore and set the panel again for those changes.
this.props.knobStore.subscribe(this.setPaneKnobs);
// Set knobs in the panel for the first time.
this.setPaneKnobs();
}

onDestroy() {
this.props.channel.removeListener('addon:knobs:knobChange', this.knobChanged);
this.props.channel.removeListener('addon:knobs:knobClick', this.knobClicked);
this.props.channel.removeListener('addon:knobs:reset', this.resetKnobs);
this.props.knobStore.unsubscribe(this.setPaneKnobs);
}

setPaneKnobs(timestamp = +new Date()) {
const { channel, knobStore } = this.props;
channel.emit('addon:knobs:setKnobs', { knobs: knobStore.getAll(), timestamp });
}

knobChanged(change) {
const { name, value } = change;
const { knobStore, storyFn, context } = this.props;

// Update the related knob and it's value.
var knobOptions = knobStore.get(name);
knobOptions.value = value;
knobStore.markAllUnused();

this.renderElement(storyFn(context));
}

knobClicked(clicked) {
let knobOptions = this.props.knobStore.get(clicked.name);
knobOptions.callback();
}

resetKnobs() {
const { knobStore, storyFn, context } = this.props;
knobStore.reset();
this.renderElement(storyFn(context));
this.setPaneKnobs(false);
}

renderElement(storyContent) {
var WrapperElm = document.getElementById('Wrapper');
if(this.currLoadedComponent) {
this.currLoadedComponent.destroy();
this.currLoadedComponent = null;
}
this.currLoadedComponent = storyContent.appendTo(WrapperElm).getComponent();
}
}

<div id="Wrapper"></div>
43 changes: 43 additions & 0 deletions addons/knobs/src/marko/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import addons from '@storybook/addons';
import WrapStory from './WrapStory.marko';

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

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

export const markoHandler = (channel, knobStore) => getStory => context => {
const initialContent = getStory(context);
const props = { context, storyFn: getStory, channel, knobStore, initialContent };

return WrapStory.renderSync({ props });
};

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

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

return markoHandler(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 app/marko/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docs
.babelrc
41 changes: 41 additions & 0 deletions app/marko/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Storybook for Marko

[![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-rrirkqohko.now.sh/badge.svg)](https://now-examples-slackin-rrirkqohko.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 for Marko is a UI development environment for your Marko components.
With it, you can visualize different states of your UI components and develop them interactively.

![Storybook Screenshot](docs/demo.gif)

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

## Getting Started

```sh
npm i -g @storybook/cli
cd my-marko-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.

Here are some featured storybooks that you can reference to see how Storybook works:

## Docs

- [Basics](https://storybook.js.org/basics/introduction)
- [Configurations](https://storybook.js.org/configurations/default-config)
- [Addons](https://storybook.js.org/addons/introduction)
3 changes: 3 additions & 0 deletions app/marko/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/marko/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../dist/server');
Binary file added app/marko/docs/demo.gif
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/marko/docs/marko_storybook_screenshot.png
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/marko/docs/storybooks_io_logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions app/marko/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@storybook/marko",
"version": "4.0.0-alpha.4",
"description": "Storybook for Marko: Develop Marko Component in isolation with Hot Reloading.",
"homepage": "https://github.com/storybooks/storybook/tree/master/app/marko",
"bugs": {
"url": "https://github.com/storybooks/storybook/issues"
},
"license": "MIT",
"main": "dist/client/index.js",
"jsnext:main": "src/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": {
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addons": "4.0.0-alpha.4",
"@storybook/channel-postmessage": "4.0.0-alpha.4",
"@storybook/client-logger": "4.0.0-alpha.4",
"@storybook/core": "4.0.0-alpha.4",
"@storybook/node-logger": "4.0.0-alpha.4",
"@storybook/ui": "4.0.0-alpha.4",
"airbnb-js-shims": "^1.4.1",
"babel-loader": "^7.1.4",
"babel-plugin-macros": "^2.2.0",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.3.0",
"babel-preset-stage-0": "^6.24.1",
"babel-runtime": "^6.26.0",
"case-sensitive-paths-webpack-plugin": "^2.1.2",
"common-tags": "^1.7.2",
"core-js": "^2.5.4",
"dotenv-webpack": "^1.5.5",
"glamor": "^2.20.40",
"glamorous": "^4.12.1",
"global": "^4.3.2",
"html-webpack-plugin": "^3.2.0",
"raw-loader": "^0.5.1",
"lodash.flattendeep": "^4.4.0",
"prop-types": "^15.6.1",
"webpack": "^4.5.0",
"webpack-hot-middleware": "^2.21.2"
},
"peerDependencies": {
"babel-core": "^6.26.0 || ^7.0.0-0",
"babel-runtime": ">=6.0.0"
}
}
9 changes: 9 additions & 0 deletions app/marko/src/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export {
storiesOf,
setAddon,
addDecorator,
addParameters,
configure,
getStorybook,
forceReRender,
} from './preview';
17 changes: 17 additions & 0 deletions app/marko/src/client/preview/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { start } from '@storybook/core/client';

import render from './render';

const { clientApi, configApi, forceReRender } = start(render);

export const {
storiesOf,
setAddon,
addDecorator,
addParameters,
clearDecorators,
getStorybook,
} = clientApi;

export const { configure } = configApi;
export { forceReRender };
28 changes: 28 additions & 0 deletions app/marko/src/client/preview/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { document } from 'global';
import { stripIndents } from 'common-tags';

const rootEl = document.getElementById('root');
let currLoadedComponent = null; // currently loaded marko widget!

export default function renderMain({ story, selectedKind, selectedStory, showMain, showError }) {
const element = story();

// We need to unmount the existing set of components in the DOM node.
if (currLoadedComponent) {
currLoadedComponent.destroy();
}

if (!element || !element.out) {
showError({
title: `Expecting a Marko element from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Did you forget to return the Marko element from the story?
Use "() => MyComp.renderSync({})" or "() => { return MyComp.renderSync({}); }" when defining the story.
`,
});
return;
}

showMain();
currLoadedComponent = element.appendTo(rootEl).getComponent();
}
12 changes: 12 additions & 0 deletions app/marko/src/demo/Button.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class {
onCreate(input) {
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this empty method needed?


handleStartClick() {
alert('hi')
}
}

<div>
<button type="button" on-click("handleStartClick")>Hello!</button>
</div>
32 changes: 32 additions & 0 deletions app/marko/src/demo/Welcome.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}

h1, h2 {
font-weight: normal;
}

ul {
list-style-type: none;
padding: 0;
}

li {
display: inline-block;
margin: 0 10px;
}

a {
color: #42b983;
}
</style>

<div id="app">
<h1>Welcome to Storybook for Marko</h1>
</div>
12 changes: 12 additions & 0 deletions app/marko/src/server/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { buildStatic } from '@storybook/core/server';
import path from 'path';
import packageJson from '../../package.json';
import getBaseConfig from './config/webpack.config.prod';
import loadConfig from './config';

buildStatic({
packageJson,
getBaseConfig,
loadConfig,
defaultFavIcon: path.resolve(__dirname, 'public/favicon.ico'),
});