From 17d26b84ba73529149f28ad66e8ad482a2adac59 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 15:49:07 -0300 Subject: [PATCH 001/247] feat(core): base global configuration --- src/utils/config.js | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/utils/config.js diff --git a/src/utils/config.js b/src/utils/config.js new file mode 100644 index 00000000000..3c33dc4493b --- /dev/null +++ b/src/utils/config.js @@ -0,0 +1,58 @@ +// +// General Bootstrap Vue config parameters +// +// TODO: +// - Make this cofigurable before bootstrap Vue is loaded, eitther by +// passing an expression to Vue.use(BootstrapVue, config = {}) or +// via global window.BoostrapVue.config (or similar) +// - Add default variants for each component (that may have a default +// variant, such as button, etc +// +import get from './get' + +const BV_DEFAULTS = { + breakpoints: ['xs', 'sm', 'md', 'lg', 'xl'] +} + +// This will be the object that any future user defined +// configuration will be in +const config = {} + +// Method to grab a config value based on a dotted/array notation key +const getConfigParam = key => { + // First we try the user config, and if key not found we + // fall back to default value. + return get(config, key, get(BV_DEFAULTS, key)) +} + +// Convenience method for getting all breakpoint names +const getBreakpointsAll = () => { + const bpts = getConfigParam('breakpoints').slice() + return bpts +} + +// Convenience method for getting breakpoints with +// the smallest breakpoint set as ''. +// Usefull for components that create breakpoint specific props +const getBreakpointsUp = () => { + const bpts = getBreakpointsAll() + bpts[0] = '' + return bpts +} + +// Convenience method for getting breakpoints with +// the largest breakpoint set as ''. +// Usefull for components that create breakpoint specific props +const getBreakpointsDown = () => { + const bpts = getBreakpointsAll() + bpts[bpts.length - 1] = '' + return bpts +} + +// Named Exports +export { + getConfigParam, + getBreakpointsAll, + getBreakpointsUp, + getBreakpointsDown +} From 6c21bab57c4a53b2aa5fab48aa361ce9a64ef4be Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 15:52:26 -0300 Subject: [PATCH 002/247] Update config.js --- src/utils/config.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/utils/config.js b/src/utils/config.js index 3c33dc4493b..28614c6698c 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -22,7 +22,7 @@ const config = {} const getConfigParam = key => { // First we try the user config, and if key not found we // fall back to default value. - return get(config, key, get(BV_DEFAULTS, key)) + return get(config, key, get(BV_DEFAULTS, key)) } // Convenience method for getting all breakpoint names @@ -50,9 +50,4 @@ const getBreakpointsDown = () => { } // Named Exports -export { - getConfigParam, - getBreakpointsAll, - getBreakpointsUp, - getBreakpointsDown -} +export { getConfigParam, getBreakpointsAll, getBreakpointsUp, getBreakpointsDown } From 89f7dbaf83873aa8b84adaa87e0178d0156a15ac Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 15:58:02 -0300 Subject: [PATCH 003/247] Update form-group.js --- src/components/form-group/form-group.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/form-group/form-group.js b/src/components/form-group/form-group.js index b591c825093..1308e9d0be2 100644 --- a/src/components/form-group/form-group.js +++ b/src/components/form-group/form-group.js @@ -2,6 +2,7 @@ import idMixin from '../../mixins/id' import formStateMixin from '../../mixins/form-state' // Utils +import { getBreakpointsUp } from '../../utils/config' import upperFirst from '../../utils/upper-first' import memoize from '../../utils/memoize' import warn from '../../utils/warn' @@ -19,7 +20,7 @@ import BFormValidFeedback from '../form/form-valid-feedback' const SELECTOR = 'input:not(:disabled),textarea:not(:disabled),select:not(:disabled)' // Breakpoint names for label-cols and label-align props -const BREAKPOINTS = ['', 'sm', 'md', 'lg', 'xl'] +const BREAKPOINTS = getPreakpointsUp() // Memoize this function to return cached values to save time in computed functions const makePropName = memoize((breakpoint = '', prefix) => { @@ -28,7 +29,7 @@ const makePropName = memoize((breakpoint = '', prefix) => { // Generate the labelCol breakpoint props const bpLabelColProps = BREAKPOINTS.reduce((props, breakpoint) => { - // label-cols, label-cols-sm, label-cols-md, ... + // i.e. label-cols, label-cols-sm, label-cols-md, ... props[makePropName(breakpoint, 'labelCols')] = { type: [Number, String, Boolean], default: breakpoint ? false : null From 3404dc2dac89683b365cae63d294550b6866c307 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 16:00:00 -0300 Subject: [PATCH 004/247] Update form-group.js --- src/components/form-group/form-group.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/form-group/form-group.js b/src/components/form-group/form-group.js index 1308e9d0be2..b71dc4b07de 100644 --- a/src/components/form-group/form-group.js +++ b/src/components/form-group/form-group.js @@ -20,7 +20,7 @@ import BFormValidFeedback from '../form/form-valid-feedback' const SELECTOR = 'input:not(:disabled),textarea:not(:disabled),select:not(:disabled)' // Breakpoint names for label-cols and label-align props -const BREAKPOINTS = getPreakpointsUp() +const BREAKPOINTS = getBreakpointsUp() // Memoize this function to return cached values to save time in computed functions const makePropName = memoize((breakpoint = '', prefix) => { From 286fe14b405691d6d8a073b9f972087a99b785ab Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 16:02:58 -0300 Subject: [PATCH 005/247] Update config.js --- src/utils/config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/config.js b/src/utils/config.js index 28614c6698c..4969acf5879 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -22,12 +22,13 @@ const config = {} const getConfigParam = key => { // First we try the user config, and if key not found we // fall back to default value. - return get(config, key, get(BV_DEFAULTS, key)) + // Returns a deep cloned version + return JSON.parse(JSON.stringify(get(config, key, get(BV_DEFAULTS, key)))) } // Convenience method for getting all breakpoint names const getBreakpointsAll = () => { - const bpts = getConfigParam('breakpoints').slice() + const bpts = getConfigParam('breakpoints') return bpts } From fb6117b5294d3daffab63daf300a18d13b1f3828 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 16:09:30 -0300 Subject: [PATCH 006/247] Create config.spec.js --- src/utils/config.spec.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/utils/config.spec.js diff --git a/src/utils/config.spec.js b/src/utils/config.spec.js new file mode 100644 index 00000000000..a4e2da76b4c --- /dev/null +++ b/src/utils/config.spec.js @@ -0,0 +1,27 @@ +import { getConfigParam, getBreakPointsAll, getBreakpointsUp, getBreakPointsDown } from './config' + +describe('utils/config', () => { + it('getConfigParam works', async () => { + expect(getConfigParam('breakpoints')).toEqual(['xs', 'sm', 'md', 'lg', 'xl']) + // Should return a deep clone + expect(getConfigParam('breakpoints')).not.toBe(getConfigParam('breakpoints')) + }) + + it('getBreakpointsAll works', async () => { + expect(getBreakpointsAll()).toEqual(['xs', 'sm', 'md', 'lg', 'xl']) + // Should return a deep clone + expect(getBreakpointsAll()).not.toBe(getBreakpointsAll()) + }) + + it('getBreakpointsUp works', async () => { + expect(getBreakpointsUp()).toEqual(['', 'sm', 'md', 'lg', 'xl']) + // Should return a deep clone + expect(getBreakpointsUp()).not.toBe(getBreakpointsUp()) + }) + + it('getBreakpointsDown works', async () => { + expect(getBreakpointsDown()).toEqual(['xs', 'sm', 'md', 'lg', '']) + // Should return a deep clone + expect(getBreakpointsDown()).not.toBe(getBreakpointsDown()) + }) +}) From e8bad3a4760d40a52a833fd3b881f023ab712085 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 16:12:11 -0300 Subject: [PATCH 007/247] Update config.spec.js --- src/utils/config.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/config.spec.js b/src/utils/config.spec.js index a4e2da76b4c..103ff748b67 100644 --- a/src/utils/config.spec.js +++ b/src/utils/config.spec.js @@ -1,10 +1,12 @@ -import { getConfigParam, getBreakPointsAll, getBreakpointsUp, getBreakPointsDown } from './config' +import { getConfigParam, getBreakpointsAll, getBreakpointsUp, getBreakpointsDown } from './config' describe('utils/config', () => { it('getConfigParam works', async () => { expect(getConfigParam('breakpoints')).toEqual(['xs', 'sm', 'md', 'lg', 'xl']) // Should return a deep clone expect(getConfigParam('breakpoints')).not.toBe(getConfigParam('breakpoints')) + // Should return null for not found + expect(getConfigParam('foo.bar[1].baz')).toBe(null) }) it('getBreakpointsAll works', async () => { From ae21764a1dcabc48c53154882c8d029378ec0fe2 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 16:37:07 -0300 Subject: [PATCH 008/247] Update config.js --- src/utils/config.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/utils/config.js b/src/utils/config.js index 4969acf5879..0370a8e139b 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -11,19 +11,29 @@ import get from './get' const BV_DEFAULTS = { - breakpoints: ['xs', 'sm', 'md', 'lg', 'xl'] + breakpoints: ['xs', 'sm', 'md', 'lg', 'xl'], + // Component Specific defaults are keyed by the component name + BAlert: { variant: 'info' }, + BBadge: { variant: 'secondary' }, + BButton: { variant: 'secondary' }, + BButtonCose: { textVariant: null }, + BDropdown: { variant: null }, // defaults to button variant + BImg: { blankColor: 'transparent' } } // This will be the object that any future user defined -// configuration will be in +// configuration will be placed in the future const config = {} -// Method to grab a config value based on a dotted/array notation key +// Method to get a deep clone (immutable) copy of the defaults +const getDefaults = () => JSON.parse(JSON.stringify(BV_DEFAULTS)) + +// Method to grab a config value based on a dotted/array notation key. +// Returns a deep clone (immutable) copy const getConfigParam = key => { // First we try the user config, and if key not found we // fall back to default value. - // Returns a deep cloned version - return JSON.parse(JSON.stringify(get(config, key, get(BV_DEFAULTS, key)))) + return JSON.parse(JSON.stringify(get(config, key, get(getDefaults(), key)))) } // Convenience method for getting all breakpoint names @@ -51,4 +61,10 @@ const getBreakpointsDown = () => { } // Named Exports -export { getConfigParam, getBreakpointsAll, getBreakpointsUp, getBreakpointsDown } +export { + getDefaults, + getConfigParam, + getBreakpointsAll, + getBreakpointsUp, + getBreakpointsDown +} From 370dc99eef3a9497e64299a5d76e4e2f543d28ec Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 16:40:52 -0300 Subject: [PATCH 009/247] Update config.js --- src/utils/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/config.js b/src/utils/config.js index 0370a8e139b..d8b20ce091a 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -61,6 +61,7 @@ const getBreakpointsDown = () => { } // Named Exports +// prettier-ignore export { getDefaults, getConfigParam, From 4edaea103502c12613b93fc425a9d94bf2ef6146 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 16:42:35 -0300 Subject: [PATCH 010/247] Update config.js --- src/utils/config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/config.js b/src/utils/config.js index d8b20ce091a..c33e17ceeb1 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -12,7 +12,8 @@ import get from './get' const BV_DEFAULTS = { breakpoints: ['xs', 'sm', 'md', 'lg', 'xl'], - // Component Specific defaults are keyed by the component name + // Component Specific defaults are keyed by the component + // name (PascalCase) and prop name (camelCase) BAlert: { variant: 'info' }, BBadge: { variant: 'secondary' }, BButton: { variant: 'secondary' }, From 481ba54d597e99ea4d1c4d81dcde00191ccbe068 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 16:45:03 -0300 Subject: [PATCH 011/247] Update config.js --- src/utils/config.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/config.js b/src/utils/config.js index c33e17ceeb1..f3ebd9640ef 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -6,8 +6,10 @@ // passing an expression to Vue.use(BootstrapVue, config = {}) or // via global window.BoostrapVue.config (or similar) // - Add default variants for each component (that may have a default -// variant, such as button, etc -// +// variant, such as button, etc) +// - Pull this default config into the documentation (/docs/reference/settings) +// and document how to configure the settings +// import get from './get' const BV_DEFAULTS = { From 668f6aa7115beebbd36b07c51bff1b4dadedeb35 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 16:50:40 -0300 Subject: [PATCH 012/247] lint --- src/utils/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/config.js b/src/utils/config.js index f3ebd9640ef..cafe0fb523f 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -9,7 +9,7 @@ // variant, such as button, etc) // - Pull this default config into the documentation (/docs/reference/settings) // and document how to configure the settings -// +// import get from './get' const BV_DEFAULTS = { From eda357215f6321c0d3824d8e3fec3235655f980b Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 17:08:11 -0300 Subject: [PATCH 013/247] Update config.spec.js --- src/utils/config.spec.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/utils/config.spec.js b/src/utils/config.spec.js index 103ff748b67..6e2a59cf5d4 100644 --- a/src/utils/config.spec.js +++ b/src/utils/config.spec.js @@ -1,7 +1,14 @@ -import { getConfigParam, getBreakpointsAll, getBreakpointsUp, getBreakpointsDown } from './config' +import { + getDefaults, + getConfigParam, + getBreakpointsAll, + getBreakpointsUp, + getBreakpointsDown +} from './config' +import looseEqual from './loose-equal' describe('utils/config', () => { - it('getConfigParam works', async () => { + it('getConfigParam() works', async () => { expect(getConfigParam('breakpoints')).toEqual(['xs', 'sm', 'md', 'lg', 'xl']) // Should return a deep clone expect(getConfigParam('breakpoints')).not.toBe(getConfigParam('breakpoints')) @@ -9,21 +16,36 @@ describe('utils/config', () => { expect(getConfigParam('foo.bar[1].baz')).toBe(null) }) - it('getBreakpointsAll works', async () => { + it('getBreakpointsAll() works', async () => { expect(getBreakpointsAll()).toEqual(['xs', 'sm', 'md', 'lg', 'xl']) // Should return a deep clone expect(getBreakpointsAll()).not.toBe(getBreakpointsAll()) }) - it('getBreakpointsUp works', async () => { + it('getBreakpointsUp() works', async () => { expect(getBreakpointsUp()).toEqual(['', 'sm', 'md', 'lg', 'xl']) // Should return a deep clone expect(getBreakpointsUp()).not.toBe(getBreakpointsUp()) }) - it('getBreakpointsDown works', async () => { + it('getBreakpointsDown() works', async () => { expect(getBreakpointsDown()).toEqual(['xs', 'sm', 'md', 'lg', '']) // Should return a deep clone expect(getBreakpointsDown()).not.toBe(getBreakpointsDown()) }) + + it('getDefaults() returns deep clone', async () => { + const defaults = getDefaults() + expect(getDefaults()).toEqual(defaults) + expect(getDefaults()).not.toBe(defaults) + + // Each key should be a clone (top level key test) + expect(Object.keys(defaults).every(key => { + // Should not point to the same reference + const param = getConfigParam(key) + return param !== defaults[key] && looseEqual(param, defaults[key]) + })).toBe(true) + + // TODO: test each nested key (if Array or Plain Object) + }) }) From c7d0f37b227629e516b96259a98b17b58e6cd7aa Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 17:13:13 -0300 Subject: [PATCH 014/247] Update config.spec.js --- src/utils/config.spec.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/utils/config.spec.js b/src/utils/config.spec.js index 6e2a59cf5d4..bf59219fa63 100644 --- a/src/utils/config.spec.js +++ b/src/utils/config.spec.js @@ -36,15 +36,19 @@ describe('utils/config', () => { it('getDefaults() returns deep clone', async () => { const defaults = getDefaults() + + expect(Object.keys(defaults).length).toBeGreaterThan(1) expect(getDefaults()).toEqual(defaults) expect(getDefaults()).not.toBe(defaults) // Each key should be a clone (top level key test) - expect(Object.keys(defaults).every(key => { - // Should not point to the same reference - const param = getConfigParam(key) - return param !== defaults[key] && looseEqual(param, defaults[key]) - })).toBe(true) + expect( + Object.keys(defaults).every(key => { + // Should not point to the same reference + const param = getConfigParam(key) + return param !== defaults[key] && looseEqual(param, defaults[key]) + }) + ).toBe(true) // TODO: test each nested key (if Array or Plain Object) }) From 4354c2bb2606629ca79f02809f642221833d1446 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 17:49:29 -0300 Subject: [PATCH 015/247] Update componentdoc.vue --- docs/components/componentdoc.vue | 48 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/docs/components/componentdoc.vue b/docs/components/componentdoc.vue index 5521ae909d9..51f0ead7c09 100644 --- a/docs/components/componentdoc.vue +++ b/docs/components/componentdoc.vue @@ -134,44 +134,46 @@ export default { }, propsFields() { const component = Vue.options.components[this.component] - let props = [] + let props = {} if (component) { - props = component.options.props + props = component.options.props || {} } - const hasRequired = props.length > 0 && props.filter(p => p.required).length > 0 - const fields = { - prop: { label: 'Property' }, - type: { label: 'Type' }, - default: { label: 'Default Value' } - } + const hasRequired = Object.keys(props).some(p => props[p].required) + + const fields = [ + { key: 'prop', label: 'Property' }, + { key: 'type', label: 'Type' }, + { key: 'default', label: 'Default Value' } + ] // Add the required column if there are required field(s) if (hasRequired) { - fields.required = { label: 'Required' } + // Insert Required field after prop name + fileds.splice(1, 0, { key: 'required', label: 'Required' }) } return fields }, eventsFields() { - return { - event: { label: 'Event' }, - args: { label: 'Arguments' }, - description: { label: 'Description' } - } + return [ + { key: 'event', label: 'Event' }, + { key: 'args', label: 'Arguments' }, + { key: 'description', label: 'Description' } + ] }, rootEventListenersFields() { - return { - event: { label: 'Event' }, - args: { label: 'Arguments' }, - description: { label: 'Description' } - } + return [ + { key: 'event', label: 'Event' }, + { key: 'args', label: 'Arguments' }, + { key: 'description', label: 'Description' } + ] }, slotsFields() { - return { - name: { label: 'Slot' }, - description: { label: 'Description' } - } + return [ + { key: 'name', label: 'Slot' }, + { key: 'description', label: 'Description' } + ] }, propsItems() { const component = Vue.options.components[this.component] From fb9061d35103a06d2c2b198553b92e0da9e472ce Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 17:52:20 -0300 Subject: [PATCH 016/247] Update componentdoc.vue --- docs/components/componentdoc.vue | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/components/componentdoc.vue b/docs/components/componentdoc.vue index 51f0ead7c09..35bd3ad10df 100644 --- a/docs/components/componentdoc.vue +++ b/docs/components/componentdoc.vue @@ -150,7 +150,7 @@ export default { // Add the required column if there are required field(s) if (hasRequired) { // Insert Required field after prop name - fileds.splice(1, 0, { key: 'required', label: 'Required' }) + fields.splice(1, 0, { key: 'required', label: 'Required' }) } return fields @@ -170,10 +170,7 @@ export default { ] }, slotsFields() { - return [ - { key: 'name', label: 'Slot' }, - { key: 'description', label: 'Description' } - ] + return [{ key: 'name', label: 'Slot' }, { key: 'description', label: 'Description' }] }, propsItems() { const component = Vue.options.components[this.component] From 01a3345f084eb94725887b9e16ac81406a8023ca Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 18:19:34 -0300 Subject: [PATCH 017/247] Update componentdoc.vue --- docs/components/componentdoc.vue | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/components/componentdoc.vue b/docs/components/componentdoc.vue index 35bd3ad10df..4615442f124 100644 --- a/docs/components/componentdoc.vue +++ b/docs/components/componentdoc.vue @@ -31,6 +31,14 @@ head-variant="default" striped > + From b57bc4fb3a7d71d132e16bfa2cc1b0ff0f7f26cd Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 23 Mar 2019 18:27:06 -0300 Subject: [PATCH 018/247] Update componentdoc.vue --- docs/components/componentdoc.vue | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/components/componentdoc.vue b/docs/components/componentdoc.vue index 4615442f124..da12c055961 100644 --- a/docs/components/componentdoc.vue +++ b/docs/components/componentdoc.vue @@ -35,12 +35,15 @@ {{ value }} -