Skip to Content

notifier

A utility for displaying notifications with pre-configured colors. Built on top of @mantine/notifications.

Import

import { notifier } from '@tidbcloud/uikit'

Setup

Before using notifier, make sure you have the Notifications component set up in your app:

import { Notifications } from '@tidbcloud/uikit' function App() { return ( <> <Notifications /> {/* Your app content */} </> ) }

Basic Usage

import { notifier, Button, Group } from '@tidbcloud/uikit' function Demo() { return ( <Group> <Button onClick={() => notifier.success('Operation completed successfully!')}>Success</Button> <Button onClick={() => notifier.error('Something went wrong!')}>Error</Button> <Button onClick={() => notifier.warn('Please check your input')}>Warning</Button> <Button onClick={() => notifier.info('New updates available')}>Info</Button> </Group> ) }

With Additional Options

You can pass additional notification options as the second argument:

import { notifier, Button } from '@tidbcloud/uikit' function Demo() { return ( <Button onClick={() => notifier.success('File uploaded!', { title: 'Upload Complete', autoClose: 5000, withCloseButton: true }) } > Upload File </Button> ) }

Clear All Notifications

import { notifier, Button } from '@tidbcloud/uikit' function Demo() { return <Button onClick={() => notifier.clear()}>Clear All Notifications</Button> }

Methods

MethodParametersDescription
notifier.success(message: ReactNode, props?: NotificationData)Show green success notification
notifier.error(message: ReactNode, props?: NotificationData)Show red error notification
notifier.warn(message: ReactNode, props?: NotificationData)Show yellow warning notification
notifier.info(message: ReactNode, props?: NotificationData)Show cyan info notification
notifier.clear()Clear all notifications

NotificationData Options

OptionTypeDescription
titleReactNodeNotification title
iconReactNodeNotification icon
autoClosenumber | falseAuto close timeout in ms, false to disable
withCloseButtonbooleanShow close button
onClose() => voidCalled when notification is closed
onOpen() => voidCalled when notification is opened
loadingbooleanShow loading state
radiusMantineRadiusBorder radius
withBorderbooleanAdd border
Last updated on