@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
39 lines • 1.45 kB
JavaScript
import { array, assign, object, string, union } from "@metamask/superstruct";
import { ButtonStruct } from "./button.mjs";
import { InputStruct } from "./input.mjs";
import { literal } from "../../internals/index.mjs";
import { createBuilder } from "../builder.mjs";
import { NodeStruct, NodeType } from "../nodes.mjs";
export const FormComponentStruct = union([InputStruct, ButtonStruct]);
export const FormStruct = assign(NodeStruct, object({
type: literal(NodeType.Form),
children: array(FormComponentStruct),
name: string(),
}));
/**
* Create a {@link Form} node.
*
* @param args - The node arguments. This can be either an array of children and a string, or
* an object with a `name` and `children` property.
* @param args.name - The form name used to identify it.
* @param args.children - The child nodes of the form. This can be any valid
* {@link FormComponent}.
* @returns The form node as object.
* @deprecated Snaps component functions are deprecated, in favor of the new JSX
* components. This function will be removed in a future release.
* @example
* const node = form({
* name: 'myForm',
* children: [
* input({ name: 'myInput' }),
* button({ value: 'Hello, world!' }),
* ],
* });
*
* const node = form('myForm', [input('myInput'), button('Hello, world!')]);
*/
export const form = createBuilder(NodeType.Form, FormStruct, [
'name',
'children',
]);
//# sourceMappingURL=form.mjs.map