UNPKG

@metamask/snaps-sdk

Version:

A library containing the core functionality for building MetaMask Snaps

69 lines 2.27 kB
import { array, assign, lazy, object } from "@metamask/superstruct"; import { AddressStruct } from "./address.mjs"; import { ButtonStruct } from "./button.mjs"; import { CopyableStruct } from "./copyable.mjs"; import { DividerStruct } from "./divider.mjs"; import { FormStruct } from "./form.mjs"; import { HeadingStruct } from "./heading.mjs"; import { ImageStruct } from "./image.mjs"; import { InputStruct } from "./input.mjs"; import { RowStruct } from "./row.mjs"; import { SpinnerStruct } from "./spinner.mjs"; import { TextStruct } from "./text.mjs"; import { typedUnion, literal } from "../../internals/index.mjs"; import { createBuilder } from "../builder.mjs"; import { NodeStruct, NodeType } from "../nodes.mjs"; /** * @internal */ export const ParentStruct = assign(NodeStruct, object({ // This node references itself indirectly, so we need to use `lazy()`. // eslint-disable-next-line @typescript-eslint/no-use-before-define children: array(lazy(() => ComponentStruct)), })); /** * @internal */ export const PanelStruct = assign(ParentStruct, object({ type: literal(NodeType.Panel), })); /** * Create a {@link Panel} node. * * @param args - The node arguments. This can be either an array of children, or * an object with a `children` property. * @param args.children - The child nodes of the panel. This can be any valid * {@link Component}. * @returns The panel 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 * const node = panel({ * children: [ * heading({ text: 'Hello, world!' }), * text({ text: 'This is a panel.' }), * ], * }); * * const node = panel([ * heading('Hello, world!'), * text('This is a panel.'), * ]); */ export const panel = createBuilder(NodeType.Panel, PanelStruct, ['children']); // This is defined separately from `Component` to avoid circular dependencies. export const ComponentStruct = typedUnion([ CopyableStruct, DividerStruct, HeadingStruct, ImageStruct, PanelStruct, SpinnerStruct, TextStruct, RowStruct, AddressStruct, InputStruct, FormStruct, ButtonStruct, ]); //# sourceMappingURL=panel.mjs.map