Skip to content

Commit 3b9231d

Browse files
authored
feat(NotificationDrawer): Add notification drawer demo (#4640)
* feat(NotificationDrawer): Add notificaiton drawer demo * fix snapshots * reorgainize PageHeaderToolItems in demos * address PR comments after incorporating updated notification badge * only apply selected modifier if notifications all read * bump version and fix selected icon modifier application
1 parent 1d28c9e commit 3b9231d

File tree

13 files changed

+1172
-24
lines changed

13 files changed

+1172
-24
lines changed

packages/react-catalog-view-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"clean": "rimraf dist"
3636
},
3737
"dependencies": {
38-
"@patternfly/patternfly": "4.31.2",
38+
"@patternfly/patternfly": "4.31.3",
3939
"@patternfly/react-core": "^4.38.1",
4040
"@patternfly/react-styles": "^4.6.1",
4141
"classnames": "^2.2.5",

packages/react-charts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/patternfly/patternfly-react#readme",
3131
"dependencies": {
32-
"@patternfly/patternfly": "4.31.2",
32+
"@patternfly/patternfly": "4.31.3",
3333
"@patternfly/react-styles": "^4.6.1",
3434
"@patternfly/react-tokens": "^4.8.1",
3535
"hoist-non-react-statics": "^3.3.0",

packages/react-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"tslib": "^1.11.1"
4545
},
4646
"devDependencies": {
47-
"@patternfly/patternfly": "4.31.2",
47+
"@patternfly/patternfly": "4.31.3",
4848
"@rollup/plugin-commonjs": "^11.0.2",
4949
"@rollup/plugin-node-resolve": "^7.1.1",
5050
"@rollup/plugin-replace": "^2.3.1",

packages/react-core/src/components/NotificationDrawer/NotificationDrawerHeader.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export const NotificationDrawerHeader: React.FunctionComponent<NotificationDrawe
3030
<Text component={TextVariants.h1} className={css(styles.notificationDrawerHeaderTitle)}>
3131
{title}
3232
</Text>
33-
{count && <span className={css(styles.notificationDrawerHeaderStatus)}>{`${count} ${unreadText}`}</span>}
33+
{count !== undefined && (
34+
<span className={css(styles.notificationDrawerHeaderStatus)}>{`${count} ${unreadText}`}</span>
35+
)}
3436
{children && <div className={css(styles.notificationDrawerHeaderAction)}>{children}</div>}
3537
</div>
3638
);

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styles from '@patternfly/react-styles/css/components/Page/page';
33
import { css } from '@patternfly/react-styles';
44
import globalBreakpointXl from '@patternfly/react-tokens/dist/js/global_breakpoint_xl';
55
import { debounce } from '../../helpers/util';
6+
import { Drawer, DrawerContent, DrawerContentBody, DrawerPanelContent } from '../Drawer';
67

78
export enum PageLayouts {
89
vertical = 'vertical',
@@ -33,6 +34,12 @@ export interface PageProps extends React.HTMLProps<HTMLDivElement> {
3334
header?: React.ReactNode;
3435
/** Sidebar component for a side nav (e.g. <PageSidebar />) */
3536
sidebar?: React.ReactNode;
37+
/** Notification drawer component for an optional notification drawer (e.g. <NotificationDrawer />) */
38+
notificationDrawer?: React.ReactNode;
39+
/** Flag indicating Notification drawer in expanded */
40+
isNotificationDrawerExpanded?: boolean;
41+
/** Callback when notification drawer panel is finished expanding. */
42+
onNotificationDrawerExpand?: () => void;
3643
/** Skip to content component for the page */
3744
skipToContent?: React.ReactElement;
3845
/** Sets the value for role on the <main> element */
@@ -73,7 +80,9 @@ export class Page extends React.Component<PageProps, PageState> {
7380
isManagedSidebar: false,
7481
defaultManagedSidebarIsOpen: true,
7582
onPageResize: (): void => null,
76-
mainTabIndex: -1
83+
mainTabIndex: -1,
84+
isNotificationDrawerExpanded: false,
85+
onNotificationDrawerExpand: () => null
7786
};
7887

7988
constructor(props: PageProps) {
@@ -134,6 +143,9 @@ export class Page extends React.Component<PageProps, PageState> {
134143
children,
135144
header,
136145
sidebar,
146+
notificationDrawer,
147+
isNotificationDrawerExpanded,
148+
onNotificationDrawerExpand,
137149
skipToContent,
138150
role,
139151
mainContainerId,
@@ -154,22 +166,37 @@ export class Page extends React.Component<PageProps, PageState> {
154166
isNavOpen: mobileView ? mobileIsNavOpen : desktopIsNavOpen
155167
};
156168

169+
const main = (
170+
<main
171+
role={role}
172+
id={mainContainerId}
173+
className={css(styles.pageMain)}
174+
tabIndex={mainTabIndex}
175+
aria-label={mainAriaLabel}
176+
>
177+
{breadcrumb && <section className={css(styles.pageMainBreadcrumb)}>{breadcrumb}</section>}
178+
{children}
179+
</main>
180+
);
181+
182+
const panelContent = <DrawerPanelContent>{notificationDrawer}</DrawerPanelContent>;
183+
157184
return (
158185
<PageContextProvider value={context}>
159186
<div {...rest} className={css(styles.page, className)}>
160187
{skipToContent}
161188
{header}
162189
{sidebar}
163-
<main
164-
role={role}
165-
id={mainContainerId}
166-
className={css(styles.pageMain)}
167-
tabIndex={mainTabIndex}
168-
aria-label={mainAriaLabel}
169-
>
170-
{breadcrumb && <section className={css(styles.pageMainBreadcrumb)}>{breadcrumb}</section>}
171-
{children}
172-
</main>
190+
{notificationDrawer && (
191+
<div className={css(styles.pageDrawer)}>
192+
<Drawer isExpanded={isNotificationDrawerExpanded} onExpand={onNotificationDrawerExpand}>
193+
<DrawerContent panelContent={panelContent}>
194+
<DrawerContentBody>{main}</DrawerContentBody>
195+
</DrawerContent>
196+
</Drawer>
197+
</div>
198+
)}
199+
{!notificationDrawer && main}
173200
</div>
174201
</PageContextProvider>
175202
);

packages/react-core/src/components/Page/__tests__/__snapshots__/Page.test.tsx.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ exports[`Check dark page against snapshot 1`] = `
1414
}
1515
id="PageId"
1616
isManagedSidebar={false}
17+
isNotificationDrawerExpanded={false}
1718
mainTabIndex={-1}
19+
onNotificationDrawerExpand={[Function]}
1820
onPageResize={[Function]}
1921
sidebar={
2022
<PageSidebar
@@ -124,7 +126,9 @@ exports[`Check page horizontal layout example against snapshot 1`] = `
124126
}
125127
id="PageId"
126128
isManagedSidebar={false}
129+
isNotificationDrawerExpanded={false}
127130
mainTabIndex={-1}
131+
onNotificationDrawerExpand={[Function]}
128132
onPageResize={[Function]}
129133
sidebar={
130134
<PageSidebar
@@ -234,7 +238,9 @@ exports[`Check page to verify breadcrumb is created 1`] = `
234238
}
235239
id="PageId"
236240
isManagedSidebar={false}
241+
isNotificationDrawerExpanded={false}
237242
mainTabIndex={-1}
243+
onNotificationDrawerExpand={[Function]}
238244
onPageResize={[Function]}
239245
sidebar={
240246
<PageSidebar
@@ -536,8 +542,10 @@ exports[`Check page to verify skip to content points to main content region 1`]
536542
}
537543
id="PageId"
538544
isManagedSidebar={false}
545+
isNotificationDrawerExpanded={false}
539546
mainContainerId="main-content-page-layout-test-nav"
540547
mainTabIndex={-1}
548+
onNotificationDrawerExpand={[Function]}
541549
onPageResize={[Function]}
542550
sidebar={
543551
<PageSidebar
@@ -834,7 +842,9 @@ exports[`Check page vertical layout example against snapshot 1`] = `
834842
}
835843
id="PageId"
836844
isManagedSidebar={false}
845+
isNotificationDrawerExpanded={false}
837846
mainTabIndex={-1}
847+
onNotificationDrawerExpand={[Function]}
838848
onPageResize={[Function]}
839849
sidebar={
840850
<PageSidebar

0 commit comments

Comments
 (0)