Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: documentation re-renders #4349

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/docs/app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default async function DocPage({params}: DocPageProps) {
if (!doc) {
notFound();
}

const editUrl = `${GITHUB_URL}/${REPO_NAME}/edit/${TAG}${CONTENT_PATH}${currentRoute?.path}`;

return (
Expand Down
37 changes: 19 additions & 18 deletions apps/docs/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,27 @@ export interface ProvidersProps {
themeProps?: ThemeProviderProps;
}

export function Providers({children, themeProps}: ProvidersProps) {
const router = useRouter();

const ProviderWrapper = ({children}: {children: ReactNode}) => {
useEffect(() => {
if (typeof window !== "undefined" && __PROD__) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
api_host: "/ingest",
person_profiles: "identified_only",
ui_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
});
}
}, []);

if (__PROD__) {
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
const ProviderWrapper = ({children}: {children: ReactNode}) => {
useEffect(() => {
// Initialize PostHog only once when the app starts
if (typeof window !== "undefined" && __PROD__ && !posthog.isFeatureEnabled("capture")) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
api_host: "/ingest",
person_profiles: "identified_only",
ui_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
});
}
}, []);

if (__PROD__) {
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
}

return children;
};
return children;
};

export function Providers({children, themeProps}: ProvidersProps) {
const router = useRouter();

return (
<ProviderWrapper>
Expand Down
121 changes: 64 additions & 57 deletions apps/docs/components/navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import {useRef, useState, FC, ReactNode, Key} from "react";
import {useRef, useState, FC, ReactNode, Key, useMemo, useCallback} from "react";
import {
link,
Navbar as NextUINavbar,
Expand Down Expand Up @@ -94,6 +94,31 @@ export const Navbar: FC<NavbarProps> = ({children, routes, mobileRoutes = [], sl
"/docs/guide/upgrade-to-v2",
];

const navLinkClasses = clsx(
link({color: "foreground"}),
"data-[active=true]:text-primary data-[active=true]:font-semibold",
);

const handleVersionChange = useCallback((key: Key) => {
if (key === "v1") {
const newWindow = window.open("https://v1.nextui.org", "_blank", "noopener,noreferrer");

if (newWindow) newWindow.opener = null;
}
}, []);

const handlePressNavbarItem = useCallback(
(name: string, url: string) => {
posthog.capture("NavbarItem", {
name,
action: "press",
category: "navbar",
data: url,
});
},
[posthog],
);

const searchButton = (
<Button
aria-label="Quick search"
Expand All @@ -120,32 +145,47 @@ export const Navbar: FC<NavbarProps> = ({children, routes, mobileRoutes = [], sl
</Button>
);

const versionDropdown = useMemo(() => {
return ref.current ? (
<Dropdown placement="bottom-start" portalContainer={ref.current}>
<AnimatePresence>
{isMounted && (
<motion.div animate={{opacity: 1}} exit={{opacity: 0}} initial={{opacity: 0}}>
<DropdownTrigger>
<Button
className="min-w-[74px] max-w-[74px] hidden font-medium text-default-500 text-xs h-6 w-[74px] py-1 min-w-fit sm:flex gap-0.5 bg-default-400/20 dark:bg-default-500/20"
endContent={<ChevronDownIcon className="text-tiny" />}
radius="full"
size="sm"
variant="flat"
>
v{currentVersion}
</Button>
</DropdownTrigger>
</motion.div>
)}
</AnimatePresence>
<DropdownMenu
aria-label="NextUI versions"
defaultSelectedKeys={["v2"]}
selectionMode="single"
onAction={handleVersionChange}
>
<DropdownItem key="v2">v{currentVersion}</DropdownItem>
<DropdownItem key="v1" endContent={<LinkIcon />}>
v1.0.0
</DropdownItem>
</DropdownMenu>
</Dropdown>
) : (
<div className="w-[74px]" />
);
}, [ref.current, isMounted]);

if (pathname.includes("/examples")) {
return null;
}

const navLinkClasses = clsx(
link({color: "foreground"}),
"data-[active=true]:text-primary data-[active=true]:font-semibold",
);

const handleVersionChange = (key: Key) => {
if (key === "v1") {
const newWindow = window.open("https://v1.nextui.org", "_blank", "noopener,noreferrer");

if (newWindow) newWindow.opener = null;
}
};

const handlePressNavbarItem = (name: string, url: string) => {
posthog.capture("NavbarItem", {
name,
action: "press",
category: "navbar",
data: url,
});
};

return (
<NextUINavbar
ref={ref}
Expand All @@ -172,40 +212,7 @@ export const Navbar: FC<NavbarProps> = ({children, routes, mobileRoutes = [], sl
<SmallLogo className="w-6 h-6 md:hidden" />
<LargeLogo className="h-5 md:h-6" />
</NextLink>
{ref.current ? (
<Dropdown placement="bottom-start" portalContainer={ref.current}>
<AnimatePresence>
{isMounted && (
<motion.div animate={{opacity: 1}} exit={{opacity: 0}} initial={{opacity: 0}}>
<DropdownTrigger>
<Button
className="min-w-[74px] max-w-[74px] hidden font-medium text-default-500 text-xs h-6 w-[74px] py-1 min-w-fit sm:flex gap-0.5 bg-default-400/20 dark:bg-default-500/20"
endContent={<ChevronDownIcon className="text-tiny" />}
radius="full"
size="sm"
variant="flat"
>
v{currentVersion}
</Button>
</DropdownTrigger>
</motion.div>
)}
</AnimatePresence>
<DropdownMenu
aria-label="NextUI versions"
defaultSelectedKeys={["v2"]}
selectionMode="single"
onAction={handleVersionChange}
>
<DropdownItem key="v2">v{currentVersion}</DropdownItem>
<DropdownItem key="v1" endContent={<LinkIcon />}>
v1.0.0
</DropdownItem>
</DropdownMenu>
</Dropdown>
) : (
<div className="w-[74px]" />
)}
{versionDropdown}
<Chip
as={NextLink}
className="hidden sm:flex bg-primary-100/50 border-1 hover:bg-primary-100/80 border-primary-200/50 cursor-pointer"
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"next-themes": "0.4.3",
"nprogress": "^0.2.0",
"parse-numeric-range": "1.2.0",
"posthog-js": "1.184.1",
"posthog-js": "1.197.0",
"prism-react-renderer": "^1.2.1",
"querystring": "^0.2.1",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ z-index: 0;
}

.step:before {
@apply absolute w-7 h-7 bg-default-100 rounded-full font-medium text-center text-base inline-flex items-center justify-center -indent-px;
@apply absolute w-7 h-7 border-1 border-default-200 bg-default-100 rounded-full font-semibold text-center text-base inline-flex items-center justify-center -indent-px;
@apply ml-[-41px];
content: counter(step);
}
Expand Down
Loading
Loading