Skip to content

Commit 26da01d

Browse files
Add font weight and size props
1 parent 50398a0 commit 26da01d

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

ui/components/app/snaps/snap-ui-button/snap-ui-button.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useSnapInterfaceContext } from '../../../../contexts/snaps';
1010

1111
export type SnapUIButtonProps = {
1212
name?: string;
13+
textVariant: ButtonLinkProps<'button'>['variant'];
1314
};
1415

1516
const COLORS = {
@@ -27,6 +28,7 @@ export const SnapUIButton: FunctionComponent<
2728
variant = 'primary',
2829
disabled = false,
2930
className = '',
31+
textVariant,
3032
...props
3133
}) => {
3234
const { handleEvent } = useSnapInterfaceContext();
@@ -58,6 +60,7 @@ export const SnapUIButton: FunctionComponent<
5860
onClick={handleClick}
5961
color={color}
6062
disabled={disabled}
63+
variant={textVariant}
6164
{...props}
6265
>
6366
{children}

ui/components/app/snaps/snap-ui-renderer/components/button.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ButtonElement, JSXElement } from '@metamask/snaps-sdk/jsx';
22
import { getJsxChildren } from '@metamask/snaps-utils';
33
import { NonEmptyArray } from '@metamask/utils';
44
import { mapTextToTemplate } from '../utils';
5+
import { TextVariant } from '../../../../../helpers/constants/design-system';
56
import { UIComponentFactory } from './types';
67

78
export const button: UIComponentFactory<ButtonElement> = ({
@@ -15,6 +16,8 @@ export const button: UIComponentFactory<ButtonElement> = ({
1516
variant: element.props.variant,
1617
name: element.props.name,
1718
disabled: element.props.disabled,
19+
textVariant:
20+
element.props.size === 'sm' ? TextVariant.bodySm : TextVariant.bodyMd,
1821
},
1922
children: mapTextToTemplate(
2023
getJsxChildren(element) as NonEmptyArray<string | JSXElement>,

ui/components/app/snaps/snap-ui-renderer/components/text.ts

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,45 @@ import {
66
TextVariant,
77
OverflowWrap,
88
TextColor,
9+
FontWeight,
910
} from '../../../../../helpers/constants/design-system';
1011
import { UIComponentFactory } from './types';
1112

13+
function getTextColor(color: TextElement['props']['color']) {
14+
switch (color) {
15+
case 'default':
16+
return TextColor.textDefault;
17+
case 'alternative':
18+
return TextColor.textAlternative;
19+
case 'muted':
20+
return TextColor.textMuted;
21+
case 'error':
22+
return TextColor.errorDefault;
23+
case 'success':
24+
return TextColor.successDefault;
25+
case 'warning':
26+
return TextColor.warningDefault;
27+
default:
28+
return TextColor.inherit;
29+
}
30+
}
31+
32+
function getFontWeight(color: TextElement['props']['fontWeight']) {
33+
switch (color) {
34+
case 'bold':
35+
return FontWeight.Bold;
36+
case 'medium':
37+
return FontWeight.Medium;
38+
case 'regular':
39+
default:
40+
return FontWeight.Normal;
41+
}
42+
}
43+
1244
export const text: UIComponentFactory<TextElement> = ({
1345
element,
1446
...params
1547
}) => {
16-
const getTextColor = () => {
17-
switch (element.props.color) {
18-
case 'default':
19-
return TextColor.textDefault;
20-
case 'alternative':
21-
return TextColor.textAlternative;
22-
case 'muted':
23-
return TextColor.textMuted;
24-
case 'error':
25-
return TextColor.errorDefault;
26-
case 'success':
27-
return TextColor.successDefault;
28-
case 'warning':
29-
return TextColor.warningDefault;
30-
default:
31-
return TextColor.inherit;
32-
}
33-
};
34-
3548
return {
3649
element: 'Text',
3750
children: mapTextToTemplate(
@@ -41,8 +54,9 @@ export const text: UIComponentFactory<TextElement> = ({
4154
props: {
4255
variant:
4356
element.props.size === 'sm' ? TextVariant.bodySm : TextVariant.bodyMd,
57+
fontWeight: getFontWeight(element.props.fontWeight),
4458
overflowWrap: OverflowWrap.Anywhere,
45-
color: getTextColor(),
59+
color: getTextColor(element.props.color),
4660
className: 'snap-ui-renderer__text',
4761
textAlign: element.props.alignment,
4862
},

0 commit comments

Comments
 (0)