-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add notifications provider in sidebarlayout (#2672)
- Loading branch information
1 parent
9cb2d37
commit edcfbe0
Showing
13 changed files
with
333 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@kadena/kode-ui': minor | ||
--- | ||
|
||
add notifications hook to the sidebar layout |
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
12 changes: 12 additions & 0 deletions
12
...ages/libs/kode-ui/src/patterns/SideBarLayout/components/LayoutProvider/LayoutProvider.tsx
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,12 @@ | ||
import type { FC, PropsWithChildren } from 'react'; | ||
import React from 'react'; | ||
import { NotificationsProvider } from './NotificationsProvider'; | ||
import { SideBarLayoutProvider } from './SideBarLayoutProvider'; | ||
|
||
export const LayoutProvider: FC<PropsWithChildren> = ({ children }) => { | ||
return ( | ||
<NotificationsProvider> | ||
<SideBarLayoutProvider>{children}</SideBarLayoutProvider> | ||
</NotificationsProvider> | ||
); | ||
}; |
63 changes: 63 additions & 0 deletions
63
...bs/kode-ui/src/patterns/SideBarLayout/components/LayoutProvider/NotificationsProvider.tsx
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,63 @@ | ||
import type { FC, PropsWithChildren } from 'react'; | ||
import React, { createContext, useContext, useState } from 'react'; | ||
import type { INotificationProps } from 'src/components'; | ||
|
||
export type INotificationMinimizedProps = Pick< | ||
INotificationProps, | ||
'icon' | 'role' | 'isDismissable' | 'onDismiss' | 'intent' | ||
> & { | ||
id: string; | ||
label: string; | ||
message: string; | ||
}; | ||
|
||
interface INotificationsContext { | ||
notifications: INotificationMinimizedProps[]; | ||
addNotification: (notification: Partial<INotificationMinimizedProps>) => void; | ||
removeNotification: (notification: INotificationMinimizedProps) => void; | ||
} | ||
|
||
export const NotificationsContext = createContext<INotificationsContext>({ | ||
notifications: [], | ||
addNotification: () => {}, | ||
removeNotification: () => {}, | ||
}); | ||
|
||
export const useNotifications = () => useContext(NotificationsContext); | ||
|
||
export interface INotificationsProvider extends PropsWithChildren {} | ||
|
||
export const NotificationsProvider: FC<INotificationsProvider> = ({ | ||
children, | ||
}) => { | ||
const [notifications, setNotifications] = useState< | ||
INotificationMinimizedProps[] | ||
>([]); | ||
|
||
const removeNotification = (notification: INotificationMinimizedProps) => { | ||
setNotifications((v) => v.filter((not) => not.id !== notification.id)); | ||
}; | ||
|
||
const addNotification = ( | ||
notification: Partial<INotificationMinimizedProps>, | ||
) => { | ||
const notificationProps: INotificationMinimizedProps = { | ||
...notification, | ||
id: crypto.randomUUID(), | ||
role: notification.role ?? 'status', | ||
intent: notification.intent ?? 'info', | ||
label: notification.label!, | ||
message: notification.message!, | ||
}; | ||
|
||
setNotifications((v) => [...v, notificationProps]); | ||
}; | ||
|
||
return ( | ||
<NotificationsContext.Provider | ||
value={{ notifications, addNotification, removeNotification }} | ||
> | ||
{children} | ||
</NotificationsContext.Provider> | ||
); | ||
}; |
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
3 changes: 3 additions & 0 deletions
3
packages/libs/kode-ui/src/patterns/SideBarLayout/components/LayoutProvider/index.ts
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,3 @@ | ||
export { LayoutProvider } from './LayoutProvider'; | ||
export { useNotifications } from './NotificationsProvider'; | ||
export { useLayout } from './SideBarLayoutProvider'; |
Oops, something went wrong.