ant-design给我们提供的图标不够怎么办呢?答案是我们可以自定义图标。

自定义图标也挺简单的,现在图标推荐用svg格式,那么我们就需要制作svg图片。

下面让我们看看如果制作svg图片吧。

1.百度搜索svg在线编辑器

2.打开https://c.runoob.com/more/svgeditor/

3.在右侧调整好canvas宽高,使之和图片宽高相同

4.点击文件->导入图片

5.点击视图->源代码,就可以看到生成的源代码了

6.去掉无用代码,光留下svg和image标签即可

7.自定义svg组件

import { Icon } from 'antd';

const HeartSvg = () => (
<svg width="1em" height="1em" fill="currentColor" viewBox="0 0 1024 1024">
<path d="M923 283.6c-13.4-31.1-32.6-58.9-56.9-82.8-24.3-23.8-52.5-42.4-84-55.5-32.5-13.5-66.9-20.3-102.4-20.3-49.3 0-97.4 13.5-139.2 39-10 6.1-19.5 12.8-28.5 20.1-9-7.3-18.5-14-28.5-20.1-41.8-25.5-89.9-39-139.2-39-35.5 0-69.9 6.8-102.4 20.3-31.4 13-59.7 31.7-84 55.5-24.4 23.9-43.5 51.7-56.9 82.8-13.9 32.3-21 66.6-21 101.9 0 33.3 6.8 68 20.3 103.3 11.3 29.5 27.5 60.1 48.2 91 32.8 48.9 77.9 99.9 133.9 151.6 92.8 85.7 184.7 144.9 188.6 147.3l23.7 15.2c10.5 6.7 24 6.7 34.5 0l23.7-15.2c3.9-2.5 95.7-61.6 188.6-147.3 56-51.7 101.1-102.7 133.9-151.6 20.7-30.9 37-61.5 48.2-91 13.5-35.3 20.3-70 20.3-103.3 0.1-35.3-7-69.6-20.9-101.9z" />
</svg>
);

自定义图标组件

const HeartIcon = props => (
<Icon component={HeartSvg} {...props} />
);

调用

ReactDOM.render(
<div className="custom-icons-list">
<HeartIcon style={{ color: 'hotpink' }} />
</div>,
mountNode
);

完整示例

import { Icon } from 'antd';

const HeartSvg = () => (
<svg width="1em" height="1em" fill="currentColor" viewBox="0 0 1024 1024">
<path d="M923 283.6c-13.4-31.1-32.6-58.9-56.9-82.8-24.3-23.8-52.5-42.4-84-55.5-32.5-13.5-66.9-20.3-102.4-20.3-49.3 0-97.4 13.5-139.2 39-10 6.1-19.5 12.8-28.5 20.1-9-7.3-18.5-14-28.5-20.1-41.8-25.5-89.9-39-139.2-39-35.5 0-69.9 6.8-102.4 20.3-31.4 13-59.7 31.7-84 55.5-24.4 23.9-43.5 51.7-56.9 82.8-13.9 32.3-21 66.6-21 101.9 0 33.3 6.8 68 20.3 103.3 11.3 29.5 27.5 60.1 48.2 91 32.8 48.9 77.9 99.9 133.9 151.6 92.8 85.7 184.7 144.9 188.6 147.3l23.7 15.2c10.5 6.7 24 6.7 34.5 0l23.7-15.2c3.9-2.5 95.7-61.6 188.6-147.3 56-51.7 101.1-102.7 133.9-151.6 20.7-30.9 37-61.5 48.2-91 13.5-35.3 20.3-70 20.3-103.3 0.1-35.3-7-69.6-20.9-101.9z" />
</svg>
); const PandaSvg = () => (
<svg viewBox="0 0 1024 1024" width="1em" height="1em" fill="currentColor">
<path d="M99.096 315.634s-82.58-64.032-82.58-132.13c0-66.064 33.032-165.162 148.646-148.646 83.37 11.91 99.096 165.162 99.096 165.162l-165.162 115.614zM924.906 315.634s82.58-64.032 82.58-132.13c0-66.064-33.032-165.162-148.646-148.646-83.37 11.91-99.096 165.162-99.096 165.162l165.162 115.614z" fill="#6B676E" p-id="1143" />
<path d="M1024 561.548c0 264.526-229.23 429.42-512.002 429.42S0 826.076 0 561.548 283.96 66.064 512.002 66.064 1024 297.022 1024 561.548z" fill="#FFEBD2" p-id="1144" />
<path d="M330.324 842.126c0 82.096 81.34 148.646 181.678 148.646s181.678-66.55 181.678-148.646H330.324z" fill="#E9D7C3" p-id="1145" />
<path d="M644.13 611.098C594.582 528.516 561.55 512 512.002 512c-49.548 0-82.58 16.516-132.13 99.096-42.488 70.814-78.73 211.264-49.548 247.742 66.064 82.58 165.162 33.032 181.678 33.032 16.516 0 115.614 49.548 181.678-33.032 29.18-36.476-7.064-176.93-49.55-247.74z" fill="#FFFFFF" p-id="1146" />
<path d="M611.098 495.484c0-45.608 36.974-82.58 82.58-82.58 49.548 0 198.194 99.098 198.194 165.162s-79.934 144.904-148.646 99.096c-49.548-33.032-132.128-148.646-132.128-181.678zM412.904 495.484c0-45.608-36.974-82.58-82.58-82.58-49.548 0-198.194 99.098-198.194 165.162s79.934 144.904 148.646 99.096c49.548-33.032 132.128-148.646 132.128-181.678z" fill="#6B676E" p-id="1147" />
<path d="M512.002 726.622c-30.06 0-115.614 5.668-115.614 33.032 0 49.638 105.484 85.24 115.614 82.58 10.128 2.66 115.614-32.944 115.614-82.58-0.002-27.366-85.556-33.032-115.614-33.032z" fill="#464655" p-id="1148" />
<path d="M330.324 495.484m-33.032 0a33.032 33.032 0 1 0 66.064 0 33.032 33.032 0 1 0-66.064 0Z" fill="#464655" p-id="1149" />
<path d="M693.678 495.484m-33.032 0a33.032 33.032 0 1 0 66.064 0 33.032 33.032 0 1 0-66.064 0Z" fill="#464655" p-id="1150" />
</svg>
); const HeartIcon = props => (
<Icon component={HeartSvg} {...props} />
); const PandaIcon = props => (
<Icon component={PandaSvg} {...props} />
); ReactDOM.render(
<div className="custom-icons-list">
<HeartIcon style={{ color: 'hotpink' }} />
<PandaIcon style={{ fontSize: '32px' }} />
</div>,
mountNode
);

