Skip to content

Commit

Permalink
feat: Add the size prop to Heading (#2759)
Browse files Browse the repository at this point in the history
This PR adds an optional `size` prop to the `Heading` component. I can
be `md` or `lg`.
  • Loading branch information
GuillaumeRx authored Sep 25, 2024
1 parent 92fca8b commit 80b6497
Show file tree
Hide file tree
Showing 7 changed files with 26 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": "Rvk4nDRt8bofy5oUtavVGwVB0pnZ7BdsmO9V315Qs+w=",
"shasum": "Kn7XJHg0P1YYLU+sZF9pon4NXLadxLmUETLuLAn1qkw=",
"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": "3LsbiHzT2I8gHJPQCu6JbTiKKCy5XA2VQQdW9Qkn3XU=",
"shasum": "xvq90PFxbF6rSf1t2+LeGCP5oeby0u7bobCT2ySxpF0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
13 changes: 13 additions & 0 deletions packages/snaps-sdk/src/jsx/components/Heading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,17 @@ describe('Heading', () => {
},
});
});

it('renders a heading with a `lg` size', () => {
const result = <Heading size="lg">Foo</Heading>;

expect(result).toStrictEqual({
type: 'Heading',
key: null,
props: {
children: 'Foo',
size: 'lg',
},
});
});
});
5 changes: 5 additions & 0 deletions packages/snaps-sdk/src/jsx/components/Heading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { createSnapComponent } from '../component';
* The props of the {@link Heading} component.
*
* @property children - The text to display in the heading.
* @property size - The size of the heading.
*/
type HeadingProps = {
children: StringElement;
size?: 'md' | 'lg' | undefined;
};

const TYPE = 'Heading';
Expand All @@ -17,9 +19,12 @@ const TYPE = 'Heading';
*
* @param props - The props of the component.
* @param props.children - The text to display in the heading.
* @param props.size - The size of the heading.
* @returns A heading element.
* @example
* <Heading>Hello world!</Heading>
* @example
* <Heading size="lg">Hello world!</Heading>
*/
export const Heading = createSnapComponent<HeadingProps, typeof TYPE>(TYPE);

Expand Down
4 changes: 4 additions & 0 deletions packages/snaps-sdk/src/jsx/components/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export type TextColors =
* The props of the {@link Text} component.
*
* @property children - The text to display.
* @property alignment - The alignment of the text.
* @property color - The color of the text.
*/
export type TextProps = {
children: TextChildren;
Expand All @@ -39,6 +41,8 @@ const TYPE = 'Text';
* A text component, which is used to display text.
*
* @param props - The props of the component.
* @param props.alignment - The alignment of the text.
* @param props.color - The color of the text.
* @param props.children - The text to display.
* @returns A text element.
* @example
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ describe('SelectorStruct', () => {
});

describe('HeadingStruct', () => {
it.each([<Heading>Hello</Heading>])(
it.each([<Heading>Hello</Heading>, <Heading size="lg">Hello</Heading>])(
'validates a heading element',
(value) => {
expect(is(value, HeadingStruct)).toBe(true);
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-sdk/src/jsx/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ export const ValueStruct: Describe<ValueElement> = element('Value', {
*/
export const HeadingStruct: Describe<HeadingElement> = element('Heading', {
children: StringElementStruct,
size: optional(nullUnion([literal('md'), literal('lg')])),
});

/**
Expand Down

0 comments on commit 80b6497

Please sign in to comment.