-
-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
909 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useState } from "react"; | ||
import { Input, Tag, TagCloseButton, TagLabel } from "@chakra-ui/react"; | ||
|
||
export default function InputTag(props: { value: string[]; onChange: (value: string[]) => any }) { | ||
const { value, onChange } = props; | ||
const [inputV, setInputV] = useState(""); | ||
const handleEnter = (e: any) => { | ||
if (e.key === "Enter" || e.key === " ") { | ||
e.preventDefault(); | ||
const input = inputV.trim(); | ||
if (input.trim() !== "" && !value.some((x) => x === input)) { | ||
onChange([...value, input]); | ||
} | ||
setInputV(""); | ||
} | ||
}; | ||
const handleClose = (item: string) => { | ||
onChange(value.filter((name) => name !== item)); | ||
}; | ||
return ( | ||
<> | ||
<Input | ||
placeholder=" 按「回车键」或「空格键」分隔" | ||
className="mb-2" | ||
value={inputV} | ||
onKeyDown={(e) => handleEnter(e)} | ||
onChange={(e) => setInputV(e.target.value)} | ||
/> | ||
{value.length > 0 ? ( | ||
<div className="flex items-center flex-wrap pb-2 px-2 border-2 rounded border-white-700 border-dashed max-h-20 overflow-auto"> | ||
{value.map((item) => ( | ||
<Tag className="mr-2 mt-2" key={item} variant="inputTag"> | ||
<TagLabel>{item}</TagLabel> | ||
<TagCloseButton | ||
onClick={() => { | ||
handleClose(item); | ||
}} | ||
/> | ||
</Tag> | ||
))} | ||
</div> | ||
) : null} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.