Skip to content

Commit

Permalink
Smooth scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenramthun committed Nov 21, 2024
1 parent b22e4ff commit de2516e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions components/openapi/OpenApiView.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@

.operationAnchor:hover:after {
opacity: 1;
}

.scrollAnchor {
display: block;
position: relative;
top: calc(var(--a-spacing-16) * -1);
}
6 changes: 5 additions & 1 deletion components/openapi/OpenApiView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ export const OpenApiView: React.FC = () => {
size="medium"
>
{pathItem.summary}
<a
id={pathItem.operationId}
className={styles.scrollAnchor}
/>
</Heading>
<div id={pathItem.operationId} className={styles.path}>
<div className={styles.path}>
<Tag
className={styles.method}
type={calloutTypeForMethod(method)}
Expand Down
5 changes: 2 additions & 3 deletions lib/openapi/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useData } from "nextra/hooks"
import { OpenApiObjectSchema } from "@/lib/openapi/schema"
import { OpenApiDoc } from "@/lib/openapi/types"
import { useMemo } from "react"

export const useOpenApiDoc = (): OpenApiDoc => {
const { spec } = useData()
import spec from "./openapi.yml"

export const useOpenApiDoc = (): OpenApiDoc => {
return useMemo(() => OpenApiObjectSchema.parse(spec) as OpenApiDoc, [spec])
}
4 changes: 4 additions & 0 deletions pages/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
margin: 0;
}

html {
scroll-behavior: smooth;
}

body {
line-height: 1.5;
-webkit-font-smoothing: antialiased;
Expand Down

0 comments on commit de2516e

Please sign in to comment.