Commit 898525b
feat(snaps): Add background color prop to Snaps UI Container component (#29095)
This PR adds `backgroundColor` property to Container component.
Background colors that can be used are predefined as: default and
alternative.
This PR deliberately disables the `backgroundColor` feature for
containers used within Transaction Insights pages (Snaps).
[](https://codespaces.new/MetaMask/metamask-extension/pull/29095?quickstart=1)
Fixes: MetaMask/snaps#2906
Related Snaps PR: MetaMask/snaps#2950
1. Try installing and using a Snap with confirmation window or home
page, with `Container` in its content with `backgroundColor` defined
(e.g. `<Container backgroundColor="default">`).
2. Try the same thing on transaction insights Snaps and confirm that the
colors are not changing there.
3. Confirm that the colors are as expected on all pages.
Some source code used for testing:
- Source code used for confirmation content:
```typescript
export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
switch (request.method) {
case 'hello':
return snap.request({
method: 'snap_dialog',
params: {
content: (
<Container backgroundColor="default">
<Box>
<Section>
<Row label="From">
<Address address="0x1234567890123456789012345678901234567890" />
</Row>
<Row
label="To"
variant="warning"
tooltip="This address has been deemed dangerous."
>
<Address address="0x0000000000000000000000000000000000000000" />
</Row>
</Section>
<Form name="form">
<Box direction="horizontal">
<Field label="baz">
<Input name="baz" placeholder="Enter something..." />
</Field>
<Field label="foo">
<Selector title="bar" name="test">
<SelectorOption value="one">
<Card title="test" value="test" />
</SelectorOption>
</Selector>
</Field>
</Box>
<Field label="something_else">
<Selector title="bar" name="test2">
<SelectorOption value="one">
<Card title="test" value="test" />
</SelectorOption>
</Selector>
</Field>
<Box direction="horizontal">
<Field label="baz2">
<Input name="baz2" placeholder="Enter something..." />
</Field>
<Field label="foo3">
<Input name="foo3" placeholder="Enter something..." />
</Field>
</Box>
<Box direction="horizontal">
<Field label="Example Dropdown">
<Dropdown name="example-dropdown">
<Option value="option1">Option 1</Option>
<Option value="option2">Option 2</Option>
<Option value="option3">Option 3</Option>
</Dropdown>
</Field>
<Field label="Example RadioGroup">
<RadioGroup name="example-radiogroup">
<Radio value="option1">Option 1</Radio>
<Radio value="option2">Option 2</Radio>
<Radio value="option3">Option 3</Radio>
</RadioGroup>
</Field>
</Box>
<Field label="Example Dropdown full width">
<Dropdown name="example-dropdown-full">
<Option value="option1">Option 1</Option>
<Option value="option2">Option 2</Option>
<Option value="option3">Option 3</Option>
</Dropdown>
</Field>
<Field label="Example RadioGroup full width">
<RadioGroup name="example-radiogroup-full">
<Radio value="option11">Option 11</Radio>
<Radio value="option22">Option 22</Radio>
<Radio value="option33">Option 33</Radio>
</RadioGroup>
</Field>
<Field label="foo4">
<Input name="foo4" placeholder="Enter something..." />
</Field>
<Box direction="horizontal">
<Field label="baz3">
<Input name="baz3" placeholder="Enter something..." />
</Field>
</Box>
<Box direction="horizontal">
<Field label="Example Checkbox">
<Checkbox name="example-checkbox" label="Checkbox" />
</Field>
<Field label="Example Selector">
<Selector
name="example-selector"
title="Choose an option"
value="option1"
>
<SelectorOption value="option1">
<Card title="Option 1" value="option1" />
</SelectorOption>
<SelectorOption value="option2">
<Card title="Option 2" value="option2" />
</SelectorOption>
<SelectorOption value="option3">
<Card title="Option 3" value="option3" />
</SelectorOption>
</Selector>
</Field>
</Box>
<Field label="Example FileInput 2">
<FileInput name="file-input-2" />
</Field>
<Field label="Example Checkbox Full field">
<Checkbox name="example-checkbox-full" label="Checkbox" />
</Field>
<Box direction="horizontal">
<Field label="baz4">
<Input name="baz4" placeholder="Enter something..." />
</Field>
<Field label="Example FileInput">
<FileInput name="file-input-1" />
</Field>
</Box>
<Box direction="horizontal">
<Field label="baz5">
<Input name="baz5" placeholder="Enter something..." />
</Field>
<Field label="FileInput Compact">
<FileInput name="file-input-3" compact={true} />
</Field>
</Box>
<Field label="FileInput Compact 2 full">
<FileInput name="file-input-4" compact={true} />
</Field>
</Form>
</Box>
</Container>
),
},
});
default:
throw new Error('Method not found.');
}
};
```
Note: Changing container colors was not possible before.








- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.1 parent 1844e67 commit 898525b
File tree
11 files changed
+45
-9
lines changed- ui
- components/app/snaps
- insight-warnings
- snap-home-page
- snap-insight
- snap-ui-renderer
- components
- snap-ui-selector
- pages/confirmations
- components/confirm/snaps/snaps-section
- confirmation
11 files changed
+45
-9
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | 96 | | |
98 | 97 | | |
99 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
| |||
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
25 | | - | |
| 33 | + | |
26 | 34 | | |
27 | 35 | | |
28 | 36 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
| |||
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
| 88 | + | |
82 | 89 | | |
83 | | - | |
| 90 | + | |
84 | 91 | | |
85 | 92 | | |
86 | 93 | | |
| |||
134 | 141 | | |
135 | 142 | | |
136 | 143 | | |
137 | | - | |
| 144 | + | |
138 | 145 | | |
139 | 146 | | |
140 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
0 commit comments