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(true)}>Open modal + 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} + , + + {cancelButtonLabel} + , + ]} + {...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": + + + + + + + + + + + + + + + + + + + + + Warning alert: + + + Unsaved changes + + + + + Warning modal content + + + + + + + , + "container": , + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "rerender": [Function], + "unmount": [Function], +} +`; diff --git a/packages/module/src/WarningModal/index.ts b/packages/module/src/WarningModal/index.ts new file mode 100644 index 00000000..c640c292 --- /dev/null +++ b/packages/module/src/WarningModal/index.ts @@ -0,0 +1,2 @@ +export { default } from './WarningModal'; +export * from './WarningModal'; diff --git a/packages/module/src/index.ts b/packages/module/src/index.ts index 69ff1c26..80ed1afb 100644 --- a/packages/module/src/index.ts +++ b/packages/module/src/index.ts @@ -35,3 +35,6 @@ export * from './TagCount'; export { default as UnavailableContent } from './UnavailableContent'; export * from './UnavailableContent'; + +export { default as WarningModal } from './WarningModal'; +export * from './WarningModal';