Skip to content

fix(ConfigProvider): fix ConfigProvider merge bug #3442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/components/config-provider/ConfigContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export const defaultAnimation = {
exclude: [],
};

type DefaultGlobalConfig = Partial<GlobalConfigProvider>;

export const defaultGlobalConfig: DefaultGlobalConfig = {
export const defaultGlobalConfig: GlobalConfigProvider = {
animation: defaultAnimation,
classPrefix: defaultClassPrefix,
...merge({}, defaultLocale, defaultConfig),
Expand Down
9 changes: 5 additions & 4 deletions packages/components/config-provider/_example/calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { merge } from 'lodash-es';
import { ConfigProvider, Calendar } from 'tdesign-react';
import type { GlobalConfigProvider } from 'tdesign-react';
import enConfig from 'tdesign-react/es/locale/en_US';

const MONTHS = [
Expand All @@ -20,12 +20,13 @@ const MONTHS = [

export default function configDemo() {
// 全局特性配置,可以引入英文默认配置 enConfig,还可以在默认配置的基础上进行自定义配置
const globalConfig = merge(enConfig, {
const globalConfig: GlobalConfigProvider = {
...enConfig,
calendar: {
yearSelection: '{year}',
// 1 表示周一;7 表示周日
firstDayOfWeek: 7,
monthSelection: ({ month }: { month: number }) => MONTHS[month - 1],
monthSelection: ({ month }) => MONTHS[month - 1],
yearRadio: 'Year',
monthRadio: 'Month',
hideWeekend: 'Hide Weekend',
Expand Down Expand Up @@ -76,7 +77,7 @@ export default function configDemo() {
},
},
},
});
};

return (
<ConfigProvider globalConfig={globalConfig}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { merge } from 'lodash-es';
import { ConfigProvider, DatePicker, DateRangePicker, Space } from 'tdesign-react';
import type { GlobalConfigProvider } from 'tdesign-react';
import enConfig from 'tdesign-react/es/locale/en_US';

export default function configDemo() {
// 全局特性配置,可以引入英文默认配置 enConfig,还可以在默认配置的基础上进行自定义配置
const globalConfig = merge(enConfig, {
const globalConfig: GlobalConfigProvider = {
...enConfig,
datePicker: {
placeholder: {
date: 'select date',
Expand All @@ -21,7 +22,7 @@ export default function configDemo() {
selectTime: 'Select Time',
selectDate: 'Select Date',
},
});
};

return (
<ConfigProvider globalConfig={globalConfig}>
Expand Down
7 changes: 4 additions & 3 deletions packages/components/config-provider/_example/dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { merge } from 'lodash-es';
import { ConfigProvider, DialogCard, Space } from 'tdesign-react';
import type { GlobalConfigProvider } from 'tdesign-react';
import enConfig from 'tdesign-react/es/locale/en_US';

export default function configDemo() {
// 全局特性配置,可以引入英文默认配置 enConfig,还可以在默认配置的基础上进行自定义配置
const globalConfig = merge(enConfig, {
const globalConfig: GlobalConfigProvider = {
...enConfig,
dialog: {
confirm: 'confirm',
cancel: 'cancel',
Expand All @@ -17,7 +18,7 @@ export default function configDemo() {
success: 'success',
},
},
});
};

return (
<ConfigProvider globalConfig={globalConfig}>
Expand Down
7 changes: 4 additions & 3 deletions packages/components/config-provider/_example/global.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/* eslint-disable react/no-unescaped-entities */
import React from 'react';
import { merge } from 'lodash-es';
import { ConfigProvider, Space } from 'tdesign-react';
import type { GlobalConfigProvider } from 'tdesign-react';
import enConfig from 'tdesign-react/es/locale/en_US';

export default function GlobalDemo() {
// 全局特性配置,引入英文语言配置包 enConfig
const globalConfig = merge(enConfig, {
const globalConfig: GlobalConfigProvider = {
...enConfig,
// 可以在此处定义更多自定义配置,具体可配置内容参看 API 文档
calendar: {},
table: {},
pagination: {},
// 全局动画设置
animation: { exclude: [] },
});
};

return (
<ConfigProvider globalConfig={globalConfig}>
Expand Down
3 changes: 2 additions & 1 deletion packages/components/config-provider/_example/input.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { ConfigProvider, Input } from 'tdesign-react';
import type { GlobalConfigProvider } from 'tdesign-react';
import enConfig from 'tdesign-react/es/locale/en_US';

export default function configDemo() {
// 全局特性配置,可以引入英文默认配置 enConfig,还可以在默认配置的基础上进行自定义配置
const globalConfig = {
const globalConfig: GlobalConfigProvider = {
...enConfig,
input: {
clearTrigger: 'always',
Expand Down
8 changes: 4 additions & 4 deletions packages/components/config-provider/_example/others.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { merge } from 'lodash-es';
import {
ConfigProvider,
Form,
Expand All @@ -14,13 +13,14 @@ import {
Space,
Image,
} from 'tdesign-react';
import type { ImageProps } from 'tdesign-react';
import type { ImageProps, GlobalConfigProvider } from 'tdesign-react';
import { ChevronRightIcon, CloseIcon, CloseCircleIcon, ErrorIcon } from 'tdesign-icons-react';
import enConfig from 'tdesign-react/es/locale/en_US';

export default function configDemo() {
// 全局特性配置,可以引入英文默认配置 enConfig,还可以在默认配置的基础上进行自定义配置
const globalConfig = merge(enConfig, {
const globalConfig: GlobalConfigProvider = {
...enConfig,
image: {
// 全局替换图片地址
replaceImageSrc(params: ImageProps) {
Expand Down Expand Up @@ -67,7 +67,7 @@ export default function configDemo() {
steps: {
errorIcon: <ErrorIcon />,
},
});
};

return (
<ConfigProvider globalConfig={globalConfig}>
Expand Down
7 changes: 4 additions & 3 deletions packages/components/config-provider/_example/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React from 'react';
import { merge } from 'lodash-es';
import { ConfigProvider, Pagination } from 'tdesign-react';
import type { GlobalConfigProvider } from 'tdesign-react';
import enConfig from 'tdesign-react/es/locale/en_US';

export default function configDemo() {
// 全局特性配置,可以引入英文默认配置 enConfig,还可以在默认配置的基础上进行自定义配置
const globalConfig = merge(enConfig, {
const globalConfig: GlobalConfigProvider = {
...enConfig,
pagination: {
itemsPerPage: '{size} / page',
jumpTo: 'jump to',
total: 'Total {total} items',
},
});
};

return (
<ConfigProvider globalConfig={globalConfig}>
Expand Down
7 changes: 4 additions & 3 deletions packages/components/config-provider/_example/popconfirm.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { merge } from 'lodash-es';
import { ConfigProvider, Popconfirm, Button, Space } from 'tdesign-react';
import type { GlobalConfigProvider } from 'tdesign-react';
import enConfig from 'tdesign-react/es/locale/en_US';

export default function configDemo() {
// 全局特性配置,可以引入英文默认配置 enConfig,还可以在默认配置的基础上进行自定义配置
const globalConfig = merge(enConfig, {
const globalConfig: GlobalConfigProvider = {
...enConfig,
popconfirm: {
confirmBtnTheme: {
default: 'primary',
Expand All @@ -19,7 +20,7 @@ export default function configDemo() {
content: 'Cancel',
},
},
});
};

return (
<ConfigProvider globalConfig={globalConfig}>
Expand Down
7 changes: 4 additions & 3 deletions packages/components/config-provider/_example/table.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { merge } from 'lodash-es';
import { ConfigProvider, Table, Space } from 'tdesign-react';
import type { GlobalConfigProvider } from 'tdesign-react';
import { ChevronRightIcon, CaretDownSmallIcon } from 'tdesign-icons-react';
import enConfig from 'tdesign-react/es/locale/en_US';

Expand Down Expand Up @@ -35,7 +35,8 @@ const data = [

export default function configDemo() {
// 全局特性配置,可以引入英文默认配置 enConfig,还可以在默认配置的基础上进行自定义配置
const globalConfig = merge(enConfig, {
const globalConfig: GlobalConfigProvider = {
...enConfig,
table: {
// 支持 String 和 Function 两种数据类型
empty: 'Empty Data',
Expand All @@ -52,7 +53,7 @@ export default function configDemo() {
// sortDescendingOperationText: 'descending sort',
// treeExpandAndFoldIcon: (h, { type }) => type === 'expand' ? <ChevronRightIcon /> : <ChevronDownIcon />,
},
});
};

return (
<ConfigProvider globalConfig={globalConfig}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fillWithZero | Boolean | true | \- | N
firstDayOfWeek | Number | 1 | options: 1/2/3/4/5/6/7 | N
hideWeekend | String | - | \- | N
monthRadio | String | - | \- | N
monthSelection | String | - | \- | N
monthSelection | String / Function | - | Typescript:`string \| (( data: { month: number })=>string)` | N
showWeekend | String | - | \- | N
thisMonth | String | - | \- | N
today | String | - | \- | N
Expand Down
2 changes: 1 addition & 1 deletion packages/components/config-provider/config-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fillWithZero | Boolean | true | 当日期数字小于 10 时,是否使用 '0'
firstDayOfWeek | Number | 1 | 第一天从星期几开始。可选项:1/2/3/4/5/6/7 | N
hideWeekend | String | - | 语言配置,“隐藏周末”描述文本 | N
monthRadio | String | - | 语言配置,模式切换时的“月”描述文本 | N
monthSelection | String | - | 语言配置,\"月\"选择描述文本。示例:`'{month} 月'` | N
monthSelection | String / Function | - | 语言配置,“月”选择描述文本。示例:`'{month} 月'`。TS 类型:`string \| (( data: { month: number })=>string)` | N
showWeekend | String | - | 语言配置,“显示周末”描述文本 | N
thisMonth | String | - | 语言配置,“本月”描述文本 | N
today | String | - | 语言配置,“今天”描述文本 | N
Expand Down
1 change: 1 addition & 0 deletions packages/components/config-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ConfigContext from './ConfigContext';

export type { Config, Locale } from './ConfigContext';
export type { ConfigProviderProps } from './ConfigProvider';
export * from './type';

export { ConfigContext, ConfigProvider, merge };
export default ConfigProvider;
2 changes: 1 addition & 1 deletion packages/components/config-provider/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export interface CalendarConfig {
* 语言配置,\"月\"选择描述文本。示例:`'{month} 月'`
* @default ''
*/
monthSelection?: string;
monthSelection?: string | ((data: { month: number }) => string);
/**
* 语言配置,“显示周末”描述文本
* @default ''
Expand Down
Loading