react-modal-navigation 1.1.3 → 1.1.4
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.
- package/CHANGELOG.md +3 -0
- package/README.md +60 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +385 -378
- package/dist/style.css +7 -1
- package/docs/API.md +73 -0
- package/package.json +1 -1
package/dist/style.css
CHANGED
|
@@ -15,7 +15,13 @@
|
|
|
15
15
|
.pmn-icon-button{display:inline-flex;align-items:center;justify-content:center;padding:8px;border:0;background:transparent;color:inherit;border-radius:8px;cursor:pointer}.pmn-icon-button:hover{background:var(--pmn-hover)}
|
|
16
16
|
.pmn-footer{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;gap:12px;padding:16px 20px;background:transparent}.pmn-border-top{border-top:1px solid var(--pmn-border)}
|
|
17
17
|
.pmn-button{padding:8px 16px;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}.pmn-button:disabled{opacity:.5;cursor:not-allowed}.pmn-button-secondary{border:1px solid var(--pmn-border);background:transparent;color:var(--pmn-text)}.pmn-button-secondary:hover:not(:disabled){background:var(--pmn-hover)}.pmn-button-primary{border:1px solid #2563eb;background:#2563eb;color:white}.pmn-button-primary:hover:not(:disabled){background:#1d4ed8}
|
|
18
|
-
.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:
|
|
18
|
+
.pmn-loading-overlay{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,.72);backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px);cursor:progress}
|
|
19
|
+
.pmn-dialog[data-modal-theme=dark] .pmn-loading-overlay{background:rgba(15,23,42,.72)}
|
|
20
|
+
.pmn-loading-content{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;max-width:85%;text-align:center;color:var(--pmn-text);pointer-events:none}
|
|
21
|
+
.pmn-loading-text{font-size:14px;font-weight:500;line-height:1.5;overflow-wrap:anywhere}
|
|
22
|
+
.pmn-spinner{width:38px;height:38px;border:3px solid rgba(37,99,235,.2);border-top-color:#2563eb;border-radius:50%;animation:pmn-spin .8s linear infinite}
|
|
23
|
+
@keyframes pmn-spin{to{transform:rotate(360deg)}}
|
|
24
|
+
@media (prefers-reduced-motion:reduce){.pmn-spinner{animation-duration:1.8s}}
|
|
19
25
|
.pmn-error{position:absolute;z-index:60;bottom:8px;left:12px;right:12px;display:flex;justify-content:space-between;gap:12px;padding:12px;border:1px solid #fca5a5;border-radius:8px;background:#fef2f2;color:#991b1b;font-size:13px}.pmn-error button{border:0;background:transparent;font-size:20px;cursor:pointer;color:inherit}
|
|
20
26
|
.pmn-dialog input:not([type=checkbox]):not([type=radio]),.pmn-dialog textarea,.pmn-dialog select{color:var(--pmn-text);border-color:var(--pmn-border)}
|
|
21
27
|
|
package/docs/API.md
CHANGED
|
@@ -443,3 +443,76 @@ await modal.enqueueAsync({ name: 'userModal', screen: 'UserEdit' });
|
|
|
443
443
|
|
|
444
444
|
`screen` 不属于 `ModalOptions`,不会传入 CSS/布局配置;不存在的页面抛出 Error。
|
|
445
445
|
`open` 和 `openAsync` 的字符串签名保持兼容。
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
## navigation.setOptions(options) — 动态设置当前页面选项
|
|
449
|
+
|
|
450
|
+
**签名**:`setOptions(options: ModalScreenOptions): void`。参数必须为非空对象(允许 `{}`),数组与 `null` 会抛出 `TypeError`。更新采用浅合并;只影响当前路由实例,切换到其他路由时使用该路由自己的配置。
|
|
451
|
+
|
|
452
|
+
优先级:`screens[route.name]` 的页面默认配置 < 当前路由 `setOptions()` 覆盖配置。`setOptions` 可动态修改 `title`、`showTitle`、`showBackButton`、`renderHeader`、`renderHeaderRight`、`renderFooter`、`showFooter` 等页面级选项;弹窗尺寸与位置应使用 `modal.update()`。
|
|
453
|
+
|
|
454
|
+
```jsx
|
|
455
|
+
function UserDetail({ route, navigation }) {
|
|
456
|
+
const userId = route.params?.userId;
|
|
457
|
+
React.useEffect(() => {
|
|
458
|
+
navigation.setOptions({
|
|
459
|
+
title: `用户详情 ${userId}`,
|
|
460
|
+
showBackButton: true,
|
|
461
|
+
renderHeaderRight: () => <button onClick={() => console.log(userId)}>刷新</button>,
|
|
462
|
+
});
|
|
463
|
+
}, [navigation.setOptions, userId]);
|
|
464
|
+
return <div>{userId}</div>;
|
|
465
|
+
}
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
**获取参数的三种方式:**
|
|
469
|
+
|
|
470
|
+
```jsx
|
|
471
|
+
// 方式一:页面组件的 route 属性(推荐)
|
|
472
|
+
function EditUser({ route }) { const userId = route.params?.userId; return <div>{userId}</div>; }
|
|
473
|
+
|
|
474
|
+
// 方式二:从 useModal 获取当前路由
|
|
475
|
+
function EditUser() {
|
|
476
|
+
const { navigation } = useModal();
|
|
477
|
+
const userId = navigation.currentRoute?.params?.userId;
|
|
478
|
+
return <div>{userId}</div>;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// 方式三:useModalNavigation
|
|
482
|
+
function EditUser() {
|
|
483
|
+
const navigation = useModalNavigation();
|
|
484
|
+
const userId = navigation.currentRoute?.params?.userId;
|
|
485
|
+
return <div>{userId}</div>;
|
|
486
|
+
}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
**参数来源:** `modal.open({ name, screen, params })` 初始化首屏参数;`navigation.navigate(name, params)` / `replace(name, params)` / `reset(name, params)` 传递目标页面参数;`navigation.setParams({ field: value })` 浅合并当前页面参数。
|
|
490
|
+
|
|
491
|
+
**注意:** `setOptions()` 不会更改 `route.params`,`setParams()` 也不会直接修改 `title`。当 `title` 是基于参数的函数时,`setParams()` 更新参数后会触发重新渲染。动态覆盖选项在对应路由被移除后清除。
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
## Footer 异步操作与整窗 Loading
|
|
495
|
+
|
|
496
|
+
默认 Footer 的 `done` / `cancel` 返回 Promise 时,执行期间自动展示 `ModalLoading` 蒙层,覆盖整个弹窗并阻止交互,结束时自动撤销。显示文本为 `loadingText ?? translate('modal.processing')`。
|
|
497
|
+
|
|
498
|
+
```jsx
|
|
499
|
+
useModalFooter({
|
|
500
|
+
doneText: t('common.save'),
|
|
501
|
+
loadingText: t('common.saving'),
|
|
502
|
+
done: async () => await save(),
|
|
503
|
+
});
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
页面手动控制 Loading 仍可使用 `useModalLoading()` 和 `modal.setLoading()`。
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
### 整窗 Loading 蒙层
|
|
510
|
+
|
|
511
|
+
`useModalLoading()` / `modal.setLoading()` 触发的 Loading 覆盖整个弹窗(Header、页面内容和 Footer),居中展示无卡片、无阴影的旋转圆圈及可国际化文案。背景使用半透明蒙层,弹窗内的操作在加载期间被遮挡。
|
|
512
|
+
|
|
513
|
+
```jsx
|
|
514
|
+
modal.setLoading(true, { text: t("common.loading") });
|
|
515
|
+
// 请求结束后
|
|
516
|
+
modal.setLoading(false);
|
|
517
|
+
```
|
|
518
|
+
|