Added item select

This commit is contained in:
Djeeberjr 2021-11-14 16:09:44 +01:00
parent fbfdaaccba
commit c6beeed8e2
2 changed files with 37 additions and 6 deletions

View File

@ -0,0 +1,35 @@
import React, { useState } from "react"
import ItemToDisplay from "../ItemToDisplay"
import Item from "../types/Item"
import Side from "../types/Side"
interface Props {
side: Side
onChange?: (newItem: Item)=>void
}
const AddItem: React.FC<Props> = ({side,onChange}) => {
const [selected,setSelected] = useState<Item>(Item.DEFAULT_PISTOL)
return (
<div
className=""
>
<select
onChange={(e)=>setSelected(Item[e.target.value as keyof typeof Item])}
>
{
Object.keys(Item).map(e=><option key={e} value={e}>{ItemToDisplay(Item[e as keyof typeof Item],side)}</option>)
}
</select>
<span
onClick={()=>onChange?.(selected)}
className="cursor-pointer"
>
Add
</span>
</div>
)
}
export default AddItem

View File

@ -3,6 +3,7 @@ import ItemToDisplay from "../ItemToDisplay"
import Card from "../types/Card"
import Item from "../types/Item"
import Side from "../types/Side"
import AddItem from "./AddItem"
import SwitchButton from "./SwitchButton"
import TextEdit from "./TextEdit"
@ -31,12 +32,7 @@ const CardComp: React.FC<Props> = ({card,side,onChange}) => {
}} className="float-right cursor-pointer" >X</span>
</div>
)}
<div className="text-center cursor-pointer" onClick={()=>{
onChange?.(new Card(card.title,card.armor,card.helmet,...card.items,Item.HE))
}} >
Add
</div>
<AddItem side={side} onChange={newItem => onChange?.(new Card(card.title,card.armor,card.helmet,...card.items,newItem))} />
</div>
</div>
)