Skip to content

Commit 0b92ccb

Browse files
fix: Special sidebar behaviour for pages without sidebar
1 parent d585a99 commit 0b92ccb

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

components/Sidebar.tsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@ const DocLink = ({
1616
label,
1717
onClick,
1818
setOpen,
19+
matchPaths,
1920
}: {
2021
uri: string;
2122
label: string | React.ReactNode;
2223
onClick?: () => void;
2324
setOpen: (open: boolean) => void;
25+
matchPaths?: string[];
2426
}) => {
2527
const router = useRouter();
2628
const url = new URL(`${router.asPath}`, HOST);
2729
url.search = '';
2830
url.hash = '';
2931
const stringUrl = url.toString().substr(HOST.length, Infinity);
30-
const isActive = uri === extractPathWithoutFragment(stringUrl);
32+
const path = extractPathWithoutFragment(stringUrl);
33+
const isActive = matchPaths ? matchPaths.includes(path) : uri === path;
3134
return (
3235
<Link
3336
href={uri}
@@ -163,6 +166,13 @@ const getReferencePath = [
163166
'/understanding-json-schema/reference/generic',
164167
'/understanding-json-schema/reference',
165168
];
169+
const getReleaseNotesDraftPath = [
170+
'/specification/release-notes',
171+
'/draft/2020-12/release-notes',
172+
'/draft/2019-09/release-notes',
173+
'/draft-07/json-schema-release-notes',
174+
'/draft-06/json-schema-release-notes',
175+
];
166176
const getSpecificationPath = [
167177
'/draft/2020-12',
168178
'/draft/2019-09',
@@ -175,6 +185,10 @@ const getSpecificationPath = [
175185
'/specification/json-hyper-schema',
176186
'/specification',
177187
'/specification-links',
188+
'/draft/2020-12/release-notes',
189+
'/draft/2019-09/release-notes',
190+
'/draft-07/json-schema-release-notes',
191+
'/draft-06/json-schema-release-notes',
178192
];
179193

180194
export const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
@@ -184,6 +198,8 @@ export const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
184198
const handleRotate = () => setRotateChevron(!rotateChevron);
185199
const rotate = rotateChevron ? 'rotate(180deg)' : 'rotate(0)';
186200
const pathWtihoutFragment = extractPathWithoutFragment(router.asPath);
201+
const shouldHideSidebar = pathWtihoutFragment === '/md-style-guide';
202+
187203
useEffect(() => {
188204
if (window) {
189205
window.addEventListener('resize', () => {
@@ -254,16 +270,20 @@ export const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
254270
</div>
255271
</div>
256272
<div className='dark:bg-slate-800 max-w-[1400px] grid grid-cols-1 lg:grid-cols-4 mx-4 md:mx-12'>
257-
<div className='hidden lg:block mt-24 sticky top-24 h-[calc(100vh-6rem)] overflow-hidden'>
258-
<div className='h-full overflow-y-auto scrollbar-hidden'>
259-
<DocsNav open={open} setOpen={setOpen} />
260-
<CarbonAds
261-
className='lg:mt-8 w-4/5 mx-auto lg:ml-4'
262-
variant='sidebar'
263-
/>
273+
{!shouldHideSidebar && (
274+
<div className='hidden lg:block mt-24 sticky top-24 h-[calc(100vh-6rem)] overflow-hidden'>
275+
<div className='h-full overflow-y-auto scrollbar-hidden'>
276+
<DocsNav open={open} setOpen={setOpen} />
277+
<CarbonAds
278+
className='lg:mt-8 w-4/5 mx-auto lg:ml-4'
279+
variant='sidebar'
280+
/>
281+
</div>
264282
</div>
265-
</div>
266-
<div className='col-span-4 md:col-span-3 lg:mt-20 lg:w-5/6 mx-4 md:mx-0'>
283+
)}
284+
<div
285+
className={`lg:mt-20 mx-4 md:mx-0 ${shouldHideSidebar ? 'col-span-4 w-full' : 'col-span-4 md:col-span-3 lg:w-5/6'}`}
286+
>
267287
{children}
268288
</div>
269289
</div>
@@ -902,6 +922,7 @@ export const DocsNav = ({
902922
uri='/specification/release-notes'
903923
label='Release notes'
904924
setOpen={setOpen}
925+
matchPaths={getReleaseNotesDraftPath}
905926
/>
906927
<DocLink
907928
uri='/specification/json-hyper-schema'

0 commit comments

Comments
 (0)