Skip to content

Commit 1331a84

Browse files
committed
feat(Drawer): Added support for glass
1 parent 4e03cd7 commit 1331a84

File tree

7 files changed

+76
-6
lines changed

7 files changed

+76
-6
lines changed

packages/react-core/src/components/Drawer/Drawer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { css } from '@patternfly/react-styles';
55
export enum DrawerColorVariant {
66
default = 'default',
77
secondary = 'secondary',
8+
/**
9+
* @deprecated `DrawerColorVariant.noBackground` is deprecated. Use the `isPlain` prop on `DrawerPanelContent` and the `DrawerSection`instead.
10+
*/
811
noBackground = 'no-background'
912
}
1013

packages/react-core/src/components/Drawer/DrawerPanelContent.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export interface DrawerPanelContentProps extends Omit<React.HTMLProps<HTMLDivEle
3737
isResizable?: boolean;
3838
/** @beta Flag indicating that the drawer panel should disable glass styles. This prop is intended to work with isPill drawers. */
3939
hasNoGlass?: boolean;
40+
/** @beta Flag indicating that the drawer panel should use glass styles. */
41+
isGlass?: boolean;
42+
/** @beta Flag indicating that the drawer panel should use plain styles. */
43+
isPlain?: boolean;
44+
/** @beta Flag indicating that plain styles should be disabled when glass styles are used. */
45+
isNoPlainOnGlass?: boolean;
4046
/** Callback for resize end. */
4147
onResize?: (event: MouseEvent | TouchEvent | React.KeyboardEvent, width: number, id: string) => void;
4248
/** The minimum size of a drawer. */
@@ -56,7 +62,10 @@ export interface DrawerPanelContentProps extends Omit<React.HTMLProps<HTMLDivEle
5662
xl?: 'width_25' | 'width_33' | 'width_50' | 'width_66' | 'width_75' | 'width_100';
5763
'2xl'?: 'width_25' | 'width_33' | 'width_50' | 'width_66' | 'width_75' | 'width_100';
5864
};
59-
/** Color variant of the background of the drawer panel */
65+
/**
66+
* Color variant of the background of the drawer panel.
67+
* The `no-background`is deprecated; use the `isPlain` prop instead.
68+
*/
6069
colorVariant?: DrawerColorVariant | 'no-background' | 'default' | 'secondary';
6170
/** Adds and customizes a focus trap on the drawer panel content. */
6271
focusTrap?: DrawerPanelFocusTrapObject;
@@ -71,6 +80,9 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
7180
hasNoBorder = false,
7281
isResizable = false,
7382
hasNoGlass = false,
83+
isGlass = false,
84+
isPlain = false,
85+
isNoPlainOnGlass = false,
7486
onResize,
7587
minSize,
7688
defaultSize,
@@ -368,6 +380,9 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
368380
styles.drawerPanel,
369381
isResizable && styles.modifiers.resizable,
370382
hasNoGlass && 'pf-m-no-glass',
383+
isGlass && styles.modifiers.glass,
384+
isPlain && styles.modifiers.plain,
385+
isNoPlainOnGlass && styles.modifiers.noPlain,
371386
hasNoBorder && styles.modifiers.noBorder,
372387
formatBreakpointMods(widths, styles),
373388
colorVariant === DrawerColorVariant.noBackground && styles.modifiers.noBackground,

packages/react-core/src/components/Drawer/DrawerSection.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,26 @@ export interface DrawerSectionProps extends React.HTMLProps<HTMLDivElement> {
77
className?: string;
88
/** Content to be rendered in the drawer section. */
99
children?: React.ReactNode;
10-
/** Color variant of the background of the drawer Section */
10+
/**
11+
* Color variant of the background of the drawer section.
12+
* The `no-background` value is deprecated; use the `isPlain` prop instead.
13+
*/
1114
colorVariant?: DrawerColorVariant | 'no-background' | 'default' | 'secondary';
15+
/** @beta Flag indicating that the drawer section should use plain styles. */
16+
isPlain?: boolean;
1217
}
1318

