-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServiceNavigation.tsx
More file actions
107 lines (103 loc) · 3.53 KB
/
ServiceNavigation.tsx
File metadata and controls
107 lines (103 loc) · 3.53 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React, { HTMLAttributes } from "react";
import { ServiceNavigationProps } from "./ServiceNavigation.types";
import { LinkWithRef } from "../LinkWithRef";
const ServiceNavigation: React.FC<
ServiceNavigationProps & HTMLAttributes<HTMLDivElement>
> = (props) => {
const {
className,
containerClassName = "govuk-width-container",
menuButtonLabel = "Show or hide menu",
navigation,
navigationClassName,
navigationLabel = "Menu",
serviceName,
serviceUrlHref,
serviceUrlTo,
...attributes
} = props;
return (
<section
aria-label="Service information"
className={`govuk-service-navigation ${className || ""}`}
data-module="govuk-service-navigation"
{...attributes}
>
<div className={`govuk-width-container ${containerClassName}`}>
<div className="govuk-service-navigation__container">
{serviceName ? (
<span className="govuk-service-navigation__service-name">
<LinkWithRef
href={serviceUrlHref}
to={serviceUrlTo}
className="govuk-header__link govuk-header__link--service-name"
>
{serviceName}
</LinkWithRef>
</span>
) : null}
{navigation ? (
<nav
aria-label={navigationLabel}
className={`govuk-service-navigation__wrapper ${
navigationClassName || ""
}`}
>
<button
type="button"
className="govuk-service-navigation__toggle govuk-js-service-navigation-toggle"
aria-controls="navigation"
aria-label={menuButtonLabel}
hidden
>
Menu
</button>
<ul className="govuk-service-navigation__list" id="navigation">
{navigation.map((item, index) => {
const {
active: itemActive,
className: itemClassName,
children: itemChildren,
reactListKey,
...itemAttributes
} = item;
return itemChildren ? (
<li
key={reactListKey || index}
className={`govuk-service-navigation__item${
itemActive
? " govuk-service-navigation__item--active"
: ""
}`}
>
{item.href || item.to ? (
<LinkWithRef
className={`govuk-service-navigation__link ${
itemClassName || ""
}`}
aria-current={itemActive ? "true" : "false"}
{...itemAttributes}
>
{itemActive ? (
<strong className="govuk-service-navigation__active-fallback">
{itemChildren}
</strong>
) : (
itemChildren
)}
</LinkWithRef>
) : (
itemChildren
)}
</li>
) : null;
})}
</ul>
</nav>
) : null}
</div>
</div>
</section>
);
};
export default ServiceNavigation;