Three-layer theme overrides
vtable-guild's theme system is split into three layers so that "preset baseline", "application-wide rules" and "single-instance exceptions" can be managed separately, instead of writing every style into selectors on the page.
Three-layer structure
Themes go from low to high in three layers:
- Preset default theme
Two built-in visual baselines,antdvandelement-plus, switched withthemePreset. - The global
themeofcreateVTableGuild
Suits application-wide rules for headers, borders, hover, the default size and so on. uiandclasson aVTableinstance
Suits a local exception on a single table.
The three layers merge in order, so you do not need to copy a whole preset theme just to change the header color of one table.
Build a mental model first
The most commonly used entry point of the global theme is:
createVTableGuild({
theme: {
table: {
slots: {},
variants: {},
defaultVariants: {},
},
},
})Think of it as three parts:
slotsChange the class of a theme slot directly, such asth,td,root,loadingvariantsChange conditional styles, such ashoverable.true.td,bordered.true.rootdefaultVariantsChange default switches, such as changing the globalsizedefault fromlargetosmall
If you have already read the ui slot reference, the slot keys listed on that page can basically all be mapped directly to theme.table.slots.
How to write the global theme
When you want every table in your application to follow the same visual rules, override at the plugin layer first:
import { createApp } from 'vue'
import { createVTableGuild } from '@vtable-guild/vtable-guild'
const app = createApp(App)
app.use(
createVTableGuild({
theme: {
table: {
slots: {
root: 'rounded-2xl ring-1 ring-slate-200',
th: 'bg-slate-50 text-slate-900',
td: 'align-top',
},
defaultVariants: {
size: 'small',
},
},
},
}),
)Example 1: unify the header and body baseline
createVTableGuild({
theme: {
table: {
slots: {
th: 'bg-slate-50 text-slate-900 font-medium',
td: 'align-top',
},
},
},
})Example 2: unify the hover row background
:root {
--vtg-table-row-hover-bg: #e6f7ff;
}Overriding CSS variables is the recommended approach: the hover highlight is driven by JS state, so it handles cells merged across rows correctly.
Example 3: unify the default size
createVTableGuild({
theme: {
table: {
defaultVariants: {
size: 'small',
},
},
},
})TIP
In a TypeScript project, theme.table.slots, variants and defaultVariants all have precise key completion; override values can be your own class strings.
When to use CSS variables
If what you want to change are token values such as colors, font sizes, line heights or padding, override CSS variables instead of rewriting the class structure directly.
For example, to change only the row hover background:
:root {
--vtg-table-row-hover-bg: #e6f7ff;
}This approach is more stable, and it is especially suited to:
- keeping the existing slot structure and changing only colors or sizes
- working across multiple instances and multiple application pages at the same time
- following future preset upgrades with less class rewriting
See Table CSS variables for the full variable list.
Per-instance overrides
When you only want to adjust a single table, prefer ui and class:
<VTable
row-key="key"
:columns="columns"
:data-source="dataSource"
class="shadow-lg"
:ui="{
root: 'rounded-xl',
th: 'bg-emerald-50',
td: 'align-top',
}"
/>Utility prefix and override rules
In the default precompiled mode, utility classes inside the library are emitted with the vtg- prefix. Classes you pass in through ui, class, rowClassName and so on are not prefixed automatically.
To override a library utility, pass the same prefix:
<VTable :columns="columns" :data-source="dataSource" :ui="{ th: 'vtg-px-2' }" />Passing px-2 directly may coexist with the internal vtg-px-* and does not guarantee an override.
In tailwind3 and tailwind4 modes, the internal classes stay unprefixed, so you can keep overriding them with ordinary Tailwind classes:
app.use(createVTableGuild({ cssMode: 'tailwind3' }))
// or
app.use(createVTableGuild({ cssMode: 'tailwind4' }))<VTable :columns="columns" :data-source="dataSource" :ui="{ th: 'px-2' }" />For more integration details see Package imports and styles.
How to choose
- To switch the whole visual baseline, use
themePreset - To unify rules across your application, use the global
theme - To change a single table, use
uiandclass - To change only tokens such as colors, sizes and spacing, use CSS variables
When not to use slots directly
If your goal is only to change the header background, cell alignment, border color, hover background or default spacing, prefer theme, ui or CSS variables. Use Vue slots only when the content structure itself has to change.
Related pages
Pagination theme
Override pagination slots and the size / align / simple / disabled variants through theme.pagination. The full slot union is PaginationSlots at the end of the page. Instances accept pagination.class: string / style: CSSProperties. Pagination example.
Type Declarations
Below are the complete fields and mapping rules of the override types. Theme constants come from the public package; typeof preserves the readonly configuration, concrete slots and variant keys. For the full list of Table slot names see the ui slot reference, and for locale types see the Type reference.
Type Declarations
export declare function createVTableGuild(options?: VTableGuildOptions): Pluginexport interface VTableGuildOptions {
themePreset?: ThemePresetName
cssMode?: VTableGuildCssMode
classPrefix?: string
theme?: VTableGuildThemeOverrides
locale?: LocaleName
locales?: LocaleRegistry
localeOverrides?: DeepPartial<VTableGuildLocale>
/** 安装时读取一次,不支持运行时切换。 */
compatClass?: boolean
}export interface ThemeConfig {
slots: Record<string, string>
variants?: Record<string, Record<string, Record<string, string> | string>>
defaultVariants?: Record<string, string | boolean>
compoundVariants?: Array<Record<string, unknown>>
compoundSlots?: Array<Record<string, unknown>>
}// 以下 Theme* 辅助类型用于展开声明,不是包导出。
type ThemeSlotKeys<T extends ThemeConfig> = keyof T['slots'] & string
type ThemeVariantOverrides<T extends ThemeConfig> = {
[TVariant in keyof NonNullable<T['variants']>]?: NonNullable<
T['variants']
>[TVariant] extends Record<string, unknown>
? {
[TValue in keyof NonNullable<T['variants']>[TVariant]]?: NonNullable<
T['variants']
>[TVariant][TValue] extends string
? string
: Partial<Record<ThemeSlotKeys<T>, string>>
}
: never
}
type ThemeDefaultVariantOverrides<T extends ThemeConfig> = {
[TVariant in keyof NonNullable<T['defaultVariants']>]?: NonNullable<
T['defaultVariants']
>[TVariant] extends boolean
? boolean
: string
}
type ThemeCompoundRuleOverride<T, TSlotKey extends string> = T extends string
? string
: T extends boolean
? boolean
: T extends readonly (infer U)[]
? Array<U extends string ? Extract<U, TSlotKey> : ThemeCompoundRuleOverride<U, TSlotKey>>
: T extends object
? {
[K in keyof T]?: K extends 'class'
? string
: K extends 'slots'
? T[K] extends readonly (infer U)[]
? Array<Extract<U, TSlotKey>>
: ThemeCompoundRuleOverride<T[K], TSlotKey>
: ThemeCompoundRuleOverride<T[K], TSlotKey>
}
: T
export type ThemeOverrideConfig<T extends ThemeConfig> = {
slots?: Partial<Record<ThemeSlotKeys<T>, string>>
variants?: ThemeVariantOverrides<T>
defaultVariants?: ThemeDefaultVariantOverrides<T>
compoundVariants?: T extends { compoundVariants?: readonly (infer U)[] }
? Array<ThemeCompoundRuleOverride<U, ThemeSlotKeys<T>>>
: never
compoundSlots?: T extends { compoundSlots?: readonly (infer U)[] }
? Array<ThemeCompoundRuleOverride<U, ThemeSlotKeys<T>>>
: never
}export interface VTableGuildThemeOverridesMap {
table: ThemeOverrideConfig<TableThemeConfig>
button: ThemeOverrideConfig<ButtonThemeConfig>
checkbox: ThemeOverrideConfig<CheckboxThemeConfig>
radio: ThemeOverrideConfig<RadioThemeConfig>
input: ThemeOverrideConfig<InputThemeConfig>
tooltip: ThemeOverrideConfig<TooltipThemeConfig>
scrollbar: ThemeOverrideConfig<ScrollbarThemeConfig>
pagination: ThemeOverrideConfig<PaginationThemeConfig>
columnSettings: ThemeOverrideConfig<ColumnSettingsThemeConfig>
toolbar: ThemeOverrideConfig<ToolbarThemeConfig>
selectionAlert: ThemeOverrideConfig<SelectionAlertThemeConfig>
query: ThemeOverrideConfig<QueryThemeConfig>
}export type VTableGuildThemeOverrides = {
[K in keyof VTableGuildThemeOverridesMap]?: VTableGuildThemeOverridesMap[K]
}export type SlotProps<T extends ThemeConfig> = Partial<Record<keyof T['slots'] & string, string>>// tableTheme 是公开的默认 antdv 主题;typeof 保留 readonly 与字面量 variant 配置。
export type TableThemeConfig = typeof tableThemeexport type TableVariantProps = {
size?: 'large' | 'middle' | 'small'
bordered?: boolean
striped?: boolean
hoverable?: boolean
}export type ButtonSlots = 'root' | 'inner'
export type ButtonThemeConfig = typeof buttonTheme
export type CheckboxSlots = 'root' | 'checkMark' | 'indeterminateMark'
export type CheckboxThemeConfig = typeof checkboxTheme
export type RadioSlots = 'root' | 'dot'
export type RadioThemeConfig = typeof radioTheme
export type InputSlots = 'root'
export type InputThemeConfig = typeof inputTheme
export type TooltipSlots = 'content' | 'arrow' | 'arrowOuter' | 'arrowInner'
export type TooltipThemeConfig = typeof tooltipTheme
export type ScrollbarSlots =
| 'root'
| 'wrap'
| 'view'
| 'track'
| 'trackVertical'
| 'trackHorizontal'
| 'thumb'
export type ScrollbarThemeConfig = typeof scrollbarThemeexport type PaginationThemeConfig = typeof paginationThemeexport type PaginationSlots =
| 'root'
| 'layout'
| 'left'
| 'right'
| 'extension'
| 'pages'
| 'item'
| 'active'
| 'jump'
| 'jumpEllipsis'
| 'jumpIcon'
| 'controls'
| 'simpleControls'
| 'simpleInput'
| 'slash'
| 'go'
| 'input'
| 'select'
| 'popup'
| 'option'
| 'optionActive'
| 'total'
| 'icon'