Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backgroundColor property to Container component #2950

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "SquG9JvLanG/gJwBw5H1AZBlsthmv21Ci4Vn+sMemjM=",
"shasum": "dufO1JvWq9z+GBzDz4wzKAeMlwm1KvNTq9Ut00XkRr4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/browserify/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "pCp96i558WHqHIUZyZGUFcxAfOQ0afBHJ59nJB5ma78=",
"shasum": "2LrvEzOyxhKXC5ySK8hlvTRv9Wt9h501auraxKKipOU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/snaps-sdk/src/jsx/components/Box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createSnapComponent } from '../component';
* @property direction - The direction to stack the components within the box. Defaults to `vertical`.
* @property alignment - The alignment mode to use within the box. Defaults to `start`.
* @property center - Whether to center the children within the box. Defaults to `false`.
* @property backgroundColor - Whether the Box needs color adjustments. Defaults to undefined.
*/
export type BoxProps = {
// We can't use `JSXElement` because it causes a circular reference.
Expand All @@ -21,6 +22,7 @@ export type BoxProps = {
| 'space-around'
| undefined;
center?: boolean | undefined;
backgroundColor?: string | undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to only allow it on the Container instead of the Box? 🤔

};

const TYPE = 'Box';
Expand Down
3 changes: 2 additions & 1 deletion packages/snaps-sdk/src/jsx/components/Container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Text } from './Text';
describe('Container', () => {
it('renders a container element with a box', () => {
const result = (
<Container>
<Container backgroundColor="alternative">
<Box>
<Text>Hello world!</Text>
</Box>
Expand All @@ -18,6 +18,7 @@ describe('Container', () => {
type: 'Container',
key: null,
props: {
backgroundColor: 'alternative',
children: {
type: 'Box',
key: null,
Expand Down
9 changes: 8 additions & 1 deletion packages/snaps-sdk/src/jsx/components/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import type { GenericSnapElement } from '../component';
import { createSnapComponent } from '../component';
import type { FooterElement } from './Footer';

/**
* Definition of container background colors.
*/
export type ContainerBackgroundColor = 'default' | 'alternative';

/**
* The props of the {@link Container} component.
*
* @property children - The Box and the Footer or the Box element.
*/
export type ContainerProps = {
children: [GenericSnapElement, FooterElement] | GenericSnapElement;
backgroundColor?: ContainerBackgroundColor | undefined;
};

const TYPE = 'Container';
Expand All @@ -17,10 +23,11 @@ const TYPE = 'Container';
* A container component, which is used to create a container with a box and a footer.
*
* @param props - The props of the component.
* @param props.backgroundColor - The color of the background.
* @param props.children - The Box and the Footer or the Box element.
* @returns A container element.
* @example
* <Container>
* <Container backgroundColor="default">
* <Box>
* <Text>Hello world!</Text>
* </Box>
Expand Down
6 changes: 6 additions & 0 deletions packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,12 @@ describe('ContainerStruct', () => {
<Container>
<Text>Hello world!</Text>
</Container>,
<Container backgroundColor="default">
<Text>Hello world!</Text>
</Container>,
<Container backgroundColor="alternative">
<Text>Hello world!</Text>
</Container>,
<Container>
<Text>Hello world!</Text>
<Footer>
Expand Down
3 changes: 3 additions & 0 deletions packages/snaps-sdk/src/jsx/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,9 @@ export const ContainerStruct: Describe<ContainerElement> = element(
[GenericSnapElement, FooterElement] | GenericSnapElement,
null
>,
backgroundColor: optional(
nullUnion([literal('default'), literal('alternative')]),
),
},
);

Expand Down
Loading