forked from boa-dev/boa-dev.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnav.tsx
More file actions
215 lines (192 loc) · 5.55 KB
/
nav.tsx
File metadata and controls
215 lines (192 loc) · 5.55 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import React from "react";
import { ConformanceState, FilterOption } from "../types";
import styles from "./styles.module.css";
import Link from "@docusaurus/Link";
import Heading from "@theme/Heading";
import { availableSortingOptions } from "../utils";
type ResultsNavProps = {
state: ConformanceState;
editions: string[];
sliceNavToIndex: (number) => void;
setEcmaScriptFlag: (string) => void;
setSortOption: (string) => void;
setFilterOption: (string) => void;
};
export default function ResultNavigation(
props: ResultsNavProps,
): React.ReactNode {
return (
<div className={styles.resultsNav}>
<div className={styles.navSection}>
<EcmaScriptVersionDropdown
editions={props.editions}
setEcmaScriptFlag={props.setEcmaScriptFlag}
esVersionValue={props.state.ecmaScriptVersion}
/>
<SortingDropdown
sortValue={props.state.sortOption}
setSortOption={props.setSortOption}
/>
<FilterDropdown
filterOption={props.state.filterOption}
setFilterOption={props.setFilterOption}
/>
</div>
<div className={styles.navSection}>
<NavBreadCrumbs
navPath={props.state.testPath}
sliceNavToIndex={props.sliceNavToIndex}
/>
</div>
</div>
);
}
type BreadCrumbProps = {
navPath: string[];
sliceNavToIndex: (number) => void;
};
function NavBreadCrumbs(props: BreadCrumbProps) {
return (
<nav aria-label="breadcrumbs" style={{ padding: "0.5em" }}>
<ul className="breadcrumbs">
{props.navPath.map((pathItem, idx, arr) => {
return (
<BreadCrumbItem
key={pathItem}
itemName={pathItem}
index={idx}
sliceNavToIndex={props.sliceNavToIndex}
breadcrumbValue={
idx + 1 === arr.length
? "breadcrumbs__item breadcrumbs__item--active"
: "breadcrumbs__item"
}
/>
);
})}
</ul>
</nav>
);
}
type BreadCrumbItemProps = {
itemName: string;
index: number;
breadcrumbValue: string;
sliceNavToIndex: (number) => void;
};
function BreadCrumbItem(props: BreadCrumbItemProps): React.ReactNode {
return (
<li className={props.breadcrumbValue}>
<Link
className={styles.navLink}
onClick={() => props.sliceNavToIndex(props.index + 1)}
>
{props.itemName}
</Link>
</li>
);
}
// Below implements the ECMAScript Version Dropdown component
type DropDownProps = {
esVersionValue: string;
editions: string[];
setEcmaScriptFlag: (string) => void;
};
function EcmaScriptVersionDropdown(props: DropDownProps): React.ReactNode {
const [dropdownValue, setDropdownValue] = React.useState(
props.esVersionValue ? props.esVersionValue : "",
);
// Update the flag when props.esVersionValue is changed
React.useEffect(() => {
setDropdownValue(props.esVersionValue);
}, [props.esVersionValue]);
const handleVersionSelection = (e) => {
// Update the display value and set the flag.
setDropdownValue(e.target.value);
props.setEcmaScriptFlag(e.target.value);
};
return (
<div className={styles.dropdownContainer}>
<Heading as="h4" style={{ padding: "0.125rem 0.5rem", height: "5" }}>
ES Version:
</Heading>
<select value={dropdownValue} onChange={handleVersionSelection}>
<option value={""}>All</option>
{props.editions.map((edition) => {
return (
<option key={edition} value={edition}>
{edition}
</option>
);
})}
</select>
</div>
);
}
type SortProps = {
sortValue: string;
setSortOption: (string) => void;
};
function SortingDropdown(props: SortProps): React.ReactNode {
const [sortValue, setSortValue] = React.useState<string>(
props.sortValue ? props.sortValue : "alpha",
);
React.useEffect(() => {
setSortValue(props.sortValue);
}, [props.sortValue]);
const handleSortSelection = (e) => {
setSortValue(e.target.value);
const option = availableSortingOptions.filter(
(v) => v.id === e.target.value,
);
props.setSortOption(option[0].id);
};
return (
<div className={styles.dropdownContainer}>
<Heading as="h4" style={{ padding: "0.125rem 0.5rem", height: "5" }}>
Sort:
</Heading>
<select value={sortValue} onChange={handleSortSelection}>
{availableSortingOptions.map((key) => {
return (
<option key={key.id} value={key.id}>
{key.name}
</option>
);
})}
</select>
</div>
);
}
type FilterProps = {
filterOption: FilterOption;
setFilterOption: (string) => void;
};
function FilterDropdown(props: FilterProps): React.ReactNode {
const [filterValue, setFilterValue] = React.useState<string>(
props.filterOption ?? FilterOption.None,
);
React.useEffect(() => {
setFilterValue(props.filterOption);
}, [props.filterOption]);
const handlefilterSelection = (e) => {
setFilterValue(e.target.value);
props.setFilterOption(e.target.value);
};
return (
<div className={styles.dropdownContainer}>
<Heading as="h4" style={{ padding: "0.125rem 0.5rem", height: "5" }}>
Filter:
</Heading>
<select value={filterValue} onChange={handlefilterSelection}>
{Object.values(FilterOption).map((key) => {
return (
<option key={key} value={key}>
{key}
</option>
);
})}
</select>
</div>
);
}