Skip to content

Commit

Permalink
fix left button being primary
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeRx committed Sep 20, 2024
1 parent 60c02b7 commit 2cfcce7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { useSelector } from 'react-redux';
import {
Button,
ButtonLinkProps,
ButtonProps,
ButtonSize,
IconSize,
} from '../../../component-library';
Expand All @@ -23,19 +23,21 @@ import classnames from 'classnames';

type SnapUIFooterButtonProps = {
name?: string;
variant?: ButtonVariant;
isSnapAction?: boolean;
onCancel?: () => void;
};

export const SnapUIFooterButton: FunctionComponent<
SnapUIFooterButtonProps & ButtonLinkProps<'button'>
SnapUIFooterButtonProps & ButtonProps<'button'>
> = ({
onCancel,
name,
children,
disabled = false,
isSnapAction = false,
type,
variant = ButtonVariant.Primary,
form,
...props
}) => {
Expand All @@ -57,6 +59,12 @@ export const SnapUIFooterButton: FunctionComponent<

const handleClick = isSnapAction ? handleSnapAction : onCancel;

const brandedButtonVariant = isSnapAction
? ButtonVariant.Primary
: ButtonVariant.Secondary;

const buttonVariant = hideSnapBranding ? variant : brandedButtonVariant;

return (
<Button
className={classnames('snap-ui-renderer__footer-button', {
Expand All @@ -69,7 +77,7 @@ export const SnapUIFooterButton: FunctionComponent<
size={ButtonSize.Lg}
block
disabled={disabled}
variant={isSnapAction ? ButtonVariant.Primary : ButtonVariant.Secondary}
variant={buttonVariant}
onClick={handleClick}
textProps={{
display: Display.Flex,
Expand Down
40 changes: 21 additions & 19 deletions ui/components/app/snaps/snap-ui-renderer/components/footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Display,
FlexDirection,
} from '../../../../../helpers/constants/design-system';
import { UIComponentFactory, UIComponentParams } from './types';
import { ButtonVariant } from '../../../../component-library';
import { UIComponent, UIComponentFactory, UIComponentParams } from './types';
import { button as buttonFn } from './button';

export const DEFAULT_FOOTER = {
Expand Down Expand Up @@ -61,26 +62,27 @@ export const footer: UIComponentFactory<FooterElement> = ({
}) => {
const defaultButtons = getDefaultButtons(element, t, onCancel);

const footerChildren = (getJsxChildren(element) as ButtonElement[]).map(
(children, index) => {
const buttonMapped = buttonFn({
...params,
element: children,
} as UIComponentParams<ButtonElement>);
return {
element: 'SnapUIFooterButton',
key: `snap-footer-button-${buttonMapped.props?.name ?? index}`,
props: {
...buttonMapped.props,
isSnapAction: true,
},
children: buttonMapped.children,
};
},
);
const footerChildren: UIComponent[] = (
getJsxChildren(element) as ButtonElement[]
).map((children, index) => {
const buttonMapped = buttonFn({
...params,
element: children,
} as UIComponentParams<ButtonElement>);
return {
element: 'SnapUIFooterButton',
key: `snap-footer-button-${buttonMapped.props?.name ?? index}`,
props: {
...buttonMapped.props,
variant: index === 0 ? ButtonVariant.Secondary : ButtonVariant.Primary,
isSnapAction: true,
},
children: buttonMapped.children,
};
});

if (defaultButtons) {
footerChildren.unshift(defaultButtons);
footerChildren.unshift(defaultButtons as UIComponent);
}

return {
Expand Down

0 comments on commit 2cfcce7

Please sign in to comment.