@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
42 lines • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.form = exports.FormStruct = exports.FormComponentStruct = void 0;
const superstruct_1 = require("@metamask/superstruct");
const button_1 = require("./button.cjs");
const input_1 = require("./input.cjs");
const internals_1 = require("../../internals/index.cjs");
const builder_1 = require("../builder.cjs");
const nodes_1 = require("../nodes.cjs");
exports.FormComponentStruct = (0, superstruct_1.union)([input_1.InputStruct, button_1.ButtonStruct]);
exports.FormStruct = (0, superstruct_1.assign)(nodes_1.NodeStruct, (0, superstruct_1.object)({
type: (0, internals_1.literal)(nodes_1.NodeType.Form),
children: (0, superstruct_1.array)(exports.FormComponentStruct),
name: (0, superstruct_1.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!')]);
*/
exports.form = (0, builder_1.createBuilder)(nodes_1.NodeType.Form, exports.FormStruct, [
'name',
'children',
]);
//# sourceMappingURL=form.cjs.map