UNPKG

@metamask/snaps-sdk

Version:

A library containing the core functionality for building MetaMask Snaps

58 lines 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.input = exports.InputStruct = exports.InputType = void 0; const superstruct_1 = require("@metamask/superstruct"); const internals_1 = require("../../internals/index.cjs"); const builder_1 = require("../builder.cjs"); const nodes_1 = require("../nodes.cjs"); /** * This replicates the available input types from the metamask extension. * https://github.com/MetaMask/metamask-extension/main/ui/components/component-library/input/input.constants.js */ var InputType; (function (InputType) { InputType["Text"] = "text"; InputType["Number"] = "number"; InputType["Password"] = "password"; })(InputType || (exports.InputType = InputType = {})); exports.InputStruct = (0, superstruct_1.assign)(nodes_1.LiteralStruct, (0, superstruct_1.object)({ type: (0, internals_1.literal)(nodes_1.NodeType.Input), value: (0, superstruct_1.optional)((0, superstruct_1.string)()), name: (0, superstruct_1.string)(), inputType: (0, superstruct_1.optional)((0, superstruct_1.union)([ (0, internals_1.enumValue)(InputType.Text), (0, internals_1.enumValue)(InputType.Password), (0, internals_1.enumValue)(InputType.Number), ])), placeholder: (0, superstruct_1.optional)((0, superstruct_1.string)()), label: (0, superstruct_1.optional)((0, superstruct_1.string)()), error: (0, superstruct_1.optional)((0, superstruct_1.string)()), })); /** * Create a {@link Input} node. * * @param args - The node arguments. This can either be a name and an optional variant, value and placeholder or an object * with the properties: `inputType`, `value`, `variant`, `placeholder` and `name`. * @param args.name - The name for the input. * @param args.value - The value of the input. * @param args.inputType - An optional type, either `text`, `password` or `number`. * @param args.placeholder - An optional input placeholder. * @param args.label - An optional input label. * @param args.error - An optional error text. * @returns The input node as an 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 = input('myInput'); * const node = input('myInput', InputType.Text, 'my placeholder', 'myValue', 'myLabel'); * const node = input({ name: 'myInput' }); * const node = input({name: 'myInput', value: 'myValue', inputType: InputType.Password, placeholder: 'placeholder'}) */ exports.input = (0, builder_1.createBuilder)(nodes_1.NodeType.Input, exports.InputStruct, [ 'name', 'inputType', 'placeholder', 'value', 'label', ]); //# sourceMappingURL=input.cjs.map