67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
interface SteerButtonProps {
|
|
icon: React.ReactNode;
|
|
label: string;
|
|
color: string;
|
|
// 受控高亮:由父组件统一管理,保证同组按钮互斥(不会同时显示为按下)
|
|
active?: boolean;
|
|
disabled?: boolean;
|
|
onToggle?: () => void;
|
|
}
|
|
|
|
/**
|
|
* 锁存按钮(受控):
|
|
* 高亮状态完全由 active 决定,点击只触发 onToggle。
|
|
* 持续发送 / 互斥逻辑由父组件统一管理。
|
|
*/
|
|
const SteerButton = ({
|
|
icon,
|
|
label,
|
|
color,
|
|
active = false,
|
|
disabled = false,
|
|
onToggle,
|
|
}: SteerButtonProps) => {
|
|
return (
|
|
<button
|
|
type="button"
|
|
aria-label={label}
|
|
aria-pressed={active}
|
|
disabled={disabled}
|
|
onClick={onToggle}
|
|
onContextMenu={(e) => e.preventDefault()}
|
|
style={{
|
|
flex: '1 1 0',
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
gap: 4,
|
|
minHeight: 46,
|
|
padding: '6px 4px',
|
|
borderRadius: 8,
|
|
border: `1px solid ${active ? color : `${color}55`}`,
|
|
background: active ? `${color}22` : 'transparent',
|
|
color,
|
|
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
opacity: disabled ? 0.4 : 1,
|
|
userSelect: 'none',
|
|
touchAction: 'none',
|
|
transform: active ? 'scale(0.97)' : 'scale(1)',
|
|
boxShadow: active ? `0 0 14px ${color}66, inset 0 0 8px ${color}22` : 'none',
|
|
fontWeight: active ? 700 : 500,
|
|
transition:
|
|
'transform .08s, background .12s, border-color .12s, box-shadow .12s, font-weight .12s, opacity .12s',
|
|
}}
|
|
>
|
|
<span style={{ display: 'inline-flex', fontSize: 16, lineHeight: 1 }}>
|
|
{icon}
|
|
</span>
|
|
|
|
<span style={{ fontSize: 11, fontWeight: 600, whiteSpace: 'nowrap' }}>
|
|
{label}
|
|
</span>
|
|
</button>
|
|
);
|
|
};
|
|
export default SteerButton;
|