@lynx-js/lynx-ui-dialog 0.0.0 → 3.130.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import { useContext } from '@lynx-js/react'
6
+
7
+ import { Button } from '@lynx-js/lynx-ui-button'
8
+ import { renderContentWithExtraProps } from '@lynx-js/lynx-ui-common'
9
+ import { PresenceState } from '@lynx-js/lynx-ui-presence'
10
+ import { clsx } from 'clsx'
11
+
12
+ import { DialogContext } from './DialogContext'
13
+ import type { DialogTriggerProps } from './types'
14
+
15
+ export const resolveBusyState = (state: PresenceState) => {
16
+ switch (state) {
17
+ case PresenceState.Entering:
18
+ case PresenceState.DelayedEntering:
19
+ case PresenceState.Leaving:
20
+ return true
21
+ default:
22
+ return false
23
+ }
24
+ }
25
+
26
+ export function DialogButton(
27
+ props: DialogTriggerProps & { changeShow: boolean },
28
+ ) {
29
+ const { children, disabled = false, style, className, changeShow } = props
30
+ const { setUncontrolledShow, groupState, onShowChange } = useContext(
31
+ DialogContext,
32
+ )
33
+ const busy = resolveBusyState(groupState)
34
+ const renderedContent = renderContentWithExtraProps<{ busy: boolean }>({
35
+ busy,
36
+ }, children)
37
+ const actualDisabled = busy || disabled
38
+
39
+ const handleClick = () => {
40
+ onShowChange?.(changeShow)
41
+ setUncontrolledShow(changeShow)
42
+ }
43
+
44
+ return (
45
+ <Button
46
+ style={style}
47
+ className={clsx(className, {
48
+ 'ui-busy': busy,
49
+ })}
50
+ disabled={actualDisabled}
51
+ onClick={handleClick}
52
+ >
53
+ {renderedContent}
54
+ </Button>
55
+ )
56
+ }
@@ -0,0 +1,26 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import { createContext } from '@lynx-js/react'
6
+
7
+ import { noop } from '@lynx-js/lynx-ui-common'
8
+ import { PresenceState } from '@lynx-js/lynx-ui-presence'
9
+
10
+ export const DialogContext = createContext<{
11
+ show: boolean
12
+ forceMount: boolean
13
+ groupState: PresenceState
14
+ setGroupState: (state: PresenceState) => void
15
+ setUncontrolledShow: (prop: boolean) => void
16
+ onOpen?: () => void
17
+ onClose?: () => void
18
+ onShowChange?: (show: boolean) => void
19
+ debugLog?: boolean
20
+ }>({
21
+ show: false,
22
+ forceMount: false,
23
+ groupState: PresenceState.Left,
24
+ setGroupState: noop,
25
+ setUncontrolledShow: noop,
26
+ })
package/src/index.tsx ADDED
@@ -0,0 +1,22 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ export {
6
+ DialogView,
7
+ DialogRoot,
8
+ DialogContent,
9
+ DialogTrigger,
10
+ DialogClose,
11
+ DialogBackdrop,
12
+ } from './Dialog'
13
+
14
+ export type { PresenceAnimationStatus } from '@lynx-js/lynx-ui-presence'
15
+ export type {
16
+ DialogBackdropProps,
17
+ DialogContentProps,
18
+ DialogRootProps,
19
+ DialogTriggerProps,
20
+ DialogCloseProps,
21
+ DialogViewProps,
22
+ } from './types'
@@ -0,0 +1,315 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import type { ReactNode } from '@lynx-js/react'
6
+
7
+ import type { ComponentBasicProps } from '@lynx-js/lynx-ui-common'
8
+ import type { PresenceChildrenType } from '@lynx-js/lynx-ui-presence'
9
+ import type { OverlayProps, ViewProps } from '@lynx-js/types'
10
+
11
+ /**
12
+ * The backdrop mask of the dialog.
13
+ * @zh 弹窗的背景遮罩。
14
+ */
15
+ export interface DialogBackdropProps extends ComponentBasicProps {
16
+ /**
17
+ * children
18
+ * @zh 子元素
19
+ * @Android
20
+ * @iOS
21
+ * @Harmony
22
+ */
23
+ children?: ReactNode
24
+ /**
25
+ * If the content needs a delayed first screen to do first render, you need to set this property to true.
26
+ * @zh 如果内容需要延迟首屏进行首次渲染,则需要将此属性设置为 true。
27
+ */
28
+ delayed?: boolean
29
+ /**
30
+ * If set to true, the className will has the transition classes like 'ui-entering', 'ui-leaving', 'ui-animating'
31
+ * @Android
32
+ * @iOS
33
+ * @Harmony
34
+ * @zh 如果设置为 true,则 className 会包含 'ui-entering', 'ui-leaving', 'ui-animating' 等动画相关类名
35
+ */
36
+ transition?: boolean
37
+ /**
38
+ * Determines whether clicking on the backdrop closes the dialog.
39
+ * This prop acts as a behavior switch for the backdrop's click event.
40
+ *
41
+ * When `true`, clicking the backdrop will trigger the `onClose` callback and close the dialog if the dialog is in uncontrolled mode (when `show` is not provided).
42
+ * When `false`, clicking the backdrop will have no effect.
43
+ * @defaultValue true
44
+ * @Android
45
+ * @iOS
46
+ * @Harmony
47
+ * @zh 确定点击背景是否关闭弹窗。此属性作为背景点击事件的行为开关。当值为 `true` 时,如果弹窗处于非受控模式(未提供 `show` 属性),点击背景将触发 `onClose` 回调并关闭弹窗。当值为 `false` 时,点击背景将没有任何效果。
48
+ */
49
+ clickToClose?: boolean
50
+ /**
51
+ * DialogBackdrop supports original view props to be directly spread in this prop.
52
+ * @Android
53
+ * @iOS
54
+ * @Harmony
55
+ * @zh DialogBackdrop 支持将原始 view 属性直接展开到这个属性中。
56
+ */
57
+ dialogBackdropProps?: ViewProps
58
+ /**
59
+ * Triggered when the backdrop is clicked.
60
+ * @zh 点击背景时触发。
61
+ * @Android
62
+ * @iOS
63
+ * @Harmony
64
+ */
65
+ onClick?: () => void
66
+ }
67
+
68
+ /**
69
+ * The main content of the dialog.
70
+ * @zh 弹窗的主要内容。
71
+ */
72
+ export interface DialogContentProps extends ComponentBasicProps {
73
+ /**
74
+ * children
75
+ * @zh 子元素
76
+ * @Android
77
+ * @iOS
78
+ * @Harmony
79
+ */
80
+ children?: ReactNode
81
+ /**
82
+ * If the content needs a delayed first screen to do first render, you need to set this property to true.
83
+ * @zh 如果内容需要延迟首屏进行首次渲染,则需要将此属性设置为 true。
84
+ */
85
+ delayed?: boolean
86
+ /**
87
+ * If set to true, the className will has the transition classes like 'ui-entering', 'ui-leaving', 'ui-animating'
88
+ * @Android
89
+ * @iOS
90
+ * @Harmony
91
+ * @zh 如果设置为 true,则 className 会包含 'ui-entering', 'ui-leaving', 'ui-animating' 等动画相关类名
92
+ */
93
+ transition?: boolean
94
+ /**
95
+ * DialogContent supports original view props to be directly spread in this prop.
96
+ * @Android
97
+ * @iOS
98
+ * @Harmony
99
+ * @zh DialogContent 支持将原始 view 属性直接展开到这个属性中。
100
+ */
101
+ dialogContentProps?: ViewProps
102
+ }
103
+
104
+ export type TriggerChildrenType = (
105
+ DialogButtonStatus: { active: boolean, busy: boolean },
106
+ ) => ReactNode
107
+
108
+ /**
109
+ * The trigger of the dialog. Controls the display of the popper.
110
+ * @zh 弹窗的触发组件。控制弹窗的显示
111
+ */
112
+ export interface DialogTriggerProps extends ComponentBasicProps {
113
+ /**
114
+ * The content of the close component. It can be a function that returns a `ReactNode` or a `ReactNode` itself.
115
+ * @Android
116
+ * @iOS
117
+ * @Harmony
118
+ * @zh 关闭组件的内容。它可以是一个返回 `ReactNode` 的函数,也可以是一个 `ReactNode` 本身。
119
+ */
120
+ children:
121
+ | TriggerChildrenType
122
+ | ReactNode
123
+ /**
124
+ * Determines whether the close component is disabled.
125
+ * When `true`, the component will be in a disabled state and cannot be interacted with.
126
+ * @defaultValue false
127
+ * @Android
128
+ * @iOS
129
+ * @Harmony
130
+ * @zh 确定关闭组件是否被禁用。当值为 `true` 时,组件将处于禁用状态,无法进行交互。
131
+ */
132
+ disabled?: boolean
133
+ /**
134
+ * If set to true, the className will has the transition classes like 'ui-entering', 'ui-leaving', 'ui-animating'
135
+ * @Android
136
+ * @iOS
137
+ * @Harmony
138
+ * @zh 如果设置为 true,则 className 会包含 'ui-entering', 'ui-leaving', 'ui-animating' 等动画相关类名
139
+ */
140
+ transition?: boolean
141
+ }
142
+
143
+ /**
144
+ * The close component of the Dialog, used to close the dialog.
145
+ * @zh 弹窗的关闭组件,用于关闭弹窗。
146
+ */
147
+ export interface DialogCloseProps extends ComponentBasicProps {
148
+ /**
149
+ * The content of the close component. It can be a function that returns a `ReactNode` or a `ReactNode` itself.
150
+ * @Android
151
+ * @iOS
152
+ * @Harmony
153
+ * @zh 关闭组件的内容。它可以是一个返回 `ReactNode` 的函数,也可以是一个 `ReactNode` 本身。
154
+ */
155
+ children:
156
+ | TriggerChildrenType
157
+ | ReactNode
158
+ /**
159
+ * Determines whether the close component is disabled.
160
+ * When `true`, the component will be in a disabled state and cannot be interacted with.
161
+ * @defaultValue false
162
+ * @Android
163
+ * @iOS
164
+ * @Harmony
165
+ * @zh 确定关闭组件是否被禁用。 当值为 `true` 时,组件将处于禁用状态,无法进行交互。
166
+ */
167
+ disabled?: boolean
168
+ /**
169
+ * If set to true, the className will has the transition classes like 'ui-entering', 'ui-leaving', 'ui-animating'
170
+ * @Android
171
+ * @iOS
172
+ * @Harmony
173
+ * @zh 如果设置为 true,则 className 会包含 'ui-entering', 'ui-leaving', 'ui-animating' 等动画相关类名
174
+ */
175
+ transition?: boolean
176
+ }
177
+ /**
178
+ * The root component of the Dialog, containing all of its child components.
179
+ * @zh 弹窗的根组件,包含其所有子组件。
180
+ */
181
+ export interface DialogRootProps {
182
+ /**
183
+ * children
184
+ * @zh 子元素
185
+ * @Android
186
+ * @iOS
187
+ * @Harmony
188
+ * @docTypeFallback ReactNode | (status: {open?: boolean, closed?: boolean, leaving?: boolean, entering?: boolean, animating?: boolean)} => ReactNode
189
+ */
190
+ children?: ReactNode | PresenceChildrenType
191
+ /**
192
+ * Whether to show the popper. If this property is not set, the popper will be in controlled mode, meaning the defaultShow property will take no effects. And you have to control behavior of clicking close button and backdrop.
193
+ * @zh 是否显示弹出框。如果未设置此属性,弹出框将处于受控模式,这意味着 defaultShow 属性将无效。并且你必须控制点击关闭按钮和背景的行为。
194
+ * @Android
195
+ * @iOS
196
+ * @Harmony
197
+ */
198
+ show?: boolean
199
+ /**
200
+ * Determines whether the dialog should be shown by default. Use this property means the Dialog is uncontrolled.
201
+ * @defaultValue false
202
+ * @Android
203
+ * @iOS
204
+ * @Harmony
205
+ * @zh 确定弹窗是否默认显示。使用此属性意味着弹窗处于非受控模式。
206
+ */
207
+ defaultShow?: boolean
208
+ /**
209
+ * Mount the popper and render the content even when it's not shown. At this time, the internal state is "closed".
210
+ * @defaultValue false
211
+ * @Android
212
+ * @iOS
213
+ * @Harmony
214
+ * @zh 即使弹窗未显示,也会挂载弹窗并渲染内容。此时内部状态处于 closed
215
+ */
216
+ forceMount?: boolean
217
+ /**
218
+ * Triggered when the dialog is about to be closed, which can be triggered by clicking the backdrop or via a close button. In controlled mode (when `show` is provided), you should use this handler to update the state that controls the dialog's visibility. In uncontrolled mode, this handler is optional and is called before the dialog's internal state is updated.
219
+ * @Android
220
+ * @iOS
221
+ * @Harmony
222
+ * @zh 当弹窗即将关闭时触发,可通过点击背景或关闭按钮触发。在受控模式下(提供了 `show` 属性),您应该使用此处理器来更新控制弹窗可见性的状态。在非受控模式下,此处理器是可选的,会在弹窗内部状态更新之前调用。
223
+ */
224
+ onShowChange?: (open: boolean) => void
225
+ /**
226
+ * Triggered when the popper is actually show and the potential animation is finished.
227
+ * @zh 当弹出框实际显示且可能的动画结束时触发。
228
+ * @Android
229
+ * @iOS
230
+ * @Harmony
231
+ */
232
+ onOpen?: () => void
233
+ /**
234
+ * Triggered when the popper is actually closed and the potential animation is finished.
235
+ * @zh 当弹出框实际关闭且可能的动画结束时触发。
236
+ * @Android
237
+ * @iOS
238
+ * @Harmony
239
+ */
240
+ onClose?: () => void
241
+ /**
242
+ * Display debug logs. Open it when you find a bug.
243
+ * @Android
244
+ * @iOS
245
+ * @Harmony
246
+ * @zh 显示调试日志。发现 bug 时开启。
247
+ */
248
+ debugLog?: boolean
249
+ }
250
+
251
+ /**
252
+ * 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.
253
+ * @zh 视图容器。当正确设置 'container' 时,底层将替换为 overlay;否则,将是一个普通视图。当底层为 overlay 时,可以使用 'level' 属性控制层级关系。对于普通视图,使用 'z-index' 控制层级关系。如果此弹窗需要在 LynxView 外部使用,考虑启用 overlay。
254
+ */
255
+ export interface DialogViewProps extends ComponentBasicProps {
256
+ /**
257
+ * id
258
+ * @Android
259
+ * @iOS
260
+ * @Harmony
261
+ * @zh 标识符
262
+ */
263
+ id?: string
264
+ /**
265
+ * children
266
+ * @Android
267
+ * @iOS
268
+ * @Harmony
269
+ * @zh 子元素
270
+ * @docTypeFallback ReactNode | (status: {open?: boolean, closed?: boolean, leaving?: boolean, entering?: boolean, animating?: boolean)} => ReactNode
271
+ */
272
+ children:
273
+ | ReactNode
274
+ | PresenceChildrenType
275
+ /**
276
+ * If set to true, the className will has the transition classes like 'ui-entering', 'ui-leaving', 'ui-animating'
277
+ * @Android
278
+ * @iOS
279
+ * @Harmony
280
+ * @zh 如果设置为 true,则 className 会包含 'ui-entering', 'ui-leaving', 'ui-animating' 等动画相关类名
281
+ */
282
+ transition?: boolean
283
+ /**
284
+ * If you want to use the poppers outside of the LynxView, you need to set this property. The value is the name of the native container.
285
+ * @Android
286
+ * @iOS
287
+ * @Harmony
288
+ * @zh 如果你想在 LynxView 外部使用弹出框,则需要设置此属性。值为原生容器的名称。
289
+ */
290
+ container?: string
291
+ /**
292
+ * Only works when the 'container' is set to non-empty string. Adjust nearby elements display level.
293
+ * @Android
294
+ * @iOS
295
+ * @Harmony
296
+ * @zh 仅当 'container' 设置为非空字符串时有效。调整附近元素的显示层级。
297
+ */
298
+ overlayLevel?: 1 | 2 | 3 | 4
299
+ /**
300
+ * Display debug logs. Open it when you find a bug.
301
+ * @Android
302
+ * @iOS
303
+ * @Harmony
304
+ * @zh 显示调试日志。发现 bug 时开启。
305
+ */
306
+ debugLog?: boolean
307
+ /**
308
+ * Additional props that will be spread to the underlying OverlayView element
309
+ * @zh 将被直接传递到底层 OverlayView 元素的额外 view 或 overlay 属性
310
+ * @Android
311
+ * @iOS
312
+ * @Harmony
313
+ */
314
+ dialogViewProps?: OverlayProps | ViewProps
315
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ export type * from './index.docs'
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tools/configs/tsconfig.docs.json",
3
+ "include": [
4
+ "src",
5
+ "dist/types/index.docs.d.ts"
6
+ ]
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tools/configs/tsconfig.lib.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ },
6
+ "include": [
7
+ "src",
8
+ ],
9
+ }
File without changes