0.0.3 • Published 5 years ago

vi-icon v0.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

vi-icon

组件效果预览

image

使用

npm i vi-icon --save

使用微信开发者工具构建NPM并使用NPM模块

"usingComponents": {
  "ViIcon": "vi-icon",
}

示例

使用内置图标

iconName接收内置的图标名称

icon-style 用于定义图标的样式

<template>
  <ViIcon iconName="email" icon-style="vi-icon-email"></ViIcon>
</template>

如果要定义图标的字体大小,请给类名加上 before伪元素

内置图标的字体大小为14px

.vi-icon-email::before {
  font-size: 30px;
  color: red;
}

扩展图标库

使用图标库扩展功能请先阅读微信小程序的字体API

fontSource 接收图标库的资源文件。文件类型为 .ttf或者 .woff

<template>
  <ViIcon 
    fontSource="url('https://at.alicdn.com/t/font_629189_c2m154yp2ts.ttf')" 
    icon-style="icon-local">
  </ViIcon>
</template>

content 中的内容为字体的 unicode 编码

.icon-local::before {
  content: '\e602';
  font-size: 20px;
}

修改扩展图标的fontFamily

fontFamily 用于修改字体文件的css引用名称

<template>
  <ViIcon 
    fontSource="url('https://at.alicdn.com/t/font_849474_p1bye6fkj5.woff')" 
    icon-style="icon-network-error"
    fontFamily="viAbnormalTips">
  </ViIcon>
</template>
.icon-network-error::before {
  content: '\e602';
  font-size: 66px;
}

全局配置扩展图标的文件资源

如果是使用全局配置,请在app.js的options对象上挂载_$ViIcon配置信息

// app.js
App({
  onLaunch: function () {
  },
  ...serverData,
  globalData: {
    userInfo: null
  },
  _$ViIcon: {
    fontSource: 'url("https://at.alicdn.com/t/font_629189_c2m154yp2ts.ttf")',
    fontFamily: 'man-rong' // 可选项,如果不填,fontFamily为custom-fon
  }
})

如果是全局配置过了字体文件资源,那么只需要定义icon的样式即可

<template>
  <ViIcon 
    icon-style="icon-carams">
  </ViIcon>
</template>
.icon-carams::before {
  content: '\e603';
  color: aqua;
  font-size: 44px;
}

Config Props

接口数据类型说明选项默认值版本号
iconNameString组件内容的icon名称选填''0.0.1
fontFamilyString扩展的字体资源名称设置选填custom-font0.0.1
fontSourceString字体的资源路径需要为选填''0.0.1

Extend Class

prop说明
icon-style用于设置字体图标的样式

Event name

Event name说明
clickIcon组件点击事件

Global Config Props

接口数据类型说明选项默认值版本号
_$ViIconObject字体资源文件的相关配置选填{}0.0.3

Icon Name 内置的图标名

icon nameicon nameicon name
emailshoopinglocation
cloud-downloadcloud-uploadbranch
datatelephoneshare
pricefull-screenfull-screen-cancel
deleteqrCodesetting
setting-centecontrolreturn
linklink-cancelshopping-case
labelprintbluetooth
addreduceright
errorrefreshhistory
bottom-left-arrowbottom-right-arrowtop-right-arrow
top-left-arrowright-arrowleft-arrow
bottom-arrowtop-arrowbottom-arrow-doubl
top-arrow-doubleright-arrow-doubleright-arrow-double
left-arrow-double--

版本记录

  • v0.0.1 初始版本
  • v0.0.3 新增全局配置外部字体文件功能