-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3244 from sixmen/app-mithril-3.4.0-rc.3
App for Mithril
- Loading branch information
Showing
89 changed files
with
2,446 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |+| |+|+|+|+| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/mithril'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/mithril'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/mithril'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
docs | ||
.babelrc |
Oops, something went wrong.