-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3899 from jcaianirh/drawer
Notification drawer component for console.
- Loading branch information
Showing
20 changed files
with
686 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"jasmine": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:import/errors", | ||
"plugin:import/warnings", | ||
"plugin:react/recommended", | ||
"plugin:console/json", | ||
"plugin:console/prettier" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"comment": true, | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"extraFileExtensions": [".json"], | ||
"ecmaVersion": 2017, | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["react", "react-hooks", "@typescript-eslint"], | ||
"rules": { | ||
"camelcase": 2, | ||
"consistent-return": 0, | ||
"consistent-this": [1, "that"], | ||
"curly": [2, "all"], | ||
"default-case": [2], | ||
"dot-notation": [2], | ||
"no-multiple-empty-lines": [2, { "max": 2, "maxEOF": 0 }], | ||
"eqeqeq": [2, "allow-null"], | ||
"guard-for-in": 2, | ||
"import/no-unresolved": ["error"], | ||
"import/no-duplicates": ["error"], | ||
"max-nested-callbacks": [1, 4], | ||
"no-alert": 2, | ||
"no-caller": 2, | ||
"no-console": 2, | ||
"no-constant-condition": 2, | ||
"no-debugger": 2, | ||
"no-else-return": ["error"], | ||
"no-global-strict": 0, | ||
"no-irregular-whitespace": ["error"], | ||
"no-shadow": ["error"], | ||
"no-underscore-dangle": 0, | ||
"@typescript-eslint/no-unused-vars": [ | ||
"error", | ||
{ "varsIgnorePattern": "React", "args": "after-used" } | ||
], | ||
"@typescript-eslint/no-use-before-define": 2, | ||
"no-var": 2, | ||
"object-shorthand": ["error", "properties"], | ||
"prefer-const": ["error", { "destructuring": "all" }], | ||
"prefer-template": 2, | ||
"radix": 2, | ||
"react/jsx-fragments": "error", | ||
"react/jsx-no-duplicate-props": 2, | ||
"react/jsx-uses-react": "error", | ||
"react/jsx-uses-vars": "error", | ||
"react/no-string-refs": 1, | ||
"react/no-unknown-property": "error", | ||
"react/prop-types": 0, | ||
"react/self-closing-comp": ["error", { "component": true, "html": false }], | ||
"react-hooks/rules-of-hooks": "error", | ||
"react-hooks/exhaustive-deps": "warn", | ||
"react/display-name": 0, | ||
"react/no-unescaped-entities": 0 | ||
}, | ||
"settings": { | ||
"import/extensions": [".js", ".jsx"], | ||
"import/resolver": { "node": { "extensions": [".js", ".jsx", ".ts", ".tsx"] } }, | ||
"react": { | ||
"version": "detect" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "@console/patternfly", | ||
"version": "0.0.0-fixed", | ||
"description": "Components ready for possible export to patternfly react-core repo.", | ||
"private": true, | ||
"main": "src/index.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './notification-drawer'; |
4 changes: 4 additions & 0 deletions
4
frontend/packages/patternfly/src/components/notification-drawer/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { default as NotificationDrawer } from './notification-drawer'; | ||
export { default as NotificationDrawerHeading } from './notification-drawer-heading'; | ||
export { default as NotificationEntry, NotificationTypes } from './notification-entry'; | ||
export { default as NotificationCategory } from './notification-category'; |
50 changes: 50 additions & 0 deletions
50
frontend/packages/patternfly/src/components/notification-drawer/notification-category.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as React from 'react'; | ||
import * as classNames from 'classnames'; | ||
import { Badge } from '@patternfly/react-core'; | ||
|
||
const NotificationCategory: React.FC<NotificationCategoryProps> = ({ | ||
label, | ||
count, | ||
isExpanded, | ||
children, | ||
onExpandContents, | ||
}) => ( | ||
<section | ||
className={classNames('query-pf-c-notification-drawer__group', { | ||
'pf-m-expanded': isExpanded, | ||
})} | ||
> | ||
<button | ||
className="pf-c-notification-drawer__group-toggle" | ||
aria-expanded={isExpanded} | ||
onClick={() => onExpandContents(!isExpanded)} | ||
> | ||
<div className="pf-c-notification-drawer__group-toggle-title">{label}</div> | ||
<div className="pf-c-notification-drawer__group-toggle-count"> | ||
<Badge isRead>{count}</Badge> | ||
</div> | ||
<span className="pf-c-notification-drawer__group-toggle-icon"> | ||
<i | ||
className={classNames({ | ||
'fas fa-angle-down': isExpanded, | ||
'fas fa-angle-right': !isExpanded, | ||
})} | ||
aria-hidden={!isExpanded} | ||
/> | ||
</span> | ||
</button> | ||
<ul className="pf-c-notification-drawer__list" hidden={!isExpanded}> | ||
{children} | ||
</ul> | ||
</section> | ||
); | ||
|
||
type NotificationCategoryProps = { | ||
children: React.ReactNode; | ||
count: number; | ||
isExpanded: boolean; | ||
label: string; | ||
onExpandContents: React.Dispatch<React.SetStateAction<boolean>>; | ||
}; | ||
|
||
export default NotificationCategory; |
25 changes: 25 additions & 0 deletions
25
...nd/packages/patternfly/src/components/notification-drawer/notification-drawer-heading.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react'; | ||
|
||
const NotificationDrawerHeading: React.FC<NotificationDrawerHeadingProps> = ({ | ||
count, | ||
children, | ||
}) => ( | ||
<div className="pf-c-notification-drawer"> | ||
<div className="pf-c-notification-drawer__header"> | ||
<h1 className="pf-c-notification-drawer__header-title">Notifications</h1> | ||
{count && ( | ||
<span className="pf-c-notification-drawer__header-status">{`${count} unread`}</span> | ||
)} | ||
</div> | ||
<div className="pf-c-notification-drawer__body"> | ||
<div className="pf-c-notification-drawer__group-list">{children}</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
type NotificationDrawerHeadingProps = { | ||
children: React.ReactNode; | ||
count?: number; | ||
}; | ||
|
||
export default NotificationDrawerHeading; |
36 changes: 36 additions & 0 deletions
36
frontend/packages/patternfly/src/components/notification-drawer/notification-drawer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as React from 'react'; | ||
import { | ||
Drawer, | ||
DrawerContent, | ||
DrawerPanelContent, | ||
} from '@patternfly/react-core/dist/js/experimental/components/Drawer'; | ||
|
||
import NotificationDrawerHeading from './notification-drawer-heading'; | ||
|
||
const NotificationDrawer: React.FC<NotificationDrawerProps> = ({ | ||
isExpanded, | ||
isInline, | ||
children, | ||
notificationEntries, | ||
}) => { | ||
return ( | ||
<Drawer isExpanded={isExpanded} isInline={isInline}> | ||
<DrawerContent>{children}</DrawerContent> | ||
<DrawerPanelContent noPadding> | ||
<NotificationDrawerHeading>{notificationEntries}</NotificationDrawerHeading> | ||
</DrawerPanelContent> | ||
</Drawer> | ||
); | ||
}; | ||
|
||
NotificationDrawer.displayName = 'NotificationDrawer'; | ||
|
||
export type NotificationDrawerProps = { | ||
isInline: boolean; | ||
isExpanded: boolean; | ||
notificationEntries?: JSX.Element[]; | ||
count?: number; | ||
children: React.ReactNode; | ||
}; | ||
|
||
export default NotificationDrawer; |
100 changes: 100 additions & 0 deletions
100
frontend/packages/patternfly/src/components/notification-drawer/notification-entry.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import * as classNames from 'classnames'; | ||
import * as _ from 'lodash'; | ||
import * as React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { | ||
YellowExclamationTriangleIcon, | ||
GreenCheckCircleIcon, | ||
BlueInfoCircleIcon, | ||
RedExclamationCircleIcon, | ||
} from '@console/shared'; | ||
import { ArrowCircleUpIcon } from '@patternfly/react-icons'; | ||
import { global_info_color_100 as blueInfoColor } from '@patternfly/react-tokens'; | ||
import { history, Timestamp } from '@console/internal/components/utils'; | ||
|
||
export enum NotificationTypes { | ||
info = 'info', | ||
warning = 'warning', | ||
critical = 'danger', | ||
success = 'success', | ||
update = 'update', | ||
} | ||
|
||
const NotificationIcon: React.FC<NotificationIconTypes> = ({ type }) => { | ||
switch (type) { | ||
case NotificationTypes.update: | ||
return <ArrowCircleUpIcon color={blueInfoColor.value} />; | ||
case NotificationTypes.success: | ||
return <GreenCheckCircleIcon />; | ||
case NotificationTypes.critical: | ||
return <RedExclamationCircleIcon />; | ||
case NotificationTypes.warning: | ||
return <YellowExclamationTriangleIcon />; | ||
case NotificationTypes.info: | ||
default: | ||
return <BlueInfoCircleIcon />; | ||
} | ||
}; | ||
|
||
const NotificationEntry: React.FC<NotificationEntryProps> = ({ | ||
title, | ||
description, | ||
isRead = false, | ||
timestamp, | ||
targetURL, | ||
toggleNotificationDrawer, | ||
type, | ||
}) => { | ||
const notificationAction = type === NotificationTypes.update && targetURL && ( | ||
<div className="pf-c-notification-drawer__header-action"> | ||
<Link to="">Install Update</Link> | ||
</div> | ||
); | ||
return ( | ||
<li | ||
className={classNames(`pf-c-notification-drawer__list-item pf-m-hoverable pf-m-${type}`, { | ||
'pf-m-read': isRead, | ||
})} | ||
tabIndex={0} | ||
onClick={ | ||
targetURL | ||
? () => { | ||
history.push(targetURL); | ||
toggleNotificationDrawer(); | ||
} | ||
: null | ||
} | ||
> | ||
<div className="pf-c-notification-drawer__list-item-header"> | ||
<span className="pf-c-notification-drawer__list-item-header-icon"> | ||
<NotificationIcon type={type} /> | ||
</span> | ||
<h4 className="pf-c-notification-drawer__list-item-header-title"> | ||
<span className="pf-screen-reader">{`${_.capitalize(type)} notification:`}</span> | ||
{title} | ||
</h4> | ||
{notificationAction} | ||
</div> | ||
<div className="pf-c-notification-drawer__list-item-description">{description}</div> | ||
<div className="pf-c-notification-drawer__list-item-timestamp"> | ||
{timestamp && <Timestamp simple timestamp={timestamp} />} | ||
</div> | ||
</li> | ||
); | ||
}; | ||
|
||
export type NotificationEntryProps = { | ||
title: string; | ||
description: string; | ||
isRead?: boolean; | ||
targetURL?: string; | ||
timestamp?: string; | ||
toggleNotificationDrawer?: () => any; | ||
type: NotificationTypes; | ||
}; | ||
|
||
type NotificationIconTypes = { | ||
type: NotificationTypes; | ||
}; | ||
|
||
export default NotificationEntry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.