diff --git a/apps/mantine.dev/src/pages/changelog/7-12-0.mdx b/apps/mantine.dev/src/pages/changelog/7-12-0.mdx index 3f03f213b8..b1cf2d1fdb 100644 --- a/apps/mantine.dev/src/pages/changelog/7-12-0.mdx +++ b/apps/mantine.dev/src/pages/changelog/7-12-0.mdx @@ -5,7 +5,7 @@ import { import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx'; -export default Layout(MDX_DATA.Changelog7110); +export default Layout(MDX_DATA.Changelog7120); ## Notifications at any position @@ -14,6 +14,12 @@ with [@mantine/notifications package](/x/notifications): +## Subscribe to notifications state + +You can now subscribe to notifications state changes with `useNotifications` hook: + + + ## SemiCircleProgress component New [SemiCircleProgress](/core/semi-circle-progress) component: diff --git a/apps/mantine.dev/src/pages/x/notifications.mdx b/apps/mantine.dev/src/pages/x/notifications.mdx index 48ce9f1be8..11129c8fbf 100644 --- a/apps/mantine.dev/src/pages/x/notifications.mdx +++ b/apps/mantine.dev/src/pages/x/notifications.mdx @@ -220,3 +220,12 @@ notifications.update({ `notifications.show` and `notifications.update` functions `autoClose` prop has higher priority. + +## Subscribe to notifications state + +You can subscribe to notifications state changes with `useNotifications` hook. +The hook returns an object with `notifications` and `queue` arrays. `notifications` +array contains all notifications that are currently displayed, `queue` contains +notifications that are waiting to be displayed. + + diff --git a/packages/@docs/demos/src/demos/notifications/Notifications.demo.store.tsx b/packages/@docs/demos/src/demos/notifications/Notifications.demo.store.tsx new file mode 100644 index 0000000000..1c6fdd5945 --- /dev/null +++ b/packages/@docs/demos/src/demos/notifications/Notifications.demo.store.tsx @@ -0,0 +1,57 @@ +import { Button, Code, Text } from '@mantine/core'; +import { useCounter } from '@mantine/hooks'; +import { notifications, useNotifications } from '@mantine/notifications'; +import { MantineDemo } from '@mantinex/demo'; + +const code = ` +import { Button } from '@mantine/core'; +import { notifications } from '@mantine/notifications'; + +function Demo() { + return ( + + ); +}`; + +function Demo() { + const [counter, { increment }] = useCounter(); + const notificationsStore = useNotifications(); + + const showNotification = () => { + notifications.show({ + title: `Notification ${counter}`, + message: 'Most notifications are added to queue', + }); + + increment(); + }; + + return ( + <> + + + Notifications state + {JSON.stringify(notificationsStore.notifications, null, 2)} + + Notifications queue + {JSON.stringify(notificationsStore.queue, null, 2)} + + ); +} + +export const store: MantineDemo = { + type: 'code', + code, + component: Demo, +}; diff --git a/packages/@docs/demos/src/demos/notifications/Notifications.demos.story.tsx b/packages/@docs/demos/src/demos/notifications/Notifications.demos.story.tsx index ef312cff8b..3de7258ad0 100644 --- a/packages/@docs/demos/src/demos/notifications/Notifications.demos.story.tsx +++ b/packages/@docs/demos/src/demos/notifications/Notifications.demos.story.tsx @@ -37,3 +37,8 @@ export const Demo_position = { name: '⭐ Demo: position', render: renderDemo(demos.position), }; + +export const Demo_store = { + name: '⭐ Demo: store', + render: renderDemo(demos.store), +}; diff --git a/packages/@docs/demos/src/demos/notifications/index.ts b/packages/@docs/demos/src/demos/notifications/index.ts index 8579b46e77..3484a6a9e3 100644 --- a/packages/@docs/demos/src/demos/notifications/index.ts +++ b/packages/@docs/demos/src/demos/notifications/index.ts @@ -5,3 +5,4 @@ export { limit } from './Notifications.demo.limit'; export { update } from './Notifications.demo.update'; export { customize } from './Notifications.demo.customize'; export { position } from './Notifications.demo.position'; +export { store } from './Notifications.demo.store'; diff --git a/packages/@mantine/notifications/src/Notifications.story.tsx b/packages/@mantine/notifications/src/Notifications.story.tsx index 8955ebdca0..c342430343 100644 --- a/packages/@mantine/notifications/src/Notifications.story.tsx +++ b/packages/@mantine/notifications/src/Notifications.story.tsx @@ -1,5 +1,4 @@ import { Button, Group } from '@mantine/core'; -import { Notifications } from './Notifications'; import { showNotification } from './notifications.store'; export default { title: 'Notifications' }; @@ -7,8 +6,6 @@ export default { title: 'Notifications' }; export function Usage() { return (
- -