RC-Dialog

10.0.0 · deprecated · verified Sun Apr 19

rc-dialog is a foundational React UI component providing a highly customizable and accessible dialog (modal) implementation. It offers core functionalities like visibility control, masking, animation hooks, and keyboard interaction (e.g., Esc key to close). While version 10.0.0 is the latest stable release of `rc-dialog` as a standalone package, its active development has largely shifted to its successor, `@rc-component/dialog`. `rc-dialog` itself has not seen new releases or significant updates for over a year, suggesting it is now in a maintenance or deprecated state. Developers are generally advised to consider `@rc-component/dialog` for new projects or migrations due to its ongoing development and improved features, including enhanced focus management. This package prioritizes stateless design and easy customization via props like `prefixCls`, `className`, `classNames`, and `styles`, making it a flexible choice for various design systems.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic functional React component using `rc-dialog`, including state management for visibility, custom title, and event handling for closing. It highlights essential props like `visible`, `onClose`, `maskClosable`, `keyboard`, and `destroyOnClose`, and includes the necessary CSS import.

import React, { useState, useCallback } from 'react';
import ReactDOM from 'react-dom/client';
import Dialog from 'rc-dialog';
import 'rc-dialog/assets/index.css'; // Don't forget to import the default styles

const App = () => {
  const [visible, setVisible] = useState(false);
  const [title, setTitle] = useState('Basic Dialog');

  const showDialog = useCallback(() => {
    setVisible(true);
  }, []);

  const onClose = useCallback(() => {
    console.log('Dialog closed!');
    setVisible(false);
  }, []);

  return (
    <div>
      <button onClick={showDialog}>Open Dialog</button>
      <Dialog
        title={title}
        visible={visible}
        onClose={onClose}
        maskClosable={true} // Allow closing by clicking the mask
        keyboard={true}    // Allow closing by pressing Esc key
        destroyOnClose={true} // Unmount children when dialog closes
        className="my-custom-dialog"
        style={{ width: 500 }}
      >
        <p>This is the content of the dialog.</p>
        <p>You can put any React elements here.</p>
        <p>Current version: 10.0.0</p>
        <button onClick={() => alert('Button inside dialog clicked!')}>Click Me</button>
      </Dialog>
    </div>
  );
};

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(<App />);

view raw JSON →