Dialog
一个适用于 ReactLynx 的无样式对话框组件,提供遮罩渲染、开关状态管理以及进出场动画基础能力。你可以查看源码来了解它的运行原理,也欢迎大家提 PR 来丰富其能力。
弹窗组件,可以设置背景遮罩层。
基础用法
结构
组件 API
DialogRoot
The root component of the Dialog, containing all of its child components.
show 属性),您应该使用此处理器来更新控制弹窗可见性的状态。在非受控模式下,此处理器是可选的,会在弹窗内部状态更新之前调用。基于状态的样式与渲染
该组件通过以下一种或两种方式暴露运行时状态。下表仅展示每个状态实际支持的方式:
- UI variant class:支持时,对应组件节点会动态加上
ui-<state>形式的类名,可用.ui-<state> { ... }选择器定制样式; - Render-prop 字段:支持时,当
children传入函数,状态会以children({ <state>: boolean, ... })的形式作为参数传入,便于在运行时做条件渲染。
DialogRoot exposes the following render prop states.
| 渲染属性 | 类型 | 说明 |
|---|---|---|
animating | boolean | 弹层正在执行动画。仅在 transition:true 时生效。 |
closed | boolean | 弹层处于关闭状态。如果开启了 forceMount,初始状态会是 ui-closed。 |
entering | boolean | 弹层正在执行进入动画。仅在 transition:true 时生效。 |
leaving | boolean | 弹层正在执行离开动画。仅在 transition:true 时生效。 |
open | boolean | 弹层处于打开状态。 |
DialogTrigger
The trigger of the dialog. Controls the display of the popper.
true 时,组件将处于禁用状态,无法进行交互。ReactNode 的函数,也可以是一个 ReactNode 本身。UI variants applied by DialogTrigger based on its render state.
| 类名 | 渲染属性 | 类型 | 说明 |
|---|---|---|---|
| ui-active | active | boolean | 组合的弹窗按钮处于按下态且未被禁用时生效。 |
| ui-animating | — | boolean | 当 status.animating 为 true 时生效,可用于 `.ui-animating { ... }`。 |
| ui-busy | busy | boolean | 弹窗正在进入或离开时生效。 |
| ui-closed | — | boolean | 当 status.closed 为 true 时生效,可用于 `.ui-closed { ... }`。 |
| ui-disabled | — | boolean | 弹窗按钮被显式禁用或弹窗处于忙碌状态时生效。 |
| ui-entering | — | boolean | 当 status.entering 为 true 时生效,可用于 `.ui-entering { ... }`。 |
| ui-leaving | — | boolean | 当 status.leaving 为 true 时生效,可用于 `.ui-leaving { ... }`。 |
| ui-open | — | boolean | 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。 |
DialogBackdrop
The backdrop mask of the dialog.
true 时,如果弹窗处于非受控模式(未提供 show 属性),点击背景将触发 onClose 回调并关闭弹窗。当值为 false 时,点击背景将没有任何效果。UI variants applied by DialogBackdrop.
| 类名 | 说明 |
|---|---|
| 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 { ... }`。 |
DialogView
View container. When 'container' is set correctly, the underlying layer will be replaced with overlay; otherwise, it will be a regular view. When the underlying layer is overlay, the 'level' property can be used to control the hierarchical relationship. For a regular view, use 'z-index' to control the hierarchical relationship. If this dialog needs to be used outside of LynxView, consider enabling overlay.
UI variants applied by DialogView 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 { ... }`。 |
DialogContent
The main content of the dialog.
UI variants applied by DialogContent.
| 类名 | 说明 |
|---|---|
| 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 { ... }`。 |
DialogClose
The close component of the Dialog, used to close the dialog.
true 时,组件将处于禁用状态,无法进行交互。ReactNode 的函数,也可以是一个 ReactNode 本身。UI variants applied by DialogClose based on its render state.
| 类名 | 渲染属性 | 类型 | 说明 |
|---|---|---|---|
| ui-active | active | boolean | 组合的弹窗按钮处于按下态且未被禁用时生效。 |
| ui-animating | — | boolean | 当 status.animating 为 true 时生效,可用于 `.ui-animating { ... }`。 |
| ui-busy | busy | boolean | 弹窗正在进入或离开时生效。 |
| ui-closed | — | boolean | 当 status.closed 为 true 时生效,可用于 `.ui-closed { ... }`。 |
| ui-disabled | — | boolean | 弹窗按钮被显式禁用或弹窗处于忙碌状态时生效。 |
| ui-entering | — | boolean | 当 status.entering 为 true 时生效,可用于 `.ui-entering { ... }`。 |
| ui-leaving | — | boolean | 当 status.leaving 为 true 时生效,可用于 `.ui-leaving { ... }`。 |
| ui-open | — | boolean | 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。 |