-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bold, italic, link, text, tooltip components
- Loading branch information
Showing
20 changed files
with
373 additions
and
1 deletion.
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,51 @@ | ||
import type { Meta, Story } from '@metamask/snaps-storybook'; | ||
|
||
import { Bold, Italic } from './formatting'; | ||
import type { LinkProps } from './Link'; | ||
import { Link } from './Link'; | ||
|
||
const meta: Meta<typeof Link> = { | ||
title: 'Link', | ||
component: Link, | ||
argTypes: { | ||
href: { | ||
description: 'The URL to link to.', | ||
control: 'text', | ||
}, | ||
children: { | ||
description: | ||
'The text to display in the link. This can contain formatting components.', | ||
control: 'text', | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
/** | ||
* The link component renders a hyperlink, and an icon to indicate that the link | ||
* will open in a new tab. | ||
*/ | ||
export const Default: Story<LinkProps> = { | ||
render: (props) => <Link {...props} />, | ||
args: { | ||
href: 'https://metamask.io', | ||
children: 'MetaMask', | ||
}, | ||
}; | ||
|
||
/** | ||
* Links can contain the usual formatting components, such as `Bold` and | ||
* `Italic`. | ||
*/ | ||
export const Formatting: Story<LinkProps> = { | ||
render: (props) => <Link {...props} />, | ||
args: { | ||
href: 'https://metamask.io', | ||
children: ( | ||
<Bold> | ||
Formatted <Italic>link</Italic> | ||
</Bold> | ||
), | ||
}, | ||
}; |
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,61 @@ | ||
import type { Meta, Story } from '@metamask/snaps-storybook'; | ||
|
||
import { Bold, Italic } from './formatting'; | ||
import { Link } from './Link'; | ||
import type { TextProps } from './Text'; | ||
import { Text } from './Text'; | ||
|
||
const meta: Meta<typeof Text> = { | ||
title: 'Text/Text', | ||
component: Text, | ||
argTypes: { | ||
children: { | ||
description: 'The text to render.', | ||
table: { | ||
type: { | ||
summary: | ||
'SnapsChildren<string | StandardFormattingElement | LinkElement>', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
/** | ||
* The text component renders text. It can be used in combination with other | ||
* formatting components to create rich text. | ||
*/ | ||
export const Default: Story<TextProps> = { | ||
render: (props) => <Text {...props} />, | ||
args: { | ||
children: 'This is some text.', | ||
}, | ||
}; | ||
|
||
/** | ||
* Text can contain formatting components (like `Bold` and `Italic`) to create | ||
* rich text. | ||
*/ | ||
export const Formatting: Story<TextProps> = { | ||
render: (props) => ( | ||
<Text {...props}> | ||
This is some <Bold>bold</Bold> and <Italic>italic</Italic> text. | ||
</Text> | ||
), | ||
args: {}, | ||
}; | ||
|
||
/** | ||
* Text can contain links. | ||
*/ | ||
export const WithLink: Story<TextProps> = { | ||
render: (props) => ( | ||
<Text {...props}> | ||
This is some text with a link:{' '} | ||
<Link href="https://metamask.io">metamask.io</Link>. | ||
</Text> | ||
), | ||
args: {}, | ||
}; |
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,63 @@ | ||
import type { Meta, Story } from '@metamask/snaps-storybook'; | ||
|
||
import { Bold, Italic } from './formatting'; | ||
import { Text } from './Text'; | ||
import type { TooltipProps } from './Tooltip'; | ||
import { Tooltip } from './Tooltip'; | ||
|
||
const meta: Meta<typeof Tooltip> = { | ||
title: 'Tooltip', | ||
component: Tooltip, | ||
argTypes: { | ||
content: { | ||
description: 'The element to display in the tooltip.', | ||
table: { | ||
type: { | ||
summary: | ||
'TextElement | StandardFormattingElement | LinkElement | string', | ||
}, | ||
}, | ||
}, | ||
children: { | ||
description: | ||
'The children to render outside the tooltip, which will trigger the tooltip when hovered over.', | ||
table: { | ||
type: { | ||
summary: | ||
'TextElement | StandardFormattingElement | LinkElement | ImageElement | boolean | null', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
/** | ||
* The tooltip component shows a tooltip when hovering over the children, like | ||
* text, a link, or an image. | ||
*/ | ||
export const Default: Story<TooltipProps> = { | ||
render: (props) => <Tooltip {...props} />, | ||
args: { | ||
content: <Text>Tooltip content.</Text>, | ||
children: <Text>Hover me!</Text>, | ||
}, | ||
}; | ||
|
||
/** | ||
* The tooltip component can contain text with formatting, like bold and italic | ||
* text. | ||
*/ | ||
export const Formatting: Story<TooltipProps> = { | ||
render: (props) => <Tooltip {...props} />, | ||
args: { | ||
content: ( | ||
<Text> | ||
Tooltips can contain <Bold>bold</Bold> and <Italic>italic</Italic> text | ||
as well. | ||
</Text> | ||
), | ||
children: <Text>Hover me!</Text>, | ||
}, | ||
}; |
30 changes: 30 additions & 0 deletions
30
packages/snaps-sdk/src/jsx/components/formatting/Bold.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,30 @@ | ||
import type { Meta, Story } from '@metamask/snaps-storybook'; | ||
|
||
import type { BoldProps } from './Bold'; | ||
import { Bold } from './Bold'; | ||
|
||
const meta: Meta<typeof Bold> = { | ||
title: 'Text/Bold', | ||
component: Bold, | ||
argTypes: { | ||
children: { | ||
description: 'The text to render in bold.', | ||
table: { | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
/** | ||
* The bold component renders text in bold. It can be used in combination with | ||
* other formatting components to create rich text. | ||
*/ | ||
export const Default: Story<BoldProps> = { | ||
render: (props) => <Bold {...props} />, | ||
args: { | ||
children: 'I am bold!', | ||
}, | ||
}; |
30 changes: 30 additions & 0 deletions
30
packages/snaps-sdk/src/jsx/components/formatting/Italic.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,30 @@ | ||
import type { Meta, Story } from '@metamask/snaps-storybook'; | ||
|
||
import type { ItalicProps } from './Italic'; | ||
import { Italic } from './Italic'; | ||
|
||
const meta: Meta<typeof Italic> = { | ||
title: 'Text/Italic', | ||
component: Italic, | ||
argTypes: { | ||
children: { | ||
description: 'The text to render in italic.', | ||
table: { | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
/** | ||
* The italic component renders text in italic. It can be used in combination with | ||
* other formatting components to create rich text. | ||
*/ | ||
export const Default: Story<ItalicProps> = { | ||
render: (props) => <Italic {...props} />, | ||
args: { | ||
children: 'I am italic!', | ||
}, | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/snaps-storybook/src/components/icons/ExportIcon.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,11 @@ | ||
import { createIcon } from '@chakra-ui/react'; | ||
|
||
export const ExportIcon = createIcon({ | ||
displayName: 'ExportIcon', | ||
viewBox: '0 0 512 512', | ||
d: 'm313 469l-114 0c-108 0-156-48-156-156l0-114c0-108 48-156 156-156l39 0c13 0 23 9 23 23 0 13-10 23-23 23l-39 0c-83 0-110 27-110 110l0 114c0 83 27 110 110 110l114 0c83 0 110-27 110-110l0-39c0-13 10-23 23-23 14 0 23 10 23 23l0 39c0 108-48 156-156 156z m-39-208c-7 0-11-3-16-7-9-9-9-23 0-32l133-133-36 0c-14 0-23-10-23-23 0-14 9-23 23-23l91 0c14 0 23 9 23 23l0 91c0 14-9 23-23 23-13 0-23-9-23-23l0-36-133 133c-4 4-9 7-16 7z', | ||
defaultProps: { | ||
width: '14px', | ||
height: '14px', | ||
}, | ||
}); |
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
13 changes: 13 additions & 0 deletions
13
packages/snaps-storybook/src/components/snaps/bold/Bold.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,13 @@ | ||
import type { BoldProps } from '@metamask/snaps-sdk/jsx'; | ||
import type { FunctionComponent } from 'react'; | ||
|
||
import type { RenderProps } from '../../Renderer'; | ||
|
||
export const Bold: FunctionComponent<RenderProps<BoldProps>> = ({ | ||
children, | ||
Renderer, | ||
}) => ( | ||
<b> | ||
<Renderer id="bold" element={children} /> | ||
</b> | ||
); |
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 @@ | ||
export { Bold as Component } from './Bold'; |
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
13 changes: 13 additions & 0 deletions
13
packages/snaps-storybook/src/components/snaps/italic/Italic.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,13 @@ | ||
import type { ItalicProps } from '@metamask/snaps-sdk/jsx'; | ||
import type { FunctionComponent } from 'react'; | ||
|
||
import type { RenderProps } from '../../Renderer'; | ||
|
||
export const Italic: FunctionComponent<RenderProps<ItalicProps>> = ({ | ||
children, | ||
Renderer, | ||
}) => ( | ||
<i> | ||
<Renderer id="italic" element={children} /> | ||
</i> | ||
); |
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 @@ | ||
export { Italic as Component } from './Italic'; |
10 changes: 10 additions & 0 deletions
10
packages/snaps-storybook/src/components/snaps/link/Link.styles.ts
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,10 @@ | ||
import { defineStyle, defineStyleConfig } from '@chakra-ui/react'; | ||
|
||
export const styles = defineStyleConfig({ | ||
baseStyle: defineStyle({ | ||
color: 'primary.default', | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
gap: '1', | ||
}), | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/snaps-storybook/src/components/snaps/link/Link.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 { Link as ChakraLink } from '@chakra-ui/react'; | ||
import type { LinkProps } from '@metamask/snaps-sdk/jsx'; | ||
import type { FunctionComponent } from 'react'; | ||
|
||
import { ExportIcon } from '../../icons'; | ||
import type { RenderProps } from '../../Renderer'; | ||
|
||
export const Link: FunctionComponent<RenderProps<LinkProps>> = ({ | ||
href, | ||
children, | ||
Renderer, | ||
}) => ( | ||
<ChakraLink target="_blank" href={href}> | ||
<Renderer id="link" element={children} /> | ||
<ExportIcon /> | ||
</ChakraLink> | ||
); |
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,2 @@ | ||
export { Link as Component } from './Link'; | ||
export { styles } from './Link.styles'; |
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
24 changes: 24 additions & 0 deletions
24
packages/snaps-storybook/src/components/snaps/tooltip/Tooltip.styles.ts
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 { cssVar, defineStyle, defineStyleConfig } from '@chakra-ui/react'; | ||
|
||
const background = cssVar('popper-arrow-bg'); | ||
|
||
export const styles = defineStyleConfig({ | ||
baseStyle: defineStyle({ | ||
background: 'background.default', | ||
color: 'text.default', | ||
boxShadow: 'md', | ||
[background.variable]: 'colors.background.default', | ||
}), | ||
|
||
sizes: { | ||
sm: defineStyle({ | ||
fontSize: 'xs', | ||
fontWeight: 'normal', | ||
lineHeight: 'short', | ||
}), | ||
}, | ||
|
||
defaultProps: { | ||
size: 'sm', | ||
}, | ||
}); |
Oops, something went wrong.