1 回答
TA贡献1801条经验 获得超15个赞
我决定在钩子的帮助下
import React from 'react';
import {DeleteTwoTone, WarningTwoTone, EditTwoTone} from '@ant-design/icons';
const iconStyle = {fontSize: '18px'};
const activeColors= {
warn: '#ff9d52',
delete: '#ff4d4f',
edit: '#709cd9'
};
const defaultColors = {
warn: '#d9d9d9',
delete: '#d9d9d9',
edit: '#d9d9d9'
};
export const Control = ({className, onClick}) => {
const [colors, setColors] = React.useState(defaultColors);
const mouseLeaveHandler = () => {
setColors(defaultColors)
};
const mouseEnterHandler = (field) => {
setColors(prev => {
return {
...prev,
[field]: activeColors[field]
}
})
};
return (
<div className={className}>
<WarningTwoTone
twoToneColor={colors.warn}
style={iconStyle}
onMouseEnter={() => mouseEnterHandler('warn')}
onMouseLeave={mouseLeaveHandler}
/>
<EditTwoTone
twoToneColor={colors.edit}
onMouseEnter={() => mouseEnterHandler('edit')}
onMouseLeave={mouseLeaveHandler}
style={iconStyle}
/>
<DeleteTwoTone
twoToneColor={colors.delete}
style={iconStyle}
onMouseEnter={() => mouseEnterHandler('delete')}
onMouseLeave={mouseLeaveHandler}
/>
</div>
)
};
添加回答
举报