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

App for Mithril #3244

Merged
merged 31 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0c1c2dd
create app/mithril by copying app/react
sixmen Mar 20, 2018
aa2eb52
implement Mithril app
sixmen Mar 20, 2018
33edc20
add Mithril support to addon-knobs
sixmen Mar 20, 2018
3e050ac
add Mithril support to addon-background
sixmen Mar 20, 2018
5c9a26c
add Mithril support in CLI
sixmen Mar 20, 2018
ff8a14a
add Mithril support to addon-centered
sixmen Mar 20, 2018
3948142
add Mithril kitchen sink
sixmen Mar 20, 2018
424c01f
fix test
sixmen Mar 20, 2018
6b9a073
remove demo components from Mithril app
sixmen Mar 21, 2018
9e50f6e
remove unused code
sixmen Mar 21, 2018
cf0c198
Add documentation for Mithril app & addons
sixmen Mar 21, 2018
5a1627d
build Mithril kitchen-sink in CircleCI
sixmen Mar 21, 2018
b32418f
add Mithril demo components for CLI
sixmen Mar 21, 2018
df62729
fix build mithril-kitchen-sink
sixmen Mar 21, 2018
d5eaf71
Add guide documents for Mithril
sixmen Mar 21, 2018
682c899
Add netlify build for Mithril
sixmen Mar 21, 2018
56ea9d9
Merge branch 'master' into app-mithril-3.4.0-rc.3
igor-dv Mar 21, 2018
538a2bf
mark Mithril app as alpha
sixmen Mar 22, 2018
78ec915
Remove addon dependency from demo component
sixmen Mar 22, 2018
576b3bc
Merge branch 'master' into app-mithril-3.4.0-rc.3
ndelangen Mar 26, 2018
f8818e4
Merge branch 'master' into app-mithril-3.4.0-rc.3
danielduan Mar 26, 2018
2c658b8
update Mithril app for Webpack 4
sixmen Mar 27, 2018
56d2320
Apply startup code change to the Mithril app
sixmen Mar 27, 2018
414b84c
update Mithril kitchen sink for Webpack 4
sixmen Mar 27, 2018
d839afd
update yarn.lock
sixmen Mar 27, 2018
a0773c7
Merge branch 'master' into app-mithril-3.4.0-rc.3
Hypnosphi Mar 27, 2018
fab5d35
Merge remote-tracking branch 'origin/master' into app-mithril-3.4.0-rc.3
Hypnosphi Mar 27, 2018
4eeda3d
Update common deps
Hypnosphi Mar 27, 2018
ff22716
Add mithril acceptance story
Hypnosphi Mar 28, 2018
26222a7
Update live examples
Hypnosphi Mar 28, 2018
36379bb
Update storyshot
Hypnosphi Mar 28, 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
1 change: 1 addition & 0 deletions addons/background/mithril.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/mithril');
39 changes: 39 additions & 0 deletions addons/background/src/mithril.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @jsx m */

// eslint-disable-next-line import/no-extraneous-dependencies
import m from 'mithril';

import addons from '@storybook/addons';

export class BackgroundDecorator {
constructor(vnode) {
this.props = vnode.attrs;

const { channel, story } = vnode.attrs;

// A channel is explicitly passed in for testing
if (channel) {
this.channel = channel;
} else {
this.channel = addons.getChannel();
}

this.story = story();
}

oncreate() {
this.channel.emit('background-set', this.props.backgrounds);
}

onremove() {
this.channel.emit('background-unset');
}

view() {
return m(this.story);
}
}

export default backgrounds => story => ({
view: () => <BackgroundDecorator story={story} backgrounds={backgrounds} />,
});
1 change: 1 addition & 0 deletions addons/centered/mithril.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/mithril');
30 changes: 30 additions & 0 deletions addons/centered/src/mithril.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @jsx m */

// eslint-disable-next-line import/no-extraneous-dependencies
import m from 'mithril';

const style = {
position: 'fixed',
top: 0,
left: 0,
bottom: 0,
right: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
overflow: 'auto',
};

const innerStyle = {
margin: 'auto',
};

export default function(storyFn) {
return {
view: () => (
<div style={style}>
<div style={innerStyle}>{m(storyFn())}</div>
</div>
),
};
}
1 change: 1 addition & 0 deletions addons/knobs/mithril.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/mithril');
68 changes: 68 additions & 0 deletions addons/knobs/src/mithril/WrapStory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import m from 'mithril';

