Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/components/Notifications/Inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { Liquid } from 'liquidjs';
import { InAppNotification } from '@notificationapi/core/dist/interfaces';
import { Filter } from './interface';
import { NotificationAPIContext } from '../Provider/context';
import { List, ListItem, Pagination } from '@mui/material';
import { List, ListItem, Pagination, useTheme } from '@mui/material';
import { DefaultEmptyComponent } from './DefaultEmpty';
import VirtualList from 'rc-virtual-list';
import { getThemeColors } from '../../utils/theme';

export type InboxProps = {
pagination: unknown;
Expand All @@ -30,6 +31,9 @@ export const Inbox: React.FC<InboxProps> = (props) => {
const [page, setPage] = useState(1);

const context = useContext(NotificationAPIContext);
const theme = useTheme();
const themeColors = getThemeColors(theme);

if (!context) {
return null;
}
Expand Down Expand Up @@ -95,6 +99,10 @@ export const Inbox: React.FC<InboxProps> = (props) => {
<div>
{props.pagination === 'INFINITE_SCROLL' ? (
<List
sx={{
backgroundColor: themeColors.paper,
color: themeColors.text
}}
subheader={
<InboxHeader
title={props.header?.title}
Expand Down Expand Up @@ -138,6 +146,10 @@ export const Inbox: React.FC<InboxProps> = (props) => {
</List>
) : (
<List
sx={{
backgroundColor: themeColors.paper,
color: themeColors.text
}}
subheader={
<InboxHeader
title={props.header?.title}
Expand Down
31 changes: 26 additions & 5 deletions lib/components/Notifications/Notification.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ReactElement, ReactNode } from 'react';
import { Liquid } from 'liquidjs';
import { InAppNotification } from '@notificationapi/core/dist/interfaces';
import { Avatar, Badge, IconButton, Typography } from '@mui/material';
import { Avatar, Badge, IconButton, Typography, useTheme } from '@mui/material';
import { Check } from '@mui/icons-material';
import styled from '@emotion/styled';
import TimeAgo from 'javascript-time-ago';
import en from 'javascript-time-ago/locale/en';
import ReactTimeAgo from 'react-time-ago';
import { getThemeColors } from '../../utils/theme';

TimeAgo.addDefaultLocale(en);
TimeAgo.addLocale(en);
Expand All @@ -15,11 +16,12 @@ const NotificationDiv = styled.div<{
$redirect: boolean;
$seen: boolean;
$archived: boolean;
$hoverBackground: string;
}>`
cursor: ${(props) => (props.$redirect ? 'pointer' : 'default')};

&:hover {
background: #eee !important;
background: ${(props) => props.$hoverBackground} !important;
border-radius: 8px !important;
}

Expand All @@ -43,6 +45,9 @@ export type NotificationProps = {
};

export const Notification = (props: NotificationProps) => {
const theme = useTheme();
const themeColors = getThemeColors(theme);

if (props.renderer) {
return props.renderer(props.notifications) as ReactElement;
}
Expand Down Expand Up @@ -89,11 +94,18 @@ export const Notification = (props: NotificationProps) => {
const date = props.notifications[groupSize - 1].date;
const ids = props.notifications.map((n) => n.id);

// Calculate hover background (slightly lighter/darker than paper)
const hoverBackground =
theme.palette.mode === 'dark'
? 'rgba(255, 255, 255, 0.08)'
: 'rgba(0, 0, 0, 0.04)';

return (
<NotificationDiv
$redirect={redirectURL ? true : false}
$seen={seen || (opened ? true : false)}
$archived={archived ? true : false}
$hoverBackground={hoverBackground}
onClick={() => {
props.markAsClicked(ids);
if (redirectURL) {
Expand All @@ -106,7 +118,8 @@ export const Notification = (props: NotificationProps) => {
}}
style={{
padding: '16px 6px 16px 0',
background: '#fff',
background: themeColors.paper,
color: themeColors.text,
position: 'relative',
display: 'flex',
alignItems: 'center',
Expand Down Expand Up @@ -135,14 +148,22 @@ export const Notification = (props: NotificationProps) => {
variant="body2"
fontWeight={archived ? 300 : 400}
style={{
whiteSpace: 'pre-line'
whiteSpace: 'pre-line',
color: themeColors.text
}}
>
<span dangerouslySetInnerHTML={{ __html: title as string }}></span>
</Typography>
</div>
<div>
<Typography variant="body2" fontWeight={300} style={{ fontSize: 12 }}>
<Typography
variant="body2"
fontWeight={300}
style={{
fontSize: 12,
color: themeColors.textSecondary
}}
>
<ReactTimeAgo date={new Date(date).getTime()} locale="en-US" />
</Typography>
</div>
Expand Down
13 changes: 10 additions & 3 deletions lib/components/Notifications/NotificationFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { NotificationPreferencesPopup } from '../Preferences';
import { InAppNotification } from '@notificationapi/core/dist/interfaces';
import { Filter, Pagination } from './interface';
import Divider from '@mui/material/Divider';
import { useTheme } from '@mui/material/styles';
import WebPushOptInMessage from '../WebPush/WebPushOptInMessage';
import Language from '@mui/icons-material/Language';
import { getThemeColors } from '../../utils/theme';

export type NotificationFeedProps = {
pagination?: keyof typeof Pagination;
Expand All @@ -28,6 +30,8 @@ export type NotificationFeedProps = {
export const NotificationFeed: React.FC<NotificationFeedProps> = (props) => {
const [openPreferences, setOpenPreferences] = useState(false);
const context = useContext(NotificationAPIContext);
const theme = useTheme();
const themeColors = getThemeColors(theme);

// every 5 seconds
useEffect(() => {
Expand Down Expand Up @@ -74,8 +78,9 @@ export const NotificationFeed: React.FC<NotificationFeedProps> = (props) => {
padding: '0 12px',
boxSizing: 'border-box',
borderRadius: 8,
background: '#fff',
border: '1px solid #dcdcdc',
background: themeColors.paper,
border: `1px solid ${themeColors.border}`,
color: themeColors.text,
...props.style
}}
>
Expand All @@ -93,7 +98,9 @@ export const NotificationFeed: React.FC<NotificationFeedProps> = (props) => {
{context.webPushOptInMessage &&
localStorage.getItem('hideWebPushOptInMessage') !== 'true' && (
<div>
<Divider style={{ margin: '10px 0' }} />
<Divider
style={{ margin: '10px 0', borderColor: themeColors.divider }}
/>
<WebPushOptInMessage
hideAfterInteraction={true}
icon={<Language type="text" style={{ marginLeft: '9px' }} />}
Expand Down
77 changes: 48 additions & 29 deletions lib/components/Notifications/NotificationLauncher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { NotificationAPIContext } from '../Provider/context';
import { NotificationPreferencesPopup } from '../Preferences';
import { Position } from './interface';
import { LanguageOutlined, NotificationsOutlined } from '@mui/icons-material';
import { Divider, IconButton, Popover } from '@mui/material';
import { Divider, IconButton, Popover, useTheme } from '@mui/material';
import WebPushOptInMessage from '../WebPush/WebPushOptInMessage';
import { getThemeColors } from '../../utils/theme';

type NotificationLaucherProps = NotificationPopupProps & {
position?: keyof typeof Position;
Expand All @@ -23,6 +24,8 @@ export const NotificationLauncher: React.FC<NotificationLaucherProps> = (
const [open, setOpen] = useState(false);
const context = useContext(NotificationAPIContext);
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const theme = useTheme();
const themeColors = getThemeColors(theme);

if (!context) {
return null;
Expand All @@ -33,7 +36,7 @@ export const NotificationLauncher: React.FC<NotificationLaucherProps> = (
<NotificationsOutlined
style={{
fontSize: props.buttonIconSize || 20,
color: props.iconColor || '#000000'
color: props.iconColor || themeColors.icon
}}
/>
),
Expand All @@ -45,7 +48,7 @@ export const NotificationLauncher: React.FC<NotificationLaucherProps> = (
popupWidth: props.popupWidth || 400,
popupHeight: props.popupHeight || 600,
buttonIconSize: props.buttonIconSize || 20,
iconColor: props.iconColor || '#000000',
iconColor: props.iconColor || themeColors.icon,
pagination: props.pagination || 'INFINITE_SCROLL',
pageSize: props.pageSize || 10,
pagePosition: props.pagePosition || 'top',
Expand Down Expand Up @@ -119,36 +122,52 @@ export const NotificationLauncher: React.FC<NotificationLaucherProps> = (
slotProps={{
paper: {
style: {
width: config.popupWidth,
padding: '0 16px',
borderRadius: 8
borderRadius: 8,
backgroundColor: themeColors.paper,
color: themeColors.text
}
}
}}
>
<Inbox
maxHeight={500}
pagination={config.pagination}
filter={config.filter}
pageSize={config.pageSize}
pagePosition={config.pagePosition}
notificationRenderer={config.renderers.notification}
header={config.header}
newTab={config.newTab}
/>
{context.webPushOptInMessage &&
localStorage.getItem('hideWebPushOptInMessage') !== 'true' && (
<div>
<Divider style={{ margin: '10px 0' }} />
<WebPushOptInMessage
hideAfterInteraction={true}
icon={
<LanguageOutlined type="text" style={{ marginLeft: '9px' }} />
}
alertContainerStyle={{ maxWidth: '345px' }}
/>
</div>
)}
<div
style={{
width: config.popupWidth,
padding: '0 16px',
zIndex: config.popupZIndex,
height: config.popupHeight,
backgroundColor: themeColors.paper,
color: themeColors.text
}}
>
<Inbox
maxHeight={config.popupHeight - 73}
pagination={config.pagination}
filter={config.filter}
pageSize={config.pageSize}
pagePosition={config.pagePosition}
notificationRenderer={config.renderers.notification}
header={config.header}
newTab={config.newTab}
/>
{context.webPushOptInMessage &&
localStorage.getItem('hideWebPushOptInMessage') !== 'true' && (
<div>
<Divider
style={{ margin: '10px 0', borderColor: themeColors.divider }}
/>
<WebPushOptInMessage
hideAfterInteraction={true}
icon={
<LanguageOutlined
type="text"
style={{ marginLeft: '9px' }}
/>
}
alertContainerStyle={{ maxWidth: '345px' }}
/>
</div>
)}
</div>
</Popover>
<NotificationPreferencesPopup
open={openPreferences}
Expand Down
21 changes: 15 additions & 6 deletions lib/components/Notifications/NotificationPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { InAppNotification } from '@notificationapi/core/dist/interfaces';
import { NotificationPreferencesPopup } from '../Preferences';
import { InboxHeaderProps } from './InboxHeader';
import { Filter, Pagination } from './interface';
import { Divider, IconButton, Popover } from '@mui/material';
import { Divider, IconButton, Popover, useTheme } from '@mui/material';
import NotificationsOutlined from '@mui/icons-material/NotificationsOutlined';
import WebPushOptInMessage from '../WebPush/WebPushOptInMessage';
import { getThemeColors } from '../../utils/theme';

export type NotificationPopupProps = {
buttonIcon?: React.ReactNode;
Expand Down Expand Up @@ -42,6 +43,8 @@ export const NotificationPopup: React.FC<NotificationPopupProps> = (props) => {
const [openPreferences, setOpenPreferences] = useState(false);
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const context = useContext(NotificationAPIContext);
const theme = useTheme();
const themeColors = getThemeColors(theme);

if (!context) {
return null;
Expand All @@ -52,7 +55,7 @@ export const NotificationPopup: React.FC<NotificationPopupProps> = (props) => {
<NotificationsOutlined
style={{
fontSize: props.buttonIconSize || 20,
color: props.iconColor || '#000000'
color: props.iconColor || themeColors.icon
}}
/>
),
Expand All @@ -64,7 +67,7 @@ export const NotificationPopup: React.FC<NotificationPopupProps> = (props) => {
popupWidth: props.popupWidth || 400,
popupHeight: props.popupHeight || 600,
buttonIconSize: props.buttonIconSize || 20,
iconColor: props.iconColor || '#000000',
iconColor: props.iconColor || themeColors.icon,
pagination: props.pagination || 'INFINITE_SCROLL',
pageSize: props.pageSize || 10,
pagePosition: props.pagePosition || 'bottom',
Expand Down Expand Up @@ -120,7 +123,9 @@ export const NotificationPopup: React.FC<NotificationPopupProps> = (props) => {
slotProps={{
paper: {
style: {
borderRadius: 8
borderRadius: 8,
backgroundColor: themeColors.paper,
color: themeColors.text
}
}
}}
Expand All @@ -132,7 +137,9 @@ export const NotificationPopup: React.FC<NotificationPopupProps> = (props) => {
width: config.popupWidth,
padding: '0 16px',
zIndex: props.popupZIndex,
height: config.popupHeight
height: config.popupHeight,
backgroundColor: themeColors.paper,
color: themeColors.text
}}
>
<Inbox
Expand All @@ -148,7 +155,9 @@ export const NotificationPopup: React.FC<NotificationPopupProps> = (props) => {
{context.webPushOptInMessage &&
localStorage.getItem('hideWebPushOptInMessage') !== 'true' && (
<div>
<Divider style={{ margin: '10px 0' }} />
<Divider
style={{ margin: '10px 0', borderColor: themeColors.divider }}
/>
<WebPushOptInMessage hideAfterInteraction={true} />
</div>
)}
Expand Down
Loading