react-modal-navigation 1.1.3 → 1.1.5

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/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:var(--pmn-overlay-card);backdrop-filter:blur(1px)}.pmn-loading-card{display:flex;flex-direction:column;align-items:center;gap:12px;max-width:85%;padding:20px 28px;border-radius:12px;background:var(--pmn-surface);box-shadow:0 10px 20px rgba(0,0,0,.15)}.pmn-spinner{width:36px;height:36px;border:3px solid #2563eb;border-top-color:transparent;border-radius:50%;animation:pmn-spin 1s linear infinite}@keyframes pmn-spin{to{transform:rotate(360deg)}}
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
 
@@ -57,3 +63,15 @@
57
63
  .pmn-exiting.pmn-place-bottom .pmn-dialog{animation-name:pmn-bottom-out}
58
64
  .pmn-no-animation,.pmn-no-animation .pmn-dialog{animation:none!important}
59
65
  @media(prefers-reduced-motion:reduce){.pmn-entering,.pmn-exiting,.pmn-entering .pmn-dialog,.pmn-exiting .pmn-dialog{animation:none!important}}
66
+
67
+ /* Modal-local toast region; clipped by .pmn-dialog and never portaled outside. */
68
+ .pmn-toast-region{position:absolute;top:56px;left:12px;right:12px;z-index:80;display:flex;flex-direction:column;align-items:center;gap:8px;pointer-events:none;max-height:calc(100% - 72px);overflow:hidden}
69
+ .pmn-toast{pointer-events:auto;display:flex;align-items:flex-start;gap:10px;width:max-content;max-width:100%;min-width:min(260px,100%);padding:11px 13px;border:1px solid var(--pmn-border);border-radius:9px;background:var(--pmn-surface);color:var(--pmn-text);box-shadow:0 5px 18px rgba(0,0,0,.10);font-size:13px;line-height:1.5;overflow-wrap:anywhere}
70
+ .pmn-toast-symbol{flex:0 0 20px;display:grid;place-items:center;width:20px;height:20px;border-radius:50%;font-size:13px;font-weight:700;background:var(--pmn-hover);color:var(--pmn-muted)}
71
+ .pmn-toast-success .pmn-toast-symbol{background:#dcfce7;color:#15803d}
72
+ .pmn-toast-error .pmn-toast-symbol{background:#fee2e2;color:#b91c1c}
73
+ .pmn-toast-warning .pmn-toast-symbol{background:#fef3c7;color:#b45309}
74
+ .pmn-toast-info .pmn-toast-symbol{background:#dbeafe;color:#1d4ed8}
75
+ .pmn-toast-message{flex:1;min-width:0;white-space:pre-wrap}
76
+ .pmn-toast-close{border:0;background:transparent;color:var(--pmn-muted);cursor:pointer;font-size:19px;line-height:18px;padding:0 1px}
77
+ .pmn-toast-close:hover{color:var(--pmn-text)}
package/docs/API.md CHANGED
@@ -443,3 +443,114 @@ 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
+
519
+
520
+
521
+ ## 弹窗内部 Toast 消息提醒
522
+
523
+ `useToast()` 只在当前弹窗的范围内显示消息,不会向全局 `document.body` 添加通知。支持成功、错误、警告、信息四种状态,最多同时显示 5 条;默认 3000ms 后自动消失。
524
+
525
+ ```jsx
526
+ import { useToast } from 'react-modal-navigation';
527
+ import { useTranslation } from 'react-i18next';
528
+
529
+ function EditDevice() {
530
+ const toast = useToast();
531
+ const { t } = useTranslation();
532
+ const save = async () => {
533
+ try {
534
+ await saveDevice();
535
+ toast.success(t('device.saveSuccess'));
536
+ } catch (error) {
537
+ toast.error(t('device.saveFailed'), { duration: 5000 });
538
+ }
539
+ };
540
+ return <button onClick={save}>{t('common.save')}</button>;
541
+ }
542
+ ```
543
+
544
+ ```jsx
545
+ const toast = useToast();
546
+ toast('操作提示'); // 默认 info
547
+ toast.info('请先填写名称');
548
+ toast.success('保存成功');
549
+ toast.warning('设备暂时离线');
550
+ toast.error('保存失败', { duration: 5000 });
551
+ const id = toast('持续提醒', { duration: 0 }); // 不自动关闭
552
+ toast.dismiss(id); // 关闭指定消息
553
+ toast.clear(); // 清空当前弹窗消息
554
+ ```
555
+
556
+ `duration` 单位毫秒;设为 `0` 则不自动消失。`dismissible: false` 隐藏关闭按钮。消息区域始终限制在弹窗内,弹窗关闭时通知自动销毁。国际化文案由业务侧调用 `t()` 后传入。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-modal-navigation",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "React 19 modal navigation with automatic built-in CSS, Promise results and typed hooks",
5
5
  "type": "module",
6
6
  "license": "MIT",