From 0d28ec4f09e8cc8fc6f9a1bddd8e07b5eeb10dc9 Mon Sep 17 00:00:00 2001 From: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com> Date: Thu, 25 Jan 2024 20:56:48 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=9B=BA=E5=AE=9Aicon=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E7=9A=84=E4=BA=8B=E4=BB=B6,?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-ui/src/components/icons.tsx | 60 +++++++++++------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/amis-ui/src/components/icons.tsx b/packages/amis-ui/src/components/icons.tsx index 2a9aa6731da..540ac2a3f58 100644 --- a/packages/amis-ui/src/components/icons.tsx +++ b/packages/amis-ui/src/components/icons.tsx @@ -265,8 +265,18 @@ export function Icon({ onClick = () => {}, onMouseEnter = () => {}, onMouseLeave = () => {}, - style, - ...rest + onMouseOver = () => {}, + onMouseOut = () => {}, + onMouseDown = () => {}, + onMouseUp = () => {}, + onMouseMove = () => {}, + onBlur = () => {}, + onFocus = () => {}, + onTouchStart = () => {}, + onTouchMove = () => {}, + onTouchEnd = () => {}, + onTouchCancel = () => {}, + style }: { icon: string; iconContent?: string; @@ -281,13 +291,23 @@ export function Icon({ return null; } - // 获取全部事件 - let events: any = {}; - Object.keys(rest).forEach(key => { - if (key.startsWith('on') && key.length > 2) { - events[key] = rest[key]; - } - }); + // 支持的事件 + let events: any = { + onClick, + onMouseEnter, + onMouseLeave, + onMouseOver, + onMouseOut, + onMouseDown, + onMouseUp, + onMouseMove, + onBlur, + onFocus, + onTouchStart, + onTouchMove, + onTouchEnd, + onTouchCancel + }; // 直接的icon dom if (React.isValidElement(icon)) { @@ -298,9 +318,7 @@ export function Icon({ (icon.props as any).className ), style, - onClick, - onMouseEnter, - onMouseLeave + ...events }); } @@ -327,9 +345,6 @@ export function Icon({ return (
@@ -395,9 +404,6 @@ export function Icon({ const svgStr = /(.*?)<\/svg>/.exec(icon); const svgHTML = createElement('svg', { ...events, - onClick, - onMouseEnter, - onMouseLeave, className: cx('icon', className, classNameProp), style, dangerouslySetInnerHTML: {__html: svgStr ? svgStr[1] : ''}, @@ -412,9 +418,6 @@ export function Icon({ return (