Skip to content

Commit cbe55de

Browse files
GuillaumeRxMrtenz
andauthored
Add size prop to Text (#2908)
This adds a new optional prop to `Text` called `size`. It allows two values, `sm` and `md` that relates to `bodySm` and `bodyMd` in extension. It should default to `md`. Fixes: #2905 --------- Co-authored-by: Maarten Zuidhoorn <[email protected]>
1 parent a5714d5 commit cbe55de

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

packages/examples/packages/browserify-plugin/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "IdAFrQlUYgQaMo/lbXgEJOMKTFbB9RYylXwPvUFT6As=",
10+
"shasum": "ecGX3duI1nyJ8BOjkIPLze204JXMQKL8Eq1ir8Mm/dg=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/browserify/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "bzhrHkJoo2dRz2utZ10KRNL2X2mgRxkur3DrGXHbNOc=",
10+
"shasum": "KSkMBlnuET6wdxlrTCFlg6h1GDiCK8ShQoTbKPse0Ek=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snaps-sdk/src/jsx/components/Text.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,17 @@ describe('Text', () => {
5151
},
5252
});
5353
});
54+
55+
it('renders text with props', () => {
56+
const result = <Text size="sm">Hello world!</Text>;
57+
58+
expect(result).toStrictEqual({
59+
type: 'Text',
60+
key: null,
61+
props: {
62+
children: 'Hello world!',
63+
size: 'sm',
64+
},
65+
});
66+
});
5467
});

packages/snaps-sdk/src/jsx/components/Text.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ export type TextColors =
2828
* @property children - The text to display.
2929
* @property alignment - The alignment of the text.
3030
* @property color - The color of the text.
31+
* @property size - The size of the text. Defaults to `md`.
3132
*/
3233
export type TextProps = {
3334
children: TextChildren;
3435
alignment?: 'start' | 'center' | 'end' | undefined;
3536
color?: TextColors | undefined;
37+
size?: 'sm' | 'md' | undefined;
3638
};
3739

3840
const TYPE = 'Text';
@@ -44,6 +46,7 @@ const TYPE = 'Text';
4446
* @param props.alignment - The alignment of the text.
4547
* @param props.color - The color of the text.
4648
* @param props.children - The text to display.
49+
* @param props.size - The size of the text. Defaults to `md`.
4750
* @returns A text element.
4851
* @example
4952
* <Text>
@@ -53,6 +56,10 @@ const TYPE = 'Text';
5356
* <Text alignment="end">
5457
* Hello <Bold>world</Bold>!
5558
* </Text>
59+
* @example
60+
* <Text size="sm">
61+
* Hello <Bold>world</Bold>!
62+
* </Text>
5663
*/
5764
export const Text = createSnapComponent<TextProps, typeof TYPE>(TYPE);
5865

packages/snaps-sdk/src/jsx/validation.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ describe('TextStruct', () => {
11771177
<Text>
11781178
Hello, <Bold>world</Bold>
11791179
</Text>,
1180+
<Text size="sm">foo</Text>,
11801181
])('validates a text element', (value) => {
11811182
expect(is(value, TextStruct)).toBe(true);
11821183
});

packages/snaps-sdk/src/jsx/validation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ export const TextStruct: Describe<TextElement> = element('Text', {
713713
literal('warning'),
714714
]),
715715
),
716+
size: optional(nullUnion([literal('sm'), literal('md')])),
716717
});
717718

718719
/**

0 commit comments

Comments
 (0)