@blocklet/ui-react 3.4.14 → 3.5.0
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/common/org-switch/use-org.d.ts +4 -4
- package/lib/common/ws.d.ts +22 -1
- package/package.json +10 -7
- package/.aigne/doc-smith/.local/afs-storage.sqlite3 +0 -0
- package/.aigne/doc-smith/config.yaml +0 -78
- package/.aigne/doc-smith/history.yaml +0 -14
- package/.aigne/doc-smith/media-description.yaml +0 -11
- package/.aigne/doc-smith/output/structure-plan.json +0 -255
- package/.aigne/doc-smith/translation-cache.yaml +0 -11
- package/.aigne/doc-smith/upload-cache.yaml +0 -528
- package/build.config.ts +0 -24
- package/docs/_sidebar.md +0 -19
- package/docs/assets/diagram/component-installer-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/component-installer-diagram-0.jpg +0 -0
- package/docs/assets/diagram/component-installer-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/component-installer-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/component-management-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/component-management-diagram-0.jpg +0 -0
- package/docs/assets/diagram/component-management-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/component-management-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/core-concepts-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/core-concepts-diagram-0.jpg +0 -0
- package/docs/assets/diagram/core-concepts-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/core-concepts-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/dashboard-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/dashboard-diagram-0.jpg +0 -0
- package/docs/assets/diagram/dashboard-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/dashboard-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/header-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/header-diagram-0.jpg +0 -0
- package/docs/assets/diagram/header-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/header-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/layout-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/layout-diagram-0.jpg +0 -0
- package/docs/assets/diagram/layout-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/layout-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/notifications-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/notifications-diagram-0.jpg +0 -0
- package/docs/assets/diagram/notifications-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/notifications-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/overview-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/overview-diagram-0.jpg +0 -0
- package/docs/assets/diagram/overview-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/overview-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/user-center-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/user-center-diagram-0.jpg +0 -0
- package/docs/assets/diagram/user-center-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/user-center-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/user-management-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/user-management-diagram-0.jpg +0 -0
- package/docs/assets/diagram/user-management-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/user-management-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/user-sessions-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/user-sessions-diagram-0.jpg +0 -0
- package/docs/assets/diagram/user-sessions-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/user-sessions-diagram-0.zh.jpg +0 -0
- package/docs/components-component-management-blocklet-studio.ja.md +0 -194
- package/docs/components-component-management-blocklet-studio.md +0 -194
- package/docs/components-component-management-blocklet-studio.zh-TW.md +0 -194
- package/docs/components-component-management-blocklet-studio.zh.md +0 -194
- package/docs/components-component-management-component-installer.ja.md +0 -182
- package/docs/components-component-management-component-installer.md +0 -182
- package/docs/components-component-management-component-installer.zh-TW.md +0 -182
- package/docs/components-component-management-component-installer.zh.md +0 -182
- package/docs/components-component-management.ja.md +0 -30
- package/docs/components-component-management.md +0 -30
- package/docs/components-component-management.zh-TW.md +0 -30
- package/docs/components-component-management.zh.md +0 -30
- package/docs/components-layout-dashboard.ja.md +0 -185
- package/docs/components-layout-dashboard.md +0 -187
- package/docs/components-layout-dashboard.zh-TW.md +0 -185
- package/docs/components-layout-dashboard.zh.md +0 -185
- package/docs/components-layout-footer.ja.md +0 -165
- package/docs/components-layout-footer.md +0 -165
- package/docs/components-layout-footer.zh-TW.md +0 -165
- package/docs/components-layout-footer.zh.md +0 -165
- package/docs/components-layout-header.ja.md +0 -183
- package/docs/components-layout-header.md +0 -183
- package/docs/components-layout-header.zh-TW.md +0 -183
- package/docs/components-layout-header.zh.md +0 -183
- package/docs/components-layout.ja.md +0 -31
- package/docs/components-layout.md +0 -31
- package/docs/components-layout.zh-TW.md +0 -31
- package/docs/components-layout.zh.md +0 -31
- package/docs/components-notifications.ja.md +0 -125
- package/docs/components-notifications.md +0 -125
- package/docs/components-notifications.zh-TW.md +0 -125
- package/docs/components-notifications.zh.md +0 -125
- package/docs/components-user-management-user-center.ja.md +0 -148
- package/docs/components-user-management-user-center.md +0 -147
- package/docs/components-user-management-user-center.zh-TW.md +0 -148
- package/docs/components-user-management-user-center.zh.md +0 -148
- package/docs/components-user-management-user-sessions.ja.md +0 -121
- package/docs/components-user-management-user-sessions.md +0 -123
- package/docs/components-user-management-user-sessions.zh-TW.md +0 -121
- package/docs/components-user-management-user-sessions.zh.md +0 -121
- package/docs/components-user-management.ja.md +0 -49
- package/docs/components-user-management.md +0 -51
- package/docs/components-user-management.zh-TW.md +0 -49
- package/docs/components-user-management.zh.md +0 -49
- package/docs/components-utilities-icon.ja.md +0 -106
- package/docs/components-utilities-icon.md +0 -106
- package/docs/components-utilities-icon.zh-TW.md +0 -106
- package/docs/components-utilities-icon.zh.md +0 -106
- package/docs/components-utilities.ja.md +0 -136
- package/docs/components-utilities.md +0 -136
- package/docs/components-utilities.zh-TW.md +0 -136
- package/docs/components-utilities.zh.md +0 -136
- package/docs/components.ja.md +0 -27
- package/docs/components.md +0 -27
- package/docs/components.zh-TW.md +0 -27
- package/docs/components.zh.md +0 -27
- package/docs/core-concepts.ja.md +0 -134
- package/docs/core-concepts.md +0 -135
- package/docs/core-concepts.zh-TW.md +0 -134
- package/docs/core-concepts.zh.md +0 -134
- package/docs/getting-started.ja.md +0 -132
- package/docs/getting-started.md +0 -132
- package/docs/getting-started.zh-TW.md +0 -132
- package/docs/getting-started.zh.md +0 -132
- package/docs/hooks-api.ja.md +0 -214
- package/docs/hooks-api.md +0 -214
- package/docs/hooks-api.zh-TW.md +0 -214
- package/docs/hooks-api.zh.md +0 -214
- package/docs/how-to-guides.ja.md +0 -413
- package/docs/how-to-guides.md +0 -413
- package/docs/how-to-guides.zh-TW.md +0 -413
- package/docs/how-to-guides.zh.md +0 -413
- package/docs/overview.ja.md +0 -51
- package/docs/overview.md +0 -51
- package/docs/overview.zh-TW.md +0 -51
- package/docs/overview.zh.md +0 -51
- package/glossary.md +0 -12
- package/src/@types/index.ts +0 -230
- package/src/@types/shims.d.ts +0 -18
- package/src/BlockletStudio/README.md +0 -116
- package/src/BlockletStudio/index.tsx +0 -145
- package/src/ComponentInstaller/ComponentInstaller.stories.jsx +0 -16
- package/src/ComponentInstaller/index.jsx +0 -207
- package/src/ComponentInstaller/installer-item.jsx +0 -129
- package/src/ComponentInstaller/locales.js +0 -22
- package/src/ComponentInstaller/use-component-installed.js +0 -88
- package/src/ComponentManager/components/add-component.tsx +0 -136
- package/src/ComponentManager/components/check-component.tsx +0 -3
- package/src/ComponentManager/components/publish-component.tsx +0 -90
- package/src/ComponentManager/components/resource-dialog.tsx +0 -91
- package/src/ComponentManager/index.tsx +0 -3
- package/src/ComponentManager/libs/locales.ts +0 -15
- package/src/Dashboard/Dashboard.stories.jsx +0 -20
- package/src/Dashboard/app-shell/app-badge.stories.tsx +0 -64
- package/src/Dashboard/app-shell/app-badge.tsx +0 -94
- package/src/Dashboard/app-shell/app-header.tsx +0 -104
- package/src/Dashboard/app-shell/app-info-context.tsx +0 -182
- package/src/Dashboard/app-shell/badges/app-badge-default.tsx +0 -130
- package/src/Dashboard/app-shell/badges/app-badge-did.tsx +0 -28
- package/src/Dashboard/app-shell/badges/app-badge-state.tsx +0 -40
- package/src/Dashboard/app-shell/badges/app-badge-switch.tsx +0 -72
- package/src/Dashboard/app-shell/badges/app-badge-version.tsx +0 -60
- package/src/Dashboard/app-shell/index.ts +0 -5
- package/src/Dashboard/index.jsx +0 -184
- package/src/Footer/Footer.stories.jsx +0 -33
- package/src/Footer/brand.jsx +0 -81
- package/src/Footer/copyright.jsx +0 -22
- package/src/Footer/index.jsx +0 -111
- package/src/Footer/internal-footer.jsx +0 -139
- package/src/Footer/layout/plain.jsx +0 -55
- package/src/Footer/layout/row.jsx +0 -43
- package/src/Footer/layout/standard.jsx +0 -114
- package/src/Footer/links.jsx +0 -321
- package/src/Footer/social-media.jsx +0 -55
- package/src/Header/Header.stories.jsx +0 -30
- package/src/Header/index.tsx +0 -259
- package/src/Icon/Icon.stories.jsx +0 -12
- package/src/Icon/index.tsx +0 -87
- package/src/Notifications/Snackbar.tsx +0 -261
- package/src/Notifications/hooks/use-title.tsx +0 -254
- package/src/Notifications/hooks/use-width.tsx +0 -16
- package/src/Notifications/utils.ts +0 -246
- package/src/UserCenter/assets/banner.png +0 -0
- package/src/UserCenter/components/config-inviter.tsx +0 -48
- package/src/UserCenter/components/config-profile.tsx +0 -99
- package/src/UserCenter/components/danger-zone.tsx +0 -82
- package/src/UserCenter/components/editable-field.tsx +0 -273
- package/src/UserCenter/components/fallback.tsx +0 -57
- package/src/UserCenter/components/nft-preview.tsx +0 -84
- package/src/UserCenter/components/nft.tsx +0 -279
- package/src/UserCenter/components/notification.tsx +0 -319
- package/src/UserCenter/components/passport.tsx +0 -107
- package/src/UserCenter/components/privacy.tsx +0 -120
- package/src/UserCenter/components/settings.tsx +0 -170
- package/src/UserCenter/components/status-dialog/date-picker.tsx +0 -77
- package/src/UserCenter/components/status-dialog/index.tsx +0 -293
- package/src/UserCenter/components/status-selector/duration-menu.tsx +0 -90
- package/src/UserCenter/components/status-selector/index.tsx +0 -58
- package/src/UserCenter/components/status-selector/menu-item.tsx +0 -56
- package/src/UserCenter/components/storage/action.tsx +0 -49
- package/src/UserCenter/components/storage/connected.tsx +0 -61
- package/src/UserCenter/components/storage/delete.tsx +0 -72
- package/src/UserCenter/components/storage/disconnect.tsx +0 -40
- package/src/UserCenter/components/storage/icons/empty-spaces-nft.svg +0 -1
- package/src/UserCenter/components/storage/icons/long-arrow.svg +0 -5
- package/src/UserCenter/components/storage/icons/space-connected.svg +0 -3
- package/src/UserCenter/components/storage/icons/space-disconnect.svg +0 -3
- package/src/UserCenter/components/storage/index.tsx +0 -41
- package/src/UserCenter/components/storage/preview-nft.tsx +0 -72
- package/src/UserCenter/components/third-party-login/index.tsx +0 -199
- package/src/UserCenter/components/third-party-login/third-party-item.tsx +0 -296
- package/src/UserCenter/components/user-center.tsx +0 -787
- package/src/UserCenter/components/user-info/address.tsx +0 -143
- package/src/UserCenter/components/user-info/index.tsx +0 -4
- package/src/UserCenter/components/user-info/link-preview-input.tsx +0 -274
- package/src/UserCenter/components/user-info/metadata.tsx +0 -658
- package/src/UserCenter/components/user-info/social-actions/chat.tsx +0 -43
- package/src/UserCenter/components/user-info/social-actions/follow.tsx +0 -23
- package/src/UserCenter/components/user-info/social-actions/index.tsx +0 -17
- package/src/UserCenter/components/user-info/switch-role.tsx +0 -42
- package/src/UserCenter/components/user-info/timezone-select.tsx +0 -119
- package/src/UserCenter/components/user-info/user-basic-info.tsx +0 -292
- package/src/UserCenter/components/user-info/user-info-item.tsx +0 -54
- package/src/UserCenter/components/user-info/user-info.tsx +0 -91
- package/src/UserCenter/components/user-info/user-status.tsx +0 -234
- package/src/UserCenter/components/user-info/utils.ts +0 -320
- package/src/UserCenter/components/webhook-item.tsx +0 -248
- package/src/UserCenter/index.tsx +0 -1
- package/src/UserCenter/libs/locales.ts +0 -378
- package/src/UserCenter/libs/utils.ts +0 -30
- package/src/UserSessions/components/user-session-info.tsx +0 -78
- package/src/UserSessions/components/user-sessions.tsx +0 -545
- package/src/UserSessions/index.tsx +0 -1
- package/src/UserSessions/libs/locales.ts +0 -60
- package/src/UserSessions/libs/utils.ts +0 -82
- package/src/blocklets.js +0 -195
- package/src/common/domain-warning.jsx +0 -178
- package/src/common/header-addons.jsx +0 -119
- package/src/common/link-blocker.jsx +0 -20
- package/src/common/notification-addon.jsx +0 -135
- package/src/common/org-switch/avatar-uploader.jsx +0 -271
- package/src/common/org-switch/create.jsx +0 -267
- package/src/common/org-switch/index.jsx +0 -407
- package/src/common/org-switch/locales.js +0 -52
- package/src/common/org-switch/use-org.jsx +0 -79
- package/src/common/overridable-theme-provider.jsx +0 -17
- package/src/common/wallet-hidden-topbar.js +0 -14
- package/src/common/wizard-modal.jsx +0 -200
- package/src/common/ws.js +0 -68
- package/src/contexts/config-user-space.tsx +0 -88
- package/src/contexts/user-followers.tsx +0 -54
- package/src/hooks/use-follow.tsx +0 -75
- package/src/hooks/use-mobile.tsx +0 -6
- package/src/index.ts +0 -16
- package/src/libs/constant.ts +0 -1
- package/src/libs/spaces.tsx +0 -18
- package/src/libs/with-hide-when-embed.tsx +0 -24
- package/src/types.js +0 -45
- package/src/utils.js +0 -161
- package/vite.config.mjs +0 -34
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
# Dashboard
|
|
2
|
-
|
|
3
|
-
`Dashboard` コンポーネントは、blocklet アプリケーション向けに、レスポンシブなレイアウトを事前に構築して提供します。これは通常、管理インターフェースやユーザー中心のビューに使用されます。blocklet のメタデータを解釈することで、サイドバー、ヘッダー、およびメインコンテンツエリアを持つ標準的なダッシュボードを自動的に構築します。このコンポーネントにより、一般的なアプリケーション構造を構築するための定型的なコードが大幅に削減されます。
|
|
4
|
-
|
|
5
|
-
レイアウトは、ナビゲーション用の永続的なサイドバー、グローバルなアクションとユーザー情報用のヘッダー、そしてページ固有のコンテンツがレンダリングされるメインコンテンツエリアの3つの主要なセクションで構成されています。
|
|
6
|
-
|
|
7
|
-
<!-- DIAGRAM_IMAGE_START:architecture:16:9:1765962229 -->
|
|
8
|
-