注意,添加image,xlink:href需要改为xlinkHref,例如

<svg width="14" height="14">
<image xlinkHref="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167+3t+9f7vOec5/zOec8PgBESJpHmomoAOVKFPDrYH49PSMTJvYACFUjgBCAQ5svCZwXFAADwA3l4fnSwP/wBr28AAgBw1S4kEsfh/4O6UCZXACCRAOAiEucLAZBSAMguVMgUAMgYALBTs2QKAJQAAGx5fEIi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AHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAJ8SURBVHjaNJJPSFRRFMa/c+99d94oooIDvsE2IjELqZ3gyoJqEfR3VRhIBNai3EStRKVw0yIoV0a0MIkWUbZICBeBC8lmBlHURbPUHBoU48047/neu/e0cObAgW/z8fE73yFmBgBsb2/D9/0Ox3EmANwF0IGTqQGYJ6KpIAj+9vb2wvM8UNO4tbV13ff9L1prENEKM68AsAAGAJxjZgRBMJLL5eYymQzI933UarWrOzs7X6WUv4joJhH9sdYCAJgZQoguZv4QBMHFnp6ekc7OzjkqFovpMAzrWuu8lHKAmdFcANBaI45jtLe3wxjz/eDg4JJSqos2NjZeB0HwSErZSkT1BheklGBmuK6LMAxPE1FZa12t1WospfxIq6urrLX+qZQaTJIEzIwGJ4wxsNY+SZLkBYD7Sqk31tola+0FyufzLKWcJKJnxhhIKaG1BjMjiqLJKIqmhBCL/f39w3t7e/8qlcqY1voVFQoFZuZxpdS0tfapEOK31nohiqKZOI4fMvM713XveZ6H3d1dGGNGiWiWCoUCW2uXlVJDANaZ+QwR/TDGnJdSvmTmx83rGmOglFpg5mu0trY2G8fxaDqdVkIIE4bhijFmUCk1IaV8niQJrLVQSkEIgePjYzbGfKNisdgWRZGfTqeXhRBDcRyDmc8S0boQAnEcw3EctLW1IQzDz9Vq9Ybrulna39+H7/t3yuXy+1QqtQjgChHZZo/WWjiO08rMb4+Ojm5ls9mx7u7uGWJmHB4eYnNzc7ilpWW+wbNERMsNPQjgMhGhXq8/yOVys5lM5uRXK5UKSqUSUqnUKSHENIDbzKwAoJH+CcB4vV4v9fX1wfM8/B8A1T9dWIAXascAAAAASUVORK5CYII=" id="svg_1" height="14" width="14" y="0" x="0"/>
</svg>

