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 CHANGED
@@ -1,59 +1,115 @@
1
1
  # mv-iconfront
2
2
 
3
- A general purpose Vue 3 icon component encapsulating your custom Iconfont icons.
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
- Register it globally in your main file:
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' // Import styles if needed, though they are usually bundled
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
- Or import locally:
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
- The component accepts a `name` prop for the icon class (e.g., `icon-home`) and a `color` prop.
47
+ ### 基础示例
35
48
 
36
49
  ```html
37
- <!-- Default color (White) -->
50
+ <!-- 使用全局默认颜色 (如果未配置则默认为白色) -->
38
51
  <mv-iconfront name="icon-home" />
39
52
 
40
- <!-- Custom color -->
53
+ <!-- 自定义颜色 (覆盖全局默认值) -->
41
54
  <mv-iconfront name="icon-user" color="#FF0000" />
42
55
 
43
- <!-- With Size -->
44
- <mv-iconfront name="icon-settings" color="#000" size="24" />
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
- Note: The `name` prop must match the class names in your iconfont assets (e.g., `icon-a-qianse_tubiao_yichangbaocuo1`).
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
- ## Build and Publish
105
+ ## 构建与发布
50
106
 
51
- 1. Build the library:
107
+ 1. 构建库 (生成 JS 和 类型定义文件):
52
108
  ```bash
53
109
  npm run build
54
110
  ```
55
111
 
56
- 2. Publish to npm:
112
+ 2. 发布到 npm:
57
113
  ```bash
58
114
  npm publish
59
115
  ```
@@ -1,5 +1,5 @@
1
- import { defineComponent as c, computed as l, createElementBlock as r, openBlock as i, mergeProps as a } from "vue";
2
- const d = c({
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: "#FFFFFF"
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: l(() => {
34
+ iconStyle: f(() => {
33
35
  const t = {};
34
- if (e.disabled ? t.color = "#C0C4CC" : e.isRed ? t.color = "#f56c6c" : e.color && (t.color = e.color), e.size) {
35
- const o = e.size.toString();
36
- t.fontSize = o.endsWith("px") || o.endsWith("rem") ? o : `${o}px`;
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
- }), f = (e, n) => {
43
- const t = e.__vccOpts || e;
44
- for (const [o, s] of n)
45
- t[o] = s;
46
- return t;
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 u(e, n, t, o, s, y) {
49
- return i(), r("i", a({
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 p = /* @__PURE__ */ f(d, [["render", u], ["__scopeId", "data-v-a841787a"]]), m = (e) => {
55
- e.component("MvIconfront", p);
56
- }, _ = {
57
- install: m
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
- p as MvIconfront,
61
- _ as default
62
+ C as MvIconfront,
63
+ S as default
62
64
  };
@@ -1 +1 @@
1
- (function(o,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.MvIconfront={},o.Vue))})(this,function(o,t){"use strict";const r=t.defineComponent({name:"MvIconfront",props:{name:{type:String,default:""},color:{type:String,default:"#FFFFFF"},size:{type:[String,Number],default:""},isRed:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1}},setup(e){return{iconStyle:t.computed(()=>{const n={};if(e.disabled?n.color="#C0C4CC":e.isRed?n.color="#f56c6c":e.color&&(n.color=e.color),e.size){const i=e.size.toString();n.fontSize=i.endsWith("px")||i.endsWith("rem")?i:`${i}px`}return n})}}}),d=(e,s)=>{const n=e.__vccOpts||e;for(const[i,c]of s)n[i]=c;return n};function f(e,s,n,i,c,p){return t.openBlock(),t.createElementBlock("i",t.mergeProps({class:["icon2",e.name,{"is-disabled":e.disabled}],style:e.iconStyle},e.$attrs),null,16)}const l=d(r,[["render",f],["__scopeId","data-v-a841787a"]]),a={install:e=>{e.component("MvIconfront",l)}};o.MvIconfront=l,o.default=a,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
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"}})});