1419
export const DrawerSection: React.FunctionComponent<DrawerSectionProps> = ({
1520
className = '',
1621
children,
1722
colorVariant = DrawerColorVariant.default,
23+
isPlain = false,
1824
...props
1925
}: DrawerSectionProps) => (
2026
<div
2127
className={css(
2228
styles.drawerSection,
29+
isPlain && styles.modifiers.plain,
2330
colorVariant === DrawerColorVariant.noBackground && styles.modifiers.noBackground,
2431
colorVariant === DrawerColorVariant.secondary && styles.modifiers.secondary,
2532
className

packages/react-core/src/components/Drawer/__tests__/DrawerPanelContent.test.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test(`Renders with only class ${styles.drawerPanel} by default`, () => {
1313
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.drawerPanel, { exact: true });
1414
});
1515

16-
test(`Renders with class ${styles.modifiers.noBackground} when colorVariant="no-background"`, () => {
16+
test(`Renders with class ${styles.modifiers.noBackground} when deprecated colorVariant="no-background" is used`, () => {
1717
render(
1818
<Drawer isExpanded>
1919
<DrawerPanelContent colorVariant="no-background">Drawer panel content</DrawerPanelContent>
@@ -188,3 +188,33 @@ test(`Renders with class 'pf-m-no-glass' when hasNoGlass is true`, () => {
188188

189189
expect(screen.getByText('Drawer panel content')).toHaveClass('pf-m-no-glass');
190190
});
191+
192+
test(`Renders with class ${styles.modifiers.glass} when isGlass is true`, () => {
193+
render(
194+
<Drawer isExpanded>
195+
<DrawerPanelContent isGlass>Drawer panel content</DrawerPanelContent>
196+
</Drawer>
197+
);
198+
199+
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.glass);
200+
});
201+
202+
test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () => {
203+
render(
204+
<Drawer isExpanded>
205+
<DrawerPanelContent isPlain>Drawer panel content</DrawerPanelContent>
206+
</Drawer>
207+
);
208+
209+
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.plain);
210+
});
211+
212+
test(`Renders with class ${styles.modifiers.noPlain} when isNoPlainOnGlass is true`, () => {
213+
render(
214+
<Drawer isExpanded>
215+
<DrawerPanelContent isNoPlainOnGlass>Drawer panel content</DrawerPanelContent>
216+
</Drawer>
217+
);
218+
219+
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.noPlain);
220+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { DrawerSection } from '../DrawerSection';
3+
import styles from '@patternfly/react-styles/css/components/Drawer/drawer';
4+
5+
test(`Renders with only class ${styles.drawerSection} by default`, () => {
6+
render(<DrawerSection>Section content</DrawerSection>);
7+
8+
expect(screen.getByText('Section content')).toHaveClass(styles.drawerSection, { exact: true });
9+
});
10+
11+
test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () => {
12+
render(<DrawerSection isPlain>Section content</DrawerSection>);
13+
14+
expect(screen.getByText('Section content')).toHaveClass(styles.modifiers.plain);
15+
});

packages/react-core/src/components/Drawer/examples/Drawer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ propComponents:
1313
DrawerCloseButton,
1414
DrawerPanelDescription,
1515
DrawerPanelBody,
16-
DrawerPanelFocusTrapObject
16+
DrawerPanelFocusTrapObject,
1717
]
1818
section: components
1919
---

packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailContentPadding.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export const PrimaryDetailContentPadding: React.FunctionComponent = () => {
178178
);
179179

180180
const panelContent = (
181-
<DrawerPanelContent>
181+
<DrawerPanelContent isPlain>
182182
<DrawerHead>
183183
<Title headingLevel="h2" size="xl">
184184
node-{drawerPanelBodyContent}
@@ -429,7 +429,7 @@ export const PrimaryDetailContentPadding: React.FunctionComponent = () => {
429429
<Divider component="div" />
430430
<PageSection padding={{ default: 'noPadding' }} aria-label="Drawer content section">
431431
<Drawer isExpanded={isDrawerExpanded}>
432-
<DrawerContent panelContent={panelContent} colorVariant="no-background">
432+
<DrawerContent panelContent={panelContent}>
433433
<DrawerContentBody hasPadding>{drawerContent}</DrawerContentBody>
434434
</DrawerContent>
435435
</Drawer>

0 commit comments

Comments
 (0)