UNPKG

@metamask/snaps-sdk

Version:

A library containing the core functionality for building MetaMask Snaps

55 lines 2.28 kB
import { assign, object, optional, string, union } from "@metamask/superstruct"; import { enumValue, literal } from "../../internals/index.mjs"; import { createBuilder } from "../builder.mjs"; import { LiteralStruct, NodeType } from "../nodes.mjs"; /** * 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 */ export var InputType; (function (InputType) { InputType["Text"] = "text"; InputType["Number"] = "number"; InputType["Password"] = "password"; })(InputType || (InputType = {})); export const InputStruct = assign(LiteralStruct, object({ type: literal(NodeType.Input), value: optional(string()), name: string(), inputType: optional(union([ enumValue(InputType.Text), enumValue(InputType.Password), enumValue(InputType.Number), ])), placeholder: optional(string()), label: optional(string()), error: optional(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'}) */ export const input = createBuilder(NodeType.Input, InputStruct, [ 'name', 'inputType', 'placeholder', 'value', 'label', ]); //# sourceMappingURL=input.mjs.map