mv-iconfront 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -16
- package/dist/mv-iconfront.es.js +23 -21
- package/dist/mv-iconfront.umd.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,59 +1,115 @@
|
|
|
1
1
|
# mv-iconfront
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个通用的 Vue 3 Iconfont 图标组件封装库。
|
|
4
4
|
|
|
5
|
-
## Installation
|
|
5
|
+
## 安装 (Installation)
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install mv-iconfront
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Usage
|
|
11
|
+
## 使用方法 (Usage)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### 全局注册
|
|
14
|
+
|
|
15
|
+
在项目的入口文件中全局注册组件。您还可以在此配置全局默认的主题色。
|
|
14
16
|
|
|
15
17
|
```js
|
|
16
18
|
import { createApp } from 'vue'
|
|
17
19
|
import App from './App.vue'
|
|
18
20
|
import MvIconfront from 'mv-iconfront'
|
|
19
|
-
import 'mv-iconfront/dist/style.css' //
|
|
21
|
+
import 'mv-iconfront/dist/style.css' // 必须引入 CSS 文件以保证样式正常
|
|
20
22
|
|
|
21
23
|
const app = createApp(App)
|
|
24
|
+
|
|
25
|
+
// 基础注册 (默认颜色为白色 #FFFFFF)
|
|
22
26
|
app.use(MvIconfront)
|
|
27
|
+
|
|
28
|
+
// 或者:配置全局默认主题色
|
|
29
|
+
app.use(MvIconfront, {
|
|
30
|
+
defaultColor: '#409EFF' // 自定义全局默认颜色
|
|
31
|
+
})
|
|
32
|
+
|
|
23
33
|
app.mount('#app')
|
|
24
34
|
```
|
|
25
35
|
|
|
26
|
-
|
|
36
|
+
### 局部引入
|
|
27
37
|
|
|
28
38
|
```js
|
|
29
39
|
import { MvIconfront } from 'mv-iconfront'
|
|
40
|
+
import 'mv-iconfront/dist/style.css'
|
|
30
41
|
```
|
|
31
42
|
|
|
32
|
-
## Component Usage
|
|
43
|
+
## 组件使用 (Component Usage)
|
|
44
|
+
|
|
45
|
+
该组件接收 `name` 属性来指定图标类名(例如 `icon-home`),并支持多种自定义属性。
|
|
33
46
|
|
|
34
|
-
|
|
47
|
+
### 基础示例
|
|
35
48
|
|
|
36
49
|
```html
|
|
37
|
-
<!--
|
|
50
|
+
<!-- 使用全局默认颜色 (如果未配置则默认为白色) -->
|
|
38
51
|
<mv-iconfront name="icon-home" />
|
|
39
52
|
|
|
40
|
-
<!--
|
|
53
|
+
<!-- 自定义颜色 (覆盖全局默认值) -->
|
|
41
54
|
<mv-iconfront name="icon-user" color="#FF0000" />
|
|
42
55
|
|
|
43
|
-
<!--
|
|
44
|
-
<mv-iconfront name="icon-settings"
|
|
56
|
+
<!-- 自定义大小 (支持数字或带单位的字符串) -->
|
|
57
|
+
<mv-iconfront name="icon-settings" size="24" />
|
|
58
|
+
<mv-iconfront name="icon-settings" size="2rem" />
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 状态与变体
|
|
62
|
+
|
|
63
|
+
**1. 禁用状态 (Disabled State)**
|
|
64
|
+
图标显示为**灰色** (`#C0C4CC`),并且鼠标悬停时显示为禁止手势 (`not-allowed`)。
|
|
65
|
+
优先级:**最高** (会覆盖所有其他颜色设置)。
|
|
66
|
+
|
|
67
|
+
```html
|
|
68
|
+
<mv-iconfront name="icon-edit" disabled />
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**2. 红色变体 (Red Variant)**
|
|
72
|
+
快速将图标设置为标准的错误/危险红色 (`#f56c6c`)。
|
|
73
|
+
优先级:**中等** (会覆盖 `color` 和全局默认值,但在 `disabled` 状态下无效)。
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<mv-iconfront name="icon-delete" isRed />
|
|
45
77
|
```
|
|
46
78
|
|
|
47
|
-
|
|
79
|
+
### 颜色优先级逻辑 (Color Priority)
|
|
80
|
+
|
|
81
|
+
组件确定图标颜色的顺序如下(优先级从高到低):
|
|
82
|
+
|
|
83
|
+
1. **`disabled`**: 如果为 `true`,强制显示 **灰色** (`#C0C4CC`)。
|
|
84
|
+
2. **`isRed`**: 如果为 `true`,强制显示 **红色** (`#f56c6c`)。
|
|
85
|
+
3. **`color`**: 如果提供了该属性,使用 **自定义颜色**。
|
|
86
|
+
4. **`defaultColor`**: 使用 `app.use()` 中配置的全局颜色 (未配置则默认为 `#FFFFFF`)。
|
|
87
|
+
|
|
88
|
+
```html
|
|
89
|
+
<!-- 示例:禁用状态优先级高于红色变体 -->
|
|
90
|
+
<mv-iconfront name="icon-trash" isRed disabled />
|
|
91
|
+
<!-- 结果:显示为灰色图标 -->
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 属性 API (Props API)
|
|
95
|
+
|
|
96
|
+
| 属性名 (Prop) | 类型 (Type) | 默认值 (Default) | 说明 (Description) |
|
|
97
|
+
|---|---|---|---|
|
|
98
|
+
| `name` | String | `''` | 具体的图标类名 (例如 `icon-a-qianse_tubiao_yichangbaocuo1`) |
|
|
99
|
+
| `color` | String | `''` | 自定义颜色覆盖 (hex, rgb 等) |
|
|
100
|
+
| `size` | String/Number | `''` | 字体大小。纯数字会被视为 `px` 单位。 |
|
|
101
|
+
| `isRed` | Boolean | `false` | 设置图标为红色 (`#f56c6c`)。 |
|
|
102
|
+
| `disabled` | Boolean | `false` | 设置图标为灰色 (`#C0C4CC`) 并将鼠标样式设为禁止。 |
|
|
103
|
+
|
|
48
104
|
|
|
49
|
-
##
|
|
105
|
+
## 构建与发布
|
|
50
106
|
|
|
51
|
-
1.
|
|
107
|
+
1. 构建库 (生成 JS 和 类型定义文件):
|
|
52
108
|
```bash
|
|
53
109
|
npm run build
|
|
54
110
|
```
|
|
55
111
|
|
|
56
|
-
2.
|
|
112
|
+
2. 发布到 npm:
|
|
57
113
|
```bash
|
|
58
114
|
npm publish
|
|
59
115
|
```
|
package/dist/mv-iconfront.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineComponent as c, computed as
|
|
2
|
-
const d =
|
|
1
|
+
import { defineComponent as r, inject as c, computed as f, createElementBlock as s, openBlock as a, mergeProps as i } from "vue";
|
|
2
|
+
const d = r({
|
|
3
3
|
name: "MvIconfront",
|
|
4
4
|
props: {
|
|
5
5
|
// The specific icon class, e.g. "icon-home"
|
|
@@ -7,10 +7,11 @@ const d = c({
|
|
|
7
7
|
type: String,
|
|
8
8
|
default: ""
|
|
9
9
|
},
|
|
10
|
-
// Icon color, defaults to white
|
|
10
|
+
// Icon color, defaults to white if not provided
|
|
11
11
|
color: {
|
|
12
12
|
type: String,
|
|
13
|
-
default: "
|
|
13
|
+
default: ""
|
|
14
|
+
// CHANGED: Empty default so we can detect difference between prop passed vs global default
|
|
14
15
|
},
|
|
15
16
|
// Optional size prop
|
|
16
17
|
size: {
|
|
@@ -28,35 +29,36 @@ const d = c({
|
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
setup(e) {
|
|
32
|
+
const o = c("mvIconfrontDefaultColor", "#FFFFFF");
|
|
31
33
|
return {
|
|
32
|
-
iconStyle:
|
|
34
|
+
iconStyle: f(() => {
|
|
33
35
|
const t = {};
|
|
34
|
-
if (e.disabled ? t.color = "#C0C4CC" : e.isRed ? t.color = "#f56c6c" : e.color
|
|
35
|
-
const
|
|
36
|
-
t.fontSize =
|
|
36
|
+
if (e.disabled ? t.color = "#C0C4CC" : e.isRed ? t.color = "#f56c6c" : e.color ? t.color = e.color : t.color = o, e.size) {
|
|
37
|
+
const l = e.size.toString();
|
|
38
|
+
t.fontSize = l.endsWith("px") || l.endsWith("rem") ? l : `${l}px`;
|
|
37
39
|
}
|
|
38
40
|
return t;
|
|
39
41
|
})
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
|
-
}),
|
|
43
|
-
const
|
|
44
|
-
for (const [
|
|
45
|
-
t
|
|
46
|
-
return
|
|
44
|
+
}), u = (e, o) => {
|
|
45
|
+
const n = e.__vccOpts || e;
|
|
46
|
+
for (const [t, l] of o)
|
|
47
|
+
n[t] = l;
|
|
48
|
+
return n;
|
|
47
49
|
};
|
|
48
|
-
function
|
|
49
|
-
return
|
|
50
|
+
function m(e, o, n, t, l, g) {
|
|
51
|
+
return a(), s("i", i({
|
|
50
52
|
class: ["icon2", e.name, { "is-disabled": e.disabled }],
|
|
51
53
|
style: e.iconStyle
|
|
52
54
|
}, e.$attrs), null, 16);
|
|
53
55
|
}
|
|
54
|
-
const
|
|
55
|
-
e.component("MvIconfront",
|
|
56
|
-
},
|
|
57
|
-
install:
|
|
56
|
+
const C = /* @__PURE__ */ u(d, [["render", m]]), y = (e, o) => {
|
|
57
|
+
o != null && o.defaultColor && (e.config.globalProperties.$mvIconfrontDefaultColor = o.defaultColor, e.provide("mvIconfrontDefaultColor", o.defaultColor)), e.component("MvIconfront", C);
|
|
58
|
+
}, S = {
|
|
59
|
+
install: y
|
|
58
60
|
};
|
|
59
61
|
export {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
C as MvIconfront,
|
|
63
|
+
S as default
|
|
62
64
|
};
|
package/dist/mv-iconfront.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o
|
|
1
|
+
(function(l,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.MvIconfront={},l.Vue))})(this,function(l,o){"use strict";const i=o.defineComponent({name:"MvIconfront",props:{name:{type:String,default:""},color:{type:String,default:""},size:{type:[String,Number],default:""},isRed:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1}},setup(e){const t=o.inject("mvIconfrontDefaultColor","#FFFFFF");return{iconStyle:o.computed(()=>{const n={};if(e.disabled?n.color="#C0C4CC":e.isRed?n.color="#f56c6c":e.color?n.color=e.color:n.color=t,e.size){const r=e.size.toString();n.fontSize=r.endsWith("px")||r.endsWith("rem")?r:`${r}px`}return n})}}}),s=(e,t)=>{const f=e.__vccOpts||e;for(const[n,r]of t)f[n]=r;return f};function d(e,t,f,n,r,m){return o.openBlock(),o.createElementBlock("i",o.mergeProps({class:["icon2",e.name,{"is-disabled":e.disabled}],style:e.iconStyle},e.$attrs),null,16)}const c=s(i,[["render",d]]),a={install:(e,t)=>{t!=null&&t.defaultColor&&(e.config.globalProperties.$mvIconfrontDefaultColor=t.defaultColor,e.provide("mvIconfrontDefaultColor",t.defaultColor)),e.component("MvIconfront",c)}};l.MvIconfront=c,l.default=a,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|