Skip to content

Commit

Permalink
feat(ModalFooter): basic modal footer (#2463)
Browse files Browse the repository at this point in the history
  • Loading branch information
YossiSaadi committed Dec 2, 2024
1 parent 97d81fa commit b18754a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.primary {
order: 2;

&:only-child {
margin-left: auto;
}
}

.secondary {
order: 1;
margin-left: auto;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { forwardRef } from "react";
import cx from "classnames";
import ModalFooterBase from "../ModalFooterBase/ModalFooterBase";
import { getTestId } from "../../../../tests/test-ids-utils";
import { ComponentDefaultTestId } from "../../../../tests/constants";
import { ModalFooterProps } from "./ModalFooter.types";
import styles from "./ModalFooter.module.scss";

const ModalFooter = forwardRef(
(
{ primaryButton, secondaryButton, renderSideAction, "data-testid": dataTestId, className, id }: ModalFooterProps,
ref: React.ForwardedRef<HTMLDivElement>
) => {
const primary = { ...primaryButton, className: cx(primaryButton.className, styles.primary) };
const secondary = secondaryButton
? { ...secondaryButton, className: cx(secondaryButton.className, styles.secondary) }
: undefined;
return (
<ModalFooterBase
ref={ref}
className={className}
id={id}
data-testid={dataTestId || getTestId(ComponentDefaultTestId.MODAL_NEXT_FOOTER, id)}
primaryButton={primary}
secondaryButton={secondary}
renderAction={renderSideAction}
/>
);
}
);

export default ModalFooter;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
import { ModalFooterBaseProps } from "../ModalFooterBase/ModalFooterBase.types";

export interface ModalFooterProps extends Omit<ModalFooterBaseProps, "renderAction"> {
renderSideAction?: React.ReactNode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const ModalFooterBase = forwardRef(
{ primaryButton, secondaryButton, renderAction, id, className, "data-testid": dataTestId }: ModalFooterBaseProps,
ref: React.ForwardedRef<HTMLDivElement>
) => {
const { text: primaryButtonText, ...primaryButtonProps } = primaryButton;
const { text: secondaryButtonText, ...secondaryButtonProps } = secondaryButton || {};
return (
<Flex
ref={ref}
Expand All @@ -19,12 +21,10 @@ const ModalFooterBase = forwardRef(
className={cx(styles.footer, className)}
data-testid={dataTestId}
>
<Button onClick={primaryButton.onClick} className={primaryButton.className}>
{primaryButton.text}
</Button>
<Button {...primaryButtonProps}>{primaryButtonText}</Button>
{secondaryButton && (
<Button kind={Button.kinds.TERTIARY} className={secondaryButton.className} onClick={secondaryButton.onClick}>
{secondaryButton.text}
<Button {...secondaryButtonProps} kind={Button.kinds.TERTIARY}>
{secondaryButtonText}
</Button>
)}
{renderAction}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ButtonProps } from "../../../Button";
import React from "react";
import { VibeComponentProps } from "../../../../types";

export interface ModalFooterActionProps extends Pick<ButtonProps, "onClick" | "className"> {
export interface ModalFooterActionProps extends Omit<ButtonProps, "children" | "kind"> {
text: string;
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export enum ComponentDefaultTestId {
MODAL_NEXT_OVERLAY = "modal-overlay",
MODAL_NEXT_HEADER = "modal-header",
MODAL_NEXT_CONTENT = "modal-content",
MODAL_NEXT_FOOTER = "modal-footer",
MODAL_NEXT_MEDIA = "modal-media",
MODAL_NEXT_BASIC_LAYOUT = "modal-basic-layout",
MODAL_NEXT_SIDE_BY_SIDE_LAYOUT = "modal-side-by-side-layout",
Expand Down

0 comments on commit b18754a

Please sign in to comment.