🔥 遇见我们的新项目 t0ggles - 你最终的项目管理工具! 🔥

Popover Svelte 组件

Popover 组件用于管理弹出框中内容的呈现。使用弹出框临时显示信息。弹出框将一直显示,直到用户点击弹出框窗口外部或您显式关闭它。

Popover 组件

包含以下组件

  • 弹出框

Popover 属性

名称类型默认值描述
angle布尔值true

渲染弹出框的“角度”/“角”

angleClass字符串undefined

要添加到“角度”/“角”元素上的附加 CSS 类

backdrop布尔值true

启用 Popover 背景(弹出框后面的半透明暗层)

colors对象

包含 Tailwind CSS 颜色类别的对象

colors.bgIos字符串'bg-ios-light-surface-3 dark:bg-ios-dark-surface-3'
colors.bgMaterial字符串'bg-md-light-surface-3 dark:bg-md-dark-surface-3'
opened布尔值false

允许打开/关闭弹出框并设置其初始状态

size字符串'w-64'

Tailwind CSS 大小类别

target字符串 | HTMLElement | 引用

弹出框的目标元素。弹出框将围绕此元素定位

targetHeight数字

虚拟目标元素高度(以像素为单位)。在不使用真实目标元素(target 属性)的情况下需要。

targetWidth数字

虚拟目标元素宽度(以像素为单位)。在不使用真实目标元素(target 属性)的情况下需要。

targetX数字

虚拟目标元素相对于屏幕左侧的水平偏移量。在不使用真实目标元素(target 属性)的情况下需要。

targetY数字

虚拟目标元素相对于屏幕顶部的垂直偏移量。在不使用真实目标元素(target 属性)的情况下需要。

translucent布尔值true

在 iOS 主题中使 Popover 背景半透明(使用 backdrop-filter: blur

onBackdropClickfunction(e)

背景元素上的点击处理程序

示例

Popover.svelte
<script>
import {
Page,
Navbar,
NavbarBackLink,
Popover,
Block,
Link,
Button,
List,
ListItem,
} from 'konsta/svelte';
let popoverOpened = false;
let popoverTargetEl = null;
const openPopover = (targetEl) => {
popoverTargetEl = targetEl;
popoverOpened = true;
};
</script>
<Page>
<Navbar title="Popover">
<Link
slot="right"
class="popover-navbar-link"
navbar
onClick={() => openPopover('.popover-navbar-link')}
>
Popover
</Link>
</Navbar>
<Block class="space-y-4">
<p>
<Button
class="popover-button"
onClick={() => openPopover('.popover-button')}
>
Open popover on me
</Button>
</p>
<p>
Mauris fermentum neque et luctus venenatis. Vivamus a sem rhoncus, ornare
tellus eu, euismod mauris. In porta turpis at semper convallis. Duis
adipiscing leo eu nulla lacinia, quis rhoncus metus condimentum. Etiam nec
malesuada nibh. Maecenas quis lacinia nisl, vel posuere dolor. Vestibulum
condimentum, nisl ac vulputate egestas, neque enim dignissim elit, rhoncus
volutpat magna enim a est. Aenean sit amet ligula neque. Cras suscipit
rutrum enim. Nam a odio facilisis, elementum tellus non,{' '}
<Link
class="popover-link-1"
onClick={() => openPopover('.popover-link-1')}
>
popover
</Link>{' '}
tortor. Pellentesque felis eros, dictum vitae lacinia quis, lobortis vitae
ipsum. Cras vehicula bibendum lorem quis imperdiet.
</p>
<p>
In hac habitasse platea dictumst. Etiam varius, ante vel ornare facilisis,
velit massa rutrum dolor, ac porta magna magna lacinia nunc. Curabitur{' '}
<Link
class="popover-link-2"
onClick={() => openPopover('.popover-link-2')}
>
popover!
</Link>{' '}
cursus laoreet. Aenean vel tempus augue. Pellentesque in imperdiet nibh. Mauris
rhoncus nulla id sem suscipit volutpat. Pellentesque ac arcu in nisi viverra
pulvinar. Nullam nulla orci, bibendum sed ligula non, ullamcorper iaculis mi.
In hac habitasse platea dictumst. Praesent varius at nisl eu luctus. Cras aliquet
porta est. Quisque elementum quis dui et consectetur. Cum sociis natoque penatibus
et magnis dis parturient montes, nascetur ridiculus mus. Sed sed laoreet purus.
Pellentesque eget ante ante.
</p>
<p>
Duis et ultricies nibh. Sed facilisis turpis urna, ac imperdiet erat
venenatis eu. Proin sit amet faucibus tortor, et varius sem. Etiam vitae
lacinia neque. Aliquam nisi purus, interdum in arcu sed, ultrices rutrum
arcu. Nulla mi turpis, consectetur vel enim quis, facilisis viverra dui.
Aliquam quis convallis tortor, quis semper ligula. Morbi ullamcorper{' '}
<Link
class="popover-link-3"
onClick={() => openPopover('.popover-link-3')}
>
one more popover
</Link>{' '}
massa at accumsan. Etiam purus odio, posuere in ligula vitae, viverra ultricies
justo. Vestibulum nec interdum nisi. Aenean ac consectetur velit, non malesuada
magna. Sed pharetra vehicula augue, vel venenatis lectus gravida eget. Curabitur
lacus tellus, venenatis eu arcu in, interdum auctor nunc. Nunc non metus neque.
Suspendisse viverra lectus sed risus aliquet, vel accumsan dolor feugiat.
</p>
</Block>
<Popover
opened={popoverOpened}
target={popoverTargetEl}
onBackdropClick={() => (popoverOpened = false)}
>
<List nested>
<ListItem title="Item 1" link onClick={() => (popoverOpened = false)} />
<ListItem
title="List Item 2"
link
onClick={() => (popoverOpened = false)}
/>
<ListItem title="Item 3" link onClick={() => (popoverOpened = false)} />
<ListItem
title="List Item 4"
link
onClick={() => (popoverOpened = false)}
/>
<ListItem title="Item 5" link onClick={() => (popoverOpened = false)} />
</List>
</Popover>
</Page>
代码许可证: MIT.
2022 © Konsta UI 作者: nolimits4web.