Skip to content

Commit

Permalink
Refactor (change approach)
Browse files Browse the repository at this point in the history
  • Loading branch information
david0xd committed Dec 9, 2024
1 parent dfe4482 commit a9f1364
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
5 changes: 3 additions & 2 deletions ui/components/app/snaps/snap-ui-button/snap-ui-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { useSnapInterfaceContext } from '../../../../contexts/snaps';

export type SnapUIButtonProps = {
name?: string;
loading?: boolean;
};

const COLORS = {
primary: TextColor.infoDefault,
destructive: TextColor.errorDefault,
disabled: TextColor.textMuted,
loading: TextColor.primaryDefault,
};

export const SnapUIButton: FunctionComponent<
Expand All @@ -32,6 +32,7 @@ export const SnapUIButton: FunctionComponent<
type = ButtonType.Button,
variant = 'primary',
disabled = false,
loading = false,
className = '',
...props
}) => {
Expand Down Expand Up @@ -66,7 +67,7 @@ export const SnapUIButton: FunctionComponent<
disabled={disabled}
{...props}
>
{variant === 'loading' ? (
{loading ? (
<Icon
name={IconName.Loading}
style={{ animation: 'spin 2s linear infinite' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Icon,
IconName,
IconSize,
ButtonVariant as ExtensionButtonVariant,
} from '../../../component-library';
import {
AlignItems,
Expand All @@ -38,6 +37,7 @@ export const SnapUIFooterButton: FunctionComponent<
name,
children,
disabled = false,
loading = false,
isSnapAction = false,
type,
variant = ButtonVariant.Primary,
Expand Down Expand Up @@ -67,8 +67,6 @@ export const SnapUIFooterButton: FunctionComponent<
: ButtonVariant.Secondary;

const buttonVariant = hideSnapBranding ? variant : brandedButtonVariant;
const finalButtonVariant =
buttonVariant === 'loading' ? ButtonVariant.Primary : buttonVariant;

return (
<Button
Expand All @@ -82,18 +80,18 @@ export const SnapUIFooterButton: FunctionComponent<
size={ButtonSize.Lg}
block
disabled={disabled}
variant={finalButtonVariant as unknown as ExtensionButtonVariant}
variant={buttonVariant}
onClick={handleClick}
textProps={{
display: Display.Flex,
alignItems: AlignItems.center,
flexDirection: FlexDirection.Row,
}}
>
{isSnapAction && !hideSnapBranding && variant !== 'loading' && (
{isSnapAction && !hideSnapBranding && !loading && (
<SnapIcon snapId={snapId} avatarSize={IconSize.Sm} marginRight={2} />
)}
{variant === 'loading' ? (
{loading ? (
<Icon
name={IconName.Loading}
style={{ animation: 'spin 2s linear infinite' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const button: UIComponentFactory<ButtonElement> = ({
variant: element.props.variant,
name: element.props.name,
disabled: element.props.disabled,
loading: element.props.loading,
},
children: mapTextToTemplate(
getJsxChildren(element) as NonEmptyArray<string | JSXElement>,
Expand Down
12 changes: 4 additions & 8 deletions ui/components/app/snaps/snap-ui-renderer/components/footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,15 @@ export const footer: UIComponentFactory<FooterElement> = ({
...params,
element: children,
} as UIComponentParams<ButtonElement>);

const variant =
buttonMapped.props?.variant ??
(providedChildren.length === 2 && index === 0
? ButtonVariant.Secondary
: ButtonVariant.Primary);

return {
element: 'SnapUIFooterButton',
key: `snap-footer-button-${buttonMapped.props?.name ?? index}`,
props: {
...buttonMapped.props,
variant,
variant:
providedChildren.length === 2 && index === 0
? ButtonVariant.Secondary
: ButtonVariant.Primary,
isSnapAction: true,
},
children: buttonMapped.children,
Expand Down

0 comments on commit a9f1364

Please sign in to comment.