1.0.4 • Published 1 month ago

@tanzhenxing/zx-tag v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

ZX-Tag 标签组件

用于标记和选择的标签组件,提供了丰富的表现形式,参考 Element Plus Tag 组件设计。

特性

  • 🎨 多种类型:primary、success、info、warning、danger
  • 🎯 多种主题:dark、light、plain
  • 📏 多种尺寸:large、default、small
  • 🔘 支持圆形标签
  • 🚫 可关闭标签
  • ✅ 可选中标签(CheckTag)
  • 🎭 支持自定义图标
  • 🎪 支持动画效果
  • 🧩 插槽支持

组件列表

ZxTag - 基础标签

基础的标签组件,支持多种样式和功能。

ZxCheckTag - 可选中标签

可选中的标签组件,类似复选框但是按钮式的样式。

安装使用

// 导入组件
import { ZxTag, ZxCheckTag } from '@/components/zx-tag'

// 或者单独导入
import ZxTag from '@/components/zx-tag/zx-tag.vue'
import ZxCheckTag from '@/components/zx-tag/zx-check-tag.vue'

ZxTag 基础用法

基础标签

<template>
  <view class="flex gap-2">
    <zx-tag text="Primary" type="primary" />
    <zx-tag text="Success" type="success" />
    <zx-tag text="Info" type="info" />
    <zx-tag text="Warning" type="warning" />
    <zx-tag text="Danger" type="danger" />
  </view>
</template>

不同主题

<template>
  <view>
    <!-- Dark 主题 -->
    <view class="flex gap-2 mb-2">
      <zx-tag text="Dark" type="primary" effect="dark" />
      <zx-tag text="Dark" type="success" effect="dark" />
    </view>
    
    <!-- Light 主题(默认) -->
    <view class="flex gap-2 mb-2">
      <zx-tag text="Light" type="primary" effect="light" />
      <zx-tag text="Light" type="success" effect="light" />
    </view>
    
    <!-- Plain 主题 -->
    <view class="flex gap-2">
      <zx-tag text="Plain" type="primary" effect="plain" />
      <zx-tag text="Plain" type="success" effect="plain" />
    </view>
  </view>
</template>

不同尺寸

<template>
  <view class="flex gap-2">
    <zx-tag text="Large" size="large" />
    <zx-tag text="Default" size="default" />
    <zx-tag text="Small" size="small" />
  </view>
</template>

可移除标签

<template>
  <view class="flex gap-2">
    <zx-tag 
      v-for="tag in tags" 
      :key="tag.name" 
      :text="tag.name"
      :type="tag.type"
      closable 
      @close="handleClose"
    />
  </view>
</template>

<script setup>
import { ref } from 'vue'

const tags = ref([
  { name: 'Tag 1', type: 'primary' },
  { name: 'Tag 2', type: 'success' },
  { name: 'Tag 3', type: 'info' }
])

const handleClose = (index) => {
  tags.value.splice(index, 1)
}
</script>

圆形标签

<template>
  <view class="flex gap-2">
    <zx-tag text="Round" type="primary" round />
    <zx-tag text="Round" type="success" round />
    <zx-tag text="Round" type="info" round />
  </view>
</template>

带图标的标签

<template>
  <view class="flex gap-2">
    <zx-tag text="图标标签" type="primary" icon="star" />
    <zx-tag text="图片标签" type="success" icon="https://zxui.org/logo.png" />
  </view>
</template>

自定义插槽

<template>
  <zx-tag type="primary">
    <template #icon>
      <zx-icon name="heart" />
    </template>
    自定义内容
  </zx-tag>
</template>

ZxCheckTag 可选中标签

基础用法

<template>
  <view class="flex gap-2">
    <zx-check-tag v-model:checked="checked1" text="可选标签" />
    <zx-check-tag :checked="true" text="已选中" disabled />
    <zx-check-tag text="未选中" />
  </view>
</template>

<script setup>
import { ref } from 'vue'
const checked1 = ref(false)
</script>

不同类型

<template>
  <view class="flex gap-2">
    <zx-check-tag v-model:checked="checked1" text="Primary" type="primary" />
    <zx-check-tag v-model:checked="checked2" text="Success" type="success" />
    <zx-check-tag v-model:checked="checked3" text="Warning" type="warning" />
  </view>
</template>

ZxTag API

Attributes

属性名说明类型可选值默认值
type标签类型stringprimary/success/info/warning/danger/errorprimary
effect主题stringdark/light/plainlight
size标签尺寸stringlarge/default/smalldefault
shape标签形状stringcircle/squaresquare
round是否为圆形boolean-false
hit是否有边框描边boolean-false
text标签文字string/number--
closable是否可关闭boolean-false
disabled是否禁用boolean-false
show是否显示boolean-true
disableTransitions是否禁用动画boolean-false
icon图标名称或图片路径string--
iconColor图标颜色string--
bgColor背景色string--
color文字颜色string--
borderColor边框颜色string--
closeColor关闭按钮颜色string-#C6C7CB
name标识符string/number--
plain是否镂空(废弃)boolean-false
plainFill镂空时是否填充boolean-false

Events

事件名说明回调参数
click点击标签时触发(name)
close关闭标签时触发(name)

Slots

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

ZxCheckTag API

Attributes

属性名说明类型可选值默认值
checked / v-model:checked是否选中boolean-false
disabled是否禁用boolean-false
type标签类型stringprimary/success/info/warning/dangerprimary
size标签尺寸stringlarge/default/smalldefault
text标签文字string/number--
bgColor背景色string--
color文字颜色string--
borderColor边框颜色string--

Events

事件名说明回调参数
change选中状态改变时触发(checked: boolean)

Slots

名称说明
default标签内容

更新日志

v1.1.0

  • ✨ 新增 effect 属性支持多种主题
  • ✨ 新增 round 属性支持圆形标签
  • ✨ 新增 hit 属性支持边框描边
  • ✨ 新增 disableTransitions 属性禁用动画
  • ✨ 新增 ZxCheckTag 可选中标签组件
  • 🐛 修复尺寸规范化问题
  • 🐛 修复图标颜色逻辑
  • 📖 完善文档和示例

v1.0.0

  • 🎉 初始版本发布
  • ✨ 支持基础标签功能
  • ✨ 支持可关闭标签
  • ✨ 支持自定义图标

兼容性说明

  • 支持 error 类型向 danger 的自动转换
  • 支持旧版本尺寸名称:minismallmediumdefault
  • 保留 plain 属性的向后兼容性,建议使用 effect="plain"

贡献

欢迎提交 Issue 和 Pull Request 来完善组件功能。