-
Notifications
You must be signed in to change notification settings - Fork 568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JSX support for custom UI #2258
Conversation
971bad9
to
507855f
Compare
packages/snaps-utils/src/jsx.ts
Outdated
if ( | ||
hasProperty(node, 'props') && | ||
isPlainObject(node.props) && | ||
hasProperty(node.props, 'children') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't a prop also be a component or do we not want to support that in our implementation?
I seem to recall some of the SIP having components as props
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of the components use components in props at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we want to do that, how do we remember to add support in this file and others?
module.exports = deepmerge(baseConfig, { | ||
preset: '@metamask/snaps-jest', | ||
|
||
// Since `@metamask/snaps-jest` runs in the browser, we can't collect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still accurate? I guess we could collect something now potentially?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's accurate for the wrong reason. We still can't collect coverage information since the Snap runs in a separate thread.
packages/snaps-jest/src/internals/simulation/interface.test.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Frederik Bolding <[email protected]>
This changes Snaps UI to use a new JSX based format. I've added a JSX-equivalent for each existing component (with some small differences, see below), and a simple renderer, which serialises the elements. Existing (now legacy) components are transformed into the JSX based format automatically, so under the hood we only need to support JSX.
Snaps JSX only supports the new JSX transform, i.e.,
react-jsx
orreact-jsxdev
, with@metamask/snaps-sdk
as import source. For development, usingreact-jsxdev
is recommended as it will provide additional validation which is otherwise handled by MetaMask. The CLI has been updated to usereact-jsx
automatically.Differences
There are some minor differences between the legacy components and JSX equivalents:
General
panel
was replaced byBox
, which is more in line with existing UI frameworks.value
, but usechildren
instead.Forms and form components
Button
usestype
instead ofbuttonType
.Button
'ssecondary
variant was replaced bydestructive
.Input
usestype
instead ofinputType
.Form
does not acceptInput
directly, but rather expects aField
component with anInput
.Field
has props to set alabel
orerror
.Images
Image
now takes an optionalalt
prop.Text and formatting
Text
component does not support markdown. Instead, you can use theBold
,Italic
, andLink
components. The new component does not have amarkdown
prop.Breaking changes
snaps-jest
changed. When usingtoStrictEqual
(or equivalent) matchers, the expected value needs to be updated.toRender
works with the legacy and JSX format.