Popover
一个适用于 ReactLynx 的无样式气泡浮层组件,提供定位和锚点追踪基础能力。你可以查看源码来了解它的运行原理,也欢迎大家提 PR 来丰富其能力。
基础用法
示例
动画过渡
使用弹簧进入与补间退出过渡,为浮层内容添加动画。
额外锚点
如果您想添加额外的锚点,可以使用 PopoverAnchor 组件。
交叉轴偏移调整
在 PopoverPositioner 上使用 crossAxisOffset 来设置浮动元素的交叉轴偏移量。
结构
组件 API
PopoverRoot
The root component of the Popover, containing all of its child components.
PopoverTrigger
The element that triggers the Popover to show.
基于状态的样式与渲染
该组件通过以下一种或两种方式暴露运行时状态。下表仅展示每个状态实际支持的方式:
- UI variant class:支持时,对应组件节点会动态加上
ui-<state>形式的类名,可用.ui-<state> { ... }选择器定制样式; - Render-prop 字段:支持时,当
children传入函数,状态会以children({ <state>: boolean, ... })的形式作为参数传入,便于在运行时做条件渲染。
UI variants applied by PopoverTrigger.
| 类名 | 说明 |
|---|---|
| ui-active | 组合的触发按钮处于按下态且未被禁用时生效。 |
| ui-animating | 当 status.animating 为 true 时生效,可用于 `.ui-animating { ... }`。 |
| ui-busy | Popover 正在进入或离开时生效。 |
| ui-closed | 当 status.closed 为 true 时生效,可用于 `.ui-closed { ... }`。 |
| ui-disabled | 触发器被禁用时生效。 |
| ui-entering | 当 status.entering 为 true 时生效,可用于 `.ui-entering { ... }`。 |
| ui-leaving | 当 status.leaving 为 true 时生效,可用于 `.ui-leaving { ... }`。 |
| ui-open | 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。 |
PopoverAnchor
If this component is used, the Popover will use it rather than PopoverTrigger as the real anchor.
UI variants applied by PopoverAnchor.
| 类名 | 说明 |
|---|---|
| ui-animating | 当 status.animating 为 true 时生效,可用于 `.ui-animating { ... }`。 |
| ui-closed | 当 status.closed 为 true 时生效,可用于 `.ui-closed { ... }`。 |
| ui-entering | 当 status.entering 为 true 时生效,可用于 `.ui-entering { ... }`。 |
| ui-leaving | 当 status.leaving 为 true 时生效,可用于 `.ui-leaving { ... }`。 |
| ui-open | 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。 |
PopoverPositioner
Helps position the Content and Arrow correctly.
UI variants applied by PopoverPositioner based on its render state.
| 类名 | 渲染属性 | 类型 | 说明 |
|---|---|---|---|
| ui-animating | animating | boolean | 弹层正在执行动画。仅在 transition:true 时生效。 当 status.animating 为 true 时生效,可用于 `.ui-animating { ... }`。 |
| ui-closed | closed | boolean | 弹层处于关闭状态。如果开启了 forceMount,初始状态会是 ui-closed。 当 status.closed 为 true 时生效,可用于 `.ui-closed { ... }`。 |
| ui-entering | entering | boolean | 弹层正在执行进入动画。仅在 transition:true 时生效。 当 status.entering 为 true 时生效,可用于 `.ui-entering { ... }`。 |
| ui-leaving | leaving | boolean | 弹层正在执行离开动画。仅在 transition:true 时生效。 当 status.leaving 为 true 时生效,可用于 `.ui-leaving { ... }`。 |
| ui-open | open | boolean | 弹层处于打开状态。 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。 |
PopoverBackdrop
A transparent backdrop that can be used to close the Popover when clicked.
UI variants applied by PopoverBackdrop.
| 类名 | 说明 |
|---|---|
| ui-active | 组合的背景按钮处于按下态且未被禁用时生效。 |
| ui-animating | 当 status.animating 为 true 时生效,可用于 `.ui-animating { ... }`。 |
| ui-closed | 当 status.closed 为 true 时生效,可用于 `.ui-closed { ... }`。 |
| ui-disabled | 未使用动画内容且 Popover 正在进入或离开时生效。 |
| ui-entering | 当 status.entering 为 true 时生效,可用于 `.ui-entering { ... }`。 |
| ui-leaving | 当 status.leaving 为 true 时生效,可用于 `.ui-leaving { ... }`。 |
| ui-open | 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。 |
PopoverContent
The content of the Popover.
UI variants applied by PopoverContent.
| 类名 | 说明 |
|---|---|
| ui-animating | 当 status.animating 为 true 时生效,可用于 `.ui-animating { ... }`。 |
| ui-closed | 当 status.closed 为 true 时生效,可用于 `.ui-closed { ... }`。 |
| ui-entering | 当 status.entering 为 true 时生效,可用于 `.ui-entering { ... }`。 |
| ui-leaving | 当 status.leaving 为 true 时生效,可用于 `.ui-leaving { ... }`。 |
| ui-open | 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。 |
PopoverMotionContent
Motion-driven content. It owns opacity when an opacity target is specified, and transform when a transform target is specified. It stays mounted until all exit properties complete. Use one motion content per popover root.
UI variants applied by PopoverMotionContent.
| 类名 | 说明 |
|---|---|
| ui-animating | 当 status.animating 为 true 时生效,可用于 `.ui-animating { ... }`。 |
| ui-closed | 当 status.closed 为 true 时生效,可用于 `.ui-closed { ... }`。 |
| ui-entering | 当 status.entering 为 true 时生效,可用于 `.ui-entering { ... }`。 |
| ui-leaving | 当 status.leaving 为 true 时生效,可用于 `.ui-leaving { ... }`。 |
| ui-open | 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。 |
PopoverArrow
The arrow of the Popover.
{ width, height } 表示旋转前的底边宽度和突出高度;左右方向由底层自动旋转。未传 children 时,对象尺寸仍取最大值绘制默认三角形。UI variants applied by PopoverArrow.
| 类名 | 说明 |
|---|---|
| ui-animating | 当 status.animating 为 true 时生效,可用于 `.ui-animating { ... }`。 |
| ui-closed | 当 status.closed 为 true 时生效,可用于 `.ui-closed { ... }`。 |
| ui-entering | 当 status.entering 为 true 时生效,可用于 `.ui-entering { ... }`。 |
| ui-leaving | 当 status.leaving 为 true 时生效,可用于 `.ui-leaving { ... }`。 |
| ui-open | 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。 |
辅助类型
PopoverOverlayProps
The view container of the Popover. Can be overlay or view. Controls the z-index of the popover.
PopoverMotionOptions
Motion targets and their shared default transition.
PopoverMotionValues
Numeric visual properties supported by PopoverMotionContent.
PopoverMotionTarget
A visual target and its transition settings.
PopoverMotionTransition
easeOut when its duration or easing is omitted.