Skip to content

Commit e759aa2

Browse files
feat: Cell component
1 parent 882232c commit e759aa2

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createSnapComponent } from '../component';
2+
3+
/**
4+
* The props of the {@link Cell} component.
5+
*
6+
* @property image - The image to show as part of the Cell, must be an SVG string.
7+
* @property title - The title.
8+
* @property description - The description, shown below the title.
9+
* @property value - The value, shown on the right side.
10+
* @property extra - An additional optional value shown below the value.
11+
*/
12+
export type CellProps = {
13+
image?: string | undefined;
14+
title: string;
15+
description?: string | undefined;
16+
value: string;
17+
extra?: string | undefined;
18+
};
19+
20+
const TYPE = 'Cell';
21+
22+
/**
23+
* A cell component which can be used to display values within a cell structure.
24+
*
25+
* @param props - The props of the component.
26+
* @param props.image - The image to show as part of the Cell, must be an SVG string.
27+
* @param props.title - The title.
28+
* @param props.description - The description, shown below the title.
29+
* @param props.value - The value, shown on the right side.
30+
* @param props.extra - An additional optional value shown below the value.
31+
* @returns A box element.
32+
* @example
33+
* <Cell image="<svg />" title="Title" description="Description" value="$1200" extra="0.12 ETH" />
34+
*/
35+
export const Cell = createSnapComponent<CellProps, typeof TYPE>(TYPE);
36+
37+
/**
38+
* A cell element.
39+
*
40+
* @see Cell
41+
*/
42+
export type CellElement = ReturnType<typeof Cell>;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { AddressElement } from './Address';
22
import type { BoxElement } from './Box';
3+
import type { CellElement } from './Cell';
34
import type { ContainerElement } from './Container';
45
import type { CopyableElement } from './Copyable';
56
import type { DividerElement } from './Divider';
@@ -19,6 +20,7 @@ export * from './form';
1920
export * from './formatting';
2021
export * from './Address';
2122
export * from './Box';
23+
export * from './Cell';
2224
export * from './Copyable';
2325
export * from './Divider';
2426
export * from './Value';
@@ -40,6 +42,7 @@ export type JSXElement =
4042
| StandardFormattingElement
4143
| AddressElement
4244
| BoxElement
45+
| CellElement
4346
| ContainerElement
4447
| CopyableElement
4548
| DividerElement

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import type {
4242
BoxElement,
4343
ButtonElement,
4444
CheckboxElement,
45+
CellElement,
4546
CopyableElement,
4647
DividerElement,
4748
DropdownElement,
@@ -380,6 +381,17 @@ export const ValueStruct: Describe<ValueElement> = element('Value', {
380381
extra: string(),
381382
});
382383

384+
/**
385+
* A struct for the {@link CellElement} type.
386+
*/
387+
export const CellStruct: Describe<CellElement> = element('Cell', {
388+
image: optional(string()),
389+
title: string(),
390+
description: optional(string()),
391+
value: string(),
392+
extra: optional(string()),
393+
});
394+
383395
/**
384396
* A struct for the {@link HeadingElement} type.
385397
*/
@@ -488,6 +500,7 @@ export const BoxChildStruct = nullUnion([
488500
TextStruct,
489501
TooltipStruct,
490502
CheckboxStruct,
503+
CellStruct,
491504
]);
492505

493506
/**
@@ -527,6 +540,7 @@ export const JSXElementStruct: Describe<JSXElement> = nullUnion([
527540
CheckboxStruct,
528541
FooterStruct,
529542
ContainerStruct,
543+
CellStruct,
530544
]);
531545

532546
/**

0 commit comments

Comments
 (0)