Skip to content

Commit

Permalink
🎨 move kitchen/next/link to kitchen/link compatible with next
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineKM committed Jan 10, 2024
1 parent c8a127a commit 7eae7e5
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 355 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-bottles-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tonightpass/kitchen": minor
---

Move kitchen/next/link to kitchen/link compatible with next
2 changes: 1 addition & 1 deletion docs/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Logo from "@components/Logo/TonightPass";
import kitchen, {
Container,
Link,
Footer,
FooterGroup,
FooterLink,
} from "@tonightpass/kitchen";
import { Link } from "@tonightpass/kitchen/next";
import { ThemeSwitch } from "nextra-theme-docs";

const navigation = {
Expand Down
10 changes: 8 additions & 2 deletions docs/components/Landing/Featured/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Button, Container, Text, Image, useTheme } from "@tonightpass/kitchen";
import { Link } from "@tonightpass/kitchen/next";
import {
Button,
Container,
Link,
Text,
Image,
useTheme,
} from "@tonightpass/kitchen";

const Featured: React.FC = () => {
const { theme } = useTheme();
Expand Down
3 changes: 1 addition & 2 deletions docs/components/Landing/Showcase/List/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import kitchen, { Container, Text } from "@tonightpass/kitchen";
import { Link } from "@tonightpass/kitchen/next";
import kitchen, { Container, Text, Link } from "@tonightpass/kitchen";
import showcases from "data/showcases";

import ShowcaseCard from "./Card";
Expand Down
148 changes: 1 addition & 147 deletions docs/pages/docs/frameworks/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ category: frameworks
---

import Playground from "@components/Playground";
import kitchen, { Container } from "@tonightpass/kitchen";
import kitchen, { Container, FragmentLink, Link } from "@tonightpass/kitchen";
import { Tab, Tabs } from "nextra-theme-docs";
import { FragmentLink, Link } from "@tonightpass/kitchen/next";

# Getting Started with Next.js

Expand Down Expand Up @@ -77,148 +76,3 @@ Deploy the example using [Vercel](https://vercel.com/new/clone?repository-url=ht
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/tonightpass/kitchen/tree/master/examples/next-typescript&project-name=kitchen-next&repository-name=kitchen-next)

In addition, here is a complete [project example](https://github.com/tonightpass/kitchen/tree/master/examples/next-typescript) using Kitchen with Next.js.

## Kitchen with Next.js Link

If you're using Next.js 13, we've provided a `@tonightpass/kitchen/next` package that
gives you a smoother experience when using Kitchen Link component with
`next/link`.

export const Card = kitchen(Container)`
border: 1px solid ${({ theme }) => theme.colors.layout.dark};
border-radius: 8px;
padding: 16px;
`;

### Usage

First of all, you need to import the `Link` component from the `@tonightpass/kitchen` package.

```js
import { Link } from "@tonightpass/kitchen"
```

### Default

<Playground
scope={{ Link }}
code={`
<Link href="/">Return to the home page</Link>
`}
/>

### Using onClick

<Playground
scope={{ Link }}
code={`
<Link onClick={() => router.push("/")}>Return to the home page</Link>
`}
/>

### Disabled

<Playground
scope={{ Link }}
code={`
<Container gap={"small"}>
<Link disabled>Disabled link</Link>
<Link href={undefined} onClick={undefined}>
Disabled link (no href or onClick)
</Link>
<Link href="#" disabled>
{"Disabled link (href=#)"}
</Link>
</Container>
`}
/>

### Non text

<Playground
scope={{ Link, Card }}
code={`
<Link href="/">
<Card>This entire div is wrapped in a link</Card>
</Link>
`}
/>

### Variants

<Playground
scope={{ Link }}
code={`
<Container gap={"small"}>
<Container gap={"small"}>
<Text size={"small"}>highlight</Text>
<Link href="#" variant="highlight">
Highlight variant
</Link>
</Container>
<Container gap={"small"}>
<Text size={"small"}>primary</Text>
<Link href="#" variant="primary">
Primary variant
</Link>
</Container>
<Container gap={"small"} align={"flex-start"}>
<Text size={"small"}>secondary</Text>
<Link href="#" variant="secondary">
Secondary variant
</Link>
</Container>
<Container gap={"small"}>
<Text size={"small"}>blend</Text>
<Note type="danger" label={false}>
<Link href="#" variant="blend">
Blend variant
</Link>{" "}
works well with themed components.
</Note>
</Container>
</Container>
`}
/>

### Fragment link (anchor)

<Playground
scope={{ FragmentLink }}
code={`
<FragmentLink id="fragment-link-example">
Click on this to jump to this section of the page
</FragmentLink>
`}
/>

### Internal href

<Playground
scope={{ Link }}
code={`
<Link href="/">Click on this to jump back to the home page</Link>
`}
/>

### External href

<Playground
scope={{ Link }}
code={`
<Link href="https://tonightpass.com/">
Click on this to go to our website
</Link>
`}
/>

### Props

| Name | Type | Default | Required | Description | Accepted values |
| :--- | :--- | :-----: | :------: | :---------- | :-------------- |
| `href` | `string` \| `UrlObject` | - | - | The href of the link. | - |
| `locale` | `string` | - | - | The locale of the link. | - |
| `className` | `string` | - | - | The classname of the link. | - |
| `onClick` | `(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void` | - | - | The click event handler of the link. | - |
| `disabled` | `boolean` | `false` | - | The status (disabled or not) of the link. | - |
| `variant` | `string` | `primary` | - | The variant of the link. | `highlight`, `primary`, `secondary`, `blend` |
2 changes: 1 addition & 1 deletion examples/next-typescript/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import kitchen, {
convertRGBToRGBA,
Image,
Text,
Link,
rotate,
} from "@tonightpass/kitchen";
import { Link } from "@tonightpass/kitchen/next";
import Head from "next/head";

const IndexPage = () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/kitchen/src/components/GlobalStyle/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ const mainCss = css`
a {
text-decoration: none;
color: ${({ theme }) => theme.colors.text.lightest};
transition: all 0.2s;
color: inherit;
cursor: pointer;
&:hover {
Expand Down
8 changes: 7 additions & 1 deletion packages/kitchen/src/components/Link/Fragment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import React from "react";
import styled from "styled-components";

import Link, { LinkProps } from "..";
import { KitchenComponent } from "../../../types";

export type FragmentLinkProps = LinkProps & {
type Props = LinkProps & {
/**
* The link's id.
*/
id: string;
};

export type FragmentLinkProps = KitchenComponent<
Props,
React.AnchorHTMLAttributes<HTMLAnchorElement>
>;

const FragmentLink = styled(({ id, ...props }: FragmentLinkProps) => {
const href = `#${id}`;
return <Link id={id} href={href} {...props} />;
Expand Down
22 changes: 18 additions & 4 deletions packages/kitchen/src/components/Link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ const Link = styled(
};

if (isString(href)) {
href = href as string;
// regex to check if the href is internal or external

const internal = href.match(/^(\/(?!\/)[^#]*|#.*)$/);
const internal = (href as string).match(/^(\/(?!\/)[^#]*|#.*)$/);
if (!internal) {
return (
<Component
Expand All @@ -76,6 +73,23 @@ const Link = styled(
}
}

if (typeof window !== "undefined" && window.next) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const NextLink = require("next/link").default;
if (href && NextLink) {
return (
<NextLink
href={href}
className={className}
onClick={handleClick}
{...props}
>
{children}
</NextLink>
);
}
}

return (
<Component
className={className}
Expand Down
2 changes: 2 additions & 0 deletions packages/kitchen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export { default as UnorderedList } from "./components/List/Unordered";

export { default as Link } from "./components/Link";
export type { LinkProps } from "./components/Link";
export { default as FragmentLink } from "./components/Link/Fragment";
export type { FragmentLinkProps } from "./components/Link/Fragment";

export { default as Modal } from "./components/Modal";
export type { ModalProps, ModalActionProps } from "./components/Modal";
Expand Down
18 changes: 0 additions & 18 deletions packages/kitchen/src/next/components/Link/Fragment/index.tsx

This file was deleted.

Loading

1 comment on commit 7eae7e5

@vercel
Copy link

@vercel vercel bot commented on 7eae7e5 Jan 10, 2024

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.