Skip to content
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

fix: can't transfer configProvider in the content of Modal/Message/No… #1642

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions components/ConfigProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { lighten } from './util';
import Message from '../Message';
import Notification from '../Notification';
import Empty from '../Empty';
import { setConfigProviderProps } from '../Modal/config';
import { setConfigProviderProps } from '../_util/transferConfigProvider';
import { IconContext } from '../../icon/react-icon/context';
import { ConfigProviderProps } from './interface';
import omit from '../_util/omit';
Expand Down Expand Up @@ -87,7 +87,7 @@ export const ConfigContext = createContext<ConfigProviderProps>({

function ConfigProvider(baseProps: ConfigProviderProps) {
const props = useMergeProps<ConfigProviderProps>(baseProps, defaultProps, componentConfig);
const { theme, prefixCls, children, locale, rtl, effectGlobalNotice = true } = props;
const { theme, prefixCls, children, rtl, effectGlobalNotice = true } = props;

useEffect(() => {
setTheme(theme);
Expand All @@ -110,8 +110,11 @@ function ConfigProvider(baseProps: ConfigProviderProps) {
};

useEffect(() => {
setConfigProviderProps({ locale, prefixCls, rtl });
}, [locale, prefixCls]);
// If the internal components are manually wrapped, there is no need to reset
if (!props._inLoop) {
setConfigProviderProps(config);
}
}, [config]);

let child = children;

Expand Down
1 change: 1 addition & 0 deletions components/ConfigProvider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,5 @@ export interface ConfigProviderProps {
effectGlobalNotice?: boolean;
zIndex?: number;
children?: ReactNode;
_inLoop?: boolean;
}
22 changes: 14 additions & 8 deletions components/Message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import Notice from '../_class/notice';
import cs from '../_util/classNames';
import { MessageProps } from './interface';
import { isUndefined } from '../_util/is';
import { getConfigProviderProps } from '../_util/transferConfigProvider';
import useMessage, { messageFuncType } from './useMessage';
import { ConfigProvider } from '..';

const messageTypes = ['info', 'success', 'error', 'warning', 'loading', 'normal'];
let messageInstance: object = {};
Expand Down Expand Up @@ -140,6 +142,8 @@ class Message extends BaseNotification {
const mergedRtl = !isUndefined(_rtl) ? _rtl : rtl;
const prefixClsMessage = mergedPrefixCls ? `${mergedPrefixCls}-message` : 'arco-message';
const classNames = cs(`${prefixClsMessage}-wrapper`, `${prefixClsMessage}-wrapper-${position}`);
const configProviderProps = getConfigProviderProps();

return (
<div className={classNames}>
<TransitionGroup component={null}>
Expand All @@ -162,14 +166,16 @@ class Message extends BaseNotification {
notice.onClose && notice.onClose();
}}
>
<Notice
{...notice}
prefixCls={prefixClsMessage}
iconPrefix={mergedPrefixCls}
onClose={this.remove}
noticeType="message"
rtl={mergedRtl}
/>
<ConfigProvider {...configProviderProps} _inLoop>
<Notice
{...notice}
prefixCls={prefixClsMessage}
iconPrefix={mergedPrefixCls}
onClose={this.remove}
noticeType="message"
rtl={mergedRtl}
/>
</ConfigProvider>
</CSSTransition>
))}
</TransitionGroup>
Expand Down
14 changes: 0 additions & 14 deletions components/Modal/config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
import type { ConfigProviderProps } from '../ConfigProvider';

let configProvider = {} as ConfigProviderProps;

export function setConfigProviderProps(configProviderProps: ConfigProviderProps) {
configProvider = {
...configProviderProps,
};
}

export function getConfigProviderProps() {
return configProvider;
}

export type ModalConfigType = {
prefixCls?: string;
simple?: boolean;
Expand Down
5 changes: 3 additions & 2 deletions components/Modal/confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import IconInfoCircleFill from '../../icon/react-icon/IconInfoCircleFill';
import IconCheckCircleFill from '../../icon/react-icon/IconCheckCircleFill';
import IconExclamationCircleFill from '../../icon/react-icon/IconExclamationCircleFill';
import IconCloseCircleFill from '../../icon/react-icon/IconCloseCircleFill';
import { getModalConfig, destroyList, getConfigProviderProps } from './config';
import { getModalConfig, destroyList } from './config';
import { getConfigProviderProps } from '../_util/transferConfigProvider';
import ConfigProvider from '../ConfigProvider';

export interface ConfirmProps extends ModalProps {
Expand Down Expand Up @@ -74,7 +75,7 @@ function confirm(config: ConfirmProps, renderFunc?: (props: ConfirmProps) => voi

function render(props: ConfirmProps) {
const dom = (
<ConfigProvider {...configProviderProps}>
<ConfigProvider {...configProviderProps} _inLoop>
<ConfirmModal {...props} onCancel={onCancel} />
</ConfigProvider>
);
Expand Down
22 changes: 14 additions & 8 deletions components/Notification/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import cs from '../_util/classNames';
import { isNumber, isUndefined } from '../_util/is';
import { NotificationProps } from './interface';
import useNotification, { notificationFuncType } from './useNotification';
import { getConfigProviderProps } from '../_util/transferConfigProvider';
import { ConfigProvider } from '..';

const notificationTypes = ['info', 'success', 'error', 'warning', 'normal'];
let notificationInstance: object = {};
Expand Down Expand Up @@ -148,6 +150,8 @@ class Notification extends BaseNotification {
{ [`${prefixClsNotification}-wrapper-rtl`]: rtl }
);

const configProviderProps = getConfigProviderProps();

return (
<div className={classNames}>
<TransitionGroup component={null}>
Expand All @@ -170,14 +174,16 @@ class Notification extends BaseNotification {
notice.onClose && notice.onClose();
}}
>
<Notice
{...notice}
onClose={this.remove}
prefixCls={prefixClsNotification}
iconPrefix={mergedPrefixCls}
noticeType="notification"
rtl={mergedRtl}
/>
<ConfigProvider {...configProviderProps} _inLoop>
<Notice
{...notice}
onClose={this.remove}
prefixCls={prefixClsNotification}
iconPrefix={mergedPrefixCls}
noticeType="notification"
rtl={mergedRtl}
/>
</ConfigProvider>
</CSSTransition>
))}
</TransitionGroup>
Expand Down
13 changes: 13 additions & 0 deletions components/_util/transferConfigProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { ConfigProviderProps } from '../ConfigProvider';

let configProvider = {} as ConfigProviderProps;

export function setConfigProviderProps(configProviderProps: ConfigProviderProps) {
configProvider = {
...configProviderProps,
};
}

export function getConfigProviderProps() {
return configProvider;
}