From b8eb46cf5dc752de35168bd783de375ac2d053b0 Mon Sep 17 00:00:00 2001 From: Zein Sleiman Date: Tue, 23 Jan 2024 15:55:13 -0600 Subject: [PATCH 1/9] feat(WarningModal): add RemoveModal features to WarningModal --- .../examples/RemoveModal/RemoveModal.md | 35 ++++++++ .../RemoveModalCheckboxExample.tsx | 22 +++++ .../RemoveModal/RemoveModalExample.tsx | 22 +++++ .../src/RemoveModal/RemoveModal.test.tsx | 21 +++++ .../module/src/RemoveModal/RemoveModal.tsx | 83 +++++++++++++++++++ packages/module/src/RemoveModal/index.ts | 2 + packages/module/src/index.ts | 3 + 7 files changed, 188 insertions(+) create mode 100644 packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModal.md create mode 100644 packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModalCheckboxExample.tsx create mode 100644 packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModalExample.tsx create mode 100644 packages/module/src/RemoveModal/RemoveModal.test.tsx create mode 100644 packages/module/src/RemoveModal/RemoveModal.tsx create mode 100644 packages/module/src/RemoveModal/index.ts diff --git a/packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModal.md b/packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModal.md new file mode 100644 index 00000000..21a06a74 --- /dev/null +++ b/packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModal.md @@ -0,0 +1,35 @@ +--- +# 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: Remove 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: ['RemoveModal'] +--- + +import RemoveModal from '@patternfly/react-component-groups/dist/dynamic/RemoveModal'; + +A **remove modal** component displays a modal when a user performs a removal of a object, which asks them to confirm or cancel the action. + +## Examples + +### Basic remove modal + +A basic remove modal is triggered when a user tries to perform a removal of an object. + +```js file="./RemoveModalExample.tsx" + +``` + +### Remove modal with checkbox +A basic remove modal that requires a checkbox before confirming. +```js file="./RemoveModalCheckboxExample.tsx" + +``` + diff --git a/packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModalCheckboxExample.tsx b/packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModalCheckboxExample.tsx new file mode 100644 index 00000000..c8df5044 --- /dev/null +++ b/packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModalCheckboxExample.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import RemoveModal from '@patternfly/react-component-groups/dist/dynamic/RemoveModal'; +import { Button } from '@patternfly/react-core'; + +export const BasicExample: React.FunctionComponent = () => { + const [ isOpen, setIsOpen ] = React.useState(false); + return <> + + setIsOpen(false)} + onSubmit={() => setIsOpen(false)} + withCheckbox={true} + confirmCheckMessage='checked' + > + + + +} \ No newline at end of file diff --git a/packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModalExample.tsx b/packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModalExample.tsx new file mode 100644 index 00000000..26636d1a --- /dev/null +++ b/packages/module/patternfly-docs/content/extensions/component-groups/examples/RemoveModal/RemoveModalExample.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import RemoveModal from '@patternfly/react-component-groups/dist/dynamic/RemoveModal'; +import { Button } from '@patternfly/react-core'; + +export const BasicExample: React.FunctionComponent = () => { + const [ isOpen, setIsOpen ] = React.useState(false); + return <> + + setIsOpen(false)} + onSubmit={() => setIsOpen(false)} + withCheckbox={false} + confirmCheckMessage='checked' + > + + + +} \ No newline at end of file diff --git a/packages/module/src/RemoveModal/RemoveModal.test.tsx b/packages/module/src/RemoveModal/RemoveModal.test.tsx new file mode 100644 index 00000000..84d736cc --- /dev/null +++ b/packages/module/src/RemoveModal/RemoveModal.test.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import RemoveModal from './RemoveModal'; + +describe('RemoveModal component', () => { + const initialProps = { + title: 'Delete Item', + text: 'do you want to delete?', + confirmButtonLabel: '', + confirmCheckMessage: 'checked', + onClose: () => null, + onConfirm: () => null, + onSubmit: () => null, + withCheckbox: false, + }; + + it('should render', () => { + const container = render(); + expect(container).toMatchSnapshot(); + }); +}); \ No newline at end of file diff --git a/packages/module/src/RemoveModal/RemoveModal.tsx b/packages/module/src/RemoveModal/RemoveModal.tsx new file mode 100644 index 00000000..edd57296 --- /dev/null +++ b/packages/module/src/RemoveModal/RemoveModal.tsx @@ -0,0 +1,83 @@ +import React, { useState } from 'react'; +import { Button, Checkbox, Modal, ModalProps, ModalVariant, Split, SplitItem, Stack, TextContent } from '@patternfly/react-core'; +import { createUseStyles } from 'react-jss' + + +const useStyles = createUseStyles({ + rbacDeleteIcon: { + color: 'var(--pf-v5-global--warning-color--100)', + marginRight: 'var(--pf-v5-global--spacer--xs)' + }, +}) + +export interface RemoveModalProps extends Omit { + /** Title for the Remove Modal. */ + title: string; + /** Text inside the Remove Modal */ + text: string; + /** Custom label for the cancel action button */ + confirmButtonLabel: string; + /** Callback for the submit action button */ + onSubmit: () => void; + /** Callback for the close action button */ + onClose: () => void; + /** Whether Modal requires a checkbox before confirming */ + withCheckbox: boolean, + /** Custom message after confirmation */ + confirmCheckMessage: string, +} + +const RemoveModal: React.FunctionComponent = ({ + title, + text, + onClose, + onSubmit, + isOpen, + confirmButtonLabel, + withCheckbox=false, + confirmCheckMessage, + ...props +}: RemoveModalProps) => { + const classes = useStyles(); + const [ checked, setChecked ] = useState(false); + + return ( + + {confirmButtonLabel} + , + , + ]} + {...props} + > + + + + {text} + + + + {withCheckbox ? ( + setChecked(!checked)} + label={confirmCheckMessage} + id="remove-modal-check" + className="pf-v5-u-mt-lg" + /> + ) : null} + + ); +}; + +export default RemoveModal; + diff --git a/packages/module/src/RemoveModal/index.ts b/packages/module/src/RemoveModal/index.ts new file mode 100644 index 00000000..1ffc6ec4 --- /dev/null +++ b/packages/module/src/RemoveModal/index.ts @@ -0,0 +1,2 @@ +export { default } from './RemoveModal'; +export * from './RemoveModal'; \ No newline at end of file diff --git a/packages/module/src/index.ts b/packages/module/src/index.ts index 168bfd0a..5691fd6f 100644 --- a/packages/module/src/index.ts +++ b/packages/module/src/index.ts @@ -39,6 +39,9 @@ export * from './NotAuthorized'; export { default as NotFoundIcon } from './NotFoundIcon'; export * from './NotFoundIcon'; +export { default as RemoveModal } from './RemoveModal'; +export * from './RemoveModal'; + export { default as SkeletonTable } from './SkeletonTable'; export * from './SkeletonTable'; From a222c8c10ff9b65d2c4540b775dd021f042f3bc3 Mon Sep 17 00:00:00 2001 From: Zein Sleiman Date: Tue, 23 Jan 2024 16:03:32 -0600 Subject: [PATCH 2/9] add snapshot --- .../__snapshots__/RemoveModal.test.tsx.snap | 197 ++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 packages/module/src/RemoveModal/__snapshots__/RemoveModal.test.tsx.snap diff --git a/packages/module/src/RemoveModal/__snapshots__/RemoveModal.test.tsx.snap b/packages/module/src/RemoveModal/__snapshots__/RemoveModal.test.tsx.snap new file mode 100644 index 00000000..a4829b9d --- /dev/null +++ b/packages/module/src/RemoveModal/__snapshots__/RemoveModal.test.tsx.snap @@ -0,0 +1,197 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`RemoveModal component should render 1`] = ` +{ + "asFragment": [Function], + "baseElement": +