react ant-design自定义图标的更多相关文章

  1. React+Ant Design设置左侧菜单导航路由的显示与隐藏(与权限无关)

    最近在学习react时,用到了很流行的UI框架Ant Design,也了解了一下Ant Design Pro,发现它们都有导航组件,Ant Design框架的导航菜单在这里,Ant Design Pr ...

  2. React + Ant Design网页,配置

    第一个React + Ant Design网页(一.配置+编写主页) 引用博主的另外一篇VUE2.0+ElementUI教程, 请移步:  https://blog.csdn.net/u0129070 ...

  3. 实现Ant Design 自定义表单组件

    Ant Design 组件提供了Input,InputNumber,Radio,Select,uplod等表单组件,但实际开发中这是不能满足需求,同时我们希望可以继续使用Form提供的验证和提示等方法 ...

  4. (二)React Ant Design Pro + .Net5 WebApi:前端环境搭建

    首先,你需要先装一个Nodejs,这是基础哦.如果没有这方面知识的小伙伴可以在园子里搜索cnpm yarn等关键字,内容繁多,此不赘述,参考链接 一. 简介 1. Ant Design Pro v5 ...

  5. 【React自制全家桶】一、Webstrom+React+Ant Design+echarts搭建react项目

    前言 一.React是Facebook推出的一个前端框架,之前被用于著名的社交媒体Instagram中,后来由于取得了不错的反响,于是Facebook决定将其开源.出身名门的React也不负众望,成功 ...

  6. React / Ant Design Pro 实现Canvas画布实时自适应

    如何实现canvas根据父容器进行自适应? Ant Design的组件都提供了强大的自适应能力,为了对齐父组件,镶嵌在Ant Design组件里的canvas也需要能根据父级容器进行自适应的能力,页面 ...

  7. ant design 自定义表单验证大全

     需求是 账号名可以是手机号也可以是邮箱 要做手机号和邮箱的验证,官网的那个验证规则不匹配  怎么自定义验证规则?  一:组件部分 <Form horizontal> <Row gu ...

  8. react+ant design Breadcrumb面包屑组件

    import React from 'react'; import { Link }from 'react-router-dom'; import { Breadcrumb } from 'antd' ...

  9. (一)React Ant Design Pro + .Net5 WebApi:先搞定服务器,顺手装个Nginx

    腾讯云搞定服务器,具体过程就不赘述了,文档都有,咨询客服或者自行百度,体验一下过程. 一. 服务器 1. 云服务器 cvm 1核2G centos8.0 2. 域名注册 www.homejok.com ...

  10. (十一)React Ant Design Pro + .Net5 WebApi:后端环境搭建-IdentityServer4(三)持久化

    一.前言 IdentityServer配合EFCore持久化,框架已经为我们准备了两个上下文: ConfigurationDbContext:配置数据(资源.客户端.身份等) PersistedGra ...

随机推荐

  1. php入门到精通(复习笔记)

    第一章:php语言基础 1,标记风格: ①<?php echo “hello”;?> ②<script language="php">echo " ...

  2. HTML专题

    1. 在<form><form/>标签里面的<button>标签要设置type="button",否则可能会在点击按钮时自动提交这个表单 2. ...

  3. Jerry的Fiori原创文章合集

    我曾经于2014年10月到2016年5月工作于SAP CRM Fiori应用的开发团队, 我所在的团队负责下列这8个Fiori应用的维护和持续开发: My Opportunities My Tasks ...

  4. 搭建packagist私服和composer

    1.下载源码 https://github.com/composer/packagist 2.修改配置文件 cp app/config/parameters.yml.dist  app/config/ ...

  5. vue错误提示 Cannot read property 'beforeRouteEnter' of undefined,刷新后跳到首页

    vue错误提示 Cannot read property 'beforeRouteEnter' of undefined,刷新后跳到首页 因为vue-router版本太高了,我vue用的是2.3.4, ...

  6. Arcgis Javascript中geometryEngine报错’hq‘of undefined的解决方法

    这个问题困扰了我一个星期,原因是使用geomagicbuffer时候,有的线可正常使用,有的就直接报错,一直没有解决,后来发现是api自己的bug导致的 干脆直接读代码,在geometryEngine ...

  7. Error: Error SSL Required Code: 403

    Error: Error SSL Required Code: 403 Error Message If the 'services' Web directory for ArcGIS is set ...

  8. 编程思想的理解(POP,OOP,SOA,AOP) x

    http://blog.chinaunix.net/uid-29417436-id-4060980.html 1)POP--面向过程编程(Process-oriented programming ): ...

  9. HDU 6070 线段树

    题意:求AC率,x/y 的最小值,x是区间数字的种类数,y是区间的长度. 分析: 二分答案比率.ans, 动态插入结点,一些区间的size会发生变化,是那些前面暂时没有新的结点的区间 size + 1 ...

  10. 使用ParseExact方法将字符串转换为日期格式

    实现效果: 知识运用: DateTime结构的ParseExact方法 public static DateTime ParseExact(string s,string format,IFormat ...