Skip to content

Commit ba6c908

Browse files
feat: Support fontWeight prop on Text (#2959)
Add support for specifying the `fontWeight` prop on the `Text` component.
1 parent 21ee99d commit ba6c908

File tree

6 files changed

+21
-3
lines changed

6 files changed

+21
-3
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": "vr/JCeU5DXN3CeJIeLbZmr44rFnq+BGqQPng7kVxZGY=",
10+
"shasum": "zWAvAKOxzUuZWjb75gYJw+izGqyBRcXoy2ocUCKMyGk=",
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": "4diRqHxV2Sr2wHuyoP1dL/WcSbS6HSVzxkDL+Iv0JNM=",
10+
"shasum": "i5/9SEgHydVQotkWZ7ErpPhOI2N7Cg3U+lbR5/ApQI4=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,19 @@ describe('Text', () => {
5353
});
5454

5555
it('renders text with props', () => {
56-
const result = <Text size="sm">Hello world!</Text>;
56+
const result = (
57+
<Text size="sm" fontWeight="medium">
58+
Hello world!
59+
</Text>
60+
);
5761

5862
expect(result).toStrictEqual({
5963
type: 'Text',
6064
key: null,
6165
props: {
6266
children: 'Hello world!',
6367
size: 'sm',
68+
fontWeight: 'medium',
6469
},
6570
});
6671
});

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ export type TextColors =
2929
* @property alignment - The alignment of the text.
3030
* @property color - The color of the text.
3131
* @property size - The size of the text. Defaults to `md`.
32+
* @property fontWeight - The font weight of the text. Defaults to `regular`.
3233
*/
3334
export type TextProps = {
3435
children: TextChildren;
3536
alignment?: 'start' | 'center' | 'end' | undefined;
3637
color?: TextColors | undefined;
3738
size?: 'sm' | 'md' | undefined;
39+
fontWeight?: 'regular' | 'medium' | 'bold' | undefined;
3840
};
3941

4042
const TYPE = 'Text';
@@ -47,6 +49,7 @@ const TYPE = 'Text';
4749
* @param props.color - The color of the text.
4850
* @param props.children - The text to display.
4951
* @param props.size - The size of the text. Defaults to `md`.
52+
* @param props.fontWeight - The font weight of the text. Defaults to `regular`.
5053
* @returns A text element.
5154
* @example
5255
* <Text>
@@ -60,6 +63,10 @@ const TYPE = 'Text';
6063
* <Text size="sm">
6164
* Hello <Bold>world</Bold>!
6265
* </Text>
66+
* @example
67+
* <Text fontWeight="medium">
68+
* Hello <Bold>world</Bold>!
69+
* </Text>
6370
*/
6471
export const Text = createSnapComponent<TextProps, typeof TYPE>(TYPE);
6572

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,7 @@ describe('TextStruct', () => {
11821182
Hello, <Bold>world</Bold>
11831183
</Text>,
11841184
<Text size="sm">foo</Text>,
1185+
<Text fontWeight="medium">foo</Text>,
11851186
])('validates a text element', (value) => {
11861187
expect(is(value, TextStruct)).toBe(true);
11871188
});
@@ -1197,6 +1198,8 @@ describe('TextStruct', () => {
11971198
<Text />,
11981199
// @ts-expect-error - Invalid props.
11991200
<Text foo="bar">foo</Text>,
1201+
// @ts-expect-error - Invalid props.
1202+
<Text fontWeight="bar">foo</Text>,
12001203
<Box>
12011204
<Text>foo</Text>
12021205
</Box>,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,9 @@ export const TextStruct: Describe<TextElement> = element('Text', {
721721
]),
722722
),
723723
size: optional(nullUnion([literal('sm'), literal('md')])),
724+
fontWeight: optional(
725+
nullUnion([literal('regular'), literal('medium'), literal('bold')]),
726+
),
724727
});
725728

726729
/**

0 commit comments

Comments
 (0)