Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加对于不规范(任意)结构的svg处理支持? #445

Open
yijinc opened this issue Apr 27, 2022 · 1 comment
Open

增加对于不规范(任意)结构的svg处理支持? #445

yijinc opened this issue Apr 27, 2022 · 1 comment

Comments

@yijinc
Copy link

yijinc commented Apr 27, 2022

发现用@icon-park/compiler处理svg图标,就算不规范的大部分也可以compiler正确,但是对于很多类似outline类型的svg,生成出来的代码将 颜色 参数丢失了(fill="#000000"没有被替换

举个栗子🌰

source svg

<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
  <path fill-rule="evenodd" clip-rule="evenodd" d="M22 40C22 40.5523 22.4477 41 23 41H25C25.5523 41 26 40.5523 26 40V26H40C40.5523 26 41 25.5523 41 25V23C41 22.4477 40.5523 22 40 22H26V8C26 7.44772 25.5523 7 25 7H23C22.4477 7 22 7.44772 22 8V22H8C7.44772 22 7 22.4477 7 23V25C7 25.5523 7.44772 26 8 26H22V40Z" fill="#131212"/>
</svg>

生成的 svg code

import {ISvgIconProps, IconWrapper} from '../runtime';

export default IconWrapper('add-base-outline', (props: ISvgIconProps) => (
    '<?xml version="1.0" encoding="UTF-8"?>'
    + '<svg width="' + props.size + '" height="' + props.size + '" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">'
        + '<path fill-rule="evenodd" clip-rule="evenodd" d="M22 40C22 40.5523 22.4477 41 23 41H25C25.5523 41 26 40.5523 26 40V26H40C40.5523 26 41 25.5523 41 25V23C41 22.4477 40.5523 22 40 22H26V8C26 7.44772 25.5523 7 25 7H23C22.4477 7 22 7.44772 22 8V22H8C7.44772 22 7 22.4477 7 23V25C7 25.5523 7.44772 26 8 26H22V40Z" fill="#131212"/>'
    + '</svg>'
));

生成的 react code

export default IconWrapper(
    'add-base-outline',
    true,
    (props: ISvgIconProps) => (
        <svg
            width={props.size}
            height={props.size}
            viewBox="0 0 48 48"
            fill="none"
        >
            <path
                fillRule="evenodd"
                clipRule="evenodd"
                d="M22 40C22 40.5523 22.4477 41 23 41H25C25.5523 41 26 40.5523 26 40V26H40C40.5523 26 41 25.5523 41 25V23C41 22.4477 40.5523 22 40 22H26V8C26 7.44772 25.5523 7 25 7H23C22.4477 7 22 7.44772 22 8V22H8C7.44772 22 7 22.4477 7 23V25C7 25.5523 7.44772 26 8 26H22V40Z"
                fill="#131212"
            />
        </svg>
    )
);

期望:

生成的 react code

export default IconWrapper(
    'add-base-outline',
    true,
    (props: ISvgIconProps) => (
        <svg
            width={props.size}
            height={props.size}
            viewBox="0 0 48 48"
            fill="none"
        >
            <path
                fillRule="evenodd"
                clipRule="evenodd"
                d="M22 40C22 40.5523 22.4477 41 23 41H25C25.5523 41 26 40.5523 26 40V26H40C40.5523 26 41 25.5523 41 25V23C41 22.4477 40.5523 22 40 22H26V8C26 7.44772 25.5523 7 25 7H23C22.4477 7 22 7.44772 22 8V22H8C7.44772 22 7 22.4477 7 23V25C7 25.5523 7.44772 26 8 26H22V40Z"
                fill={props.colors[0]}
            />
        </svg>
    )
);

⚠️注:
项目大部分图标只需要配置 size & color 就满足;
设计师无需学习绘制规范,figma\sketch 直接导出svg即可;

@yijinc
Copy link
Author

yijinc commented May 7, 2022

自己搞了个简单粗暴版本 https://github.com/yijinc/icon-garden

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant