Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ ToolTip 组件 offset 属性支持数组和对象写法 #625

Merged
merged 2 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/component/tooltip.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const control = () => {
| placement | Tooltip 的出现位置 | string | top / top-start / top-end / bottom / bottom-start / bottom-end / left / left-start / left-end / right / right-start / right-end | bottom | - |
| disabled | Tooltip 是否可用 | boolean | - | false | - |
| visible-arrow | 是否显示 Tooltip 箭头 | boolean | - | true | - |
| offset | 出现位置的偏移量 | number | - | 0 | - |
| offset | 出现位置的偏移量 | number | number[] | {x:0, y:0} | - | 0 | $LOWEST_VERSION$ |
| show-close | 是否显示 Tooltip 内部的关闭按钮 | boolean | - | false | - |

## Events
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCurrentInstance, ref } from 'vue'
import { getRect } from '../common/util'
import { getRect, isObj } from '../common/util'

export function usePopover() {
const { proxy } = getCurrentInstance() as any
Expand Down Expand Up @@ -77,7 +77,7 @@ export function usePopover() {
| 'right'
| 'right-start'
| 'right-end',
offset: number
offset: number | number[] | Record<'x' | 'y', number>
) {
// arrow size
const arrowSize = 9
Expand All @@ -90,8 +90,20 @@ export function usePopover() {
// 左右位(横轴)对应的距离底部的距离
const horizontalY = height.value / 2

const offsetX = (verticalX - 17 > 0 ? 0 : verticalX - 25) + offset
const offsetY = (horizontalY - 17 > 0 ? 0 : horizontalY - 25) + offset
let offsetX = 0
let offsetY = 0
if (Array.isArray(offset)) {
offsetX = (verticalX - 17 > 0 ? 0 : verticalX - 25) + offset[0]
offsetY = (horizontalY - 17 > 0 ? 0 : horizontalY - 25) + (offset[1] ? offset[1] : offset[0])
} else if (isObj(offset)) {
offsetX = (verticalX - 17 > 0 ? 0 : verticalX - 25) + offset.x
offsetY = (horizontalY - 17 > 0 ? 0 : horizontalY - 25) + offset.y
} else {
offsetX = (verticalX - 17 > 0 ? 0 : verticalX - 25) + offset
offsetY = (horizontalY - 17 > 0 ? 0 : horizontalY - 25) + offset
}
// const offsetX = (verticalX - 17 > 0 ? 0 : verticalX - 25) + offset
// const offsetY = (horizontalY - 17 > 0 ? 0 : horizontalY - 25) + offset

const placements = new Map([
// 上
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export const tooltipProps = {
* 类型:number
* 默认值:0
*/
offset: makeNumberProp(0),
// offset: makeNumberProp(0),
offset: {
// 需要支持数字、数组、对象类型
type: [Number, Array, Object] as PropType<number | Array<number> | Record<'x' | 'y', number>>,
default: 0
},

/**
* 是否使用slot来传入content内容
Expand Down