Skip to main content

ConfigProvider

Provides unified global configuration for components (size, locale, theme variables, background-pattern allowlist).

Basic usage​

Global size and theme variables
import { LhConfigProvider, LhButton } from '@lh-ui/react'

export default function Demo() {
return (
<>
<LhConfigProvider size="large" themeVars={{ 'primary-color': '#722ed1' }}>
<LhButton type="primary">Global large + custom primary</LhButton>
</LhConfigProvider>

<LhConfigProvider size="small">
<LhButton type="primary">Global small</LhButton>
</LhConfigProvider>
</>
)
}

Props​

PropDescriptionTypeDefault
sizeGlobal size'large' | 'middle' | 'small'—
localeGlobal localeLhComponentLanguage'zh-CN'
themeVarsGlobal theme variables (keys without the --lh- prefix)Record<string, string>—
patternComponentsAllowlist of components that apply the background patternLhThemeableComponent[]—
componentThemePer-component theme variablesPartial<Record<LhThemeableComponent, Record<string, string>>>—

Theme variable precedence​

Component's own props > componentTheme[componentName] > global themeVars

Available themeVars keys​

KeyDescription
primary-colorPrimary color
success-color / warning-color / danger-color / info-colorSemantic colors
gold-color / vermilion-color / jade-colorChinese-style colors
bg-color / text-color / border-colorNeutral colors
bg-patternPattern background URL (e.g. var(--lh-pattern-willow))
bg-pattern-opacity / bg-pattern-colorPattern opacity and color
decoration-colorDecoration color

See Theme customization for the full story.

Reading in components​

import { useLhConfigContext } from '@lh-ui/react'

function Probe() {
const { size, locale } = useLhConfigContext()
return <span>{size} / {locale}</span>
}
Consumer fallback

When no LhConfigProvider wraps the tree, useLhConfigContext() returns a fallback object with every field undefined (not null), so components need no null checks. This is an intentional difference from plus.

Styles​

import '@lh-ui/react/style/config-provider'