From b4855825be39be5c647bbd3b90c473240fabe04d Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 21 Oct 2024 09:54:05 +0300 Subject: [PATCH] docs: fix scroll + divider issues (#9663) --- .../components/Section/Container/index.tsx | 4 ++- .../components/Tags/Operation/index.tsx | 2 +- .../components/Tags/Section/index.tsx | 5 +-- .../api-reference/layouts/Divided/index.tsx | 20 ++++++------ .../src/components/Heading/H2/index.tsx | 32 +++++++++++++++---- .../src/components/Heading/H3/index.tsx | 32 +++++++++++++++---- .../hooks/use-page-scroll-manager/index.tsx | 4 +-- .../docs-ui/src/layouts/main-content.tsx | 2 +- 8 files changed, 73 insertions(+), 28 deletions(-) diff --git a/www/apps/api-reference/components/Section/Container/index.tsx b/www/apps/api-reference/components/Section/Container/index.tsx index 83bb64b349..9de1251bed 100644 --- a/www/apps/api-reference/components/Section/Container/index.tsx +++ b/www/apps/api-reference/components/Section/Container/index.tsx @@ -19,7 +19,9 @@ const SectionContainer = forwardRef( ref={ref} > {children} - {!noDivider && } + {!noDivider && ( + + )} ) } diff --git a/www/apps/api-reference/components/Tags/Operation/index.tsx b/www/apps/api-reference/components/Tags/Operation/index.tsx index ec014f383d..2b4a4ed05f 100644 --- a/www/apps/api-reference/components/Tags/Operation/index.tsx +++ b/www/apps/api-reference/components/Tags/Operation/index.tsx @@ -134,7 +134,7 @@ const TagOperation = ({ } /> - + ) } diff --git a/www/apps/api-reference/components/Tags/Section/index.tsx b/www/apps/api-reference/components/Tags/Section/index.tsx index 2c318afc62..291c4b5dd0 100644 --- a/www/apps/api-reference/components/Tags/Section/index.tsx +++ b/www/apps/api-reference/components/Tags/Section/index.tsx @@ -123,7 +123,7 @@ const TagSection = ({ tag }: TagSectionProps) => { +

{tag.name}

{tag.description && (
@@ -154,6 +154,7 @@ const TagSection = ({ tag }: TagSectionProps) => { vertical question="Was this section helpful?" /> + } codeContent={<>} @@ -166,7 +167,7 @@ const TagSection = ({ tag }: TagSectionProps) => { )} - {!loadPaths && } + {!loadPaths && } ) } diff --git a/www/apps/api-reference/layouts/Divided/index.tsx b/www/apps/api-reference/layouts/Divided/index.tsx index a66ec4dd6d..5152ab0a65 100644 --- a/www/apps/api-reference/layouts/Divided/index.tsx +++ b/www/apps/api-reference/layouts/Divided/index.tsx @@ -39,15 +39,17 @@ const DividedLayout = forwardRef( > {mainContent} -
- {codeContent} -
+ {codeContent && ( +
+ {codeContent} +
+ )} ) } diff --git a/www/packages/docs-ui/src/components/Heading/H2/index.tsx b/www/packages/docs-ui/src/components/Heading/H2/index.tsx index 48eda599ef..e285c0afea 100644 --- a/www/packages/docs-ui/src/components/Heading/H2/index.tsx +++ b/www/packages/docs-ui/src/components/Heading/H2/index.tsx @@ -1,6 +1,9 @@ +"use client" + import clsx from "clsx" -import React from "react" -import { Link } from "@/components" +import React, { useMemo } from "react" +import { CopyButton, Link } from "@/components" +import { useIsBrowser } from "../../../providers" type H2Props = React.HTMLAttributes & { id?: string @@ -8,6 +11,21 @@ type H2Props = React.HTMLAttributes & { } export const H2 = ({ className, children, passRef, ...props }: H2Props) => { + const { isBrowser } = useIsBrowser() + const copyText = useMemo(() => { + const url = `#${props.id}` + if (!isBrowser) { + return url + } + + const hashIndex = window.location.href.indexOf("#") + return ( + window.location.href.substring( + 0, + hashIndex !== -1 ? hashIndex : window.location.href.length + ) + url + ) + }, [props.id, isBrowser]) return (

{ > {children} {props.id && ( - - # - + + # + + )}

) diff --git a/www/packages/docs-ui/src/components/Heading/H3/index.tsx b/www/packages/docs-ui/src/components/Heading/H3/index.tsx index 5e2c3ba751..36b3e005ca 100644 --- a/www/packages/docs-ui/src/components/Heading/H3/index.tsx +++ b/www/packages/docs-ui/src/components/Heading/H3/index.tsx @@ -1,12 +1,30 @@ +"use client" + import clsx from "clsx" -import React from "react" -import { Link } from "@/components" +import React, { useMemo } from "react" +import { CopyButton, Link } from "@/components" +import { useIsBrowser } from "../../../providers" type H3Props = React.HTMLAttributes & { id?: string } export const H3 = ({ className, children, ...props }: H3Props) => { + const { isBrowser } = useIsBrowser() + const copyText = useMemo(() => { + const url = `#${props.id}` + if (!isBrowser) { + return url + } + + const hashIndex = window.location.href.indexOf("#") + return ( + window.location.href.substring( + 0, + hashIndex !== -1 ? hashIndex : window.location.href.length + ) + url + ) + }, [props.id, isBrowser]) return (

{ > {children} {props.id && ( - - # - + + # + + )}

) diff --git a/www/packages/docs-ui/src/hooks/use-page-scroll-manager/index.tsx b/www/packages/docs-ui/src/hooks/use-page-scroll-manager/index.tsx index 317d957fd0..ea3e600eb4 100644 --- a/www/packages/docs-ui/src/hooks/use-page-scroll-manager/index.tsx +++ b/www/packages/docs-ui/src/hooks/use-page-scroll-manager/index.tsx @@ -36,7 +36,7 @@ export const usePageScrollManager = () => { targetElm?.scrollIntoView() } - }, [pathname, scrollableElement]) + }, [pathname, scrollableElement, checkedPageReload]) useEffect(() => { if (!scrollableElement || checkedPageReload) { @@ -71,5 +71,5 @@ export const usePageScrollManager = () => { ) } }) - }, [scrollableElement]) + }, [scrollableElement, checkedPageReload]) } diff --git a/www/packages/docs-ui/src/layouts/main-content.tsx b/www/packages/docs-ui/src/layouts/main-content.tsx index 290986e530..034901373d 100644 --- a/www/packages/docs-ui/src/layouts/main-content.tsx +++ b/www/packages/docs-ui/src/layouts/main-content.tsx @@ -38,7 +38,7 @@ export const MainContentLayout = ({ "relative max-w-full", "h-full flex-1", "flex flex-col", - "gap-docs_0.5 lg:pt-docs_0.25 lg:mr-docs_0.25", + "gap-docs_0.5 lg:pt-docs_0.25 lg:mr-docs_0.25 scroll-m-docs_0.25", !desktopSidebarOpen && "lg:ml-docs_0.25", mainWrapperClasses )}