Nuxt/examples/storybook/stories/storybase.js

83 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-02-06 03:06:45 +00:00
import { storiesOf } from '@storybook/vue'
import { action } from '@storybook/addon-actions'
2018-02-06 02:36:22 +00:00
import {
withKnobs,
text,
number,
boolean,
array,
select,
color,
date,
object,
button
2018-02-06 03:06:45 +00:00
} from '@storybook/addon-knobs/vue'
import centered from '@storybook/addon-centered'
import { linkTo } from '@storybook/addon-links'
2018-02-06 02:36:22 +00:00
/**
* Template function for Vuetify
* @param {*} cmp component inside object {cmp}
* @param {*} cmpStr template string or function returning on
*/
const vtmp = (cmp, cmpStr) => ({
components: cmp,
template: `
<v-app style="min-width:400px">
<v-container fluid fill-height>
<v-flex xs12>${cmpStr instanceof Function ? cmpStr() : cmpStr}</v-flex>
</v-container>
</v-app>
`
})
/**
* Richer aLternative to storiesOf
* @param {*} cmp
* @param {*} name
* @param {*} params
*/
const nStoriesOf = (cmp, name = Object.keys(cmp)[0], params = {}) => {
let x = storiesOf(name, module)
.addDecorator(centered)
.addDecorator(withKnobs)
if (params.withDefault) {
2018-02-06 03:06:45 +00:00
x.add('Default', () => ({
2018-02-06 02:36:22 +00:00
render: h => h(Object.values(cmp)[0])
}))
}
x.addVT = (title, cmpStr) => {
x.add(title, () => vtmp(cmp, cmpStr))
return x
}
return x
}
/**
* Stories of which just works
* @param {*} cmp
* @param {*} name
*/
const nStoriesOfWithDefault = (cmp, name = Object.keys(cmp)[0]) =>
2018-02-06 03:06:45 +00:00
nStoriesOf(cmp, name, { withDefault: 'withDefault' })
2018-02-06 02:36:22 +00:00
export {
nStoriesOf,
nStoriesOfWithDefault,
action,
linkTo,
withKnobs,
text,
number,
object,
boolean,
array,
select,
color,
date,
button,
vtmp
2018-02-06 03:06:45 +00:00
}