2
2
// General Bootstrap Vue configuration
3
3
//
4
4
// TODO:
5
- //
6
- // - Make this cofigurable before bootstrap Vue is loaded, either by
7
- // passing an expression to Vue.use(BootstrapVue, config = {}) or
8
- // via global window.BoostrapVue.config, or Vue.prototype.XXX (or similar)
9
- //
10
5
// - Pull this default config into the documentation (/docs/reference/settings)
11
6
// and document how to configure the settings
12
7
//
@@ -16,44 +11,20 @@ import { isArray } from './array'
16
11
17
12
// DISCUSSION: Breakpoint definitions
18
13
//
19
- // Should breakpoints be stored here, or maybe on the Vue prototype?
20
- //
21
- // i.e. Vue.prototype.$BV_BREAKPOINTS
22
- //
23
14
// Some components (BCol and BFormGroup) generate props based on breakpoints, and this
24
15
// occurs when the component is first loaded (evaluated), which may happen before the
25
16
// config is created/modified
26
17
//
27
- // To get around this would be to make the components that need to generate
28
- // prop names based on the config would be to define the component(s) as such:
29
- //
30
- // // we use a named function so that component.name resolves to the components name
31
- // // and that minification doesn't mangle the name
32
- // const BFormGroup = function BFormGroup(resolve, reject) => {
33
- // // prop computation could happen before the resolve
34
- // // or within the component using object spread on a function()
35
- // resolve( /* @vue/component */ {
36
- // // component definition
37
- // })
38
- // }
39
- // export default BFormGroup
40
- //
41
- // Now the component definition is only called/executed when the first access to the
18
+ // To get around this we make these components async (lazy evaluation).
19
+ // The component definition is only called/executed when the first access to the
42
20
// component is used (and cached on subsequent uses)
43
21
//
44
22
// See: https://vuejs.org/v2/guide/components-dynamic-async.html#Async-Components
45
23
//
46
- // This might be the better solution to the problem, although if other components need to
47
- // pluck props from this component, they wont be able to.
48
- // We are safe with BCol and BFormGroup as nothing else users their props
49
- //
50
-
51
- const BREAKPOINTS_DEFAULT = [ 'xs' , 'sm' , 'md' , 'lg' , 'xl' ]
52
-
53
24
// DISCUSSION: Prop Defaults
54
25
//
55
26
// For default values on props, we use the default value factory function approach so
56
- // so that the default values are pulled in at **runtime**
27
+ // so that the default values are pulled in at each component instantiation.
57
28
//
58
29
// props: {
59
30
// variant: {
@@ -63,23 +34,43 @@ const BREAKPOINTS_DEFAULT = ['xs', 'sm', 'md', 'lg', 'xl']
63
34
// }
64
35
//
65
36
37
+ // prettier-ignore
66
38
const DEFAULTS = {
67
39
// Breakpoints... see discussion above
68
- breakpoints : BREAKPOINTS_DEFAULT ,
40
+ breakpoints : [
41
+ 'xs' , 'sm' , 'md' , 'lg' , 'xl'
42
+ ] ,
43
+
69
44
// Component Specific defaults are keyed by the component
70
45
// name (PascalCase) and prop name (camelCase)
71
- BAlert : { variant : 'info' } ,
72
- BBadge : { variant : 'secondary' } ,
73
- BButton : { variant : 'secondary' } ,
74
- BButtonClose : { textVariant : null , ariaLabel : 'Close' } ,
75
- BDropdown : { variant : 'secondary' } ,
46
+ BAlert : {
47
+ variant : 'info'
48
+ } ,
49
+ BBadge : {
50
+ variant : 'secondary'
51
+ } ,
52
+ BButton : {
53
+ variant : 'secondary'
54
+ } ,
55
+ BButtonClose : {
56
+ textVariant : null ,
57
+ ariaLabel : 'Close'
58
+ } ,
59
+ BDropdown : {
60
+ variant : 'secondary'
61
+ } ,
76
62
BFormFile : {
77
63
browseText : 'Browse' ,
78
- dropPlaceholder : 'Drop files here' ,
79
- placeholder : 'No file chosen' // Chrome default file prompt
64
+ // Chrome default file prompt
65
+ placeholder : 'No file chosen' ,
66
+ dropPlaceholder : 'Drop files here'
67
+ } ,
68
+ BImg : {
69
+ blankColor : 'transparent'
70
+ } ,
71
+ BImgLazy : {
72
+ blankColor : 'transparent'
80
73
} ,
81
- BImg : { blankColor : 'transparent' } ,
82
- BImgLazy : { blankColor : 'transparent' } ,
83
74
BModal : {
84
75
cancelTitle : 'Cancel' ,
85
76
cancelVariant : 'secondary' ,
@@ -90,26 +81,14 @@ const DEFAULTS = {
90
81
}
91
82
92
83
// This contains user defined configuration
93
- //
94
- // Should this be stored here, or on the Vue.prototype ?????
95
- // For testing purposes, we might want to store this on Vue, so
96
- // we can use localVue so that testing doesn't pollute the config.
97
- // (unless we create a clearConfig() method to reset it)
98
84
const CONFIG = { }
99
85
100
86
// Method to get a deep clone (immutable) copy of the defaults
101
87
const getDefaults = ( ) => JSON . parse ( JSON . stringify ( DEFAULTS ) )
102
88
103
89
// Method to set the config.
104
90
// Merges in only known top-level and sub-level keys.
105
- //
106
91
// Vue.use(BootstrapVue, config)
107
- // or
108
- // BootstrapVue.config(config)
109
- // Vue.use(BootstrapVue)
110
- //
111
- // Breakpoint definition may need to be moved out of the config object
112
- // and set globally before bootstrapVue is loaded
113
92
114
93
/* istanbul ignore next: just for now to prevent red X on codecov until we can test this */
115
94
const setConfig = ( opts = { } ) => {
@@ -153,6 +132,16 @@ const getConfigComponent = (cmpName, key = null) => {
153
132
}
154
133
}
155
134
135
+ const getComponentConfig = ( cmpName , key = null ) => {
136
+ if ( key ) {
137
+ // Return the particular config value for key for specified component
138
+ return getConfigParam ( `${ cmpName } .${ key } ` )
139
+ } else {
140
+ // return the components full config
141
+ return getConfigParam ( cmpName ) || { }
142
+ }
143
+ }
144
+
156
145
// Convenience method for getting all breakpoint names
157
146
const getBreakpointsAll = ( ) => {
158
147
return getConfigParam ( 'breakpoints' )
@@ -183,6 +172,7 @@ export {
183
172
getDefaults ,
184
173
getConfigParam ,
185
174
getConfigComponent ,
175
+ getComponentConfig ,
186
176
getBreakpointsAll ,
187
177
getBreakpointsUp ,
188
178
getBreakpointsDown
0 commit comments