Skip to content

Commit d71d6d8

Browse files
authored
Add Skeleton component (#3024)
### Add Skeleton component. Related PR in extension: MetaMask/metamask-extension#29764 #### Code example JSX code used for testing: ```typescript <Container> <Box> <Text>Skeleton inside text component:</Text> <Text> <Skeleton /> </Text> <Text>Classic Skeleton inside a box:</Text> <Skeleton /> <Text>Top level Skeleton: </Text> <Skeleton height={32} width="100%" /> <Skeleton height={16} width="50%" borderRadius="none" /> <Skeleton height={16} width="25%" borderRadius="medium" /> <Skeleton height={32} width={32} borderRadius="full" /> <Text>Skeleton inside Section: </Text> <Section> <Skeleton height={32} width="100%" /> <Skeleton height={16} width="50%" borderRadius="none" /> <Skeleton height={16} width="25%" borderRadius="medium" /> <Skeleton height={32} width={32} borderRadius="full" /> </Section> <Text>Skeleton inside Row: </Text> <Row label="Row"> <Skeleton height={22} width="30%" /> </Row> <Row label="Row"> <Text> <Skeleton height={22} width={40} /> </Text> </Row> </Box> </Container> ``` #### Screenshots ![Screenshot 2025-01-17 at 13 09 22](https://github.com/user-attachments/assets/7ebd5646-6664-4b72-8578-33e7db6557a5)
1 parent 657cf53 commit d71d6d8

File tree

14 files changed

+144
-14
lines changed

14 files changed

+144
-14
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": "ssGPi4fxyZSvKOMXbVdOa/vnTx0qrq6WZWCUV91dLqo=",
10+
"shasum": "B0senywfM+w5lQ+iMvK+bVcKJ6VeLDj7HiUVYR5Cuag=",
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": "+342Ghzfo9UpTxJgqIPOieHvqRTnf4h00s8r0DpbozY=",
10+
"shasum": "PS0U7SHYXWpFhO8QMtArHKU1rFzMkwtTLFlc3/g1HQ4=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snaps-rpc-methods/src/permitted/createInterface.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('snap_createInterface', () => {
141141
error: {
142142
code: -32602,
143143
message:
144-
'Invalid params: At path: ui -- Expected type to be one of: "Address", "Bold", "Box", "Button", "Copyable", "Divider", "Dropdown", "RadioGroup", "Field", "FileInput", "Form", "Heading", "Input", "Image", "Italic", "Link", "Row", "Spinner", "Text", "Tooltip", "Checkbox", "Card", "Icon", "Selector", "Section", "Avatar", "Banner", "Container", but received: undefined.',
144+
'Invalid params: At path: ui -- Expected type to be one of: "Address", "Bold", "Box", "Button", "Copyable", "Divider", "Dropdown", "RadioGroup", "Field", "FileInput", "Form", "Heading", "Input", "Image", "Italic", "Link", "Row", "Spinner", "Text", "Tooltip", "Checkbox", "Card", "Icon", "Selector", "Section", "Avatar", "Banner", "Skeleton", "Container", but received: undefined.',
145145
stack: expect.any(String),
146146
},
147147
id: 1,

packages/snaps-sdk/src/internals/structs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('typedUnion', () => {
6666
const result = validate(Text({}), unionStruct);
6767

6868
expect(result[0]?.message).toBe(
69-
'At path: props.children -- Expected type to be one of: "Bold", "Italic", "Link", "Icon", but received: undefined',
69+
'At path: props.children -- Expected type to be one of: "Bold", "Italic", "Link", "Icon", "Skeleton", but received: undefined',
7070
);
7171
});
7272

@@ -75,7 +75,7 @@ describe('typedUnion', () => {
7575
const result = validate(Text({}), nestedUnionStruct);
7676

7777
expect(result[0]?.message).toBe(
78-
'At path: props.children -- Expected type to be one of: "Bold", "Italic", "Link", "Icon", but received: undefined',
78+
'At path: props.children -- Expected type to be one of: "Bold", "Italic", "Link", "Icon", "Skeleton", but received: undefined',
7979
);
8080
});
8181

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ButtonElement } from './form/Button';
33
import type { StandardFormattingElement } from './formatting';
44
import type { IconElement } from './Icon';
55
import type { LinkElement } from './Link';
6+
import type { SkeletonElement } from './Skeleton';
67
import type { TextElement } from './Text';
78

