用法
从'react'导入{useState}; 从“@wordpress/components”导入{Button,Popover}; const MyPopover=()=>{ const[isVisible,setIsVisible]=使用状态(false); 常量切换可见=()=>{ setIsVisible((state)=>! 状态); }; 返回( <Button variant=“secondary”onClick={toggleVisible}> 切换Popover! {isVisible&&<Popover>Popover已切换!</Popover>} </按钮> ); };
从'react'导入{useState}; 从“@wordpress/components”导入{Button,Popover}; const MyPopover=()=>{ //使用内部状态而不是ref来确保组件 //当popover的锚更新时重新读取。 const[popoverAnchor,setPopoverAncor]=useState(); const[isVisible,setIsVisible]=使用状态(false); 常量切换可见=()=>{ setIsVisible((state)=>! 状态); }; 返回( <p ref={setPopoverAnchor}>Popover的锚点</p> <Button variant=“secondary”onClick={toggleVisible}> 切换Popover! </按钮> {可见&&( <波波弗 锚={popoverAnchor} > Popover被切换了! </Popover> ) } ); };
从“react-dom/client”导入{createRoot}; 从“@wordpress/components”导入{Popover}; 从“导入内容”/ 内容'; const-app=document.getElementById('app'); const root=createRoot(app); 根.根.根( <div> <内容/> <波波。 插槽/> </div> );
道具
锚点:元素|VirtualElement|null
必需:否
anchorRect:带所有者文档的DomRect
必需:否
anchorRef:Element | PopoverAnchorRefRefReference | Popover AnchorrefTopBottom |范围
必需:否
动画:布尔
必需:否 违约: 真的
子级:ReactNode
必需:是
expandOnMobile:布尔值
必需:否
翻转:布尔
必需:否 违约: 真的
focusOnMount:'firstElement'|布尔值
必需:否 违约: “第一元素”
onFocusOutside:(事件:SyntheticEvent)=>无效
必需:否
getAnchorRect:(fallbackReferenceElement:Element|null)=>DomRectWithOwnerDocument
必需:否
headerTitle:字符串
必需:否
isAlternate:布尔值
必需:否
无箭头:布尔
必需:否 违约: 真的
偏移:数字
必需:否
onClose:()=>无效
必需:否
位置:'top'|'top-start'|'op-end'|'right'|'reght-start'|'right-end'|'bottom'|'bottom-start''|'bottom-end'|'left'|'left-start` |'overlay'
必需:否 违约: “从下到下”
位置:[yAxis][xAxis][optionalCorner]
Y轴 : “顶部”|“中间”|“底部” X轴 : “左”|“中”|“右” 角 : “顶部”|“右侧”|“底部”|“左侧”
必需:否
调整大小:布尔值
必需:否 违约: 真的
variant:'工具栏'|'未设置样式'