prompt-modal.tsx


Overview

prompt-modal.tsx defines a React functional component PromptModal that renders a modal dialog displaying a provided prompt string with markdown syntax highlighted. The component leverages Ant Design's Modal and Space components for UI layout, alongside custom components for rendering SVG icons and highlighted markdown content. It is designed to be reusable and controlled externally via props for visibility and hiding behavior.

This file primarily serves as a presentational component within a larger UI system, likely involved in displaying prompts or feedback content in a chat or feedback interface.


Component: PromptModal

Description

PromptModal is a React functional component that displays a modal dialog containing a prompt message formatted with markdown. It accepts props controlling its visibility, a callback to hide the modal, and the prompt text itself.

Props

The component's props are based on an intersection of:

From the code and naming conventions, the effective props are:

Prop Name

Type

Description

visible

boolean

Controls whether the modal is visible or hidden.

hideModal

() => void

Callback function invoked to close the modal.

prompt

string (optional)

The prompt content to display inside the modal.

Return Value

Returns JSX representing the modal dialog with:

Usage Example

import { useState } from 'react';
import PromptModal from './prompt-modal';

const ExampleComponent = () => {
  const [isModalVisible, setModalVisible] = useState(false);
  const promptText = "### Hello World\nThis is a *markdown* prompt.";

  const openModal = () => setModalVisible(true);
  const closeModal = () => setModalVisible(false);

  return (
    <>
      <button onClick={openModal}>Show Prompt</button>
      <PromptModal
        visible={isModalVisible}
        hideModal={closeModal}
        prompt={promptText}
      />
    </>
  );
};

Implementation Details


Interactions with Other Parts of the System


Mermaid Diagram: Component Structure and Props

componentDiagram
    component PromptModal {
      +visible: boolean
      +hideModal(): void
      +prompt?: string
    }

    component Modal {
      +title: ReactNode
      +width: string | number
      +open: boolean
      +onCancel(): void
      +footer: ReactNode | null
    }

    component Space
    component SvgIcon {
      +name: string
      +width: number
    }
    component HightLightMarkdown {
      +children: string
    }

    PromptModal --> Modal : renders
    Modal --> Space : uses in title
    Space --> SvgIcon : contains
    Modal --> HightLightMarkdown : contains prompt content

Summary

The prompt-modal.tsx file provides a simple yet effective React component for displaying a prompt message within a modal dialog. By combining Ant Design UI elements with custom markdown rendering and SVG icons, it creates a reusable and visually consistent component that fits into larger chat or feedback systems. Its controlled props make it easy to integrate and manage within parent components.