UNPKG

@metamask/snaps-sdk

Version:

A library containing the core functionality for building MetaMask Snaps

1 lines 2.85 kB
{"version":3,"file":"Input.mjs","sourceRoot":"","sources":["../../../../src/jsx/components/form/Input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,4BAAwB;AA2CtD,MAAM,IAAI,GAAG,OAAO,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,mBAAmB,CAA0B,IAAI,CAAC,CAAC","sourcesContent":["import { createSnapComponent } from '../../component';\n\n// TODO: Add the `onChange` prop to the `InputProps` type.\n\nexport type GenericInputProps = {\n name: string;\n value?: string | undefined;\n placeholder?: string | undefined;\n disabled?: boolean | undefined;\n};\n\nexport type TextInputProps = { type: 'text' } & GenericInputProps;\n\nexport type PasswordInputProps = { type: 'password' } & GenericInputProps;\n\nexport type NumberInputProps = {\n type: 'number';\n min?: number;\n max?: number;\n step?: number;\n} & GenericInputProps;\n\n/**\n * The props of the {@link Input} component.\n *\n * @property name - The name of the input field. This is used to identify the\n * input field in the form data.\n * @property type - The type of the input field. Defaults to `text`.\n * @property value - The value of the input field.\n * @property placeholder - The placeholder text of the input field.\n * @property min - The minimum value of the input field.\n * Only applicable to the type `number` input.\n * @property max - The maximum value of the input field.\n * Only applicable to the type `number` input.\n * @property step - The step value of the input field.\n * Only applicable to the type `number` input.\n */\nexport type InputProps =\n | GenericInputProps\n | TextInputProps\n | PasswordInputProps\n | NumberInputProps;\n\nconst TYPE = 'Input';\n\n/**\n * An input component, which is used to create an input field.\n *\n * @param props - The props of the component.\n * @param props.name - The name of the input field. This is used to identify the\n * input field in the form data.\n * @param props.type - The type of the input field.\n * @param props.value - The value of the input field.\n * @param props.placeholder - The placeholder text of the input field.\n * @param props.min - The minimum value of the input field.\n * Only applicable to the type `number` input.\n * @param props.max - The maximum value of the input field.\n * Only applicable to the type `number` input.\n * @param props.step - The step value of the input field.\n * Only applicable to the type `number` input.\n * @param props.disabled - Whether the input is disabled.\n * @returns An input element.\n * @example\n * <Input name=\"username\" type=\"text\" />\n * @example\n * <Input name=\"numeric\" type=\"number\" min={1} max={100} step={1} />\n */\nexport const Input = createSnapComponent<InputProps, typeof TYPE>(TYPE);\n\n/**\n * An input element.\n *\n * @see Input\n */\nexport type InputElement = ReturnType<typeof Input>;\n"]}