diff --git a/examples/bpk-component-drawer/examples.js b/examples/bpk-component-drawer/examples.js index 0d0f6b47fa..67883ace4c 100644 --- a/examples/bpk-component-drawer/examples.js +++ b/examples/bpk-component-drawer/examples.js @@ -262,10 +262,28 @@ const WithFullHeightContentExample = () => ( ); +const WithNonPaddedContentExample = () => ( + document.getElementById('pagewrap')} + padded={false} + > +
+

+ This has default padding disabled to give full control of the layout + e.g. full width background color. +

+
+
+); + export { DefaultExample, OverflowingExamples, CloseButtonTextExample, WithVisuallyHiddenTitleExample, WithFullHeightContentExample, + WithNonPaddedContentExample, }; diff --git a/examples/bpk-component-drawer/examples.module.scss b/examples/bpk-component-drawer/examples.module.scss index d9e5f6db36..0bec865783 100644 --- a/examples/bpk-component-drawer/examples.module.scss +++ b/examples/bpk-component-drawer/examples.module.scss @@ -30,3 +30,15 @@ .bpk-drawer-button { margin: auto auto 0; } + +.bpk-drawer-content-full-width { + height: 100%; + padding: tokens.bpk-spacing-base(); + background-color: tokens.$bpk-canvas-contrast-day; + + p { + padding: tokens.bpk-spacing-base(); + border-radius: tokens.$bpk-border-radius-md; + background-color: tokens.$bpk-surface-default-day; + } +} diff --git a/examples/bpk-component-drawer/stories.js b/examples/bpk-component-drawer/stories.js index 0972b7092c..6f12ca419b 100644 --- a/examples/bpk-component-drawer/stories.js +++ b/examples/bpk-component-drawer/stories.js @@ -16,7 +16,6 @@ * limitations under the License. */ - import BkpDrawer from '../../packages/bpk-component-drawer/src/BpkDrawer'; import { @@ -25,6 +24,7 @@ import { CloseButtonTextExample, WithVisuallyHiddenTitleExample, WithFullHeightContentExample, + WithNonPaddedContentExample, } from './examples'; export default { @@ -39,3 +39,5 @@ export const CloseButtonText = CloseButtonTextExample; export const WithVisuallyHiddenTitle = WithVisuallyHiddenTitleExample; export const WithFullHeightContent = WithFullHeightContentExample; + +export const WithNonPaddedContent = WithNonPaddedContentExample; diff --git a/packages/bpk-component-drawer/src/BpkDrawer.js b/packages/bpk-component-drawer/src/BpkDrawer.js index 88abfe42dc..4f201fe6a5 100644 --- a/packages/bpk-component-drawer/src/BpkDrawer.js +++ b/packages/bpk-component-drawer/src/BpkDrawer.js @@ -42,6 +42,7 @@ type Props = { closeLabel: ?string, closeText: ?string, hideTitle: ?boolean, + padded?: boolean, }; type State = { @@ -118,6 +119,7 @@ BpkDrawer.defaultProps = { closeLabel: null, closeText: null, hideTitle: false, + padded: true, }; export default BpkDrawer; diff --git a/packages/bpk-component-drawer/src/BpkDrawerContent-test.js b/packages/bpk-component-drawer/src/BpkDrawerContent-test.tsx similarity index 85% rename from packages/bpk-component-drawer/src/BpkDrawerContent-test.js rename to packages/bpk-component-drawer/src/BpkDrawerContent-test.tsx index 7c98f25186..acd6e7d7fe 100644 --- a/packages/bpk-component-drawer/src/BpkDrawerContent-test.js +++ b/packages/bpk-component-drawer/src/BpkDrawerContent-test.tsx @@ -16,7 +16,7 @@ * limitations under the License. */ -/* @flow strict */ +import type { ReactElement } from 'react'; import { render } from '@testing-library/react'; @@ -25,7 +25,7 @@ import BpkDrawerContent from './BpkDrawerContent'; jest.mock( 'react-transition-group/Transition', () => - ({ children }) => + ({ children }: { children: (state: string) => ReactElement }) => children('entered'), ); @@ -63,6 +63,22 @@ describe('BpkDrawerContent', () => { expect(asFragment()).toMatchSnapshot(); }); + it('should render correctly when it has padded=true', () => { + const { asFragment } = render( + + Drawer content + , + ); + expect(asFragment()).toMatchSnapshot(); + }); + it('should render correctly when it has a contentClassName', () => { const { asFragment } = render( mixed, - onCloseAnimationComplete: () => mixed, - onClose: () => mixed, + children: ReactNode, + dialogRef: () => React.RefObject, + onCloseAnimationComplete: () => void, + onClose: () => void id: string, title: string, - className: ?string, - contentClassName: ?string, - closeLabel: string, - closeText: ?string, - isDrawerShown: boolean, - hideTitle: boolean, - closeOnScrimClick: boolean, - isIphone: boolean, - isIpad: boolean, + className?: string, + contentClassName?: string, + closeLabel?: string, + closeText?: string, + isDrawerShown?: boolean, + hideTitle?: boolean, + closeOnScrimClick?: boolean, + isIphone?: boolean, + isIpad?: boolean, + padded?: boolean, }; -const BpkDrawerContent = (props: Props) => { - const { - children, - className, - closeLabel, - closeOnScrimClick, // Unused from withScrim scrim HOC - closeText, - contentClassName, - dialogRef, - hideTitle, - id, - isDrawerShown, - isIpad, // Unused from withScrim scrim HOC - isIphone, // Unused from withScrim scrim HOC - onClose, - onCloseAnimationComplete, - title, - ...rest - } = props; +const BpkDrawerContent = ({ + children, + className, + closeLabel, + closeOnScrimClick = true, // Unused from withScrim scrim HOC + closeText, + contentClassName, + dialogRef, + hideTitle = false, + id, + isDrawerShown = true, + isIpad = false, // Unused from withScrim scrim HOC + isIphone = false, // Unused from withScrim scrim HOC + onClose, + onCloseAnimationComplete, + padded, + title, + ...rest +}: Props) => { const drawerClassNames = [getClassName('bpk-drawer')]; const headerClassNames = [getClassName('bpk-drawer__heading')]; @@ -83,6 +84,10 @@ const BpkDrawerContent = (props: Props) => { headerClassNames.push(getClassName('bpk-drawer__heading--visually-hidden')); } + if (padded) { + contentClassNames.push(getClassName('bpk-drawer__content--padded')); + } + if (contentClassName) { contentClassNames.push(contentClassName); } @@ -101,11 +106,10 @@ const BpkDrawerContent = (props: Props) => { in={isDrawerShown} onExited={onCloseAnimationComplete} > - {(status) => ( - // $FlowFixMe[cannot-spread-inexact] - inexact rest. See decisions/flowfixme.md + {(status: string) => (