|
|
|
@ -13,9 +13,10 @@ import { composeRef } from 'rc-util/lib/ref';
|
|
|
|
|
import * as React from 'react';
|
|
|
|
|
import { ConfigContext } from '../../config-provider';
|
|
|
|
|
import { useLocaleReceiver } from '../../locale-provider/LocaleReceiver';
|
|
|
|
|
import Tooltip from '../../tooltip';
|
|
|
|
|
import { isStyleSupport } from '../../_util/styleChecker';
|
|
|
|
|
import TransButton from '../../_util/transButton';
|
|
|
|
|
import { isStyleSupport } from '../../_util/styleChecker';
|
|
|
|
|
import type { TooltipProps } from '../../tooltip';
|
|
|
|
|
import Tooltip from '../../tooltip';
|
|
|
|
|
import Editable from '../Editable';
|
|
|
|
|
import useMergedConfig from '../hooks/useMergedConfig';
|
|
|
|
|
import useUpdatedEffect from '../hooks/useUpdatedEffect';
|
|
|
|
@ -55,7 +56,7 @@ export interface EllipsisConfig {
|
|
|
|
|
symbol?: React.ReactNode;
|
|
|
|
|
onExpand?: React.MouseEventHandler<HTMLElement>;
|
|
|
|
|
onEllipsis?: (ellipsis: boolean) => void;
|
|
|
|
|
tooltip?: React.ReactNode;
|
|
|
|
|
tooltip?: React.ReactNode | TooltipProps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface BlockProps extends TypographyProps {
|
|
|
|
@ -309,7 +310,16 @@ const Base = React.forwardRef((props: InternalBlockProps, ref: any) => {
|
|
|
|
|
}, [enableEllipsis, cssEllipsis, children, cssLineClamp]);
|
|
|
|
|
|
|
|
|
|
// ========================== Tooltip ===========================
|
|
|
|
|
const tooltipTitle = ellipsisConfig.tooltip === true ? children : ellipsisConfig.tooltip;
|
|
|
|
|
let tooltipProps: TooltipProps = {};
|
|
|
|
|
if (ellipsisConfig.tooltip === true) {
|
|
|
|
|
tooltipProps = { title: children };
|
|
|
|
|
} else if (React.isValidElement(ellipsisConfig.tooltip)) {
|
|
|
|
|
tooltipProps = { title: ellipsisConfig.tooltip };
|
|
|
|
|
} else if (typeof ellipsisConfig.tooltip === 'object') {
|
|
|
|
|
tooltipProps = { title: children, ...ellipsisConfig.tooltip };
|
|
|
|
|
} else {
|
|
|
|
|
tooltipProps = { title: ellipsisConfig.tooltip };
|
|
|
|
|
}
|
|
|
|
|
const topAriaLabel = React.useMemo(() => {
|
|
|
|
|
const isValid = (val: any) => ['string', 'number'].includes(typeof val);
|
|
|
|
|
|
|
|
|
@ -325,12 +335,12 @@ const Base = React.forwardRef((props: InternalBlockProps, ref: any) => {
|
|
|
|
|
return title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isValid(tooltipTitle)) {
|
|
|
|
|
return tooltipTitle;
|
|
|
|
|
if (isValid(tooltipProps.title)) {
|
|
|
|
|
return tooltipProps.title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
|
}, [enableEllipsis, cssEllipsis, title, tooltipTitle, isMergedEllipsis]);
|
|
|
|
|
}, [enableEllipsis, cssEllipsis, title, tooltipProps.title, isMergedEllipsis]);
|
|
|
|
|
|
|
|
|
|
// =========================== Render ===========================
|
|
|
|
|
// >>>>>>>>>>> Editing input
|
|
|
|
@ -452,7 +462,7 @@ const Base = React.forwardRef((props: InternalBlockProps, ref: any) => {
|
|
|
|
|
<ResizeObserver onResize={onResize} disabled={!mergedEnableEllipsis || cssEllipsis}>
|
|
|
|
|
{resizeRef => (
|
|
|
|
|
<EllipsisTooltip
|
|
|
|
|
title={tooltipTitle}
|
|
|
|
|
tooltipProps={tooltipProps}
|
|
|
|
|
enabledEllipsis={mergedEnableEllipsis}
|
|
|
|
|
isEllipsis={isMergedEllipsis}
|
|
|
|
|
>
|
|
|
|
|