Skip to content

Commit

Permalink
feat: Support fontWeight prop on Text (#2959)
Browse files Browse the repository at this point in the history
Add support for specifying the `fontWeight` prop on the `Text`
component.
  • Loading branch information
FrederikBolding authored Dec 16, 2024
1 parent 21ee99d commit ba6c908
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/browserify/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion packages/snaps-sdk/src/jsx/components/Text.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ describe('Text', () => {
});

it('renders text with props', () => {
const result = <Text size="sm">Hello world!</Text>;
const result = (
<Text size="sm" fontWeight="medium">
Hello world!
</Text>
);

expect(result).toStrictEqual({
type: 'Text',
key: null,
props: {
children: 'Hello world!',
size: 'sm',
fontWeight: 'medium',
},
});
});
Expand Down
7 changes: 7 additions & 0 deletions packages/snaps-sdk/src/jsx/components/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ 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;
alignment?: 'start' | 'center' | 'end' | undefined;
color?: TextColors | undefined;
size?: 'sm' | 'md' | undefined;
fontWeight?: 'regular' | 'medium' | 'bold' | undefined;
};

const TYPE = 'Text';
Expand All @@ -47,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
* <Text>
Expand All @@ -60,6 +63,10 @@ const TYPE = 'Text';
* <Text size="sm">
* Hello <Bold>world</Bold>!
* </Text>
* @example
* <Text fontWeight="medium">
* Hello <Bold>world</Bold>!
* </Text>
*/
export const Text = createSnapComponent<TextProps, typeof TYPE>(TYPE);

Expand Down
3 changes: 3 additions & 0 deletions packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ describe('TextStruct', () => {
Hello, <Bold>world</Bold>
</Text>,
<Text size="sm">foo</Text>,
<Text fontWeight="medium">foo</Text>,
])('validates a text element', (value) => {
expect(is(value, TextStruct)).toBe(true);
});
Expand All @@ -1197,6 +1198,8 @@ describe('TextStruct', () => {
<Text />,
// @ts-expect-error - Invalid props.
<Text foo="bar">foo</Text>,
// @ts-expect-error - Invalid props.
<Text fontWeight="bar">foo</Text>,
<Box>
<Text>foo</Text>
</Box>,
Expand Down
3 changes: 3 additions & 0 deletions packages/snaps-sdk/src/jsx/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ export const TextStruct: Describe<TextElement> = element('Text', {
]),
),
size: optional(nullUnion([literal('sm'), literal('md')])),
fontWeight: optional(
nullUnion([literal('regular'), literal('medium'), literal('bold')]),
),
});

/**
Expand Down

0 comments on commit ba6c908

Please sign in to comment.