-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DS-Dapp Notification Component (#1801)
* add in-app semantics and block files * update notification component * add localstorage identifier * update library * add duration option * resolve comments * update comment fixes * fix comments * testing notification * update notification component --------- Co-authored-by: rohitmalhotra1420 <[email protected]>
- Loading branch information
1 parent
a0a3ddd
commit ea96da6
Showing
11 changed files
with
1,154 additions
and
0 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,111 @@ | ||
import { FC } from 'react'; | ||
import styled from 'styled-components'; | ||
import { Cross } from '../icons'; | ||
import { NotificationProps } from './Notification.types'; | ||
import { toast } from 'sonner'; | ||
import { getTextVariantStyles } from 'blocks/Blocks.utils'; | ||
|
||
const NotificationContainer = styled.div` | ||
position: relative; | ||
background-color: var(--components-in-app-notification-background-default); | ||
border-radius: var(--radius-xxs); | ||
box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.05); | ||
display: flex; | ||
flex-direction: row; | ||
align-items: stretch; | ||
max-height: 111px; | ||
min-width: 397px; | ||
max-width: 100%; | ||
cursor: pointer; | ||
box-sizing: border-box; | ||
border: var(--border-sm) solid var(--components-in-app-notification-stroke-bg); | ||
`; | ||
|
||
const TextContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
justify-content: flex-start; | ||
padding: var(--spacing-sm); | ||
flex: 1; | ||
box-sizing: border-box; | ||
`; | ||
|
||
const NotificationTitle = styled.span` | ||
${() => getTextVariantStyles('h5-semibold', 'components-in-app-notification-text-default')} | ||
`; | ||
|
||
const NotificationDescription = styled.span` | ||
${() => getTextVariantStyles('bes-regular', 'components-in-app-notification-text-secondary')} | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
display: -webkit-box; | ||
-webkit-line-clamp: 3; | ||
line-clamp: 3; | ||
-webkit-box-orient: vertical; | ||
`; | ||
|
||
const IconContainer = styled.div` | ||
padding: var(--spacing-sm) var(--spacing-xs); | ||
border-radius: var(--radius-xxs) var(--radius-none) var(--radius-none) var(--radius-xxs); | ||
background: radial-gradient(79.55% 79.55% at 50% 50%, #344efd 0%, #171717 100%); | ||
`; | ||
|
||
const CloseButton = styled.div` | ||
background-color: var(--surface-transparent); | ||
cursor: pointer; | ||
color: var(--components-in-app-notification-icon-default); | ||
padding: var(--spacing-none); | ||
position: absolute; | ||
right: var(--spacing-xxs); | ||
top: var(--spacing-xxs); | ||
`; | ||
|
||
const Notification: FC<NotificationProps> = ({ onClose, title, description, image, onClick }) => { | ||
const handleNotificationClick = () => onClick?.(); | ||
|
||
const handleNotificationClose = () => { | ||
onClose?.(); | ||
notification.hide(); | ||
}; | ||
|
||
return ( | ||
<NotificationContainer onClick={handleNotificationClick}> | ||
<IconContainer>{image}</IconContainer> | ||
<CloseButton | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
handleNotificationClose(); | ||
}} | ||
> | ||
<Cross size={16} /> | ||
</CloseButton> | ||
<TextContainer> | ||
<NotificationTitle>{title}</NotificationTitle> | ||
<NotificationDescription>{description}</NotificationDescription> | ||
</TextContainer> | ||
</NotificationContainer> | ||
); | ||
}; | ||
|
||
// Store the toastId(s) in an array to manage multiple notifications | ||
const toastIds: Array<string | number> = []; | ||
|
||
// Export the notification object with show and hide methods | ||
const notification = { | ||
show: (config: NotificationProps) => { | ||
const toastId = toast.custom(() => <Notification {...config} />, { | ||
duration: config.duration || Infinity, | ||
position: config.position || 'bottom-right', | ||
}); | ||
toastIds.push(toastId); | ||
}, | ||
hide: () => { | ||
if (toastIds.length > 0) { | ||
const toastId = toastIds.pop(); | ||
toast.dismiss(toastId); | ||
} | ||
}, | ||
}; | ||
|
||
export { notification }; |
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,18 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
export type NotificationProps = { | ||
/* Svg React component to be passed as the image. */ | ||
image: ReactNode; | ||
/* Title of the notification */ | ||
title: string; | ||
/* Description of the notification */ | ||
description: string; | ||
/* Optional onClick event for the notification */ | ||
onClick?: () => void; | ||
/* Optional onClose action for the notification */ | ||
onClose?: () => void; | ||
/* Position of the notification */ | ||
position?: 'bottom-right' | 'bottom-left'; | ||
/* Optional duration of the notification component */ | ||
duration?: number; | ||
}; |
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,2 @@ | ||
export * from './Notification'; | ||
export * from './Notification.types'; |
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,15 @@ | ||
import { iconSemantics } from './semantics.icon'; | ||
import { strokeSemantics } from './semantics.stroke'; | ||
import { surfaceSemantics } from './semantics.surface'; | ||
import { textSemantics } from './semantics.text'; | ||
|
||
export const notificationsSemantics = { | ||
'background-default': { light: surfaceSemantics['primary'].light, dark: surfaceSemantics['primary'].dark }, | ||
'stroke-bg': { light: strokeSemantics['secondary'].light, dark: strokeSemantics['secondary'].dark }, | ||
'text-default': { | ||
light: textSemantics['primary'].light, | ||
dark: textSemantics['primary'].dark, | ||
}, | ||
'text-secondary': { light: textSemantics['tertiary'].light, dark: textSemantics['tertiary'].dark }, | ||
'icon-default': { light: iconSemantics['primary'].light, dark: iconSemantics['primary'].dark }, | ||
}; |
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