Skip to content

Commit abbe8f7

Browse files
FrederikBoldingPatrykLucka
authored andcommitted
feat: Add size prop to Button (#2953)
Add `size` prop to buttons, letting devs size them similarly to `Text`. Progresses #2947
1 parent cda2586 commit abbe8f7

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-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": "SquG9JvLanG/gJwBw5H1AZBlsthmv21Ci4Vn+sMemjM=",
10+
"shasum": "eug1Oxfxo/X97epSDNuF3elpxJUBNGgPgfvvmVxShxo=",
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": "pCp96i558WHqHIUZyZGUFcxAfOQ0afBHJ59nJB5ma78=",
10+
"shasum": "Jh7Kcnzc5flRZM4SL8yQnMBj99YrmU91iLLaIxH2o/k=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snaps-sdk/src/jsx/components/form/Button.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,17 @@ describe('Button', () => {
8282
key: null,
8383
});
8484
});
85+
86+
it('returns a button element with a size', () => {
87+
const result = <Button size="sm">bar</Button>;
88+
89+
expect(result).toStrictEqual({
90+
type: 'Button',
91+
props: {
92+
children: 'bar',
93+
size: 'sm',
94+
},
95+
key: null,
96+
});
97+
});
8598
});

packages/snaps-sdk/src/jsx/components/form/Button.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { ImageElement } from '../Image';
1515
* Defaults to `'button'`.
1616
* @property variant - The variant of the button, i.e., `'primary'` or
1717
* `'destructive'`. Defaults to `'primary'`.
18+
* @property size - The size of the button. Defaults to `md`.
1819
* @property disabled - Whether the button is disabled. Defaults to `false`.
1920
* @property loading - Whether the button is loading. Defaults to `false`.
2021
* @property form - The name of the form component to associate the button with.
@@ -24,6 +25,7 @@ export type ButtonProps = {
2425
name?: string | undefined;
2526
type?: 'button' | 'submit' | undefined;
2627
variant?: 'primary' | 'destructive' | undefined;
28+
size?: 'sm' | 'md' | undefined;
2729
disabled?: boolean | undefined;
2830
loading?: boolean | undefined;
2931
form?: string | undefined;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ describe('ButtonStruct', () => {
175175
<Image src="<svg></svg>" />
176176
</Button>,
177177
<Button form="foo">bar</Button>,
178+
<Button size="sm">bar</Button>,
178179
])('validates a button element', (value) => {
179180
expect(is(value, ButtonStruct)).toBe(true);
180181
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export const ButtonStruct: Describe<ButtonElement> = element('Button', {
244244
name: optional(string()),
245245
type: optional(nullUnion([literal('button'), literal('submit')])),
246246
variant: optional(nullUnion([literal('primary'), literal('destructive')])),
247+
size: optional(nullUnion([literal('sm'), literal('md')])),
247248
disabled: optional(boolean()),
248249
loading: optional(boolean()),
249250
form: optional(string()),

0 commit comments

Comments
 (0)