From fcf5b9e6a186fb78fc1f94de8a62f034928a182c Mon Sep 17 00:00:00 2001 From: Tomohisa Igarashi Date: Fri, 11 Oct 2024 12:17:11 -0400 Subject: [PATCH] chore: Fix confirmation modal buttons layout Added a storybook to show them --- .../modal/ActionConfirmationModal.stories.tsx | 66 +++++++++++++++++++ ...n-confirmaton-modal.provider.test.tsx.snap | 54 +++++++++------ .../action-confirmation-modal.provider.tsx | 52 ++++++++------- 3 files changed, 129 insertions(+), 43 deletions(-) create mode 100644 packages/ui-tests/stories/modal/ActionConfirmationModal.stories.tsx diff --git a/packages/ui-tests/stories/modal/ActionConfirmationModal.stories.tsx b/packages/ui-tests/stories/modal/ActionConfirmationModal.stories.tsx new file mode 100644 index 000000000..8fa88270c --- /dev/null +++ b/packages/ui-tests/stories/modal/ActionConfirmationModal.stories.tsx @@ -0,0 +1,66 @@ +import { + ActionConfirmationModalContextProvider, + ActionConfirmationModalContext, + ActionConfirmationButtonOption, +} from '@kaoto/kaoto/testing'; +import { Meta, StoryFn } from '@storybook/react'; +import { FunctionComponent, useContext, useState } from 'react'; +import { ButtonVariant } from '@patternfly/react-core'; + +export default { + title: 'Modal/ActionConfirmationModal', + component: ActionConfirmationModalContextProvider, +} as Meta; + +type TestComponentProps = { + title: string; + btnTitle?: string; + text?: string; + additionalModalText?: string; + buttonOptions?: Record; +}; + +const TestComponent: FunctionComponent = (props) => { + const [confirmationResult, setConfirmationResult] = useState(''); + const { actionConfirmation: deleteConfirmation } = useContext(ActionConfirmationModalContext)!; + const handleDelete = async () => { + const res = await deleteConfirmation(props); + setConfirmationResult(res); + }; + + return ( +

+ +
+

{confirmationResult}

+

+ ); +}; + +const Template: StoryFn = (_args) => { + return ( + + + + + ); +}; + +export const ActionConfirmationModal = Template.bind({}); +ActionConfirmationModal.args = {}; diff --git a/packages/ui/src/providers/__snapshots__/action-confirmaton-modal.provider.test.tsx.snap b/packages/ui/src/providers/__snapshots__/action-confirmaton-modal.provider.test.tsx.snap index 76d27264e..b7091e6ec 100644 --- a/packages/ui/src/providers/__snapshots__/action-confirmaton-modal.provider.test.tsx.snap +++ b/packages/ui/src/providers/__snapshots__/action-confirmaton-modal.provider.test.tsx.snap @@ -84,28 +84,40 @@ exports[`ActionConfirmationModalProvider should allow consumers to update the mo
- - +
+ +
+
+ +
+
`; diff --git a/packages/ui/src/providers/action-confirmation-modal.provider.tsx b/packages/ui/src/providers/action-confirmation-modal.provider.tsx index b2f734f45..2dcd5ad23 100644 --- a/packages/ui/src/providers/action-confirmation-modal.provider.tsx +++ b/packages/ui/src/providers/action-confirmation-modal.provider.tsx @@ -1,4 +1,4 @@ -import { Button, ButtonVariant, Modal, ModalVariant } from '@patternfly/react-core'; +import { Button, ButtonVariant, Modal, ModalVariant, Split, SplitItem } from '@patternfly/react-core'; import { FunctionComponent, PropsWithChildren, createContext, useCallback, useMemo, useRef, useState } from 'react'; export const ACTION_ID_CANCEL = 'cancel'; @@ -81,6 +81,34 @@ export const ActionConfirmationModalContextProvider: FunctionComponent + {...Object.entries(buttonOptions).map(([actionId, option]) => ( + + + + ))} + + + + + ); + return ( {props.children} @@ -93,27 +121,7 @@ export const ActionConfirmationModalContextProvider: FunctionComponent ( - - )), - , - ]} + footer={footer} > {textParagraphs.length === 1 ? textParagraphs[0]