Skip to main content
Version: 0.7.6

Overview

The @abpjs/theme-shared package provides shared UI components and services for notifications, modals, and error handling.

Installation

npm install @abpjs/theme-shared

Required peer dependencies:

npm install @abpjs/core @chakra-ui/react @emotion/react lucide-react
note

Chakra UI v3 no longer requires @emotion/styled or framer-motion as peer dependencies.

Features

  • Toast Notifications - Success, error, warning, and info toasts
  • Confirmation Dialogs - Promise-based confirmation modals
  • Modal Component - Generic modal with Chakra UI v3 Dialog
  • Global Error Handling - Automatic error handling for ABP errors
  • Theme Configuration - Customize with defineConfig()
  • Color Mode - Built-in light/dark theme support (opt-in)

Main Exports

Hooks

HookDescription
useToasterShow toast notifications
useConfirmationShow confirmation dialogs
useColorModeAccess and toggle color mode

Components

ComponentDescription
ToastContainerToast notification container
ConfirmationDialogConfirmation dialog component
ModalGeneric modal component
ColorModeButtonPre-built color mode toggle button

Providers

ProviderDescription
ThemeSharedProviderTop-level provider (includes Chakra provider)

Utilities

ExportDescription
defineConfigCreate custom theme configuration
ToasterNamespace with types and Status enum

Setup

Wrap your app with ThemeSharedProvider:

import { ThemeSharedProvider } from '@abpjs/theme-shared';

function App() {
return (
<ThemeSharedProvider>
{/* Your app content */}
</ThemeSharedProvider>
);
}
tip

ThemeSharedProvider includes Chakra's provider internally, so you don't need to wrap with ChakraProvider separately.

Quick Example

import { useToaster, useConfirmation, Toaster } from '@abpjs/theme-shared';

function MyComponent() {
const toaster = useToaster();
const confirmation = useConfirmation();

const handleSave = async () => {
try {
await saveData();
toaster.success('Saved successfully!', 'Success');
} catch (error) {
toaster.error('Failed to save', 'Error');
}
};

const handleDelete = async () => {
const status = await confirmation.warn(
'Are you sure you want to delete this item?',
'Delete Item',
{ yesCopy: 'Delete', cancelCopy: 'Cancel' }
);

if (status === Toaster.Status.confirm) {
await deleteItem();
toaster.success('Item deleted', 'Success');
}
};

return (
<div>
<button onClick={handleSave}>Save</button>
<button onClick={handleDelete}>Delete</button>
</div>
);
}

Provider Props

PropTypeDefaultDescription
childrenReactNode-Child components
renderToastsbooleantrueRender ToastContainer
renderConfirmationbooleantrueRender ConfirmationDialog
themeOverridesThemeOverride-Custom theme configuration
toastPositionstring'bottom-right'Toast position
enableColorModebooleanfalseEnable dark/light mode
defaultColorMode'light' | 'dark' | 'system''light'Default color mode

Documentation