0.2.4 • Published 1 year ago

@tawa/mario-config-provider v0.2.4

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

title: ConfigProvider 全局配置 nav: title: 组件 path: /components order: 1 group: title: 其他 path: /config-provider

order: 999

ConfigProvider 全局配置

为组件提供统一的全局化配置。

使用

ConfigProvider 使用 React 的 context 特性,只需在应用外围包裹一次即可全局生效。该组件继承了 antd 中 ConfigProvider 的属性,新增 components,可以为被 withConfigConsumer 包裹的组件设置全局属性。

import ConfigProvider, {
  withConfigConsumer,
} from '@tawa/mario-config-provider';
import { Input } from 'antd';

const contextValue = {
  components: {
    // key为被withConfigConsumer包裹组件的displayName或name
    Table: {
      pagination: {
        pageSizeOptions: [20, 30, 50],
      },
    },
  },
};

withConfigConsumer(Input);

export default () => (
  <ConfigProvider {...contextValue}>
    <App />
  </ConfigProvider>
);

API

参数说明类型默认值
components组件公共属性配置Object{}
widgetstable 等渲染类型为组件的 type 配置公共属性Object{}

其他属性见 antd ConfigProvider