-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add notification panel (#4484)
* feat: Add notificiation panel * fix test * small changes * moved new notifications to the top Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
- Loading branch information
Showing
14 changed files
with
408 additions
and
79 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
74 changes: 74 additions & 0 deletions
74
Composer/packages/client/src/components/Notifications/NotificationButton.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,74 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** @jsx jsx */ | ||
import { css, jsx } from '@emotion/core'; | ||
import React, { useState } from 'react'; | ||
import { FontWeights } from '@uifabric/styling'; | ||
import { IButtonStyles, IconButton } from 'office-ui-fabric-react/lib/Button'; | ||
import { NeutralColors, SharedColors } from '@uifabric/fluent-theme'; | ||
import { useRecoilValue } from 'recoil'; | ||
import formatMessage from 'format-message'; | ||
|
||
import { notificationsSelector } from '../../recoilModel/selectors/notificationsSelector'; | ||
import { dispatcherState } from '../../recoilModel'; | ||
|
||
import { NotificationPanel } from './NotificationPanel'; | ||
|
||
const styles = { | ||
container: css` | ||
position: relative; | ||
`, | ||
count: (visible?: boolean) => css` | ||
background-color: ${NeutralColors.white}; | ||
border: 2px solid ${SharedColors.cyanBlue10}; | ||
border-radius: 100%; | ||
color: ${SharedColors.cyanBlue10}; | ||
font-size: 8px; | ||
font-weight: ${FontWeights.bold}; | ||
height: 12px; | ||
right: -4px; | ||
position: absolute; | ||
text-align: center; | ||
visibility: ${visible ? 'visible' : 'hidden'}; | ||
width: 12px; | ||
`, | ||
}; | ||
|
||
type NotificationButtonProps = { | ||
buttonStyles?: IButtonStyles; | ||
}; | ||
|
||
const NotificationButton: React.FC<NotificationButtonProps> = ({ buttonStyles }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const { deleteNotification, markNotificationAsRead } = useRecoilValue(dispatcherState); | ||
const notifications = useRecoilValue(notificationsSelector); | ||
const unreadNotification = notifications.filter(({ read }) => !read); | ||
|
||
const toggleIsOpen = () => { | ||
if (!isOpen) { | ||
notifications.map(({ id }) => markNotificationAsRead(id)); | ||
} | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
return ( | ||
<div aria-label={formatMessage('Open notification panel')}> | ||
<IconButton iconProps={{ iconName: 'Ringer' }} styles={buttonStyles} onClick={toggleIsOpen}> | ||
<div css={styles.container}> | ||
<div aria-hidden css={styles.count(!isOpen && !!unreadNotification.length)}> | ||
{unreadNotification.length} | ||
</div> | ||
</div> | ||
</IconButton> | ||
<NotificationPanel | ||
isOpen={isOpen} | ||
notifications={notifications} | ||
onDeleteNotification={deleteNotification} | ||
onDismiss={toggleIsOpen} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export { NotificationButton }; |
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
Oops, something went wrong.