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 size prop to Button #2953

Merged
merged 3 commits into from
Dec 12, 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": "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
Loading