-
-
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 #1267 from storybooks/add-app-vue
WIP - add vue support
- Loading branch information
Showing
107 changed files
with
3,791 additions
and
209 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ node_modules | |
app/**/demo/** | ||
docs/public | ||
|
||
vue | ||
|
||
*.bundle.js | ||
*.js.map | ||
|
||
|
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
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
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
File renamed without changes.
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,11 @@ | ||
import React from 'react'; | ||
import WrapStory from './WrapStory'; | ||
|
||
/** | ||
* Handles a react story | ||
*/ | ||
export const reactHandler = (channel, knobStore) => getStory => context => { | ||
const initialContent = getStory(context); | ||
const props = { context, storyFn: getStory, channel, knobStore, initialContent }; | ||
return <WrapStory {...props} />; | ||
}; |
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,27 @@ | ||
import React from 'react'; | ||
import { reactHandler } from './index'; | ||
import { shallow } from 'enzyme'; // eslint-disable-line | ||
import KnobStore from '../KnobStore'; | ||
|
||
describe('React Handler', () => { | ||
describe('wrapStory', () => { | ||
it('should contain the story and add correct props', () => { | ||
const testChannel = { emit: () => {} }; | ||
const testStory = () => <div id="test-story">Test Content</div>; | ||
const testContext = { | ||
kind: 'Foo', | ||
story: 'bar baz', | ||
}; | ||
|
||
const testStore = new KnobStore(); | ||
|
||
const wrappedStory = reactHandler(testChannel, testStore)(testStory)(testContext); | ||
const wrapper = shallow(wrappedStory); | ||
expect(wrapper.find('#test-story').length).toBe(1); | ||
|
||
const storyWrapperProps = wrappedStory.props; | ||
expect(storyWrapperProps.channel).toEqual(testChannel); | ||
expect(storyWrapperProps.context).toEqual(testContext); | ||
}); | ||
}); | ||
}); |
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,37 @@ | ||
export const vueHandler = (channel, knobStore) => getStory => context => ({ | ||
render(h) { | ||
return h(getStory(context)); | ||
}, | ||
|
||
methods: { | ||
onKnobChange(change) { | ||
const { name, value } = change; | ||
// Update the related knob and it's value. | ||
const knobOptions = knobStore.get(name); | ||
knobOptions.value = value; | ||
this.$forceUpdate(); | ||
}, | ||
|
||
onKnobReset() { | ||
knobStore.reset(); | ||
this.setPaneKnobs(false); | ||
this.$forceUpdate(); | ||
}, | ||
|
||
setPaneKnobs(timestamp = +new Date()) { | ||
channel.emit('addon:knobs:setKnobs', { knobs: knobStore.getAll(), timestamp }); | ||
}, | ||
}, | ||
|
||
created() { | ||
channel.on('addon:knobs:reset', this.onKnobReset); | ||
channel.on('addon:knobs:knobChange', this.onKnobChange); | ||
knobStore.subscribe(this.setPaneKnobs); | ||
}, | ||
|
||
beforeDestroy(){ | ||
channel.removeListener('addon:knobs:reset', this.onKnobReset); | ||
channel.removeListener('addon:knobs:knobChange', this.onKnobChange); | ||
knobStore.unsubscribe(this.setPaneKnobs); | ||
} | ||
}); |
Oops, something went wrong.