generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Notifications): Added archived state, NotificationsPopupWrapper
component and enhanced the stories for notifications
#83
Merged
Ruminat
merged 14 commits into
main
from
feat-added-archived-state-and-enhanced-the-stories-for-notifications
Aug 9, 2023
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f9cd5d5
feat: added archived state to the Notification component + enhanced t…
Ruminat 38c68d5
fix: changed the Notifications' Error state illustrations to the righ…
Ruminat 4b01829
fix: tiny style fix + typo fix
Ruminat 663c7f7
Merge branch 'main' of https://github.com/gravity-ui/components into …
Ruminat 01240f7
chore: updated version to 2.0.2
Ruminat a39a2c9
feat: added NotificationsPopupWrapper component + cleaned up the stor…
Ruminat 6ac3261
fix: typecheck
Ruminat 9f3e6ac
fix: changed `return <></>` to `return null`
Ruminat 9fd73cf
Merge branch 'main' of https://github.com/gravity-ui/components into …
Ruminat f1a57ff
fix: fixed eslint
Ruminat ca8fcfd
fix: changed the version to origin/main
Ruminat dda332c
fix: removed useless img tag in Notification.scss
Ruminat b7088c8
feat: added `errorImage` and `emptyImage` props to Notifications
Ruminat af227c0
Merge branch 'main' of https://github.com/gravity-ui/components into …
Ruminat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,91 @@ | ||
import React from 'react'; | ||
|
||
import {useMobile} from '@gravity-ui/uikit'; | ||
|
||
import {Notification} from '../Notification'; | ||
import {NotificationWithSwipe} from '../Notification/NotificationWithSwipe'; | ||
import {NotificationProps} from '../Notification/definitions'; | ||
import {block} from '../utils/cn'; | ||
|
||
import './Notifications.scss'; | ||
|
||
const b = block('notifications'); | ||
|
||
export const NotificationWrapper = (props: { | ||
notification: NotificationProps; | ||
swipeThreshold?: number; | ||
}) => { | ||
const ref = React.useRef<HTMLDivElement>(null); | ||
|
||
const {notification, swipeThreshold} = props; | ||
const [mobile] = useMobile(); | ||
const [wrapperMaxHeight, setWrapperMaxHeight] = React.useState<number | undefined>(undefined); | ||
const [isRemoved, setIsRemoved] = React.useState(false); | ||
|
||
React.useEffect(() => { | ||
if (!ref.current) { | ||
if (!notification.archived && isRemoved) { | ||
setIsRemoved(false); | ||
} | ||
return () => {}; | ||
} | ||
|
||
if (notification.archived) { | ||
const listener = (event: TransitionEvent) => { | ||
if (event.propertyName === 'max-height') { | ||
setIsRemoved(true); | ||
ref.current?.removeEventListener('transitionend', listener); | ||
} | ||
}; | ||
|
||
ref.current.addEventListener('transitionend', listener); | ||
|
||
ref.current.style.transition = 'max-height 0.3s'; | ||
setWrapperMaxHeight(0); | ||
|
||
return () => { | ||
ref.current?.removeEventListener('transitionend', listener); | ||
}; | ||
} else { | ||
setIsRemoved(false); | ||
|
||
setTimeout(() => { | ||
if (!ref.current) return; | ||
|
||
ref.current.style.transition = 'none'; | ||
ref.current.style.maxHeight = 'none'; | ||
|
||
const maxHeight = ref.current?.getBoundingClientRect().height ?? 0; | ||
setWrapperMaxHeight(maxHeight); | ||
}, 0); | ||
|
||
return () => {}; | ||
} | ||
}, [ref, notification.archived, isRemoved]); | ||
|
||
const style = wrapperMaxHeight === undefined ? {} : {maxHeight: `${wrapperMaxHeight}px`}; | ||
|
||
if (isRemoved) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
className={b('notification-wrapper', { | ||
archived: notification.archived, | ||
unread: notification.unread, | ||
})} | ||
ref={ref} | ||
style={style} | ||
> | ||
{mobile && notification.swipeActions ? ( | ||
<NotificationWithSwipe | ||
notification={notification} | ||
swipeThreshold={swipeThreshold} | ||
/> | ||
) : ( | ||
<Notification notification={notification} /> | ||
)} | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a little bit weird that notification manages it's visibility state by itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because we need to animate the removing effect (
archive
)I thought it would be more convenient if we manage it in the
NotificationWrapper
component