5
5
>
6
6
<b-row tag =" header" align-v =" center" >
7
7
<b-col sm =" 9" >
8
- <h2 :id =" `comp-ref-${componentName}`" ><code >{{ tag }}</code ></h2 >
8
+ <anchored-heading :id =" `comp-ref-${componentName}`" level =" 2" >
9
+ <code >{{ tag }}</code >
10
+ </anchored-heading >
9
11
</b-col >
10
12
<b-col sm =" 3" class =" text-sm-right" >
11
13
<b-btn variant =" outline-secondary" size =" sm" :href =" githubURL" target =" _blank" >
15
17
</b-row >
16
18
17
19
<article v-if =" aliases && aliases.length > 0" >
18
- <h4 :id =" `comp-ref-${componentName}-aliases`" >Component aliases</h4 >
20
+ <anchored-heading :id =" `comp-ref-${componentName}-aliases`" level =" 4" >
21
+ Component aliases
22
+ </anchored-heading >
19
23
<p ><code >{{ tag }}</code > can also be used via the following aliases:</p >
20
24
<ul >
21
25
<li v-for =" alias in aliases" :key =" alias" ><code >< ; {{ kebabCase(alias) }}> ; </code ></li >
22
26
</ul >
23
27
</article >
24
28
25
29
<article v-if =" propsItems && propsItems.length > 0" >
26
- <h4 :id =" `comp-ref-${componentName}-props`" >Properties</h4 >
30
+ <anchored-heading :id =" `comp-ref-${componentName}-props`" level =" 4" >
31
+ Properties
32
+ </anchored-heading >
27
33
<b-table
28
34
:items =" propsItems"
29
35
:fields =" propsFields"
30
36
small
31
37
head-variant =" default"
32
38
striped
33
39
>
34
- <template slot="default" slot-scope="field">
35
- <code v-if =" field.value" >{{ field.value }}</code >
40
+ <template slot="prop" slot-scope="{ value }">
41
+ <code >{{ value }}</code >
42
+ </template >
43
+ <template slot="row-details" slot-scope="{ item }">
44
+ <b-badge variant =" warning" >
45
+ {{ typeof item.deprecated === 'string' ? 'deprecation' : 'deprecated' }}
46
+ </b-badge >
47
+ <!-- if deprecated is a string, show the string value -->
48
+ <small v-if =" typeof item.deprecated === 'string'" >{{ item.deprecated }}</small >
49
+ </template >
50
+ <template slot="defaultValue" slot-scope="{ value }">
51
+ <code v-if =" value" >{{ value }}</code >
36
52
</template >
37
53
</b-table >
54
+
55
+ <template v-if =" componentVModel " >
56
+ <anchored-heading :id =" `comp-ref-${componentName}-v-model`" level =" 4" >
57
+ V-Model
58
+ </anchored-heading >
59
+ <b-table
60
+ :items =" [componentVModel]"
61
+ :fields =" ['prop', 'event']"
62
+ small
63
+ head-variant =" default"
64
+ striped
65
+ >
66
+ <template slot="prop" slot-scope="{ value }">
67
+ <code >{{ kebabCase(value) }}</code >
68
+ </template >
69
+ <template slot="event" slot-scope="{ value }">
70
+ <code >{{ value }}</code >
71
+ </template >
72
+ </b-table >
73
+ </template >
38
74
</article >
39
75
40
76
<article v-if =" slots && slots.length > 0" >
41
- <h4 :id =" `comp-ref-${componentName}-slots`" >Slots</h4 >
77
+ <anchored-heading :id =" `comp-ref-${componentName}-slots`" level =" 4" >
78
+ Slots
79
+ </anchored-heading >
42
80
<b-table
43
81
:items =" slots"
44
82
:fields =" slotsFields"
49
87
</article >
50
88
51
89
<article v-if =" events && events.length > 0" >
52
- <h4 :id =" `comp-ref-${componentName}-events`" >Events</h4 >
90
+ <anchored-heading :id =" `comp-ref-${componentName}-events`" level =" 4" >
91
+ Events
92
+ </anchored-heading >
53
93
<b-table
54
94
:items =" events"
55
95
:fields =" eventsFields"
56
96
small
57
97
head-variant =" default"
58
98
striped
59
99
>
60
- <template slot="args" slot-scope="field ">
100
+ <template slot="args" slot-scope="{ value, item } ">
61
101
<div
62
- v-for =" arg in field. value"
63
- :key =" `event-${field. item.event}-${arg.arg ? arg.arg : 'none'}`"
102
+ v-for =" arg in value"
103
+ :key =" `event-${item.event}-${arg.arg ? arg.arg : 'none'}`"
64
104
>
65
105
<template v-if =" arg .arg " ><code >{{ arg.arg }}</code > - </template >
66
- <span v-html =" arg.description" / >
106
+ <span v-html =" arg.description" ></ span >
67
107
</div >
68
108
</template >
69
109
</b-table >
70
110
</article >
71
111
72
112
<article v-if =" rootEventListeners && rootEventListeners.length > 0" >
73
- <h4 :id =" `comp-ref-${componentName}-rootEventListeners`" >$root Event Listeners</h4 >
113
+ <anchored-heading :id =" `comp-ref-${componentName}-rootEventListeners`" level =" 4" >
114
+ $root Event Listeners
115
+ </anchored-heading >
74
116
<p >You can control <code >{{ tag }}</code > by emitting the following events on <samp >$root</samp >:</p >
75
117
<b-table
76
118
:items =" rootEventListeners"
79
121
head-variant =" default"
80
122
striped
81
123
>
82
- <template slot="args" slot-scope="field ">
124
+ <template slot="args" slot-scope="{ value, item } ">
83
125
<div
84
- v-for =" arg in field. value"
85
- :key =" `event-${field. item.event}-${arg.arg ? arg.arg : 'none'}`"
126
+ v-for =" arg in value"
127
+ :key =" `event-${item.event}-${arg.arg ? arg.arg : 'none'}`"
86
128
>
87
129
<template v-if =" arg .arg " ><code >{{ arg.arg }}</code > - </template >
88
- <span v-html =" arg.description" / >
130
+ <span v-html =" arg.description" ></ span >
89
131
</div >
90
132
</template >
91
133
</b-table >
@@ -106,8 +148,12 @@ h5 {
106
148
<script >
107
149
import Vue from ' vue'
108
150
import kebabCase from ' lodash/kebabCase'
151
+ import AnchoredHeading from ' ./anchored-heading'
109
152
110
153
export default {
154
+ components: {
155
+ AnchoredHeading
156
+ },
111
157
props: {
112
158
component: {},
113
159
slots: {
@@ -130,56 +176,73 @@ export default {
130
176
computed: {
131
177
componentOptions () {
132
178
const component = Vue .options .components [this .component ]
133
- return component && component .options ? component .options : {}
134
- },
135
- propsFields () {
136
- const component = Vue .options .components [this .component ]
137
- let props = []
138
- if (component) {
139
- props = component .options .props
179
+ if (! component) {
180
+ return {}
140
181
}
141
- const hasRequired = props .length > 0 && props .filter (p => p .required ).length > 0
142
182
143
- const fields = {
144
- prop: { label: ' Property' },
145
- type: { label: ' Type' },
146
- default: { label: ' Default Value' }
183
+ let options = {}
184
+ if (! component .options && typeof component === ' function' ) {
185
+ // Async component that hans't been resolved yet
186
+ component (opts => {
187
+ options = opts ? { ... opts } : {}
188
+ })
189
+ } else {
190
+ // Regular component
191
+ options = component .options || {}
192
+ }
193
+
194
+ return options
195
+ },
196
+ componentVModel () {
197
+ const model = this .componentOptions .model
198
+ if (model && model .prop && model .event ) {
199
+ return model
200
+ } else {
201
+ return false
147
202
}
203
+ },
204
+ componentProps () {
205
+ return this .componentOptions .props || {}
206
+ },
207
+ propsFields () {
208
+ const props = this .componentProps
209
+
210
+ const hasRequired = Object .keys (props).some (p => props[p].required )
211
+
212
+ const fields = [
213
+ { key: ' prop' , label: ' Property' },
214
+ { key: ' type' , label: ' Type' },
215
+ { key: ' defaultValue' , label: ' Default Value' }
216
+ ]
148
217
149
218
// Add the required column if there are required field(s)
150
219
if (hasRequired) {
151
- fields .required = { label: ' Required' }
220
+ // Insert required field after prop name
221
+ fields .splice (1 , 0 , { key: ' required' , label: ' Required' })
152
222
}
153
223
154
224
return fields
155
225
},
156
226
eventsFields () {
157
- return {
158
- event : { label: ' Event' },
159
- args : { label: ' Arguments' },
160
- description : { label: ' Description' }
161
- }
227
+ return [
228
+ { key : ' event ' , label: ' Event' },
229
+ { key : ' args ' , label: ' Arguments' },
230
+ { key : ' description ' , label: ' Description' }
231
+ ]
162
232
},
163
233
rootEventListenersFields () {
164
- return {
165
- event : { label: ' Event' },
166
- args : { label: ' Arguments' },
167
- description : { label: ' Description' }
168
- }
234
+ return [
235
+ { key : ' event ' , label: ' Event' },
236
+ { key : ' args ' , label: ' Arguments' },
237
+ { key : ' description ' , label: ' Description' }
238
+ ]
169
239
},
170
240
slotsFields () {
171
- return {
172
- name: { label: ' Slot' },
173
- description: { label: ' Description' }
174
- }
241
+ return [{ key: ' name' , label: ' Slot' }, { key: ' description' , label: ' Description' }]
175
242
},
176
243
propsItems () {
177
- const component = Vue .options .components [this .component ]
178
- if (! component) {
179
- return {}
180
- }
244
+ const props = this .componentProps
181
245
182
- const props = component .options .props
183
246
return Object .keys (props).map (prop => {
184
247
const p = props[prop]
185
248
@@ -213,13 +276,17 @@ export default {
213
276
214
277
// Requied prop?
215
278
const required = p .required ? ' Yes' : ' '
279
+ // Deprecation?
280
+ const deprecated = p .deprecated || false
216
281
217
282
return {
218
283
prop: kebabCase (prop),
219
284
type,
220
285
required,
221
286
typeClass,
222
- default: defaultVal
287
+ defaultValue: defaultVal,
288
+ deprecated,
289
+ _showDetails: !! deprecated
223
290
}
224
291
})
225
292
},
0 commit comments