frontend/Components/ItemSelect/index.tsx
2022-08-27 17:41:59 +03:00

42 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useState } from "react";
import styles from "./itemSelect.module.css"
export interface SelectItemIE{
name:string
value: string|number
}
interface SelectIE{
onChange: (value:string|number) => void
items: SelectItemIE[]
value?:number
}
export const ItemSelect: React.FC<SelectIE> = (props) =>{
const [selected, setSelected] = useState(props.items[0])
const [open, setOpen] = useState(false)
let options = new Array()
props.items.map((item:SelectItemIE)=>{
options.push(
<div className={selected.name == item.name? styles.selected:styles.option} onClick={()=>onItemChange(item)}>{item.name}</div>
)
})
const onItemChange = (item:SelectItemIE) =>{
setSelected(item)
props.onChange(item.value)
}
return(
<div >
<div className={styles.myselect}>
<div className={styles.head} onClick={()=>setOpen(!open)}>Выберите документ <img style={{transform: open? "rotate(180deg)":""}} src="/images/arrow.svg"></img></div>
{
open? <div className={styles.options}>
{options}
</div>: ""
}
</div>
</div>
)
}