From dfaea7181335ef1e39fb6e7c1e768963fdc1c8eb Mon Sep 17 00:00:00 2001 From: Olaf Tomalka Date: Thu, 12 Sep 2024 13:09:21 +0200 Subject: [PATCH] Added form property to Button JSX component (#2712) This will allow `Button` in the `Footer` be linked to a specific form so that it also can submit the form. ```tsx
``` --------- Co-authored-by: Maarten Zuidhoorn --- .../packages/browserify-plugin/snap.manifest.json | 2 +- .../examples/packages/browserify/snap.manifest.json | 2 +- .../src/jsx/components/form/Button.test.tsx | 13 +++++++++++++ .../snaps-sdk/src/jsx/components/form/Button.ts | 2 ++ packages/snaps-sdk/src/jsx/validation.test.tsx | 1 + packages/snaps-sdk/src/jsx/validation.ts | 1 + 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/examples/packages/browserify-plugin/snap.manifest.json b/packages/examples/packages/browserify-plugin/snap.manifest.json index 6ed9299c8c..e0c764b96e 100644 --- a/packages/examples/packages/browserify-plugin/snap.manifest.json +++ b/packages/examples/packages/browserify-plugin/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "A3JhkncC8nBdzAEjqVa3RtSFRAGpaO+T0ABpCA0CKpM=", + "shasum": "/Q9cCxwaArV8k2VM4puQEsbni/bpNbcPEUi1s+XOL/U=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/browserify/snap.manifest.json b/packages/examples/packages/browserify/snap.manifest.json index 48502a0930..649c3152ba 100644 --- a/packages/examples/packages/browserify/snap.manifest.json +++ b/packages/examples/packages/browserify/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "I4QX3z8+PVtiPoI5o9VcKsb4rSI2kDC6DiS+ybY/ycA=", + "shasum": "+fLeOqcKGPU0z+W2NcYDN9RwCl1ft1avMUe5fG1SUX0=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snaps-sdk/src/jsx/components/form/Button.test.tsx b/packages/snaps-sdk/src/jsx/components/form/Button.test.tsx index 472142f52e..2a1ef1f0d7 100644 --- a/packages/snaps-sdk/src/jsx/components/form/Button.test.tsx +++ b/packages/snaps-sdk/src/jsx/components/form/Button.test.tsx @@ -50,4 +50,17 @@ describe('Button', () => { key: null, }); }); + + it('returns a button element with a form', () => { + const result = ; + + expect(result).toStrictEqual({ + type: 'Button', + props: { + children: 'bar', + form: 'foo', + }, + key: null, + }); + }); }); diff --git a/packages/snaps-sdk/src/jsx/components/form/Button.ts b/packages/snaps-sdk/src/jsx/components/form/Button.ts index da9179e8d8..e41c0e6d01 100644 --- a/packages/snaps-sdk/src/jsx/components/form/Button.ts +++ b/packages/snaps-sdk/src/jsx/components/form/Button.ts @@ -16,6 +16,7 @@ import type { ImageElement } from '../Image'; * @property variant - The variant of the button, i.e., `'primary'` or * `'destructive'`. Defaults to `'primary'`. * @property disabled - Whether the button is disabled. Defaults to `false`. + * @property form - The name of the form component to associate the button with. */ export type ButtonProps = { children: SnapsChildren; @@ -23,6 +24,7 @@ export type ButtonProps = { type?: 'button' | 'submit' | undefined; variant?: 'primary' | 'destructive' | undefined; disabled?: boolean | undefined; + form?: string | undefined; }; const TYPE = 'Button'; diff --git a/packages/snaps-sdk/src/jsx/validation.test.tsx b/packages/snaps-sdk/src/jsx/validation.test.tsx index 5b7b538d29..8c6137e70b 100644 --- a/packages/snaps-sdk/src/jsx/validation.test.tsx +++ b/packages/snaps-sdk/src/jsx/validation.test.tsx @@ -169,6 +169,7 @@ describe('ButtonStruct', () => { , + , ])('validates a button element', (value) => { expect(is(value, ButtonStruct)).toBe(true); }); diff --git a/packages/snaps-sdk/src/jsx/validation.ts b/packages/snaps-sdk/src/jsx/validation.ts index 7f98a654e8..79109fef4c 100644 --- a/packages/snaps-sdk/src/jsx/validation.ts +++ b/packages/snaps-sdk/src/jsx/validation.ts @@ -203,6 +203,7 @@ export const ButtonStruct: Describe = element('Button', { type: optional(nullUnion([literal('button'), literal('submit')])), variant: optional(nullUnion([literal('primary'), literal('destructive')])), disabled: optional(boolean()), + form: optional(string()), }); /**