Created
November 21, 2019 18:42
-
-
Save patrickmaciel/7e6ca681d90c977234f2c606fee6e041 to your computer and use it in GitHub Desktop.
Notification badge with submenu/notification list
This file contains hidden or 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
return ( | |
<Container> | |
<Badge onClick={handleToggleVisible} hasUnread={hasUnread}> | |
<MdNotifications color="#7159c1" size={20} /> | |
</Badge> | |
<NotificationList visible={visible}> | |
<Scroll> | |
{notifications.map(notification => ( | |
<Notification key={notification._id} unread={!notification.read}> | |
<p>{notification.content}</p> | |
<time>{notification.timeDistance}</time> | |
{!notification.read && ( | |
<button | |
type="button" | |
onClick={() => handleMarkAsRead(notification._id)} | |
> | |
Marcar como lida | |
</button> | |
)} | |
</Notification> | |
))} | |
</Scroll> | |
</NotificationList> | |
</Container> | |
); |
This file contains hidden or 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
import styled, { css } from 'styled-components'; | |
import { lighten } from 'polished'; | |
import PerfectScrollbar from 'react-perfect-scrollbar'; | |
export const Container = styled.div` | |
position: relative; | |
`; | |
export const Badge = styled.button` | |
background: none; | |
border: 0; | |
position: relative; | |
${props => | |
props.hasUnread && | |
css` | |
&::after { | |
position: absolute; | |
right: 0; | |
top: 0; | |
width: 8px; | |
height: 8px; | |
background: #ff892e; | |
content: ''; | |
border-radius: 50%; | |
} | |
`} | |
`; | |
export const NotificationList = styled.div` | |
position: absolute; | |
width: 260px; | |
left: calc(50% - 130px); | |
top: calc(100% + 30px); | |
background: rgba(0, 0, 0, 0.6); | |
border-radius: 4px; | |
padding: 15px 5px; | |
display: ${props => (props.visible ? 'block' : 'none')}; | |
&::before { | |
content: ''; | |
position: absolute; | |
left: calc(50% - 20px); | |
top: -20px; | |
width: 0%; | |
height: 0%; | |
border-left: 20px solid transparent; | |
border-right: 20px solid transparent; | |
border-bottom: 20px solid rgba(0, 0, 0, 0.6); | |
} | |
`; | |
export const Scroll = styled(PerfectScrollbar)` | |
max-height: 260px; | |
padding: 5px 15px; | |
`; | |
export const Notification = styled.div` | |
color: #fff; | |
& + div { | |
margin-top: 15px; | |
padding-top: 15px; | |
border-top: 1px solid rgba(255, 255, 255, 0.1); | |
} | |
p { | |
font-size: 13px; | |
line-height: 18px; | |
} | |
time { | |
font-size: 12px; | |
opacity: 0.6; | |
display: block; | |
margin-bottom: 5px; | |
} | |
button { | |
font-size: 12px; | |
border: 0; | |
background: none; | |
color: ${lighten(0.2, '#7159c1')}; | |
} | |
${props => | |
props.unread && | |
css` | |
&::after { | |
content: ''; | |
display: inline-block; | |
width: 8px; | |
height: 8px; | |
background: #ff892e; | |
border-radius: 50%; | |
margin-left: 10px; | |
} | |
`} | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment