This repository has been archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/components/storybook-link/__stories__/storybook-link.mdx
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,16 @@ | ||
import { Controls, Canvas, Meta } from '@storybook/blocks'; | ||
import * as StorybookLink from './storybook-link.stories'; | ||
|
||
<Meta of={StorybookLink} /> | ||
|
||
# StorybookLink | ||
|
||
## Overview | ||
|
||
The StorybookLink component is an internal link to navigate between components/stories inside storybook. | ||
|
||
<Canvas of={StorybookLink.Overview} /> | ||
|
||
## Props | ||
|
||
<Controls /> |
17 changes: 17 additions & 0 deletions
17
src/components/storybook-link/__stories__/storybook-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,17 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import StorybookLink from '../storybook-link'; | ||
|
||
const meta: Meta<typeof StorybookLink> = { | ||
component: StorybookLink, | ||
title: 'Components/StorybookLink', | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof StorybookLink>; | ||
|
||
export const Overview: Story = { | ||
args: { | ||
page: 'Components/Paragraph', | ||
children: 'Navigate to "Paragraph"', | ||
}, | ||
}; |
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,29 @@ | ||
import { FC, useEffect, useState } from 'react'; | ||
import Link from '../link/link'; | ||
import { hrefTo } from '@storybook/addon-links'; | ||
|
||
interface StorybookLinkProps { | ||
page: string; | ||
children: string; | ||
story?: string; | ||
} | ||
|
||
const StorybookLink: FC<StorybookLinkProps> = ({ page, story = '', children }) => { | ||
const [url, setUrl] = useState(''); | ||
|
||
useEffect(() => { | ||
fetchLink(); | ||
async function fetchLink() { | ||
const href = await hrefTo(page, story); | ||
setUrl(href); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<Link href={url} target={Link.targets.SELF} withoutSpacing> | ||
{children} | ||
</Link> | ||
); | ||
}; | ||
|
||
export default StorybookLink; |