KubedConfigProvider
提供主题对象上下文、国际化上下文和自定义配色方案。必须在应用程序的根目录下使用,并且只能使用一次.
使用
1import { KubedConfigProvider } from "@kubed/components";23<KubedConfigProvider themeType={'dark'} locale={'zh'}>4<App />5</KubedConfigProvider>;
Props
1interface Props {2/** 应用程序 **/3children: React.ReactNode;4/** 自定义主题 **/5themes?: Array<KubedTheme>;6/** 暗/亮色主题、或者自定义主题的name **/7themeType?: string | 'dark' | 'light';8/** 当前语言,默认支持'en', 'zh', 'zh-tw', 'es' **/9locale?: Locale;10/** 扩展的语言 **/11extendLocales?: Record<Locale, ILocale>;12}
自定义主题
将主题对象传递给themes属性,可以自定义主题,它将与默认主题合并在所有组件中使用
1import { KubedConfigProvider, Button, themeUtils } from "@kubed/components"2function App() {3const customDarkTheme = themeUtils.createFromDark({4type: "customDark",5palette: {6accents_1: "#1098AD",7accents_2: "#3BC9DB",8},9})10const customLightTheme = themeUtils.createFromLight({11type: "customLight",12palette: {13accents_1: "#F76707",14accents_2: "#FFA94D",15},16})17const [themeType, setThemeType] = useState("customDark")18return (19<KubedConfigProvider20themes={[customDarkTheme, customLightTheme]}21themeType={themeType}22>23<Button24onClick={() => {25if (themeType === "customDark") {26setThemeType("customLight")27} else {28setThemeType("customDark")29}30}}31>32button33</Button>34</KubedConfigProvider>35)36}