@blocklet/ui-react 3.1.47 → 3.1.49
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/.aigne/doc-smith/config.yaml +76 -0
- package/.aigne/doc-smith/history.yaml +9 -0
- package/.aigne/doc-smith/output/structure-plan.json +249 -0
- package/.aigne/doc-smith/upload-cache.yaml +528 -0
- package/docs/_sidebar.md +19 -0
- package/docs/components-component-management-blocklet-studio.ja.md +194 -0
- package/docs/components-component-management-blocklet-studio.md +194 -0
- package/docs/components-component-management-blocklet-studio.zh-TW.md +194 -0
- package/docs/components-component-management-blocklet-studio.zh.md +194 -0
- package/docs/components-component-management-component-installer.ja.md +256 -0
- package/docs/components-component-management-component-installer.md +256 -0
- package/docs/components-component-management-component-installer.zh-TW.md +256 -0
- package/docs/components-component-management-component-installer.zh.md +256 -0
- package/docs/components-component-management.ja.md +59 -0
- package/docs/components-component-management.md +59 -0
- package/docs/components-component-management.zh-TW.md +59 -0
- package/docs/components-component-management.zh.md +59 -0
- package/docs/components-layout-dashboard.ja.md +231 -0
- package/docs/components-layout-dashboard.md +231 -0
- package/docs/components-layout-dashboard.zh-TW.md +231 -0
- package/docs/components-layout-dashboard.zh.md +231 -0
- package/docs/components-layout-footer.ja.md +165 -0
- package/docs/components-layout-footer.md +165 -0
- package/docs/components-layout-footer.zh-TW.md +165 -0
- package/docs/components-layout-footer.zh.md +165 -0
- package/docs/components-layout-header.ja.md +233 -0
- package/docs/components-layout-header.md +233 -0
- package/docs/components-layout-header.zh-TW.md +233 -0
- package/docs/components-layout-header.zh.md +233 -0
- package/docs/components-layout.ja.md +50 -0
- package/docs/components-layout.md +50 -0
- package/docs/components-layout.zh-TW.md +50 -0
- package/docs/components-layout.zh.md +50 -0
- package/docs/components-notifications.ja.md +173 -0
- package/docs/components-notifications.md +173 -0
- package/docs/components-notifications.zh-TW.md +174 -0
- package/docs/components-notifications.zh.md +173 -0
- package/docs/components-user-management-user-center.ja.md +183 -0
- package/docs/components-user-management-user-center.md +183 -0
- package/docs/components-user-management-user-center.zh-TW.md +183 -0
- package/docs/components-user-management-user-center.zh.md +183 -0
- package/docs/components-user-management-user-sessions.ja.md +164 -0
- package/docs/components-user-management-user-sessions.md +164 -0
- package/docs/components-user-management-user-sessions.zh-TW.md +164 -0
- package/docs/components-user-management-user-sessions.zh.md +164 -0
- package/docs/components-user-management.ja.md +76 -0
- package/docs/components-user-management.md +76 -0
- package/docs/components-user-management.zh-TW.md +76 -0
- package/docs/components-user-management.zh.md +76 -0
- package/docs/components-utilities-icon.ja.md +106 -0
- package/docs/components-utilities-icon.md +106 -0
- package/docs/components-utilities-icon.zh-TW.md +106 -0
- package/docs/components-utilities-icon.zh.md +106 -0
- package/docs/components-utilities.ja.md +136 -0
- package/docs/components-utilities.md +136 -0
- package/docs/components-utilities.zh-TW.md +136 -0
- package/docs/components-utilities.zh.md +136 -0
- package/docs/components.ja.md +27 -0
- package/docs/components.md +27 -0
- package/docs/components.zh-TW.md +27 -0
- package/docs/components.zh.md +27 -0
- package/docs/core-concepts.ja.md +164 -0
- package/docs/core-concepts.md +164 -0
- package/docs/core-concepts.zh-TW.md +164 -0
- package/docs/core-concepts.zh.md +164 -0
- package/docs/getting-started.ja.md +132 -0
- package/docs/getting-started.md +132 -0
- package/docs/getting-started.zh-TW.md +132 -0
- package/docs/getting-started.zh.md +132 -0
- package/docs/hooks-api.ja.md +214 -0
- package/docs/hooks-api.md +214 -0
- package/docs/hooks-api.zh-TW.md +214 -0
- package/docs/hooks-api.zh.md +214 -0
- package/docs/how-to-guides.ja.md +413 -0
- package/docs/how-to-guides.md +413 -0
- package/docs/how-to-guides.zh-TW.md +413 -0
- package/docs/how-to-guides.zh.md +413 -0
- package/docs/overview.ja.md +91 -0
- package/docs/overview.md +91 -0
- package/docs/overview.zh-TW.md +91 -0
- package/docs/overview.zh.md +91 -0
- package/glossary.md +12 -0
- package/lib/Dashboard/index.js +46 -42
- package/lib/Footer/index.js +51 -36
- package/lib/Header/index.js +48 -44
- package/lib/UserCenter/components/settings.js +1 -0
- package/lib/UserCenter/components/user-center.js +133 -133
- package/lib/blocklets.d.ts +13 -2
- package/lib/blocklets.js +40 -40
- package/lib/common/header-addons.js +37 -33
- package/package.json +7 -7
- package/src/Dashboard/index.jsx +8 -3
- package/src/Footer/index.jsx +22 -4
- package/src/Header/index.tsx +7 -2
- package/src/UserCenter/components/settings.tsx +1 -0
- package/src/UserCenter/components/user-center.tsx +6 -6
- package/src/blocklets.js +18 -9
- package/src/common/header-addons.jsx +7 -2
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# Dashboard
|
|
2
|
+
|
|
3
|
+
`Dashboard` コンポーネントは、blocklet アプリケーション向けに、レスポンシブなレイアウトを事前に構築して提供します。これは通常、管理インターフェースやユーザー中心のビューに使用されます。blocklet のメタデータを解釈することで、サイドバー、ヘッダー、およびメインコンテンツエリアを持つ標準的なダッシュボードを自動的に構築します。このコンポーネントにより、一般的なアプリケーション構造を構築するための定型的なコードが大幅に削減されます。
|
|
4
|
+
|
|
5
|
+
レイアウトは、ナビゲーション用の永続的なサイドバー、グローバルなアクションとユーザー情報用のヘッダー、そしてページ固有のコンテンツがレンダリングされるメインコンテンツエリアの3つの主要なセクションで構成されています。
|
|
6
|
+
|
|
7
|
+
```d2
|
|
8
|
+
direction: down
|
|
9
|
+
|
|
10
|
+
Dashboard-Layout: {
|
|
11
|
+
label: "Dashboard コンポーネント"
|
|
12
|
+
shape: rectangle
|
|
13
|
+
grid-columns: 1
|
|
14
|
+
style: {
|
|
15
|
+
stroke: "#888"
|
|
16
|
+
stroke-width: 2
|
|
17
|
+
stroke-dash: 4
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Header: {
|
|
21
|
+
shape: rectangle
|
|
22
|
+
Logo: {}
|
|
23
|
+
HeaderAddons: {
|
|
24
|
+
label: "ヘッダーアドオン"
|
|
25
|
+
shape: rectangle
|
|
26
|
+
grid-columns: 1
|
|
27
|
+
SessionManager: {}
|
|
28
|
+
LocaleSelector: {}
|
|
29
|
+
ThemeToggle: {}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Sidebar: {
|
|
34
|
+
label: "サイドバー"
|
|
35
|
+
shape: rectangle
|
|
36
|
+
Navigation-Links: {
|
|
37
|
+
label: "ナビゲーションリンク"
|
|
38
|
+
shape: rectangle
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Content-Area: {
|
|
43
|
+
label: "コンテンツエリア"
|
|
44
|
+
shape: rectangle
|
|
45
|
+
"ページ固有のコンテンツ (children)"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Blocklet-Metadata: {
|
|
50
|
+
label: "blocklet.yml"
|
|
51
|
+
shape: cylinder
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Blocklet-Metadata -> Dashboard-Layout.Sidebar.Navigation-Links: "生成"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 基本的な使用方法
|
|
58
|
+
|
|
59
|
+
`Dashboard` コンポーネントを使用するには、ページのコンテンツをそれでラップするだけです。コンポーネントは自動的にコンテンツの周りにヘッダーとサイドバーをレンダリングします。
|
|
60
|
+
|
|
61
|
+
```javascript MyDashboard.jsx icon=logos:react
|
|
62
|
+
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
63
|
+
|
|
64
|
+
export default function MyDashboardPage() {
|
|
65
|
+
return (
|
|
66
|
+
<Dashboard>
|
|
67
|
+
<h1>Welcome to the Dashboard</h1>
|
|
68
|
+
<p>This is your main content area.</p>
|
|
69
|
+
</Dashboard>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`Dashboard` コンポーネントに渡された children は、メインコンテンツエリアに表示されます。
|
|
75
|
+
|
|
76
|
+
## Props
|
|
77
|
+
|
|
78
|
+
`Dashboard` コンポーネントは、その動作と外観をカスタマイズするために、以下の props を受け入れます。
|
|
79
|
+
|
|
80
|
+
<x-field-group>
|
|
81
|
+
<x-field data-name="children" data-type="React.ReactNode" data-required="true">
|
|
82
|
+
<x-field-desc markdown>ダッシュボードレイアウトのメインコンテンツエリア内にレンダリングされるコンテンツ。</x-field-desc>
|
|
83
|
+
</x-field>
|
|
84
|
+
<x-field data-name="meta" data-type="object" data-required="false">
|
|
85
|
+
<x-field-desc markdown>blocklet メタデータオブジェクト。指定された場合、デフォルトの `window.blocklet` メタデータとマージされ、上書きされます。これは、テストや blocklet 情報を動的に変更する場合に便利です。</x-field-desc>
|
|
86
|
+
</x-field>
|
|
87
|
+
<x-field data-name="fallbackUrl" data-type="string" data-required="false" data-default="publicPath">
|
|
88
|
+
<x-field-desc markdown>現在の認証済みユーザーがその役割に基づいてどのナビゲーションリンクにもアクセスできない場合にリダイレクトする URL。この自動リダイレクトを無効にするには `null` に設定します。</x-field-desc>
|
|
89
|
+
</x-field>
|
|
90
|
+
<x-field data-name="invalidPathFallback" data-type="function" data-required="false">
|
|
91
|
+
<x-field-desc markdown>現在の URL パスが利用可能なナビゲーションリンクのいずれとも一致しない場合に実行されるコールバック関数。デフォルトの動作は、利用可能な最初のリンクにリダイレクトすることです。</x-field-desc>
|
|
92
|
+
</x-field>
|
|
93
|
+
<x-field data-name="headerAddons" data-type="React.ReactNode | function" data-required="false">
|
|
94
|
+
<x-field-desc markdown>ヘッダーの右側のアドオンのカスタマイズを可能にします。ノードが提供された場合、すべてのデフォルトアドオンを置き換えます。関数が提供された場合、デフォルトのアドオン配列を引数として受け取り、それらを追加、削除、または並べ替えることができます。</x-field-desc>
|
|
95
|
+
</x-field>
|
|
96
|
+
<x-field data-name="sessionManagerProps" data-type="object" data-required="false">
|
|
97
|
+
<x-field-desc markdown>ヘッダー内の基盤となる `SessionUser` コンポーネントに直接渡される Props。これにより、`showRole` やカスタムの `onLogout` ハンドラの定義など、ユーザーセッションメニューのカスタマイズが可能になります。</x-field-desc>
|
|
98
|
+
</x-field>
|
|
99
|
+
<x-field data-name="links" data-type="array | function" data-required="false">
|
|
100
|
+
<x-field-desc markdown>サイドバーのナビゲーションリンクをプログラムで変更できるようにします。配列が提供された場合、そのアイテムはメタデータから生成されたリンクに追加されます。関数が提供された場合、メタデータから生成されたリンクを引数として受け取り、新しいリンクの配列を返す必要があります。</x-field-desc>
|
|
101
|
+
</x-field>
|
|
102
|
+
<x-field data-name="showDomainWarningDialog" data-type="boolean" data-required="false" data-default="true">
|
|
103
|
+
<x-field-desc markdown>`true` の場合、信頼できないドメインからアプリケーションにアクセスされた場合に警告ダイアログを表示します。</x-field-desc>
|
|
104
|
+
</x-field>
|
|
105
|
+
</x-field-group>
|
|
106
|
+
|
|
107
|
+
## 仕組み
|
|
108
|
+
|
|
109
|
+
`Dashboard` コンポーネントは、「設定駆動型」で設計されており、その構造とコンテンツは主に blocklet のメタデータファイル (`blocklet.yml`) から派生します。
|
|
110
|
+
|
|
111
|
+
### メタデータからのナビゲーション
|
|
112
|
+
|
|
113
|
+
サイドバーのナビゲーションは、`blocklet.yml` の `navigation` 配列から自動的に生成されます。コンポーネントは、`section` プロパティに `dashboard` を含むナビゲーション項目を具体的に探します。
|
|
114
|
+
|
|
115
|
+
以下は、ダッシュボードナビゲーションを定義する方法の例です。
|
|
116
|
+
|
|
117
|
+
```yaml blocklet.yml icon=mdi:file-document
|
|
118
|
+
navigation:
|
|
119
|
+
- title: 'Home'
|
|
120
|
+
link: '/'
|
|
121
|
+
section: 'dashboard'
|
|
122
|
+
icon: 'mdi:home'
|
|
123
|
+
role: ['owner', 'admin', 'guest']
|
|
124
|
+
- title: 'Analytics'
|
|
125
|
+
link: '/analytics'
|
|
126
|
+
section: 'dashboard'
|
|
127
|
+
icon: 'mdi:chart-bar'
|
|
128
|
+
role: ['owner', 'admin']
|
|
129
|
+
- title: 'Settings'
|
|
130
|
+
link: '/settings'
|
|
131
|
+
section: 'dashboard'
|
|
132
|
+
icon: 'mdi:cog'
|
|
133
|
+
role: ['owner']
|
|
134
|
+
items:
|
|
135
|
+
- title: 'Profile'
|
|
136
|
+
link: '/settings/profile'
|
|
137
|
+
- title: 'Billing'
|
|
138
|
+
link: '/settings/billing'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### ロールベースのアクセス制御
|
|
142
|
+
|
|
143
|
+
`Dashboard` コンポーネントは、ナビゲーションリンクに対してロールベースのアクセス制御 (RBAC) を強制します。各ナビゲーション項目は `role` プロパティを持つことができ、これはリンクを見ることが許可されているロールの配列です。
|
|
144
|
+
|
|
145
|
+
- ナビゲーション項目に `role` プロパティがない場合、それは誰にでも表示されます。
|
|
146
|
+
- 現在のユーザーが認証されていない場合、`guest` ロールを含む項目のみを見ることができます。
|
|
147
|
+
- 現在のユーザーが認証されている場合、コンポーネントは彼らの `user.role` を各ナビゲーション項目の `role` 配列と比較します。一致がある場合にのみ項目が表示されます。
|
|
148
|
+
- 親ナビゲーション項目は、その子の少なくとも1つが表示される場合にのみ表示されます。
|
|
149
|
+
|
|
150
|
+
上記の `blocklet.yml` の例を使用すると:
|
|
151
|
+
- `guest` ロールのユーザーは「Home」リンクのみを見ることができます。
|
|
152
|
+
- `admin` ロールのユーザーは「Home」と「Analytics」を見ることができます。
|
|
153
|
+
- `owner` ロールのユーザーは、「Settings」の下にあるネストされた「Profile」と「Billing」リンクを含むすべてのリンクを見ることができます。
|
|
154
|
+
|
|
155
|
+
### アイコン
|
|
156
|
+
|
|
157
|
+
ナビゲーション項目の `icon` プロパティは、[Iconify](https://icon-sets.iconify.design/) ライブラリのアイコン名に対応する文字列(例:`mdi:home`)である必要があります。画像ファイルへの完全な URL を提供することもできます。
|
|
158
|
+
|
|
159
|
+
## カスタマイズ
|
|
160
|
+
|
|
161
|
+
`Dashboard` はメタデータですぐに使えるように設計されていますが、より高度なカスタマイズのためのいくつかの props を提供しています。
|
|
162
|
+
|
|
163
|
+
### ヘッダーアドオンのカスタマイズ
|
|
164
|
+
|
|
165
|
+
`headerAddons` prop を使用して、デフォルトのヘッダーアドオン(例:テーマ切り替え、ロケールセレクター、セッションマネージャー)を変更できます。関数を渡すことで、新しい要素を追加したり、既存の要素を並べ替えたりすることができます。
|
|
166
|
+
|
|
167
|
+
```javascript CustomHeader.jsx icon=logos:react
|
|
168
|
+
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
169
|
+
import Button from '@mui/material/Button';
|
|
170
|
+
|
|
171
|
+
function MyCustomButton() {
|
|
172
|
+
return <Button color="inherit" onClick={() => alert('Help!')}>Help</Button>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export default function CustomDashboard() {
|
|
176
|
+
return (
|
|
177
|
+
<Dashboard
|
|
178
|
+
headerAddons={(existingAddons) => {
|
|
179
|
+
const customAddon = <MyCustomButton key="custom-help" />;
|
|
180
|
+
// Add the custom button before the other addons
|
|
181
|
+
return [customAddon, ...existingAddons];
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
<p>Dashboard with a custom header button.</p>
|
|
185
|
+
</Dashboard>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### リンクのプログラムによる追加
|
|
191
|
+
|
|
192
|
+
`links` prop を使用すると、コードから動的にサイドバーのナビゲーションリンクを追加または変更できます。これは、アプリケーションの状態に依存するリンクに便利です。
|
|
193
|
+
|
|
194
|
+
```javascript DynamicLinks.jsx icon=logos:react
|
|
195
|
+
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
196
|
+
import Icon from '@arcblock/ux/lib/Icon';
|
|
197
|
+
|
|
198
|
+
const useFeatureFlag = () => {
|
|
199
|
+
// 実際のアプリでは、ここでフィーチャーフラグサービスをチェックします
|
|
200
|
+
return true;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export default function DynamicDashboard() {
|
|
204
|
+
const isBetaFeatureEnabled = useFeatureFlag();
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<Dashboard
|
|
208
|
+
links={(existingLinks) => {
|
|
209
|
+
if (isBetaFeatureEnabled) {
|
|
210
|
+
const betaLink = {
|
|
211
|
+
id: 'beta-feature',
|
|
212
|
+
title: 'Beta Feature',
|
|
213
|
+
url: '/beta',
|
|
214
|
+
icon: <Icon name="mdi:test-tube" />,
|
|
215
|
+
external: true, // クライアントサイドのルーティングに必要
|
|
216
|
+
};
|
|
217
|
+
return [...existingLinks, betaLink];
|
|
218
|
+
}
|
|
219
|
+
return existingLinks;
|
|
220
|
+
}}
|
|
221
|
+
>
|
|
222
|
+
<p>This dashboard may have dynamic links.</p>
|
|
223
|
+
</Dashboard>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## まとめ
|
|
230
|
+
|
|
231
|
+
`Dashboard` コンポーネントは、アプリケーションのレイアウトを迅速に構築するための強力なツールです。blocklet メタデータを活用することで、構造化され、ロールを認識するナビゲーションシステムをすぐに提供します。より基本的なレイアウトコンポーネントについては、[Header](./components-layout-header.md) と [Footer](./components-layout-footer.md) のドキュメントを参照してください。
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# Dashboard
|
|
2
|
+
|
|
3
|
+
The `Dashboard` component provides a pre-built, responsive layout for blocklet applications, typically used for administrative interfaces or user-centric views. It automatically constructs a standard dashboard with a sidebar, header, and main content area by interpreting your blocklet's metadata. This component significantly reduces boilerplate code for building common application structures.
|
|
4
|
+
|
|
5
|
+
The layout is composed of three primary sections: a persistent sidebar for navigation, a header for global actions and user information, and a main content area where the page-specific content is rendered.
|
|
6
|
+
|
|
7
|
+
```d2
|
|
8
|
+
direction: down
|
|
9
|
+
|
|
10
|
+
Dashboard-Layout: {
|
|
11
|
+
label: "Dashboard Component"
|
|
12
|
+
shape: rectangle
|
|
13
|
+
grid-columns: 1
|
|
14
|
+
style: {
|
|
15
|
+
stroke: "#888"
|
|
16
|
+
stroke-width: 2
|
|
17
|
+
stroke-dash: 4
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Header: {
|
|
21
|
+
shape: rectangle
|
|
22
|
+
Logo: {}
|
|
23
|
+
HeaderAddons: {
|
|
24
|
+
label: "Header Addons"
|
|
25
|
+
shape: rectangle
|
|
26
|
+
grid-columns: 1
|
|
27
|
+
SessionManager: {}
|
|
28
|
+
LocaleSelector: {}
|
|
29
|
+
ThemeToggle: {}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Sidebar: {
|
|
34
|
+
label: "Sidebar"
|
|
35
|
+
shape: rectangle
|
|
36
|
+
Navigation-Links: {
|
|
37
|
+
label: "Navigation Links"
|
|
38
|
+
shape: rectangle
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Content-Area: {
|
|
43
|
+
label: "Content Area"
|
|
44
|
+
shape: rectangle
|
|
45
|
+
"Page-specific content (children)"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Blocklet-Metadata: {
|
|
50
|
+
label: "blocklet.yml"
|
|
51
|
+
shape: cylinder
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Blocklet-Metadata -> Dashboard-Layout.Sidebar.Navigation-Links: "Generates"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Basic Usage
|
|
58
|
+
|
|
59
|
+
To use the `Dashboard` component, simply wrap your page's content with it. The component will automatically render the header and sidebar around your content.
|
|
60
|
+
|
|
61
|
+
```javascript MyDashboard.jsx icon=logos:react
|
|
62
|
+
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
63
|
+
|
|
64
|
+
export default function MyDashboardPage() {
|
|
65
|
+
return (
|
|
66
|
+
<Dashboard>
|
|
67
|
+
<h1>Welcome to the Dashboard</h1>
|
|
68
|
+
<p>This is your main content area.</p>
|
|
69
|
+
</Dashboard>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The children passed to the `Dashboard` component will be displayed in the main content area.
|
|
75
|
+
|
|
76
|
+
## Props
|
|
77
|
+
|
|
78
|
+
The `Dashboard` component accepts the following props to customize its behavior and appearance.
|
|
79
|
+
|
|
80
|
+
<x-field-group>
|
|
81
|
+
<x-field data-name="children" data-type="React.ReactNode" data-required="true">
|
|
82
|
+
<x-field-desc markdown>The content to be rendered within the main content area of the dashboard layout.</x-field-desc>
|
|
83
|
+
</x-field>
|
|
84
|
+
<x-field data-name="meta" data-type="object" data-required="false">
|
|
85
|
+
<x-field-desc markdown>A blocklet metadata object. If provided, it will be merged with and override the default `window.blocklet` metadata. This is useful for testing or dynamically altering blocklet information.</x-field-desc>
|
|
86
|
+
</x-field>
|
|
87
|
+
<x-field data-name="fallbackUrl" data-type="string" data-required="false" data-default="publicPath">
|
|
88
|
+
<x-field-desc markdown>The URL to redirect to if the current authenticated user has no access to any navigation links based on their role. Set to `null` to disable this automatic redirection.</x-field-desc>
|
|
89
|
+
</x-field>
|
|
90
|
+
<x-field data-name="invalidPathFallback" data-type="function" data-required="false">
|
|
91
|
+
<x-field-desc markdown>A callback function that is executed when the current URL path does not match any of the available navigation links. The default behavior is to redirect to the first available link.</x-field-desc>
|
|
92
|
+
</x-field>
|
|
93
|
+
<x-field data-name="headerAddons" data-type="React.ReactNode | function" data-required="false">
|
|
94
|
+
<x-field-desc markdown>Allows for customization of the header's right-side addons. If a node is provided, it replaces all default addons. If a function is provided, it receives the default addons array as an argument, allowing you to add, remove, or reorder them.</x-field-desc>
|
|
95
|
+
</x-field>
|
|
96
|
+
<x-field data-name="sessionManagerProps" data-type="object" data-required="false">
|
|
97
|
+
<x-field-desc markdown>Props to be passed directly to the underlying `SessionUser` component in the header. This allows for customization of the user session menu, such as `showRole` or defining a custom `onLogout` handler.</x-field-desc>
|
|
98
|
+
</x-field>
|
|
99
|
+
<x-field data-name="links" data-type="array | function" data-required="false">
|
|
100
|
+
<x-field-desc markdown>Allows for programmatic modification of the sidebar navigation links. If an array is provided, its items are appended to the links generated from metadata. If a function is provided, it receives the metadata-generated links as an argument and should return a new array of links.</x-field-desc>
|
|
101
|
+
</x-field>
|
|
102
|
+
<x-field data-name="showDomainWarningDialog" data-type="boolean" data-required="false" data-default="true">
|
|
103
|
+
<x-field-desc markdown>If `true`, displays a warning dialog if the application is accessed from an untrusted domain.</x-field-desc>
|
|
104
|
+
</x-field>
|
|
105
|
+
</x-field-group>
|
|
106
|
+
|
|
107
|
+
## How It Works
|
|
108
|
+
|
|
109
|
+
The `Dashboard` component is designed to be "configuration-driven," deriving its structure and content primarily from the blocklet's metadata file (`blocklet.yml`).
|
|
110
|
+
|
|
111
|
+
### Navigation from Metadata
|
|
112
|
+
|
|
113
|
+
The sidebar navigation is automatically generated from the `navigation` array in your `blocklet.yml`. The component specifically looks for navigation items that include `dashboard` in their `section` property.
|
|
114
|
+
|
|
115
|
+
Here is an example of how to define dashboard navigation:
|
|
116
|
+
|
|
117
|
+
```yaml blocklet.yml icon=mdi:file-document
|
|
118
|
+
navigation:
|
|
119
|
+
- title: 'Home'
|
|
120
|
+
link: '/'
|
|
121
|
+
section: 'dashboard'
|
|
122
|
+
icon: 'mdi:home'
|
|
123
|
+
role: ['owner', 'admin', 'guest']
|
|
124
|
+
- title: 'Analytics'
|
|
125
|
+
link: '/analytics'
|
|
126
|
+
section: 'dashboard'
|
|
127
|
+
icon: 'mdi:chart-bar'
|
|
128
|
+
role: ['owner', 'admin']
|
|
129
|
+
- title: 'Settings'
|
|
130
|
+
link: '/settings'
|
|
131
|
+
section: 'dashboard'
|
|
132
|
+
icon: 'mdi:cog'
|
|
133
|
+
role: ['owner']
|
|
134
|
+
items:
|
|
135
|
+
- title: 'Profile'
|
|
136
|
+
link: '/settings/profile'
|
|
137
|
+
- title: 'Billing'
|
|
138
|
+
link: '/settings/billing'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Role-Based Access Control
|
|
142
|
+
|
|
143
|
+
The `Dashboard` component enforces role-based access control (RBAC) on navigation links. Each navigation item can have a `role` property, which is an array of roles that are permitted to see the link.
|
|
144
|
+
|
|
145
|
+
- If a navigation item does not have a `role` property, it is visible to everyone.
|
|
146
|
+
- If the current user is not authenticated, they can only see items that include the `guest` role.
|
|
147
|
+
- If the current user is authenticated, the component compares their `user.role` with the `role` array of each navigation item. The item is only displayed if there is a match.
|
|
148
|
+
- A parent navigation item is only visible if at least one of its children is visible.
|
|
149
|
+
|
|
150
|
+
Using the `blocklet.yml` example above:
|
|
151
|
+
- A user with the `guest` role will only see the "Home" link.
|
|
152
|
+
- A user with the `admin` role will see "Home" and "Analytics".
|
|
153
|
+
- A user with the `owner` role will see all links, including the nested "Profile" and "Billing" links under "Settings".
|
|
154
|
+
|
|
155
|
+
### Icons
|
|
156
|
+
|
|
157
|
+
The `icon` property for a navigation item should be a string that corresponds to an icon name from the [Iconify](https://icon-sets.iconify.design/) library (e.g., `mdi:home`). You can also provide a full URL to an image file.
|
|
158
|
+
|
|
159
|
+
## Customization
|
|
160
|
+
|
|
161
|
+
While the `Dashboard` is designed to work out-of-the-box with metadata, it offers several props for more advanced customization.
|
|
162
|
+
|
|
163
|
+
### Customizing Header Addons
|
|
164
|
+
|
|
165
|
+
You can modify the default header addons (e.g., Theme Toggle, Locale Selector, Session Manager) using the `headerAddons` prop. By passing a function, you can add new elements or rearrange the existing ones.
|
|
166
|
+
|
|
167
|
+
```javascript CustomHeader.jsx icon=logos:react
|
|
168
|
+
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
169
|
+
import Button from '@mui/material/Button';
|
|
170
|
+
|
|
171
|
+
function MyCustomButton() {
|
|
172
|
+
return <Button color="inherit" onClick={() => alert('Help!')}>Help</Button>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export default function CustomDashboard() {
|
|
176
|
+
return (
|
|
177
|
+
<Dashboard
|
|
178
|
+
headerAddons={(existingAddons) => {
|
|
179
|
+
const customAddon = <MyCustomButton key="custom-help" />;
|
|
180
|
+
// Add the custom button before the other addons
|
|
181
|
+
return [customAddon, ...existingAddons];
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
<p>Dashboard with a custom header button.</p>
|
|
185
|
+
</Dashboard>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Programmatically Adding Links
|
|
191
|
+
|
|
192
|
+
The `links` prop allows you to add or modify sidebar navigation links dynamically from your code. This is useful for links that depend on application state.
|
|
193
|
+
|
|
194
|
+
```javascript DynamicLinks.jsx icon=logos:react
|
|
195
|
+
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
196
|
+
import Icon from '@arcblock/ux/lib/Icon';
|
|
197
|
+
|
|
198
|
+
const useFeatureFlag = () => {
|
|
199
|
+
// In a real app, this would check a feature flag service
|
|
200
|
+
return true;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export default function DynamicDashboard() {
|
|
204
|
+
const isBetaFeatureEnabled = useFeatureFlag();
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<Dashboard
|
|
208
|
+
links={(existingLinks) => {
|
|
209
|
+
if (isBetaFeatureEnabled) {
|
|
210
|
+
const betaLink = {
|
|
211
|
+
id: 'beta-feature',
|
|
212
|
+
title: 'Beta Feature',
|
|
213
|
+
url: '/beta',
|
|
214
|
+
icon: <Icon name="mdi:test-tube" />,
|
|
215
|
+
external: true, // Required for client-side routing
|
|
216
|
+
};
|
|
217
|
+
return [...existingLinks, betaLink];
|
|
218
|
+
}
|
|
219
|
+
return existingLinks;
|
|
220
|
+
}}
|
|
221
|
+
>
|
|
222
|
+
<p>This dashboard may have dynamic links.</p>
|
|
223
|
+
</Dashboard>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Summary
|
|
230
|
+
|
|
231
|
+
The `Dashboard` component is a powerful tool for quickly scaffolding application layouts. By leveraging blocklet metadata, it provides a structured, role-aware navigation system out of the box. For more foundational layout components, see the documentation for [Header](./components-layout-header.md) and [Footer](./components-layout-footer.md).
|