-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
custom-rendering.stories.js
124 lines (107 loc) · 2.85 KB
/
custom-rendering.stories.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import Vuex from 'vuex';
import { action } from '@storybook/addon-actions';
import { linkTo } from '@storybook/addon-links';
import MyButton from './Button.vue';
export default {
title: 'Custom/Method for rendering Vue',
};
export const render = () => ({
render: h => h('div', ['renders a div with some text in it..']),
});
export const renderComponent = () => ({
render(h) {
return h(MyButton, { props: { color: 'pink' } }, ['renders component: MyButton']);
},
});
renderComponent.story = {
name: 'render + component',
};
export const template = () => ({
template: `
<div>
<h1>A template</h1>
<p>rendered in vue in storybook</p>
</div>`,
});
export const templateComponent = () => ({
components: { MyButton },
template: '<my-button>MyButton rendered in a template</my-button>',
});
templateComponent.story = {
name: 'template + component',
};
export const templateMethods = () => ({
components: { MyButton },
template: `
<p>
<em>Clicking the button will navigate to another story using the 'addon-links'</em><br/>
<my-button :rounded="true" @click="action">MyButton rendered in a template + props & methods</my-button>
</p>`,
methods: {
action: linkTo('Button'),
},
});
templateMethods.story = {
name: 'template + methods',
};
export const JSX = () => ({
components: { MyButton },
render() {
return <my-button>MyButton rendered with JSX</my-button>;
},
});
export const vuexActions = () => ({
components: { MyButton },
template: '<my-button @click="log">with vuex: {{ $store.state.count }}</my-button>',
store: new Vuex.Store({
state: { count: 0 },
mutations: {
increment(state) {
state.count += 1; // eslint-disable-line
action('vuex state')(state);
},
},
}),
methods: {
log() {
this.$store.commit('increment');
},
},
});
vuexActions.story = {
name: 'vuex + actions',
};
export const whateverYouWant = () => ({
components: { MyButton },
template: '<my-button @click="log">with awesomeness: {{ $store.state.count }}</my-button>',
store: new Vuex.Store({
state: { count: 0 },
mutations: {
increment(state) {
state.count += 1; // eslint-disable-line
action('vuex state')(state);
},
},
}),
methods: {
log() {
this.$store.commit('increment');
},
},
});
whateverYouWant.story = {
name: 'whatever you want',
};
export const preRegisteredComponent = () => ({
/* By pre-registering component in config.js,
* the need to register all components with each story is removed.
* You'll only need the template */
template: `
<p>
<em>This component was pre-registered in .storybook/config.js</em><br/>
<my-button>MyButton rendered in a template</my-button>
</p>`,
});
preRegisteredComponent.story = {
name: 'pre-registered component',
};