Skip to content

Commit cc23771

Browse files
authored
Update config.js
1 parent 81f5c15 commit cc23771

File tree

1 file changed

+44
-54
lines changed

1 file changed

+44
-54
lines changed

src/utils/config.js

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
// General Bootstrap Vue configuration
33
//
44
// 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-
//
105
// - Pull this default config into the documentation (/docs/reference/settings)
116
// and document how to configure the settings
127
//
@@ -16,44 +11,20 @@ import { isArray } from './array'
1611

1712
// DISCUSSION: Breakpoint definitions
1813
//
19-
// Should breakpoints be stored here, or maybe on the Vue prototype?
20-
//
21-
// i.e. Vue.prototype.$BV_BREAKPOINTS
22-
//
2314
// Some components (BCol and BFormGroup) generate props based on breakpoints, and this
2415
// occurs when the component is first loaded (evaluated), which may happen before the
2516
// config is created/modified
2617
//
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
4220
// component is used (and cached on subsequent uses)
4321
//
4422
// See: https://vuejs.org/v2/guide/components-dynamic-async.html#Async-Components
4523
//
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-
5324
// DISCUSSION: Prop Defaults
5425
//
5526
// 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.
5728
//
5829
// props: {
5930
// variant: {
@@ -63,23 +34,43 @@ const BREAKPOINTS_DEFAULT = ['xs', 'sm', 'md', 'lg', 'xl']
6334
// }
6435
//
6536

37+
// prettier-ignore
6638
const DEFAULTS = {
6739
// Breakpoints... see discussion above
68-
breakpoints: BREAKPOINTS_DEFAULT,
40+
breakpoints: [
41+
'xs', 'sm', 'md', 'lg', 'xl'
42+
],
43+
6944
// Component Specific defaults are keyed by the component
7045
// 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+
},
7662
BFormFile: {
7763
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'
8073
},
81-
BImg: { blankColor: 'transparent' },
82-
BImgLazy: { blankColor: 'transparent' },
8374
BModal: {
8475
cancelTitle: 'Cancel',
8576
cancelVariant: 'secondary',
@@ -90,26 +81,14 @@ const DEFAULTS = {
9081
}
9182

9283
// 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)
9884
const CONFIG = {}
9985

10086
// Method to get a deep clone (immutable) copy of the defaults
10187
const getDefaults = () => JSON.parse(JSON.stringify(DEFAULTS))
10288

10389
// Method to set the config.
10490
// Merges in only known top-level and sub-level keys.
105-
//
10691
// 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
11392

11493
/* istanbul ignore next: just for now to prevent red X on codecov until we can test this */
11594
const setConfig = (opts = {}) => {
@@ -153,6 +132,16 @@ const getConfigComponent = (cmpName, key = null) => {
153132
}
154133
}
155134

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+
156145
// Convenience method for getting all breakpoint names
157146
const getBreakpointsAll = () => {
158147
return getConfigParam('breakpoints')
@@ -183,6 +172,7 @@ export {
183172
getDefaults,
184173
getConfigParam,
185174
getConfigComponent,
175+
getComponentConfig,
186176
getBreakpointsAll,
187177
getBreakpointsUp,
188178
getBreakpointsDown

0 commit comments

Comments
 (0)