Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 8dd8184

Browse files
committed
feat: allow use boolean values for a simple configuration in some cases
1 parent 5db1b0c commit 8dd8184

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

packages/bootstrap-vue-next/src/BootstrapVue.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,21 @@ declare module '@vue/runtime-core' {
117117

118118
// Main app plugin
119119
const plugin: Plugin = {
120-
install(app: App, options?: BootstrapVueOptions) {
120+
install(app: App, options: BootstrapVueOptions = {components: true, directives: true}) {
121+
const allComponents = typeof options?.components === 'boolean' && options?.components
122+
const selectedComponents =
123+
typeof options?.components === 'object' ? options?.components : undefined
124+
const allDirectives = typeof options?.directives === 'boolean' && options?.directives
125+
const selectedDirectives =
126+
typeof options?.directives === 'object' ? options?.directives : undefined
121127
Object.entries(Components).forEach(([name, component]) => {
122-
if (!options?.components || options?.components[name as keyof typeof Components])
128+
if (allComponents || selectedComponents?.[name as keyof typeof Components])
123129
app.component(name, component)
124130
})
125131

126132
Object.entries(Directives).forEach(([name, component]) => {
127133
const parsedName = name.toLowerCase().startsWith('v') ? name.slice(1) : name
128-
if (!options?.directives || options?.directives[parsedName as keyof typeof Directives])
134+
if (allDirectives || selectedDirectives?.[parsedName as keyof typeof Directives])
129135
app.directive(parsedName, component)
130136
})
131137

packages/bootstrap-vue-next/src/components/BToast/plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ export function useToast(vm?: any, key: symbol = injectkey): ToastInstance | und
224224

225225
const BToastPlugin: Plugin = {
226226
install: (app: App, options?: BootstrapVueOptions) => {
227-
app.provide(fetchKey, options?.BToast?.injectkey ?? injectkey)
228-
app.provide(options?.BToast?.injectkey ?? injectkey, new ToastController())
227+
const key =
228+
typeof options?.BToast === 'object' ? options?.BToast?.injectkey ?? injectkey : injectkey
229+
app.provide(fetchKey, key)
230+
app.provide(key, new ToastController())
229231
},
230232
}
231233

packages/bootstrap-vue-next/src/types/BootstrapVueOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface BToastPluginOptions {
66
}
77

88
export interface BootstrapVueOptions {
9-
components?: Record<keyof typeof Components, boolean>
10-
directives?: Record<keyof typeof Directives, boolean>
11-
BToast?: BToastPluginOptions
9+
components?: boolean | Record<keyof typeof Components, boolean>
10+
directives?: boolean | Record<keyof typeof Directives, boolean>
11+
BToast?: boolean | BToastPluginOptions
1212
}

0 commit comments

Comments
 (0)