@meta-1/design 0.0.201 → 0.0.202
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -227,4 +227,24 @@
|
|
|
227
227
|
display: inline-block;
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
@utility action-effect {
|
|
233
|
+
@apply hover:bg-[var(--action-hover)] hover:text-primary;
|
|
234
|
+
@apply focus:bg-[var(--action-hover)] focus:border-[var(--border)] focus:shadow-[0_0_0_1px_var(--card),0_0_0_3px_var(--primary)];
|
|
235
|
+
@apply dark:focus:border-[var(--sidebar-border)] dark:focus:shadow-[0_0_0_1px_var(--secondary),0_0_0_3px_var(--primary)];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@utility action-effect-active {
|
|
239
|
+
@apply active:bg-[var(--action-hover)] active:border-[var(--border)] active:shadow-[0_0_0_1px_var(--card),0_0_0_3px_var(--primary)];
|
|
240
|
+
@apply dark:active:border-[var(--sidebar-border)] dark:active:shadow-[0_0_0_1px_var(--secondary),0_0_0_3px_var(--primary)];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@utility action-active {
|
|
244
|
+
@apply text-primary bg-[var(--action-hover)];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
@utility action-effect-disabled {
|
|
248
|
+
@apply opacity-50 cursor-not-allowed focus:bg-transparent active:bg-transparent focus:shadow-none active:shadow-none focus:border-transparent active:border-transparent;
|
|
249
|
+
@apply hover:bg-transparent;
|
|
230
250
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
@import "../../../assets/style/theme.css";
|
|
2
|
-
|
|
3
|
-
@utility action-effect {
|
|
4
|
-
@apply hover:bg-[var(--action-hover)] hover:text-primary;
|
|
5
|
-
@apply focus:bg-[var(--action-hover)] focus:border-[var(--border)] focus:shadow-[0_0_0_1px_var(--card),0_0_0_3px_var(--primary)];
|
|
6
|
-
@apply dark:focus:border-[var(--sidebar-border)] dark:focus:shadow-[0_0_0_1px_var(--secondary),0_0_0_3px_var(--primary)];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
@utility action-effect-active {
|
|
10
|
-
@apply active:bg-[var(--action-hover)] active:border-[var(--border)] active:shadow-[0_0_0_1px_var(--card),0_0_0_3px_var(--primary)];
|
|
11
|
-
@apply dark:active:border-[var(--sidebar-border)] dark:active:shadow-[0_0_0_1px_var(--secondary),0_0_0_3px_var(--primary)];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@utility action-active {
|
|
15
|
-
@apply text-primary bg-[var(--action-hover)];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@utility action-effect-disabled {
|
|
19
|
-
@apply opacity-50 cursor-not-allowed focus:bg-transparent active:bg-transparent focus:shadow-none active:shadow-none focus:border-transparent active:border-transparent;
|
|
20
|
-
@apply hover:bg-transparent;
|
|
21
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
# TagsInput 组件
|
|
2
|
-
|
|
3
|
-
一个功能丰富的标签输入组件,支持添加、删除标签,带有验证、最大数量限制等特性。
|
|
4
|
-
|
|
5
|
-
## 功能特性
|
|
6
|
-
|
|
7
|
-
- ✅ 受控/非受控模式
|
|
8
|
-
- ✅ 键盘操作(Enter 添加,Backspace 删除)
|
|
9
|
-
- ✅ 自定义分隔符(默认逗号)
|
|
10
|
-
- ✅ 标签验证
|
|
11
|
-
- ✅ 最大标签数量限制
|
|
12
|
-
- ✅ 最大标签长度限制
|
|
13
|
-
- ✅ 禁止重复标签
|
|
14
|
-
- ✅ 自定义标签渲染
|
|
15
|
-
- ✅ 完整的事件回调
|
|
16
|
-
- ✅ 禁用状态
|
|
17
|
-
- ✅ 自定义样式
|
|
18
|
-
|
|
19
|
-
## 基础用法
|
|
20
|
-
|
|
21
|
-
```tsx
|
|
22
|
-
import { TagsInput } from "@meta-1/design";
|
|
23
|
-
|
|
24
|
-
function App() {
|
|
25
|
-
const [tags, setTags] = useState<string[]>([]);
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<TagsInput
|
|
29
|
-
value={tags}
|
|
30
|
-
onChange={setTags}
|
|
31
|
-
placeholder="输入标签后按 Enter..."
|
|
32
|
-
/>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Props
|
|
38
|
-
|
|
39
|
-
| 属性 | 类型 | 默认值 | 说明 |
|
|
40
|
-
|------|------|--------|------|
|
|
41
|
-
| value | `string[]` | - | 受控模式的标签值 |
|
|
42
|
-
| defaultValue | `string[]` | `[]` | 非受控模式的默认值 |
|
|
43
|
-
| onChange | `(value: string[]) => void` | - | 标签变化回调 |
|
|
44
|
-
| placeholder | `string` | - | 输入框占位符 |
|
|
45
|
-
| className | `string` | - | 容器类名 |
|
|
46
|
-
| inputClassName | `string` | - | 输入框类名 |
|
|
47
|
-
| tagClassName | `string` | - | 标签类名 |
|
|
48
|
-
| maxTags | `number` | - | 最大标签数量 |
|
|
49
|
-
| maxLength | `number` | - | 单个标签最大长度 |
|
|
50
|
-
| allowDuplicates | `boolean` | `false` | 是否允许重复标签 |
|
|
51
|
-
| separator | `string \| RegExp` | `","` | 分隔符 |
|
|
52
|
-
| validate | `(tag: string) => boolean` | - | 标签验证函数 |
|
|
53
|
-
| disabled | `boolean` | `false` | 是否禁用 |
|
|
54
|
-
| onTagAdd | `(tag: string) => void` | - | 添加标签回调 |
|
|
55
|
-
| onTagRemove | `(tag: string) => void` | - | 删除标签回调 |
|
|
56
|
-
| renderTag | `(tag: string, index: number, remove: () => void) => ReactNode` | - | 自定义标签渲染 |
|
|
57
|
-
|
|
58
|
-
## 使用示例
|
|
59
|
-
|
|
60
|
-
### 最大数量限制
|
|
61
|
-
|
|
62
|
-
```tsx
|
|
63
|
-
<TagsInput
|
|
64
|
-
maxTags={5}
|
|
65
|
-
value={tags}
|
|
66
|
-
onChange={setTags}
|
|
67
|
-
placeholder="最多 5 个标签"
|
|
68
|
-
/>
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### 自定义验证
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
<TagsInput
|
|
75
|
-
validate={(tag) => /^[a-zA-Z0-9]+$/.test(tag)}
|
|
76
|
-
value={tags}
|
|
77
|
-
onChange={setTags}
|
|
78
|
-
placeholder="只允许字母和数字"
|
|
79
|
-
/>
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### 禁止重复
|
|
83
|
-
|
|
84
|
-
```tsx
|
|
85
|
-
<TagsInput
|
|
86
|
-
allowDuplicates={false}
|
|
87
|
-
value={tags}
|
|
88
|
-
onChange={setTags}
|
|
89
|
-
placeholder="不允许重复标签"
|
|
90
|
-
/>
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### 自定义标签渲染
|
|
94
|
-
|
|
95
|
-
```tsx
|
|
96
|
-
<TagsInput
|
|
97
|
-
renderTag={(tag, index, remove) => (
|
|
98
|
-
<div className="custom-tag">
|
|
99
|
-
#{tag}
|
|
100
|
-
<button onClick={remove}>×</button>
|
|
101
|
-
</div>
|
|
102
|
-
)}
|
|
103
|
-
value={tags}
|
|
104
|
-
onChange={setTags}
|
|
105
|
-
/>
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### 事件回调
|
|
109
|
-
|
|
110
|
-
```tsx
|
|
111
|
-
<TagsInput
|
|
112
|
-
onTagAdd={(tag) => console.log("添加:", tag)}
|
|
113
|
-
onTagRemove={(tag) => console.log("删除:", tag)}
|
|
114
|
-
value={tags}
|
|
115
|
-
onChange={setTags}
|
|
116
|
-
/>
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## 键盘操作
|
|
120
|
-
|
|
121
|
-
- **Enter**: 添加当前输入的标签
|
|
122
|
-
- **Backspace**: 当输入框为空时,删除最后一个标签
|
|
123
|
-
- **分隔符** (默认逗号): 添加标签
|
|
124
|
-
|
|
125
|
-
## 样式自定义
|
|
126
|
-
|
|
127
|
-
组件支持通过 `className`、`inputClassName` 和 `tagClassName` 来自定义样式:
|
|
128
|
-
|
|
129
|
-
```tsx
|
|
130
|
-
<TagsInput
|
|
131
|
-
className="border-primary"
|
|
132
|
-
tagClassName="bg-primary text-primary-foreground"
|
|
133
|
-
inputClassName="text-lg"
|
|
134
|
-
/>
|
|
135
|
-
```
|
|
136
|
-
|