@blocklet/ui-react 3.1.48 → 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,132 @@
|
|
|
1
|
+
# はじめに
|
|
2
|
+
|
|
3
|
+
このガイドでは、`@blocklet/ui-react` ライブラリをインストールし、最初のコンポーネントをレンダリングするための手順をステップバイステップで説明します。目標は、最小限の時間でアプリケーション内に機能する `Header` と `Footer` を実装することです。
|
|
4
|
+
|
|
5
|
+
## 前提条件
|
|
6
|
+
|
|
7
|
+
先に進む前に、開発環境に以下がインストールされていることを確認してください:
|
|
8
|
+
* 動作する React プロジェクト。
|
|
9
|
+
* Node.js とパッケージマネージャー(npm または yarn)。
|
|
10
|
+
|
|
11
|
+
## インストール
|
|
12
|
+
|
|
13
|
+
まず、お使いのパッケージマネージャーを使用して、`@blocklet/ui-react` パッケージをプロジェクトに追加します。
|
|
14
|
+
|
|
15
|
+
npm を使用する場合:
|
|
16
|
+
```bash npm
|
|
17
|
+
npm install @blocklet/ui-react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
yarn を使用する場合:
|
|
21
|
+
```bash yarn
|
|
22
|
+
yarn add @blocklet/ui-react
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 基本的な使用法: Header と Footer
|
|
26
|
+
|
|
27
|
+
`Header` と `Footer` コンポーネントはシンプルに設計されており、初期設定なしでレンダリングできます。これらのコンポーネントは、blocklet のメタデータから自動的にデータを取得します。
|
|
28
|
+
|
|
29
|
+
1. `Header` と `Footer` コンポーネントをメインのアプリケーションファイル(例:`App.js`)にインポートします。
|
|
30
|
+
2. それぞれをアプリケーションのレイアウトの最上部と最下部に配置します。
|
|
31
|
+
|
|
32
|
+
```jsx App.js icon=logos:react
|
|
33
|
+
import React from 'react';
|
|
34
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
35
|
+
import Footer from '@blocklet/ui-react/lib/Footer';
|
|
36
|
+
|
|
37
|
+
function App() {
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
<Header />
|
|
41
|
+
<main style={{ padding: '20px', minHeight: 'calc(100vh - 128px)' }}>
|
|
42
|
+
{/* アプリケーションのコンテンツはここに記述します */}
|
|
43
|
+
<h1>Welcome to My Blocklet</h1>
|
|
44
|
+
</main>
|
|
45
|
+
<Footer />
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default App;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
コンポーネントは、アプリケーション名、ロゴ、ナビゲーションリンクなどの設定詳細を、Blocklet Server 環境によって注入される `window.blocklet` メタデータオブジェクトから自動的に取得します。
|
|
54
|
+
|
|
55
|
+
さらに、`Header` コンポーネントは、状況に応じて追加のコントロールをインテリジェントにレンダリングします:
|
|
56
|
+
* `SessionContext` が利用可能な場合、**ユーザーセッションマネージャー**が表示されます。
|
|
57
|
+
* `LocaleContext` が利用可能な場合、**言語セレクター**が表示されます。
|
|
58
|
+
|
|
59
|
+
## 手動設定
|
|
60
|
+
|
|
61
|
+
開発、テスト、またはデフォルトのメタデータを上書きする必要がある場合、`blockletMeta` プロパティを使用して設定オブジェクトをコンポーネントに直接渡すことができます。
|
|
62
|
+
|
|
63
|
+
```jsx App.js icon=logos:react
|
|
64
|
+
import React from 'react';
|
|
65
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
66
|
+
|
|
67
|
+
const customBlockletMeta = {
|
|
68
|
+
appName: 'My Custom App',
|
|
69
|
+
appLogo: 'https://path.to/your/logo.png',
|
|
70
|
+
navigation: [
|
|
71
|
+
{
|
|
72
|
+
title: 'Home',
|
|
73
|
+
link: '/',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
title: 'Documentation',
|
|
77
|
+
link: '/docs',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
function App() {
|
|
83
|
+
return (
|
|
84
|
+
<div>
|
|
85
|
+
<Header blockletMeta={customBlockletMeta} />
|
|
86
|
+
{/* ... rest of your app */}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
このアプローチにより、グローバルな `window.blocklet` オブジェクトによって提供されるデータを上書きし、コンポーネントの外観と動作を正確に制御できます。
|
|
93
|
+
|
|
94
|
+
## Header のカスタマイズ
|
|
95
|
+
|
|
96
|
+
`Header` コンポーネントには右側に `addons` エリアがあり、アクションボタンやカスタムリンクなど、独自のコンポーネントを含めるようにカスタマイズできます。
|
|
97
|
+
|
|
98
|
+
`addons` プロパティは、デフォルトのアドオンコンポーネントを引数として受け取る関数を受け入れます。これにより、既存のコンポーネントの前に追加したり、後ろに追加したり、完全に置き換えたりすることができます。
|
|
99
|
+
|
|
100
|
+
```jsx CustomHeader.js icon=logos:react
|
|
101
|
+
import React from 'react';
|
|
102
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
103
|
+
import Button from '@mui/material/Button'; // Material-UI を使用した例
|
|
104
|
+
|
|
105
|
+
function CustomHeader() {
|
|
106
|
+
return (
|
|
107
|
+
<Header
|
|
108
|
+
addons={existingAddons => {
|
|
109
|
+
return [
|
|
110
|
+
<Button
|
|
111
|
+
key="custom-action"
|
|
112
|
+
variant="contained"
|
|
113
|
+
color="primary"
|
|
114
|
+
size="small"
|
|
115
|
+
style={{ marginRight: 8 }}>
|
|
116
|
+
Custom Action
|
|
117
|
+
</Button>,
|
|
118
|
+
...existingAddons, // 重要: デフォルトのセッション/ロケールアドオンを保持します
|
|
119
|
+
];
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
この例では、カスタムボタンが既存のアドオンの前に追加されています。`...existingAddons` を含めることで、デフォルトのセッションおよびロケールコントロールが表示されたままになるようにします。
|
|
127
|
+
|
|
128
|
+
## まとめ
|
|
129
|
+
|
|
130
|
+
これで、`@blocklet/ui-react` ライブラリのインストール、デフォルトの `Header` および `Footer` コンポーネントのレンダリング、そしてカスタム設定やアドオンの提供方法を学びました。
|
|
131
|
+
|
|
132
|
+
これらの基本を理解したことで、ライブラリで利用可能なすべてのコンポーネントを探索する準備が整いました。レイアウト、ユーザー管理、ユーティリティコンポーネントに関する詳細なドキュメントについては、[コンポーネント](./components.md) セクションに進んでください。
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
This guide provides a step-by-step walkthrough to install the `@blocklet/ui-react` library and render your first components. The objective is to have a functional `Header` and `Footer` within your application in a minimal amount of time.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before proceeding, ensure you have the following installed in your development environment:
|
|
8
|
+
* A functional React project.
|
|
9
|
+
* Node.js and a package manager (npm or yarn).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
To begin, add the `@blocklet/ui-react` package to your project using your preferred package manager.
|
|
14
|
+
|
|
15
|
+
With npm:
|
|
16
|
+
```bash npm
|
|
17
|
+
npm install @blocklet/ui-react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
With yarn:
|
|
21
|
+
```bash yarn
|
|
22
|
+
yarn add @blocklet/ui-react
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Basic Usage: Header and Footer
|
|
26
|
+
|
|
27
|
+
The `Header` and `Footer` components are designed for simplicity and can be rendered without any initial configuration. They automatically source their data from the blocklet's metadata.
|
|
28
|
+
|
|
29
|
+
1. Import the `Header` and `Footer` components into your main application file (e.g., `App.js`).
|
|
30
|
+
2. Place them at the top and bottom of your application's layout, respectively.
|
|
31
|
+
|
|
32
|
+
```jsx App.js icon=logos:react
|
|
33
|
+
import React from 'react';
|
|
34
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
35
|
+
import Footer from '@blocklet/ui-react/lib/Footer';
|
|
36
|
+
|
|
37
|
+
function App() {
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
<Header />
|
|
41
|
+
<main style={{ padding: '20px', minHeight: 'calc(100vh - 128px)' }}>
|
|
42
|
+
{/* Your application content goes here */}
|
|
43
|
+
<h1>Welcome to My Blocklet</h1>
|
|
44
|
+
</main>
|
|
45
|
+
<Footer />
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default App;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The components automatically retrieve configuration details—such as the application name, logo, and navigation links—from the `window.blocklet` metadata object, which is injected by the Blocklet Server environment.
|
|
54
|
+
|
|
55
|
+
Furthermore, the `Header` component will intelligently render additional controls:
|
|
56
|
+
* A **user session manager** is displayed if a `SessionContext` is available.
|
|
57
|
+
* A **language selector** is displayed if a `LocaleContext` is available.
|
|
58
|
+
|
|
59
|
+
## Manual Configuration
|
|
60
|
+
|
|
61
|
+
For development, testing, or cases where you need to override the default metadata, you can pass a configuration object directly to the components using the `blockletMeta` prop.
|
|
62
|
+
|
|
63
|
+
```jsx App.js icon=logos:react
|
|
64
|
+
import React from 'react';
|
|
65
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
66
|
+
|
|
67
|
+
const customBlockletMeta = {
|
|
68
|
+
appName: 'My Custom App',
|
|
69
|
+
appLogo: 'https://path.to/your/logo.png',
|
|
70
|
+
navigation: [
|
|
71
|
+
{
|
|
72
|
+
title: 'Home',
|
|
73
|
+
link: '/',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
title: 'Documentation',
|
|
77
|
+
link: '/docs',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
function App() {
|
|
83
|
+
return (
|
|
84
|
+
<div>
|
|
85
|
+
<Header blockletMeta={customBlockletMeta} />
|
|
86
|
+
{/* ... rest of your app */}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
This approach gives you precise control over the component's appearance and behavior by overriding any data provided by the global `window.blocklet` object.
|
|
93
|
+
|
|
94
|
+
## Customizing the Header
|
|
95
|
+
|
|
96
|
+
The `Header` component includes an `addons` area on the right side, which you can customize to include your own components, such as action buttons or custom links.
|
|
97
|
+
|
|
98
|
+
The `addons` prop accepts a function that receives the default addon components as an argument. This allows you to prepend, append, or completely replace them.
|
|
99
|
+
|
|
100
|
+
```jsx CustomHeader.js icon=logos:react
|
|
101
|
+
import React from 'react';
|
|
102
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
103
|
+
import Button from '@mui/material/Button'; // Example using Material-UI
|
|
104
|
+
|
|
105
|
+
function CustomHeader() {
|
|
106
|
+
return (
|
|
107
|
+
<Header
|
|
108
|
+
addons={existingAddons => {
|
|
109
|
+
return [
|
|
110
|
+
<Button
|
|
111
|
+
key="custom-action"
|
|
112
|
+
variant="contained"
|
|
113
|
+
color="primary"
|
|
114
|
+
size="small"
|
|
115
|
+
style={{ marginRight: 8 }}>
|
|
116
|
+
Custom Action
|
|
117
|
+
</Button>,
|
|
118
|
+
...existingAddons, // Important: preserves default session/locale addons
|
|
119
|
+
];
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
In this example, a custom button is prepended to the existing addons. By including `...existingAddons`, you ensure that the default session and locale controls remain visible.
|
|
127
|
+
|
|
128
|
+
## Summary
|
|
129
|
+
|
|
130
|
+
You have successfully installed the `@blocklet/ui-react` library, rendered default `Header` and `Footer` components, and learned how to provide custom configurations and addons.
|
|
131
|
+
|
|
132
|
+
With these fundamentals in place, you are now prepared to explore the full range of components available in the library. For detailed documentation on layout, user management, and utility components, please proceed to the [Components](./components.md) section.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# 入門指南
|
|
2
|
+
|
|
3
|
+
本指南提供逐步教學,引導您安裝 `@blocklet/ui-react` 函式庫並渲染您的第一個元件。目標是在最短的時間內,讓您的應用程式中能正常運作 `Header` 和 `Footer`。
|
|
4
|
+
|
|
5
|
+
## 先決條件
|
|
6
|
+
|
|
7
|
+
在繼續之前,請確保您的開發環境中已安裝以下項目:
|
|
8
|
+
* 一個可運作的 React 專案。
|
|
9
|
+
* Node.js 和一個套件管理器(npm 或 yarn)。
|
|
10
|
+
|
|
11
|
+
## 安裝
|
|
12
|
+
|
|
13
|
+
首先,使用您偏好的套件管理器將 `@blocklet/ui-react` 套件新增至您的專案中。
|
|
14
|
+
|
|
15
|
+
使用 npm:
|
|
16
|
+
```bash npm
|
|
17
|
+
npm install @blocklet/ui-react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
使用 yarn:
|
|
21
|
+
```bash yarn
|
|
22
|
+
yarn add @blocklet/ui-react
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 基本用法:Header 與 Footer
|
|
26
|
+
|
|
27
|
+
`Header` 和 `Footer` 元件的設計旨在簡化使用,無需任何初始設定即可渲染。它們會自動從 blocklet 的元資料中獲取資料。
|
|
28
|
+
|
|
29
|
+
1. 將 `Header` 和 `Footer` 元件匯入到您的主應用程式檔案中(例如 `App.js`)。
|
|
30
|
+
2. 將它們分別放置在應用程式佈局的頂部和底部。
|
|
31
|
+
|
|
32
|
+
```jsx App.js icon=logos:react
|
|
33
|
+
import React from 'react';
|
|
34
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
35
|
+
import Footer from '@blocklet/ui-react/lib/Footer';
|
|
36
|
+
|
|
37
|
+
function App() {
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
<Header />
|
|
41
|
+
<main style={{ padding: '20px', minHeight: 'calc(100vh - 128px)' }}>
|
|
42
|
+
{/* 您的應用程式內容放在這裡 */}
|
|
43
|
+
<h1>Welcome to My Blocklet</h1>
|
|
44
|
+
</main>
|
|
45
|
+
<Footer />
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default App;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
這些元件會自動從 `window.blocklet` 元資料物件中檢索設定詳情,例如應用程式名稱、標誌和導覽連結。該物件由 Blocklet Server 環境注入。
|
|
54
|
+
|
|
55
|
+
此外,`Header` 元件會智慧地渲染額外的控制項:
|
|
56
|
+
* 如果 `SessionContext` 可用,將會顯示**使用者會話管理器**。
|
|
57
|
+
* 如果 `LocaleContext` 可用,將會顯示**語言選擇器**。
|
|
58
|
+
|
|
59
|
+
## 手動設定
|
|
60
|
+
|
|
61
|
+
在開發、測試或需要覆寫預設元資料的情況下,您可以使用 `blockletMeta` 屬性將設定物件直接傳遞給元件。
|
|
62
|
+
|
|
63
|
+
```jsx App.js icon=logos:react
|
|
64
|
+
import React from 'react';
|
|
65
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
66
|
+
|
|
67
|
+
const customBlockletMeta = {
|
|
68
|
+
appName: 'My Custom App',
|
|
69
|
+
appLogo: 'https://path.to/your/logo.png',
|
|
70
|
+
navigation: [
|
|
71
|
+
{
|
|
72
|
+
title: 'Home',
|
|
73
|
+
link: '/',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
title: 'Documentation',
|
|
77
|
+
link: '/docs',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
function App() {
|
|
83
|
+
return (
|
|
84
|
+
<div>
|
|
85
|
+
<Header blockletMeta={customBlockletMeta} />
|
|
86
|
+
{/* ... rest of your app */}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
這種方法讓您能透過覆寫全域 `window.blocklet` 物件提供的任何資料,來精確控制元件的外觀和行為。
|
|
93
|
+
|
|
94
|
+
## 自訂 Header
|
|
95
|
+
|
|
96
|
+
`Header` 元件在右側包含一個 `addons` 區域,您可以自訂該區域以包含您自己的元件,例如操作按鈕或自訂連結。
|
|
97
|
+
|
|
98
|
+
`addons` 屬性接受一個函式,該函式接收預設的附加元件作為參數。這讓您可以將新元件加到現有元件的前面、後面,或是完全取代它們。
|
|
99
|
+
|
|
100
|
+
```jsx CustomHeader.js icon=logos:react
|
|
101
|
+
import React from 'react';
|
|
102
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
103
|
+
import Button from '@mui/material/Button'; // 使用 Material-UI 的範例
|
|
104
|
+
|
|
105
|
+
function CustomHeader() {
|
|
106
|
+
return (
|
|
107
|
+
<Header
|
|
108
|
+
addons={existingAddons => {
|
|
109
|
+
return [
|
|
110
|
+
<Button
|
|
111
|
+
key="custom-action"
|
|
112
|
+
variant="contained"
|
|
113
|
+
color="primary"
|
|
114
|
+
size="small"
|
|
115
|
+
style={{ marginRight: 8 }}>
|
|
116
|
+
Custom Action
|
|
117
|
+
</Button>,
|
|
118
|
+
...existingAddons, // 重要:保留預設的 session/locale 附加元件
|
|
119
|
+
];
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
在此範例中,一個自訂按鈕被加到現有的附加元件前面。透過包含 `...existingAddons`,您可以確保預設的會話和地區設定控制項仍然可見。
|
|
127
|
+
|
|
128
|
+
## 總結
|
|
129
|
+
|
|
130
|
+
您已成功安裝 `@blocklet/ui-react` 函式庫,渲染了預設的 `Header` 和 `Footer` 元件,並學會了如何提供自訂設定和附加元件。
|
|
131
|
+
|
|
132
|
+
掌握了這些基礎知識後,您現在可以開始探索此函式庫中提供的所有元件了。關於佈局、使用者管理和工具程式元件的詳細文件,請前往 [元件](./components.md) 部分。
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# 快速入门
|
|
2
|
+
|
|
3
|
+
本指南将引导你逐步安装 @blocklet/ui-react 库并渲染你的第一个组件。目标是在最短的时间内在你的应用程序中拥有一个功能完备的 `Header` 和 `Footer`。
|
|
4
|
+
|
|
5
|
+
## 前提条件
|
|
6
|
+
|
|
7
|
+
在继续之前,请确保你的开发环境中已安装以下内容:
|
|
8
|
+
* 一个可正常工作的 React 项目。
|
|
9
|
+
* Node.js 和一个包管理器(npm 或 yarn)。
|
|
10
|
+
|
|
11
|
+
## 安装
|
|
12
|
+
|
|
13
|
+
首先,使用你偏好的包管理器将 `@blocklet/ui-react` 包添加到你的项目中。
|
|
14
|
+
|
|
15
|
+
使用 npm:
|
|
16
|
+
```bash npm
|
|
17
|
+
npm install @blocklet/ui-react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
使用 yarn:
|
|
21
|
+
```bash yarn
|
|
22
|
+
yarn add @blocklet/ui-react
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 基本用法:Header 和 Footer
|
|
26
|
+
|
|
27
|
+
`Header` 和 `Footer` 组件的设计旨在简化使用,无需任何初始配置即可渲染。它们会自动从 blocklet 的元数据中获取数据。
|
|
28
|
+
|
|
29
|
+
1. 将 `Header` 和 `Footer` 组件导入到你的主应用程序文件(例如 `App.js`)中。
|
|
30
|
+
2. 将它们分别放置在应用程序布局的顶部和底部。
|
|
31
|
+
|
|
32
|
+
```jsx App.js icon=logos:react
|
|
33
|
+
import React from 'react';
|
|
34
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
35
|
+
import Footer from '@blocklet/ui-react/lib/Footer';
|
|
36
|
+
|
|
37
|
+
function App() {
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
<Header />
|
|
41
|
+
<main style={{ padding: '20px', minHeight: 'calc(100vh - 128px)' }}>
|
|
42
|
+
{/* 你的应用程序内容放在这里 */}
|
|
43
|
+
<h1>Welcome to My Blocklet</h1>
|
|
44
|
+
</main>
|
|
45
|
+
<Footer />
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default App;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
这些组件会自动从 `window.blocklet` 元数据对象中检索配置详情(如应用名称、徽标和导航链接),该对象由 Blocklet Server 环境注入。
|
|
54
|
+
|
|
55
|
+
此外,`Header` 组件还会智能地渲染额外的控件:
|
|
56
|
+
* 如果 `SessionContext` 可用,则会显示**用户会话管理器**。
|
|
57
|
+
* 如果 `LocaleContext` 可用,则会显示**语言选择器**。
|
|
58
|
+
|
|
59
|
+
## 手动配置
|
|
60
|
+
|
|
61
|
+
在开发、测试或需要覆盖默认元数据的情况下,你可以使用 `blockletMeta` 属性直接向组件传递一个配置对象。
|
|
62
|
+
|
|
63
|
+
```jsx App.js icon=logos:react
|
|
64
|
+
import React from 'react';
|
|
65
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
66
|
+
|
|
67
|
+
const customBlockletMeta = {
|
|
68
|
+
appName: 'My Custom App',
|
|
69
|
+
appLogo: 'https://path.to/your/logo.png',
|
|
70
|
+
navigation: [
|
|
71
|
+
{
|
|
72
|
+
title: 'Home',
|
|
73
|
+
link: '/',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
title: 'Documentation',
|
|
77
|
+
link: '/docs',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
function App() {
|
|
83
|
+
return (
|
|
84
|
+
<div>
|
|
85
|
+
<Header blockletMeta={customBlockletMeta} />
|
|
86
|
+
{/* ... 你的应用程序的其余部分 */}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
这种方法允许你覆盖全局 `window.blocklet` 对象提供的任何数据,从而精确控制组件的外观和行为。
|
|
93
|
+
|
|
94
|
+
## 自定义 Header
|
|
95
|
+
|
|
96
|
+
`Header` 组件右侧包含一个 `addons` 区域,你可以对其进行自定义,以包含你自己的组件,例如操作按钮或自定义链接。
|
|
97
|
+
|
|
98
|
+
`addons` 属性接受一个函数作为参数,该函数接收默认的附加组件。这允许你在现有组件前后添加新组件或完全替换它们。
|
|
99
|
+
|
|
100
|
+
```jsx CustomHeader.js icon=logos:react
|
|
101
|
+
import React from 'react';
|
|
102
|
+
import Header from '@blocklet/ui-react/lib/Header';
|
|
103
|
+
import Button from '@mui/material/Button'; // 使用 Material-UI 的示例
|
|
104
|
+
|
|
105
|
+
function CustomHeader() {
|
|
106
|
+
return (
|
|
107
|
+
<Header
|
|
108
|
+
addons={existingAddons => {
|
|
109
|
+
return [
|
|
110
|
+
<Button
|
|
111
|
+
key="custom-action"
|
|
112
|
+
variant="contained"
|
|
113
|
+
color="primary"
|
|
114
|
+
size="small"
|
|
115
|
+
style={{ marginRight: 8 }}>
|
|
116
|
+
Custom Action
|
|
117
|
+
</Button>,
|
|
118
|
+
...existingAddons, // 重要:保留默认的 session/locale 附加组件
|
|
119
|
+
];
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
在此示例中,一个自定义按钮被添加到了现有附加组件的前面。通过包含 `...existingAddons`,你可以确保默认的会话和语言区域控件保持可见。
|
|
127
|
+
|
|
128
|
+
## 总结
|
|
129
|
+
|
|
130
|
+
你已成功安装 `@blocklet/ui-react` 库,渲染了默认的 `Header` 和 `Footer` 组件,并学会了如何提供自定义配置和附加组件。
|
|
131
|
+
|
|
132
|
+
掌握了这些基础知识后,你现在可以开始探索该库中提供的全部组件了。有关布局、用户管理和实用工具组件的详细文档,请继续阅读 [组件](./components.md) 部分。
|