@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,233 @@
|
|
|
1
|
+
# Header
|
|
2
|
+
|
|
3
|
+
`Header` コンポーネントは、Blocklet アプリケーション向けにレスポンシブでカスタマイズ可能なヘッダーを提供します。Blocklet の設定 (`blocklet.yml`) から直接メタデータを読み取ることで、ナビゲーションリンク、アプリケーションのロゴ、およびユーザーセッションコントロールを自動的に設定します。このコンポーネントは、最小限の設定で一貫性のある機能豊富なヘッダーを作成するように設計されています。
|
|
4
|
+
|
|
5
|
+
## 概要
|
|
6
|
+
|
|
7
|
+
`Header` コンポーネントは、主要なナビゲーションおよびブランディング要素として機能します。これは `@arcblock/ux` のコンポーネント、`ResponsiveHeader` および `NavMenu` の上に構築されており、ユーザー認証のために DID Connect セッションコンテキストとシームレスに統合されます。
|
|
8
|
+
|
|
9
|
+
主な機能は次のとおりです。
|
|
10
|
+
- **自動設定**: `blocklet.yml` からアプリのロゴ、タイトル、ナビゲーションリンクを設定します。
|
|
11
|
+
- **レスポンシブデザイン**: さまざまな画面サイズに自動的に適応し、モバイルフレンドリーなナビゲーションメニューを提供します。
|
|
12
|
+
- **セッション管理**: DID Connect と統合し、ユーザー情報、プロフィールメニュー、ログイン/ログアウトボタンを表示します。
|
|
13
|
+
- **カスタマイズ可能なアドオン**: カスタムコンポーネントの挿入や、テーマ切り替え、ロケールセレクターなどのデフォルト要素の変更を可能にします。
|
|
14
|
+
- **組織切り替え**: Blocklet が組織サポートを有効にしている場合、自動的に組織スイッチャーを含みます。
|
|
15
|
+
- **ドメイン警告**: より良いセキュリティのためにカスタムドメインの設定を推奨するため、管理者が一時的なドメイン経由でアプリケーションにアクセスした場合に通知します。
|
|
16
|
+
|
|
17
|
+
### 仕組み
|
|
18
|
+
|
|
19
|
+
以下の図は、`Header` のデータフローとコンポーネント構成を示しています。`blocklet.yml` ファイルから設定を読み込み、それを処理して、ロゴ、ナビゲーションリンク、ユーザーセッションコントロールなど、適切な UI 要素をレンダリングします。
|
|
20
|
+
|
|
21
|
+
```d2
|
|
22
|
+
direction: down
|
|
23
|
+
|
|
24
|
+
blocklet-yml: {
|
|
25
|
+
label: "blocklet.yml"
|
|
26
|
+
shape: rectangle
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Header-Component: {
|
|
30
|
+
label: "Header コンポーネント"
|
|
31
|
+
shape: rectangle
|
|
32
|
+
|
|
33
|
+
Blocklet-Metadata-Parser: {
|
|
34
|
+
label: "メタデータパーサー"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
UI-Renderer: {
|
|
38
|
+
label: "UI レンダラー"
|
|
39
|
+
shape: rectangle
|
|
40
|
+
|
|
41
|
+
Logo
|
|
42
|
+
Navigation-Menu: {
|
|
43
|
+
label: "ナビゲーションメニュー"
|
|
44
|
+
}
|
|
45
|
+
Header-Addons: {
|
|
46
|
+
label: "ヘッダーアドオン"
|
|
47
|
+
shape: rectangle
|
|
48
|
+
grid-columns: 2
|
|
49
|
+
Session-Manager: {
|
|
50
|
+
label: "セッションマネージャー"
|
|
51
|
+
}
|
|
52
|
+
Locale-Selector: {
|
|
53
|
+
label: "ロケールセレクター"
|
|
54
|
+
}
|
|
55
|
+
Theme-Toggle: {
|
|
56
|
+
label: "テーマ切り替え"
|
|
57
|
+
}
|
|
58
|
+
Custom-Addons: {
|
|
59
|
+
label: "カスタムアドオン"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Blocklet-Metadata-Parser -> UI-Renderer: "データを提供"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
blocklet-yml -> Header-Component.Blocklet-Metadata-Parser: "設定を読み込む"
|
|
68
|
+
|
|
69
|
+
Header-Component.UI-Renderer.Logo
|
|
70
|
+
Header-Component.UI-Renderer.Navigation-Menu
|
|
71
|
+
Header-Component.UI-Renderer.Header-Addons
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 基本的な使用法
|
|
76
|
+
|
|
77
|
+
`Header` を使用するには、インポートしてアプリケーションのレイアウトに配置します。Blocklet のメタデータが必要で、これは通常 `window.blocklet` を介してグローバルに利用可能です。
|
|
78
|
+
|
|
79
|
+
```javascript "App.js" icon=logos:javascript
|
|
80
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
81
|
+
|
|
82
|
+
function App() {
|
|
83
|
+
// meta オブジェクトは通常 window.blocklet から取得されます
|
|
84
|
+
const blockletMeta = window.blocklet || {};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<div>
|
|
88
|
+
<Header meta={blockletMeta} />
|
|
89
|
+
<main>
|
|
90
|
+
{/* アプリケーションのコンテンツ */}
|
|
91
|
+
</main>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default App;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## プロパティ
|
|
100
|
+
|
|
101
|
+
`Header` コンポーネントは、カスタマイズのためにいくつかのプロパティを受け入れます。
|
|
102
|
+
|
|
103
|
+
<x-field-group>
|
|
104
|
+
<x-field data-name="meta" data-type="BlockletMetaProps" data-required="false">
|
|
105
|
+
<x-field-desc markdown>Blocklet のメタデータオブジェクト、通常は `window.blocklet` から取得します。これには、コンポーネントがレンダリングに使用する `name`、`logo`、`navigation` などの情報が含まれています。</x-field-desc>
|
|
106
|
+
</x-field>
|
|
107
|
+
<x-field data-name="addons" data-type="Function | React.ReactNode" data-required="false">
|
|
108
|
+
<x-field-desc markdown>ヘッダーの右側に追加されるカスタム要素。関数が提供された場合、組み込みのアドオンを引数として受け取り、それらを変更、並べ替え、または補足できます。ノードが提供された場合、すべての組み込みアドオンを置き換えます。</x-field-desc>
|
|
109
|
+
</x-field>
|
|
110
|
+
<x-field data-name="sessionManagerProps" data-type="SessionManagerProps" data-required="false" data-default='{ "showRole": true }'>
|
|
111
|
+
<x-field-desc markdown>基盤となる `SessionUser` コンポーネントに直接渡されるプロパティで、ユーザーのロールの表示など、ユーザーセッション情報の表示を制御します。</x-field-desc>
|
|
112
|
+
</x-field>
|
|
113
|
+
<x-field data-name="homeLink" data-type="string | Function" data-required="false" data-default="publicPath">
|
|
114
|
+
<x-field-desc markdown>ホームリンクの URL で、通常はロゴまたはブランド名をクリックするとトリガーされます。デフォルトは Blocklet の公開パス (`/`) です。JSX 要素を返す関数にすることもできます。</x-field-desc>
|
|
115
|
+
</x-field>
|
|
116
|
+
<x-field data-name="theme" data-type="object" data-required="false">
|
|
117
|
+
<x-field-desc markdown>デフォルトのテーマとマージするための Material-UI のテーマオブジェクトで、色、タイポグラフィ、その他のスタイルを詳細にカスタマイズできます。</x-field-desc>
|
|
118
|
+
</x-field>
|
|
119
|
+
<x-field data-name="hideNavMenu" data-type="boolean" data-required="false" data-default="false">
|
|
120
|
+
<x-field-desc markdown>`true` の場合、`blocklet.yml` から生成されたナビゲーションメニューは、ナビゲーションデータが存在しても非表示になります。</x-field-desc>
|
|
121
|
+
</x-field>
|
|
122
|
+
<x-field data-name="bordered" data-type="boolean" data-required="false" data-default="false">
|
|
123
|
+
<x-field-desc markdown>`true` の場合、視覚的な区分のためにヘッダーに下枠が適用されます。</x-field-desc>
|
|
124
|
+
</x-field>
|
|
125
|
+
<x-field data-name="logo" data-type="React.ReactNode" data-required="false">
|
|
126
|
+
<x-field-desc markdown>Blocklet のメタデータから取得したロゴを上書きするためのカスタムロゴ要素。</x-field-desc>
|
|
127
|
+
</x-field>
|
|
128
|
+
<x-field data-name="brand" data-type="React.ReactNode" data-required="false">
|
|
129
|
+
<x-field-desc markdown>ロゴの隣に表示するカスタムブランド要素 (例: テキストや画像)。</x-field-desc>
|
|
130
|
+
</x-field>
|
|
131
|
+
<x-field data-name="showDomainWarningDialog" data-type="boolean" data-required="false" data-default="true">
|
|
132
|
+
<x-field-desc markdown>`false` の場合、一時的なドメインに関する警告ダイアログは表示されません。</x-field-desc>
|
|
133
|
+
</x-field>
|
|
134
|
+
</x-field-group>
|
|
135
|
+
|
|
136
|
+
## 機能
|
|
137
|
+
|
|
138
|
+
### メタデータからの自動ナビゲーション
|
|
139
|
+
|
|
140
|
+
`Header` は、`blocklet.yml` ファイルの `navigation` 配列からナビゲーションメニューを自動的に生成します。コンポーネントはこの設定を解析して、プライマリナビゲーションリンクとネストされたドロップダウンメニューを作成します。
|
|
141
|
+
|
|
142
|
+
以下は、`blocklet.yml` 内の `navigation` 設定の例です。
|
|
143
|
+
|
|
144
|
+
```yaml "blocklet.yml" icon=mdi:code-braces
|
|
145
|
+
navigation:
|
|
146
|
+
- title: Features
|
|
147
|
+
link: /features
|
|
148
|
+
icon: 'mdi:star'
|
|
149
|
+
- title: Docs
|
|
150
|
+
link: /docs
|
|
151
|
+
icon: 'mdi:book-open'
|
|
152
|
+
- title: More
|
|
153
|
+
items:
|
|
154
|
+
- title: About Us
|
|
155
|
+
link: /about
|
|
156
|
+
description: Learn more about our mission.
|
|
157
|
+
- title: Community
|
|
158
|
+
link: https://community.example.com
|
|
159
|
+
description: Join our community forum.
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`parseNavigation` ユーティリティはこの構造を処理し、`title` と `description` のローカライゼーションを処理し、現在の URL パスに基づいてアクティブなリンクを決定します。
|
|
163
|
+
|
|
164
|
+
### セッション管理とアドオン
|
|
165
|
+
|
|
166
|
+
ヘッダーの右側には「アドオン」が含まれています。これらはセッション管理とアプリケーション設定のためのコントロールのコレクションです。デフォルトでは、これらには以下が含まれます。
|
|
167
|
+
|
|
168
|
+
- **組織スイッチャー**: Blocklet が組織サポートを有効にしている場合に表示されます。
|
|
169
|
+
- **通知センター**: Blocklet が通知ページを含んでいる場合に表示されます。
|
|
170
|
+
- **ロケールセレクター**: 複数の言語が設定されている場合に表示されます。
|
|
171
|
+
- **テーマモード切り替え**: ライトモードとダークモードを切り替えます。
|
|
172
|
+
- **セッションコントロール**: ログインしているユーザーのアバターと、プロフィール、設定、ログアウトへのリンクを持つメニューを表示します。ゲストには、「ウォレットに接続」ボタンが表示されます。
|
|
173
|
+
|
|
174
|
+
#### アドオンのカスタマイズ
|
|
175
|
+
|
|
176
|
+
`addons` プロパティを使用してこれらのアドオンをカスタマイズできます。
|
|
177
|
+
|
|
178
|
+
**例: カスタムボタンの追加**
|
|
179
|
+
|
|
180
|
+
`addons` プロパティに関数を指定します。この関数はデフォルトのアドオン要素の配列を受け取り、独自のアドオンを追加できます。
|
|
181
|
+
|
|
182
|
+
```javascript "HeaderWithCustomAddon.js" icon=logos:javascript
|
|
183
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
184
|
+
import Button from '@mui/material/Button';
|
|
185
|
+
|
|
186
|
+
function HeaderWithCustomAddon() {
|
|
187
|
+
return (
|
|
188
|
+
<Header
|
|
189
|
+
meta={window.blocklet}
|
|
190
|
+
addons={(builtInAddons) => (
|
|
191
|
+
<>
|
|
192
|
+
{builtInAddons}
|
|
193
|
+
<Button variant="contained" color="primary" sx={{ ml: 1 }}>
|
|
194
|
+
Upgrade
|
|
195
|
+
</Button>
|
|
196
|
+
</>
|
|
197
|
+
)}
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**例: すべてのアドオンの置き換え**
|
|
204
|
+
|
|
205
|
+
React ノードまたはノードの配列を提供して、デフォルトのアドオンを完全に置き換えます。
|
|
206
|
+
|
|
207
|
+
```javascript "HeaderWithReplacedAddons.js" icon=logos:javascript
|
|
208
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
209
|
+
import Button from '@mui/material/Button';
|
|
210
|
+
|
|
211
|
+
function HeaderWithReplacedAddons() {
|
|
212
|
+
return (
|
|
213
|
+
<Header
|
|
214
|
+
meta={window.blocklet}
|
|
215
|
+
addons={[
|
|
216
|
+
<Button key="feedback" variant="outlined" sx={{ ml: 1 }}>
|
|
217
|
+
Feedback
|
|
218
|
+
</Button>,
|
|
219
|
+
]}
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 埋め込みモードでの非表示
|
|
226
|
+
|
|
227
|
+
`Header` は `withHideWhenEmbed` 高階コンポーネントでラップされています。アプリケーションが埋め込みコンテキストでレンダリングされる場合 (例: `sessionStorage` に `EMBED_MODE_KEY: 1` が含まれる iframe 内)、自動的に非表示になります。これは、Blocklet が別のアプリケーションに統合された際に、よりクリーンな UI を提供するのに役立ちます。
|
|
228
|
+
|
|
229
|
+
## まとめ
|
|
230
|
+
|
|
231
|
+
`Header` コンポーネントは、Blocklet アプリケーション全体で一貫したブランディングとナビゲーションを確立するための強力なツールです。Blocklet のメタデータを活用することで、開発を簡素化し、プロパティを通じて広範なカスタマイズを提供します。
|
|
232
|
+
|
|
233
|
+
関連するレイアウトコンポーネントについては、[Footer](./components-layout-footer.md) のドキュメントを参照してください。
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Header
|
|
2
|
+
|
|
3
|
+
The `Header` component provides a responsive and customizable header for a Blocklet application. It automatically populates navigation links, the application logo, and user session controls by reading metadata directly from the blocklet's configuration (`blocklet.yml`). This component is designed to create a consistent and feature-rich header with minimal configuration.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The `Header` component serves as a primary navigation and branding element. It is built on top of `@arcblock/ux` components, including `ResponsiveHeader` and `NavMenu`, and integrates seamlessly with the DID Connect session context for user authentication.
|
|
8
|
+
|
|
9
|
+
Key features include:
|
|
10
|
+
- **Automatic Configuration**: Populates the app logo, title, and navigation links from `blocklet.yml`.
|
|
11
|
+
- **Responsive Design**: Adapts automatically to different screen sizes, providing a mobile-friendly navigation menu.
|
|
12
|
+
- **Session Management**: Integrates with DID Connect to display user information, profile menus, and login/logout buttons.
|
|
13
|
+
- **Customizable Addons**: Allows for the injection of custom components or modification of default elements like the theme toggle and locale selector.
|
|
14
|
+
- **Organization Switching**: Automatically includes an organization switcher if the blocklet has organization support enabled.
|
|
15
|
+
- **Domain Warnings**: Notifies administrators and users when accessing the application via a temporary domain to encourage custom domain configuration for better security.
|
|
16
|
+
|
|
17
|
+
### How It Works
|
|
18
|
+
|
|
19
|
+
The diagram below illustrates the data flow and component composition of the `Header`. It reads configuration from the `blocklet.yml` file, processes it, and renders the appropriate UI elements, including the logo, navigation links, and user session controls.
|
|
20
|
+
|
|
21
|
+
```d2
|
|
22
|
+
direction: down
|
|
23
|
+
|
|
24
|
+
blocklet-yml: {
|
|
25
|
+
label: "blocklet.yml"
|
|
26
|
+
shape: rectangle
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Header-Component: {
|
|
30
|
+
label: "Header Component"
|
|
31
|
+
shape: rectangle
|
|
32
|
+
|
|
33
|
+
Blocklet-Metadata-Parser: {
|
|
34
|
+
label: "Metadata Parser"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
UI-Renderer: {
|
|
38
|
+
label: "UI Renderer"
|
|
39
|
+
shape: rectangle
|
|
40
|
+
|
|
41
|
+
Logo
|
|
42
|
+
Navigation-Menu: {
|
|
43
|
+
label: "Navigation Menu"
|
|
44
|
+
}
|
|
45
|
+
Header-Addons: {
|
|
46
|
+
label: "Header Addons"
|
|
47
|
+
shape: rectangle
|
|
48
|
+
grid-columns: 2
|
|
49
|
+
Session-Manager: {
|
|
50
|
+
label: "Session Manager"
|
|
51
|
+
}
|
|
52
|
+
Locale-Selector: {
|
|
53
|
+
label: "Locale Selector"
|
|
54
|
+
}
|
|
55
|
+
Theme-Toggle: {
|
|
56
|
+
label: "Theme Toggle"
|
|
57
|
+
}
|
|
58
|
+
Custom-Addons: {
|
|
59
|
+
label: "Custom Addons"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Blocklet-Metadata-Parser -> UI-Renderer: "Provides data"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
blocklet-yml -> Header-Component.Blocklet-Metadata-Parser: "Reads config"
|
|
68
|
+
|
|
69
|
+
Header-Component.UI-Renderer.Logo
|
|
70
|
+
Header-Component.UI-Renderer.Navigation-Menu
|
|
71
|
+
Header-Component.UI-Renderer.Header-Addons
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Basic Usage
|
|
76
|
+
|
|
77
|
+
To use the `Header`, import it and place it in your application's layout. It requires the blocklet's metadata, which is typically available globally via `window.blocklet`.
|
|
78
|
+
|
|
79
|
+
```javascript "App.js" icon=logos:javascript
|
|
80
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
81
|
+
|
|
82
|
+
function App() {
|
|
83
|
+
// The meta object is usually sourced from window.blocklet
|
|
84
|
+
const blockletMeta = window.blocklet || {};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<div>
|
|
88
|
+
<Header meta={blockletMeta} />
|
|
89
|
+
<main>
|
|
90
|
+
{/* Your application content */}
|
|
91
|
+
</main>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default App;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Props
|
|
100
|
+
|
|
101
|
+
The `Header` component accepts several props for customization.
|
|
102
|
+
|
|
103
|
+
<x-field-group>
|
|
104
|
+
<x-field data-name="meta" data-type="BlockletMetaProps" data-required="false">
|
|
105
|
+
<x-field-desc markdown>The blocklet's metadata object, typically from `window.blocklet`. It contains information like `name`, `logo`, and `navigation` that the component uses for rendering.</x-field-desc>
|
|
106
|
+
</x-field>
|
|
107
|
+
<x-field data-name="addons" data-type="Function | React.ReactNode" data-required="false">
|
|
108
|
+
<x-field-desc markdown>Custom elements to be added to the right side of the header. If a function is provided, it receives the built-in addons as an argument, allowing you to modify, reorder, or supplement them. If a node is provided, it replaces all built-in addons.</x-field-desc>
|
|
109
|
+
</x-field>
|
|
110
|
+
<x-field data-name="sessionManagerProps" data-type="SessionManagerProps" data-required="false" data-default='{ "showRole": true }'>
|
|
111
|
+
<x-field-desc markdown>Props passed directly to the underlying `SessionUser` component to control the display of user session information, such as showing the user's role.</x-field-desc>
|
|
112
|
+
</x-field>
|
|
113
|
+
<x-field data-name="homeLink" data-type="string | Function" data-required="false" data-default="publicPath">
|
|
114
|
+
<x-field-desc markdown>The URL for the home link, which is typically triggered by clicking the logo or brand name. It defaults to the blocklet's public path (`/`). Can also be a function that returns a JSX element.</x-field-desc>
|
|
115
|
+
</x-field>
|
|
116
|
+
<x-field data-name="theme" data-type="object" data-required="false">
|
|
117
|
+
<x-field-desc markdown>A Material-UI theme object to merge with the default theme, allowing for deep customization of colors, typography, and other styles.</x-field-desc>
|
|
118
|
+
</x-field>
|
|
119
|
+
<x-field data-name="hideNavMenu" data-type="boolean" data-required="false" data-default="false">
|
|
120
|
+
<x-field-desc markdown>If `true`, the navigation menu generated from `blocklet.yml` will be hidden, even if navigation data exists.</x-field-desc>
|
|
121
|
+
</x-field>
|
|
122
|
+
<x-field data-name="bordered" data-type="boolean" data-required="false" data-default="false">
|
|
123
|
+
<x-field-desc markdown>If `true`, a bottom border will be applied to the header for visual separation.</x-field-desc>
|
|
124
|
+
</x-field>
|
|
125
|
+
<x-field data-name="logo" data-type="React.ReactNode" data-required="false">
|
|
126
|
+
<x-field-desc markdown>A custom logo element to override the one from the blocklet metadata.</x-field-desc>
|
|
127
|
+
</x-field>
|
|
128
|
+
<x-field data-name="brand" data-type="React.ReactNode" data-required="false">
|
|
129
|
+
<x-field-desc markdown>A custom brand element (e.g., text or an image) to display next to the logo.</x-field-desc>
|
|
130
|
+
</x-field>
|
|
131
|
+
<x-field data-name="showDomainWarningDialog" data-type="boolean" data-required="false" data-default="true">
|
|
132
|
+
<x-field-desc markdown>If `false`, the dialog warning about temporary domains will not be shown.</x-field-desc>
|
|
133
|
+
</x-field>
|
|
134
|
+
</x-field-group>
|
|
135
|
+
|
|
136
|
+
## Features
|
|
137
|
+
|
|
138
|
+
### Automatic Navigation from Metadata
|
|
139
|
+
|
|
140
|
+
The `Header` automatically generates its navigation menu from the `navigation` array in your `blocklet.yml` file. The component parses this configuration to create primary navigation links and nested dropdown menus.
|
|
141
|
+
|
|
142
|
+
Here is an example of a `navigation` configuration in `blocklet.yml`:
|
|
143
|
+
|
|
144
|
+
```yaml "blocklet.yml" icon=mdi:code-braces
|
|
145
|
+
navigation:
|
|
146
|
+
- title: Features
|
|
147
|
+
link: /features
|
|
148
|
+
icon: 'mdi:star'
|
|
149
|
+
- title: Docs
|
|
150
|
+
link: /docs
|
|
151
|
+
icon: 'mdi:book-open'
|
|
152
|
+
- title: More
|
|
153
|
+
items:
|
|
154
|
+
- title: About Us
|
|
155
|
+
link: /about
|
|
156
|
+
description: Learn more about our mission.
|
|
157
|
+
- title: Community
|
|
158
|
+
link: https://community.example.com
|
|
159
|
+
description: Join our community forum.
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The `parseNavigation` utility processes this structure, handles localization for `title` and `description`, and determines the active link based on the current URL path.
|
|
163
|
+
|
|
164
|
+
### Session Management and Addons
|
|
165
|
+
|
|
166
|
+
The right side of the header contains "addons," which are a collection of controls for session management and application settings. By default, these include:
|
|
167
|
+
|
|
168
|
+
- **Organization Switcher**: Appears if the blocklet has organization support enabled.
|
|
169
|
+
- **Notification Center**: Appears if the blocklet includes a notifications page.
|
|
170
|
+
- **Locale Selector**: Appears if multiple languages are configured.
|
|
171
|
+
- **Theme Mode Toggle**: Switches between light and dark modes.
|
|
172
|
+
- **Session Controls**: Displays the logged-in user's avatar and a menu with links for profile, settings, and logout. For guests, it shows a "Connect Wallet" button.
|
|
173
|
+
|
|
174
|
+
#### Customizing Addons
|
|
175
|
+
|
|
176
|
+
You can customize these addons using the `addons` prop.
|
|
177
|
+
|
|
178
|
+
**Example: Appending a custom button**
|
|
179
|
+
|
|
180
|
+
Provide a function to the `addons` prop. This function receives an array of the default addon elements, allowing you to add your own.
|
|
181
|
+
|
|
182
|
+
```javascript "HeaderWithCustomAddon.js" icon=logos:javascript
|
|
183
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
184
|
+
import Button from '@mui/material/Button';
|
|
185
|
+
|
|
186
|
+
function HeaderWithCustomAddon() {
|
|
187
|
+
return (
|
|
188
|
+
<Header
|
|
189
|
+
meta={window.blocklet}
|
|
190
|
+
addons={(builtInAddons) => (
|
|
191
|
+
<>
|
|
192
|
+
{builtInAddons}
|
|
193
|
+
<Button variant="contained" color="primary" sx={{ ml: 1 }}>
|
|
194
|
+
Upgrade
|
|
195
|
+
</Button>
|
|
196
|
+
</>
|
|
197
|
+
)}
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Example: Replacing all addons**
|
|
204
|
+
|
|
205
|
+
Provide a React node or an array of nodes to replace the default addons entirely.
|
|
206
|
+
|
|
207
|
+
```javascript "HeaderWithReplacedAddons.js" icon=logos:javascript
|
|
208
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
209
|
+
import Button from '@mui/material/Button';
|
|
210
|
+
|
|
211
|
+
function HeaderWithReplacedAddons() {
|
|
212
|
+
return (
|
|
213
|
+
<Header
|
|
214
|
+
meta={window.blocklet}
|
|
215
|
+
addons={[
|
|
216
|
+
<Button key="feedback" variant="outlined" sx={{ ml: 1 }}>
|
|
217
|
+
Feedback
|
|
218
|
+
</Button>,
|
|
219
|
+
]}
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Hiding in Embedded Mode
|
|
226
|
+
|
|
227
|
+
The `Header` is wrapped with the `withHideWhenEmbed` higher-order component. It will automatically be hidden when the application is rendered in an embedded context (e.g., within an iframe where `sessionStorage` contains `EMBED_MODE_KEY: 1`). This is useful for providing a cleaner UI when your blocklet is integrated into another application.
|
|
228
|
+
|
|
229
|
+
## Summary
|
|
230
|
+
|
|
231
|
+
The `Header` component is a powerful tool for establishing consistent branding and navigation across a Blocklet application. By leveraging blocklet metadata, it simplifies development while offering extensive customization through props.
|
|
232
|
+
|
|
233
|
+
For related layout components, please see the documentation for the [Footer](./components-layout-footer.md).
|