Skip to content

Commit

Permalink
Use @chakra-ui/next-js (#792)
Browse files Browse the repository at this point in the history
* Add  as dependency

* Replace all usages of the internal NextLink

* Remove internal NextLink

* Fix type miss
  • Loading branch information
oBusk authored Apr 13, 2023
1 parent 2342bdf commit 397f8bc
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 69 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"dependencies": {
"@chakra-ui/icons": "^2.0.18",
"@chakra-ui/next-js": "^2.1.2",
"@chakra-ui/react": "2.5.5",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
Expand Down
24 changes: 12 additions & 12 deletions src/components/DiffIntro/ViewTypeSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Link } from "@chakra-ui/next-js";
import {
Button,
ButtonGroup,
Expand All @@ -6,9 +7,8 @@ import {
forwardRef,
} from "@chakra-ui/react";
import { useRouter } from "next/router";
import type { DiffProps, ViewType } from "react-diff-view";
import type { ViewType } from "react-diff-view";
import { DIFF_TYPE_PARAM_NAME } from "^/pages/[...parts]";
import { NextLink } from "../theme";

export interface ViewTypeButtonProps extends ButtonProps {
title: string;
Expand All @@ -21,7 +21,8 @@ const ViewTypeButton = forwardRef<ViewTypeButtonProps, typeof Button>(
const router = useRouter();

return (
<NextLink
<Button
as={Link}
href={{
query: {
...router.query,
Expand All @@ -30,16 +31,15 @@ const ViewTypeButton = forwardRef<ViewTypeButtonProps, typeof Button>(
}}
replace
shallow
isActive={currentViewType === viewType}
_hover={{
textDecoration: "none",
}}
{...props}
ref={ref}
>
<Button
as="a"
isActive={currentViewType === viewType}
{...props}
ref={ref}
>
{title}
</Button>
</NextLink>
{title}
</Button>
);
},
);
Expand Down
32 changes: 17 additions & 15 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from "@chakra-ui/next-js";
import { Box, Flex, FlexProps, Heading, HStack } from "@chakra-ui/react";
import { FunctionComponent } from "react";
import { NextLink } from "^/components/theme";
import ColorModeToggle from "./ColorModeToggle";
import { GithubLink } from "./GithubLink";
import NavLink from "./NavLink";
Expand All @@ -22,20 +22,22 @@ const Header: FunctionComponent<FlexProps> = (props) => (
<GithubLink variant="ghost" />
<ColorModeToggle variant="ghost" />
</HStack>
<NextLink href="/">
<Box
as="a"
transition="all 0.2s"
borderRadius="md"
_focus={{
boxShadow: "outline",
}}
>
<Heading as="h1" fontSize={{ base: "md", sm: "xl", lg: "3xl" }}>
npm-diff.app 📦🔃
</Heading>
</Box>
</NextLink>
<Link
as={Box}
href="/"
transition="all 0.2s"
borderRadius="md"
_focus={{
boxShadow: "outline",
}}
_hover={{
textDecoration: "none",
}}
>
<Heading as="h1" fontSize={{ base: "md", sm: "xl", lg: "3xl" }}>
npm-diff.app 📦🔃
</Heading>
</Link>
<Flex flex="1 0 0px" justifyContent="flex-end">
<NavLink href="/about">about</NavLink>/
<NavLink href="/about/api">api</NavLink>
Expand Down
30 changes: 14 additions & 16 deletions src/components/Header/NavLink.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Link, LinkProps } from "@chakra-ui/react";
import { Link, LinkProps } from "@chakra-ui/next-js";
import { useRouter } from "next/router";
import { FunctionComponent, useEffect, useState } from "react";
import { NextLink } from "^/components/theme";

export interface NavLinkProps extends LinkProps {
href: string;
}

const NavLink: FunctionComponent<LinkProps> = ({
const NavLink: FunctionComponent<NavLinkProps> = ({
href = "",
children,
...props
Expand All @@ -29,19 +28,18 @@ const NavLink: FunctionComponent<LinkProps> = ({
}, [asPath, href]);

return (
<NextLink href={href}>
<Link
opacity={isActive ? 0.4 : undefined}
transition="all 0.2s"
borderRadius="md"
_focus={{
boxShadow: "outline",
}}
{...props}
>
{children}
</Link>
</NextLink>
<Link
href={href}
opacity={isActive ? 0.4 : undefined}
transition="all 0.2s"
borderRadius="md"
_focus={{
boxShadow: "outline",
}}
{...props}
>
{children}
</Link>
);
};

Expand Down
19 changes: 8 additions & 11 deletions src/components/Landing/ExamplesList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Heading, Link, Stack, StackProps } from "@chakra-ui/react";
import { Link } from "@chakra-ui/next-js";
import { Heading, Stack, StackProps } from "@chakra-ui/react";
import { FunctionComponent } from "react";
import { NextLink } from "^/components/theme";
import EXAMPLES from "^/lib/examples";
import { QueryParams } from "^/lib/query";

Expand Down Expand Up @@ -30,21 +30,18 @@ const ExamplesList: FunctionComponent<ExamplesListProps> = ({
Examples
</Heading>
{EXAMPLES.map((ex) => (
<NextLink
<Link
key={ex}
href={{
pathname: `/${ex}`,
query: { ...query },
}}
onMouseOver={() => onMouseOver(ex)}
onMouseOut={() => onMouseOut()}
onClick={() => onClick()}
>
<Link
onMouseOver={() => onMouseOver(ex)}
onMouseOut={() => onMouseOut()}
onClick={() => onClick()}
>
{ex}
</Link>
</NextLink>
{ex}
</Link>
))}
</Stack>
);
Expand Down
12 changes: 0 additions & 12 deletions src/components/theme/NextLink.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import CollapsableBorderBox, {
CollapsableBorderBoxProps,
} from "./CollapsableBorderBox";
import ExternalLink, { ExternalLinkProps } from "./ExternalLink";
import NextLink, { NextLinkProps } from "./NextLink";
import Span, { SpanProps } from "./Span";
import Tooltip, { TooltipProps } from "./Tooltip";

Expand All @@ -15,7 +14,6 @@ export type {
ButtonExpandBoxProps,
CollapsableBorderBoxProps,
ExternalLinkProps,
NextLinkProps,
SpanProps,
TooltipProps,
};
Expand All @@ -26,7 +24,6 @@ export {
ButtonExpandBox,
CollapsableBorderBox,
ExternalLink,
NextLink,
Span,
Tooltip,
};

1 comment on commit 397f8bc

@vercel
Copy link

@vercel vercel bot commented on 397f8bc Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.