<tap-callout>
长按菜单组件。长按内容时内容原地浮起,背景模糊变暗,下方显示菜单。
Example
Loading...
<tap-callout .menu=${ [ {"label":"复制"}, {"label":"收藏"}, {"label":"删除","danger":true} ] }> <div style="display: inline-block; padding: 0.75em 1em; border-radius: 1em; color: #fff; background: #536dfe">长按我</div> </tap-callout>
菜单项的 handle 在点击中同步执行,菜单同时开始关闭,所以复制到剪贴板等需要用户激活的操作可以生效。长按浮起、菜单弹出时触发 show 事件,可在其中加震动反馈。
import { icons } from '@mantou/tap-ui/lib/icons';
html`
<tap-callout
.menu=${[
{ label: '复制', icon: icons.copy, handle: copy },
{ label: '删除', icon: icons.delete, danger: true, handle: remove },
]}
>
<div>消息内容</div>
</tap-callout>
`;展示预览
当长按后需要展示和原内容不同的预览(例如完整的消息、放大的图片)时,使用 Callout.open。预览从 target 的位置展开,原内容留在原处,菜单显示在预览下方。
import { Callout } from '@mantou/tap-ui/elements/callout';
import { longPress } from '@mantou/tap-ui/lib/directives';
const ref = createRef<HTMLElement>();
html`
<div
${ref}
${longPress(() =>
Callout.open({
target: ref.value!,
preview: html`<message-preview></message-preview>`,
menu: [{ label: '复制', handle: copy }],
}),
)}
>
消息内容
</div>
`;NOTE
预览渲染在
<tap-callout>的 Shadow DOM 中,外部样式无法作用到预览内容,建议使用自带样式的元素作为预览。
API
长按内容原地浮起,下方显示菜单
使用 Callout.open 在长按元素的位置展示预览内容和菜单
Shadow DOM; Extends GemElement
Static Methods
| Method | Type |
|---|---|
open |
({ target, preview, menu }: CalloutOptions) => Promise<void> |
Instance Properties
| Property(Attribute) | Reactive | Type | Description |
|---|---|---|---|
menu |
Yes | CalloutItem[] |
|
show |
Emitter |
长按浮起、菜单弹出时触发,可用于震动反馈 |
Other
| Type | Value |
|---|---|
| Event | show |
| Slot | unnamed |
| Part | preview, menu, menu-item, menu-separator |
| CSS State | open |
