-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskList.tsx
More file actions
53 lines (49 loc) · 1.56 KB
/
TaskList.tsx
File metadata and controls
53 lines (49 loc) · 1.56 KB
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
import React, { HTMLAttributes } from "react";
import { TaskListItemProps, TaskListProps } from "./TaskList.types";
import { LinkWithRef } from "../LinkWithRef";
import { Tag } from "../Tag";
import { Hint } from "../Hint";
const TaskList: React.FC<TaskListProps & HTMLAttributes<HTMLUListElement>> = (
props,
) => {
const { className, idPrefix, items, ...attributes } = props;
const renderTaskListItem = (item: TaskListItemProps, index: number) => {
if (!item) return null;
const { title, hint, status, href, ...attributes } = item;
const itemId: string = `${idPrefix}-${index + 1}`;
return (
<li
key={itemId}
id={itemId}
className="govuk-task-list__item govuk-task-list__item--with-link"
{...attributes}
>
<div className="govuk-task-list__name-and-hint">
<LinkWithRef
className="govuk-link govuk-task-list__link"
href={href}
aria-describedby={`${itemId}-status`}
>
{title.children}
</LinkWithRef>
{hint ? (
<Hint
id={`${itemId}-hint`}
className="govuk-task-list__hint"
{...hint}
/>
) : null}
</div>
<div className="govuk-task-list__status" id={`${itemId}-status`}>
{status.tag ? <Tag {...status.tag} /> : status.children}
</div>
</li>
);
};
return (
<ul className={`govuk-task-list ${className || ""}`} {...attributes}>
{items.map(renderTaskListItem)}
</ul>
);
};
export default TaskList;