feat: add tooltip aim-center and refine position demo

This commit is contained in:
Justineo 2021-10-18 16:51:32 +08:00
parent 5a45ce11aa
commit 87e976bb7e
No known key found for this signature in database
GPG Key ID: B73F0979CF18A0EA
4 changed files with 263 additions and 407 deletions

View File

@ -28,13 +28,14 @@
| -- | -- | -- | -- | | -- | -- | -- | -- |
| `ui` | `string=` | - | [^ui] | | `ui` | `string=` | - | [^ui] |
| `open` | `boolean` | `false` | [^open] | | `open` | `boolean` | `false` | [^open] |
| `target` | `string|Vue|Node` | - | 参考 [`Overlay`](./overlay) 组件的 `target` 属性。 | | `target` | `string | Vue | Node` | - | 参考 [`Overlay`](./overlay) 组件的 `target` 属性。 |
| `position` | `string` | `'top'` | [^position] | | `position` | `string` | `'top'` | [^position] |
| `aim-center` | `boolean` | `false` | 指定浮层提示箭头是否始终指向目标元素中心。 |
| `trigger` | `string` | `'hover'` | [^trigger] | | `trigger` | `string` | `'hover'` | [^trigger] |
| `interactive` | `boolean` | `true` | 浮层内容是否允许交互。如果为 `false` 则在 `target` 外满足 `trigger` 指定的条件浮层即自动关闭。 | | `interactive` | `boolean` | `true` | 浮层内容是否允许交互。如果为 `false` 则在 `target` 外满足 `trigger` 指定的条件浮层即自动关闭。 |
| `hide-delay` | `number` | `tooltip.hideDelays` | 触发关闭条件满足后延迟关闭等待时间的毫秒数。可以用来防止光标移出 `target` 后移入浮层进行交互前已经自动关闭。 | | `hide-delay` | `number` | `tooltip.hideDelays` | 触发关闭条件满足后延迟关闭等待时间的毫秒数。可以用来防止光标移出 `target` 后移入浮层进行交互前已经自动关闭。 |
| `overlay-class` | `string|Array|Object=` | - | 参考 [`Overlay`](./overlay) 组件的 [`overlay-class`](./overlay#属性) 属性。 | | `overlay-class` | `string | Array | Object=` | - | 参考 [`Overlay`](./overlay) 组件的 [`overlay-class`](./overlay#属性) 属性。 |
| `overlay-style` | `string|Array|Object=` | - | 参考 [`Overlay`](./overlay) 组件的 [`overlay-style`](./overlay#属性) 属性。 | | `overlay-style` | `string | Array | Object=` | - | 参考 [`Overlay`](./overlay) 组件的 [`overlay-style`](./overlay#属性) 属性。 |
^^^ui ^^^ui
预设样式。 预设样式。

View File

@ -1,224 +1,151 @@
<template> <template>
<article> <article>
<veui-grid-container :columns="5"> <section>
<veui-grid-row> <veui-checkbox
<veui-grid-column v-model="aimCenter"
:span="1" ui="s"
:offset="1" >
> Aim center
<span </veui-checkbox>
ref="ts" </section>
class="target" <section class="grid">
>top-start</span> <veui-popover
<veui-popover :open.sync="open"
target="ts" :target="target"
position="top-start" :position="position"
> :aim-center="aimCenter"
Hello. >
</veui-popover> Hello.
</veui-grid-column> </veui-popover>
<veui-grid-column :span="1"> <veui-button
<span ref="top-start"
ref="t" style="grid-area: 1 / 2"
class="target" @mouseenter="show('top-start')"
>top</span> >
<veui-popover top-start
target="t" </veui-button>
position="top" <veui-button
> ref="top"
Hello. style="grid-area: 1 / 3"
</veui-popover> @mouseenter="show('top')"
</veui-grid-column> >
<veui-grid-column :span="1"> top
<span </veui-button>
ref="te" <veui-button
class="target" ref="top-end"
>top-end</span> style="grid-area: 1 / 4"
<veui-popover @mouseenter="show('top-end')"
target="te" >
position="top-end" top-end
> </veui-button>
Hello. <veui-button
</veui-popover> ref="right-start"
</veui-grid-column> style="grid-area: 2 / 5"
</veui-grid-row> @mouseenter="show('right-start')"
<veui-grid-row> >
<veui-grid-column :span="1"> right-start
<span </veui-button>
ref="ls" <veui-button
class="target" ref="right"
>left-start</span> style="grid-area: 3 / 5"
<veui-popover @mouseenter="show('right')"
target="ls" >
position="left-start" right
> </veui-button>
Hello. <veui-button
</veui-popover> ref="right-end"
</veui-grid-column> style="grid-area: 4 / 5"
<veui-grid-column @mouseenter="show('right-end')"
:span="1" >
:offset="3" right-end
> </veui-button>
<span <veui-button
ref="rs" ref="bottom-start"
class="target" style="grid-area: 5 / 2"
>right-start</span> @mouseenter="show('bottom-start')"
<veui-popover >
target="rs" bottom-start
position="right-start" </veui-button>
> <veui-button
Hello. ref="bottom"
</veui-popover> style="grid-area: 5 / 3"
</veui-grid-column> @mouseenter="show('bottom')"
</veui-grid-row> >
<veui-grid-row> bottom
<veui-grid-column :span="1"> </veui-button>
<span <veui-button
ref="l" ref="bottom-end"
class="target" style="grid-area: 5 / 4"
>left</span> @mouseenter="show('bottom-end')"
<veui-popover >
target="l" bottom-end
position="left" </veui-button>
> <veui-button
Hello. ref="left-start"
</veui-popover> style="grid-area: 2 / 1"
</veui-grid-column> @mouseenter="show('left-start')"
<veui-grid-column >
:span="1" left-start
:offset="3" </veui-button>
> <veui-button
<span ref="left"
ref="r" style="grid-area: 3 / 1"
class="target" @mouseenter="show('left')"
>right</span> >
<veui-popover left
target="r" </veui-button>
position="right" <veui-button
> ref="left-end"
Hello. style="grid-area: 4 / 1"
</veui-popover> @mouseenter="show('left-end')"
</veui-grid-column> >
</veui-grid-row> left-end
<veui-grid-row> </veui-button>
<veui-grid-column :span="1"> </section>
<span
ref="le"
class="target"
>left-end</span>
<veui-popover
target="le"
position="left-end"
>
Hello.
</veui-popover>
</veui-grid-column>
<veui-grid-column
:span="1"
:offset="3"
>
<span
ref="re"
class="target"
>right-end</span>
<veui-popover
target="re"
position="right-end"
>
Hello.
</veui-popover>
</veui-grid-column>
</veui-grid-row>
<veui-grid-row>
<veui-grid-column
:span="1"
:offset="1"
>
<span
ref="bs"
class="target"
>bottom-start</span>
<veui-popover
target="bs"
position="bottom-start"
>
Hello.
</veui-popover>
</veui-grid-column>
<veui-grid-column :span="1">
<span
ref="b"
class="target"
>bottom</span>
<veui-popover
target="b"
position="bottom"
>
Hello.
</veui-popover>
</veui-grid-column>
<veui-grid-column :span="1">
<span
ref="be"
class="target"
>bottom-end</span>
<veui-popover
target="be"
position="bottom-end"
>
Hello.
</veui-popover>
</veui-grid-column>
</veui-grid-row>
</veui-grid-container>
</article> </article>
</template> </template>
<script> <script>
import { GridContainer, GridRow, GridColumn, Popover } from 'veui' import { Popover, Button, Checkbox } from 'veui'
export default { export default {
components: { components: {
'veui-grid-container': GridContainer, 'veui-popover': Popover,
'veui-grid-row': GridRow, 'veui-button': Button,
'veui-grid-column': GridColumn, 'veui-checkbox': Checkbox
'veui-popover': Popover
}, },
data () { data () {
return { return {
ui: null target: null,
position: null,
open: false,
aimCenter: false
}
},
methods: {
show (position) {
this.target = this.$refs[position]
this.position = position
this.open = true
} }
} }
} }
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.veui-grid-container { section + section {
width: 80%; margin-top: 20px;
min-width: 600px;
} }
.veui-grid-row { .grid {
margin-bottom: 20px; display: grid;
} grid-template-columns: auto auto auto auto auto;
grid-gap: 12px;
.veui-grid-column { justify-content: center;
text-align: center; align-items: center;
vertical-align: middle;
line-height: 2;
}
.target {
display: inline-block;
width: 100%;
padding: 0.5em 0;
border: 1px solid #999;
border-radius: 2px;
transition: background-color 0.3s;
cursor: pointer;
&:hover {
background-color: #f7f7f7;
}
} }
</style> </style>
<docs>
使用 `aim-center` 属性来设置浮层提示箭头始终对准目标元素中心适合用于目标元素较小的场景
</docs>

View File

@ -1,224 +1,151 @@
<template> <template>
<article> <article>
<veui-grid-container :columns="5"> <section>
<veui-grid-row> <veui-checkbox
<veui-grid-column v-model="aimCenter"
:span="1" ui="s"
:offset="1" >
> Aim center
<span </veui-checkbox>
ref="ts" </section>
class="target" <section class="grid">
>top-start</span> <veui-tooltip
<veui-tooltip :open.sync="open"
target="ts" :target="target"
position="top-start" :position="position"
> :aim-center="aimCenter"
Hello. >
</veui-tooltip> Hello.
</veui-grid-column> </veui-tooltip>
<veui-grid-column :span="1"> <veui-button
<span ref="top-start"
ref="t" style="grid-area: 1 / 2"
class="target" @mouseenter="show('top-start')"
>top</span> >
<veui-tooltip top-start
target="t" </veui-button>
position="top" <veui-button
> ref="top"
Hello. style="grid-area: 1 / 3"
</veui-tooltip> @mouseenter="show('top')"
</veui-grid-column> >
<veui-grid-column :span="1"> top
<span </veui-button>
ref="te" <veui-button
class="target" ref="top-end"
>top-end</span> style="grid-area: 1 / 4"
<veui-tooltip @mouseenter="show('top-end')"
target="te" >
position="top-end" top-end
> </veui-button>
Hello. <veui-button
</veui-tooltip> ref="right-start"
</veui-grid-column> style="grid-area: 2 / 5"
</veui-grid-row> @mouseenter="show('right-start')"
<veui-grid-row> >
<veui-grid-column :span="1"> right-start
<span </veui-button>
ref="ls" <veui-button
class="target" ref="right"
>left-start</span> style="grid-area: 3 / 5"
<veui-tooltip @mouseenter="show('right')"
target="ls" >
position="left-start" right
> </veui-button>
Hello. <veui-button
</veui-tooltip> ref="right-end"
</veui-grid-column> style="grid-area: 4 / 5"
<veui-grid-column @mouseenter="show('right-end')"
:span="1" >
:offset="3" right-end
> </veui-button>
<span <veui-button
ref="rs" ref="bottom-start"
class="target" style="grid-area: 5 / 2"
>right-start</span> @mouseenter="show('bottom-start')"
<veui-tooltip >
target="rs" bottom-start
position="right-start" </veui-button>
> <veui-button
Hello. ref="bottom"
</veui-tooltip> style="grid-area: 5 / 3"
</veui-grid-column> @mouseenter="show('bottom')"
</veui-grid-row> >
<veui-grid-row> bottom
<veui-grid-column :span="1"> </veui-button>
<span <veui-button
ref="l" ref="bottom-end"
class="target" style="grid-area: 5 / 4"
>left</span> @mouseenter="show('bottom-end')"
<veui-tooltip >
target="l" bottom-end
position="left" </veui-button>
> <veui-button
Hello. ref="left-start"
</veui-tooltip> style="grid-area: 2 / 1"
</veui-grid-column> @mouseenter="show('left-start')"
<veui-grid-column >
:span="1" left-start
:offset="3" </veui-button>
> <veui-button
<span ref="left"
ref="r" style="grid-area: 3 / 1"
class="target" @mouseenter="show('left')"
>right</span> >
<veui-tooltip left
target="r" </veui-button>
position="right" <veui-button
> ref="left-end"
Hello. style="grid-area: 4 / 1"
</veui-tooltip> @mouseenter="show('left-end')"
</veui-grid-column> >
</veui-grid-row> left-end
<veui-grid-row> </veui-button>
<veui-grid-column :span="1"> </section>
<span
ref="le"
class="target"
>left-end</span>
<veui-tooltip
target="le"
position="left-end"
>
Hello.
</veui-tooltip>
</veui-grid-column>
<veui-grid-column
:span="1"
:offset="3"
>
<span
ref="re"
class="target"
>right-end</span>
<veui-tooltip
target="re"
position="right-end"
>
Hello.
</veui-tooltip>
</veui-grid-column>
</veui-grid-row>
<veui-grid-row>
<veui-grid-column
:span="1"
:offset="1"
>
<span
ref="bs"
class="target"
>bottom-start</span>
<veui-tooltip
target="bs"
position="bottom-start"
>
Hello.
</veui-tooltip>
</veui-grid-column>
<veui-grid-column :span="1">
<span
ref="b"
class="target"
>bottom</span>
<veui-tooltip
target="b"
position="bottom"
>
Hello.
</veui-tooltip>
</veui-grid-column>
<veui-grid-column :span="1">
<span
ref="be"
class="target"
>bottom-end</span>
<veui-tooltip
target="be"
position="bottom-end"
>
Hello.
</veui-tooltip>
</veui-grid-column>
</veui-grid-row>
</veui-grid-container>
</article> </article>
</template> </template>
<script> <script>
import { GridContainer, GridRow, GridColumn, Tooltip } from 'veui' import { Tooltip, Button, Checkbox } from 'veui'
export default { export default {
components: { components: {
'veui-grid-container': GridContainer, 'veui-tooltip': Tooltip,
'veui-grid-row': GridRow, 'veui-button': Button,
'veui-grid-column': GridColumn, 'veui-checkbox': Checkbox
'veui-tooltip': Tooltip
}, },
data () { data () {
return { return {
ui: null target: null,
position: null,
open: false,
aimCenter: false
}
},
methods: {
show (position) {
this.target = this.$refs[position]
this.position = position
this.open = true
} }
} }
} }
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.veui-grid-container { section + section {
width: 80%; margin-top: 20px;
min-width: 600px;
} }
.veui-grid-row { .grid {
margin-bottom: 20px; display: grid;
} grid-template-columns: auto auto auto auto auto;
grid-gap: 12px;
.veui-grid-column { justify-content: center;
text-align: center; align-items: center;
vertical-align: middle;
line-height: 2;
}
.target {
display: inline-block;
width: 100%;
padding: 0.5em 0;
border: 1px solid #999;
border-radius: 2px;
transition: background-color 0.3s;
cursor: pointer;
&:hover {
background-color: #f7f7f7;
}
} }
</style> </style>
<docs>
使用 `aim-center` 属性来设置浮层提示箭头始终对准目标元素中心适合用于目标元素较小的场景
</docs>

View File

@ -30,6 +30,7 @@ Use the `trigger` prop to specify when to show/hide the tooltip.
| `open` | `boolean` | `false` | [^open] | | `open` | `boolean` | `false` | [^open] |
| `target` | `string|Vue|Node` | - | See the [`target` prop](./overlay#props) of thh [`Overlay`](./overlay) component. | | `target` | `string|Vue|Node` | - | See the [`target` prop](./overlay#props) of thh [`Overlay`](./overlay) component. |
| `position` | `string` | `'top'` | [^position] | | `position` | `string` | `'top'` | [^position] |
| `aim-center` | `boolean` | `false` | Whether the tooltip arrow always points to the center of the target element. |
| `trigger` | `string` | `'hover'` | [^trigger] | | `trigger` | `string` | `'hover'` | [^trigger] |
| `interactive` | `boolean` | `true` | Whether the tooltip content is interactive. When set to `false`, the tooltip will be automatically hidden after the event specified by `trigger` is triggered outside the `target`. | | `interactive` | `boolean` | `true` | Whether the tooltip content is interactive. When set to `false`, the tooltip will be automatically hidden after the event specified by `trigger` is triggered outside the `target`. |
| `hide-delay` | `number` | `tooltip.hideDelays` | Time (in milliseconds) to wait before hiding the tooltip after the close trigger is triggered. Can be used to prevent the tooltip being immediately closed after pointer leaves the `target` element and before it enters the tooltip itself. | | `hide-delay` | `number` | `tooltip.hideDelays` | Time (in milliseconds) to wait before hiding the tooltip after the close trigger is triggered. Can be used to prevent the tooltip being immediately closed after pointer leaves the `target` element and before it enters the tooltip itself. |