Skip to content

Commit

Permalink
Add background color prop to Snaps UI Container component
Browse files Browse the repository at this point in the history
  • Loading branch information
david0xd committed Jan 10, 2025
1 parent 46bf1cf commit 0f5f5d3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default function InsightWarnings({
isCollapsable
isCollapsed={warningState[snapId]}
boxProps={{ marginBottom: idx === lastWarningIdx ? 0 : 4 }}
disableCustomBackground
/>
);
})}
Expand Down
1 change: 1 addition & 0 deletions ui/components/app/snaps/snap-insight/snap-insight.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const SnapInsight = ({ snapId, data }) => {
interfaceId={interfaceId}
delineatorType={DelineatorType.Insights}
isLoading={isLoading}
disableCustomBackground
/>
) : (
<Text
Expand Down
11 changes: 11 additions & 0 deletions ui/components/app/snaps/snap-ui-renderer/components/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BoxElement, JSXElement } from '@metamask/snaps-sdk/jsx';
import { getJsxChildren } from '@metamask/snaps-utils';
import { mapToTemplate } from '../utils';
import {
BackgroundColor,
Display,
FlexDirection,
} from '../../../../../helpers/constants/design-system';
Expand All @@ -18,6 +19,15 @@ export const container: UIComponentFactory<BoxElement> = ({
}) => {
const children = getJsxChildren(element);

const { backgroundColor } = element.props;

Check failure on line 22 in ui/components/app/snaps/snap-ui-renderer/components/container.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Property 'backgroundColor' does not exist on type 'BoxProps'.
const backgroundColorMapping: { [key: string]: string | undefined } = {
default: BackgroundColor.backgroundDefault,
alternative: BackgroundColor.backgroundAlternative,
};
const extensionCompatibleBackgroundColor = backgroundColor
? backgroundColorMapping[backgroundColor]
: undefined;

// Remove footer if it's not allowed
if (!useFooter && children.length === 2) {
children.pop();
Expand Down Expand Up @@ -75,6 +85,7 @@ export const container: UIComponentFactory<BoxElement> = ({
element: 'Box',
children: templateChildren,
props: {
backgroundColor: extensionCompatibleBackgroundColor,
display: Display.Flex,
flexDirection: FlexDirection.Column,
className: 'snap-ui-renderer__container',
Expand Down
6 changes: 6 additions & 0 deletions ui/components/app/snaps/snap-ui-renderer/snap-ui-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const SnapUIRendererComponent = ({
useFooter = false,
onCancel,
contentBackgroundColor,
disableCustomBackground = false,
}) => {
const t = useI18nContext();

Expand All @@ -59,6 +60,10 @@ const SnapUIRendererComponent = ({
? rawContent
: Container({ children: rawContent });

if (disableCustomBackground && content.type === 'Container') {
delete content.props.backgroundColor;
}

const promptLegacyProps = useMemo(
() =>
isPrompt && {
Expand Down Expand Up @@ -165,4 +170,5 @@ SnapUIRendererComponent.propTypes = {
useFooter: PropTypes.bool,
onCancel: PropTypes.func,
contentBackgroundColor: PropTypes.string,
disableCustomBackground: PropTypes.bool,
};
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const SnapInsight: React.FunctionComponent<SnapInsightProps> = ({
interfaceId={interfaceId}
isLoading={loading}
useDelineator={false}
disableCustomBackground={true}
/>
</Delineator>
);
Expand Down

0 comments on commit 0f5f5d3

Please sign in to comment.