-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mantine.dev] Add notifications state subscriptions documentation
- Loading branch information
Showing
6 changed files
with
79 additions
and
4 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
57 changes: 57 additions & 0 deletions
57
packages/@docs/demos/src/demos/notifications/Notifications.demo.store.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,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 ( | ||
<Button | ||
onClick={() => | ||
notifications.show({ | ||
title: 'Default notification', | ||
message: 'Do not forget to star Mantine on GitHub! 🌟', | ||
}) | ||
} | ||
> | ||
Show notification | ||
</Button> | ||
); | ||
}`; | ||
|
||
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 ( | ||
<> | ||
<Button onClick={showNotification} mb="md"> | ||
Show notification | ||
</Button> | ||
|
||
<Text>Notifications state</Text> | ||
<Code block>{JSON.stringify(notificationsStore.notifications, null, 2)}</Code> | ||
|
||
<Text mt="md">Notifications queue</Text> | ||
<Code block>{JSON.stringify(notificationsStore.queue, null, 2)}</Code> | ||
</> | ||
); | ||
} | ||
|
||
export const store: MantineDemo = { | ||
type: 'code', | ||
code, | ||
component: Demo, | ||
}; |
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