Skip to content

Commit dab926d

Browse files
committed
Add backgroundColor property to Container component
Minor refactoring Update manifest shasum
1 parent 51ab913 commit dab926d

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createSnapComponent } from '../component';
88
* @property direction - The direction to stack the components within the box. Defaults to `vertical`.
99
* @property alignment - The alignment mode to use within the box. Defaults to `start`.
1010
* @property center - Whether to center the children within the box. Defaults to `false`.
11+
* @property backgroundColor - Whether the Box needs color adjustments. Defaults to undefined.
1112
*/
1213
export type BoxProps = {
1314
// We can't use `JSXElement` because it causes a circular reference.
@@ -21,6 +22,7 @@ export type BoxProps = {
2122
| 'space-around'
2223
| undefined;
2324
center?: boolean | undefined;
25+
backgroundColor?: string | undefined;
2426
};
2527

2628
const TYPE = 'Box';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Text } from './Text';
77
describe('Container', () => {
88
it('renders a container element with a box', () => {
99
const result = (
10-
<Container>
10+
<Container backgroundColor="alternative">
1111
<Box>
1212
<Text>Hello world!</Text>
1313
</Box>
@@ -18,6 +18,7 @@ describe('Container', () => {
1818
type: 'Container',
1919
key: null,
2020
props: {
21+
backgroundColor: 'alternative',
2122
children: {
2223
type: 'Box',
2324
key: null,

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import type { GenericSnapElement } from '../component';
22
import { createSnapComponent } from '../component';
33
import type { FooterElement } from './Footer';
44

5+
/**
6+
* Definition of container background colors.
7+
*/
8+
export type ContainerBackgroundColor = 'default' | 'alternative';
9+
510
/**
611
* The props of the {@link Container} component.
712
*
813
* @property children - The Box and the Footer or the Box element.
914
*/
1015
export type ContainerProps = {
1116
children: [GenericSnapElement, FooterElement] | GenericSnapElement;
17+
backgroundColor?: ContainerBackgroundColor | undefined;
1218
};
1319

1420
const TYPE = 'Container';
@@ -17,10 +23,11 @@ const TYPE = 'Container';
1723
* A container component, which is used to create a container with a box and a footer.
1824
*
1925
* @param props - The props of the component.
26+
* @param props.backgroundColor - The color of the background.
2027
* @param props.children - The Box and the Footer or the Box element.
2128
* @returns A container element.
2229
* @example
23-
* <Container>
30+
* <Container backgroundColor="default">
2431
* <Box>
2532
* <Text>Hello world!</Text>
2633
* </Box>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ describe('ContainerStruct', () => {
756756
<Container>
757757
<Text>Hello world!</Text>
758758
</Container>,
759+
<Container backgroundColor="default">
760+
<Text>Hello world!</Text>
761+
</Container>,
762+
<Container backgroundColor="alternative">
763+
<Text>Hello world!</Text>
764+
</Container>,
759765
<Container>
760766
<Text>Hello world!</Text>
761767
<Footer>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,9 @@ export const ContainerStruct: Describe<ContainerElement> = element(
837837
[GenericSnapElement, FooterElement] | GenericSnapElement,
838838
null
839839
>,
840+
backgroundColor: optional(
841+
nullUnion([literal('default'), literal('alternative')]),
842+
),
840843
},
841844
);
842845

0 commit comments

Comments
 (0)