-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Fix confirmation modal buttons layout
Added a storybook to show them
- Loading branch information
1 parent
a887b87
commit 605ddd4
Showing
3 changed files
with
129 additions
and
43 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
packages/ui-tests/stories/modal/ActionConfirmationModal.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof ActionConfirmationModalContextProvider>; | ||
|
||
type TestComponentProps = { | ||
title: string; | ||
btnTitle?: string; | ||
text?: string; | ||
additionalModalText?: string; | ||
buttonOptions?: Record<string, ActionConfirmationButtonOption>; | ||
}; | ||
|
||
const TestComponent: FunctionComponent<TestComponentProps> = (props) => { | ||
const [confirmationResult, setConfirmationResult] = useState<string>(''); | ||
const { actionConfirmation: deleteConfirmation } = useContext(ActionConfirmationModalContext)!; | ||
const handleDelete = async () => { | ||
const res = await deleteConfirmation(props); | ||
setConfirmationResult(res); | ||
}; | ||
|
||
return ( | ||
<p> | ||
<button onClick={handleDelete}>{props.btnTitle ?? props.title}</button> | ||
<br /> | ||
<h4>{confirmationResult}</h4> | ||
</p> | ||
); | ||
}; | ||
|
||
const Template: StoryFn<typeof ActionConfirmationModalContextProvider> = (_args) => { | ||
return ( | ||
<ActionConfirmationModalContextProvider> | ||
<TestComponent title="Confirm / Cancel" /> | ||
<TestComponent | ||
title="Custom Title" | ||
btnTitle="Delete step & file / Delete step only / Cancel" | ||
text="Modal text: Delete step & file, Delete step only or Cancel." | ||
additionalModalText="Additional text for 3 options modal text" | ||
buttonOptions={{ | ||
'del-step-and-file': { | ||
buttonText: 'Delete both step and file', | ||
variant: ButtonVariant.danger, | ||
}, | ||
'del-step-only': { | ||
buttonText: 'Delete the step, but keep the file', | ||
variant: ButtonVariant.secondary, | ||
isDanger: true, | ||
}, | ||
}} | ||
/> | ||
</ActionConfirmationModalContextProvider> | ||
); | ||
}; | ||
|
||
export const ActionConfirmationModal = Template.bind({}); | ||
ActionConfirmationModal.args = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters