Popover 组件用于管理内容在 Popover 中的呈现方式。您可以使用 Popover 暂时显示信息。Popover 会一直保持可见,直到用户点击 Popover 窗口外部,或者您显式地将其关闭。
以下组件包含在内
Popover
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
angle | 布尔值 | true | 呈现 Popover "angle"/"corner" |
angleClassName | 字符串 | undefined | 要在 "angle"/"corner" 元素上添加的附加 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' | |
component | 字符串 | 'div' | 组件的 HTML 元素 |
opened | 布尔值 | false | 允许打开/关闭 Popover 并设置其初始状态 |
size | 字符串 | 'w-64' | Tailwind CSS 大小类 |
target | 字符串 | HTMLElement | 引用 | Popover 目标元素。Popover 将定位在这个元素周围 | |
targetHeight | 数字 | 虚拟目标元素高度(以像素为单位)。在不使用真实目标元素( | |
targetWidth | 数字 | 虚拟目标元素宽度(以像素为单位)。在不使用真实目标元素( | |
targetX | 数字 | 虚拟目标元素距屏幕左侧的水平偏移量。在不使用真实目标元素( | |
targetY | 数字 | 虚拟目标元素距屏幕顶部的垂直偏移量。在不使用真实目标元素( | |
translucent | 布尔值 | true | 在 iOS 主题中,使 Popover 背景半透明(使用 |
onBackdropClick | function(e) | 背景元素上的点击处理程序 |
import React, { useRef, useState } from 'react';import {Page,Navbar,NavbarBackLink,Popover,Block,Link,Button,List,ListItem,} from 'konsta/react';export default function PopoverPage() {const [popoverOpened, setPopoverOpened] = useState(false);const popoverTargetRef = useRef(null);const openPopover = (targetRef) => {popoverTargetRef.current = targetRef;setPopoverOpened(true);};return (<Page><Navbartitle="Popover"right={<LinkclassName="popover-navbar-link"navbaronClick={() => openPopover('.popover-navbar-link')}>Popover</Link>}/><Block className="space-y-4"><p><ButtonclassName="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 posueredolor. Vestibulum condimentum, nisl ac vulputate egestas, neque enimdignissim elit, rhoncus volutpat magna enim a est. Aenean sit ametligula neque. Cras suscipit rutrum enim. Nam a odio facilisis,elementum tellus non,{' '}<LinkclassName="popover-link-1"onClick={() => openPopover('.popover-link-1')}>popover</Link>{' '}tortor. Pellentesque felis eros, dictum vitae lacinia quis, lobortisvitae ipsum. Cras vehicula bibendum lorem quis imperdiet.</p><p>In hac habitasse platea dictumst. Etiam varius, ante vel ornarefacilisis, velit massa rutrum dolor, ac porta magna magna lacinianunc. Curabitur{' '}<LinkclassName="popover-link-2"onClick={() => openPopover('.popover-link-2')}>popover!</Link>{' '}cursus laoreet. Aenean vel tempus augue. Pellentesque in imperdietnibh. Mauris rhoncus nulla id sem suscipit volutpat. Pellentesque acarcu in nisi viverra pulvinar. Nullam nulla orci, bibendum sed ligulanon, ullamcorper iaculis mi. In hac habitasse platea dictumst.Praesent varius at nisl eu luctus. Cras aliquet porta est. Quisqueelementum quis dui et consectetur. Cum sociis natoque penatibus etmagnis dis parturient montes, nascetur ridiculus mus. Sed sed laoreetpurus. Pellentesque eget ante ante.</p><p>Duis et ultricies nibh. Sed facilisis turpis urna, ac imperdiet eratvenenatis eu. Proin sit amet faucibus tortor, et varius sem. Etiamvitae 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 semperligula. Morbi ullamcorper{' '}<LinkclassName="popover-link-3"onClick={() => openPopover('.popover-link-3')}>one more popover</Link>{' '}massa at accumsan. Etiam purus odio, posuere in ligula vitae, viverraultricies justo. Vestibulum nec interdum nisi. Aenean ac consecteturvelit, non malesuada magna. Sed pharetra vehicula augue, vel venenatislectus gravida eget. Curabitur lacus tellus, venenatis eu arcu in,interdum auctor nunc. Nunc non metus neque. Suspendisse viverra lectussed risus aliquet, vel accumsan dolor feugiat.</p></Block><Popoveropened={popoverOpened}target={popoverTargetRef.current}onBackdropClick={() => setPopoverOpened(false)}><List nested><ListItemtitle="Item 1"linkonClick={() => setPopoverOpened(false)}/><ListItemtitle="List Item 2"linkonClick={() => setPopoverOpened(false)}/><ListItemtitle="Item 3"linkonClick={() => setPopoverOpened(false)}/><ListItemtitle="List Item 4"linkonClick={() => setPopoverOpened(false)}/><ListItemtitle="Item 5"linkonClick={() => setPopoverOpened(false)}/></List></Popover></Page>);}