You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Snaps documentation for MetaMask Extension 12.6 updates (#1715)
* Add optional context param to snap_updateInterface
This closes#1673
* Update API examples for interfaces to use JSX
* Add Snaps Avatar component
This closes#1701
* Update Address component
This closes#1711
* Add 'valid' to avatar prop
* Add min, max, and step props to Snaps Input component
This fixes#1702
* Add size prop for Snaps Heading component
This fixes#1703
* Add metamask scheme for Snaps Link component
This fixes#1704
* Update Snaps Row component to include Link as a possible child
Fixes#1705
* Add Address component to children of Snaps Link component
Fixes#1706
* Update What's New
Also fix a couple missing indents
* Correct the metamask scheme URL for Snap home page
Also clarify that it leads to the Snap's settings if it does not have a home page, and what to expect when testing.
* Line breaks
* Correct information for local metamask: URLs
* edits
---------
Co-authored-by: Alexandra Tran <[email protected]>
@@ -3,6 +3,9 @@ description: Display custom user interface components using JSX.
3
3
sidebar_position: 4
4
4
---
5
5
6
+
import Tabs from "@theme/Tabs";
7
+
import TabItem from "@theme/TabItem";
8
+
6
9
# Custom UI
7
10
8
11
You can display custom user interface (UI) JSX components using the
@@ -15,7 +18,9 @@ implementing the following features:
15
18
-[Signature insights](../signature-insights.md)
16
19
17
20
:::note
18
-
JSX is supported in the MetaMask extension and Flask version 12 and later. New UI components will be added as JSX components. The previous function-based library is deprecated.
21
+
JSX is supported in the MetaMask extension and Flask version 12 and later.
22
+
New UI components will be added as JSX components.
23
+
The previous function-based library is deprecated.
19
24
:::
20
25
21
26
To use custom UI, first install [`@metamask/snaps-sdk`](https://github.com/MetaMask/snaps/tree/main/packages/snaps-sdk)
@@ -27,7 +32,8 @@ yarn add @metamask/snaps-sdk
27
32
28
33
Then, whenever you're required to return a custom UI component, import the components from the
29
34
SDK at `@metamask/snaps-sdk/jsx` and build your UI with them.
30
-
For example, to display a [`Box`](#box) using [`snap_dialog`](../../reference/snaps-api.md#snap_dialog):
@@ -166,8 +234,8 @@ For use in [interactive UI](interactive-ui.md).
166
234
- `type` - (Optional) The type of button.
167
235
Possible values are `"button"` and `"submit"`.
168
236
The default is `"button"`.
169
-
- `name`: `string` - (Optional) The name that will be sent to [`onUserInput`](../../reference/entry-points.md#onuserinput)
170
-
when a user selects the button.
237
+
- `name`: `string` - (Optional) The name that will be sent to
238
+
[`onUserInput`](../../reference/entry-points.md#onuserinput) when a user selects the button.
171
239
- `variant` - (Optional) Determines the appearance of the button.
172
240
Possible values are `"primary"` and `"destructive"`.
173
241
The default is `"primary"`.
@@ -209,7 +277,8 @@ Outputs a card component which is used to display values in a card structure.
209
277
210
278
:::info
211
279
Unlike many `Card` components from other UI libraries, the Snaps `Card` does not have any shape.
212
-
It is only used for layout. To give a shape to a `Card`, wrap it in a [`Section`](#section) component.
280
+
It is only used for layout. To give a shape to a `Card`, wrap it in a [`Section`](#section)
281
+
component.
213
282
:::
214
283
215
284
#### Props
@@ -305,7 +374,8 @@ Outputs a read-only text field with a copy-to-clipboard shortcut.
305
374
#### Props
306
375
307
376
- `value`: `string` - The value to copy when the user clicks on the copyable element.
308
-
- `sensitive`: `boolean` - (Optional) Indicates whether the value is sensitive. If `true`, the value will be hidden when the user is not interacting with the copyable element.
377
+
- `sensitive`: `boolean` - (Optional) Indicates whether the value is sensitive. If `true`, the
378
+
value will be hidden when the user is not interacting with the copyable element.
309
379
310
380
#### Example
311
381
@@ -412,9 +482,11 @@ Outputs a form field, wrapping an element to give it a label and optional error.
412
482
#### Props
413
483
414
484
- `label`: `string` - The label for the wrapped element.
415
-
- `error`: `string` - (Optional) Any error for the wrapped element. Setting this changes the style of the wrapped element to show that there is an error.
485
+
- `error`: `string` - (Optional) Any error for the wrapped element. Setting this changes the style
486
+
of the wrapped element to show that there is an error.
416
487
- `children` - The element to be wrapped.
417
-
This can be a [`Dropdown`](#dropdown), [`Input`](#input), [`Selector`](#selector), or [`RadioGroup`](#radiogroup) component.
488
+
This can be a [`Dropdown`](#dropdown), [`Input`](#input), [`Selector`](#selector), or
489
+
[`RadioGroup`](#radiogroup) component.
418
490
419
491
#### Example
420
492
@@ -508,8 +580,8 @@ Outputs a form for use in [interactive UI](interactive-ui.md).
508
580
509
581
#### Props
510
582
511
-
- `name`: `string` - The name that will be sent to [`onUserInput`](../../reference/entry-points.md#onuserinput)
512
-
when a user interacts with the form.
583
+
- `name`: `string` - The name that will be sent to
584
+
[`onUserInput`](../../reference/entry-points.md#onuserinput) when a user interacts with the form.
513
585
- `children`: `array` - An array of [`Input`](#input) or [`Button`](#button) components.
514
586
515
587
#### Example
@@ -549,6 +621,11 @@ await snap.request({
549
621
Outputs a heading.
550
622
This is useful for [`Box`](#box) titles.
551
623
624
+
#### Props
625
+
626
+
- `size`: `string` - (Optional) The size of the heading. Possible values are `"sm"`, `"md"`, and
627
+
`"lg"`. The default is `"sm"`.
628
+
552
629
#### Example
553
630
554
631
```javascript title="index.jsx"
@@ -616,7 +693,8 @@ This component takes an inline SVG.
616
693
It does not support remote URLs.
617
694
618
695
You can import SVG, PNG, and JPEG files using an import statement.
619
-
These files are automatically imported as SVG strings, so you can pass them directly to the `Image` component.
696
+
These files are automatically imported as SVG strings, so you can pass them directly to the
697
+
`Image` component.
620
698
621
699
The SVG is rendered within an `<img>` tag, which prevents JavaScript or interaction events from
622
700
being supported.
@@ -667,13 +745,20 @@ Outputs an input component for use in [interactive UI](interactive-ui.md).
667
745
#### Props
668
746
669
747
- `name`: `string` - The name that will be used as a key to the event sent to
670
-
[`onUserInput`](../../reference/entry-points.md#onuserinput) when the containing form is submitted.
748
+
[`onUserInput`](../../reference/entry-points.md#onuserinput) when the containing form is
749
+
submitted.
671
750
- `type` - (Optional) The type of input.
672
751
Possible values are `"text"`, `"number"`, and `"password"`.
673
752
The default is `"text"`.
674
753
- `placeholder`: `string` - (Optional) The text displayed when the input is empty.
675
754
- `label`: `string` - (Optional) The text displayed alongside the input to label it.
676
755
- `value`: `string` - (Optional) The default value of the input.
756
+
- `min`: `string` - (Optional) The minimum value of the input field. Only applicable to the input
757
+
type `"number"`.
758
+
- `max`: `string` - (Optional) The maximum value of the input field. Only applicable to the input
759
+
type `"number"`.
760
+
- `step`: `string` - (Optional) The step value of the input field. Only applicable to the input
761
+
type `"number"`.
677
762
678
763
#### Example
679
764
@@ -738,8 +823,28 @@ Outputs a clickable link.
738
823
739
824
#### Props
740
825
741
-
- `href`: `string` - The URL to point to. Supported schemes are `https:` and `mailto:`. `http:` is not allowed.
742
-
- `children`: `Array<string | Bold | Italic>` - The link text.
826
+
- `href`: `string` - The URL to point to. Supported schemes are `https:`, `mailto:`, and
827
+
`metamask:`. `http:` is not allowed.
828
+
- `children`: `Array<string | Bold | Italic | Address>` - The link text, or an
829
+
[`Address`](#address).
830
+
831
+
#### About `metamask:` URLs
832
+
833
+
A Snap can link to the following screens using the `metamask:` scheme:
834
+
835
+
- `metamask://client/` - Leads to the main screen of MetaMask.
836
+
-`metamask://snap/[Snap ID]/home/`- Leads to the Snap's
837
+
[home page](../custom-ui/home-pages.md), or the Snap's settings page if it does not have a home
838
+
page. Valid Snap IDs are npm IDs beginning with`npm:`, such as
839
+
`metamask://snap/npm:@consensys/starknet-snap/home`, or `local:`, such as
840
+
`metamask://snap/local:http://localhost:8080/home`. Consider using
841
+
[environment variables](../../how-to/use-environment-variables.md) so you can have different
842
+
Snap IDs for local testing and production.
843
+
844
+
:::warning
845
+
MetaMask will throw an error if the URL is not valid or if the URL leads to a Snap that is not
846
+
installed.
847
+
:::
743
848
744
849
#### Example
745
850
@@ -813,8 +918,8 @@ Outputs a row with a label and value, which can be used for key-value data.
813
918
-`variant`- (Optional) The variant of the label.
814
919
Possible values are `"default"`, `"error"`, and `"warning"`.
815
920
The default is `"default"`.
816
-
- `children` - The value of the row, which can be a [`Text`](#text), [`Image`](#image), or
817
-
[`Address`](#address) component.
921
+
-`children`- The value of the row, which can be a [`Text`](#text), [`Image`](#image),
922
+
[`Address`](#address), or [`Link`](#link) component.
-`ui` - The [custom UI](../features/custom-ui/index.md) to create.
1017
+
-`context` - (Optional) A custom context object that will be passed to [`onUserInput`](./entry-points.md#onuserinput) when the user interacts with the interface. Passing this parameter will update the context object for the interface.
0 commit comments