Skip to content

Commit

Permalink
Merge pull request #53 from AirWalk-Digital/beta-scroll-location
Browse files Browse the repository at this point in the history
fix(scroll location): scroll to anchor works
  • Loading branch information
rob-at-airwalk authored Jul 9, 2024
2 parents b36dd89 + 94d9149 commit b7003e2
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
3 changes: 2 additions & 1 deletion src/_components/Layouts/ContentLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React from 'react';
import components from '@/components/Layouts/lib/mdxComponents';
import type { ContentItem } from '@/lib/Types';

import { topBarHeight } from './constants';
import { loadMDX } from './lib/loadMDX';
// import { mdComponents } from '../../constants/mdxProvider.js';

Expand All @@ -21,7 +22,7 @@ function ContentSkeleton() {
return (
<div
style={{
marginTop: 64,
marginTop: topBarHeight,
paddingLeft: 0,
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/_components/Layouts/ContentPrint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function ContentPrint({ children }: PagedOutputProps) {
const currentPath = usePathname();

function handleClose() {
const pathnameArray = currentPath.split('/');
const pathnameArray = currentPath?.split('/') ?? [];

// Replace 'print' with 'view' in the URL path
pathnameArray[2] = 'view';
Expand Down
7 changes: 3 additions & 4 deletions src/_components/Layouts/ContentViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ContentMenu, TableOfContents } from '@/components/Menus';
import { getLogger } from '@/lib/Logger';
import type { ContentItem, RelatedContent } from '@/lib/Types';

import { topBarHeight } from './constants';
import { loadMDX } from './lib/loadMDX';
// import { mdComponents } from '../../constants/mdxProvider.js';
const logger = getLogger().child({ namespace: 'ContentViewer' });
Expand All @@ -42,7 +43,7 @@ interface ContentViewerProps {
relatedContent: RelatedContent;
}

function ContentSkeleton({ topBarHeight }: { topBarHeight: number }) {
function ContentSkeleton() {
return (
<div
style={{
Expand All @@ -63,8 +64,6 @@ export function ContentViewer({
loading,
relatedContent,
}: ContentViewerProps) {
const topBarHeight = 64;

logger.info({
msg: 'ContentViewer',
pageContent,
Expand Down Expand Up @@ -114,7 +113,7 @@ export function ContentViewer({
}

if (loading) {
return <ContentSkeleton topBarHeight={topBarHeight} />;
return <ContentSkeleton />;
}
if (pageContent) {
let frontmatter;
Expand Down
3 changes: 2 additions & 1 deletion src/_components/Layouts/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import { usePathname, useRouter } from 'next/navigation';
import React, { useState } from 'react';

import { siteConfig } from '../../../site.config';
import { topBarHeight } from './constants';
// import logo from '../../public/logos/airwalk-logo.png';
const Logo = styled('img')({
display: 'block',
width: 'auto',
height: 64,
height: topBarHeight,
});

export interface ComponentProps {
Expand Down
1 change: 1 addition & 0 deletions src/_components/Layouts/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const topBarHeight = 64;
2 changes: 0 additions & 2 deletions src/_components/Layouts/lib/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'react-toastify/dist/ReactToastify.css';

import ContentCopyIcon from '@mui/icons-material/ContentCopy';
import { Alert, IconButton, Snackbar } from '@mui/material';
import * as React from 'react';
Expand Down
16 changes: 16 additions & 0 deletions src/_components/Layouts/lib/mdxComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { ContentItem } from '@/lib/Types';
import { palette } from '@/styles/baseTheme';
import { getContrastYIQ } from '@/styles/lib/colors';

import { topBarHeight } from '../constants';
import { CopyButton } from './CopyButton';

// const StatRoot = styled('table', {
Expand Down Expand Up @@ -60,6 +61,21 @@ const components = (baseContext: ContentItem) => ({
table: (props: any) => <Table>{props.children}</Table>,
pre: (props: any) => props.children,
img: (props: any) => <MdxImage props={props} baseContext={baseContext} />,
h2: (props: any) => (
<h2 id={props.id} style={{ scrollMarginTop: topBarHeight }}>
{props.children}
</h2>
),
h3: (props: any) => (
<h3 id={props.id} style={{ scrollMarginTop: topBarHeight }}>
{props.children}
</h3>
),
h4: (props: any) => (
<h4 id={props.id} style={{ scrollMarginTop: topBarHeight }}>
{props.children}
</h4>
),
code: (props: any) => {
const { className } = props;
const language = className?.replace('language-', '');
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const metadata = {

export default function RootLayout(props: { children: React.ReactNode }) {
return (
<html lang='en'>
<html lang='en' style={{ scrollBehavior: 'smooth' }}>
<body>
<AppRouterCacheProvider options={{ enableCssLayer: true }}>
<ThemeProvider theme={baseTheme}>
Expand Down

0 comments on commit b7003e2

Please sign in to comment.