@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
49 lines • 1.92 kB
JavaScript
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";
export var ButtonVariant;
(function (ButtonVariant) {
ButtonVariant["Primary"] = "primary";
ButtonVariant["Secondary"] = "secondary";
})(ButtonVariant || (ButtonVariant = {}));
export var ButtonType;
(function (ButtonType) {
ButtonType["Button"] = "button";
ButtonType["Submit"] = "submit";
})(ButtonType || (ButtonType = {}));
export const ButtonStruct = assign(LiteralStruct, object({
type: literal(NodeType.Button),
value: string(),
variant: optional(union([
enumValue(ButtonVariant.Primary),
enumValue(ButtonVariant.Secondary),
])),
buttonType: optional(union([enumValue(ButtonType.Button), enumValue(ButtonType.Submit)])),
name: optional(string()),
}));
/**
* Create a {@link Button} node.
*
* @param args - The node arguments. This can be either a string, or an object
* with a `value` property. A set of optional properties can be passed.
* @param args.variant - The optional variant of the button.
* @param args.value - The text content of the node.
* @param args.name - The optional name of the button.
* @returns The text 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
* ```typescript
* const node = button({ variant: 'primary', text: 'Hello, world!', name: 'myButton' });
* const node = button('Hello, world!', 'button', 'myButton', 'primary');
* const node = button('Hello, world!');
* ```
*/
export const button = createBuilder(NodeType.Button, ButtonStruct, [
'value',
'buttonType',
'name',
'variant',
]);
//# sourceMappingURL=button.mjs.map