mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-12 20:43:11 +08:00
refactor: use React.useContext replace ConfigConsumer (#41184)
* chore: use React.useContext replace ConfigConsumer * fix
This commit is contained in:
parent
2f02fe01f0
commit
669e58c380
@ -1,7 +1,6 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import type { ConfigConsumerProps } from '../config-provider';
|
import { ConfigContext } from '../config-provider';
|
||||||
import { ConfigConsumer } from '../config-provider';
|
|
||||||
import warning from '../_util/warning';
|
import warning from '../_util/warning';
|
||||||
import type { AntAnchor } from './Anchor';
|
import type { AntAnchor } from './Anchor';
|
||||||
import AnchorContext from './context';
|
import AnchorContext from './context';
|
||||||
@ -46,33 +45,33 @@ const AnchorLink: React.FC<AnchorLinkProps> = (props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
||||||
|
|
||||||
|
const prefixCls = getPrefixCls('anchor', customizePrefixCls);
|
||||||
|
|
||||||
|
const active = activeLink === href;
|
||||||
|
|
||||||
|
const wrapperClassName = classNames(`${prefixCls}-link`, className, {
|
||||||
|
[`${prefixCls}-link-active`]: active,
|
||||||
|
});
|
||||||
|
|
||||||
|
const titleClassName = classNames(`${prefixCls}-link-title`, {
|
||||||
|
[`${prefixCls}-link-title-active`]: active,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfigConsumer>
|
<div className={wrapperClassName}>
|
||||||
{({ getPrefixCls }: ConfigConsumerProps) => {
|
<a
|
||||||
const prefixCls = getPrefixCls('anchor', customizePrefixCls);
|
className={titleClassName}
|
||||||
const active = activeLink === href;
|
href={href}
|
||||||
const wrapperClassName = classNames(`${prefixCls}-link`, className, {
|
title={typeof title === 'string' ? title : ''}
|
||||||
[`${prefixCls}-link-active`]: active,
|
target={target}
|
||||||
});
|
onClick={handleClick}
|
||||||
const titleClassName = classNames(`${prefixCls}-link-title`, {
|
>
|
||||||
[`${prefixCls}-link-title-active`]: active,
|
{title}
|
||||||
});
|
</a>
|
||||||
return (
|
{direction !== 'horizontal' ? children : null}
|
||||||
<div className={wrapperClassName}>
|
</div>
|
||||||
<a
|
|
||||||
className={titleClassName}
|
|
||||||
href={href}
|
|
||||||
title={typeof title === 'string' ? title : ''}
|
|
||||||
target={target}
|
|
||||||
onClick={handleClick}
|
|
||||||
>
|
|
||||||
{title}
|
|
||||||
</a>
|
|
||||||
{direction !== 'horizontal' ? children : null}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
</ConfigConsumer>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user