Skip to content

Commit ed2fd7e

Browse files
author
erik_ritter
committed
Add docs in storybook
1 parent 211ecea commit ed2fd7e

File tree

8 files changed

+70
-27
lines changed

8 files changed

+70
-27
lines changed

.storybook/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ const path = require('path');
33
const toPath = (_path) => path.join(process.cwd(), _path);
44

55
module.exports = {
6+
addons: [
7+
{
8+
name: '@storybook/addon-docs',
9+
options: {
10+
configureJSX: true,
11+
},
12+
},
13+
],
614
stories: ['../**/*.stories.tsx'],
715
webpackFinal: async (config) => {
816
return {
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { storiesOf } from '@storybook/react';
21
import React from 'react';
32
import { Address } from '.';
43

54
import { useWallet, Provider } from '@web3-ui/hooks';
65
import { Button } from '@chakra-ui/react';
76

8-
storiesOf('Address', module).add('Default', () => <Address value='testaddress.eth' />);
7+
export default {
8+
title: 'Components/Address',
9+
component: Address,
10+
};
11+
12+
export const Default = () => <Address value='testaddress.eth' />;
913

10-
const WithWallet = () => {
14+
const AddressUsingProvider = () => {
1115
const { connected, connectWallet, connection } = useWallet();
1216

1317
return (
@@ -20,8 +24,8 @@ const WithWallet = () => {
2024
);
2125
};
2226

23-
storiesOf('Address', module).add('WithWallet', () => (
27+
export const WithWallet = () => (
2428
<Provider network='rinkeby'>
25-
<WithWallet />
29+
<AddressUsingProvider />
2630
</Provider>
27-
));
31+
);

packages/components/src/components/Address/Address.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ import { Input } from '@chakra-ui/react';
22
import React from 'react';
33

44
export interface AddressProps {
5+
/**
6+
* The address to display
7+
*/
58
value: string;
69
}
710

11+
/**
12+
* A component to display an address
13+
*/
814
export const Address: React.FC<AddressProps> = ({ value }) => {
915
return <Input value={value} />;
1016
};
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { storiesOf } from '@storybook/react';
21
import React from 'react';
32
import { NFT } from '.';
43

5-
storiesOf('NFT', module).add('Renders an NFT', () => (
4+
export default {
5+
title: 'Components/NFT',
6+
component: NFT,
7+
};
8+
9+
export const Default = () => (
610
<NFT
711
tokenId='1'
812
name='Dev #1'
913
imageUrl='https://storage.opensea.io/files/acef01b1f111088c40a0d86a4cd8a2bd.svg'
1014
assetContractName='Devs for Revolution'
1115
assetContractSymbol='DEVS'
1216
/>
13-
));
17+
);

packages/components/src/components/NFT/NFT.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@ import React from 'react';
22
import { Box, Heading, Image, Flex, Tag, Text } from '@chakra-ui/react';
33

44
export interface NFTProps {
5+
/**
6+
* The id for the NFT, unique within the contract
7+
*/
58
tokenId: string;
9+
/**
10+
* The name of the NFT, potentially null
11+
*/
612
name: string | null;
13+
/**
14+
* The image of the NFT, cached from OpenSea
15+
*/
716
imageUrl: string;
17+
/**
18+
* The name of the NFT collection
19+
*/
820
assetContractName: string;
21+
/**
22+
* The symbol for the NFT collection
23+
*/
924
assetContractSymbol: string;
1025
}
1126

1227
/**
13-
* @dev Component to display an NFT given render params
14-
*
15-
* TODO: Add a component that fetchs the NFT data from the blockchain and uses this component to
16-
* display it
28+
* Component to display an NFT given render params
1729
*/
1830
export const NFT = ({
1931
tokenId,
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { storiesOf } from '@storybook/react';
21
import React from 'react';
32
import { NFTGallery } from '.';
43

5-
storiesOf('NFTGallery', module).add('Renders a list of nfts owned by an account', () => (
6-
<NFTGallery address='0x1A16c87927570239FECD343ad2654fD81682725e' />
7-
));
4+
export default {
5+
title: 'Components/NFTGallery',
6+
component: NFTGallery,
7+
};
88

9-
storiesOf('NFTGallery', module).add('Renders an error when OpenSea fails', () => (
10-
<NFTGallery address='bad_address' />
11-
));
9+
export const Default = () => <NFTGallery address='0x1A16c87927570239FECD343ad2654fD81682725e' />;
10+
11+
export const WithAnError = () => <NFTGallery address='bad_address' />;

packages/components/src/components/NFTGallery/NFTGallery.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { VStack, Heading, Grid, Alert, AlertIcon } from '@chakra-ui/react';
55
import { NFT } from '../NFT';
66

77
export interface NFTGalleryProps {
8+
/**
9+
* The owner of the NFTs
10+
*/
811
address: string;
12+
/**
13+
* The number of columns in the grid
14+
*/
915
gridWidth?: number;
1016
}
1117

@@ -20,7 +26,7 @@ export interface OpenSeaAsset {
2026
}
2127

2228
/**
23-
* @dev Component to display a grid of NFTs owned by an address. It uses the OpenSea API to fetch
29+
* Component to display a grid of NFTs owned by an address. It uses the OpenSea API to fetch
2430
* the NFTs.
2531
*/
2632
export const NFTGallery = ({ address, gridWidth = 4 }: NFTGalleryProps) => {
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { storiesOf } from '@storybook/react';
21
import React from 'react';
32
import { Button } from '@chakra-ui/react';
43
import { Provider, useWallet } from '..';
54

6-
const Default = () => {
5+
export default {
6+
title: 'Hooks/useWallet',
7+
};
8+
9+
const DefaultUsingProvider = () => {
710
const { connection, connectWallet, disconnectWallet, connected } = useWallet();
811

912
if (connected) {
@@ -15,11 +18,11 @@ const Default = () => {
1518
);
1619
}
1720

18-
return <button onClick={connectWallet}>Connect Wallet</button>;
21+
return <Button onClick={connectWallet}>Connect Wallet</Button>;
1922
};
2023

21-
storiesOf('ConnectWallet', module).add('Default', () => (
24+
export const Default = () => (
2225
<Provider network='rinkeby'>
23-
<Default />
26+
<DefaultUsingProvider />
2427
</Provider>
25-
));
28+
);

0 commit comments

Comments
 (0)