Caret-Tui

NotificationProvider

Global context provider for toast notifications.

NotificationProvider wraps your application and provides the useNotify hook, enabling you to trigger floating "toast" style notifications anywhere in your CLI app. It queues multiple notifications and automatically dismisses them.

Usage

import { NotificationProvider, useNotify, Box } from 'caret-tui';
import { useInput } from 'ink';

const Content = () => {
  const { notify } = useNotify();

  useInput((input, key) => {
    if (key.return) {
      notify('Task completed successfully!', 'success');
    }
  });

  return <Box>Press Enter to notify</Box>;
};

const App = () => (
  <NotificationProvider>
    <Content />
  </NotificationProvider>
);

API

useNotify()

Returns an object containing the notify function.

const { notify } = useNotify();

// Signature:
notify(message: string, type?: 'success' | 'error' | 'info' | 'warning')

On this page