From 1549ebdeca5991ee7cb98ff99531ebdbf0eb7614 Mon Sep 17 00:00:00 2001 From: duenyang <377153400@qq.com> Date: Tue, 15 Oct 2024 19:16:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(web-components):=20=E5=A2=9E=E5=8A=A0inner?= =?UTF-8?q?Class=E5=92=8CinnerStyle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/web-components/src/icon.tsx | 19 ++++++++++--------- .../web-components/src/iconfont/index.tsx | 13 +++++++------ .../web-components/src/svg-sprite/index.tsx | 13 +++++++------ 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/web-components/src/icon.tsx b/packages/web-components/src/icon.tsx index d3c2c3c8..7297df96 100644 --- a/packages/web-components/src/icon.tsx +++ b/packages/web-components/src/icon.tsx @@ -7,10 +7,11 @@ import { getStylesheet } from './util/check-url-and-load'; export interface IconProps extends OmiDOMAttributes { style?: CSSStyleDeclaration; + innerStyle?: CSSStyleDeclaration; /** - * 类名,叫cls是为了和className区分 + * 类名,叫innerClass是为了和最外层className区分 */ - cls?: string; + innerClass?: string; size?: 'small' | 'medium' | 'large' | string | number; } @@ -45,23 +46,23 @@ function render(node: VNode, id: string, rootProps?: { [key: string]: any }): VN ); } -export class IconBase extends Component { +export class IconBase extends Component { static css = [getStylesheet()]; static icon: VNode | null = null; static propTypes = { - cls: String, + innerClass: String, + innerStyle: Object, size: String, - style: Object, } render(props) { const { id, - cls, size, - style, + innerClass, + innerStyle, ...restProps } = props; @@ -69,10 +70,10 @@ export class IconBase extends Component { delete (restProps as any)?.className; const { className: sizeClassName, style: sizeStyle } = getSizeProps(size); - const combinCls = classname('t-icon', `t-icon-${id}`, cls, sizeClassName); + const combinCls = classname('t-icon', `t-icon-${id}`, sizeClassName, innerClass); return render((this.constructor as typeof IconBase).icon as VNode, `${id}`, { className: combinCls, - style: { ...style, ...sizeStyle }, + style: { ...sizeStyle, ...innerStyle }, ...restProps, }); } diff --git a/packages/web-components/src/iconfont/index.tsx b/packages/web-components/src/iconfont/index.tsx index b0f0c33f..14d1a445 100644 --- a/packages/web-components/src/iconfont/index.tsx +++ b/packages/web-components/src/iconfont/index.tsx @@ -75,9 +75,9 @@ export default class IconFont extends Component { name: String, url: [String, Array], loadDefaultIcons: Boolean, - cls: String, size: String, - style: Object, + innerClass: String, + innerStyle: Object, } get isBuiltInIcon() { @@ -90,21 +90,22 @@ export default class IconFont extends Component { [this.props.name || '']: this.props.url, [`${this.classPrefix}-icon`]: !this.props.url || this.isBuiltInIcon, [`${this.classPrefix}-icon-${this.props.name}`]: !this.props.url, - }, sizeClassName, this.props.cls); + }, sizeClassName, this.props.innerClass); } render(props: OmiProps) { const { size, tag: Tag = 'i', - style: customStyle, + innerStyle, ...htmlProps } = props; delete htmlProps.loadDefaultIcons; delete htmlProps.url; - delete htmlProps.cls; delete htmlProps.className; + delete htmlProps.class; + delete htmlProps.style; delete htmlProps.name; const { style: sizeStyle } = getSizeProps(size); @@ -114,7 +115,7 @@ export default class IconFont extends Component { diff --git a/packages/web-components/src/svg-sprite/index.tsx b/packages/web-components/src/svg-sprite/index.tsx index c622aad8..6c7acc48 100644 --- a/packages/web-components/src/svg-sprite/index.tsx +++ b/packages/web-components/src/svg-sprite/index.tsx @@ -61,9 +61,9 @@ export class Icon extends Component { name: String, url: [String, Array], loadDefaultIcons: Boolean, - cls: String, size: String, - style: Object, + innerClass: String, + innerStyle: Object, } classPrefix = getClassPrefix(); @@ -72,7 +72,7 @@ export class Icon extends Component { get class() { const { - url, name, size, cls: customClassName, + url, name, size, innerClass: customClassName, } = this.props; const iconName = url ? name : `${this.classPrefix}-icon-${name}`; const { className: sizeClassName } = getSizeProps(size); @@ -94,13 +94,14 @@ export class Icon extends Component { const { name = '', size, - style, + innerStyle, ...restProps } = props; delete restProps.loadDefaultIcons; - delete restProps.cls; + delete restProps.class; delete (restProps as any)?.className; + delete restProps.style; delete restProps.url; const { style: sizeStyle } = getSizeProps(size); @@ -109,7 +110,7 @@ export class Icon extends Component { const node = JSON.parse(this.svgIconJson?.[name] || '{}'); return render(node, `${name}`, { className: this.class, - style: { ...style, ...sizeStyle }, + style: { ...sizeStyle, ...innerStyle }, ...restProps, part: 't-icon', });