From 85c48c0566c755adce803fa46f0b24e851a46cde Mon Sep 17 00:00:00 2001 From: Carl Chen <71313168+cc-hearts@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:17:15 +0800 Subject: [PATCH] feat[tooltip]: add `arrow` attribute (#7459) * docs: updating the `dropdownRender` description and jumps in the FAQ for Select * wip: add popover-arrow * wip: trigger add arrow attr * fix: remove popupContextKey * optimize * perf: optimize * docs: optimize docs * docs: add `arrow` attribute in tooltip en-US docs * fix: fix bug * perf[demo]: `radio-group` replace with `segmented` --- components/style/placementArrow.ts | 16 ++- components/tooltip/Tooltip.tsx | 10 +- components/tooltip/abstractTooltipProps.ts | 5 + components/tooltip/demo/arrow.vue | 143 +++++++++++++++++++++ components/tooltip/demo/index.vue | 3 + components/tooltip/index.en-US.md | 1 + components/tooltip/index.zh-CN.md | 1 + components/vc-tooltip/src/Tooltip.tsx | 12 +- components/vc-tour/Tour.tsx | 1 + components/vc-trigger/Popup/PopupInner.tsx | 8 +- components/vc-trigger/Popup/interface.ts | 2 + components/vc-trigger/Trigger.tsx | 2 + components/vc-trigger/interface.ts | 1 + 13 files changed, 195 insertions(+), 10 deletions(-) create mode 100644 components/tooltip/demo/arrow.vue diff --git a/components/style/placementArrow.ts b/components/style/placementArrow.ts index 5af5bbe78..152b329f5 100644 --- a/components/style/placementArrow.ts +++ b/components/style/placementArrow.ts @@ -209,7 +209,9 @@ export default function getArrowStyle>>>> Top [connectArrowCls( - [`&-placement-topLeft`, `&-placement-top`, `&-placement-topRight`], + [`&-placement-topLeft`, `&-placement-top`, `&-placement-topRight`].map( + cls => (cls += ':not(&-arrow-hidden)'), + ), showArrowCls, )]: { paddingBottom: dropdownArrowDistance, @@ -217,7 +219,9 @@ export default function getArrowStyle>>>> Bottom [connectArrowCls( - [`&-placement-bottomLeft`, `&-placement-bottom`, `&-placement-bottomRight`], + [`&-placement-bottomLeft`, `&-placement-bottom`, `&-placement-bottomRight`].map( + cls => (cls += ':not(&-arrow-hidden)'), + ), showArrowCls, )]: { paddingTop: dropdownArrowDistance, @@ -225,7 +229,9 @@ export default function getArrowStyle>>>> Left [connectArrowCls( - [`&-placement-leftTop`, `&-placement-left`, `&-placement-leftBottom`], + [`&-placement-leftTop`, `&-placement-left`, `&-placement-leftBottom`].map( + cls => (cls += ':not(&-arrow-hidden)'), + ), showArrowCls, )]: { paddingRight: { @@ -236,7 +242,9 @@ export default function getArrowStyle>>>> Right [connectArrowCls( - [`&-placement-rightTop`, `&-placement-right`, `&-placement-rightBottom`], + [`&-placement-rightTop`, `&-placement-right`, `&-placement-rightBottom`].map( + cls => (cls += ':not(&-arrow-hidden)'), + ), showArrowCls, )]: { paddingLeft: { diff --git a/components/tooltip/Tooltip.tsx b/components/tooltip/Tooltip.tsx index 0a9902afb..65d6203e4 100644 --- a/components/tooltip/Tooltip.tsx +++ b/components/tooltip/Tooltip.tsx @@ -145,11 +145,16 @@ export default defineComponent({ }); const tooltipPlacements = computed(() => { - const { builtinPlacements, arrowPointAtCenter, autoAdjustOverflow } = props; + const { builtinPlacements, autoAdjustOverflow, arrow, arrowPointAtCenter } = props; + let mergedArrowPointAtCenter = arrowPointAtCenter; + + if (typeof arrow === 'object') { + mergedArrowPointAtCenter = arrow.pointAtCenter ?? arrowPointAtCenter; + } return ( builtinPlacements || getPlacements({ - arrowPointAtCenter, + arrowPointAtCenter: mergedArrowPointAtCenter, autoAdjustOverflow, }) ); @@ -283,6 +288,7 @@ export default defineComponent({ ...attrs, ...(props as TooltipProps), prefixCls: prefixCls.value, + arrow: !!props.arrow, getPopupContainer: getPopupContainer?.value, builtinPlacements: tooltipPlacements.value, visible: tempVisible, diff --git a/components/tooltip/abstractTooltipProps.ts b/components/tooltip/abstractTooltipProps.ts index 489829de4..a3f142db1 100644 --- a/components/tooltip/abstractTooltipProps.ts +++ b/components/tooltip/abstractTooltipProps.ts @@ -35,7 +35,12 @@ export default () => ({ mouseEnterDelay: Number, mouseLeaveDelay: Number, getPopupContainer: Function as PropType<(triggerNode: HTMLElement) => HTMLElement>, + /**@deprecated Please use `arrow={{ pointAtCenter: true }}` instead. */ arrowPointAtCenter: { type: Boolean, default: undefined }, + arrow: { + type: [Boolean, Object] as PropType, + default: true as boolean | { pointAtCenter?: boolean }, + }, autoAdjustOverflow: { type: [Boolean, Object] as PropType, default: undefined as boolean | AdjustOverflow, diff --git a/components/tooltip/demo/arrow.vue b/components/tooltip/demo/arrow.vue new file mode 100644 index 000000000..3fe3f25d5 --- /dev/null +++ b/components/tooltip/demo/arrow.vue @@ -0,0 +1,143 @@ + +--- +order: 6 +title: + zh-CN: 箭头展示 + en-US: Arrow show +--- + +## zh-CN +支持显示、隐藏以及将箭头保持居中定位。 + +## en-US + +Support show, hide or keep arrow in the center. + + + + + diff --git a/components/tooltip/demo/index.vue b/components/tooltip/demo/index.vue index 60fb98dd3..ac227a9be 100644 --- a/components/tooltip/demo/index.vue +++ b/components/tooltip/demo/index.vue @@ -5,6 +5,7 @@ +