Skip to content

Commit a98029c

Browse files
feat: Add border radius to Image (#3023)
Add a border radius prop to `Image`. Progresses MetaMask/metamask-extension#29668
1 parent fe8d398 commit a98029c

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
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": "jyM2N8Y8sIxLacv1mwtPh41wGSt9lWsBNbFo9CSx7mM=",
10+
"shasum": "ssGPi4fxyZSvKOMXbVdOa/vnTx0qrq6WZWCUV91dLqo=",
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": "qHCkTRpYoHUFtt9Dd0nxQyw7Eblv0e5znQ39NszlJOo=",
10+
"shasum": "+342Ghzfo9UpTxJgqIPOieHvqRTnf4h00s8r0DpbozY=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snaps-sdk/src/jsx/components/Image.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { Image } from './Image';
22

33
describe('Image', () => {
44
it('renders an image', () => {
5-
const result = <Image src="<svg />" alt="Foo" />;
5+
const result = <Image src="<svg />" alt="Foo" borderRadius="medium" />;
66

77
expect(result).toStrictEqual({
88
type: 'Image',
99
key: null,
1010
props: {
1111
src: '<svg />',
1212
alt: 'Foo',
13+
borderRadius: 'medium',
1314
},
1415
});
1516
});

packages/snaps-sdk/src/jsx/components/Image.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createSnapComponent } from '../component';
1212
type ImageProps = {
1313
src: string;
1414
alt?: string | undefined;
15+
borderRadius?: 'none' | 'medium' | 'full' | undefined;
1516
};
1617

1718
const TYPE = 'Image';
@@ -27,6 +28,7 @@ const TYPE = 'Image';
2728
* You can use the `data:` URL scheme to embed images inside the SVG.
2829
* @param props.alt - The alternative text of the image, which describes the
2930
* image for users who cannot see it.
31+
* @param props.borderRadius - The border radius applied to the image.
3032
* @returns An image element.
3133
* @example
3234
* <Image src="<svg>...</svg>" alt="An example image" />

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,12 +1075,13 @@ describe('HeadingStruct', () => {
10751075
});
10761076

10771077
describe('ImageStruct', () => {
1078-
it.each([<Image src="<svg />" alt="alt" />, <Image src="<svg />" />])(
1079-
'validates an image element',
1080-
(value) => {
1081-
expect(is(value, ImageStruct)).toBe(true);
1082-
},
1083-
);
1078+
it.each([
1079+
<Image src="<svg />" alt="alt" />,
1080+
<Image src="<svg />" />,
1081+
<Image src="<svg />" alt="alt" borderRadius="medium" />,
1082+
])('validates an image element', (value) => {
1083+
expect(is(value, ImageStruct)).toBe(true);
1084+
});
10841085

10851086
it.each([
10861087
'foo',
@@ -1093,6 +1094,8 @@ describe('ImageStruct', () => {
10931094
<Image />,
10941095
// @ts-expect-error - Invalid props.
10951096
<Image src="<svg />" alt={42} />,
1097+
// @ts-expect-error - Invalid props.
1098+
<Image src="<svg />" borderRadius="52px" />,
10961099
<Text>foo</Text>,
10971100
<Box>
10981101
<Text>foo</Text>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ function elementWithSelectiveProps<
221221
export const ImageStruct: Describe<ImageElement> = element('Image', {
222222
src: svg(),
223223
alt: optional(string()),
224+
borderRadius: optional(
225+
nullUnion([literal('none'), literal('medium'), literal('full')]),
226+
),
224227
});
225228

226229
const IconNameStruct: Struct<`${IconName}`, null> = nullUnion(

0 commit comments

Comments
 (0)