Skip to content

Commit bf1e4d6

Browse files
david0xdFrederikBolding
authored andcommitted
feat(snaps): Add loading variant to Snap UI button (#28997)
## **Description** This PR enables loading button variant for Snaps UI. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28997?quickstart=1) #### Notes - Targets Snaps release integration PR: #29275 ## **Related issues** Fixes: MetaMask/snaps#2694 ## **Related PR dependencies** Snaps monorepo: MetaMask/snaps#2930 ## **Manual testing steps** 1. Create some example Snap for testing and add Snap UI Button with `loading` variant. Example: ```TypeScript <Button variant="loading">Loading button</Button> ``` ## **Screenshots/Recordings** ### **Before** Loading button variant was not available before. ### **After** https://github.com/user-attachments/assets/5afea22c-1951-4475-a908-aa5b97eafb6b ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent a97f2b4 commit bf1e4d6

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

ui/components/app/snaps/snap-ui-button/snap-ui-button.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React, { FunctionComponent, MouseEvent as ReactMouseEvent } from 'react';
22
import classnames from 'classnames';
33
import { ButtonType, UserInputEventType } from '@metamask/snaps-sdk';
4-
import { ButtonLinkProps, Text } from '../../../component-library';
4+
import {
5+
ButtonLinkProps,
6+
Icon,
7+
IconName,
8+
Text,
9+
} from '../../../component-library';
510
import {
611
FontWeight,
712
TextColor,
@@ -11,6 +16,7 @@ import { useSnapInterfaceContext } from '../../../../contexts/snaps';
1116
export type SnapUIButtonProps = {
1217
name?: string;
1318
textVariant: ButtonLinkProps<'button'>['variant'];
19+
loading?: boolean;
1420
};
1521

1622
const COLORS = {
@@ -27,6 +33,7 @@ export const SnapUIButton: FunctionComponent<
2733
type = ButtonType.Button,
2834
variant = 'primary',
2935
disabled = false,
36+
loading = false,
3037
className = '',
3138
textVariant,
3239
...props
@@ -63,7 +70,14 @@ export const SnapUIButton: FunctionComponent<
6370
variant={textVariant}
6471
{...props}
6572
>
66-
{children}
73+
{loading ? (
74+
<Icon
75+
name={IconName.Loading}
76+
style={{ animation: 'spin 1.2s linear infinite' }}
77+
/>
78+
) : (
79+
children
80+
)}
6781
</Text>
6882
);
6983
};

ui/components/app/snaps/snap-ui-footer-button/snap-ui-footer-button.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
Button,
1111
ButtonProps,
1212
ButtonSize,
13+
Icon,
14+
IconName,
1315
IconSize,
1416
} from '../../../component-library';
1517
import {
@@ -35,6 +37,7 @@ export const SnapUIFooterButton: FunctionComponent<
3537
name,
3638
children,
3739
disabled = false,
40+
loading = false,
3841
isSnapAction = false,
3942
type,
4043
variant = ButtonVariant.Primary,
@@ -85,10 +88,17 @@ export const SnapUIFooterButton: FunctionComponent<
8588
flexDirection: FlexDirection.Row,
8689
}}
8790
>
88-
{isSnapAction && !hideSnapBranding && (
91+
{isSnapAction && !hideSnapBranding && !loading && (
8992
<SnapIcon snapId={snapId} avatarSize={IconSize.Sm} marginRight={2} />
9093
)}
91-
{children}
94+
{loading ? (
95+
<Icon
96+
name={IconName.Loading}
97+
style={{ animation: 'spin 1.2s linear infinite' }}
98+
/>
99+
) : (
100+
children
101+
)}
92102
</Button>
93103
);
94104
};

ui/components/app/snaps/snap-ui-renderer/components/button.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const button: UIComponentFactory<ButtonElement> = ({
1616
variant: element.props.variant,
1717
name: element.props.name,
1818
disabled: element.props.disabled,
19+
loading: element.props.loading,
1920
textVariant:
2021
element.props.size === 'sm' ? TextVariant.bodySm : TextVariant.bodyMd,
2122
},

0 commit comments

Comments
 (0)