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 all 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- node_modules
- examples/angular-cli/node_modules
- examples/cra-kitchen-sink/node_modules
- examples/mithril-kitchen-sink/node_modules
- examples/official-storybook/node_modules
- examples/polymer-cli/node_modules
- examples/vue-kitchen-sink/node_modules
Expand Down Expand Up @@ -100,6 +101,11 @@ jobs:
command: |
cd examples/official-storybook
yarn build-storybook
- run:
name: "Build mithril kitchen-sink"
command: |
cd examples/mithril-kitchen-sink
yarn build-storybook
- run:
name: "Visually test storybook"
command: |
Expand Down Expand Up @@ -148,6 +154,11 @@ jobs:
command: |
cd examples/official-storybook
yarn storybook --smoke-test
- run:
name: "Run mithril kitchen-sink (smoke test)"
command: |
cd examples/mithril-kitchen-sink
yarn storybook --smoke-test
react-native:
<<: *defaults
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/autolabeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'app: react-native': ["app/react-native/**"]
'app: react': ["app/react/**"]
'app: vue': ["app/vue/**"]
'app: mithril': ["app/mithril/**"]
'babel / webpack': ["webpack", "babel"]
'cli': ["lib/cli/**"]
'compatibility with other tools': []
Expand Down
34 changes: 17 additions & 17 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)|
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|
|[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) |+| |+|+|+|
| |[React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)|
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|
|[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 @@ -72,6 +72,7 @@ For additional help, join us [in our Slack](https://now-examples-slackin-rrirkqo
- [Vue](app/vue)
- [Angular](app/angular)
- [Polymer](app/polymer) <sup>alpha</sup>
- [Mithril](app/mithril) <sup>alpha</sup>

### Sub Projects

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

### 3.4
- [React Official](https://release-3-4--storybooks-official.netlify.com)
Expand Down
7 changes: 7 additions & 0 deletions addons/background/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ storiesOf("Button", module)
.addDecorator(backgrounds)
.add("with text", () => <button>Click me</button>);
```

> In the case of Mithril, use these imports:
>
> ```js
> import { storiesOf } from '@storybook/mithril';
> import backgrounds from "@storybook/addon-backgrounds/mithril";
> ```
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} />,
});
35 changes: 33 additions & 2 deletions addons/centered/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,29 @@ storiesOf('MyComponent', module)
.add('without props', () => ({
components: { MyComponent },
template: '<my-component />'
})
}))
.add('with some props', () => ({
components: { MyComponent },
template: '<my-component text="The Comp"/>'
});
}));
```

example for Mithril:

```js
import { storiesOf } from '@storybook/mithril';
import centered from '@storybook/addon-centered/mithril';

import MyComponent from '../Component';

storiesOf('MyComponent', module)
.addDecorator(centered)
.add('without props', () => ({
view: () => <MyComponent />
}))
.add('with some props', () => ({
view: () => <MyComponent text="The Comp"/>
}));
```

Also, you can also add this decorator globally
Expand Down Expand Up @@ -84,6 +102,19 @@ configure(function () {
}, module);
```

example for Mithril:

```js
import { configure, addDecorator } from '@storybook/mithril';
import centered from '@storybook/addon-centered/mithril';

addDecorator(centered);

configure(function () {
//...
}, module);
```

#### As an extension

##### 1 - Configure the extension
Expand Down
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>
),
};
}
7 changes: 7 additions & 0 deletions addons/knobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ stories.add('as dynamic variables', () => {
> import { storiesOf } from '@storybook/angular';
> import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/angular';
> ```
>
> In the case of Mithril, use these imports:
>
> ```js
> import { storiesOf } from '@storybook/mithril';
> import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/mithril';
> ```

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

Expand Down
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
Loading