Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.

Commit

Permalink
feat: add storybook-link component
Browse files Browse the repository at this point in the history
  • Loading branch information
talkor committed Nov 23, 2023
1 parent 9abf636 commit f24cc40
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/storybook-link/__stories__/storybook-link.mdx
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 />
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"',
},
};
29 changes: 29 additions & 0 deletions src/components/storybook-link/storybook-link.tsx
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;

0 comments on commit f24cc40

Please sign in to comment.