diff --git a/examples/bpk-component-modal-v2/examples.tsx b/examples/bpk-component-modal-v2/examples.tsx index a461fba300..ee11a5122e 100644 --- a/examples/bpk-component-modal-v2/examples.tsx +++ b/examples/bpk-component-modal-v2/examples.tsx @@ -23,7 +23,7 @@ import { Component, Children } from 'react'; import BpkText, { TEXT_STYLES } from '../../packages/bpk-component-text'; import BpkButton from '../../packages/bpk-component-button'; import { cssModules, withDefaultProps } from '../../packages/bpk-react-utils'; -import { BpkModalV2 } from '../../packages/bpk-component-modal/src/BpkModalV2/BpkModal'; +import { BpkModalV2 } from '../../packages/bpk-component-modal'; import STYLES from './examples.module.scss'; @@ -161,8 +161,8 @@ const LongTitleExample = () => ( const HeaderNoTitleExample = () => ( - This is a default modal using the HTML dialog element without a header. - You can put anything you want in here. + This is a modal using the HTML dialog element without a header. You can + put anything you want in here. ); @@ -199,31 +199,41 @@ const NoPaddingExample = () => ( const NoPaddingNoTitleExample = () => ( - This is a default modal. You can put anything you want in here. + This is a modal without padding. You can put anything you want in here. ); const FullScreenOnDesktopExample = () => ( - This is a default modal. You can put anything you want in here. + This is a full screen modal for desktop. You can put anything you want in + here. ); const FullScreenOnDesktopNoTitleExample = () => ( - This is a default modal. You can put anything you want in here. + This is a full screen modal for mobile without title. You can put anything + you want in here. ); const NoFullScreenOnMobileExample = () => ( - This is a default modal. You can put anything you want in here. + This is a no full screen modal for mobile. You can put anything you want in + here. ); const NoFullScreenOnMobileNoTitleExample = () => ( - This is a default modal. You can put anything you want in here. + This is a no full screen modal for mobile without title. You can put + anything you want in here. + +); + +const NoHeaderExample = () => ( + + This is a modal without header. You can put anything you want in here. ); @@ -266,5 +276,6 @@ export { FullScreenOnDesktopNoTitleExample, NoFullScreenOnMobileExample, NoFullScreenOnMobileNoTitleExample, + NoHeaderExample, MultipleModalsExample, }; diff --git a/examples/bpk-component-modal-v2/stories.tsx b/examples/bpk-component-modal-v2/stories.tsx index a51e0203a8..d548d5bf0f 100644 --- a/examples/bpk-component-modal-v2/stories.tsx +++ b/examples/bpk-component-modal-v2/stories.tsx @@ -30,6 +30,7 @@ import { FullScreenOnDesktopNoTitleExample, NoFullScreenOnMobileExample, NoFullScreenOnMobileNoTitleExample, + NoHeaderExample, MultipleModalsExample, } from './examples'; @@ -50,4 +51,5 @@ export const FullScreenOnDesktop = FullScreenOnDesktopExample; export const FullScreenOnDesktopNoTitle = FullScreenOnDesktopNoTitleExample; export const NoFullScreenOnMobile = NoFullScreenOnMobileExample; export const NoFullScreenOnMobileNoTitle = NoFullScreenOnMobileNoTitleExample; +export const NoHeader = NoHeaderExample; export const MultipleModals = MultipleModalsExample; diff --git a/packages/bpk-component-modal/src/BpkModalV2/BpKModal-test.tsx b/packages/bpk-component-modal/src/BpkModalV2/BpKModal-test.tsx index 7b4937f6ae..4a419b1e06 100644 --- a/packages/bpk-component-modal/src/BpkModalV2/BpKModal-test.tsx +++ b/packages/bpk-component-modal/src/BpkModalV2/BpKModal-test.tsx @@ -24,12 +24,10 @@ import { type BpkModalV2 as DialogType } from './BpkModal'; describe('BpkModalV2', () => { const props = { id: 'bpk-modal-element', - ariaLabelledby: 'bpk-modal-label-my-dialog', + ariaLabelledby: 'bpk-modal-element', closeLabel: 'bpk-modal-button-close', isOpen: true, onClose: jest.fn(), - title: 'Backpack Dialog Element', - showHeader: true, }; beforeEach(() => { @@ -47,7 +45,7 @@ describe('BpkModalV2', () => { it('should render correctly with content', () => { const { asFragment } = render( - +
Content
, ); @@ -91,15 +89,39 @@ describe('BpkModalV2', () => { expect(document.getElementById('bpk-modal-element')).toBeInTheDocument(); }); - it('should not render title if title is set to empty string', () => { + it('should render title correctly', () => { + render( + +
Content
+
, + ); + + expect(screen.getByText('Modal with dialog element')).toBeInTheDocument(); + expect(screen.getByTitle('bpk-modal-button-close')).toBeInTheDocument(); + }); + + it('should not render title when title does not exist', () => { + render( + +
Content
+
, + ); + + expect( + screen.queryByText('Modal with dialog element'), + ).not.toBeInTheDocument(); + expect(screen.getByTitle('bpk-modal-button-close')).toBeInTheDocument(); + }); + + it('should not render header when showHeader is false', () => { render( - +
Content
, ); - expect(screen.queryByRole('Dialog Element')).not.toBeInTheDocument(); - expect(document.getElementsByClassName('bpk-close-button')).toBeTruthy(); + expect(document.getElementById('bpk-modal-element')).toBeInTheDocument(); + expect(document.getElementById('bpk-modal-element-title')).toBeNull(); }); it('should call showModal to open dialog', () => { diff --git a/packages/bpk-component-modal/src/BpkModalV2/BpKModal.module.scss b/packages/bpk-component-modal/src/BpkModalV2/BpKModal.module.scss index 1637c50e9c..3548fc7bca 100644 --- a/packages/bpk-component-modal/src/BpkModalV2/BpKModal.module.scss +++ b/packages/bpk-component-modal/src/BpkModalV2/BpKModal.module.scss @@ -71,7 +71,7 @@ margin: 0 auto; padding: 0; border: none; - background: $bpk-canvas-contrast-day; + background: $bpk-modal-background-color; overflow-y: scroll; inset-block-start: 0; inset-inline: 0; diff --git a/packages/bpk-component-modal/src/BpkModalV2/BpkModal.d.ts b/packages/bpk-component-modal/src/BpkModalV2/BpkModal.d.ts index 38ea61cac1..d37940c8b2 100644 --- a/packages/bpk-component-modal/src/BpkModalV2/BpkModal.d.ts +++ b/packages/bpk-component-modal/src/BpkModalV2/BpkModal.d.ts @@ -29,6 +29,7 @@ export type Props = { noFullScreenOnMobile?: boolean; onClose: () => void | null; padded?: boolean; + showHeader?: boolean; title?: string | null; wide?: boolean; }; diff --git a/packages/bpk-component-modal/src/BpkModalV2/BpkModal.tsx b/packages/bpk-component-modal/src/BpkModalV2/BpkModal.tsx index e75d58eb5c..04fa7c60e5 100644 --- a/packages/bpk-component-modal/src/BpkModalV2/BpkModal.tsx +++ b/packages/bpk-component-modal/src/BpkModalV2/BpkModal.tsx @@ -38,10 +38,39 @@ export type Props = { noFullScreenOnMobile?: boolean; onClose: () => void | null; padded?: boolean; + showHeader?: boolean; title?: string | null; wide?: boolean; }; +const Header = ({ + closeLabel, + id, + onClose, + title, +}: { + closeLabel: string; + id: string | undefined; + onClose: () => void | null; + title?: string | null; +}) => { + if (title) { + return ( +
+
+ {title} +
+ +
+ ); + } + return ( +
+ +
+ ); +}; + const Heading = withDefaultProps(BpkText, { textStyle: TEXT_STYLES.label1, tagName: 'h2', @@ -75,6 +104,7 @@ export const BpkModalV2 = (props: Props) => { noFullScreenOnMobile, onClose, padded, + showHeader = true, title, wide, } = props; @@ -116,12 +146,6 @@ export const BpkModalV2 = (props: Props) => { padded && 'bpk-modal__container--padded', ); - const closeButton = ( -
- -
- ); - return isOpen ? (
{ data-open={isOpen} ref={ref} > - {title ? ( -
-
- {title} -
- {closeButton} -
- ) : ( -
- {closeButton} -
+ {showHeader && ( +
)}
{children}
diff --git a/packages/bpk-component-modal/src/BpkModalV2/README.md b/packages/bpk-component-modal/src/BpkModalV2/README.md index defae34959..466939d887 100644 --- a/packages/bpk-component-modal/src/BpkModalV2/README.md +++ b/packages/bpk-component-modal/src/BpkModalV2/README.md @@ -85,5 +85,6 @@ class App extends Component { | fullScreenOnMobile | bool | false | false | | noFullScreenOnMobile | bool | false | false | | padded | bool | false | false | +| showHeader | bool | false | true | | title | string | false | '' | | wide | bool | false | false | diff --git a/packages/bpk-component-modal/src/BpkModalV2/__snapshots__/BpKModal-test.tsx.snap b/packages/bpk-component-modal/src/BpkModalV2/__snapshots__/BpKModal-test.tsx.snap index 0ab722159e..d6157a5389 100644 --- a/packages/bpk-component-modal/src/BpkModalV2/__snapshots__/BpKModal-test.tsx.snap +++ b/packages/bpk-component-modal/src/BpkModalV2/__snapshots__/BpKModal-test.tsx.snap @@ -11,44 +11,33 @@ exports[`BpkModalV2 is not supported should render correctly with polyfill and c id="bpk-modal-element-polyfill" />
-
-

- Backpack Dialog Element -

-
-
- -
+ + +
- Backpack Dialog Element + Modal with dialog element
-
- -
+ + +