Basic Usage
Use the global configuration component for style overrides.
<template>
<b-config-provider
:theme="{
binColorPrimary: '#722ed1',
binColorSuccess: '#13c2c2',
binColorWarning: '#e14c19',
binColorDanger: '#d42a87'
}"
>
<div>
<div>[default]Default Button</div>
<div class="demo-button">
<b-button type="primary">Primary</b-button>
<b-button type="success">Success</b-button>
<b-button type="warning">Warning</b-button>
<b-button type="danger">Danger</b-button>
</div>
<div>[plain]Plain Button</div>
<div class="demo-button">
<b-button type="primary" plain>Primary</b-button>
<b-button type="success" plain>Success</b-button>
<b-button type="warning" plain>Warning</b-button>
<b-button type="danger" plain>Danger</b-button>
</div>
<div>[round]Round Button</div>
<div class="demo-button">
<b-button type="primary" round>Primary</b-button>
<b-button type="success" round>Success</b-button>
<b-button type="warning" round>Warning</b-button>
<b-button type="danger" round>Danger</b-button>
</div>
<div>[dashed]Dashed Button</div>
<div class="demo-button">
<b-button type="primary" dashed>Primary</b-button>
<b-button type="success" dashed>Success</b-button>
<b-button type="warning" dashed>Warning</b-button>
<b-button type="danger" dashed>Danger</b-button>
</div>
</div>
</b-config-provider>
</template>
<style scoped>
.demo-button {
margin: 8px 0;
}
</style>Abstract Container
Can be injected using an abstract tag, which will be injected into the HTML by default for global overrides (use with caution to avoid conflicts; generally used for global theme configuration).
<template>
<b-config-provider abstract :theme="config">
<b-button type="primary" @click="setGlobal">
Click to apply (primary color will change, affecting global)
</b-button>
</b-config-provider>
</template>
<script setup>
import { ref } from 'vue'
const config = ref({})
function setGlobal() {
config.value = { binColorPrimary: '#00c181' }
}
</script>Dark Mode
Enable dark mode with theme-name="dark". Runtime switching is supported, and teleported/function components (such as Message, Notice, MessageBox) will follow the current theme automatically.
<template>
<b-config-provider :theme-name="themeName">
<div class="demo-dark">
<b-button size="small" @click="toggleTheme">
Switch to {{ themeName === 'dark' ? 'Light' : 'Dark' }} Mode
</b-button>
<div class="demo-dark__row">
<b-input v-model="keyword" placeholder="Type keyword" clearable style="width: 220px" />
<b-select v-model="city" placeholder="Select city" style="width: 220px">
<b-option label="Shanghai" value="shanghai" />
<b-option label="Beijing" value="beijing" />
<b-option label="Shenzhen" value="shenzhen" />
</b-select>
<b-date-picker v-model="date" type="date" placeholder="Select date" style="width: 220px" />
</div>
<div class="demo-dark__row">
<b-dropdown @command="handleCommand">
<b-button>
Dropdown
<i class="b-iconfont b-icon-down"></i>
</b-button>
<template #dropdown>
<b-dropdown-menu>
<b-dropdown-item name="a">Menu A</b-dropdown-item>
<b-dropdown-item name="b">Menu B</b-dropdown-item>
</b-dropdown-menu>
</template>
</b-dropdown>
<b-button @click="showMessage">Message</b-button>
<b-button @click="showNotice">Notice</b-button>
<b-button @click="showConfirm">MessageBox</b-button>
</div>
</div>
</b-config-provider>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { Message, Notice, MessageBox } from 'bin-ui-design'
const themeName = ref<'light' | 'dark'>('light')
const keyword = ref('')
const city = ref('')
const date = ref('')
const toggleTheme = () => {
themeName.value = themeName.value === 'dark' ? 'light' : 'dark'
}
const handleCommand = value => {
Message.info(`Clicked menu: ${value}`)
}
const showMessage = () => {
Message.success('Message now follows current theme')
}
const showNotice = () => {
Notice.info({
title: 'Theme Sync',
message: 'Notice follows ConfigProvider theme switching'
})
}
const showConfirm = () => {
MessageBox.confirm({
title: 'Theme Sync',
message: 'MessageBox follows ConfigProvider theme switching'
})
}
</script>
<style scoped>
.demo-dark {
display: flex;
flex-direction: column;
gap: 12px;
}
.demo-dark__row {
display: flex;
gap: 12px;
flex-wrap: wrap;
}
</style>Internationalization
You can switch languages via the locale property. Currently, zh-CN and en-US are supported.
It is recommended to manage internationalization uniformly outside of business projects (e.g., via the application-layer i18n solution), while the component library injects language settings through ConfigProvider.
For more details, see Internationalization.
<template>
<div>
<div class="locale-actions">
<b-button size="small" :type="locale === 'zh-CN' ? 'primary' : 'default'" @click="locale = 'zh-CN'">
Chinese
</b-button>
<b-button size="small" :type="locale === 'en-US' ? 'primary' : 'default'" @click="locale = 'en-US'">
English
</b-button>
</div>
<b-config-provider :locale="locale">
<div class="locale-demo-wrap">
<b-date-picker v-model="date" type="date" />
<b-time-picker v-model="time" />
</div>
</b-config-provider>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const locale = ref<'zh-CN' | 'en-US'>('zh-CN')
const date = ref(new Date())
const time = ref(new Date())
</script>
<style scoped>
.locale-actions {
display: flex;
gap: 8px;
margin-bottom: 12px;
}
.locale-demo-wrap {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
</style>