mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 14:13:37 +08:00
refactor: delete legacy function withConfigConsumer (#39798)
* chore: delete legacy function withConfigConsumer * fix * fix
This commit is contained in:
parent
7be364f3d9
commit
fa6c9c15f4
@ -81,42 +81,4 @@ export const ConfigContext = React.createContext<ConfigConsumerProps>({
|
||||
iconPrefixCls: defaultIconPrefixCls,
|
||||
});
|
||||
|
||||
export const ConfigConsumer = ConfigContext.Consumer;
|
||||
|
||||
// =========================== withConfigConsumer ===========================
|
||||
interface BasicExportProps {
|
||||
prefixCls?: string;
|
||||
}
|
||||
|
||||
interface ConsumerConfig {
|
||||
prefixCls: string;
|
||||
}
|
||||
|
||||
interface ConstructorProps {
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
/** @deprecated Use hooks instead. This is a legacy function */
|
||||
export function withConfigConsumer<ExportProps extends BasicExportProps>(config: ConsumerConfig) {
|
||||
return function withConfigConsumerFunc<ComponentDef>(
|
||||
Component: React.ComponentType<ExportProps>,
|
||||
): React.FC<ExportProps> & ComponentDef {
|
||||
// Wrap with ConfigConsumer. Since we need compatible with react 15, be careful when using ref methods
|
||||
const SFC: React.FC<ExportProps> & ComponentDef = ((props) => {
|
||||
const configProps = React.useContext<ConfigConsumerProps>(ConfigContext);
|
||||
const { getPrefixCls } = configProps;
|
||||
const { prefixCls: basicPrefixCls } = config;
|
||||
const { prefixCls: customizePrefixCls } = props;
|
||||
const prefixCls = getPrefixCls(basicPrefixCls, customizePrefixCls);
|
||||
return <Component {...configProps} {...props} prefixCls={prefixCls} />;
|
||||
}) as React.FC<ExportProps> & ComponentDef;
|
||||
|
||||
const cons: ConstructorProps = Component.constructor as ConstructorProps;
|
||||
const name = (cons && cons.displayName) || Component.name || 'Component';
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
SFC.displayName = `withConfigConsumer(${name})`;
|
||||
}
|
||||
return SFC;
|
||||
};
|
||||
}
|
||||
export const { Consumer: ConfigConsumer } = ConfigContext;
|
||||
|
@ -1,18 +1,12 @@
|
||||
import classNames from 'classnames';
|
||||
import * as React from 'react';
|
||||
|
||||
import type { ConfigConsumerProps } from '../config-provider';
|
||||
import { withConfigConsumer } from '../config-provider/context';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import Skeleton from '../skeleton';
|
||||
import type Countdown from './Countdown';
|
||||
import StatisticNumber from './Number';
|
||||
import type { FormatConfig, valueType } from './utils';
|
||||
|
||||
import useStyle from './style';
|
||||
|
||||
type CompoundedComponent = {
|
||||
Countdown: typeof Countdown;
|
||||
};
|
||||
import Countdown from './Countdown';
|
||||
|
||||
export interface StatisticProps extends FormatConfig {
|
||||
prefixCls?: string;
|
||||
@ -29,9 +23,13 @@ export interface StatisticProps extends FormatConfig {
|
||||
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
|
||||
}
|
||||
|
||||
const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = (props) => {
|
||||
type CompoundedComponent = {
|
||||
Countdown: typeof Countdown;
|
||||
};
|
||||
|
||||
const Statistic: React.FC<StatisticProps> & CompoundedComponent = (props) => {
|
||||
const {
|
||||
prefixCls,
|
||||
prefixCls: customizePrefixCls,
|
||||
className,
|
||||
style,
|
||||
valueStyle,
|
||||
@ -41,22 +39,28 @@ const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = (props) => {
|
||||
prefix,
|
||||
suffix,
|
||||
loading = false,
|
||||
direction,
|
||||
onMouseEnter,
|
||||
onMouseLeave,
|
||||
decimalSeparator = '.',
|
||||
groupSeparator = ',',
|
||||
} = props;
|
||||
const valueNode = (
|
||||
|
||||
const { getPrefixCls, direction } = React.useContext<ConfigConsumerProps>(ConfigContext);
|
||||
|
||||
const prefixCls = getPrefixCls('statistic', customizePrefixCls);
|
||||
|
||||
const [wrapSSR, hashId] = useStyle(prefixCls);
|
||||
|
||||
const valueNode: React.ReactNode = (
|
||||
<StatisticNumber
|
||||
decimalSeparator={decimalSeparator}
|
||||
groupSeparator={groupSeparator}
|
||||
prefixCls={prefixCls}
|
||||
{...props}
|
||||
value={value}
|
||||
/>
|
||||
);
|
||||
// Style
|
||||
const [wrapSSR, hashId] = useStyle(String(prefixCls));
|
||||
|
||||
const cls = classNames(
|
||||
prefixCls,
|
||||
{
|
||||
@ -65,6 +69,7 @@ const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = (props) => {
|
||||
className,
|
||||
hashId,
|
||||
);
|
||||
|
||||
return wrapSSR(
|
||||
<div className={cls} style={style} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
|
||||
{title && <div className={`${prefixCls}-title`}>{title}</div>}
|
||||
@ -79,8 +84,6 @@ const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
const WrapperStatistic = withConfigConsumer<StatisticProps>({
|
||||
prefixCls: 'statistic',
|
||||
})<CompoundedComponent>(Statistic);
|
||||
Statistic.Countdown = Countdown;
|
||||
|
||||
export default WrapperStatistic;
|
||||
export default Statistic;
|
||||
|
@ -1,8 +1,5 @@
|
||||
import Countdown from './Countdown';
|
||||
import Statistic, { type StatisticProps } from './Statistic';
|
||||
|
||||
Statistic.Countdown = Countdown;
|
||||
import Statistic from './Statistic';
|
||||
import type { StatisticProps } from './Statistic';
|
||||
|
||||
export type { StatisticProps };
|
||||
|
||||
export default Statistic;
|
||||
|
Loading…
Reference in New Issue
Block a user