@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
48 lines • 2.23 kB
JavaScript
import { assign, object, string, optional, union } from "@metamask/superstruct";
import { AddressStruct } from "./address.mjs";
import { ImageStruct } from "./image.mjs";
import { TextStruct } from "./text.mjs";
import { enumValue, literal } from "../../internals/index.mjs";
import { createBuilder } from "../builder.mjs";
import { LiteralStruct, NodeType } from "../nodes.mjs";
export var RowVariant;
(function (RowVariant) {
RowVariant["Default"] = "default";
RowVariant["Critical"] = "critical";
RowVariant["Warning"] = "warning";
})(RowVariant || (RowVariant = {}));
// A subset of components made available to the row
const RowComponentStruct = union([ImageStruct, TextStruct, AddressStruct]);
export const RowStruct = assign(LiteralStruct, object({
type: literal(NodeType.Row),
variant: optional(union([
enumValue(RowVariant.Default),
enumValue(RowVariant.Critical),
enumValue(RowVariant.Warning),
])),
label: string(),
value: RowComponentStruct,
}));
/**
* Create a {@link Row} node.
*
* @param args - The node arguments. This can either be a string, a component and an optional variant or an object
* with the properties: `label`, `value` and `variant`.
* @param args.label - The label for the row.
* @param args.value - Another component, is currently limited to `image`, `text` and `address`.
* @param args.variant - An optional variant, either `default`, `warning` or `critical`.
* @returns The row 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 = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520') });
* const node = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), variant: RowVariant.Warning });
* const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'));
* const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), RowVariant.Warning);
*/
export const row = createBuilder(NodeType.Row, RowStruct, [
'label',
'value',
'variant',
]);
//# sourceMappingURL=row.mjs.map