npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@metadiv-studio/delete-dialog

v0.3.1

Published

A React component library that provides a reusable delete confirmation dialog with context-based state management. Built with TypeScript, React, and Tailwind CSS.

Readme

@metadiv-studio/delete-dialog

A React component library that provides a reusable delete confirmation dialog with context-based state management. Built with TypeScript, React, and Tailwind CSS.

🚀 Installation

npm i @metadiv-studio/delete-dialog

📋 Description

This package provides a comprehensive delete confirmation dialog solution for React applications. It includes:

  • DeleteDialogProvider: A context provider that manages the global state of delete dialogs
  • useDeleteDialog: A React hook to trigger delete dialogs from anywhere in your component tree
  • Customizable confirmation messages: Support for both default and custom confirmation messages
  • Loading states: Built-in loading state management during delete operations
  • Internationalization: Integrated with @metadiv-studio/translation for multi-language support
  • Accessible: Built with proper dialog semantics and keyboard navigation

The component leverages other Metadiv Studio packages including @metadiv-studio/button, @metadiv-studio/dialog, and @metadiv-studio/translation for a consistent design system.

🛠️ Usage

1. Setup the Provider

First, wrap your application with the DeleteDialogProvider:

import React from 'react';
import { DeleteDialogProvider } from '@metadiv-studio/delete-dialog';

function App() {
  return (
    <DeleteDialogProvider>
      {/* Your app content */}
      <YourComponent />
    </DeleteDialogProvider>
  );
}

export default App;

2. Use the Hook in Components

Use the useDeleteDialog hook to trigger delete confirmations:

import React from 'react';
import { useDeleteDialog } from '@metadiv-studio/delete-dialog';
import { Button } from '@metadiv-studio/button';

function UserList() {
  const { openDeleteDialog } = useDeleteDialog();

  const handleDeleteUser = async (userId: string) => {
    // Your delete logic here
    await fetch(`/api/users/${userId}`, { method: 'DELETE' });
    console.log(`User ${userId} deleted`);
  };

  return (
    <div>
      <Button 
        variant="destructive" 
        onClick={() => openDeleteDialog(() => handleDeleteUser('123'))}
      >
        Delete User
      </Button>
    </div>
  );
}

3. Custom Confirmation Messages

You can provide custom messages for specific delete operations:

import React from 'react';
import { useDeleteDialog } from '@metadiv-studio/delete-dialog';

function ProjectManager() {
  const { openDeleteDialog } = useDeleteDialog();

  const deleteProject = async () => {
    await fetch('/api/project/delete', { method: 'DELETE' });
  };

  const handleDeleteProject = () => {
    openDeleteDialog(
      deleteProject,
      <div className="flex items-center gap-2">
        <span>⚠️</span>
        <span>This will permanently delete the project and all associated data. This action cannot be undone.</span>
      </div>
    );
  };

  return (
    <Button variant="destructive" onClick={handleDeleteProject}>
      Delete Project
    </Button>
  );
}

4. Multiple Delete Operations

Handle different types of delete operations with specific messages:

import React from 'react';
import { useDeleteDialog } from '@metadiv-studio/delete-dialog';

function DataManager() {
  const { openDeleteDialog } = useDeleteDialog();

  const deleteFile = async (fileId: string) => {
    await fetch(`/api/files/${fileId}`, { method: 'DELETE' });
  };

  const deleteFolder = async (folderId: string) => {
    await fetch(`/api/folders/${folderId}`, { method: 'DELETE' });
  };

  return (
    <div className="space-y-4">
      {/* Simple delete with default message */}
      <Button 
        variant="destructive" 
        onClick={() => openDeleteDialog(() => deleteFile('file-123'))}
      >
        Delete File
      </Button>

      {/* Delete with custom warning */}
      <Button 
        variant="destructive" 
        onClick={() => openDeleteDialog(
          () => deleteFolder('folder-456'),
          "This folder contains 15 files. All files will be permanently deleted."
        )}
      >
        Delete Folder
      </Button>
    </div>
  );
}

🎯 API Reference

DeleteDialogProvider

A React context provider that should wrap your application.

Props:

  • children: React.ReactNode - Your application content

useDeleteDialog

A React hook that provides access to the delete dialog functionality.

Returns:

  • openDeleteDialog: (onDelete: () => Promise<void>, message?: React.ReactNode) => void

Parameters:

  • onDelete: () => Promise<void> - An async function that performs the delete operation
  • message?: React.ReactNode - Optional custom message to display in the dialog (defaults to translated "Are you sure you want to delete this?")

🔧 Configuration

Tailwind CSS

Ensure your tailwind.config.js includes the package path:

module.exports = {
  content: [
    // ... your other content paths
    "./node_modules/@metadiv-studio/**/*.{js,ts,jsx,tsx}",
  ],
  // ... rest of config
}

Dependencies

This package requires the following peer dependencies:

{
  "react": "^18",
  "react-dom": "^18"
}

And includes these dependencies:

  • @metadiv-studio/button - For consistent button styling
  • @metadiv-studio/dialog - For the modal dialog functionality
  • @metadiv-studio/translation - For internationalization support

🌍 Internationalization

The component uses @metadiv-studio/translation for internationalization. It expects the following translation keys:

  • delete - Dialog title
  • cancel - Cancel button text
  • are you sure you want to delete this? - Default confirmation message

🎨 Styling

The component uses Tailwind CSS classes and integrates with the Metadiv Studio design system. The dialog includes:

  • Responsive design
  • Dark mode support
  • Consistent spacing and typography
  • Loading states with disabled buttons
  • Destructive styling for the delete button

📝 TypeScript Support

Full TypeScript support is included with proper type definitions for all components and hooks.

interface IContext {
  openDeleteDialog: (onDelete: () => Promise<void>, message?: React.ReactNode) => void;
}

🚀 Best Practices

  1. Always handle errors: Wrap your delete functions in try-catch blocks
  2. Use descriptive messages: Provide clear, actionable confirmation messages
  3. Test delete operations: Ensure your delete functions work correctly before integration
  4. Consider user experience: Use appropriate loading states and feedback
  5. Implement proper permissions: Check user permissions before showing delete options

📦 Package Information

  • Version: 0.0.0
  • License: UNLICENSED
  • Repository: Part of the Metadiv Studio component library ecosystem