mtxuilib 0.1.337 → 0.1.339

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.
@@ -0,0 +1,2 @@
1
+ import { type InputProps } from "../../input";
2
+ export declare const TagsInput: (props: InputProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,39 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { useFormContext } from "react-hook-form";
5
+ import { Input } from "../../input";
6
+ export const TagsInput = (props) => {
7
+ const { name, placeholder } = props;
8
+ if (!name)
9
+ throw new Error("require field name @ TagsInput");
10
+ const form = useFormContext();
11
+ const [tags, setTags] = useState([]);
12
+ const [inputValue, setInputValue] = useState("");
13
+ const handleInputChange = (e) => {
14
+ setInputValue(e.target.value);
15
+ };
16
+ const handleInputKeyDown = (e) => {
17
+ if (e.key === "Enter" || e.key === " ") {
18
+ e.preventDefault();
19
+ addTag();
20
+ }
21
+ };
22
+ const addTag = () => {
23
+ const trimmedInput = inputValue.trim();
24
+ if (trimmedInput && !tags.includes(trimmedInput)) {
25
+ const newTags = [...tags, trimmedInput];
26
+ setTags(newTags);
27
+ setInputValue("");
28
+ form.setValue(name, newTags);
29
+ }
30
+ else {
31
+ setInputValue("");
32
+ }
33
+ };
34
+ const removeTag = (indexToRemove) => {
35
+ setTags(tags.filter((_, index) => index !== indexToRemove));
36
+ form.setValue(name, tags.filter((_, index) => index !== indexToRemove));
37
+ };
38
+ return (_jsx("div", { className: "flex flex-col space-y-2", children: _jsxs("div", { className: "flex flex-wrap gap-2 p-2 bg-white border border-gray-300 rounded-md", children: [tags.map((tag, index) => (_jsxs("div", { className: "flex items-center bg-blue-100 text-blue-800 text-sm font-medium px-2 py-1 rounded-full", children: [tag, _jsx("button", { type: "button", onClick: () => removeTag(index), className: "ml-1 text-blue-600 hover:text-blue-800 focus:outline-none", children: "\u00D7" })] }, index))), _jsx(Input, { type: "text", value: inputValue, onChange: handleInputChange, onKeyDown: handleInputKeyDown, onBlur: addTag, placeholder: placeholder || "Type and press Enter or Space to add tags", className: "flex-grow min-w-[120px] border-none focus:ring-0" })] }) }));
39
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mtxuilib",
3
3
  "private": false,
4
- "version": "0.1.337",
4
+ "version": "0.1.339",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -1 +0,0 @@
1
- export { Slot } from "@radix-ui/react-slot";
@@ -1 +0,0 @@
1
- export { Slot } from "@radix-ui/react-slot";