Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ModalFooter): basic modal footer #2463

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
YossiSaadi marked this conversation as resolved.
Show resolved Hide resolved
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
YossiSaadi marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
1 change: 1 addition & 0 deletions packages/core/src/tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export enum ComponentDefaultTestId {
MODAL_NEXT_OVERLAY = "modal-overlay",
MODAL_NEXT_HEADER = "modal-header",
MODAL_NEXT_CONTENT = "modal-content",
MODAL_NEXT_FOOTER = "modal-footer",
FORMATTED_NUMBER = "formatted-number",
HIDDEN_TEXT = "hidden-text",
DIALOG_CONTENT_CONTAINER = "dialog-content-container",
Expand Down