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

feat: add section component #26718

Merged
merged 5 commits into from
Sep 11, 2024
Merged
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
11 changes: 6 additions & 5 deletions ui/components/app/snaps/snap-ui-renderer/components/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NonEmptyArray } from '@metamask/utils';
import {
Display,
FlexDirection,
JustifyContent,
TextColor,
} from '../../../../../helpers/constants/design-system';
import { mapToTemplate } from '../utils';
Expand All @@ -13,19 +14,19 @@ function generateJustifyContent(alignment?: BoxProps['alignment']) {
switch (alignment) {
default:
case 'start':
return 'flex-start';
return JustifyContent.flexStart;

case 'center':
return 'center';
return JustifyContent.center;

case 'end':
return 'flex-end';
return JustifyContent.flexEnd;

case 'space-between':
return 'space-between';
return JustifyContent.spaceBetween;

case 'space-around':
return 'space-around';
return JustifyContent.spaceAround;
}
}

Expand Down
2 changes: 2 additions & 0 deletions ui/components/app/snaps/snap-ui-renderer/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { footer } from './footer';
import { container } from './container';
import { selector } from './selector';
import { icon } from './icon';
import { section } from './section';

export const COMPONENT_MAPPING = {
Box: box,
Expand Down Expand Up @@ -54,4 +55,5 @@ export const COMPONENT_MAPPING = {
Footer: footer,
Container: container,
Selector: selector,
Section: section,
};
28 changes: 28 additions & 0 deletions ui/components/app/snaps/snap-ui-renderer/components/section.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { SectionElement, BoxElement } from '@metamask/snaps-sdk/jsx';
import {
BackgroundColor,
BorderRadius,
} from '../../../../../helpers/constants/design-system';
import { UIComponentFactory, UIComponentParams } from './types';
import { box } from './box';

export const section: UIComponentFactory<SectionElement> = ({
FrederikBolding marked this conversation as resolved.
Show resolved Hide resolved
element,
...params
}) => {
const { children, props } = box({
element,
...params,
} as unknown as UIComponentParams<BoxElement>);
return {
element: 'Box',
children,
props: {
...props,
className: 'snap-ui-renderer__section',
padding: 4,
backgroundColor: BackgroundColor.backgroundDefault,
borderRadius: BorderRadius.LG,
},
};
};