📚 Wiki Documentation

Version 8.3 - Code Copy Component Enhancement

Major refactoring of the code copy component with improved type safety, component structure, and maintainability

📅
⏱️
2 min read
Minor Release

Overview

Version 8.3 introduces a significant refactor of the code copy component, improving its structure, maintainability, and type safety. The changes focus on better separation of concerns and improved type management.

Key Changes

1. Component Structure Reorganization

  • Split the monolithic CodeCopySimple.tsx into separate logical components:
    • CopyButton.tsx: UI component for the copy button
    • useCopyButton.ts: Custom hook for copy functionality
    • styles.ts: Centralized styles configuration
    • CodeCopySimple.tsx: Main wrapper component

2. Type System Improvements

  • Created centralized type definitions in src/types/codeblock.ts
  • Added proper TypeScript interfaces for:
    • StyleValue: Base style object type
    • Styles: Component styles configuration
    • CopyButtonProps: Copy button component props
    • UseCopyButtonProps: Copy button hook props

3. Style Enhancements

  • Maintained Tokyo Night theme consistency
  • Improved toast notification styling:
    • Semi-transparent backgrounds
    • Frosted glass effect
    • Theme-appropriate colors
    • Subtle animations and transitions

4. Technical Improvements

  • Better error handling for clipboard operations
  • Improved mobile responsiveness
  • Enhanced accessibility attributes
  • Proper cleanup of DOM modifications
  • Optimized performance through memoization

Component Usage

// Basic usage in MDX or other content
<CodeCopySimple />

The component automatically enhances all code blocks in the document with:

  • Copy button functionality
  • Language label display
  • Toast notifications for copy operations
  • Mobile-responsive design

Styling

The component uses a consistent Tokyo Night theme with:

  • Primary colors: #24283b (background), #a9b1d6 (text)
  • Success state: #9ece6a
  • Error state: #f7768e
  • Hover state: #414868

Technical Details

Type Definitions

interface CopyButtonProps {
  codeText: string;
  isMobile: boolean;
  onCopy: () => void;
}

interface UseCopyButtonProps {
  buttonRef: RefObject<HTMLButtonElement | null>;
  codeText: string;
  onCopy: () => void;
  toastStyles: any;
}

Component Structure

  • CodeCopySimple: Main wrapper that handles DOM manipulation
  • CopyButton: Pure UI component for the copy button
  • useCopyButton: Hook containing copy logic and state management
  • styles: Centralized style configurations

Future Improvements

  • Add proper typing for toast styles
  • Consider adding customization options for themes
  • Implement copy progress indication
  • Add support for copying specific line ranges
📤

Share this Web Wiki

Help others discover this content by sharing it on your favorite platform

Ready to Share
4 Platforms Available