Skip to content

Commit 90b2e39

Browse files
authored
Add loading variant for Snaps UI Button (#2930)
This PR adds loading variant for Snap UI button. This button shows loading icon with an infinite animation. Related ticket: #2694 Related extension PR: MetaMask/metamask-extension#28997 Loading button in action: https://github.com/user-attachments/assets/a2f15262-dc68-44cb-bbd2-22e288d9d09c
1 parent 9d8915b commit 90b2e39

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-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": "d1js9Y4zJwk7n/e47V5fdMreo1FBtVKl4GtPhfckZrs=",
10+
"shasum": "lyy+HECzOFQzuzjyD1nas6GPc4kMt340ChbqQZl7uEo=",
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": "2OhDjaajEbvT1LdHB1G/Jl9NpfRtJxYl87w1c+1eJck=",
10+
"shasum": "k7NYoT8jI2E4u785PN5PoruwtjF18KNOSagNY9fS44U=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,23 @@ describe('Button', () => {
6363
key: null,
6464
});
6565
});
66+
67+
it('returns a button element with a variant and loading state', () => {
68+
const result = (
69+
<Button type="button" variant="primary" loading={true}>
70+
foo
71+
</Button>
72+
);
73+
74+
expect(result).toStrictEqual({
75+
type: 'Button',
76+
props: {
77+
children: 'foo',
78+
type: 'button',
79+
variant: 'primary',
80+
loading: true,
81+
},
82+
key: null,
83+
});
84+
});
6685
});

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

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ describe('ButtonStruct', () => {
164164
<Button type="submit">foo</Button>,
165165
<Button variant="destructive">foo</Button>,
166166
<Button disabled={true}>foo</Button>,
167+
<Button variant="primary" loading={true}>
168+
foo
169+
</Button>,
167170
<Button key="button">foo</Button>,
168171
<Button>
169172
<Icon name="wifi" />

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export const ButtonStruct: Describe<ButtonElement> = element('Button', {
245245
type: optional(nullUnion([literal('button'), literal('submit')])),
246246
variant: optional(nullUnion([literal('primary'), literal('destructive')])),
247247
disabled: optional(boolean()),
248+
loading: optional(boolean()),
248249
form: optional(string()),
249250
});
250251

0 commit comments

Comments
 (0)