Skip to content

Alert

Alert dialogs for confirmations and important messages.

Installation

import { AlertProvider, useAlert } from '@smc/darwin-ui';

Setup

Wrap your app with AlertProvider:

import { AlertProvider } from '@smc/darwin-ui';
function App() {
return (
<AlertProvider>
<YourApp />
</AlertProvider>
);
}

Usage

import { useAlert, Button } from '@smc/darwin-ui';
export function Example() {
const { showAlert } = useAlert();
return (
<Button
variant="destructive"
onClick={() =>
showAlert({
title: 'Delete Item?',
message: 'This action cannot be undone.',
type: 'warning',
onConfirm: () => console.log('Deleted'),
})
}
>
Delete
</Button>
);
}

Types

showAlert({ type: 'info', ... });
showAlert({ type: 'success', ... });
showAlert({ type: 'warning', ... });
showAlert({ type: 'error', ... });

API Reference

useAlert Hook

const { showAlert } = useAlert();

showAlert Options

OptionTypeDefaultDescription
titlestring-Alert title
messagestring-Alert message
typeAlertType"info"Alert variant
onConfirm() => void-Confirm callback
onCancel() => void-Cancel callback

AlertType

type AlertType = 'info' | 'success' | 'warning' | 'error';