react ant-design自定义图标
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/4O6UCZXACCRAOAiEucLAZBSAMguVMgUAMgYALBTs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p8zAAAAIGNIUk0AAHolAACAgwAA+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自定义图标的更多相关文章
- React+Ant Design设置左侧菜单导航路由的显示与隐藏(与权限无关)
最近在学习react时,用到了很流行的UI框架Ant Design,也了解了一下Ant Design Pro,发现它们都有导航组件,Ant Design框架的导航菜单在这里,Ant Design Pr ...
- React + Ant Design网页,配置
第一个React + Ant Design网页(一.配置+编写主页) 引用博主的另外一篇VUE2.0+ElementUI教程, 请移步: https://blog.csdn.net/u0129070 ...
- 实现Ant Design 自定义表单组件
Ant Design 组件提供了Input,InputNumber,Radio,Select,uplod等表单组件,但实际开发中这是不能满足需求,同时我们希望可以继续使用Form提供的验证和提示等方法 ...
- (二)React Ant Design Pro + .Net5 WebApi:前端环境搭建
首先,你需要先装一个Nodejs,这是基础哦.如果没有这方面知识的小伙伴可以在园子里搜索cnpm yarn等关键字,内容繁多,此不赘述,参考链接 一. 简介 1. Ant Design Pro v5 ...
- 【React自制全家桶】一、Webstrom+React+Ant Design+echarts搭建react项目
前言 一.React是Facebook推出的一个前端框架,之前被用于著名的社交媒体Instagram中,后来由于取得了不错的反响,于是Facebook决定将其开源.出身名门的React也不负众望,成功 ...
- React / Ant Design Pro 实现Canvas画布实时自适应
如何实现canvas根据父容器进行自适应? Ant Design的组件都提供了强大的自适应能力,为了对齐父组件,镶嵌在Ant Design组件里的canvas也需要能根据父级容器进行自适应的能力,页面 ...
- ant design 自定义表单验证大全
需求是 账号名可以是手机号也可以是邮箱 要做手机号和邮箱的验证,官网的那个验证规则不匹配 怎么自定义验证规则? 一:组件部分 <Form horizontal> <Row gu ...
- react+ant design Breadcrumb面包屑组件
import React from 'react'; import { Link }from 'react-router-dom'; import { Breadcrumb } from 'antd' ...
- (一)React Ant Design Pro + .Net5 WebApi:先搞定服务器,顺手装个Nginx
腾讯云搞定服务器,具体过程就不赘述了,文档都有,咨询客服或者自行百度,体验一下过程. 一. 服务器 1. 云服务器 cvm 1核2G centos8.0 2. 域名注册 www.homejok.com ...
- (十一)React Ant Design Pro + .Net5 WebApi:后端环境搭建-IdentityServer4(三)持久化
一.前言 IdentityServer配合EFCore持久化,框架已经为我们准备了两个上下文: ConfigurationDbContext:配置数据(资源.客户端.身份等) PersistedGra ...
随机推荐
- Oracle SYS用户无法设置session级别的read only
官方文档参考:SYSDBA is used internally in the Oracle database and has specialized functions. Its behavior ...
- May 24th 2017 Week 21th Wednesday
Always remember that you are absolutely unique. 永远记住,你是独一无二的. I am unique, in the way that all I do ...
- March 25 2017 Week 12 Saturday
Better master one than engage with ten. 会十事不如精一事. My colleagues think I have known a lot of things, ...
- ZT在谷歌上班感受如何?
在谷歌上班感受如何? 2013-11-05 作者:腾讯科技 出处: 互联网 责编:zlu 在谷歌这家全球最大最有抱负的技术公司工作将是怎样的情景呢?是天堂般的享受,还是地狱般的折磨呢?下面看一 ...
- 关于自学C语言这件事
说在前面 为什么会写下这篇文章?本人也并不是什么大神,但是也自学了很久,从一个小白开始自学,期间走过很多弯路,掉过许多坑.一路跌跌撞撞下来,算是有了点收获,有了点感想,将它们记录下来,希望能帮助新入坑 ...
- Java Android 32位16位 MD5加密
// md5加密 32位小写 private String Md5(String sourceStr) { String result = ""; try { MessageDig ...
- UVa 1606 - Amphiphilic Carbon Molecules
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- ASP.NET MVC有用工具
Route Debugger https://www.nuget.org/packages/routedebugger 在Asp.Net MVC程序中,路由(Route)是一个非常核心的概念,可以说是 ...
- 了解Mysql与MariaDb的关系
MariaDB是MySQL源代码的一个分支,随着Oracle买下Sun,MySQL也落入了关系型数据库王者之手.在意识到Oracle会对MySQL许可做什么后便分离了出来(MySQL先后被Sun.Or ...
- servlet三种方式实现servlet接口
简单介绍 Servlet接口实现类 1.Servlet接口SUN公司定义了两个默认实现类,分别为:GenericServlet.HttpServlet. 2.HttpServlet指能够处理HTTP请 ...