mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-14 22:11:02 +08:00

* feat: ConfigProvider support arrow for tooltip/popover/popconfirm * update mergedhook * add test * improve hooks * improve
29 lines
866 B
TypeScript
29 lines
866 B
TypeScript
import React from 'react';
|
|
|
|
import { AbstractTooltipProps } from '..';
|
|
import { TooltipConfig } from '../../config-provider/context';
|
|
|
|
interface MergedArrow {
|
|
show: boolean;
|
|
pointAtCenter?: boolean;
|
|
}
|
|
const useMergedArrow = (
|
|
providedArrow?: AbstractTooltipProps['arrow'],
|
|
providedContextArrow?: TooltipConfig['arrow'],
|
|
): MergedArrow => {
|
|
const toConfig = (arrow?: boolean | AbstractTooltipProps['arrow']): Partial<MergedArrow> =>
|
|
typeof arrow === 'boolean' ? { show: arrow } : arrow || {};
|
|
|
|
return React.useMemo(() => {
|
|
const arrowConfig = toConfig(providedArrow);
|
|
const contextArrowConfig = toConfig(providedContextArrow);
|
|
|
|
return {
|
|
...contextArrowConfig,
|
|
...arrowConfig,
|
|
show: arrowConfig.show ?? contextArrowConfig.show ?? true,
|
|
};
|
|
}, [providedArrow, providedContextArrow]);
|
|
};
|
|
export default useMergedArrow;
|