diff --git a/packages/module/patternfly-docs/content/extensions/component-groups/examples/WarningModal/WarningModal.md b/packages/module/patternfly-docs/content/extensions/component-groups/examples/WarningModal/WarningModal.md new file mode 100644 index 00000000..21dd2eb8 --- /dev/null +++ b/packages/module/patternfly-docs/content/extensions/component-groups/examples/WarningModal/WarningModal.md @@ -0,0 +1,29 @@ +--- +# Sidenav top-level section +# should be the same for all markdown files +section: extensions +subsection: Component groups +# Sidenav secondary level section +# should be the same for all markdown files +id: Warning modal +# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility) +source: react +# If you use typescript, the name of the interface to display props for +# These are found through the sourceProps function provided in patternfly-docs.source.js +propComponents: ['WarningModal'] +--- + +import WarningModal from '@patternfly/react-component-groups/dist/dynamic/WarningModal'; + +A **warning modal** component displays a modal asking user to confirm his intention to perform a risky action. + +## Examples + +### Basic warning modal + +A basic warning modal component provides users with a basic layout to which only specific texts need to be passed. +Action buttons callbacks can be customized using `onConfirm` and `onClose`. + +```js file="./WarningModalExample.tsx" + +``` diff --git a/packages/module/patternfly-docs/content/extensions/component-groups/examples/WarningModal/WarningModalExample.tsx b/packages/module/patternfly-docs/content/extensions/component-groups/examples/WarningModal/WarningModalExample.tsx new file mode 100644 index 00000000..92b3079b --- /dev/null +++ b/packages/module/patternfly-docs/content/extensions/component-groups/examples/WarningModal/WarningModalExample.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import WarningModal from '@patternfly/react-component-groups/dist/dynamic/WarningModal'; +import { Button } from '@patternfly/react-core'; + +export const BasicExample: React.FunctionComponent = () => { + const [ isOpen, setIsOpen ] = React.useState(false); + return <> + + setIsOpen(false)} + onConfirm={() => setIsOpen(false)}> + Your page contains unsaved changes. Do you want to leave? + + +}; diff --git a/packages/module/src/WarningModal/WarningModal.test.tsx b/packages/module/src/WarningModal/WarningModal.test.tsx new file mode 100644 index 00000000..9467870e --- /dev/null +++ b/packages/module/src/WarningModal/WarningModal.test.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import WarningModal from './WarningModal'; + +describe('WarningModal component', () => { + const initialProps = { + title: 'Unsaved changes', + onClose: () => null, + onConfirm: () => null, + }; + + it('should render', () => { + const container = render(Warning modal content); + expect(container).toMatchSnapshot(); + }); +}); \ No newline at end of file diff --git a/packages/module/src/WarningModal/WarningModal.tsx b/packages/module/src/WarningModal/WarningModal.tsx new file mode 100644 index 00000000..5f5f25b6 --- /dev/null +++ b/packages/module/src/WarningModal/WarningModal.tsx @@ -0,0 +1,55 @@ +import React from 'react'; +import { Button, ModalProps, Modal, ModalVariant, ButtonVariant } from '@patternfly/react-core'; + +export interface WarningModalProps extends Omit { + /** Callback for the confirm action button. */ + onConfirm?: () => void; + /** Custom label for the confirm action button */ + confirmButtonLabel? : string; + /** Custom label for the cancel action button */ + cancelButtonLabel? : string; +} + +const WarningModal: React.FunctionComponent = ({ + isOpen, + onConfirm, + onClose, + children, + confirmButtonLabel = 'Confirm', + cancelButtonLabel = 'Cancel', + variant = ModalVariant.small, + titleIconVariant = 'warning', + ...props +}: WarningModalProps) => ( + + {confirmButtonLabel} + , + , + ]} + {...props} + > + {children} + +); + + +export default WarningModal; diff --git a/packages/module/src/WarningModal/__snapshots__/WarningModal.test.tsx.snap b/packages/module/src/WarningModal/__snapshots__/WarningModal.test.tsx.snap new file mode 100644 index 00000000..8bc5beaf --- /dev/null +++ b/packages/module/src/WarningModal/__snapshots__/WarningModal.test.tsx.snap @@ -0,0 +1,183 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`WarningModal component should render 1`] = ` +{ + "asFragment": [Function], + "baseElement": +