-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task.tsx
59 lines (49 loc) · 1.55 KB
/
Task.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {Check, Trash} from 'phosphor-react';
import {useTranslation} from 'react-i18next';
import {TaskType} from '../../hooks/useTaskList';
import styles from './Task.module.css';
type Props = {
task: TaskType;
toggleCheckTask: (taskId: string) => void;
deleteTask: (taskId: string) => void;
};
export function Task({task, toggleCheckTask, deleteTask}: Props) {
const {t} = useTranslation();
const checkboxClassName = `${styles.checkbox} ${
task.isCompleted ? styles.checkboxChecked : styles.checkboxUnchecked
}`;
const descriptionClassName = `${styles.description} ${
task.isCompleted ? styles.descriptionChecked : ''
}`;
function handleToggleCheckTask() {
toggleCheckTask(task.id);
}
function handleDeleteTask() {
deleteTask(task.id);
}
return (
<li className={styles.container} role="listitem">
<button
className={checkboxClassName}
type="button"
title={task.isCompleted ? t('task.uncheckTask') : t('task.checkTask')}
aria-label={
task.isCompleted ? t('task.uncheckTask') : t('task.checkTask')
}
onClick={handleToggleCheckTask}
>
{task.isCompleted ? <Check size={12} weight="bold" /> : null}
</button>
<p className={descriptionClassName}>{task.description}</p>
<button
className={styles.trashButton}
type="button"
title={t('task.deleteTask')}
aria-label={t('task.deleteTask')}
onClick={handleDeleteTask}
>
<Trash size={16} weight="bold" />
</button>
</li>
);
}