Skip to content

Commit b3674e3

Browse files
fix: use gap for Snap UI spacing (#23369)
## **Description** This PR changes the Snap UI renderer to use `gap` for spacing between elements instead of margin. This is more effective than our previous attempts at normalizing spacing with nested panels etc. The new standard is `8px` of gap between everything except panels at the root level which has `16px` of gap (at the request of @eriknson). This PR removes all the margins for the existing components. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/23369?quickstart=1)
1 parent 3423aab commit b3674e3

File tree

10 files changed

+7
-37
lines changed

10 files changed

+7
-37
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export const SnapUIButton: FunctionComponent<
2424
<Button
2525
className="snap-ui-renderer__button"
2626
id={name}
27-
marginTop={1}
28-
marginBottom={1}
2927
type={type}
3028
onClick={handleClick}
3129
block

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const SnapUIForm: FunctionComponent<SnapUIFormProps> = ({
3030
id={name}
3131
display={Display.Flex}
3232
flexDirection={FlexDirection.Column}
33+
gap={2}
3334
>
3435
{children}
3536
</Box>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export type SnapUIImageProps = {
77
export const SnapUIImage = ({ value }: SnapUIImageProps) => {
88
const src = `data:image/svg+xml;utf8,${encodeURIComponent(value)}`;
99

10-
return <img style={{ marginTop: '4px', marginBottom: '4px' }} src={src} />;
10+
return <img src={src} />;
1111
};

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ export const SnapUIInput: FunctionComponent<
3636
<FormTextField
3737
className="snap-ui-renderer__input"
3838
id={name}
39-
marginBottom={1}
40-
marginTop={1}
4139
value={value}
4240
onChange={handleChange}
4341
{...props}

ui/components/app/snaps/snap-ui-markdown/snap-ui-markdown.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import SnapLinkWarning from '../snap-link-warning';
1717
const Paragraph = (props) => (
1818
<Text
1919
{...props}
20-
marginTop={1}
21-
marginBottom={1}
2220
variant={TextVariant.bodyMd}
2321
className="snap-ui-markdown__text"
2422
overflowWrap={OverflowWrap.Anywhere}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ export const copyable: UIComponentFactory<Copyable> = ({ element }) => ({
66
props: {
77
text: element.value,
88
sensitive: element.sensitive,
9-
marginTop: 1,
10-
marginBottom: 1,
119
},
1210
});

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ export const divider: UIComponentFactory<Divider> = () => ({
77
props: {
88
className: 'snap-ui-renderer__divider',
99
backgroundColor: BorderColor.borderDefault,
10-
marginTop: 1,
11-
marginBottom: 1,
1210
},
1311
});

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ export const heading: UIComponentFactory<Heading> = ({ element }) => ({
1111
props: {
1212
variant: TextVariant.headingSm,
1313
overflowWrap: OverflowWrap.Anywhere,
14-
marginTop: 1,
15-
marginBottom: 1,
1614
},
1715
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const row: UIComponentFactory<Row> = ({ element, ...params }) => ({
1313
// We do this to cause an overhang with certain confirmation row variants
1414
marginLeft: '-8px',
1515
marginRight: '-8px',
16+
marginTop: '0px',
17+
marginBottom: '0px',
1618
},
1719
},
1820
});

ui/components/app/snaps/snap-ui-renderer/index.scss

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
&__spinner {
77
width: 30px;
8-
margin-top: 4px;
9-
margin-bottom: 4px;
108
}
119

1210
&__divider {
@@ -16,29 +14,10 @@
1614

1715
&__panel {
1816
height: 100%;
17+
gap: 8px;
1918
}
2019

21-
&__content > *:first-child {
22-
margin-top: 0;
23-
}
24-
25-
&__content > &__panel > *:first-child {
26-
margin-top: 0;
27-
}
28-
29-
&__content > &__form > *:first-child {
30-
margin-top: 0;
31-
}
32-
33-
&__content > *:last-child {
34-
margin-bottom: 0;
35-
}
36-
37-
&__content > &__panel > *:last-child {
38-
margin-bottom: 0;
39-
}
40-
41-
&__content > &__form > *:last-child {
42-
margin-bottom: 0;
20+
&__content > &__panel:has(.snap-ui-renderer__panel) {
21+
gap: 16px;
4322
}
4423
}

0 commit comments

Comments
 (0)