Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add the size prop to Heading #2759

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Comment on lines +44 to +45
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also added some missing JSDOC params to 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
Loading