@blocklet/ui-react 3.0.38 → 3.0.41
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/lib/Dashboard/index.js +52 -53
- package/lib/Footer/links.js +4 -3
- package/lib/Header/index.d.ts +0 -1
- package/lib/Header/index.js +96 -86
- package/lib/common/header-addons.d.ts +1 -3
- package/lib/common/header-addons.js +51 -112
- package/lib/common/wizard-modal.d.ts +3 -1
- package/lib/common/wizard-modal.js +61 -52
- package/package.json +5 -5
- package/src/Dashboard/index.jsx +0 -1
- package/src/Footer/Footer.stories.jsx +2 -1
- package/src/Footer/links.jsx +1 -0
- package/src/Header/index.tsx +32 -9
- package/src/common/header-addons.jsx +8 -78
- package/src/common/wizard-modal.jsx +12 -3
- package/src/common/wizard-example.md +0 -168
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
|
-
import { Box, CircularProgress, Dialog, useMediaQuery, useTheme } from '@mui/material';
|
|
2
|
+
import { Box, CircularProgress, Dialog, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { useEffect, useRef, useState } from 'react';
|
|
5
5
|
import { joinURL, withQuery } from 'ufo';
|
|
6
6
|
|
|
7
7
|
const DEFAULT_WIZARD_PATH = '/.well-known/service/wizard/bind-account';
|
|
8
8
|
|
|
9
|
-
export default function WizardModal({
|
|
9
|
+
export default function WizardModal({
|
|
10
|
+
onFinished = () => {},
|
|
11
|
+
show = false,
|
|
12
|
+
onChangeVisible = () => {},
|
|
13
|
+
loadingText = '',
|
|
14
|
+
}) {
|
|
10
15
|
const [open, setOpen] = useState(show);
|
|
11
16
|
const [loaded, setLoaded] = useState(false);
|
|
12
17
|
const [currentUrl, setCurrentUrl] = useState(() => {
|
|
@@ -169,7 +174,10 @@ export default function WizardModal({ onFinished = () => {}, show = false, onCha
|
|
|
169
174
|
alignItems: 'center',
|
|
170
175
|
bgcolor: 'background.paper',
|
|
171
176
|
}}>
|
|
172
|
-
<
|
|
177
|
+
<Box sx={{ display: 'flex', alignItems: 'center', flexDirection: 'column', gap: 1 }}>
|
|
178
|
+
<CircularProgress />
|
|
179
|
+
{typeof loadingText === 'string' ? <Typography variant="body1">{loadingText}</Typography> : loadingText}
|
|
180
|
+
</Box>
|
|
173
181
|
</Box>
|
|
174
182
|
)}
|
|
175
183
|
</Dialog>
|
|
@@ -180,4 +188,5 @@ WizardModal.propTypes = {
|
|
|
180
188
|
onFinished: PropTypes.func,
|
|
181
189
|
show: PropTypes.bool,
|
|
182
190
|
onChangeVisible: PropTypes.func,
|
|
191
|
+
loadingText: PropTypes.node,
|
|
183
192
|
};
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
# WizardModal 使用示例
|
|
2
|
-
|
|
3
|
-
WizardModal 是一个自动弹窗的 iframe 组件,用于在页面加载时显示向导界面。
|
|
4
|
-
|
|
5
|
-
## 基本用法
|
|
6
|
-
|
|
7
|
-
### 在 Header 组件中使用
|
|
8
|
-
|
|
9
|
-
```jsx
|
|
10
|
-
import { Header } from '@arcblock/blocklet-ui-react';
|
|
11
|
-
|
|
12
|
-
function App() {
|
|
13
|
-
return (
|
|
14
|
-
<Header
|
|
15
|
-
meta={blockletMeta}
|
|
16
|
-
// 默认不显示 wizard 按钮,设置为 true 启用
|
|
17
|
-
showWizard={true}
|
|
18
|
-
/>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### 默认行为
|
|
24
|
-
|
|
25
|
-
```jsx
|
|
26
|
-
// 默认不显示 wizard 按钮
|
|
27
|
-
<Header meta={blockletMeta} />
|
|
28
|
-
|
|
29
|
-
// 显示 wizard 按钮
|
|
30
|
-
<Header meta={blockletMeta} showWizard={true} />
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### 重置向导状态
|
|
34
|
-
|
|
35
|
-
```javascript
|
|
36
|
-
// 清除已完成标记,下次刷新页面时会重新显示向导
|
|
37
|
-
localStorage.removeItem('wizard-completed');
|
|
38
|
-
window.location.reload();
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### 启用向导
|
|
42
|
-
|
|
43
|
-
```jsx
|
|
44
|
-
<Header
|
|
45
|
-
meta={blockletMeta}
|
|
46
|
-
showWizard={true} // 设置为 true 显示向导按钮
|
|
47
|
-
/>
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### 自定义向导 URL
|
|
51
|
-
|
|
52
|
-
```jsx
|
|
53
|
-
<Header
|
|
54
|
-
meta={blockletMeta}
|
|
55
|
-
wizardUrl="/.well-known/service/wizard/custom-setup"
|
|
56
|
-
onWizardFinished={(data) => {
|
|
57
|
-
console.log('自定义向导完成:', data);
|
|
58
|
-
}}
|
|
59
|
-
/>
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### 使用外部 URL
|
|
63
|
-
|
|
64
|
-
```jsx
|
|
65
|
-
<Header
|
|
66
|
-
meta={blockletMeta}
|
|
67
|
-
wizardUrl="https://external-wizard.example.com/setup"
|
|
68
|
-
onWizardFinished={(data) => {
|
|
69
|
-
console.log('外部向导完成:', data);
|
|
70
|
-
}}
|
|
71
|
-
/>
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## 直接使用 WizardModal 组件
|
|
75
|
-
|
|
76
|
-
```jsx
|
|
77
|
-
import { WizardModal } from '@arcblock/blocklet-ui-react/lib/common/wizard-modal';
|
|
78
|
-
|
|
79
|
-
function MyComponent() {
|
|
80
|
-
const [showWizard, setShowWizard] = useState(false);
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<div>
|
|
84
|
-
<button onClick={() => setShowWizard(true)}>打开向导</button>
|
|
85
|
-
|
|
86
|
-
<WizardModal
|
|
87
|
-
open={showWizard}
|
|
88
|
-
wizardUrl="/.well-known/service/wizard/bind-account"
|
|
89
|
-
onFinished={(data) => {
|
|
90
|
-
console.log('向导完成:', data);
|
|
91
|
-
setShowWizard(false);
|
|
92
|
-
}}
|
|
93
|
-
/>
|
|
94
|
-
</div>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## 向导页面消息通信
|
|
100
|
-
|
|
101
|
-
向导页面可以通过 postMessage 与父页面通信:
|
|
102
|
-
|
|
103
|
-
### 向导页面发送消息
|
|
104
|
-
|
|
105
|
-
```javascript
|
|
106
|
-
// 通知父页面向导已加载完成
|
|
107
|
-
window.parent.postMessage(
|
|
108
|
-
{
|
|
109
|
-
type: 'wizard.loaded',
|
|
110
|
-
},
|
|
111
|
-
window.location.origin
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
// 通知父页面向导已完成
|
|
115
|
-
window.parent.postMessage(
|
|
116
|
-
{
|
|
117
|
-
type: 'wizard.finished',
|
|
118
|
-
data: { success: true, result: 'setup-complete' },
|
|
119
|
-
},
|
|
120
|
-
window.location.origin
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
// 通知父页面关闭向导
|
|
124
|
-
window.parent.postMessage(
|
|
125
|
-
{
|
|
126
|
-
type: 'wizard.close',
|
|
127
|
-
},
|
|
128
|
-
window.location.origin
|
|
129
|
-
);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## Props 说明
|
|
133
|
-
|
|
134
|
-
### Header 组件新增 Props
|
|
135
|
-
|
|
136
|
-
| 属性 | 类型 | 默认值 | 说明 |
|
|
137
|
-
| ---------- | ------- | ------ | ---------------- |
|
|
138
|
-
| showWizard | boolean | false | 是否显示向导按钮 |
|
|
139
|
-
|
|
140
|
-
### WizardModal 组件 Props
|
|
141
|
-
|
|
142
|
-
| 属性 | 类型 | 默认值 | 说明 |
|
|
143
|
-
| --------------- | -------- | --------- | ------------------------------------ |
|
|
144
|
-
| show | boolean | false | 控制弹窗显示状态 |
|
|
145
|
-
| onFinished | function | undefined | 向导完成回调函数 |
|
|
146
|
-
| onChangeVisible | function | undefined | 弹窗显示状态变化回调 |
|
|
147
|
-
| onClose | function | undefined | 弹窗关闭回调(isCompleted: boolean) |
|
|
148
|
-
|
|
149
|
-
## 新增功能特性
|
|
150
|
-
|
|
151
|
-
### 1. 智能提示系统
|
|
152
|
-
|
|
153
|
-
- 点击遮罩关闭时显示 tooltip 提示:"想要再次打开 wizard 可以点击这里"
|
|
154
|
-
- Tooltip 显示 5 秒后自动消失
|
|
155
|
-
- 完成向导后不显示 tooltip
|
|
156
|
-
- 按钮在提示期间有闪烁动画效果
|
|
157
|
-
|
|
158
|
-
### 2. URL 状态保存
|
|
159
|
-
|
|
160
|
-
- 关闭 wizard 时自动保存当前 iframe 的 URL 到 localStorage
|
|
161
|
-
- 下次打开时直接加载上次的位置,继续之前的进度
|
|
162
|
-
- 完成向导后重置为默认 URL
|
|
163
|
-
|
|
164
|
-
### 3. 交互优化
|
|
165
|
-
|
|
166
|
-
- 点击遮罩或 ESC 键可以关闭弹窗
|
|
167
|
-
- 关闭时会保存当前进度
|
|
168
|
-
- 完成后自动清理临时状态
|