<tap-callout>
Long-press menu component. Long pressing lifts the content in place, blurs and dims the background, and shows a menu below it.
Example
<tap-callout .menu=${ [ {"label":"Copy"}, {"label":"Favorite"}, {"label":"Delete","danger":true} ] }> <div style="display: inline-block; padding: 0.75em 1em; border-radius: 1em; color: #fff; background: #536dfe">Long press me</div> </tap-callout>
A menu item's handle runs synchronously in the click while the menu starts closing, so actions that need user activation, such as writing to the clipboard, work. The show event fires when a long press lifts the content and opens the menu, e.g. for haptic feedback.
import { icons } from '@mantou/tap-ui/lib/icons';
html`
<tap-callout
.menu=${[
{ label: 'Copy', icon: icons.copy, handle: copy },
{ label: 'Delete', icon: icons.delete, danger: true, handle: remove },
]}
>
<div>Message content</div>
</tap-callout>
`;Showing a Preview
Use Callout.open when the long press should show a preview that differs from the original content, such as the full message or an enlarged image. The preview expands from the position of target, the original content stays in place, and the menu is shown below the preview.
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: 'Copy', handle: copy }],
}),
)}
>
Message content
</div>
`;NOTE
The preview is rendered inside the Shadow DOM of
<tap-callout>, so outside styles don't apply to it. Use an element that carries its own styles as the preview.
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 |
