diff --git a/src/statusTag/__tests__/__snapshots__/index.test.tsx.snap b/src/statusTag/__tests__/__snapshots__/index.test.tsx.snap index 58e9e880f..173626f97 100644 --- a/src/statusTag/__tests__/__snapshots__/index.test.tsx.snap +++ b/src/statusTag/__tests__/__snapshots__/index.test.tsx.snap @@ -6,11 +6,15 @@ exports[`test StatusTag suite should support StatusTag success render 1`] = ` "baseElement":
基础使用
+基础使用
状态点
-外边框
-自定义状态
加载中
+加载中
## API
### StatusTag
-| 参数 | 说明 | 类型 | 默认值 |
-| ---------- | -------------------------------------------------------- | --------------------------------------------------------- | ----------- |
-| type | 设置状态类型 | `'warning' \| 'error' \| 'success' \| 'run' \| 'stopped'` | `'success'` |
-| showBorder | 是否展示外面的 border | `boolean` | `true` |
-| color | 自定义颜色(当 type 所支持的颜色不满足时可用,优先级更高) | `string` | - |
-| onClick | 点击事件 | `() => void` | - |
-| loading | 设置状态标签载入状态 | `boolean` | `false` |
+| 参数 | 说明 | 类型 | 默认值 |
+| ---------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------ | --------- | --- |
+| color | 状态色,内置了六种颜色,不满足时可自定义(仅支持 RGB 和十六进制颜色) | `blue \| yellow \| green \| gray \| red \| purple \| cyan \| pink` \| `string` | `success` | - |
+| icon | 自定义图标 | `React.ReactNode` | - |
+| loading | 状态标签载入状态 | `boolean` | `false` |
+| type | 状态类型 | `default \| outline \| fill` | `default` |
+| background | 背景颜色,仅在自定义颜色且为 fill 的情况下生效 | `string` | `--` |
diff --git a/src/statusTag/index.tsx b/src/statusTag/index.tsx
index d44ea032b..2f5c431c5 100644
--- a/src/statusTag/index.tsx
+++ b/src/statusTag/index.tsx
@@ -5,43 +5,108 @@ import classNames from 'classnames';
import './style.scss';
-export type StatusTagType = 'warning' | 'error' | 'success' | 'run' | 'stopped';
+const calculateTransparentColor = (color: string) => {
+ if (color.startsWith('rgb')) return `${color.slice(0, -1)},0.15)`;
+ let hex = color;
+ if (hex.length === 4) {
+ hex = hex.replace(/^#(.)(.)(.)$/, '#$1$1$2$2$3$3');
+ }
+ const r = parseInt(hex.substring(1, 3), 16);
+ const g = parseInt(hex.substring(3, 5), 16);
+ const b = parseInt(hex.substring(5, 7), 16);
+ return `rgba(${r}, ${g}, ${b}, ${0.15})`;
+};
+
+const PresetColorTypes = [
+ 'blue',
+ 'yellow',
+ 'green',
+ 'gray',
+ 'red',
+ 'purple',
+ 'cyan',
+ 'pink',
+] as const;
+const StatusTagTypes = ['default', 'outline', 'fill'] as const;
+
+export type PresetColorType = (typeof PresetColorTypes)[number] | (string & {});
+export type StatusTagType = (typeof StatusTagTypes)[number];
+
+function isPresetStatus(color?: any): color is PresetColorType {
+ return PresetColorTypes.includes(color);
+}
export interface IStatusTagProps extends HTMLAttributes