Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Notification Badge): Adds the notification badge component (#2342)
* Added notification badge * feat(react-core): Added Notification Badge Component Added the notificatoin badge component. Currently adding the typescript integreation tests. Will update the PR when they are done. "fix #2021" * Added integration tests.
- Loading branch information
Showing
10 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...s/patternfly-4/react-core/src/components/NotificationBadge/NotificationBadge.md
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,40 @@ | ||
--- | ||
title: 'NotificationBadge' | ||
cssPrefix: 'pf-c-notification-badge' | ||
typescript: true | ||
propComponents: ['NotificationBadge'] | ||
--- | ||
|
||
import { NotificationBadge } from '@patternfly/react-core'; | ||
import { BellIcon } from '@patternfly/react-icons'; | ||
|
||
## Simple notification badge | ||
|
||
```js | ||
import React from 'react'; | ||
import { NotificationBadge } from '@patternfly/react-core'; | ||
import { BellIcon } from '@patternfly/react-icons'; | ||
|
||
class SimpleNotificationBadge extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
isRead: false | ||
}; | ||
this.onClick = () => { | ||
this.setState({ | ||
isRead: true | ||
}); | ||
}; | ||
} | ||
|
||
render() { | ||
const { isRead } = this.state; | ||
return ( | ||
<NotificationBadge isRead={isRead} onClick={this.onClick} aria-label="Notifications"> | ||
<BellIcon /> | ||
</NotificationBadge> | ||
); | ||
} | ||
} | ||
``` |
10 changes: 10 additions & 0 deletions
10
packages/patternfly-4/react-core/src/components/NotificationBadge/NotificationBadge.test.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,10 @@ | ||
import { NotificationBadge } from './NotificationBadge'; | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
Object.values([true, false]).forEach(isRead => { | ||
test(`${isRead} NotificationBadge`, () => { | ||
const view = shallow(<NotificationBadge isRead={isRead}>{isRead ? 'read' : 'unread'} Badge</NotificationBadge>); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/patternfly-4/react-core/src/components/NotificationBadge/NotificationBadge.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,28 @@ | ||
import * as React from 'react'; | ||
import { Button, ButtonVariant, ButtonProps } from '../Button'; | ||
import { css } from '@patternfly/react-styles'; | ||
import styles from '@patternfly/react-styles/css/components/NotificationBadge/notification-badge'; | ||
|
||
export interface NotificationBadgeProps extends ButtonProps { | ||
/** Adds styling to the notification badge to indicate it has been read */ | ||
isRead?: boolean; | ||
/** content rendered inside the Notification Badge */ | ||
children?: React.ReactNode; | ||
/** additional classes added to the Notification Badge */ | ||
className?: string; | ||
/** Adds accessible text to the Notification Badge. */ | ||
'aria-label'?: string; | ||
} | ||
|
||
export const NotificationBadge: React.FunctionComponent<NotificationBadgeProps> = ({ | ||
isRead = false, | ||
className, | ||
children, | ||
...props | ||
}: NotificationBadgeProps) => ( | ||
<Button variant={ButtonVariant.plain} className={className} {...props}> | ||
<span className={css(styles.notificationBadge, isRead ? styles.modifiers.read : styles.modifiers.unread)}> | ||
{children} | ||
</span> | ||
</Button> | ||
); |
27 changes: 27 additions & 0 deletions
27
...react-core/src/components/NotificationBadge/__snapshots__/NotificationBadge.test.tsx.snap
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,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`false NotificationBadge 1`] = ` | ||
<Component | ||
variant="plain" | ||
> | ||
<span | ||
className="pf-c-notification-badge pf-m-unread" | ||
> | ||
unread | ||
Badge | ||
</span> | ||
</Component> | ||
`; | ||
|
||
exports[`true NotificationBadge 1`] = ` | ||
<Component | ||
variant="plain" | ||
> | ||
<span | ||
className="pf-c-notification-badge pf-m-read" | ||
> | ||
read | ||
Badge | ||
</span> | ||
</Component> | ||
`; |
1 change: 1 addition & 0 deletions
1
packages/patternfly-4/react-core/src/components/NotificationBadge/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 './NotificationBadge'; |
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
16 changes: 16 additions & 0 deletions
16
packages/patternfly-4/react-integration/cypress/integration/notificationbadge.spec.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,16 @@ | ||
describe('Notification Badge Demo Test', () => { | ||
it('Navigate to notificatoin badge demo section', () => { | ||
cy.visit('http://localhost:3000/'); | ||
cy.get('#notification-badge-demo-nav-item-link').click(); | ||
cy.url().should('eq', 'http://localhost:3000/notification-badge-demo-nav-link'); | ||
}); | ||
|
||
it('Verify notification badge is unread', () => { | ||
cy.get('.pf-c-notification-badge').should('have.class', 'pf-m-unread'); | ||
}); | ||
|
||
it('Verify notification badge is read after click', () => { | ||
cy.get('#notification-demo-badge').click(); | ||
cy.get('.pf-c-notification-badge').should('have.class', 'pf-m-read'); | ||
}); | ||
}) |
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
30 changes: 30 additions & 0 deletions
30
...egration/demo-app-ts/src/components/demos/NotificationBadgeDemo/NotificationBadgeDemo.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,30 @@ | ||
import React from 'react'; | ||
import { NotificationBadge, NotificationBadgeProps } from '@patternfly/react-core'; | ||
import { BellIcon } from '@patternfly/react-icons'; | ||
|
||
interface NotificationBadgeDemoState { | ||
isRead: boolean; | ||
} | ||
|
||
export class NotificationBadgeDemo extends React.Component <NotificationBadgeProps, NotificationBadgeDemoState>{ | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
isRead: false | ||
}; | ||
} | ||
onClick = () => { | ||
this.setState({ | ||
isRead: true | ||
}); | ||
}; | ||
|
||
render() { | ||
const { isRead } = this.state; | ||
return ( | ||
<NotificationBadge id="notification-demo-badge" isRead={isRead} onClick={this.onClick} aria-label="Notifications"> | ||
<BellIcon /> | ||
</NotificationBadge> | ||
); | ||
} | ||
} |
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