Nuxt/examples/storybook/stories/storybase.js

86 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-02-06 02:36:22 +00:00
import { storiesOf } from "@storybook/vue"
import { action } from "@storybook/addon-actions"
import {
withKnobs,
text,
number,
boolean,
array,
select,
color,
date,
object,
button
} from "@storybook/addon-knobs/vue"
// import { withSmartKnobs } from "storybook-addon-smart-knobs"
// import { withInfo } from "@storybook/addon-info"
import centered from "@storybook/addon-centered"
import { linkTo } from "@storybook/addon-links"
/**
* 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) {
x.add("Default", () => ({
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]) =>
nStoriesOf(cmp, name, { withDefault: "withDefault" })
export {
nStoriesOf,
nStoriesOfWithDefault,
action,
withSmartKnobs,
withInfo,
linkTo,
withKnobs,
text,
number,
object,
boolean,
array,
select,
color,
date,
button,
vtmp
}