feat: 优化iconfont组件库用户体验

This commit is contained in:
lifan 2024-03-22 17:19:37 +08:00
parent d36518078d
commit caf7869f15
35 changed files with 207 additions and 57 deletions

View File

@ -1,16 +0,0 @@
import React from 'react';
import { ReactNode } from 'react';
interface IconFontProps {
styles?: React.CSSProperties;
icon: string;
size?: number;
color?: string;
title?: string;
className?: string;
onIconClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
children?: ReactNode;
active?: boolean;
disable?: boolean;
}
declare const IconFont: React.FC<IconFontProps>;
export default IconFont;

View File

@ -7,7 +7,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
import { createFromIconfontCN } from '@ant-design/icons';
import React from 'react';
var Icon = createFromIconfontCN({
scriptUrl: require("./font_1739270_pqkfa2ldec/iconfont.js")
scriptUrl: require("./font/iconfont.js")
});
var IconFont = function IconFont(props) {
var _ref = props || {},

View File

@ -0,0 +1,33 @@
import React from 'react';
var iconJson = require("../font/iconfont.json");
import { IconFont } from '@zhst/icon';
import "./index.less";
import { message } from '@zhst/meta';
var demo = function demo() {
var iconArr = iconJson['glyphs'];
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("ul", {
className: 'demo-ul'
}, iconArr.map(function (item) {
var font_class = item.font_class,
name = item.name;
var fontName = "icon-".concat(font_class);
return /*#__PURE__*/React.createElement("li", {
className: 'demo-li'
}, /*#__PURE__*/React.createElement(IconFont, {
styles: {
marginBottom: 20
},
icon: fontName,
size: 32,
onIconClick: function onIconClick() {
navigator.clipboard.writeText(fontName);
message.success("\u590D\u5236".concat(fontName, "\u6210\u529F"));
}
}), /*#__PURE__*/React.createElement("div", {
className: "demo-li-name"
}, name), /*#__PURE__*/React.createElement("div", {
className: "demo-li-name"
}, fontName));
})));
};
export default demo;

View File

@ -0,0 +1,20 @@
.demo {
&-ul {
list-style-type: none;
display: flex;
flex-wrap: wrap;
}
&-li {
display: flex;
flex-direction: column;
align-items: center;
height: 150px;
width: 150px;
&-name {
color: #666;
font-size: 12px;
}
}
}

View File