export default class WrapStory {
constructor(vnode) {
this.knobChanged = this.knobChanged.bind(this);
this.knobClicked = this.knobClicked.bind(this);
this.resetKnobs = this.resetKnobs.bind(this);
this.setPaneKnobs = this.setPaneKnobs.bind(this);
this.props = vnode.attrs;
this.storyContent = vnode.attrs.initialContent;
}

oncreate() {
// 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();
}

onremove() {
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.
const knobOptions = knobStore.get(name);

knobOptions.value = value;
knobStore.markAllUnused();
this.storyContent = storyFn(context);
m.redraw();
}

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

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

view() {
return m(this.storyContent);
}
}
49 changes: 49 additions & 0 deletions addons/knobs/src/mithril/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/** @jsx m */

// eslint-disable-next-line import/no-extraneous-dependencies
import m from 'mithril';
import addons from '@storybook/addons';

import WrapStory from './WrapStory';

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 mithrilHandler = (channel, knobStore) => getStory => context => {
const initialContent = getStory(context);
const props = { context, storyFn: getStory, channel, knobStore, initialContent };
return {
view: () => <WrapStory {...props} />,
};
};

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

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

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

[![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 Mithril is a UI development environment for your Mithril 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-mithril-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.
3 changes: 3 additions & 0 deletions app/mithril/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/mithril/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/mithril/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').default,
Button: require('./dist/demo/Button').default,
};
Binary file added app/mithril/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/mithril/docs/react_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/mithril/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.
70 changes: 70 additions & 0 deletions app/mithril/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "@storybook/mithril",
"version": "3.4.0-rc.3",
"description": "Storybook for Mithril: Develop Mithril Component in isolation.",
"homepage": "https://github.com/storybooks/storybook/tree/master/app/mithril",
"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": {
"dev": "cross-env DEV_BUILD=1 nodemon --watch ./src --exec \"yarn prepare\"",
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addon-links": "3.4.0-rc.3",
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need to be dependant on specific addons. Every addon example should be in a dedicated example-app.

"@storybook/addons": "3.4.0-rc.3",
"@storybook/channel-postmessage": "3.4.0-rc.3",
"@storybook/client-logger": "3.4.0-rc.3",
"@storybook/core": "3.4.0-rc.3",
"@storybook/node-logger": "3.4.0-rc.3",
"@storybook/ui": "3.4.0-rc.3",
"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.3",
"dotenv-webpack": "^1.5.5",
"find-cache-dir": "^1.0.0",
"global": "^4.3.2",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^2.30.1",
"json5": "^0.5.1",
"markdown-loader": "^2.0.2",
"react": "^16.2.0",
"react-dev-utils": "^5.0.0",
"react-dom": "^16.2.0",
"redux": "^3.7.2",
"uglifyjs-webpack-plugin": "^1.2.4",
"util-deprecate": "^1.0.2",
"webpack": "^3.11.0",
"webpack-hot-middleware": "^2.21.2"
},
"devDependencies": {
"mithril": "^1.1.6",
"nodemon": "^1.17.2"
},
"peerDependencies": {
"babel-core": "^6.26.0 || ^7.0.0-0",
"babel-runtime": ">=6.0.0",
"mithril": "^1.1.6"
}
}
8 changes: 8 additions & 0 deletions app/mithril/src/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export {
storiesOf,
setAddon,
addDecorator,
configure,
getStorybook,
forceReRender,
} from './preview';
45 changes: 45 additions & 0 deletions app/mithril/src/client/preview/error_display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/** @jsx m */

import m from 'mithril';

const mainStyle = {
position: 'fixed',
top: 0,
bottom: 0,
left: 0,
right: 0,
padding: 20,
backgroundColor: 'rgb(187, 49, 49)',
color: '#FFF',
WebkitFontSmoothing: 'antialiased',
};

const headingStyle = {
fontSize: 20,
fontWeight: 600,
letterSpacing: 0.2,
margin: '10px 0',
fontFamily: `
-apple-system, ".SFNSText-Regular", "San Francisco", Roboto, "Segoe UI",
"Helvetica Neue", "Lucida Grande", sans-serif
`,
};

const codeStyle = {
fontSize: 14,
width: '100vw',
overflow: 'auto',
};

const ErrorDisplay = {
view: vnode => (
<div style={mainStyle}>
<div style={headingStyle}>{vnode.attrs.error.message}</div>
<pre style={codeStyle}>
<code>{vnode.attrs.error.stack}</code>
</pre>
</div>
),
};

export default ErrorDisplay;