-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document next/link component and create stories
- Loading branch information
1 parent
6ae449f
commit 544d8e5
Showing
6 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
74 changes: 74 additions & 0 deletions
74
code/frameworks/nextjs/template/stories_default-js/Link.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* eslint-disable react/prop-types */ | ||
import React from 'react'; | ||
import Link from 'next/link'; | ||
|
||
import style from './Link.stories.module.css'; | ||
|
||
// `onClick`, `href`, and `ref` need to be passed to the DOM element | ||
// for proper handling | ||
const MyButton = React.forwardRef(function Button({ onClick, href, children }, ref) { | ||
return ( | ||
<a href={href} onClick={onClick} ref={ref}> | ||
{children} | ||
</a> | ||
); | ||
}); | ||
|
||
const Component = () => ( | ||
<ul> | ||
<li> | ||
<Link href="/">Normal Link</Link> | ||
</li> | ||
<li> | ||
<Link | ||
href={{ | ||
pathname: '/with-url-object', | ||
query: { name: 'test' }, | ||
}} | ||
> | ||
With URL Object | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/replace-url" replace> | ||
Replace the URL instead of push | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/legacy-behaviour" legacyBehavior> | ||
<a>Legacy behavior</a> | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/child-is-functional-component" passHref legacyBehavior> | ||
<MyButton>child is a functional component</MyButton> | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/#hashid" scroll={false}> | ||
Disables scrolling to the top | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/no-prefetch" prefetch={false}> | ||
No Prefetching | ||
</Link> | ||
</li> | ||
<li> | ||
<Link style={{ color: 'red' }} href="/with-style"> | ||
With style | ||
</Link> | ||
</li> | ||
<li> | ||
<Link className={style.link} href="/with-classname"> | ||
With className | ||
</Link> | ||
</li> | ||
</ul> | ||
); | ||
|
||
export default { | ||
component: Component, | ||
}; | ||
|
||
export const Default = {}; |
3 changes: 3 additions & 0 deletions
3
code/frameworks/nextjs/template/stories_default-js/Link.stories.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.link { | ||
color: green; | ||
} |
3 changes: 3 additions & 0 deletions
3
code/frameworks/nextjs/template/stories_default-ts/Link.stories.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.link { | ||
color: green; | ||
} |
77 changes: 77 additions & 0 deletions
77
code/frameworks/nextjs/template/stories_default-ts/Link.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from 'react'; | ||
import Link from 'next/link'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import style from './Link.stories.module.css'; | ||
|
||
// `onClick`, `href`, and `ref` need to be passed to the DOM element | ||
// for proper handling | ||
const MyButton = React.forwardRef< | ||
HTMLAnchorElement, | ||
React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement> | ||
>(function Button({ onClick, href, children }, ref) { | ||
return ( | ||
<a href={href} onClick={onClick} ref={ref}> | ||
{children} | ||
</a> | ||
); | ||
}); | ||
|
||
const Component = () => ( | ||
<ul> | ||
<li> | ||
<Link href="/">Normal Link</Link> | ||
</li> | ||
<li> | ||
<Link | ||
href={{ | ||
pathname: '/with-url-object', | ||
query: { name: 'test' }, | ||
}} | ||
> | ||
With URL Object | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/replace-url" replace> | ||
Replace the URL instead of push | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/legacy-behaviour" legacyBehavior> | ||
<a>Legacy behavior</a> | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/child-is-functional-component" passHref legacyBehavior> | ||
<MyButton>child is a functional component</MyButton> | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/#hashid" scroll={false}> | ||
Disables scrolling to the top | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/no-prefetch" prefetch={false}> | ||
No Prefetching | ||
</Link> | ||
</li> | ||
<li> | ||
<Link style={{ color: 'red' }} href="/with-style"> | ||
With style | ||
</Link> | ||
</li> | ||
<li> | ||
<Link className={style.link} href="/with-classname"> | ||
With className | ||
</Link> | ||
</li> | ||
</ul> | ||
); | ||
|
||
export default { | ||
component: Component, | ||
} as Meta<typeof Component>; | ||
|
||
export const Default: StoryObj<typeof Component> = {}; |