import React from 'react' import Button from '../Button/Button' import { type TooltipProps } from '../Tooltip/Tooltip' import styles from './_form-footer.module.scss' import { type ConfirmationItem } from '../Button/ButtonComponents/ConfirmationButton' import { type ButtonProps } from '../Button/Button.models' import { c } from '../../translations/LibraryTranslationService' type FormButtonProps = { /** Required callout for each button */ onClick: React.MouseEventHandler /** Optionally disable a button */ disabled?: ButtonProps['disabled'] /** Optionally pass in children for a button */ children?: React.ReactNode /** Optionally style the button */ styleType?: ButtonProps['styleType'] /** Optionally style the Button as destructive */ destructive?: ButtonProps['destructive'] /** Optionally pass in a tooltip content for the button */ tooltip?: Omit /** Optional prop to add a test id to the FormFooter buttons for QA testing */ qaTestId?: string } // don't need an onclick for the save button if we are using popover with confirmation type ButtonWithConfirmationProps = Omit & { confirmation: ConfirmationItem } type ButtonWithoutConfirmationProps = FormButtonProps & { confirmation?: never } type CancelButtonProps = FormButtonProps & { /** Optional prop to add a data-dd-action-name to the FormFooter buttons for DD testing */ dataDDActionName?: string } type DetermineConfirmationButtonProps = | ButtonWithoutConfirmationProps | ButtonWithConfirmationProps export type FormFooterProps = { /** Cancel button props */ cancelButtonProps?: CancelButtonProps /** Save button props */ saveButtonProps: DetermineConfirmationButtonProps /** Reset button props */ resetButtonProps?: DetermineConfirmationButtonProps /** Optional prop to add a test id to the FormFooter for QA testing */ qaTestId?: string } const FormFooter = ({ cancelButtonProps, saveButtonProps, resetButtonProps, qaTestId = 'form-footer', }: FormFooterProps): React.JSX.Element => { return (
{resetButtonProps ? ( resetButtonProps?.confirmation ? ( ) : ( ) ) : (
)}
{cancelButtonProps ? ( ) : (
)} {saveButtonProps?.confirmation ? ( ) : ( )}
) } export default FormFooter