forked from MetaMask/metamask-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust snaps insights documentation (MetaMask#616)
* fix: adjust snaps insights documentation Transaction insights is now using Custom UI for its output * fix: kick ci * fix: autofix lint errors * feat: add documentation on Snaps Custom UI * fix: remove "soon" tag on Custom UI * fix: link Custom UI text to relevant concept * Update docs/guide/snaps-concepts.md Co-authored-by: legobeat <[email protected]> * improve insights and Custom UI docs * Update docs/guide/snaps-exports.md Co-authored-by: Maarten Zuidhoorn <[email protected]> * Update docs/guide/snaps-exports.md Co-authored-by: Maarten Zuidhoorn <[email protected]> * Update docs/guide/snaps-exports.md Co-authored-by: Maarten Zuidhoorn <[email protected]> * Update docs/guide/snaps-exports.md Co-authored-by: Maarten Zuidhoorn <[email protected]> * Update docs/guide/snaps-exports.md Co-authored-by: Frederik Bolding <[email protected]> --------- Co-authored-by: legobeat <[email protected]> Co-authored-by: Maarten Zuidhoorn <[email protected]> Co-authored-by: Frederik Bolding <[email protected]>
- Loading branch information
1 parent
e4a619e
commit 111ccaa
Showing
4 changed files
with
172 additions
and
7 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
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,147 @@ | ||
# Concepts | ||
|
||
[[toc]] | ||
|
||
## Custom UI | ||
|
||
### Introduction | ||
|
||
Custom UI is a UI definition system used by various Snaps features. It enables Snaps to describe a rich UI to be displayed in some contexts. | ||
|
||
Custom UI is used to describe custom user interfaces in [`snap_dialog`](./snaps-rpc-api.html#snap-dialog), and in the [`onTransaction` export](./snaps-exports.html#ontransaction). | ||
|
||
### How to use it | ||
|
||
To use Custom UI, you must first install the `@metamask/snaps-ui` NPM package: | ||
|
||
```sh | ||
yarn add @metamask/snaps-ui | ||
``` | ||
|
||
Then, whenever you're required to return a Custom UI, import the components you need from the package, and build your UI with them. For example: | ||
|
||
```javascript | ||
import { panel, heading, text } from '@metamask/snaps-ui'; | ||
|
||
// ... | ||
|
||
const content = panel([ | ||
heading('Alert heading'), | ||
text('Something happened in the system.'), | ||
]); | ||
|
||
return content; | ||
``` | ||
|
||
### Components | ||
|
||
The `NodeType` enum exported by `@metamask/snaps-ui` details the available components. | ||
|
||
#### `Copyable` | ||
|
||
##### Description | ||
|
||
Outputs a read-only text field with a copy-to-clipboard shortcut. | ||
|
||
##### Usage | ||
|
||
```javascript | ||
import { copyable } from '@metamask/snaps-ui'; | ||
|
||
// ... | ||
|
||
const content = copyable('Text to be copied'); | ||
``` | ||
|
||
#### `Divider` | ||
|
||
##### Description | ||
|
||
Outputs a horizontal divider. | ||
|
||
##### Usage | ||
|
||
```javascript | ||
import { panel, divider, text } from '@metamask/snaps-ui'; | ||
|
||
// ... | ||
|
||
const content = panel([ | ||
text('Text before the divider'), | ||
divider(), | ||
text('Text after the divider'), | ||
]); | ||
``` | ||
|
||
#### `Heading` | ||
|
||
##### Description | ||
|
||
Outputs a heading. Useful for panel titles. | ||
|
||
##### Usage | ||
|
||
```javascript | ||
import { panel, heading, text } from '@metamask/snaps-ui'; | ||
|
||
// ... | ||
|
||
const content = panel([ | ||
heading('Title of the panel'), | ||
text('Text of the panel'), | ||
]); | ||
``` | ||
|
||
#### `Panel` | ||
|
||
##### Description | ||
|
||
Outputs a panel, which can be used as a container for other components. | ||
|
||
##### Usage | ||
|
||
```javascript | ||
import { panel, heading, text } from '@metamask/snaps-ui'; | ||
|
||
// ... | ||
|
||
const insights = [ | ||
/*...*/ | ||
]; | ||
const content = panel([ | ||
heading('Here are the transaction insights'), | ||
...insights.map((insight) => text(insight.description)), | ||
]); | ||
``` | ||
|
||
#### `Spinner` | ||
|
||
##### Description | ||
|
||
Outputs a loading indicator. | ||
|
||
##### Usage | ||
|
||
```javascript | ||
import { panel, heading, spinner } from '@metamask/snaps-ui'; | ||
|
||
// ... | ||
|
||
const content = panel([heading('Please wait...'), spinner()]); | ||
``` | ||
|
||
#### `Text` | ||
|
||
##### Description | ||
|
||
Outputs text. | ||
|
||
##### Usage | ||
|
||
```javascript | ||
import { text } from '@metamask/snaps-ui'; | ||
|
||
// ... | ||
|
||
const content = text('This is a simple text UI'); | ||
``` |
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