From 24b2cbd143fc515163016dbcfa8589c21648ed3c Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Sat, 6 Aug 2022 09:06:37 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(component):=20[Tag}=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20Tag=20=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/src/component/tag/index.less | 88 +++++ package/component/src/component/tag/index.ts | 5 + package/component/src/component/tag/index.vue | 71 ++++ .../component/src/component/tag/interface.ts | 11 + .../component/src/component/tagInput/Tag.vue | 64 ++++ .../src/component/tagInput/index.less | 65 ++++ .../component/src/component/tagInput/index.ts | 5 + .../src/component/tagInput/index.vue | 158 +++++++++ package/component/src/index.ts | 3 + .../src/document/zh-CN/components/tag.md | 313 ++++++++++++++++++ .../document-component/src/router/zh-CN.ts | 5 + 11 files changed, 788 insertions(+) create mode 100644 package/component/src/component/tag/index.less create mode 100644 package/component/src/component/tag/index.ts create mode 100644 package/component/src/component/tag/index.vue create mode 100644 package/component/src/component/tag/interface.ts create mode 100644 package/component/src/component/tagInput/Tag.vue create mode 100644 package/component/src/component/tagInput/index.less create mode 100644 package/component/src/component/tagInput/index.ts create mode 100644 package/component/src/component/tagInput/index.vue create mode 100644 package/document-component/src/document/zh-CN/components/tag.md diff --git a/package/component/src/component/tag/index.less b/package/component/src/component/tag/index.less new file mode 100644 index 00000000..d3d7792d --- /dev/null +++ b/package/component/src/component/tag/index.less @@ -0,0 +1,88 @@ +@tag-size-default: 24px; +@tag-size-default-font-size: 12px; +@tag-size-lg: @tag-size-default + 2px; +@tag-size-md: @tag-size-default; +@tag-size-sm: @tag-size-default - 2px; +@tag-size-xs: @tag-size-default - 2px * 2; +@tag-size-lg-font-size: @tag-size-default-font-size + 2px; +@tag-size-md-font-size: @tag-size-default-font-size; +@tag-size-sm-font-size: @tag-size-default-font-size - 2px; +@tag-size-xs-font-size: @tag-size-default-font-size - 2px * 2; +@tag-border-width: 1px; + +.layui-tag { + display: inline-flex; + align-items: baseline; + vertical-align: middle; + box-sizing: border-box; + height: @tag-size-md; + line-height: @tag-size-md - @tag-border-width * 2; + padding: 0 6px; + font-size: @tag-size-md-font-size; + font-weight: 500; + color: currentColor; + border-width: @tag-border-width; + border-style: solid; + border-color: transparent; + border-radius: var(--global-border-radius); + + &-icon { + margin-right: 4px; + } + + &-bordered { + border-color: var(--global-neutral-color-5); + } + + &-size-lg { + height: @tag-size-lg; + font-size: @tag-size-lg-font-size; + line-height: @tag-size-lg - @tag-border-width * 2; + + .layui-icon { + font-size: @tag-size-lg-font-size - 2px; + } + } + + &-size-md { + height: @tag-size-md; + font-size: @tag-size-md-font-size; + line-height: @tag-size-md - @tag-border-width * 2; + + .layui-icon { + font-size: @tag-size-md-font-size - 2px; + } + } + + &-size-sm { + height: @tag-size-sm; + font-size: @tag-size-sm-font-size; + line-height: @tag-size-sm - @tag-border-width * 2; + + .layui-icon { + font-size: @tag-size-sm-font-size - 2px; + } + } + + &-size-xs { + height: @tag-size-xs; + font-size: @tag-size-xs-font-size; + line-height: @tag-size-xs - @tag-border-width * 2; + + .layui-icon { + font-size: @tag-size-xs-font-size - 2px; + } + } + + & &-close-icon { + margin-left: 4px; + font-size: @tag-size-default-font-size - 2px; + + .layui-icon { + + &:hover { + cursor: pointer; + } + } + } +} diff --git a/package/component/src/component/tag/index.ts b/package/component/src/component/tag/index.ts new file mode 100644 index 00000000..bc751ebc --- /dev/null +++ b/package/component/src/component/tag/index.ts @@ -0,0 +1,5 @@ +import { withInstall, WithInstallType } from "../../utils"; +import Component from "./index.vue"; + +const component: WithInstallType = withInstall(Component); +export default component; diff --git a/package/component/src/component/tag/index.vue b/package/component/src/component/tag/index.vue new file mode 100644 index 00000000..a38c6ef9 --- /dev/null +++ b/package/component/src/component/tag/index.vue @@ -0,0 +1,71 @@ + + + diff --git a/package/component/src/component/tag/interface.ts b/package/component/src/component/tag/interface.ts new file mode 100644 index 00000000..e3802fed --- /dev/null +++ b/package/component/src/component/tag/interface.ts @@ -0,0 +1,11 @@ +export const TAG_COLORS = [ + "red", + "orange", + "green", + "cyan", + "blue", + "black", + "gray", +] as const; + +export type TagColor = typeof TAG_COLORS[number]; diff --git a/package/component/src/component/tagInput/Tag.vue b/package/component/src/component/tagInput/Tag.vue new file mode 100644 index 00000000..5ab4b9fc --- /dev/null +++ b/package/component/src/component/tagInput/Tag.vue @@ -0,0 +1,64 @@ + + + + + diff --git a/package/component/src/component/tagInput/index.less b/package/component/src/component/tagInput/index.less new file mode 100644 index 00000000..d37fc198 --- /dev/null +++ b/package/component/src/component/tagInput/index.less @@ -0,0 +1,65 @@ +.layui-input-tag { + position: relative; + display: block; + padding: 0 5px; + height: auto; + overflow: hidden; + + .layui-input-prefix { + display: inline; + text-align: left; + height: 100%; + flex: unset; + } + + .layui-input-suffix{ + position: absolute; + right: 3px; + bottom: 0; + height: 100%; + } + + .layui-input { + display: inline-block; + padding-left: 0; + width: auto; + flex: 1; + max-width: 100%; + min-width: 12px; + } +} + +.layui-input-tag-collapsed-panel, +.layui-input-tag { + .layui-badge { + margin-right: 5px; + height: 28px; + line-height: 28px; + user-select: none; + white-space: pre-wrap; + + .layui-icon { + font-size: 12px; + padding-left: 3px; + + &:hover { + cursor: pointer; + color: #ff5722; + } + } + } +} + +.layui-input-tag-collapsed-panel { + white-space: normal; + display: flex; + align-items: center; + flex-wrap: wrap; + width: fit-content; + max-width: 200px; + height: auto; + overflow: hidden; + .layui-badge{ + margin-bottom: 4px; + } +} \ No newline at end of file diff --git a/package/component/src/component/tagInput/index.ts b/package/component/src/component/tagInput/index.ts new file mode 100644 index 00000000..bc751ebc --- /dev/null +++ b/package/component/src/component/tagInput/index.ts @@ -0,0 +1,5 @@ +import { withInstall, WithInstallType } from "../../utils"; +import Component from "./index.vue"; + +const component: WithInstallType = withInstall(Component); +export default component; diff --git a/package/component/src/component/tagInput/index.vue b/package/component/src/component/tagInput/index.vue new file mode 100644 index 00000000..33d3d6b4 --- /dev/null +++ b/package/component/src/component/tagInput/index.vue @@ -0,0 +1,158 @@ + + + diff --git a/package/component/src/index.ts b/package/component/src/index.ts index 300b1b3a..4021ce3d 100644 --- a/package/component/src/index.ts +++ b/package/component/src/index.ts @@ -88,6 +88,7 @@ import LayNoticeBar from "./component/noticeBar/index"; import LayPageHeader from "./component/pageHeader/index"; import LayCascader from "./component/cascader/index"; import LayAffix from "./component/affix/index"; +import LayTag from "./component/tag/index"; import LayConfigProvider from "./provider"; import { InstallOptions } from "./types"; @@ -174,6 +175,7 @@ const components: Record = { LayPageHeader, LayCascader, LayAffix, + LayTag, }; const install = (app: App, options?: InstallOptions): void => { @@ -267,6 +269,7 @@ export { LayPageHeader, LayCascader, LayAffix, + LayTag, install, }; diff --git a/package/document-component/src/document/zh-CN/components/tag.md b/package/document-component/src/document/zh-CN/components/tag.md new file mode 100644 index 00000000..1f8c4aba --- /dev/null +++ b/package/document-component/src/document/zh-CN/components/tag.md @@ -0,0 +1,313 @@ +::: anchor +::: + +::: title 基本介绍 +::: + +::: describe 标签组件。 +::: + +::: title 基础使用 +::: + +::: demo 标签的基本用法。 + + + + + +::: + +::: title 标签尺寸 +::: + +::: demo 通过 size 属性控制标签尺寸。 + + + + + +::: + +::: title 可关闭 +::: + +::: demo 通过 closable 属性控制标签是否可关闭 + + + + + +::: + +::: title 标签颜色 +::: + +::: demo 标签颜色,待优化。 + + + + + +::: + +::: title 图标插槽 +::: + +::: demo 标签的基本用法。 + + + + + +::: + +::: title 动态编辑 +::: + +::: demo 标签的基本用法。 + + + + +::: + + +::: title Tag 属性 +::: + +::: table + +| 属性 | 描述 | 类型 | 默认值 | 可选值 | +| ----------- | -------- | ------ | ------ | ------ | +| size | 标签大小 | string | md | `lg` `md` `sm` `xs`| +| color | 标签颜色 | string | `green`| `red` `orange` `green` `cyan` `blue` `black` `gray` `string` | +| bordered | 是否显示边框 | boolean | false | `true` `false`| +| closable | 是否可关闭 | boolean | false | `true` `false`| + +::: + +:::title Tag 插槽 +::: + +:::table +| 插槽 | 描述 | 参数 | +|------ |----------|-----------| +| default | 默认插槽 | - | +| icon | 图标 | - | +| close-icon | 关闭图标 | - | +::: + +:::title Tag 事件 +::: + +:::table +| 事件 | 描述 | 参数 | +|------ |----------|-----------| +| close | 关闭时触发 | e: MouseEvent | +::: + +::: contributor tag +::: + +::: previousNext tag +::: \ No newline at end of file diff --git a/package/document-component/src/router/zh-CN.ts b/package/document-component/src/router/zh-CN.ts index 61be2e38..00cb3750 100644 --- a/package/document-component/src/router/zh-CN.ts +++ b/package/document-component/src/router/zh-CN.ts @@ -419,6 +419,11 @@ const zhCN = [ component: () => import("../document/zh-CN/components/photo.md"), meta: { title: "相册" }, }, + { + path: "/zh-CN/components/tag", + component: () => import("../document/zh-CN/components/tag.md"), + meta: { title: "标签" }, + }, ], }, ],