Ckeditor dark and light mode solution in react js,next js

It sounds like you’ve spent a lot of time trying to solve an issue without using CKEditor’s built-in props, and after some frustration, you found an alternative approach. Based on the CKEditor React guide here, you may want to share the method you found or any specific problem you’re encountering. I’d be happy to help you refine your solution or suggest alternatives if needed

// eslint-disable-next-line import/no-extraneous-dependencies
import 'ckeditor5/ckeditor5.css';

// eslint-disable-next-line import/no-extraneous-dependencies
import { CKEditor } from '@ckeditor/ckeditor5-react';
// eslint-disable-next-line import/no-extraneous-dependencies
import {
  Alignment,
  AutoLink,
  BlockQuote,
  Bold,
  ClassicEditor,
  Essentials,
  FontColor,
  FontSize,
  Heading,
  Highlight,
  Image,
  ImageCaption,
  ImageStyle,
  ImageToolbar,
  ImageUpload,
  Indent,
  Italic,
  Link,
  List,
  MediaEmbed,
  Mention,
  Paragraph,
  PasteFromOffice,
  RemoveFormat,
  Strikethrough,
  Table,
  TableToolbar,
  TextTransformation,
  Underline,
  Undo,
} from 'ckeditor5';
import React, { useEffect } from 'react';

interface CustomEditorInterface {
  value: string;
  onValueChange: (e: any) => void;
  toolbarItems: any;
  theme?: string;
  isDisable?: boolean;
  editorKey?: string;
}

const CustomEditor = ({
  toolbarItems,
  value,
  onValueChange,
  theme,
  isDisable = false,
  editorKey = 'defaultKey',
}: CustomEditorInterface) => {
  useEffect(() => {
    // Delay to ensure CKEditor is fully mounted before selecting DOM elements

    setTimeout(() => {
      const editorElementtoolbar: any =
        document.getElementsByClassName('ck-toolbar');
      const editorElement: any =
        document.getElementsByClassName('ck-editor__main');

      if (editorElement && editorElementtoolbar) {
        if (theme === 'dark') {
          // Apply dark mode classes
          Array.from(editorElementtoolbar).forEach((element: any) => {
            element.classList.add('ck-editor__editable_bg_color_darkmode');
          });

          Array.from(editorElement).forEach((element: any) => {
            element.classList.add('ck-editor__editable_bg_color_darkmode');
          });
        } else {
          // Apply light mode classes
          Array.from(editorElementtoolbar).forEach((element: any) => {
            element.classList.add('ck-editor__editable_bg_color_lightmode');
          });

          Array.from(editorElement).forEach((element: any) => {
            element.classList.add('ck-editor__editable_bg_color_lightmode');
          });
        }
      }
    }, 500);
  }, [theme, editorKey]); // Only run when the theme changes

  return (
    <CKEditor
      editor={ClassicEditor}
      key={editorKey}
      data={value}
      disabled={isDisable}
      config={{
        toolbar: {
          items: toolbarItems,
        },
        plugins: [
          Alignment,
          AutoLink,
          BlockQuote,
          Bold,
          Essentials,
          FontColor,
          FontSize,
          Heading,
          Highlight,
          Image,
          ImageCaption,
          ImageStyle,
          ImageToolbar,
          ImageUpload,
          Indent,
          Italic,
          Link,
          List,
          MediaEmbed,
          Mention,
          Paragraph,
          PasteFromOffice,
          RemoveFormat,
          Strikethrough,
          Table,
          TableToolbar,
          TextTransformation,
          Underline,
          Undo,
        ],
        list: {
          properties: {
            styles: true,
            startIndex: true,
            reversed: true,
          },
        },
        image: {
          toolbar: [
            'imageStyle:inline',
            'imageStyle:block',
            'imageStyle:side',
            '|',
            'toggleImageCaption',
            'imageTextAlternative',
          ],
        },
        table: {
          contentToolbar: ['tableColumn', 'tableRow', 'mergeTableCells'],
        },
      }}
      onChange={(_: any, editor: any) => {
        const data = editor.getData();
        onValueChange(data);
      }}
    />
  );
};

export default CustomEditor;
```;

const editorToolbar = [
  "undo",
  "redo",
  "|",
  "heading",
  "|",
  "bold",
  "italic",
  "underline",
  "strikethrough",
  "|",
  "fontSize",
  // 'fontColor',
  // 'highlight',
  "|",
  "alignment",
  "|",
  "numberedList",
  "bulletedList",
  "|",
  "indent",
  "outdent",
  "|",
  "link",
  "blockQuote",
  // 'insertTable',
  // 'imageUpload',
  // 'mediaEmbed',
  "|",
  "removeFormat",
];

    <CustomEditor
            value={
              questionInstructions.current !== ''
                ? questionInstructions.current
                : activeDetailsQuestion[0]?.optionalQuestionsInstruction
            }
            toolbarItems={editorToolbar}
            onValueChange={(e: any) => {
              // eslint-disable-next-line no-param-reassign
              questionInstructions.current = e;
            }}
            theme={currentTheme === 'dark' ? 'dark' : 'light'}
          />

this is css 

.ck-editor__editable_bg_color_darkmode .ck-editor__editable {
background-color: rgb(20, 20, 20) !important;
color: rgb(255, 255, 255) !important;
}
.ck-editor__editable_bg_color_darkmode, .ck-editor__editable_bg_color_darkmode .ck-toolbar__items button {
background-color: rgb(20, 20, 20) !important;
color: rgb(255, 255, 255) !important;
}
.ck.ck-button.ck-on
{
color: blue !important;
}
.ck-editor__editable_bg_color_lightmode .ck-editor__editable {
background-color: rgb(255, 255, 255) !important;
color: rgb(0, 0, 0) !important;
}
.ck-sticky-panel__content
{
border-radius: 6px 6px 0px 0px !important;
padding: 1px !important;
}

.ck-editor__editable
{
border-radius: 0px 0px 6px 6px !important;
}


dark mode 
[enter image description here](https://i.sstatic.net/UhI5YsED.png)
light mode 
[enter image description here](https://i.sstatic.net/tRvU5tyf.png)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật