Icon 图标

Uniboot UI 提供一组常用图标。

使用方式

安装

包管理器

任选其一。

shell
$ npm install @uniboot/icons-vue
shell
$ yarn add @uniboot/icons-vue
shell
$ pnpm install @uniboot/icons-vue

注册全部图标

@uniboot/icons-vue 引入并全局注册。

ts
// main.ts

// 若使用 CDN 方式,请删除本段 import。
import * as UnibootUIIconsVue from '@uniboot/icons-vue'

const app = createApp(App)
for (const [key, component] of Object.entries(UnibootUIIconsVue)) {
  app.component(key, component)
}

也可参考 CodePen 模板

浏览器引入

通过 <script> 直接引入后,可使用全局变量 UnibootUIIconsVue

不同 CDN 引入方式略有差异,以下以 unpkgjsDelivr 为例,也可换用其他 CDN。

html
<script src="//unpkg.com/@uniboot/icons-vue"></script>
html
<script src="//cdn.jsdelivr.net/npm/@uniboot/icons-vue"></script>

TIP

通过 CDN 引入时建议在链接中锁定版本,避免后续 Uniboot UI 升级带来的不兼容变更。锁定方式见 unpkg.com

自动导入

可结合 unplugin-iconsunplugin-auto-import 自动导入 iconify 图标集。

配置示例可参考 该模板

简单示例

WARNING

HTML 标准中已存在 menu 标签,若直接注册名为 Menu 的图标组件将无法按预期渲染,需使用别名注册。

vue
<!-- 使用 u-icon 向内部 SVG 传递尺寸、颜色等 -->
<template>
  <div>
    <u-icon :size="size" :color="color">
      <Edit />
    </u-icon>
    <!-- 或单独使用图标组件,不继承外层属性 -->
    <Edit />
  </div>
</template>

与 u-icon 组合

u-icon 可为原始 SVG 图标补充尺寸、颜色等属性,详见文末 API。

vue
<template>
  <p>增加 <b>is-loading</b> 类可在约 2 秒内旋转一圈,也可自行覆盖动画。</p>
  <u-icon :size="20">
    <Edit />
  </u-icon>
  <u-icon color="#409efc" class="no-inherit">
    <Share />
  </u-icon>
  <u-icon>
    <Delete />
  </u-icon>
  <u-icon class="is-loading">
    <Loading />
  </u-icon>
  <u-button type="primary">
    <u-icon style="vertical-align: middle">
      <Search />
    </u-icon>
    <span style="vertical-align: middle"> Search </span>
  </u-button>
</template>

增加 is-loading 类可在约 2 秒内旋转一圈,也可自行覆盖动画。

直接使用 SVG 组件

vue
<template>
  <div style="font-size: 20px">
    <!-- SVG 图标默认不带尺寸等属性,需自行设置 -->
    <Edit style="width: 1em; height: 1em; margin-right: 8px" />
    <Share style="width: 1em; height: 1em; margin-right: 8px" />
    <Delete style="width: 1em; height: 1em; margin-right: 8px" />
    <Search style="width: 1em; height: 1em; margin-right: 8px" />
  </div>
</template>

自定义 SVG

u-icon 的默认插槽不只限于 @uniboot/icons-vue,只要最终渲染出 <svg>(或其中有 svg),即可用 :size:color 等与官方图标同样的方式组合使用。

内联 SVG

<svg> 直接写在插槽内即可。

vue
<template>
  <u-icon :size="24" color="#409efc">
    <svg
      viewBox="0 0 24 24"
      xmlns="http://www.w3.org/2000/svg"
      aria-hidden="true"
    >
      <circle cx="12" cy="12" r="10" fill="currentColor" />
    </svg>
  </u-icon>
</template>

自建图标组件

写一个根节点为 <svg> 的单文件组件(与 @uniboot/icons-vue 中图标结构类似),再引入并放入 u-icon

vue
<template>
  <u-icon :size="20">
    <MyLogo />
  </u-icon>
</template>

<script lang="ts" setup>
import MyLogo from './icons/MyLogo.vue'
</script>

.svg 文件导入

在 Vite 等环境中可借助 vite-svg-loader 等插件将单个 .svg 作为 Vue 组件导入,也可结合 import.meta.glob 批量注册;亦可沿用项目里已配置的 SVG 相关插件,得到组件后按上例放入 u-icon

精灵图 / <symbol>(如 vite-plugin-svg-icons)

若使用 SVG Sprite(<svg><use href="#icon-xxx" /></svg>),同样可以外包一层 u-icon。能否随 color 变色取决于符号内部是否使用 currentColor 等可被继承的填色方式;硬编码 fill/stroke 时可能不会响应 u-iconcolor

TIP

需要图标跟随 u-iconcolor 时,建议在 SVG 中对图形使用 fill="currentColor"(线图标则相应处理 stroke),以便继承外层 currentColor

图标集合

TIP

任意版本均可使用 SVG 图标,只需安装对应包。

点击图标可复制名称。

Copy icon code
System
  • Plus
  • Minus
  • CirclePlus
  • Search
  • Female
  • Male
  • Aim
  • House
  • FullScreen
  • Loading
  • Link
  • Service
  • Pointer
  • Star
  • Notification
  • Connection
  • ChatDotRound
  • Setting
  • Clock
  • Position
  • Discount
  • Odometer
  • ChatSquare
  • ChatRound
  • ChatLineRound
  • ChatLineSquare
  • ChatDotSquare
  • View
  • Hide
  • Unlock
  • Lock
  • RefreshRight
  • RefreshLeft
  • Refresh
  • Bell
  • MuteNotification
  • User
  • Check
  • CircleCheck
  • Warning
  • CircleClose
  • Close
  • PieChart
  • More
  • Compass
  • Filter
  • Switch
  • Select
  • SemiSelect
  • CloseBold
  • EditPen
  • Edit
  • Message
  • MessageBox
  • TurnOff
  • Finished
  • Delete
  • Crop
  • SwitchButton
  • Operation
  • Open
  • Remove
  • ZoomOut
  • ZoomIn
  • InfoFilled
  • CircleCheckFilled
  • SuccessFilled
  • WarningFilled
  • CircleCloseFilled
  • QuestionFilled
  • WarnTriangleFilled
  • UserFilled
  • MoreFilled
  • Tools
  • HomeFilled
  • Menu
  • UploadFilled
  • Avatar
  • HelpFilled
  • Share
  • StarFilled
  • Comment
  • Histogram
  • Grid
  • Promotion
  • DeleteFilled
  • RemoveFilled
  • CirclePlusFilled
Arrow
  • ArrowLeft
  • ArrowUp
  • ArrowRight
  • ArrowDown
  • ArrowLeftBold
  • ArrowUpBold
  • ArrowRightBold
  • ArrowDownBold
  • DArrowRight
  • DArrowLeft
  • Download
  • Upload
  • Top
  • Bottom
  • Back
  • Right
  • TopRight
  • TopLeft
  • BottomRight
  • BottomLeft
  • Sort
  • SortUp
  • SortDown
  • Rank
  • CaretLeft
  • CaretTop
  • CaretRight
  • CaretBottom
  • DCaret
  • Expand
  • Fold
Document
  • DocumentAdd
  • Document
  • Notebook
  • Tickets
  • Memo
  • Collection
  • Postcard
  • ScaleToOriginal
  • SetUp
  • DocumentDelete
  • DocumentChecked
  • DataBoard
  • DataAnalysis
  • CopyDocument
  • FolderChecked
  • Files
  • Folder
  • FolderDelete
  • FolderRemove
  • FolderOpened
  • DocumentCopy
  • DocumentRemove
  • FolderAdd
  • FirstAidKit
  • Reading
  • DataLine
  • Management
  • Checked
  • Ticket
  • Failed
  • TrendCharts
  • List
Media
  • Microphone
  • Mute
  • Mic
  • VideoPause
  • VideoCamera
  • VideoPlay
  • Headset
  • Monitor
  • Film
  • Camera
  • Picture
  • PictureRounded
  • Iphone
  • Cellphone
  • VideoCameraFilled
  • PictureFilled
  • Platform
  • CameraFilled
  • BellFilled
Traffic
  • Location
  • LocationInformation
  • DeleteLocation
  • Coordinate
  • Bicycle
  • OfficeBuilding
  • School
  • Guide
  • AddLocation
  • MapLocation
  • Place
  • LocationFilled
  • Van
Food
  • Watermelon
  • Pear
  • NoSmoking
  • Smoking
  • Mug
  • GobletSquareFull
  • GobletFull
  • KnifeFork
  • Sugar
  • Bowl
  • MilkTea
  • Lollipop
  • Coffee
  • Chicken
  • Dish
  • IceTea
  • ColdDrink
  • CoffeeCup
  • DishDot
  • IceDrink
  • IceCream
  • Dessert
  • IceCreamSquare
  • ForkSpoon
  • IceCreamRound
  • Food
  • HotWater
  • Grape
  • Fries
  • Apple
  • Burger
  • Goblet
  • GobletSquare
  • Orange
  • Cherry
Items
  • Printer
  • Calendar
  • CreditCard
  • Box
  • Money
  • Refrigerator
  • Cpu
  • Football
  • Brush
  • Suitcase
  • SuitcaseLine
  • Umbrella
  • AlarmClock
  • Medal
  • GoldMedal
  • Present
  • Mouse
  • Watch
  • QuartzWatch
  • Magnet
  • Help
  • Soccer
  • ToiletPaper
  • ReadingLamp
  • Paperclip
  • MagicStick
  • Basketball
  • Baseball
  • Coin
  • Goods
  • Sell
  • SoldOut
  • Key
  • ShoppingCart
  • ShoppingCartFull
  • ShoppingTrolley
  • Phone
  • Scissor
  • Handbag
  • ShoppingBag
  • Trophy
  • TrophyBase
  • Stopwatch
  • Timer
  • CollectionTag
  • TakeawayBox
  • PriceTag
  • Wallet
  • Opportunity
  • PhoneFilled
  • WalletFilled
  • GoodsFilled
  • Flag
  • BrushFilled
  • Briefcase
  • Stamp
Weather
  • Sunrise
  • Sunny
  • Ship
  • MostlyCloudy
  • PartlyCloudy
  • Sunset
  • Drizzling
  • Pouring
  • Cloudy
  • Moon
  • MoonNight
  • Lightning
Other
  • AddRole
  • AddTag
  • AddUser
  • Adjust
  • Cancel
  • CancelAccount
  • Center
  • Check2
  • ChromeFilled
  • CircleCancel
  • CircleCheck2
  • Close2
  • CloseUp
  • Company
  • Copy
  • Delete2
  • DeviceList
  • Disable
  • Disconnect
  • Download2
  • Earth
  • EditFilled
  • Eleme
  • ElemeFilled
  • ElementPlus
  • Email
  • Enable
  • Export
  • EyeClose
  • EyeOpen
  • File
  • FolderAdd2
  • Ftp
  • Group
  • Height
  • Import
  • Key2
  • Layer
  • Link2
  • List2
  • Lock2
  • Logout
  • Map
  • MenuApp
  • MenuCollapse
  • MenuDashboard
  • MenuExpand
  • MenuLog
  • MenuNotify
  • MenuParameters
  • MenuPartner
  • MenuProviders
  • MenuSandbox
  • MenuSettings
  • MenuTerminal
  • MenuUser
  • MenuUsers
  • Minus2
  • More2
  • NotificationConfiguration
  • Notify
  • PinBottom
  • PinTop
  • Plus2
  • Qrcode
  • Question
  • Recipient
  • Record
  • Recycle
  • Refresh2
  • RefreshRight2
  • Reset
  • Review
  • Scale
  • Scan
  • Search2
  • Send
  • SendMsg
  • Setting2
  • Share2
  • Shop
  • ShutDown
  • SixDot
  • Sort2
  • SwitchFilled
  • Tip
  • UnbindRole
  • Unlock2
  • Upload2
  • UploadLog
  • User2
  • User3
  • Video
  • View2
  • Void
  • Warning2
  • WindPower

API

属性

名称说明类型默认值
color对应 SVG 的 fillstring继承文字颜色
size图标宽高(正方形边长)number / string继承 font-size

插槽

名称说明
default自定义图标内容