Skip to content

Commit

Permalink
Merge pull request #121 from Conflux-Chain/notification
Browse files Browse the repository at this point in the history
feat: add Notification component
  • Loading branch information
0x74616e67 authored Dec 10, 2020
2 parents 33f8589 + 3c38739 commit 8cb5623
Show file tree
Hide file tree
Showing 15 changed files with 1,262 additions and 3 deletions.
18 changes: 17 additions & 1 deletion components/cfx-provider/cfx-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import {
CfxUIContextParams,
UpdateToastsFunction,
UpdateMessagesFunction,
UpdateNotificationsFunction,
} from '../utils/use-cfx-ui-context'
import ThemeProvider from '../styles/theme-provider'
import { ThemeParam } from '../styles/theme-provider/theme-provider'
import useCurrentState from '../utils/use-current-state'
import ToastContainer, { ToastWithID } from '../use-toasts/toast-container'
import MessageContainer from '../use-messages/message-container'
import { MessageItemProps } from '../use-messages/message-item'
import NotificationContainer from '../use-notifications/notification-container'
import { NotificationItemProps } from '../use-notifications/notification-item'

export interface Props {
theme?: ThemeParam
Expand Down Expand Up @@ -38,16 +41,28 @@ const CfxProvider: React.FC<PropsWithChildren<Props>> = ({ theme, children }) =>
setMessages(nextMessages)
}

const [notifications, setNotifications, notificationsRef] = useCurrentState<
Array<NotificationItemProps>
>([])
const updateNotifications: UpdateNotificationsFunction<NotificationItemProps> = (
fn: (notifications: NotificationItemProps[]) => NotificationItemProps[],
) => {
const nextNotifications = fn(notificationsRef.current)
setNotifications(nextNotifications)
}

const initialValue = useMemo<CfxUIContextParams>(
() => ({
messages,
updateMessages,
notifications,
updateNotifications,
toasts,
toastHovering,
updateToasts,
updateToastHoverStatus,
}),
[toasts, toastHovering, messages],
[toasts, toastHovering, messages, notifications],
)

return (
Expand All @@ -56,6 +71,7 @@ const CfxProvider: React.FC<PropsWithChildren<Props>> = ({ theme, children }) =>
{children}
<ToastContainer />
<MessageContainer />
<NotificationContainer />
</ThemeProvider>
</CfxUIContent.Provider>
)
Expand Down
1 change: 1 addition & 0 deletions components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as useTheme } from './styles/use-theme'
export { default as CfxProvider } from './cfx-provider'
export { default as CssBaseline } from './css-baseline'
export { default as useMessages } from './use-messages'
export { default as useNotifications } from './use-notifications'
export { default as useToasts } from './use-toasts'
export { default as useBodyScroll } from './use-body-scroll'
export { default as useClickAway } from './use-click-away'
Expand Down
Loading

0 comments on commit 8cb5623

Please sign in to comment.