Skip to content

Commit

Permalink
feat: Add size prop to Button (#2953)
Browse files Browse the repository at this point in the history
Add `size` prop to buttons, letting devs size them similarly to `Text`. 

Progresses #2947
  • Loading branch information
FrederikBolding authored Dec 12, 2024
1 parent 51ab913 commit b0036f5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 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": "SquG9JvLanG/gJwBw5H1AZBlsthmv21Ci4Vn+sMemjM=",
"shasum": "eug1Oxfxo/X97epSDNuF3elpxJUBNGgPgfvvmVxShxo=",
"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": "pCp96i558WHqHIUZyZGUFcxAfOQ0afBHJ59nJB5ma78=",
"shasum": "Jh7Kcnzc5flRZM4SL8yQnMBj99YrmU91iLLaIxH2o/k=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
13 changes: 13 additions & 0 deletions packages/snaps-sdk/src/jsx/components/form/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,17 @@ describe('Button', () => {
key: null,
});
});

it('returns a button element with a size', () => {
const result = <Button size="sm">bar</Button>;

expect(result).toStrictEqual({
type: 'Button',
props: {
children: 'bar',
size: 'sm',
},
key: null,
});
});
});
2 changes: 2 additions & 0 deletions packages/snaps-sdk/src/jsx/components/form/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { ImageElement } from '../Image';
* Defaults to `'button'`.
* @property variant - The variant of the button, i.e., `'primary'` or
* `'destructive'`. Defaults to `'primary'`.
* @property size - The size of the button. Defaults to `md`.
* @property disabled - Whether the button is disabled. Defaults to `false`.
* @property loading - Whether the button is loading. Defaults to `false`.
* @property form - The name of the form component to associate the button with.
Expand All @@ -24,6 +25,7 @@ export type ButtonProps = {
name?: string | undefined;
type?: 'button' | 'submit' | undefined;
variant?: 'primary' | 'destructive' | undefined;
size?: 'sm' | 'md' | undefined;
disabled?: boolean | undefined;
loading?: boolean | undefined;
form?: string | undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ describe('ButtonStruct', () => {
<Image src="<svg></svg>" />
</Button>,
<Button form="foo">bar</Button>,
<Button size="sm">bar</Button>,
])('validates a button element', (value) => {
expect(is(value, ButtonStruct)).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 @@ -244,6 +244,7 @@ export const ButtonStruct: Describe<ButtonElement> = element('Button', {
name: optional(string()),
type: optional(nullUnion([literal('button'), literal('submit')])),
variant: optional(nullUnion([literal('primary'), literal('destructive')])),
size: optional(nullUnion([literal('sm'), literal('md')])),
disabled: optional(boolean()),
loading: optional(boolean()),
form: optional(string()),
Expand Down

0 comments on commit b0036f5

Please sign in to comment.