From a28a693766740bad7a4dca22720f6604f2d8ad48 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 20 Nov 2023 12:03:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90tooltip=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 4 ++-- src/tooltip/index.js | 29 +++++++++++++---------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Readme.md b/Readme.md index 39dc69e..bafce41 100644 --- a/Readme.md +++ b/Readme.md @@ -16,7 +16,7 @@ - wkit 针对`web components`的核心封装库, 以数据驱动, 可以更方便的开发 wc 组件 -### 开发进度 && 计划 (42/56) +### 开发进度 && 计划 (43/56) - [x] `wc-card` 卡片组件 - [x] `wc-space` 间隔组件 @@ -66,7 +66,7 @@ - [x] `wc-timeline` 时间线组件 - [ ] `wc-layout` 布局组件 - [x] `wc-tag` 标签组件 -- [ ] `wc-tooltip` 文字提示组件 +- [x] `wc-tooltip` 文字提示组件 - [x] `wc-popconfirm` 气泡确认框组件 - [ ] `wc-chatbubble` 聊天气泡组件 - [x] `wc-divider` 分割线组件 diff --git a/src/tooltip/index.js b/src/tooltip/index.js index 65e1b41..5c53134 100644 --- a/src/tooltip/index.js +++ b/src/tooltip/index.js @@ -48,12 +48,14 @@ class Tooltip extends Component { background: var(--wc-tooltip-background, #fff); content: ''; transform: rotate(45deg); + box-shadow: -1px -1px 0 var(--wc-tooltip-shadow, rgba(0, 0, 0, 0.1)); } &[placement='left-top'] { &::after { right: 16px; bottom: -4px; + box-shadow: 1px 1px 0 var(--wc-tooltip-shadow, rgba(0, 0, 0, 0.1)); } } &[placement='left-bottom'] { @@ -66,6 +68,7 @@ class Tooltip extends Component { &::after { left: 16px; bottom: -4px; + box-shadow: 1px 1px 0 var(--wc-tooltip-shadow, rgba(0, 0, 0, 0.1)); } } &[placement='right-bottom'] { @@ -79,49 +82,43 @@ class Tooltip extends Component { ] mounted() { - console.log(this.clientWidth, this.offsetHeight) bind(this.$refs.wrap, 'mouseenter', ev => { - console.log(ev.pageX, ev.pageY) let { left, top } = offset(this) let placement = 'left' let styles = { display: 'block' } - if (left < 200 || left + this.clientWidth < 360) { + if (left < 360 || (left > 360 && window.innerWidth - left > 360)) { placement = 'right' styles.left = left + 'px' } else { let right = window.innerWidth - left - this.clientWidth - console.log('right: ', right) - styles.right = right + 'px' } - top += 8 + this.clientHeight - if (top < 100) { + if (top < 96) { + top += 8 + this.clientHeight placement += '-bottom' styles.top = top + 'px' } else { - // top -= 8 + let bottom = window.innerHeight - top + 8 placement += '-top' - styles.bottom = top + 'px' + styles.bottom = bottom + 'px' } - console.log(placement) // this.$refs.tips.setAttribute('placement', placement) this.$refs.tips.style.cssText = styleMap(styles) + this.$refs.tips.$animate() }) bind(this.$refs.wrap, 'mouseleave', ev => { - console.log(ev.pageX, ev.pageY) - // - this.$refs.tips.style.cssText = styleMap({ display: 'none' }) + this.$refs.tips.$animate(true) }) } render() { return html` -
-
-
+
+
+
${this.title}