@ -1,8 +1,8 @@
@font-face {
font-family: iconfont; /* Project id 1739270 */
src: url('iconfont.woff2?t=1711007646448') format('woff2'),
url('iconfont.woff?t=1711007646448') format('woff'),
url('iconfont.ttf?t=1711007646448') format('truetype');
src: url('iconfont.woff2?t=1711094074098') format('woff2'),
url('iconfont.woff?t=1711094074098') format('woff'),
url('iconfont.ttf?t=1711094074098') format('truetype');
}
.iconfont {

Binary file not shown.

View File

@ -1,16 +0,0 @@
import React from 'react';
import { ReactNode } from 'react';
interface IconFontProps {
styles?: React.CSSProperties;
icon: string;
size?: number;
color?: string;
title?: string;
className?: string;
onIconClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
children?: ReactNode;
active?: boolean;
disable?: boolean;
}
declare const IconFont: React.FC<IconFontProps>;
export default IconFont;

View File

@ -35,7 +35,7 @@ module.exports = __toCommonJS(Iconfont_exports);
var import_icons = require("@ant-design/icons");
var import_react = __toESM(require("react"));
var Icon = (0, import_icons.createFromIconfontCN)({
scriptUrl: require("./font_1739270_pqkfa2ldec/iconfont.js")
scriptUrl: require("./font/iconfont.js")
});
var IconFont = (props) => {
const {

View File

@ -0,0 +1,59 @@
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/demo/demo.tsx
var demo_exports = {};
__export(demo_exports, {
default: () => demo_default
});
module.exports = __toCommonJS(demo_exports);
var import_react = __toESM(require("react"));
var import_icon = require("@zhst/icon");
var import_index = require("./index.less");
var import_meta = require("@zhst/meta");
var iconJson = require("../font/iconfont.json");
var demo = () => {
const iconArr = iconJson["glyphs"];
return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("ul", { className: "demo-ul" }, iconArr.map((item) => {
const { font_class, name } = item;
const fontName = `icon-${font_class}`;
return /* @__PURE__ */ import_react.default.createElement("li", { className: "demo-li" }, /* @__PURE__ */ import_react.default.createElement(
import_icon.IconFont,
{
styles: { marginBottom: 20 },
icon: fontName,
size: 32,
onIconClick: () => {
navigator.clipboard.writeText(fontName);
import_meta.message.success(`复制${fontName}成功`);
}
}
), /* @__PURE__ */ import_react.default.createElement("div", { className: "demo-li-name" }, name), /* @__PURE__ */ import_react.default.createElement("div", { className: "demo-li-name" }, fontName));
})));
};
var demo_default = demo;

View File

@ -0,0 +1,20 @@
.demo {
&-ul {
list-style-type: none;
display: flex;
flex-wrap: wrap;
}
&-li {
display: flex;
flex-direction: column;
align-items: center;
height: 150px;
width: 150px;
&-name {
color: #666;
font-size: 12px;
}
}
}

View File

@ -1,8 +1,8 @@
@font-face {
font-family: iconfont; /* Project id 1739270 */
src: url('iconfont.woff2?t=1711007646448') format('woff2'),
url('iconfont.woff?t=1711007646448') format('woff'),
url('iconfont.ttf?t=1711007646448') format('truetype');
src: url('iconfont.woff2?t=1711094074098') format('woff2'),
url('iconfont.woff?t=1711094074098') format('woff'),
url('iconfont.ttf?t=1711094074098') format('truetype');
}
.iconfont {

Binary file not shown.

View File

@ -15,7 +15,7 @@ interface IconFontProps {
disable?: boolean;
}
const Icon = createFromIconfontCN({
scriptUrl: require('./font_1739270_pqkfa2ldec/iconfont.js'),
scriptUrl: require('./font/iconfont.js'),
});
const IconFont: React.FC<IconFontProps> = (props) => {
const {

View File

@ -0,0 +1,31 @@
import React from 'react';
const iconJson = require('../font/iconfont.json')
import { IconFont } from '@zhst/icon';
import './index.less';
import { message } from '@zhst/meta';
const demo = ()=>{
const iconArr = iconJson['glyphs']
return (
<div>
<ul className={'demo-ul'}>
{iconArr.map((item: any)=>{
const {font_class,name}= item;
const fontName = `icon-${font_class}`
return <li className={'demo-li'} >
<IconFont
styles={{marginBottom:20}}
icon={fontName} size={32}
onIconClick={()=>{
navigator.clipboard.writeText(fontName)
message.success(`复制${fontName}成功`)
}}>
</IconFont>
<div className="demo-li-name">{name}</div>
<div className="demo-li-name">{fontName}</div>
</li>
})}
</ul>
</div>
);
}
export default demo

View File

@ -0,0 +1,20 @@
.demo {
&-ul {
list-style-type: none;
display: flex;
flex-wrap: wrap;
}
&-li {
display: flex;
flex-direction: column;
align-items: center;
height: 150px;
width: 150px;
&-name {
color: #666;
font-size: 12px;
}
}
}

View File

@ -1,8 +1,8 @@
@font-face {
font-family: iconfont; /* Project id 1739270 */
src: url('iconfont.woff2?t=1711007646448') format('woff2'),
url('iconfont.woff?t=1711007646448') format('woff'),
url('iconfont.ttf?t=1711007646448') format('truetype');
src: url('iconfont.woff2?t=1711094074098') format('woff2'),
url('iconfont.woff?t=1711094074098') format('woff'),
url('iconfont.ttf?t=1711094074098') format('truetype');
}
.iconfont {

Binary file not shown.

View File

@ -9,3 +9,14 @@ title: 快速上手
<embed src="../README.md" ></embed>
<code src="./demo/basic.tsx">基本用法</code>
<code src="./demo/demo.tsx">icon列表</code>
## API
| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| title | 标题 | string | '' | - |
| styles | 样式 | cssProperties | {} | - |
| icon | fontClass名 | string | '' | - |
| size | fontClass名 | integer | 14 | - |
| onIconClick | icon点击事件 | function | ()=>{} | - |
| color | 图标颜色 | string | '' | - |

View File

@ -1,11 +0,0 @@
---
nav:
title: 其它
title: 静态变量库
toc: content
---
<embed src="../../README.md" ></embed>
<embed src="../../CHANGELOG.md" ></embed>

View File

@ -1 +0,0 @@
export default {}