From 1331a84303955d1b2bca9b8548ce0dc70885d77f Mon Sep 17 00:00:00 2001 From: Titani Date: Tue, 31 Mar 2026 10:27:43 -0400 Subject: [PATCH] feat(Drawer): Added support for glass --- .../src/components/Drawer/Drawer.tsx | 3 ++ .../components/Drawer/DrawerPanelContent.tsx | 17 +++++++++- .../src/components/Drawer/DrawerSection.tsx | 9 +++++- .../__tests__/DrawerPanelContent.test.tsx | 32 ++++++++++++++++++- .../Drawer/__tests__/DrawerSection.test.tsx | 15 +++++++++ .../src/components/Drawer/examples/Drawer.md | 2 +- .../PrimaryDetailContentPadding.tsx | 4 +-- 7 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 packages/react-core/src/components/Drawer/__tests__/DrawerSection.test.tsx diff --git a/packages/react-core/src/components/Drawer/Drawer.tsx b/packages/react-core/src/components/Drawer/Drawer.tsx index 3470426a6b8..eaa6c58dfcd 100644 --- a/packages/react-core/src/components/Drawer/Drawer.tsx +++ b/packages/react-core/src/components/Drawer/Drawer.tsx @@ -5,6 +5,9 @@ import { css } from '@patternfly/react-styles'; export enum DrawerColorVariant { default = 'default', secondary = 'secondary', + /** + * @deprecated `DrawerColorVariant.noBackground` is deprecated. Use the `isPlain` prop on `DrawerPanelContent` and the `DrawerSection`instead. + */ noBackground = 'no-background' } diff --git a/packages/react-core/src/components/Drawer/DrawerPanelContent.tsx b/packages/react-core/src/components/Drawer/DrawerPanelContent.tsx index 814390d3955..b1106f28c49 100644 --- a/packages/react-core/src/components/Drawer/DrawerPanelContent.tsx +++ b/packages/react-core/src/components/Drawer/DrawerPanelContent.tsx @@ -37,6 +37,12 @@ export interface DrawerPanelContentProps extends Omit void; /** The minimum size of a drawer. */ @@ -56,7 +62,10 @@ export interface DrawerPanelContentProps extends Omit { className?: string; /** Content to be rendered in the drawer section. */ children?: React.ReactNode; - /** Color variant of the background of the drawer Section */ + /** + * Color variant of the background of the drawer section. + * The `no-background` value is deprecated; use the `isPlain` prop instead. + */ colorVariant?: DrawerColorVariant | 'no-background' | 'default' | 'secondary'; + /** @beta Flag indicating that the drawer section should use plain styles. */ + isPlain?: boolean; } export const DrawerSection: React.FunctionComponent = ({ className = '', children, colorVariant = DrawerColorVariant.default, + isPlain = false, ...props }: DrawerSectionProps) => (
{ expect(screen.getByText('Drawer panel content')).toHaveClass(styles.drawerPanel, { exact: true }); }); -test(`Renders with class ${styles.modifiers.noBackground} when colorVariant="no-background"`, () => { +test(`Renders with class ${styles.modifiers.noBackground} when deprecated colorVariant="no-background" is used`, () => { render( Drawer panel content @@ -188,3 +188,33 @@ test(`Renders with class 'pf-m-no-glass' when hasNoGlass is true`, () => { expect(screen.getByText('Drawer panel content')).toHaveClass('pf-m-no-glass'); }); + +test(`Renders with class ${styles.modifiers.glass} when isGlass is true`, () => { + render( + + Drawer panel content + + ); + + expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.glass); +}); + +test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () => { + render( + + Drawer panel content + + ); + + expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.plain); +}); + +test(`Renders with class ${styles.modifiers.noPlain} when isNoPlainOnGlass is true`, () => { + render( + + Drawer panel content + + ); + + expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.noPlain); +}); diff --git a/packages/react-core/src/components/Drawer/__tests__/DrawerSection.test.tsx b/packages/react-core/src/components/Drawer/__tests__/DrawerSection.test.tsx new file mode 100644 index 00000000000..849cf457ddf --- /dev/null +++ b/packages/react-core/src/components/Drawer/__tests__/DrawerSection.test.tsx @@ -0,0 +1,15 @@ +import { render, screen } from '@testing-library/react'; +import { DrawerSection } from '../DrawerSection'; +import styles from '@patternfly/react-styles/css/components/Drawer/drawer'; + +test(`Renders with only class ${styles.drawerSection} by default`, () => { + render(Section content); + + expect(screen.getByText('Section content')).toHaveClass(styles.drawerSection, { exact: true }); +}); + +test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () => { + render(Section content); + + expect(screen.getByText('Section content')).toHaveClass(styles.modifiers.plain); +}); diff --git a/packages/react-core/src/components/Drawer/examples/Drawer.md b/packages/react-core/src/components/Drawer/examples/Drawer.md index 544bc08a2ba..22d79215fe6 100644 --- a/packages/react-core/src/components/Drawer/examples/Drawer.md +++ b/packages/react-core/src/components/Drawer/examples/Drawer.md @@ -13,7 +13,7 @@ propComponents: DrawerCloseButton, DrawerPanelDescription, DrawerPanelBody, - DrawerPanelFocusTrapObject + DrawerPanelFocusTrapObject, ] section: components --- diff --git a/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailContentPadding.tsx b/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailContentPadding.tsx index 98c69eabcd8..fb26723037a 100644 --- a/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailContentPadding.tsx +++ b/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailContentPadding.tsx @@ -178,7 +178,7 @@ export const PrimaryDetailContentPadding: React.FunctionComponent = () => { ); const panelContent = ( - + node-{drawerPanelBodyContent} @@ -429,7 +429,7 @@ export const PrimaryDetailContentPadding: React.FunctionComponent = () => { <Divider component="div" /> <PageSection padding={{ default: 'noPadding' }} aria-label="Drawer content section"> <Drawer isExpanded={isDrawerExpanded}> - <DrawerContent panelContent={panelContent} colorVariant="no-background"> + <DrawerContent panelContent={panelContent}> <DrawerContentBody hasPadding>{drawerContent}</DrawerContentBody> </DrawerContent> </Drawer>