codernew-api-frontend/src/components/Settings/block.tsx
gaoziman f77675e5fc feat(核心): 添加项目源代码
- 实现 React + Arco Design Pro 基础框架
- 添加页面路由和布局组件
- 实现用户认证和权限管理
- 添加数据可视化图表组件
- 实现列表、表单等常用页面模块
- 配置 Redux 状态管理
- 添加工具函数和自定义 Hooks
2025-11-05 09:48:31 +08:00

78 lines
2.5 KiB
TypeScript

import React, { ReactNode } from 'react';
import { Switch, Divider, InputNumber } from '@arco-design/web-react';
import { useSelector, useDispatch } from 'react-redux';
import { GlobalState } from '../../store';
import useLocale from '../../utils/useLocale';
import styles from './style/block.module.less';
export interface BlockProps {
title?: ReactNode;
options?: { name: string; value: string; type?: 'switch' | 'number' }[];
children?: ReactNode;
}
export default function Block(props: BlockProps) {
const { title, options, children } = props;
const locale = useLocale();
const settings = useSelector((state: GlobalState) => state.settings);
const dispatch = useDispatch();
return (
<div className={styles.block}>
<h5 className={styles.title}>{title}</h5>
{options &&
options.map((option) => {
const type = option.type || 'switch';
return (
<div className={styles['switch-wrapper']} key={option.value}>
<span>{locale[option.name]}</span>
{type === 'switch' && (
<Switch
size="small"
checked={!!settings[option.value]}
onChange={(checked) => {
const newSetting = {
...settings,
[option.value]: checked,
};
dispatch({
type: 'update-settings',
payload: { settings: newSetting },
});
// set color week
if (checked && option.value === 'colorWeek') {
document.body.style.filter = 'invert(80%)';
}
if (!checked && option.value === 'colorWeek') {
document.body.style.filter = 'none';
}
}}
/>
)}
{type === 'number' && (
<InputNumber
style={{ width: 80 }}
size="small"
value={settings.menuWidth}
onChange={(value) => {
const newSetting = {
...settings,
[option.value]: value,
};
dispatch({
type: 'update-settings',
payload: { settings: newSetting },
});
}}
/>
)}
</div>
);
})}
{children}
<Divider />
</div>
);
}