-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
1 parent
0c7835a
commit 42ba2cc
Showing
7 changed files
with
119 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint-disable jsx-a11y/label-has-associated-control */ | ||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
|
||
interface Props { | ||
id: number; | ||
title: string; | ||
editableTitle: string; | ||
isTodoChecked: boolean; | ||
editableTodoById: number; | ||
todoInputRef: React.MutableRefObject<HTMLInputElement | null>; | ||
setEditableTitle: (value: string) => void; | ||
editHandler: (id: number, title: string) => void; | ||
deleteHandler: (ids: number[]) => void; | ||
toogleHandler: (id: number) => void; | ||
onSubmit: (event: React.FormEvent, id: number) => void; | ||
} | ||
|
||
export const TodoItem: React.FC<Props> = React.memo( | ||
({ | ||
id, | ||
title, | ||
editableTitle, | ||
editableTodoById, | ||
isTodoChecked, | ||
todoInputRef, | ||
setEditableTitle, | ||
editHandler, | ||
deleteHandler, | ||
toogleHandler, | ||
onSubmit, | ||
}) => { | ||
return ( | ||
<div | ||
data-cy="Todo" | ||
className={classNames('todo', { completed: isTodoChecked })} | ||
> | ||
<label className="todo__status-label"> | ||
<input | ||
data-cy="TodoStatus" | ||
type="checkbox" | ||
className="todo__status" | ||
onChange={() => toogleHandler(id)} | ||
checked={isTodoChecked} | ||
/> | ||
</label> | ||
|
||
{editableTodoById === id ? ( | ||
<form onSubmit={event => onSubmit(event, id)}> | ||
<input | ||
ref={todoInputRef} | ||
onBlur={event => onSubmit(event, id)} | ||
data-cy="TodoTitleField" | ||
type="text" | ||
className="todo__title-field" | ||
placeholder="Empty todo will be deleted" | ||
value={editableTitle} | ||
onChange={event => setEditableTitle(event.target.value)} | ||
/> | ||
</form> | ||
) : ( | ||
<span | ||
data-cy="TodoTitle" | ||
className="todo__title" | ||
onDoubleClick={() => editHandler(id, title)} | ||
> | ||
{title || 'Todo is being saved now'} | ||
</span> | ||
)} | ||
|
||
{editableTodoById !== id && ( | ||
<button | ||
type="button" | ||
className="todo__remove" | ||
data-cy="TodoDelete" | ||
onClick={() => deleteHandler([id])} | ||
> | ||
× | ||
</button> | ||
)} | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
TodoItem.displayName = 'TodoItem'; |
Empty file.
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.