From 39b99dcdfa86111db88b841f1c452edf855fdf44 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Mon, 16 Dec 2024 13:05:21 +0100 Subject: [PATCH 1/3] feat: Support fontWeight prop on Text --- packages/snaps-sdk/src/jsx/components/Text.test.tsx | 7 ++++++- packages/snaps-sdk/src/jsx/components/Text.ts | 1 + packages/snaps-sdk/src/jsx/validation.test.tsx | 3 +++ packages/snaps-sdk/src/jsx/validation.ts | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/snaps-sdk/src/jsx/components/Text.test.tsx b/packages/snaps-sdk/src/jsx/components/Text.test.tsx index 0cf2df8e14..3a66d6e8f8 100644 --- a/packages/snaps-sdk/src/jsx/components/Text.test.tsx +++ b/packages/snaps-sdk/src/jsx/components/Text.test.tsx @@ -53,7 +53,11 @@ describe('Text', () => { }); it('renders text with props', () => { - const result = Hello world!; + const result = ( + + Hello world! + + ); expect(result).toStrictEqual({ type: 'Text', @@ -61,6 +65,7 @@ describe('Text', () => { props: { children: 'Hello world!', size: 'sm', + fontWeight: 'medium', }, }); }); diff --git a/packages/snaps-sdk/src/jsx/components/Text.ts b/packages/snaps-sdk/src/jsx/components/Text.ts index 7fb99e4ba3..53f724e7b0 100644 --- a/packages/snaps-sdk/src/jsx/components/Text.ts +++ b/packages/snaps-sdk/src/jsx/components/Text.ts @@ -35,6 +35,7 @@ export type TextProps = { alignment?: 'start' | 'center' | 'end' | undefined; color?: TextColors | undefined; size?: 'sm' | 'md' | undefined; + fontWeight?: 'regular' | 'medium' | 'bold' | undefined; }; const TYPE = 'Text'; diff --git a/packages/snaps-sdk/src/jsx/validation.test.tsx b/packages/snaps-sdk/src/jsx/validation.test.tsx index f755a75d70..23bccc91c2 100644 --- a/packages/snaps-sdk/src/jsx/validation.test.tsx +++ b/packages/snaps-sdk/src/jsx/validation.test.tsx @@ -1182,6 +1182,7 @@ describe('TextStruct', () => { Hello, world , foo, + foo, ])('validates a text element', (value) => { expect(is(value, TextStruct)).toBe(true); }); @@ -1197,6 +1198,8 @@ describe('TextStruct', () => { , // @ts-expect-error - Invalid props. foo, + // @ts-expect-error - Invalid props. + foo, foo , diff --git a/packages/snaps-sdk/src/jsx/validation.ts b/packages/snaps-sdk/src/jsx/validation.ts index be3702912b..99a1ce24fb 100644 --- a/packages/snaps-sdk/src/jsx/validation.ts +++ b/packages/snaps-sdk/src/jsx/validation.ts @@ -721,6 +721,9 @@ export const TextStruct: Describe = element('Text', { ]), ), size: optional(nullUnion([literal('sm'), literal('md')])), + fontWeight: optional( + nullUnion([literal('regular'), literal('medium'), literal('bold')]), + ), }); /** From d149bb04a0f54367d57d941a82e2c646bbc6c1f3 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Mon, 16 Dec 2024 13:06:59 +0100 Subject: [PATCH 2/3] Update manifests --- packages/examples/packages/browserify-plugin/snap.manifest.json | 2 +- packages/examples/packages/browserify/snap.manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/examples/packages/browserify-plugin/snap.manifest.json b/packages/examples/packages/browserify-plugin/snap.manifest.json index d17e6c7427..712aba8313 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": "vr/JCeU5DXN3CeJIeLbZmr44rFnq+BGqQPng7kVxZGY=", + "shasum": "zWAvAKOxzUuZWjb75gYJw+izGqyBRcXoy2ocUCKMyGk=", "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 fe772a5cf5..f7b044698a 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": "4diRqHxV2Sr2wHuyoP1dL/WcSbS6HSVzxkDL+Iv0JNM=", + "shasum": "i5/9SEgHydVQotkWZ7ErpPhOI2N7Cg3U+lbR5/ApQI4=", "location": { "npm": { "filePath": "dist/bundle.js", From c6aeab39bb7607aa917f0f85e1a90d67a19cca93 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Mon, 16 Dec 2024 13:12:59 +0100 Subject: [PATCH 3/3] Add docs --- packages/snaps-sdk/src/jsx/components/Text.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/snaps-sdk/src/jsx/components/Text.ts b/packages/snaps-sdk/src/jsx/components/Text.ts index 53f724e7b0..9994713b2c 100644 --- a/packages/snaps-sdk/src/jsx/components/Text.ts +++ b/packages/snaps-sdk/src/jsx/components/Text.ts @@ -29,6 +29,7 @@ export type TextColors = * @property alignment - The alignment of the text. * @property color - The color of the text. * @property size - The size of the text. Defaults to `md`. + * @property fontWeight - The font weight of the text. Defaults to `regular`. */ export type TextProps = { children: TextChildren; @@ -48,6 +49,7 @@ const TYPE = 'Text'; * @param props.color - The color of the text. * @param props.children - The text to display. * @param props.size - The size of the text. Defaults to `md`. + * @param props.fontWeight - The font weight of the text. Defaults to `regular`. * @returns A text element. * @example * @@ -61,6 +63,10 @@ const TYPE = 'Text'; * * Hello world! * + * @example + * + * Hello world! + * */ export const Text = createSnapComponent(TYPE);