Skip to content

Commit

Permalink
feat: Add color prop to Snaps text component (#26682)
Browse files Browse the repository at this point in the history
Added `color` prop to Snaps text component
  • Loading branch information
hmalik88 authored Aug 27, 2024
1 parent b699850 commit cd6f85d
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions ui/components/app/snaps/snap-ui-renderer/components/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,38 @@ import { UIComponentFactory } from './types';
export const text: UIComponentFactory<TextElement> = ({
element,
...params
}) => ({
element: 'Text',
children: mapTextToTemplate(
getJsxChildren(element) as NonEmptyArray<string | JSXElement>,
params,
),
props: {
variant: TextVariant.bodyMd,
overflowWrap: OverflowWrap.Anywhere,
color: TextColor.inherit,
className: 'snap-ui-renderer__text',
textAlign: element.props.alignment,
},
});
}) => {
const getTextColor = () => {
switch (element.props.color) {
case 'default':
return TextColor.textDefault;
case 'alternative':
return TextColor.textAlternative;
case 'muted':
return TextColor.textMuted;
case 'error':
return TextColor.errorDefault;
case 'success':
return TextColor.successDefault;
case 'warning':
return TextColor.warningDefault;
default:
return TextColor.inherit;
}
};

return {
element: 'Text',
children: mapTextToTemplate(
getJsxChildren(element) as NonEmptyArray<string | JSXElement>,
params,
),
props: {
variant: TextVariant.bodyMd,
overflowWrap: OverflowWrap.Anywhere,
color: getTextColor(),
className: 'snap-ui-renderer__text',
textAlign: element.props.alignment,
},
};
};

0 comments on commit cd6f85d

Please sign in to comment.