diff --git a/packages/devui-vue/devui/tag/src/tag-types.ts b/packages/devui-vue/devui/tag/src/tag-types.ts index f8fd95a57f4f119dcc6f936a55362e4121b9a462..2d3f6a8c1eaee2d6c4fa23fd674054e8c8f2b8d3 100644 --- a/packages/devui-vue/devui/tag/src/tag-types.ts +++ b/packages/devui-vue/devui/tag/src/tag-types.ts @@ -10,6 +10,10 @@ export const tagProps = { color: { type: String as PropType, default: '' + }, + deletable: { + type: Boolean, + default: false } } as const diff --git a/packages/devui-vue/devui/tag/src/tag.tsx b/packages/devui-vue/devui/tag/src/tag.tsx index 615641197e99bcea75035dbb35a61d70c551cfc3..69965585d3628f9794187395bc3cdf84d25a0ac9 100644 --- a/packages/devui-vue/devui/tag/src/tag.tsx +++ b/packages/devui-vue/devui/tag/src/tag.tsx @@ -1,4 +1,4 @@ -import { defineComponent } from 'vue' +import { defineComponent, ref } from 'vue' import { tagProps, TagProps } from './tag-types' import { useStyle } from './hooks' import './tag.scss' @@ -7,17 +7,46 @@ import './tag.scss' export default defineComponent({ name: 'DTag', props: tagProps, - emits: [], - setup(props: TagProps, { slots }) { + emits: ["tagDelete"], + components:{}, + setup(props: TagProps, { slots, emit }) { //获取type对应样式 const tagClass = useStyle(props) - return () => ( -
- - {slots.default?.()} - -
+ // 是否可关闭 + const isDelete = ref(!props.deletable) + const onCloseTag = (event: MouseEvent) => { + event.stopPropagation() + emit("tagDelete", event) + isDelete.value = true + } + + return { + props, + slots, + tagClass, + isDelete, + onCloseTag + } + }, + render() { + const { + props, + slots, + tagClass, + isDelete, + onCloseTag + } = this + return ( + (!props.deletable || !isDelete) ?
+ + {slots.default?.()} + { + props.deletable && + onCloseTag(event)}> + } + +
:"" ) } }) diff --git a/packages/devui-vue/docs/components/tag/index.md b/packages/devui-vue/docs/components/tag/index.md index c96b6238269cb9840a566900ab74031101aada47..c8760329ba96c211c451003f713bbdd5e01656ae 100644 --- a/packages/devui-vue/docs/components/tag/index.md +++ b/packages/devui-vue/docs/components/tag/index.md @@ -36,14 +36,55 @@ export default defineComponent({ ::: +## 可移除标签 + +:::demo 由`closable`属性来选择 tag 的可移除属性,也可以通过自定义`tagDelete`事件触发回调 + +```vue + + + + + +``` + +::: + ## API ### Props -| 参数 | 类型 | 默认值 | 说明 | 可选值 | 跳转至 Demo | -| :---: | :------: | :-----: | :----------------: | :------------------------------: | :---------------: | -| type | `string` | defalut | 可选,标签的类型 | `success\|info\|warning\|danger` | [示例](#基本用法) | -| color | `string` | '' | 可选,标签的主题色 | | | +| 参数 | 类型 | 默认值 | 说明 | 可选值 | 跳转至 Demo | +| :------: | :-------: | :-----: | :----------------: | :------------------------------: | :-----------------: | +| type | `string` | defalut | 可选,标签的类型 | `success\|info\|warning\|danger` | [示例](#基本用法) | +| color | `string` | '' | 可选,标签的主题色 | | | +| closable | `boolean` | false | 可选,标签的可关闭 | `true\|false` | [示例](#可移除标签) | ### Event