-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Storybook plugin and stories for SDK components
- Loading branch information
Showing
90 changed files
with
6,783 additions
and
1,598 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { StorybookConfig } from '@storybook/types'; | ||
|
||
const config: StorybookConfig = { | ||
stories: ['../src/**/*.stories.tsx', '../src/**/*.mdx'], | ||
framework: { | ||
name: '@metamask/snaps-storybook', | ||
options: {}, | ||
}, | ||
addons: [ | ||
'@storybook/addon-controls', | ||
], | ||
core: { | ||
disableTelemetry: true, | ||
} | ||
}; | ||
|
||
export default config; |
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,7 @@ | ||
import type { Preview, SnapsRenderer } from '@metamask/snaps-storybook'; | ||
|
||
const preview: Preview = { | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default preview; |
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
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
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,31 @@ | ||
import type { Meta, Story } from '@metamask/snaps-storybook'; | ||
|
||
import type { AddressProps } from './Address'; | ||
import { Address } from './Address'; | ||
|
||
const meta: Meta<typeof Address> = { | ||
title: 'Address', | ||
component: Address, | ||
argTypes: { | ||
address: { | ||
description: | ||
'The address to display. This must be a valid Ethereum address starting with `0x`.', | ||
table: { | ||
// eslint-disable-next-line no-template-curly-in-string | ||
type: { summary: '`0x${string}`' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
/** | ||
* The address component renders an (Ethereum) address. | ||
*/ | ||
export const Default: Story<AddressProps> = { | ||
render: (props) => <Address {...props} />, | ||
args: { | ||
address: '0x4bbeEB066eD09B7AEd07bF39EEe0460DFa261520', | ||
}, | ||
}; |
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,112 @@ | ||
import type { Meta, Story } from '@metamask/snaps-storybook'; | ||
|
||
import type { BoxProps } from './Box'; | ||
import { Box } from './Box'; | ||
import { Button } from './form'; | ||
import { Heading } from './Heading'; | ||
import { Text } from './Text'; | ||
|
||
const meta: Meta<typeof Box> = { | ||
title: 'Box', | ||
component: Box, | ||
argTypes: { | ||
direction: { | ||
description: 'The direction in which to lay out the children.', | ||
options: ['vertical', 'horizontal'], | ||
control: { | ||
type: 'inline-radio', | ||
}, | ||
table: { | ||
defaultValue: { | ||
summary: 'vertical', | ||
}, | ||
}, | ||
}, | ||
alignment: { | ||
description: 'The alignment of the children in the box.', | ||
options: ['start', 'center', 'end', 'space-between'], | ||
control: { | ||
type: 'select', | ||
}, | ||
table: { | ||
defaultValue: { | ||
summary: 'start', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
/** | ||
* The default box, which renders its children in a vertical layout. | ||
*/ | ||
export const Vertical: Story<BoxProps> = { | ||
name: 'Vertical direction', | ||
render: (props) => ( | ||
<Box {...props}> | ||
<Heading>Box</Heading> | ||
<Text>A box with some text, and a</Text> | ||
<Button>Button</Button> | ||
</Box> | ||
), | ||
args: { | ||
direction: 'vertical', | ||
}, | ||
}; | ||
|
||
/** | ||
* The box with horizontal layout, which renders its children in a horizontal | ||
* layout (i.e., next to each other instead of on top of each other). | ||
*/ | ||
export const Horizontal: Story<BoxProps> = { | ||
name: 'Horizontal direction', | ||
render: (props) => ( | ||
<Box {...props}> | ||
<Heading>Box</Heading> | ||
<Text>A box with some text, and a</Text> | ||
<Button>Button</Button> | ||
</Box> | ||
), | ||
args: { | ||
direction: 'horizontal', | ||
}, | ||
}; | ||
|
||
/** | ||
* The box with center alignment, which centers its children. | ||
*/ | ||
export const Center: Story<BoxProps> = { | ||
name: 'Center alignment', | ||
render: (props) => ( | ||
<Box {...props}> | ||
<Heading>Box</Heading> | ||
<Text>A box with some text, and a</Text> | ||
<Button>Button</Button> | ||
</Box> | ||
), | ||
args: { | ||
alignment: 'center', | ||
}, | ||
}; | ||
|
||
/** | ||
* The box with space-between alignment, which spaces its children evenly. | ||
* | ||
* This only works with horizontal direction. | ||
*/ | ||
export const SpaceBetween: Story<BoxProps> = { | ||
name: 'Space between alignment', | ||
render: (props) => ( | ||
<Box {...props}> | ||
<Heading>Box</Heading> | ||
<Text>A box with some text, and a</Text> | ||
<Button>Button</Button> | ||
</Box> | ||
), | ||
args: { | ||
direction: 'horizontal', | ||
alignment: 'space-between', | ||
}, | ||
}; |
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,24 @@ | ||
import type { Meta, Story } from '@metamask/snaps-storybook'; | ||
|
||
import type { HeadingProps } from './Heading'; | ||
import { Heading } from './Heading'; | ||
|
||
const meta: Meta<typeof Heading> = { | ||
title: 'Heading', | ||
component: Heading, | ||
}; | ||
|
||
export default meta; | ||
|
||
/** | ||
* The default heading, with text. It can be used to display a title or section | ||
* header. | ||
* | ||
* This is currently the only variant. | ||
*/ | ||
export const Default: Story<HeadingProps> = { | ||
render: (props) => <Heading {...props} />, | ||
args: { | ||
children: 'Heading', | ||
}, | ||
}; |
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
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,116 @@ | ||
import type { Meta, Story } from '@metamask/snaps-storybook'; | ||
|
||
import { Address } from './Address'; | ||
import type { RowProps } from './Row'; | ||
import { Row } from './Row'; | ||
import { Text } from './Text'; | ||
|
||
const meta: Meta<typeof Row> = { | ||
title: 'Row', | ||
component: Row, | ||
argTypes: { | ||
label: { | ||
description: 'The label of the row, shown on the left.', | ||
table: { | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
|
||
children: { | ||
description: | ||
'The children of the row, shown on the right. This can be an address, an image, value, or text.', | ||
table: { | ||
type: { | ||
summary: 'AddressElement | ImageElement | TextElement | ValueElement', | ||
}, | ||
}, | ||
}, | ||
|
||
variant: { | ||
description: 'The variant of the row.', | ||
options: ['default', 'warning', 'critical'], | ||
control: { | ||
type: 'select', | ||
}, | ||
table: { | ||
type: { summary: '"default" | "warning" | "critical"' }, | ||
defaultValue: { summary: '"default"' }, | ||
}, | ||
}, | ||
|
||
tooltip: { | ||
description: 'The tooltip text to show on hover.', | ||
control: { | ||
type: 'text', | ||
}, | ||
table: { | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
/** | ||
* The default row, with a label and children. | ||
*/ | ||
export const Default: Story<RowProps> = { | ||
render: (props) => <Row {...props} />, | ||
args: { | ||
label: 'Label', | ||
children: <Text>Row text</Text>, | ||
}, | ||
}; | ||
|
||
/** | ||
* A warning row, which indicates a warning. It renders the row with a yellow | ||
* background. | ||
*/ | ||
export const Warning: Story<RowProps> = { | ||
render: (props) => <Row {...props} />, | ||
args: { | ||
label: 'Label', | ||
children: <Text>Warning text</Text>, | ||
variant: 'warning', | ||
}, | ||
}; | ||
|
||
/** | ||
* A critical row, which indicates a critical issue. It renders the row with a | ||
* red background. | ||
*/ | ||
export const Critical: Story<RowProps> = { | ||
render: (props) => <Row {...props} />, | ||
args: { | ||
label: 'Label', | ||
children: <Text>Critical text</Text>, | ||
variant: 'critical', | ||
}, | ||
}; | ||
|
||
/** | ||
* A row with a tooltip, which shows the tooltip text on hover. It shows a | ||
* different icon depending on the variant. | ||
*/ | ||
export const Tooltip: Story<RowProps> = { | ||
name: 'With tooltip', | ||
render: (props) => <Row {...props} />, | ||
args: { | ||
label: 'Label', | ||
children: <Text>Row text</Text>, | ||
tooltip: 'Tooltip text', | ||
}, | ||
}; | ||
|
||
/** | ||
* A row with an address. | ||
*/ | ||
export const WithAddress: Story<RowProps> = { | ||
name: 'With address', | ||
render: (props) => <Row {...props} />, | ||
args: { | ||
label: 'Label', | ||
children: <Address address="0x4bbeEB066eD09B7AEd07bF39EEe0460DFa261520" />, | ||
}, | ||
}; |
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
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
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 |
---|---|---|
|
@@ -12,5 +12,10 @@ | |
"jsx.d.ts", | ||
"jsx-runtime.d.ts", | ||
"jsx-dev-runtime.d.ts" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../snaps-storybook" | ||
} | ||
] | ||
} |
Oops, something went wrong.