add lesson-52

parent fd54d3c4
import './GuestForm.scss' import './GuestForm.scss'
const GuestForm = () => { type TProps = {
onChange: (e: React.FormEvent<HTMLInputElement>) => void
onSubmit: (e: React.SyntheticEvent<HTMLFormElement>) => void
value: string
}
const GuestForm = ({onChange, onSubmit, value}: TProps) => {
return ( return (
<form className='GuestForm'> <form className='GuestForm' onSubmit={onSubmit}>
<input/> <input onChange={onChange} value={value}/>
</form> </form>
) )
} }
......
...@@ -6,14 +6,14 @@ type TProps = { ...@@ -6,14 +6,14 @@ type TProps = {
} }
const List = ({list, title}: TProps) => { const List = ({list, title}: TProps) => {
return ( return (
<div className='List'> <div className='List'>
<h2>{title}</h2> <h2>{title}</h2>
<div> <div>
{ {
list.map(item => ( list.map((item, index) => (
<p key={item}> <p key={index}>
{item} {item}
</p> </p>
)) ))
......
.Modal {
position: fixed;
top: 30%;
right: 40%;
width: 200px;
height: 50px;
border-radius: 10px;
border: 1px solid blueviolet;
background-color: blueviolet;
color: white;
display: flex;
align-items: center;
justify-content: center;
}
\ No newline at end of file
import './Modal.scss'
type TProps = {
show: boolean
}
const Modal = ({show}: TProps) => {
return (
<div className='Modal' style={{display: show ? 'flex' : 'none'}}>
Нужно ввести имя гостя!
</div>
)
}
export default Modal
\ No newline at end of file
...@@ -3,17 +3,49 @@ import List from "../components/List/List" ...@@ -3,17 +3,49 @@ import List from "../components/List/List"
import SendBtn from "../components/SendBtn/SendBtn" import SendBtn from "../components/SendBtn/SendBtn"
import GuestForm from "../components/GuestForm/GuestForm" import GuestForm from "../components/GuestForm/GuestForm"
import './App.scss' import './App.scss'
import Modal from "../components/Modal/Modal"
function App() { function App() {
const [guestList, setGuestList] = useState<string[]>(['John', 'Alibek', 'Tramp', 'Jose', 'Aida']) const [guestList, setGuestList] = useState<string[]>(['John', 'Alibek', 'Tramp', 'Jose', 'Aida'])
const [inComeList, setIncomeList] = useState<string[]>([]) const [inComeList, setIncomeList] = useState<string[]>([])
const [inpVal, setInpVal] = useState<string>('')
const [isModal, setIsModal] = useState<boolean>(false)
const onChangeHandler = (e: React.FormEvent<HTMLInputElement>) => {
setInpVal(e.currentTarget.value)
setIsModal(false)
}
const onSubmitHandler = (e: React.SyntheticEvent<HTMLFormElement>) => {
e.preventDefault()
if(inpVal === '') {
setIsModal(true)
} else {
setGuestList((prevState) => {
prevState.push(inpVal)
return prevState
})
}
}
const onClickHandler = () => {
const copyGuestList = guestList
const randomList = copyGuestList.filter(item => {
const random = Math.floor(Math.random() * 100)
if(random > 50) return item
})
setIncomeList(randomList)
}
return ( return (
<div className="App"> <div className="App">
<Modal show={isModal}/>
<div className="Lists"> <div className="Lists">
<List <List
title="Список основных гостей" title="Список основных гостей"
list={guestList} list={guestList.reverse()}
/> />
<List <List
title="Список приглашенных гостей" title="Список приглашенных гостей"
...@@ -22,8 +54,12 @@ function App() { ...@@ -22,8 +54,12 @@ function App() {
</div> </div>
<div className="Controllers"> <div className="Controllers">
<GuestForm/> <GuestForm
<SendBtn onClick={() => {}}/> onChange={onChangeHandler}
onSubmit={onSubmitHandler}
value={inpVal}
/>
<SendBtn onClick={onClickHandler}/>
</div> </div>
</div> </div>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment