-
Notifications
You must be signed in to change notification settings - Fork 14
/
_app.tsx
157 lines (146 loc) · 5.19 KB
/
_app.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { ReactElement, ReactNode, useMemo, useState } from "react";
import type { NextPage } from "next";
import type { AppProps } from "next/app";
import Head from "next/head";
import styled from "styled-components";
import {
DxcApplicationLayout,
DxcTextInput,
HalstackProvider,
} from "@dxc-technology/halstack-react";
import "../global-styles.css";
import { responsiveSizes } from "../screens/common/variables";
import SidenavLogo from "@/common/sidenav/SidenavLogo";
import { useRouter } from "next/router";
import {
LinksSectionDetails,
LinksSections,
themeGeneratorLinks,
} from "@/common/pagesList";
import Link from "next/link";
import StatusTag from "@/common/StatusTag";
type NextPageWithLayout = NextPage & {
getLayout?: (page: ReactElement) => ReactNode;
};
type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};
type ApplicationLayoutWrapperProps = {
condition: boolean;
wrapper: (children: React.ReactNode) => JSX.Element;
children: ReactNode;
};
const ApplicationLayoutWrapper = ({
condition,
wrapper,
children,
}: ApplicationLayoutWrapperProps): JSX.Element => (
<>{condition ? wrapper(children) : children}</>
);
const MyApp = ({ Component, pageProps }: AppPropsWithLayout) => {
const getLayout = Component.getLayout || ((page) => page);
const componentWithLayout = getLayout(<Component {...pageProps} />);
const [filter, setFilter] = useState("");
const { asPath: currentPath } = useRouter();
const filteredLinks = useMemo(() => {
const filtered: LinksSectionDetails[] = [];
LinksSections.map((section) => {
const sectionFilteredLinks = section?.links.filter((link) =>
link.label.toLowerCase().includes(filter.toLowerCase())
);
if (sectionFilteredLinks.length) {
filtered.push({ label: section.label, links: sectionFilteredLinks });
}
});
return filtered;
}, [filter]);
const onFilterInputChange = ({ value }: { value: string }) => {
setFilter(value);
};
const matchPaths = (linkPath: string) => {
const pathToBeMatched = currentPath.split("#")[0].slice(0, -1);
const desiredPaths = [
linkPath,
`${linkPath}/specifications`,
`${linkPath}/usage`,
];
return desiredPaths.includes(pathToBeMatched);
};
return (
<>
<Head>
<link rel="icon" type="image/png" sizes="32x32" href="/favicon.png" />
</Head>
<HalstackProvider>
<ApplicationLayoutWrapper
condition={!themeGeneratorLinks.includes(currentPath)}
wrapper={(children) => (
<DxcApplicationLayout
visibilityToggleLabel="Menu"
sidenav={
<DxcApplicationLayout.SideNav title={<SidenavLogo />}>
<DxcApplicationLayout.SideNav.Section>
<DxcTextInput
placeholder="Search docs"
value={filter}
onChange={onFilterInputChange}
size="fillParent"
clearable
margin={{
top: "small",
bottom: "small",
right: "xsmall",
left: "xsmall",
}}
/>
</DxcApplicationLayout.SideNav.Section>
{filteredLinks?.map(({ label, links }) => (
<DxcApplicationLayout.SideNav.Section key={label}>
<DxcApplicationLayout.SideNav.Group title={label}>
{links.map(({ label, path, status }) => (
<Link key={`${label}-${path}`} href={path} passHref>
<DxcApplicationLayout.SideNav.Link
selected={matchPaths(path)}
>
{label}
{status !== "Ready" && (
<StatusTag status={status}>{status}</StatusTag>
)}
</DxcApplicationLayout.SideNav.Link>
</Link>
))}
</DxcApplicationLayout.SideNav.Group>
</DxcApplicationLayout.SideNav.Section>
))}
<DxcApplicationLayout.SideNav.Section>
<DxcApplicationLayout.SideNav.Link
href="https://github.com/dxc-technology/halstack-react"
newWindow
>
GitHub
</DxcApplicationLayout.SideNav.Link>
</DxcApplicationLayout.SideNav.Section>
</DxcApplicationLayout.SideNav>
}
>
<DxcApplicationLayout.Main>
<MainContainer>{children}</MainContainer>
</DxcApplicationLayout.Main>
</DxcApplicationLayout>
)}
>
{componentWithLayout}
</ApplicationLayoutWrapper>
</HalstackProvider>
</>
);
};
const MainContainer = styled.div`
margin: 80px 0;
max-width: 1124px;
margin-inline: max(5%, 50% - 1124px/2);
@media (max-width: ${responsiveSizes.laptop}px) {
margin: 80px 32px;
}
`;
export default MyApp;