-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
781fa94
commit 686d85e
Showing
3 changed files
with
154 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* eslint-disable jsx-a11y/label-has-associated-control */ | ||
import classNames from 'classnames'; | ||
|
||
type Props = { | ||
tempTodo: string; | ||
}; | ||
|
||
export const TempTodoItem: React.FC<Props> = ({ tempTodo }) => { | ||
return ( | ||
<div data-cy="Todo" className="todo"> | ||
<label className="todo__status-label"> | ||
<input data-cy="TodoStatus" type="checkbox" className="todo__status" /> | ||
</label> | ||
|
||
<span data-cy="TodoTitle" className="todo__title"> | ||
{tempTodo} | ||
</span> | ||
|
||
{/* Remove button appears only on hover */} | ||
<button type="button" className="todo__remove" data-cy="TodoDelete"> | ||
x | ||
</button> | ||
|
||
{/* overlay will cover the todo while it is being deleted or updated */} | ||
<div data-cy="TodoLoader" className="modal overlay is-active"> | ||
<div | ||
className={classNames('modal-background', 'has-background-white-ter')} | ||
/> | ||
<div className="loader" /> | ||
</div> | ||
</div> | ||
); | ||
}; |
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,100 @@ | ||
/* eslint-disable jsx-a11y/label-has-associated-control */ | ||
import classNames from 'classnames'; | ||
import { Todo } from '../types/Todo'; | ||
import { FormEditingTitle } from './FormEditingTitle'; | ||
|
||
type Props = { | ||
todo: Todo; | ||
changeTodo: (todo: Todo) => void; | ||
updatingAndDeletingCompletedTodos: Todo[] | []; | ||
setUpdatingAndDeletingCompletedTodos: ( | ||
deletingCompletedTodos: Todo[] | [], | ||
) => void; | ||
editingTitle: number; | ||
setEditingTitle: (editingTitle: number) => void; | ||
titleEdit: string; | ||
setTitleEdit: (titleEdit: string) => void; | ||
handleChangeSubmit: (todo: Todo) => void; | ||
deleteTodo: (todo: Todo) => void; | ||
}; | ||
|
||
export const TodoItem: React.FC<Props> = ({ | ||
todo, | ||
changeTodo, | ||
updatingAndDeletingCompletedTodos, | ||
setUpdatingAndDeletingCompletedTodos, | ||
editingTitle, | ||
setEditingTitle, | ||
titleEdit, | ||
setTitleEdit, | ||
handleChangeSubmit, | ||
deleteTodo, | ||
}) => { | ||
const { id, completed, title } = todo; | ||
|
||
return ( | ||
<div | ||
data-cy="Todo" | ||
className={classNames('todo', { completed: completed })} | ||
> | ||
<label className="todo__status-label"> | ||
<input | ||
data-cy="TodoStatus" | ||
type="checkbox" | ||
className="todo__status" | ||
checked={completed} | ||
onClick={() => { | ||
changeTodo({ ...todo, completed: !completed }); | ||
setUpdatingAndDeletingCompletedTodos([todo]); | ||
}} | ||
/> | ||
</label> | ||
|
||
{editingTitle === id ? ( | ||
<FormEditingTitle | ||
todo={todo} | ||
titleEdit={titleEdit} | ||
setTitleEdit={setTitleEdit} | ||
handleChangeSubmit={handleChangeSubmit} | ||
setEditingTitle={setEditingTitle} | ||
/> | ||
) : ( | ||
<> | ||
<span | ||
data-cy="TodoTitle" | ||
className="todo__title" | ||
onDoubleClick={() => { | ||
setEditingTitle(id); | ||
setTitleEdit(title); | ||
}} | ||
> | ||
{title} | ||
</span> | ||
|
||
<button | ||
type="button" | ||
className="todo__remove" | ||
data-cy="TodoDelete" | ||
onClick={() => deleteTodo(todo)} | ||
> | ||
x | ||
</button> | ||
</> | ||
)} | ||
|
||
<div | ||
data-cy="TodoLoader" | ||
className={classNames('modal', 'overlay', { | ||
'is-active': updatingAndDeletingCompletedTodos?.some( | ||
task => task.id === todo.id, | ||
), | ||
})} | ||
> | ||
<div | ||
className={classNames('modal-background', 'has-background-white-ter')} | ||
/> | ||
<div className="loader" /> | ||
</div> | ||
</div> | ||
); | ||
}; |
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