Skip to content

Commit a97cdd9

Browse files
author
Nikolai Lopin
committed
docs: migrate TabBar docs to csf3
1 parent 1d40058 commit a97cdd9

File tree

3 files changed

+64
-61
lines changed

3 files changed

+64
-61
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { useState } from 'react';
2+
import { Meta, StoryObj } from '@storybook/react';
3+
import { TabBar } from '../TabBar';
4+
5+
const TABS = ['A New Hope', 'Empire Strikes Back', 'Return of the Jedi'];
6+
7+
const meta: Meta = {
8+
title: 'Components/TabBar',
9+
component: TabBar.Link,
10+
argTypes: {
11+
as: {
12+
control: 'text'
13+
}
14+
}
15+
};
16+
17+
export default meta;
18+
19+
type Story = StoryObj<typeof TabBar.Link>;
20+
21+
export const Default: Story = {
22+
render: args => {
23+
const [selected, setSelected] = useState<string>();
24+
25+
return (
26+
<TabBar>
27+
{TABS.map(it => (
28+
<TabBar.Link
29+
key={it}
30+
href="#"
31+
onClick={e => {
32+
e.preventDefault();
33+
setSelected(it);
34+
}}
35+
selected={selected === it}
36+
{...args}
37+
>
38+
{it}
39+
</TabBar.Link>
40+
))}
41+
</TabBar>
42+
);
43+
}
44+
};
Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
import { Canvas, Story, ArgsTable, Meta, Source } from '@storybook/blocks';
2-
import { TabBar } from '../TabBar';
3-
import { TabBarExample } from './TabBarExample';
1+
import { Primary, ArgTypes, Meta } from '@storybook/blocks';
2+
43
import { StyledSystemLinks } from '../../../docs/StyledSystemLinks';
4+
import * as TabBarStories from './TabBar.stories';
5+
6+
<Meta of={TabBarStories} />
57

6-
<Meta
7-
title="Components/TabBar"
8-
component={TabBar}
9-
argTypes={{
10-
initiallySelected: {
11-
control: 'radio',
12-
options: ['A New Hope', 'Empire Strikes Back', 'Return of the Jedi']
13-
}
14-
}}
15-
/>
16-
17-
# Tabbar
18-
19-
<Canvas>
20-
<Story name="Default" args={{}}>
21-
{TabBarExample.bind({})}
22-
</Story>
23-
</Canvas>
8+
# TabBar
9+
10+
<Primary />
2411

2512
- This component is a sub-navigation to organize different categories of a content on the same page
2613
- The recommended amount of tabs is 2-5
@@ -31,23 +18,20 @@ import { StyledSystemLinks } from '../../../docs/StyledSystemLinks';
3118

3219
### TabBar.Link
3320

34-
<ArgsTable of={TabBar.Link} />
21+
<ArgTypes of={TabBarStories} />
22+
3523
<StyledSystemLinks component="TabBar" supportedProps={['margin']} />
3624

3725
The `TabBar.Link` supports all the props that can be passed to `<a>` tag.
3826

39-
### Usage with react-router
27+
## Usage
4028

41-
When using this component as a navigational element with the `NavLink` from react-router, the class name `active` on the
42-
`TabBar.Link` element can also be used to indicate that the element is active and is the default that react-router adds
43-
to active `NavLink` elements.
29+
### Idiomatic usage
4430

45-
## Idiomatic usage
46-
47-
```jsx
31+
```tsx
4832
const TabBarExample = () => {
4933
const items = ['A New Hope', 'Empire Strikes Back', 'Return of the Jedi'];
50-
const [selected, setSelected] = useState(items[0]);
34+
const [selected, setSelected] = useState<string>(items[0]);
5135

5236
return (
5337
<TabBar my={5}>
@@ -60,3 +44,9 @@ const TabBarExample = () => {
6044
);
6145
};
6246
```
47+
48+
### With react-router
49+
50+
When using this component as a navigational element with the `NavLink` from react-router, the class name `active` on the
51+
`TabBar.Link` element can also be used to indicate that the element is active and is the default that react-router adds
52+
to active `NavLink` elements.

src/components/TabBar/docs/TabBarExample.tsx

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)