Popover component is used to manage the presentation of content in a popover. You use popovers to present information temporarily. The popover remains visible until the user taps outside of the popover window or you explicitly dismiss it.
There are following components included:
Popover
Name | Type | Default | Description |
---|---|---|---|
angle | boolean | true | Renders popover "angle"/"corner" |
angleClassName | string | undefined | Additional css class to add on "angle"/"corner" element |
backdrop | boolean | true | Enables Popover backdrop (dark semi transparent layer behind) |
colors | object | Object with Tailwind CSS colors classes | |
colors.bgIos | string | 'bg-ios-light-surface-3 dark:bg-ios-dark-surface-3' | |
colors.bgMaterial | string | 'bg-md-light-surface-3 dark:bg-md-dark-surface-3' | |
component | string | 'div' | Component's HTML Element |
opened | boolean | false | Allows to open/close Popover and set its initial state |
size | string | 'w-64' | Tailwind CSS size classes |
target | string | HTMLElement | Ref | Popover target element. Popover will be positioned around this element | |
targetHeight | number | Virtual target element height (in px). Required without using real target element ( | |
targetWidth | number | Virtual target element width (in px). Required without using real target element ( | |
targetX | number | Virtual target element horizontal offset from left side of the screen. Required without using real target element ( | |
targetY | number | Virtual target element vertical offset from top of the screen. Required without using real target element ( | |
translucent | boolean | true | Makes Popover background translucent (with |
onBackdropClick | function(e) | Click handler on backdrop element |
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>);}