Skip to content

Commit

Permalink
feat: ✨ 修改主题配置
Browse files Browse the repository at this point in the history
  • Loading branch information
G committed Dec 12, 2023
1 parent a2dd393 commit fe73f60
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/gbeata/.dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default defineConfig({
copyright: 'Copyright © 2022-present Gbeata',
theme: 'dark',
},
siteToken: {
sidebarWidth: 280,
demoInheritSiteTheme: true,
},
// 单语言时配置数组即可
// features: [{ title: '开箱即用'}, { description: '接入简单,安装即使用,全面融入 Ant Design 5.0 风格。'}]
// 多语言时配置对象,key 为语言名
Expand Down
102 changes: 102 additions & 0 deletions packages/gbeata/docs/components/locale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
group: 全局配置
---

# 国际化 - 多语言

gbeata 默认是中文,如果需要使用其它语言,请参考下面。

设置 gbeata 语言时,会在 `localStorage` 存储 `MULTIWAY_LOCALE`,存储的是语言名。

## 方法一、通过 setLanguage 更改语言

```tsx
import React, { useState } from 'react';
import { GCardGroup, setLanguage } from 'gbeata';
import { Modal } from 'antd';

export default function Demo() {
const [locale, setLocale] = useState(
localStorage.getItem('MULTIWAY_LOCALE') || 'zh_CN',
);

const handleChange = (value: string) => {
setLocale(value);
setLanguage(value);
Modal.confirm({
title: '语言更换提示',
content:
'切换语言后,只会对 Multiway 组件产生影响,可观察其它页面的变化。',
onOk: () => {
window.location.reload();
},
});
};
return (
<GCardGroup
bordered={false}
onChange={handleChange}
value={locale}
options={[
{ label: '中文', value: 'zh_CN' },
{ label: '英文', value: 'en_US' },
{ label: '日文', value: 'ja_JP' },
]}
/>
);
}
```

```js
import { setLanguage } from 'gbeata';
setLanguage('zh_CN');
```

## 方法二、通过 localStorage 更改语言

```tsx
import React, { useState } from 'react';
import { GCardGroup } from 'gbeata';
import { Modal } from 'antd';

export default function Demo() {
const [locale, setLocale] = useState(
localStorage.getItem('MULTIWAY_LOCALE') || 'zh_CN',
);

const handleChange = (value: string) => {
setLocale(value);
localStorage.setItem('MULTIWAY_LOCALE', value);
Modal.confirm({
title: '语言更换提示',
content:
'切换语言后,只会对 Multiway 组件产生影响,可观察其它页面的变化。',
onOk: () => {
window.location.reload();
},
});
};
return (
<GCardGroup
bordered={false}
onChange={handleChange}
value={locale}
options={[
{ label: '中文', value: 'zh_CN' },
{ label: '英文', value: 'en_US' },
{ label: '日文', value: 'ja_JP' },
]}
/>
);
}
```

```js
localStorage.setItem('MULTIWAY_LOCALE', 'zh_CN');
```

| 语言 | 语言名 |
| ---- | ------ |
| 中文 | zh_CN |
| 英文 | en_US |
| 日文 | ja_JP |
14 changes: 14 additions & 0 deletions packages/gbeata/docs/components/setSearchDefaultVisibleRow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
group: 全局配置
---

# 表格折叠行数设置

```js
import { setSearchDefaultVisibleRow } from 'gbeata';

// 默认是 2,可以设置成 1
setSearchDefaultVisibleRow(1);
```

<embed src="./index.md"></embed>
43 changes: 43 additions & 0 deletions packages/gbeata/docs/components/setTableDefaultProps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
group: 全局配置
---

# 设置表格默认属性

可以通过 `setTableDefaultProps` 设置一些表格的默认属性,现在你可以跑到其它表格页面,会发现已经没有了边框。

```tsx
import React from 'react';
import { GSearchTable, GSearchTableField, setTableDefaultProps } from 'gbeata';
import { listApi } from '../api';

setTableDefaultProps({
bordered: false,
});

const fields: Array<GSearchTableField> = [
{
title: '姓名',
key: 'cn',
search: true,
},
{
title: '英文名',
key: 'en',
search: true,
},
];

export default function Demo() {
return (
<GSearchTable
title="取消全局表格的边框"
rowKey="sort_id"
api={listApi}
fields={fields}
/>
);
}
```

<embed src="./index.md"></embed>

0 comments on commit fe73f60

Please sign in to comment.