feat: allow setting sidebar width in theme config

This commit is contained in:
chenos 2025-04-20 11:11:54 +08:00
parent 97f4a6ccff
commit 2c4f119651
5 changed files with 19 additions and 4 deletions

View File

@ -49,6 +49,8 @@ export interface CustomToken extends AliasToken {
marginBlock: number; marginBlock: number;
/** 区块的圆角 */ /** 区块的圆角 */
borderRadiusBlock: number; borderRadiusBlock: number;
siderWidth: number;
} }
export interface ThemeConfig extends _ThemeConfig { export interface ThemeConfig extends _ThemeConfig {

View File

@ -503,6 +503,8 @@ const subMenuItemRender = (item, dom) => {
}; };
const CollapsedButton: FC<{ collapsed: boolean }> = (props) => { const CollapsedButton: FC<{ collapsed: boolean }> = (props) => {
const { token } = useToken();
return ( return (
<RouteContext.Consumer> <RouteContext.Consumer>
{(context) => {(context) =>
@ -515,7 +517,7 @@ const CollapsedButton: FC<{ collapsed: boolean }> = (props) => {
// Fix the issue where the collapse/expand button is covered by subpages // Fix the issue where the collapse/expand button is covered by subpages
.ant-pro-sider-collapsed-button { .ant-pro-sider-collapsed-button {
top: 64px; top: 64px;
left: ${props.collapsed ? 52 : 188}px; left: ${props.collapsed ? 52 : (token.siderWidth || 200) - 12}px;
z-index: 200; z-index: 200;
transition: left 0.2s; transition: left 0.2s;
} }
@ -671,7 +673,7 @@ export const InternalAdminLayout = () => {
<DndContext onDragEnd={onDragEnd}> <DndContext onDragEnd={onDragEnd}>
<ProLayout <ProLayout
contentStyle={contentStyle} contentStyle={contentStyle}
siderWidth={200} siderWidth={token.siderWidth || 200}
className={resetStyle} className={resetStyle}
location={location} location={location}
route={route} route={route}

View File

@ -279,7 +279,7 @@ const category: TokenTree<keyof AliasToken | string> = [
nameEn: 'Others', nameEn: 'Others',
desc: '', desc: '',
descEn: '', descEn: '',
seedToken: ['wireframe'], seedToken: ['wireframe', 'siderWidth'],
}, },
], ],
}, },

View File

@ -10,7 +10,7 @@
import { CaretRightOutlined, ExpandOutlined, QuestionCircleOutlined } from '@ant-design/icons'; import { CaretRightOutlined, ExpandOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import type { ThemeConfig } from '@nocobase/client'; import type { ThemeConfig } from '@nocobase/client';
import { StablePopover } from '@nocobase/client'; import { StablePopover } from '@nocobase/client';
import { Button, Checkbox, Collapse, ConfigProvider, Switch, Tooltip, Typography } from 'antd'; import { Button, Checkbox, Collapse, ConfigProvider, InputNumber, Switch, Tooltip, Typography } from 'antd';
import seed from 'antd/es/theme/themes/seed'; import seed from 'antd/es/theme/themes/seed';
import classNames from 'classnames'; import classNames from 'classnames';
import type { FC } from 'react'; import type { FC } from 'react';
@ -346,6 +346,9 @@ const SeedTokenPreview: FC<SeedTokenProps> = ({ theme, tokenName, disabled, alph
/> />
)} )}
{tokenName === 'wireframe' && <Switch checked={tokenValue} onChange={handleChange} />} {tokenName === 'wireframe' && <Switch checked={tokenValue} onChange={handleChange} />}
{['siderWidth'].includes(tokenName) && (
<InputNumber defaultValue={200} value={tokenValue} onChange={handleChange} />
)}
</div> </div>
); );
}; };

View File

@ -1592,6 +1592,14 @@
"type": "boolean", "type": "boolean",
"source": "seed" "source": "seed"
}, },
"siderWidth": {
"name": "侧边栏宽度px",
"nameEn": "Sider width (px)",
"desc": "调整侧边栏展示区域的宽度宽度单位通常为像素px",
"descEn": "Adjust the width of the sidebar display area. The width is usually measured in pixels (px).",
"type": "number",
"source": "map"
},
"zIndexBase": { "zIndexBase": {
"name": "基础 zIndex", "name": "基础 zIndex",
"nameEn": "Base zIndex", "nameEn": "Base zIndex",