Icon setIcons
Illustration setIllustrations
Trigger
Popover
Usage
import { Popover } from '@loomhq/lens'
<Popover
isOpen
placement="rightCenter"
content={(<div>Popover</div>)}
>
Content
</Popover>
Placement
() => {const [placement, setPlacement] = React.useState({ value: 'rightCenter', title: 'rightCenter' })return (<Split gap="medium" justifyContent="space-between"><SplitSection><PopoverisOpenplacement={placement.value}content={(<DemoBox padding="xsmall">Popover</DemoBox>)}><DemoBox padding="large">Trigger</DemoBox></Popover></SplitSection><SplitSection basis={20}><SelectselectedOptionValue="rightCenter"onChange={option => setPlacement(option)}options={[{ value: 'topLeft', title: 'topLeft' },{ value: 'topCenter', title: 'topCenter' },{ value: 'topRight', title: 'topRight' },{ value: 'bottomLeft', title: 'bottomLeft' },{ value: 'bottomCenter', title: 'bottomCenter' },{ value: 'bottomRight', title: 'bottomRight' },{ value: 'leftTop', title: 'leftTop' },{ value: 'leftCenter', title: 'leftCenter' },{ value: 'leftBottom', title: 'leftBottom' },{ value: 'rightTop', title: 'rightTop' },{ value: 'rightCenter', title: 'rightCenter' },{ value: 'rightBottom', title: 'rightBottom' },]}/></SplitSection></Split>)}
Offset
<PopoverisOpenoffset={2}placement="rightCenter"content={(<DemoBox padding="xsmall">Popover</DemoBox>)}><DemoBox padding="large">Trigger</DemoBox></Popover>
Open
Open on click
() => {const [isOpen, setIsOpen] = React.useState(false)const ref = React.useRef();useOnClickOutside(ref, () => setIsOpen(false));return (<Container width="fit-content"><div ref={ref}><PopoverisOpen={isOpen}placement="bottomCenter"content={(<DemoBox padding="xsmall">Popover</DemoBox>)}><Button onClick={() => setIsOpen(!isOpen)}>Open Popover</Button></Popover></div></Container>)}
Open on hover
() => {const [isOpen, setIsOpen] = React.useState(false)return (<Container width="fit-content"><divonMouseEnter={() => setIsOpen(true)}onMouseLeave={() => setIsOpen(false)}><PopoverisOpen={isOpen}placement="bottomCenter"content={(<DemoBox padding="xsmall">Popover</DemoBox>)}>Hover me</Popover></div></Container>)}
Transition
Use transitionDuration
and transitionDelay
to animate the opening transition.
() => {const [isOpen, setIsOpen] = React.useState(false)const ref = React.useRef();useOnClickOutside(ref, () => setIsOpen(false));return (<Container width="fit-content"><div ref={ref}><PopoverisOpen={isOpen}placement="bottomCenter"content={(<DemoBox padding="xsmall">Popover</DemoBox>)}transitionDuration={200}transitionDelay={70}><Button onClick={() => setIsOpen(!isOpen)}>Open Popover</Button></Popover></div></Container>)}
Root id
Use rootId
to insert the Popover in a custom container.
<div><div id="popovers-root">Inspect me, the Popover will render here</div><br /><PopoverrootId="popovers-root"isOpenplacement="rightCenter"content={(<DemoBox padding="xsmall">Popover</DemoBox>)}><DemoBox padding="large">Trigger</DemoBox></Popover></div>
Boundary element
Use boundaryElement
to limit Popover's horizontal overflow.
() => {const [isOpen, setIsOpen] = React.useState(false)const [boundaryElement, setBoundaryElement] = React.useState(false)const boundaryRef = React.useRef()React.useEffect(() => {setBoundaryElement(boundaryRef)}, [])return (<><div ref={boundaryRef}style={{border: '1px solid var(--lns-color-border)',maxWidth: 400, height: 120}}><PopoverisOpenplacement="bottomCenter"boundaryElement={boundaryRef.current}content={(<DemoBox padding="small" width="max-content">Popover with boundary</DemoBox>)}><DemoBox padding="xsmall">Trigger</DemoBox></Popover></div><divstyle={{border: '1px solid var(--lns-color-border)',maxWidth: 400, height: 120}}><Container width='max-content'><PopoverisOpenplacement="bottomCenter"content={(<DemoBox padding="small" width="max-content">Popover without boundary</DemoBox>)}><DemoBox padding="xsmall">Trigger</DemoBox></Popover></Container></div></>)}
Examples
With popover card
() => {const [isOpen, setIsOpen] = React.useState(false)const ref = React.useRef();useOnClickOutside(ref, () => setIsOpen(false));return (<Container width="fit-content"><div ref={ref}><PopoverisOpen={isOpen}placement="bottomCenter"content={(<ContainercontentColor="body"backgroundColor="overlay"borderSide="all"radius="medium"shadow="medium"padding="medium"width={38}><Arrange gap="small" >{demoText.short}<Button onClick={() => setIsOpen(false)}>Close</Button></Arrange></Container>)}><Button onClick={() => setIsOpen(!isOpen)}>Open Popover</Button></Popover></div></Container>)}
Props
name
type
default
offset
number
0.5
boundaryOffset
number
0.5
zIndex
number | string
500
placement
| 'topLeft'
| 'topCenter'
| 'topRight'
| 'bottomLeft'
| 'bottomCenter'
| 'bottomRight'
| 'leftTop'
| 'leftCenter'
| 'leftBottom'
| 'rightTop'
| 'rightCenter'
| 'rightBottom'
'topCenter'
boundaryElement
'body' | Element
'body'
transitionDuration
number
0
transitionDelay
number
0
children
React.ReactNode
content
React.ReactNode
isOpen
boolean
rootId
string