Skip to content

Commit 7545970

Browse files
authored
feat(snaps): Add support for Address in Card title (#28539)
## **Description** This PR adds support for the `Address` component in the `Card` title following this PR: MetaMask/snaps#2894 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28539?quickstart=1) ## **Related issues** ## **Manual testing steps** ```jsx <Card image='foo' title={<Address address={your address in MetaMask} displayName avatar={false} />} description='bar' extra='foobar' /> ``` ## **Screenshots/Recordings** ![241119_12h11m39s_screenshot](https://github.com/user-attachments/assets/9b32d7f6-aef4-415b-800a-350cde6696d8) ## **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.
1 parent 345fbe3 commit 7545970

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FunctionComponent } from 'react';
1+
import React, { FunctionComponent, ReactNode } from 'react';
22
import {
33
Display,
44
FlexDirection,
@@ -13,7 +13,7 @@ import { SnapUIImage } from '../snap-ui-image';
1313

1414
export type SnapUICardProps = {
1515
image?: string | undefined;
16-
title: string;
16+
title: string | ReactNode;
1717
description?: string | undefined;
1818
value: string;
1919
extra?: string | undefined;
Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
import { CardElement } from '@metamask/snaps-sdk/jsx';
2+
import { mapToTemplate } from '../utils';
23
import { UIComponentFactory } from './types';
34

4-
export const card: UIComponentFactory<CardElement> = ({ element }) => ({
5-
element: 'SnapUICard',
6-
props: {
7-
image: element.props.image,
8-
title: element.props.title,
9-
description: element.props.description,
10-
value: element.props.value,
11-
extra: element.props.extra,
12-
},
13-
});
5+
export const card: UIComponentFactory<CardElement> = ({
6+
element,
7+
...params
8+
}) => {
9+
if (typeof element.props.title !== 'string') {
10+
return {
11+
element: 'SnapUICard',
12+
props: {
13+
image: element.props.image,
14+
description: element.props.description,
15+
value: element.props.value,
16+
extra: element.props.extra,
17+
},
18+
propComponents: {
19+
title: mapToTemplate({ element: element.props.title, ...params }),
20+
},
21+
};
22+
}
23+
24+
return {
25+
element: 'SnapUICard',
26+
props: {
27+
image: element.props.image,
28+
title: element.props.title,
29+
description: element.props.description,
30+
value: element.props.value,
31+
extra: element.props.extra,
32+
},
33+
};
34+
};

0 commit comments

Comments
 (0)