89
/**
@@ -14,6 +15,7 @@ export type BannerChildren = SnapsChildren<
1415
| LinkElement
1516
| IconElement
1617
| ButtonElement
18+
| SkeletonElement
1719
>;
1820

1921
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createSnapComponent } from '../component';
2+
import type { BorderRadius } from './utils';
23

34
/**
45
* The props of the {@link Image} component.
@@ -12,7 +13,7 @@ import { createSnapComponent } from '../component';
1213
type ImageProps = {
1314
src: string;
1415
alt?: string | undefined;
15-
borderRadius?: 'none' | 'medium' | 'full' | undefined;
16+
borderRadius?: BorderRadius | undefined;
1617
};
1718

1819
const TYPE = 'Image';

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createSnapComponent } from '../component';
22
import type { AddressElement } from './Address';
33
import type { ImageElement } from './Image';
44
import type { LinkElement } from './Link';
5+
import type { SkeletonElement } from './Skeleton';
56
import type { TextElement } from './Text';
67
import type { ValueElement } from './Value';
78

@@ -13,7 +14,8 @@ export type RowChildren =
1314
| ImageElement
1415
| TextElement
1516
| ValueElement
16-
| LinkElement;
17+
| LinkElement
18+
| SkeletonElement;
1719

1820
/**
1921
* The props of the {@link Row} component.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Skeleton } from './Skeleton';
2+
3+
describe('Skeleton', () => {
4+
it('renders a skeleton component', () => {
5+
const result = <Skeleton width={320} height={32} borderRadius="medium" />;
6+
7+
expect(result).toStrictEqual({
8+
type: 'Skeleton',
9+
key: null,
10+
props: {
11+
width: 320,
12+
height: 32,
13+
borderRadius: 'medium',
14+
},
15+
});
16+
});
17+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { createSnapComponent } from '../component';
2+
import type { BorderRadius } from './utils';
3+
4+
/**
5+
* The props of the {@link Skeleton} component.
6+
*
7+
* @param width - Width of the Skeleton.
8+
* @param width - Height of the Skeleton.
9+
* @param borderRadius - Border radius of the Skeleton.
10+
*/
11+
export type SkeletonProps = {
12+
width?: number | string | undefined;
13+
height?: number | string | undefined;
14+
borderRadius?: BorderRadius | undefined;
15+
};
16+
17+
const TYPE = 'Skeleton';
18+
19+
/**
20+
* A Skeleton component, which is used to display skeleton of loading content.
21+
*
22+
* @param props - The props of the component.
23+
* @param props.width - Width of the Skeleton.
24+
* @param props.width - Height of the Skeleton.
25+
* @param props.borderRadius - Border radius of the Skeleton.
26+
* @example
27+
* <Skeleton height={32} width="50%" />
28+
*/
29+
export const Skeleton = createSnapComponent<SkeletonProps, typeof TYPE>(TYPE);
30+
31+
/**
32+
* A Skeleton element.
33+
*
34+
* @see Skeleton
35+
*/
36+
export type SkeletonElement = ReturnType<typeof Skeleton>;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import { createSnapComponent } from '../component';
33
import type { StandardFormattingElement } from './formatting';
44
import type { IconElement } from './Icon';
55
import type { LinkElement } from './Link';
6+
import type { SkeletonElement } from './Skeleton';
67

78
/**
89
* The children of the {@link Text} component.
910
*/
1011
export type TextChildren = SnapsChildren<
11-
string | StandardFormattingElement | LinkElement | IconElement
12+
| string
13+
| StandardFormattingElement
14+
| LinkElement
15+
| IconElement
16+
| SkeletonElement
1217
>;
1318

1419
/**

0 commit comments

Comments
 (0)