|
|
9
|
-
<!-- DIAGRAM_IMAGE_END -->
|
|
10
|
-
|
|
11
|
-
## 基本的な使用方法
|
|
12
|
-
|
|
13
|
-
`Dashboard` コンポーネントを使用するには、ページのコンテンツをそれでラップするだけです。コンポーネントは自動的にコンテンツの周りにヘッダーとサイドバーをレンダリングします。
|
|
14
|
-
|
|
15
|
-
```javascript MyDashboard.jsx icon=logos:react
|
|
16
|
-
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
17
|
-
|
|
18
|
-
export default function MyDashboardPage() {
|
|
19
|
-
return (
|
|
20
|
-
<Dashboard>
|
|
21
|
-
<h1>Welcome to the Dashboard</h1>
|
|
22
|
-
<p>This is your main content area.</p>
|
|
23
|
-
</Dashboard>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
`Dashboard` コンポーネントに渡された children は、メインコンテンツエリアに表示されます。
|
|
29
|
-
|
|
30
|
-
## Props
|
|
31
|
-
|
|
32
|
-
`Dashboard` コンポーネントは、その動作と外観をカスタマイズするために、以下の props を受け入れます。
|
|
33
|
-
|
|
34
|
-
<x-field-group>
|
|
35
|
-
<x-field data-name="children" data-type="React.ReactNode" data-required="true">
|
|
36
|
-
<x-field-desc markdown>ダッシュボードレイアウトのメインコンテンツエリア内にレンダリングされるコンテンツ。</x-field-desc>
|
|
37
|
-
</x-field>
|
|
38
|
-
<x-field data-name="meta" data-type="object" data-required="false">
|
|
39
|
-
<x-field-desc markdown>blocklet メタデータオブジェクト。指定された場合、デフォルトの `window.blocklet` メタデータとマージされ、上書きされます。これは、テストや blocklet 情報を動的に変更する場合に便利です。</x-field-desc>
|
|
40
|
-
</x-field>
|
|
41
|
-
<x-field data-name="fallbackUrl" data-type="string" data-required="false" data-default="publicPath">
|
|
42
|
-
<x-field-desc markdown>現在の認証済みユーザーがその役割に基づいてどのナビゲーションリンクにもアクセスできない場合にリダイレクトする URL。この自動リダイレクトを無効にするには `null` に設定します。</x-field-desc>
|
|
43
|
-
</x-field>
|
|
44
|
-
<x-field data-name="invalidPathFallback" data-type="function" data-required="false">
|
|
45
|
-
<x-field-desc markdown>現在の URL パスが利用可能なナビゲーションリンクのいずれとも一致しない場合に実行されるコールバック関数。デフォルトの動作は、利用可能な最初のリンクにリダイレクトすることです。</x-field-desc>
|
|
46
|
-
</x-field>
|
|
47
|
-
<x-field data-name="headerAddons" data-type="React.ReactNode | function" data-required="false">
|
|
48
|
-
<x-field-desc markdown>ヘッダーの右側のアドオンのカスタマイズを可能にします。ノードが提供された場合、すべてのデフォルトアドオンを置き換えます。関数が提供された場合、デフォルトのアドオン配列を引数として受け取り、それらを追加、削除、または並べ替えることができます。</x-field-desc>
|
|
49
|
-
</x-field>
|
|
50
|
-
<x-field data-name="sessionManagerProps" data-type="object" data-required="false">
|
|
51
|
-
<x-field-desc markdown>ヘッダー内の基盤となる `SessionUser` コンポーネントに直接渡される Props。これにより、`showRole` やカスタムの `onLogout` ハンドラの定義など、ユーザーセッションメニューのカスタマイズが可能になります。</x-field-desc>
|
|
52
|
-
</x-field>
|
|
53
|
-
<x-field data-name="links" data-type="array | function" data-required="false">
|
|
54
|
-
<x-field-desc markdown>サイドバーのナビゲーションリンクをプログラムで変更できるようにします。配列が提供された場合、そのアイテムはメタデータから生成されたリンクに追加されます。関数が提供された場合、メタデータから生成されたリンクを引数として受け取り、新しいリンクの配列を返す必要があります。</x-field-desc>
|
|
55
|
-
</x-field>
|
|
56
|
-
<x-field data-name="showDomainWarningDialog" data-type="boolean" data-required="false" data-default="true">
|
|
57
|
-
<x-field-desc markdown>`true` の場合、信頼できないドメインからアプリケーションにアクセスされた場合に警告ダイアログを表示します。</x-field-desc>
|
|
58
|
-
</x-field>
|
|
59
|
-
</x-field-group>
|
|
60
|
-
|
|
61
|
-
## 仕組み
|
|
62
|
-
|
|
63
|
-
`Dashboard` コンポーネントは、「設定駆動型」で設計されており、その構造とコンテンツは主に blocklet のメタデータファイル (`blocklet.yml`) から派生します。
|
|
64
|
-
|
|
65
|
-
### メタデータからのナビゲーション
|
|
66
|
-
|
|
67
|
-
サイドバーのナビゲーションは、`blocklet.yml` の `navigation` 配列から自動的に生成されます。コンポーネントは、`section` プロパティに `dashboard` を含むナビゲーション項目を具体的に探します。
|
|
68
|
-
|
|
69
|
-
以下は、ダッシュボードナビゲーションを定義する方法の例です。
|
|
70
|
-
|
|
71
|
-
```yaml blocklet.yml icon=mdi:file-document
|
|
72
|
-
navigation:
|
|
73
|
-
- title: 'Home'
|
|
74
|
-
link: '/'
|
|
75
|
-
section: 'dashboard'
|
|
76
|
-
icon: 'mdi:home'
|
|
77
|
-
role: ['owner', 'admin', 'guest']
|
|
78
|
-
- title: 'Analytics'
|
|
79
|
-
link: '/analytics'
|
|
80
|
-
section: 'dashboard'
|
|
81
|
-
icon: 'mdi:chart-bar'
|
|
82
|
-
role: ['owner', 'admin']
|
|
83
|
-
- title: 'Settings'
|
|
84
|
-
link: '/settings'
|
|
85
|
-
section: 'dashboard'
|
|
86
|
-
icon: 'mdi:cog'
|
|
87
|
-
role: ['owner']
|
|
88
|
-
items:
|
|
89
|
-
- title: 'Profile'
|
|
90
|
-
link: '/settings/profile'
|
|
91
|
-
- title: 'Billing'
|
|
92
|
-
link: '/settings/billing'
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### ロールベースのアクセス制御
|
|
96
|
-
|
|
97
|
-
`Dashboard` コンポーネントは、ナビゲーションリンクに対してロールベースのアクセス制御 (RBAC) を強制します。各ナビゲーション項目は `role` プロパティを持つことができ、これはリンクを見ることが許可されているロールの配列です。
|
|
98
|
-
|
|
99
|
-
- ナビゲーション項目に `role` プロパティがない場合、それは誰にでも表示されます。
|
|
100
|
-
- 現在のユーザーが認証されていない場合、`guest` ロールを含む項目のみを見ることができます。
|
|
101
|
-
- 現在のユーザーが認証されている場合、コンポーネントは彼らの `user.role` を各ナビゲーション項目の `role` 配列と比較します。一致がある場合にのみ項目が表示されます。
|
|
102
|
-
- 親ナビゲーション項目は、その子の少なくとも1つが表示される場合にのみ表示されます。
|
|
103
|
-
|
|
104
|
-
上記の `blocklet.yml` の例を使用すると:
|
|
105
|
-
- `guest` ロールのユーザーは「Home」リンクのみを見ることができます。
|
|
106
|
-
- `admin` ロールのユーザーは「Home」と「Analytics」を見ることができます。
|
|
107
|
-
- `owner` ロールのユーザーは、「Settings」の下にあるネストされた「Profile」と「Billing」リンクを含むすべてのリンクを見ることができます。
|
|
108
|
-
|
|
109
|
-
### アイコン
|
|
110
|
-
|
|
111
|
-
ナビゲーション項目の `icon` プロパティは、[Iconify](https://icon-sets.iconify.design/) ライブラリのアイコン名に対応する文字列(例:`mdi:home`)である必要があります。画像ファイルへの完全な URL を提供することもできます。
|
|
112
|
-
|
|
113
|
-
## カスタマイズ
|
|
114
|
-
|
|
115
|
-
`Dashboard` はメタデータですぐに使えるように設計されていますが、より高度なカスタマイズのためのいくつかの props を提供しています。
|
|
116
|
-
|
|
117
|
-
### ヘッダーアドオンのカスタマイズ
|
|
118
|
-
|
|
119
|
-
`headerAddons` prop を使用して、デフォルトのヘッダーアドオン(例:テーマ切り替え、ロケールセレクター、セッションマネージャー)を変更できます。関数を渡すことで、新しい要素を追加したり、既存の要素を並べ替えたりすることができます。
|
|
120
|
-
|
|
121
|
-
```javascript CustomHeader.jsx icon=logos:react
|
|
122
|
-
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
123
|
-
import Button from '@mui/material/Button';
|
|
124
|
-
|
|
125
|
-
function MyCustomButton() {
|
|
126
|
-
return <Button color="inherit" onClick={() => alert('Help!')}>Help</Button>;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export default function CustomDashboard() {
|
|
130
|
-
return (
|
|
131
|
-
<Dashboard
|
|
132
|
-
headerAddons={(existingAddons) => {
|
|
133
|
-
const customAddon = <MyCustomButton key="custom-help" />;
|
|
134
|
-
// Add the custom button before the other addons
|
|
135
|
-
return [customAddon, ...existingAddons];
|
|
136
|
-
}}
|
|
137
|
-
>
|
|
138
|
-
<p>Dashboard with a custom header button.</p>
|
|
139
|
-
</Dashboard>
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### リンクのプログラムによる追加
|
|
145
|
-
|
|
146
|
-
`links` prop を使用すると、コードから動的にサイドバーのナビゲーションリンクを追加または変更できます。これは、アプリケーションの状態に依存するリンクに便利です。
|
|
147
|
-
|
|
148
|
-
```javascript DynamicLinks.jsx icon=logos:react
|
|
149
|
-
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
150
|
-
import Icon from '@arcblock/ux/lib/Icon';
|
|
151
|
-
|
|
152
|
-
const useFeatureFlag = () => {
|
|
153
|
-
// 実際のアプリでは、ここでフィーチャーフラグサービスをチェックします
|
|
154
|
-
return true;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export default function DynamicDashboard() {
|
|
158
|
-
const isBetaFeatureEnabled = useFeatureFlag();
|
|
159
|
-
|
|
160
|
-
return (
|
|
161
|
-
<Dashboard
|
|
162
|
-
links={(existingLinks) => {
|
|
163
|
-
if (isBetaFeatureEnabled) {
|
|
164
|
-
const betaLink = {
|
|
165
|
-
id: 'beta-feature',
|
|
166
|
-
title: 'Beta Feature',
|
|
167
|
-
url: '/beta',
|
|
168
|
-
icon: <Icon name="mdi:test-tube" />,
|
|
169
|
-
external: true, // クライアントサイドのルーティングに必要
|
|
170
|
-
};
|
|
171
|
-
return [...existingLinks, betaLink];
|
|
172
|
-
}
|
|
173
|
-
return existingLinks;
|
|
174
|
-
}}
|
|
175
|
-
>
|
|
176
|
-
<p>This dashboard may have dynamic links.</p>
|
|
177
|
-
</Dashboard>
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## まとめ
|
|
184
|
-
|
|
185
|
-
`Dashboard` コンポーネントは、アプリケーションのレイアウトを迅速に構築するための強力なツールです。blocklet メタデータを活用することで、構造化され、ロールを認識するナビゲーションシステムをすぐに提供します。より基本的なレイアウトコンポーネントについては、[Header](./components-layout-header.md) と [Footer](./components-layout-footer.md) のドキュメントを参照してください。
|
|
@@ -1,187 +0,0 @@
|
|
|
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
|
-
The following diagram illustrates the component's structure and its relationship with the blocklet metadata:
|
|
8
|
-
|
|
9
|
-
<!-- DIAGRAM_IMAGE_START:architecture:16:9:1765962229 -->
|
|
10
|
-

|
|
11
|
-
<!-- DIAGRAM_IMAGE_END -->
|
|
12
|
-
|
|
13
|
-
## Basic Usage
|
|
14
|
-
|
|
15
|
-
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.
|
|
16
|
-
|
|
17
|
-
```javascript MyDashboard.jsx icon=logos:react
|
|
18
|
-
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
19
|
-
|
|
20
|
-
export default function MyDashboardPage() {
|
|
21
|
-
return (
|
|
22
|
-
<Dashboard>
|
|
23
|
-
<h1>Welcome to the Dashboard</h1>
|
|
24
|
-
<p>This is your main content area.</p>
|
|
25
|
-
</Dashboard>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
The children passed to the `Dashboard` component will be displayed in the main content area.
|
|
31
|
-
|
|
32
|
-
## Props
|
|
33
|
-
|
|
34
|
-
The `Dashboard` component accepts the following props to customize its behavior and appearance.
|
|
35
|
-
|
|
36
|
-
<x-field-group>
|
|
37
|
-
<x-field data-name="children" data-type="React.ReactNode" data-required="true">
|
|
38
|
-
<x-field-desc markdown>The content to be rendered within the main content area of the dashboard layout.</x-field-desc>
|
|
39
|
-
</x-field>
|
|
40
|
-
<x-field data-name="meta" data-type="object" data-required="false">
|
|
41
|
-
<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>
|
|
42
|
-
</x-field>
|
|
43
|
-
<x-field data-name="fallbackUrl" data-type="string" data-required="false" data-default="publicPath">
|
|
44
|
-
<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>
|
|
45
|
-
</x-field>
|
|
46
|
-
<x-field data-name="invalidPathFallback" data-type="function" data-required="false">
|
|
47
|
-
<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>
|
|
48
|
-
</x-field>
|
|
49
|
-
<x-field data-name="headerAddons" data-type="React.ReactNode | function" data-required="false">
|
|
50
|
-
<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>
|
|
51
|
-
</x-field>
|
|
52
|
-
<x-field data-name="sessionManagerProps" data-type="object" data-required="false">
|
|
53
|
-
<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>
|
|
54
|
-
</x-field>
|
|
55
|
-
<x-field data-name="links" data-type="array | function" data-required="false">
|
|
56
|
-
<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>
|
|
57
|
-
</x-field>
|
|
58
|
-
<x-field data-name="showDomainWarningDialog" data-type="boolean" data-required="false" data-default="true">
|
|
59
|
-
<x-field-desc markdown>If `true`, displays a warning dialog if the application is accessed from an untrusted domain.</x-field-desc>
|
|
60
|
-
</x-field>
|
|
61
|
-
</x-field-group>
|
|
62
|
-
|
|
63
|
-
## How It Works
|
|
64
|
-
|
|
65
|
-
The `Dashboard` component is designed to be "configuration-driven," deriving its structure and content primarily from the blocklet's metadata file (`blocklet.yml`).
|
|
66
|
-
|
|
67
|
-
### Navigation from Metadata
|
|
68
|
-
|
|
69
|
-
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.
|
|
70
|
-
|
|
71
|
-
Here is an example of how to define dashboard navigation:
|
|
72
|
-
|
|
73
|
-
```yaml blocklet.yml icon=mdi:file-document
|
|
74
|
-
navigation:
|
|
75
|
-
- title: 'Home'
|
|
76
|
-
link: '/'
|
|
77
|
-
section: 'dashboard'
|
|
78
|
-
icon: 'mdi:home'
|
|
79
|
-
role: ['owner', 'admin', 'guest']
|
|
80
|
-
- title: 'Analytics'
|
|
81
|
-
link: '/analytics'
|
|
82
|
-
section: 'dashboard'
|
|
83
|
-
icon: 'mdi:chart-bar'
|
|
84
|
-
role: ['owner', 'admin']
|
|
85
|
-
- title: 'Settings'
|
|
86
|
-
link: '/settings'
|
|
87
|
-
section: 'dashboard'
|
|
88
|
-
icon: 'mdi:cog'
|
|
89
|
-
role: ['owner']
|
|
90
|
-
items:
|
|
91
|
-
- title: 'Profile'
|
|
92
|
-
link: '/settings/profile'
|
|
93
|
-
- title: 'Billing'
|
|
94
|
-
link: '/settings/billing'
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Role-Based Access Control
|
|
98
|
-
|
|
99
|
-
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.
|
|
100
|
-
|
|
101
|
-
- If a navigation item does not have a `role` property, it is visible to everyone.
|
|
102
|
-
- If the current user is not authenticated, they can only see items that include the `guest` role.
|
|
103
|
-
- 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.
|
|
104
|
-
- A parent navigation item is only visible if at least one of its children is visible.
|
|
105
|
-
|
|
106
|
-
Using the `blocklet.yml` example above:
|
|
107
|
-
- A user with the `guest` role will only see the "Home" link.
|
|
108
|
-
- A user with the `admin` role will see "Home" and "Analytics".
|
|
109
|
-
- A user with the `owner` role will see all links, including the nested "Profile" and "Billing" links under "Settings".
|
|
110
|
-
|
|
111
|
-
### Icons
|
|
112
|
-
|
|
113
|
-
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.
|
|
114
|
-
|
|
115
|
-
## Customization
|
|
116
|
-
|
|
117
|
-
While the `Dashboard` is designed to work out-of-the-box with metadata, it offers several props for more advanced customization.
|
|
118
|
-
|
|
119
|
-
### Customizing Header Addons
|
|
120
|
-
|
|
121
|
-
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.
|
|
122
|
-
|
|
123
|
-
```javascript CustomHeader.jsx icon=logos:react
|
|
124
|
-
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
125
|
-
import Button from '@mui/material/Button';
|
|
126
|
-
|
|
127
|
-
function MyCustomButton() {
|
|
128
|
-
return <Button color="inherit" onClick={() => alert('Help!')}>Help</Button>;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export default function CustomDashboard() {
|
|
132
|
-
return (
|
|
133
|
-
<Dashboard
|
|
134
|
-
headerAddons={(existingAddons) => {
|
|
135
|
-
const customAddon = <MyCustomButton key="custom-help" />;
|
|
136
|
-
// Add the custom button before the other addons
|
|
137
|
-
return [customAddon, ...existingAddons];
|
|
138
|
-
}}
|
|
139
|
-
>
|
|
140
|
-
<p>Dashboard with a custom header button.</p>
|
|
141
|
-
</Dashboard>
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Programmatically Adding Links
|
|
147
|
-
|
|
148
|
-
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.
|
|
149
|
-
|
|
150
|
-
```javascript DynamicLinks.jsx icon=logos:react
|
|
151
|
-
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
152
|
-
import Icon from '@arcblock/ux/lib/Icon';
|
|
153
|
-
|
|
154
|
-
const useFeatureFlag = () => {
|
|
155
|
-
// In a real app, this would check a feature flag service
|
|
156
|
-
return true;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export default function DynamicDashboard() {
|
|
160
|
-
const isBetaFeatureEnabled = useFeatureFlag();
|
|
161
|
-
|
|
162
|
-
return (
|
|
163
|
-
<Dashboard
|
|
164
|
-
links={(existingLinks) => {
|
|
165
|
-
if (isBetaFeatureEnabled) {
|
|
166
|
-
const betaLink = {
|
|
167
|
-
id: 'beta-feature',
|
|
168
|
-
title: 'Beta Feature',
|
|
169
|
-
url: '/beta',
|
|
170
|
-
icon: <Icon name="mdi:test-tube" />,
|
|
171
|
-
external: true, // Required for client-side routing
|
|
172
|
-
};
|
|
173
|
-
return [...existingLinks, betaLink];
|
|
174
|
-
}
|
|
175
|
-
return existingLinks;
|
|
176
|
-
}}
|
|
177
|
-
>
|
|
178
|
-
<p>This dashboard may have dynamic links.</p>
|
|
179
|
-
</Dashboard>
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
## Summary
|
|
186
|
-
|
|
187
|
-
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).
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
# Dashboard
|
|
2
|
-
|
|
3
|
-
`Dashboard` 元件為 blocklet 應用程式提供了一個預先建置、響應式的佈局,通常用於管理介面或以使用者為中心的視圖。它透過解析 blocklet 的元資料,自動建構一個包含側邊欄、頁首和主要內容區域的標準儀表板。此元件顯著減少了建構通用應用程式結構所需的樣板程式碼。
|
|
4
|
-
|
|
5
|
-
該佈局由三個主要部分組成:一個用於導覽的常駐側邊欄、一個用於全域操作和使用者資訊的頁首,以及一個呈現特定頁面內容的主要內容區域。
|
|
6
|
-
|
|
7
|
-
<!-- DIAGRAM_IMAGE_START:architecture:16:9:1765962229 -->
|
|
8
|
-

|
|
9
|
-
<!-- DIAGRAM_IMAGE_END -->
|
|
10
|
-
|
|
11
|
-
## 基本用法
|
|
12
|
-
|
|
13
|
-
若要使用 `Dashboard` 元件,只需將您的頁面內容包裹在其中即可。該元件將自動在您的內容周圍呈現頁首和側邊欄。
|
|
14
|
-
|
|
15
|
-
```javascript MyDashboard.jsx icon=logos:react
|
|
16
|
-
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
17
|
-
|
|
18
|
-
export default function MyDashboardPage() {
|
|
19
|
-
return (
|
|
20
|
-
<Dashboard>
|
|
21
|
-
<h1>Welcome to the Dashboard</h1>
|
|
22
|
-
<p>This is your main content area.</p>
|
|
23
|
-
</Dashboard>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
傳遞給 `Dashboard` 元件的 children 將顯示在主要內容區域中。
|
|
29
|
-
|
|
30
|
-
## 屬性 (Props)
|
|
31
|
-
|
|
32
|
-
`Dashboard` 元件接受以下屬性 (props) 以自訂其行為和外觀。
|
|
33
|
-
|
|
34
|
-
<x-field-group>
|
|
35
|
-
<x-field data-name="children" data-type="React.ReactNode" data-required="true">
|
|
36
|
-
<x-field-desc markdown>要在儀表板佈局的主要內容區域內呈現的內容。</x-field-desc>
|
|
37
|
-
</x-field>
|
|
38
|
-
<x-field data-name="meta" data-type="object" data-required="false">
|
|
39
|
-
<x-field-desc markdown>一個 blocklet 元資料物件。若提供,它將與預設的 `window.blocklet` 元資料合併並覆寫。這對於測試或動態更改 blocklet 資訊很有用。</x-field-desc>
|
|
40
|
-
</x-field>
|
|
41
|
-
<x-field data-name="fallbackUrl" data-type="string" data-required="false" data-default="publicPath">
|
|
42
|
-
<x-field-desc markdown>如果目前已驗證的使用者根據其角色無權存取任何導覽連結,則重新導向到的 URL。設定為 `null` 可停用此自動重新導向。</x-field-desc>
|
|
43
|
-
</x-field>
|
|
44
|
-
<x-field data-name="invalidPathFallback" data-type="function" data-required="false">
|
|
45
|
-
<x-field-desc markdown>當前 URL 路徑不符合任何可用導覽連結時執行的回呼函式。預設行為是重新導向到第一個可用的連結。</x-field-desc>
|
|
46
|
-
</x-field>
|
|
47
|
-
<x-field data-name="headerAddons" data-type="React.ReactNode | function" data-required="false">
|
|
48
|
-
<x-field-desc markdown>允許自訂頁首右側的附加元件。如果提供一個節點,它將取代所有預設的附加元件。如果提供一個函式,它會接收預設的附加元件陣列作為參數,讓您可以新增、移除或重新排序它們。</x-field-desc>
|
|
49
|
-
</x-field>
|
|
50
|
-
<x-field data-name="sessionManagerProps" data-type="object" data-required="false">
|
|
51
|
-
<x-field-desc markdown>直接傳遞給頁首底層 `SessionUser` 元件的 props。這允許自訂使用者會話選單,例如 `showRole` 或定義自訂的 `onLogout` 處理常式。</x-field-desc>
|
|
52
|
-
</x-field>
|
|
53
|
-
<x-field data-name="links" data-type="array | function" data-required="false">
|
|
54
|
-
<x-field-desc markdown>允許以程式化方式修改側邊欄導覽連結。如果提供一個陣列,其項目將附加到從元資料生成的連結中。如果提供一個函式,它會接收元資料生成的連結作為參數,並應返回一個新的連結陣列。</x-field-desc>
|
|
55
|
-
</x-field>
|
|
56
|
-
<x-field data-name="showDomainWarningDialog" data-type="boolean" data-required="false" data-default="true">
|
|
57
|
-
<x-field-desc markdown>若為 `true`,則在從不受信任的網域存取應用程式時顯示警告對話方塊。</x-field-desc>
|
|
58
|
-
</x-field>
|
|
59
|
-
</x-field-group>
|
|
60
|
-
|
|
61
|
-
## 運作方式
|
|
62
|
-
|
|
63
|
-
`Dashboard` 元件被設計為「設定驅動」,其結構和內容主要來自 blocklet 的元資料檔案 (`blocklet.yml`)。
|
|
64
|
-
|
|
65
|
-
### 透過元資料產生導覽
|
|
66
|
-
|
|
67
|
-
側邊欄導覽是根據您 `blocklet.yml` 中的 `navigation` 陣列自動產生的。該元件會特別尋找其 `section` 屬性中包含 `dashboard` 的導覽項目。
|
|
68
|
-
|
|
69
|
-
以下是如何定義儀表板導覽的範例:
|
|
70
|
-
|
|
71
|
-
```yaml blocklet.yml icon=mdi:file-document
|
|
72
|
-
navigation:
|
|
73
|
-
- title: 'Home'
|
|
74
|
-
link: '/'
|
|
75
|
-
section: 'dashboard'
|
|
76
|
-
icon: 'mdi:home'
|
|
77
|
-
role: ['owner', 'admin', 'guest']
|
|
78
|
-
- title: 'Analytics'
|
|
79
|
-
link: '/analytics'
|
|
80
|
-
section: 'dashboard'
|
|
81
|
-
icon: 'mdi:chart-bar'
|
|
82
|
-
role: ['owner', 'admin']
|
|
83
|
-
- title: 'Settings'
|
|
84
|
-
link: '/settings'
|
|
85
|
-
section: 'dashboard'
|
|
86
|
-
icon: 'mdi:cog'
|
|
87
|
-
role: ['owner']
|
|
88
|
-
items:
|
|
89
|
-
- title: 'Profile'
|
|
90
|
-
link: '/settings/profile'
|
|
91
|
-
- title: 'Billing'
|
|
92
|
-
link: '/settings/billing'
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### 角色型存取控制
|
|
96
|
-
|
|
97
|
-
`Dashboard` 元件對導覽連結強制執行角色型存取控制 (RBAC)。每個導覽項目都可以有一個 `role` 屬性,這是一個允許查看該連結的角色陣列。
|
|
98
|
-
|
|
99
|
-
- 如果導覽項目沒有 `role` 屬性,則所有人皆可見。
|
|
100
|
-
- 如果目前使用者未經驗證,他們只能看到包含 `guest` 角色的項目。
|
|
101
|
-
- 如果目前使用者已驗證,元件會將其 `user.role` 與每個導覽項目的 `role` 陣列進行比較。只有在匹配的情況下,該項目才會顯示。
|
|
102
|
-
- 只有在父導覽項目至少有一個子項目可見時,該父項目才可見。
|
|
103
|
-
|
|
104
|
-
使用上面的 `blocklet.yml` 範例:
|
|
105
|
-
- 具有 `guest` 角色的使用者只會看到「Home」連結。
|
|
106
|
-
- 具有 `admin` 角色的使用者將看到「Home」和「Analytics」。
|
|
107
|
-
- 具有 `owner` 角色的使用者將看到所有連結,包括「Settings」下的巢狀「Profile」和「Billing」連結。
|
|
108
|
-
|
|
109
|
-
### 圖示
|
|
110
|
-
|
|
111
|
-
導覽項目的 `icon` 屬性應為一個字串,對應於 [Iconify](https://icon-sets.iconify.design/) 圖示庫中的圖示名稱(例如 `mdi:home`)。您也可以提供一個指向圖片檔案的完整 URL。
|
|
112
|
-
|
|
113
|
-
## 自訂
|
|
114
|
-
|
|
115
|
-
雖然 `Dashboard` 設計為可透過元資料開箱即用,但它也提供了幾個屬性以進行更進階的自訂。
|
|
116
|
-
|
|
117
|
-
### 自訂頁首附加元件
|
|
118
|
-
|
|
119
|
-
您可以使用 `headerAddons` 屬性修改預設的頁首附加元件(例如,主題切換、語系選擇器、會話管理器)。透過傳遞一個函式,您可以新增元素或重新排列現有元素。
|
|
120
|
-
|
|
121
|
-
```javascript CustomHeader.jsx icon=logos:react
|
|
122
|
-
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
123
|
-
import Button from '@mui/material/Button';
|
|
124
|
-
|
|
125
|
-
function MyCustomButton() {
|
|
126
|
-
return <Button color="inherit" onClick={() => alert('Help!')}>Help</Button>;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export default function CustomDashboard() {
|
|
130
|
-
return (
|
|
131
|
-
<Dashboard
|
|
132
|
-
headerAddons={(existingAddons) => {
|
|
133
|
-
const customAddon = <MyCustomButton key="custom-help" />;
|
|
134
|
-
// Add the custom button before the other addons
|
|
135
|
-
return [customAddon, ...existingAddons];
|
|
136
|
-
}}
|
|
137
|
-
>
|
|
138
|
-
<p>Dashboard with a custom header button.</p>
|
|
139
|
-
</Dashboard>
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### 以程式化方式新增連結
|
|
145
|
-
|
|
146
|
-
`links` 屬性允許您從程式碼中動態新增或修改側邊欄導覽連結。這對於依賴應用程式狀態的連結很有用。
|
|
147
|
-
|
|
148
|
-
```javascript DynamicLinks.jsx icon=logos:react
|
|
149
|
-
import Dashboard from '@arcblock/blocklet-ui-react/lib/Dashboard';
|
|
150
|
-
import Icon from '@arcblock/ux/lib/Icon';
|
|
151
|
-
|
|
152
|
-
const useFeatureFlag = () => {
|
|
153
|
-
// 在實際應用程式中,這裡會檢查功能旗標服務
|
|
154
|
-
return true;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export default function DynamicDashboard() {
|
|
158
|
-
const isBetaFeatureEnabled = useFeatureFlag();
|
|
159
|
-
|
|
160
|
-
return (
|
|
161
|
-
<Dashboard
|
|
162
|
-
links={(existingLinks) => {
|
|
163
|
-
if (isBetaFeatureEnabled) {
|
|
164
|
-
const betaLink = {
|
|
165
|
-
id: 'beta-feature',
|
|
166
|
-
title: 'Beta Feature',
|
|
167
|
-
url: '/beta',
|
|
168
|
-
icon: <Icon name="mdi:test-tube" />,
|
|
169
|
-
external: true, // 客戶端路由所需
|
|
170
|
-
};
|
|
171
|
-
return [...existingLinks, betaLink];
|
|
172
|
-
}
|
|
173
|
-
return existingLinks;
|
|
174
|
-
}}
|
|
175
|
-
>
|
|
176
|
-
<p>This dashboard may have dynamic links.</p>
|
|
177
|
-
</Dashboard>
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## 總結
|
|
184
|
-
|
|
185
|
-
`Dashboard` 元件是快速建構應用程式佈局的強大工具。透過利用 blocklet 元資料,它提供了一個開箱即用的、具備角色感知能力的結構化導覽系統。若需更基礎的佈局元件,請參閱 [Header](./components-layout-header.md) 和 [Footer](./components-layout-footer.md) 的文件。
|