diff --git a/src/tinyTag/__tests__/__snapshots__/tinyTag.test.tsx.snap b/src/tinyTag/__tests__/__snapshots__/tinyTag.test.tsx.snap
index 43b7be2ff..edfec6d98 100644
--- a/src/tinyTag/__tests__/__snapshots__/tinyTag.test.tsx.snap
+++ b/src/tinyTag/__tests__/__snapshots__/tinyTag.test.tsx.snap
@@ -5,7 +5,36 @@ exports[`test StatusTag should match snapshot 1`] = `
- 完成
+
`;
diff --git a/src/tinyTag/demos/basic.tsx b/src/tinyTag/demos/basic.tsx
index 82b3ed5cc..6e5613539 100644
--- a/src/tinyTag/demos/basic.tsx
+++ b/src/tinyTag/demos/basic.tsx
@@ -2,12 +2,14 @@ import React from 'react';
import { Space } from 'antd';
import { TinyTag } from 'dt-react-component';
+import './style.scss';
+
export default () => {
return (
-
-
-
+
+
+
);
};
diff --git a/src/tinyTag/demos/style.scss b/src/tinyTag/demos/style.scss
new file mode 100644
index 000000000..618f278ef
--- /dev/null
+++ b/src/tinyTag/demos/style.scss
@@ -0,0 +1,10 @@
+.data-tag {
+ color: #D1D1D1;
+ &:hover {
+ color: #D56161;
+ }
+}
+
+.ued-tag {
+ color: #D56161;
+}
diff --git a/src/tinyTag/index.md b/src/tinyTag/index.md
index 9dd5d8535..2efa4256f 100644
--- a/src/tinyTag/index.md
+++ b/src/tinyTag/index.md
@@ -19,8 +19,7 @@ TinyTag 组件通常用于在某些文案后面,用于标识当前行数据的
### TinyTag
-| 参数 | 说明 | 类型 | 默认值 |
-| --------- | ---------- | -------- | --------- |
-| value | 标签文案 | `string` | |
-| color | 颜色 | `string` | `#1D78FF` |
-| className | class 名称 | `string` | |
+| 参数 | 说明 | 类型 | 默认值 |
+| --------- | ---------- | -------- | ------ |
+| value | 标签文案 | `string` | |
+| className | class 名称 | `string` | |
diff --git a/src/tinyTag/index.tsx b/src/tinyTag/index.tsx
index 04f49a9b2..8e8f3ac15 100644
--- a/src/tinyTag/index.tsx
+++ b/src/tinyTag/index.tsx
@@ -1,21 +1,68 @@
-import React from 'react';
+import React, { useCallback, useEffect, useState } from 'react';
import classNames from 'classnames';
import './style.scss';
+type UseSvgRef = (element: SVGTextElement) => void;
+type UseSvgWidthResult = [UseSvgRef, number, number];
+
interface ITinyTag extends React.HTMLAttributes {
- value?: string;
- color?: string;
+ value: string;
}
-export default function TinyTag({ color, value, className, ...restProps }: ITinyTag) {
+const useSvgWidth = (): UseSvgWidthResult => {
+ const [element, ref] = useState(null);
+ const [svgWidth, setSvgWidth] = useState(0);
+ const [rectWidth, setRectWidth] = useState(0);
+
+ const getWidth = useCallback(() => {
+ if (!element) return;
+ const paddingWidth = 8;
+ const textWidth = Math.round(element.getBoundingClientRect()?.width);
+ const svgWidth = textWidth + paddingWidth;
+ setSvgWidth(svgWidth);
+ setRectWidth(Math.max(svgWidth - 1, 0));
+ }, [element]);
+
+ useEffect(() => {
+ getWidth();
+ }, [element]);
+
+ return [ref, svgWidth, rectWidth];
+};
+
+export default function TinyTag({ value, className, ...restProps }: ITinyTag) {
+ const [ref, svgWidth, rectWidth] = useSvgWidth();
return (
-
- {value}
+
+
);
}
diff --git a/src/tinyTag/style.scss b/src/tinyTag/style.scss
index 639dc8cd8..690d5f404 100644
--- a/src/tinyTag/style.scss
+++ b/src/tinyTag/style.scss
@@ -1,16 +1,5 @@
-$primaryColor: #1D78FF;
-$factor: 0.83;
-
.dtc-tinyTag {
- border-radius: 2px;
- border: 1px solid $primaryColor;
- font-weight: 400;
- color: $primaryColor;
- line-height: calc(15px / $factor);
- padding: 0 calc(4px / $factor);
- font-size: 12px;
- display: inline-block;
- transform: scale($factor);
user-select: none;
- white-space: nowrap;
+ display: inline-block;
+ transform: translateY(3px);
}