parent
42f7b255f8
commit
0b4266be17
3 changed files with 51 additions and 1 deletions
@ -0,0 +1,48 @@ |
||||
import React, {useState, useEffect} from "react"; |
||||
|
||||
const TagsInput = () => { |
||||
const [tags, setTags] = useState([]); |
||||
const [tag, setTag] = useState(null); |
||||
const [fakeState, setFakeState] = useState(5); |
||||
|
||||
useEffect(() => { |
||||
if (tag) { |
||||
tags.push(tag); |
||||
setFakeState(fakeState + 1) |
||||
console.log(tags) |
||||
} |
||||
|
||||
}, [tag]); |
||||
return( |
||||
<div className="w-full rtl bg-white border mx-2 my-4 rounded-lg border-grayE0 flex flex-col py-6"> |
||||
<h1 className="text-blue3A text-lg font-bold w-full text-right px-4 mb-6 border-r-4 border-blue65"> |
||||
برچسب ها |
||||
</h1> |
||||
<div className="flex px-4"> |
||||
<input type="text" className="bg-white border border-grayE0 h-12 w-full outline-none px-2 ml-2 rounded-md" id="tagInput" onKeyDown={(e) => {if(e.key == 'Enter'){ setTag(e.target.value); document.getElementById('tagInput').value = null}}}/> |
||||
<button className="bg-grayE0 w-24 font-bold text-gray-600 rounded-md" onClick={() => {setTag(document.getElementById('tagInput').value); document.getElementById('tagInput').value = null}}> |
||||
افزودن |
||||
</button> |
||||
|
||||
</div> |
||||
<div className="w-full px-4 flex flex-wrap mt-2"> |
||||
{ |
||||
tags.map( |
||||
(item, index) => ( |
||||
<div className="bg-gray-200 py-1 flex items-center justify-center px-4 m-1 rtl rounded-md"> |
||||
|
||||
<p>{item}</p> |
||||
<p className="mr-1">x</p> |
||||
|
||||
</div> |
||||
) |
||||
) |
||||
} |
||||
</div> |
||||
|
||||
|
||||
</div> |
||||
) |
||||
} |
||||
|
||||
export default TagsInput; |
Loading…
Reference in new issue