mantur-components 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +46 -34
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,57 +1,67 @@
1
1
  # mantur-components
2
2
 
3
- Reusable Mantur React component library for React and Arco Design.
3
+ Mantur React 组件库,基于 React Arco Design
4
4
 
5
- ## Install
5
+ ## 安装
6
6
 
7
7
  ```bash
8
8
  npm install mantur-components
9
9
  ```
10
10
 
11
- Required peer dependencies:
11
+ 需要宿主项目提供以下 peer dependencies
12
12
 
13
13
  ```bash
14
14
  npm install react react-dom @arco-design/web-react next-themes react-i18next
15
15
  ```
16
16
 
17
- The library uses Tailwind utility classes and does not export a standalone CSS file.
17
+ 组件库使用 Tailwind 工具类,不再导出独立的 CSS 文件,不需要引入 `mantur-components/style.css`。
18
18
 
19
19
  ## ManturHeader
20
20
 
21
- `ManturHeader` is the shared Mantur user header. It owns the header UI and the API calls for:
21
+ `ManturHeader` Mantur 用户端共用 Header。组件内部已经封装以下能力:
22
22
 
23
- - tenant list
24
- - current tenant
25
- - tenant switching
26
- - user points
27
- - profile update
28
- - logout
29
- - language switch
30
- - theme switch
23
+ - 获取团队列表
24
+ - 获取当前团队
25
+ - 切换团队
26
+ - 获取用户积分
27
+ - 个人资料更新
28
+ - 退出登录
29
+ - 语言切换
30
+ - 主题切换
31
31
 
32
- Basic usage:
32
+ ### 基础使用
33
33
 
34
34
  ```tsx
35
35
  import { ManturHeader } from "mantur-components";
36
36
 
37
- export function Header({ userInfo }: { userInfo: { username?: string; nickname?: string; avatar?: string } | null }) {
37
+ export function Header({
38
+ userInfo,
39
+ }: {
40
+ userInfo: { username?: string; nickname?: string; avatar?: string } | null;
41
+ }) {
38
42
  return <ManturHeader user={userInfo} />;
39
43
  }
40
44
  ```
41
45
 
42
- With disabled tenant switching and custom slots:
46
+ ### 禁用团队切换和自定义插槽
43
47
 
44
48
  ```tsx
45
49
  import { ManturHeader } from "mantur-components";
46
50
 
47
- export function Header({ userInfo, disabled }: { userInfo: UserInfo | null; disabled?: boolean }) {
51
+ export function Header({
52
+ userInfo,
53
+ disabled,
54
+ }: {
55
+ userInfo: UserInfo | null;
56
+ disabled?: boolean;
57
+ }) {
48
58
  return (
49
59
  <ManturHeader
50
60
  user={userInfo}
51
61
  disabled={disabled}
52
- brandSlot={<span className="text-lg font-bold">Custom Brand</span>}
62
+ brandSlot={<span className="text-lg font-bold">自定义品牌</span>}
53
63
  >
54
- <div className="px-4">Custom center content</div>
64
+ <div className="px-4">自定义中间内容</div>
55
65
  </ManturHeader>
56
66
  );
57
67
  }
@@ -68,15 +78,15 @@ interface ManturHeaderProps {
68
78
  }
69
79
  ```
70
80
 
71
- `user`: Current user shown in the right user menu.
81
+ `user`:右侧用户菜单展示的当前用户信息。
72
82
 
73
- `disabled`: Disables tenant switching. When true, the tenant selector is shown as disabled and cannot be opened or switched.
83
+ `disabled`:是否禁用团队切换。为 `true` 时,团队选择器展示为禁用态,无法展开和切换。
74
84
 
75
- `brandSlot`: Replaces the default brand title next to the logo. If omitted, the default localized title is shown.
85
+ `brandSlot`:Logo 右侧品牌标题插槽。传入后显示传入内容;不传则显示默认国际化标题。
76
86
 
77
- `children`: Renders custom content in the middle flexible header area. If omitted, the area stays empty.
87
+ `children`:Header 中间弹性区域插槽。传入后显示传入内容;不传则保持为空。
78
88
 
79
- ### User Type
89
+ ### 用户类型
80
90
 
81
91
  ```ts
82
92
  interface ManturHeaderUser {
@@ -88,25 +98,27 @@ interface ManturHeaderUser {
88
98
  }
89
99
  ```
90
100
 
91
- ### API Base
101
+ ## API 配置
92
102
 
93
- By default, API requests use `import.meta.env.VITE_API` and fall back to `/api`.
103
+ 默认情况下,组件库接口请求使用 `import.meta.env.VITE_API`,如果没有配置则回退到 `/api`。
94
104
 
95
- You can override it before rendering:
105
+ 可以在渲染组件前通过全局变量覆盖:
96
106
 
97
107
  ```ts
98
108
  window.__MANTUR_COMPONENTS_API_BASE__ = "/api";
99
109
  ```
100
110
 
101
- Points endpoint defaults to `/users/me/points`. It can be overridden:
111
+ 积分接口默认是 `/users/me/points`,也可以覆盖:
102
112
 
103
113
  ```ts
104
114
  window.__MANTUR_COMPONENTS_POINTS_ENDPOINT__ = "/users/me/points";
105
115
  ```
106
116
 
107
- ### Tenant Context Event
117
+ ## 团队上下文同步
118
+
119
+ 团队列表、当前团队、切换团队都由 `ManturHeader` 内部处理。
108
120
 
109
- The header fetches and switches tenants internally. If the host app needs to sync local stores, listen to `MANTUR_TENANT_CONTEXT_CHANGE_EVENT`.
121
+ 如果宿主项目需要同步自己的 store,例如 `activeTenantId`、权限、角色、已开通应用,可以监听 `MANTUR_TENANT_CONTEXT_CHANGE_EVENT`。
110
122
 
111
123
  ```tsx
112
124
  import {
@@ -118,7 +130,7 @@ import {
118
130
  function applyTenantContext(detail: ManturTenantContextDetail) {
119
131
  const tenantId = detail.auth?.tenantId || detail.currentTenant?.tenantId;
120
132
 
121
- // Sync host app stores here.
133
+ // 在这里同步宿主项目的状态。
122
134
  // setActiveTenantId(tenantId)
123
135
  // setPermissions(detail.auth?.permissions || [])
124
136
  // setRoles(detail.auth?.roles || [])
@@ -137,7 +149,7 @@ if (snapshot) {
137
149
  }
138
150
  ```
139
151
 
140
- Tenant context detail:
152
+ 团队上下文数据结构:
141
153
 
142
154
  ```ts
143
155
  interface ManturTenantContextDetail {
@@ -154,7 +166,7 @@ interface ManturTenantContextDetail {
154
166
  }
155
167
  ```
156
168
 
157
- ### Exported Helpers
169
+ ## 导出的工具方法
158
170
 
159
171
  ```ts
160
172
  import {
@@ -171,7 +183,7 @@ import {
171
183
  } from "mantur-components";
172
184
  ```
173
185
 
174
- ## Build
186
+ ## 构建
175
187
 
176
188
  ```bash
177
189
  npm run build
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mantur-components",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Reusable Mantur React component library.",
5
5
  "type": "module",
6
6
  "main": "./dist/mantur-components.umd.cjs",