oee
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { createContext, useContext, useRef, type ReactNode } from 'react';
|
||||
import { Pause, Play } from 'lucide-react';
|
||||
import { useTheme } from '../../context/ThemeContext';
|
||||
import { useAutoScroll } from '../../hooks/useAutoScroll';
|
||||
|
||||
/**
|
||||
* 左右工作区列表的自动滚动开关。
|
||||
* 用 context 下发而不是逐层传 prop:一份弧板里挂着好几个页签
|
||||
* (左:销售订单 / 客户资料;右:采购单 / 生产工单 / 供应商资料),
|
||||
* 开关属于「这块面板」而不是某个列表,页签组件本身不该关心它。
|
||||
*/
|
||||
const AutoScrollCtx = createContext(false);
|
||||
|
||||
export const AutoScrollProvider = AutoScrollCtx.Provider;
|
||||
|
||||
/** 当前面板是否开启自动滚动;ScrollList 用它决定是否挂滚动循环 */
|
||||
export const useAutoScrollEnabled = () => useContext(AutoScrollCtx);
|
||||
|
||||
interface ToggleProps {
|
||||
on: boolean;
|
||||
onToggle: () => void;
|
||||
/** 收起态宽度只够一个图标,文字标签在展开态才出现 */
|
||||
expanded?: boolean;
|
||||
}
|
||||
|
||||
/** 面板标题栏的自动滚动开关按钮:开=可点击关闭,关=可点击开启 */
|
||||
export function AutoScrollToggle({ on, onToggle, expanded = true }: ToggleProps) {
|
||||
const { tokens } = useTheme();
|
||||
const c = on ? tokens.accent : tokens.textMuted;
|
||||
return (
|
||||
<button
|
||||
onClick={onToggle}
|
||||
aria-pressed={on}
|
||||
title={on ? '列表自动滚动中,点击关闭' : '自动滚动已关闭,点击开启'}
|
||||
className="ghost-btn"
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 4, flexShrink: 0,
|
||||
height: 22, padding: expanded ? '0 7px 0 5px' : '0 5px', borderRadius: 6, cursor: 'pointer',
|
||||
fontSize: 11, fontWeight: 600, whiteSpace: 'nowrap',
|
||||
color: c, background: on ? tokens.accentBg : 'transparent',
|
||||
border: `1px solid ${on ? tokens.borderAccent : tokens.border}`,
|
||||
}}
|
||||
>
|
||||
{on ? <Pause size={12} /> : <Play size={12} />}
|
||||
{expanded && <span>{on ? '自动滚动' : '已暂停'}</span>}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 面板内带自动滚动的列表容器:样式同 PanelBody,差别是它挂了滚动循环。
|
||||
* 开关默认跟随所在面板的 AutoScrollProvider,也可以显式传 autoScroll 覆盖。
|
||||
*/
|
||||
export function ScrollList({ children, autoScroll }: { children: ReactNode; autoScroll?: boolean }) {
|
||||
const ctx = useAutoScrollEnabled();
|
||||
const enabled = autoScroll ?? ctx;
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useAutoScroll(ref, enabled);
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
className="space-scroll"
|
||||
data-autoscroll={enabled ? 'on' : 'off'}
|
||||
style={{ flex: 1, minHeight: 0, overflowY: 'auto', overflowX: 'hidden', padding: '0 0 10px 0' }}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user