Skip to content

Commit

Permalink
fix(snap): Use default buttons when hideSnapsBranding is true (#2…
Browse files Browse the repository at this point in the history
…7303)

## **Description**

This PR makes the button not use the snap branding when the
`hideSnapsBranding` flag is set to `true`.

It also fixes an issue with the snap homepage footer having a margin
when only one button is rendered in the footer.

The `snap-footer-button` was also renamed
`snap-ui-renderer__footer-button` to conform to the conventional naming
of ui elements used in the `snap-ui-renderer`

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27303?quickstart=1)

## **Related issues**

Fixes: N/A

## **Manual testing steps**

1. Go to test-snaps
2. Try the preinstalled example snap

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**


![image](https://github.com/user-attachments/assets/31e1fd4b-bc6b-40d9-8d33-d941a8088479)


![image](https://github.com/user-attachments/assets/4b7551cf-0b11-4fd4-83a2-2369f5feecae)

### **After**


![image](https://github.com/user-attachments/assets/c31cbc9c-0cd0-45a4-b48c-e52cfece9a41)


![image](https://github.com/user-attachments/assets/96f6bfaa-7dc6-4033-ab94-913dad2a4060)

## **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/develop/.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/develop/.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.
  • Loading branch information
GuillaumeRx committed Sep 20, 2024
1 parent 27d8a54 commit c323433
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 92 deletions.
2 changes: 1 addition & 1 deletion ui/components/app/app-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@import 'snaps/insight-warnings/index';
@import 'snaps/snap-authorship-header/index';
@import 'snaps/snap-authorship-pill/index';
@import 'snaps/snap-footer-button/index';
@import 'snaps/snap-ui-footer-button/index';
@import 'hold-to-reveal-button/index';
@import 'home-notification/index';
@import 'info-box/index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { SnapUITooltip } from '../snaps/snap-ui-tooltip';
import { SnapUICard } from '../snaps/snap-ui-card';
import { SnapUIAddress } from '../snaps/snap-ui-address';
import { SnapUISelector } from '../snaps/snap-ui-selector';
import { SnapFooterButton } from '../snaps/snap-footer-button';
import { SnapUIFooterButton } from '../snaps/snap-ui-footer-button';
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import { SnapAccountSuccessMessage } from '../../../pages/confirmations/components/snap-account-success-message';
import { SnapAccountErrorMessage } from '../../../pages/confirmations/components/snap-account-error-message';
Expand Down Expand Up @@ -106,7 +106,7 @@ export const safeComponentList = {
SnapUICard,
SnapUISelector,
SnapUIAddress,
SnapFooterButton,
SnapUIFooterButton,
FormTextField,
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
CreateSnapAccount,
Expand Down
45 changes: 0 additions & 45 deletions ui/components/app/snaps/snap-footer-button/index.scss

This file was deleted.

1 change: 0 additions & 1 deletion ui/components/app/snaps/snap-footer-button/index.ts

This file was deleted.

51 changes: 51 additions & 0 deletions ui/components/app/snaps/snap-ui-footer-button/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.snap-ui-renderer__footer-button {
&:not(.hide-snap-branding) {
&.mm-button-primary {
box-shadow: none;
color: var(--color-text-alternative);
background-color: var(--color-icon-default);

&:hover:not(&--disabled) {
opacity: 80%;
box-shadow: none;
}

&:active:not(&--disabled) {
opacity: 60%;
}
}

&.mm-button-secondary {
border-color: var(--color-icon-default);
color: var(--color-icon-default);

& span {
color: var(--color-icon-default);
}

&:hover:not(&--disabled) {
border-color: var(--color-icon-default);
color: var(--color-background-default);
background-color: var(--color-background-default-hover);
box-shadow: none;

& span {
color: var(--color-icon-default);
}
}

&:active:not(&--disabled) {
border-color: var(--color-icon-default);
opacity: 60%;

& span {
color: var(--color-icon-default);
}
}
}
}

&--disabled {
cursor: default !important;
}
}
1 change: 1 addition & 0 deletions ui/components/app/snaps/snap-ui-footer-button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './snap-ui-footer-button';
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {
UserInputEventType,
} from '@metamask/snaps-sdk';
import { useSelector } from 'react-redux';
import classnames from 'classnames';
import {
Button,
ButtonLinkProps,
ButtonProps,
ButtonSize,
IconSize,
} from '../../../component-library';
Expand All @@ -20,20 +21,23 @@ import { useSnapInterfaceContext } from '../../../../contexts/snaps';
import { SnapIcon } from '../snap-icon';
import { getHideSnapBranding } from '../../../../selectors';

type SnapFooterButtonProps = {
type SnapUIFooterButtonProps = {
name?: string;
variant?: ButtonVariant;
isSnapAction?: boolean;
onCancel?: () => void;
};

export const SnapFooterButton: FunctionComponent<
SnapFooterButtonProps & ButtonLinkProps<'button'>
export const SnapUIFooterButton: FunctionComponent<
SnapUIFooterButtonProps & ButtonProps<'button'>
> = ({
onCancel,
name,
children,
disabled = false,
isSnapAction = false,
type,
variant = ButtonVariant.Primary,
form,
...props
}) => {
Expand All @@ -55,15 +59,25 @@ export const SnapFooterButton: FunctionComponent<

const handleClick = isSnapAction ? handleSnapAction : onCancel;

const brandedButtonVariant = isSnapAction
? ButtonVariant.Primary
: ButtonVariant.Secondary;

const buttonVariant = hideSnapBranding ? variant : brandedButtonVariant;

return (
<Button
className="snap-footer-button"
className={classnames('snap-ui-renderer__footer-button', {
'snap-ui-renderer__footer-button--disabled': disabled,
'hide-snap-branding': hideSnapBranding,
})}
type={type}
form={form}
{...props}
size={ButtonSize.Lg}
block
variant={isSnapAction ? ButtonVariant.Primary : ButtonVariant.Secondary}
disabled={disabled}
variant={buttonVariant}
onClick={handleClick}
textProps={{
display: Display.Flex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const container: UIComponentFactory<BoxElement> = ({
className: 'snap-ui-renderer__footer-centered',
},
children: {
element: 'SnapFooterButton',
element: 'SnapUIFooterButton',
key: 'default-button',
props: {
onCancel,
Expand Down
43 changes: 23 additions & 20 deletions ui/components/app/snaps/snap-ui-renderer/components/footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Display,
FlexDirection,
} from '../../../../../helpers/constants/design-system';
import { UIComponentFactory, UIComponentParams } from './types';
import { ButtonVariant } from '../../../../component-library';
import { UIComponent, UIComponentFactory, UIComponentParams } from './types';
import { button as buttonFn } from './button';

export const DEFAULT_FOOTER = {
Expand All @@ -17,6 +18,7 @@ export const DEFAULT_FOOTER = {
display: Display.Flex,
flexDirection: FlexDirection.Row,
width: BlockSize.Full,
gap: 4,
padding: 4,
className: 'snap-ui-renderer__footer',
backgroundColor: BackgroundColor.backgroundDefault,
Expand All @@ -39,7 +41,7 @@ const getDefaultButtons = (
// If onCancel is omitted by the caller we assume that it is safe to not display the default footer.
if (children.length === 1 && onCancel) {
return {
element: 'SnapFooterButton',
element: 'SnapUIFooterButton',
key: 'default-button',
props: {
onCancel,
Expand All @@ -60,26 +62,27 @@ export const footer: UIComponentFactory<FooterElement> = ({
}) => {
const defaultButtons = getDefaultButtons(element, t, onCancel);

const footerChildren = (getJsxChildren(element) as ButtonElement[]).map(
(children, index) => {
const buttonMapped = buttonFn({
...params,
element: children,
} as UIComponentParams<ButtonElement>);
return {
element: 'SnapFooterButton',
key: `snap-footer-button-${buttonMapped.props?.name ?? index}`,
props: {
...buttonMapped.props,
isSnapAction: true,
},
children: buttonMapped.children,
};
},
);
const footerChildren: UIComponent[] = (
getJsxChildren(element) as ButtonElement[]
).map((children, index) => {
const buttonMapped = buttonFn({
...params,
element: children,
} as UIComponentParams<ButtonElement>);
return {
element: 'SnapUIFooterButton',
key: `snap-footer-button-${buttonMapped.props?.name ?? index}`,
props: {
...buttonMapped.props,
variant: index === 0 ? ButtonVariant.Secondary : ButtonVariant.Primary,
isSnapAction: true,
},
children: buttonMapped.children,
};
});

if (defaultButtons) {
footerChildren.unshift(defaultButtons);
footerChildren.unshift(defaultButtons as UIComponent);
}

return {
Expand Down
16 changes: 0 additions & 16 deletions ui/components/app/snaps/snap-ui-renderer/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,5 @@

&__footer {
margin-top: auto;

&-centered {
margin-top: auto;

& button {
&:first-child {
margin-right: 0;
}
}
}

& button {
&:first-child {
margin-right: 16px;
}
}
}
}

0 comments on commit c323433

Please sign in to comment.