未验证 提交 f47e5335 编写于 作者: O oasis-cloud 提交者: GitHub

fix: icon 组件未设置 width、height 时,不应出现在 style 上 (#628)

上级 6274393c
......@@ -26,7 +26,13 @@ const defaultProps = {
} as IconProps
function pxCheck(value: string | number): string {
return Number.isNaN(Number(value)) ? String(value) : `${value}px`
if (value === '') {
return value
}
if (Number.isNaN(Number(value))) {
return String(value)
}
return `${value}px`
}
export function Icon<T>(props: Partial<IconProps> & T): ReactElement {
......@@ -59,6 +65,11 @@ export function Icon<T>(props: Partial<IconProps> & T): ReactElement {
if (isImage) return { src: name }
return {}
}
const styles: any = {}
const checkedSize: any = pxCheck(size)
if (checkedSize) {
styles.width = styles.height = styles.fontSize = checkedSize
}
return React.createElement<any>(
type,
{
......@@ -69,9 +80,7 @@ export function Icon<T>(props: Partial<IconProps> & T): ReactElement {
}`,
style: {
color,
fontSize: pxCheck(size),
width: pxCheck(size),
height: pxCheck(size),
...styles,
...style,
},
...rest,
......
......@@ -26,7 +26,13 @@ const defaultProps = {
} as IconProps
function pxCheck(value: string | number): string {
return Number.isNaN(Number(value)) ? String(value) : `${value}px`
if (value === '') {
return value
}
if (Number.isNaN(Number(value))) {
return String(value)
}
return `${value}px`
}
export function Icon<T>(props: Partial<IconProps> & T): ReactElement {
......@@ -59,6 +65,13 @@ export function Icon<T>(props: Partial<IconProps> & T): ReactElement {
if (isImage) return { src: name }
return {}
}
const styles: any = {}
const checkedSize: any = pxCheck(size)
if (checkedSize) {
styles.width = styles.height = styles.fontSize = checkedSize
}
return React.createElement<any>(
type,
{
......@@ -69,9 +82,7 @@ export function Icon<T>(props: Partial<IconProps> & T): ReactElement {
}`,
style: {
color,
fontSize: pxCheck(size),
width: pxCheck(size),
height: pxCheck(size),
...styles,
...style,
},
...rest,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册