melishev / strapi-plugin-react-editorjs

📝 Plugin for Strapi Headless CMS, hiding the standard WYSIWYG editor on Editor.js
https://www.npmjs.com/package/strapi-plugin-react-editorjs
MIT License
171 stars 80 forks source link

Dark mode has black text within editor #32

Open kgrosvenor opened 2 years ago

kgrosvenor commented 2 years ago

Strapi now has dark theme set as default, or perhaps i set it by mistake

image

melishev commented 2 years ago

@kgrosvenor

In any case, we will need to fix this soon.

kgrosvenor commented 2 years ago

Thanks @melishev it'd be great!

kgrosvenor commented 2 years ago

Hey i managed to fix it by running locally like mentioned in the docs then i wrote bit of code to detect the mode. Feel free to use in a later update. @melishev

import styled from 'styled-components';
import {Box} from "@strapi/design-system/Box";

const computeInterfaceModeStyle = () => {
  const strapiTheme = window.localStorage.getItem('STRAPI_THEME');
  let interfaceModeColor = 'black';
  let toolbarButtonHoverColor = 'white';
  let selectionColor = '#e1f2ff';

  if (strapiTheme) {
    if (strapiTheme === 'dark') {
      interfaceModeColor = 'white';
      toolbarButtonHoverColor = '#181826';
      selectionColor = "#181826"
    }
    if(strapiTheme === 'light') {
      interfaceModeColor = 'black'
    }
  } else {
    // Check what the browser settings are, strapi falls back onto this when there is no local storage
    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
      interfaceModeColor = 'white';
    }
  }

  return `
    .ce-block__content {
      color: ${interfaceModeColor};
    }

    .ce-toolbar__actions-buttons svg {
      fill: ${interfaceModeColor}
    }

    .ce-toolbar__settings-btn--active, .ce-toolbar__settings-btn:hover {
      background-color: ${toolbarButtonHoverColor};
    }

    .ce-block--selected .ce-block__content {
      background: ${selectionColor};
    }

    .cdx-block::selection {
      background-color: ${selectionColor};
    }
  `;
}

const Wrapper = styled(Box)`

  ${computeInterfaceModeStyle};
melishev commented 2 years ago

@kgrosvenor Oh that's amazing, could you send a PR with your changes so we can include them in the package?

kgrosvenor commented 2 years ago

Will do!

kgrosvenor commented 2 years ago

https://github.com/melishev/strapi-plugin-react-editorjs/pull/40

image

netviral commented 2 years ago

Hey i managed to fix it by running locally like mentioned in the docs then i wrote bit of code to detect the mode. Feel free to use in a later update. @melishev

import styled from 'styled-components';
import {Box} from "@strapi/design-system/Box";

const computeInterfaceModeStyle = () => {
  const strapiTheme = window.localStorage.getItem('STRAPI_THEME');
  let interfaceModeColor = 'black';
  let toolbarButtonHoverColor = 'white';
  let selectionColor = '#e1f2ff';

  if (strapiTheme) {
    if (strapiTheme === 'dark') {
      interfaceModeColor = 'white';
      toolbarButtonHoverColor = '#181826';
      selectionColor = "#181826"
    }
    if(strapiTheme === 'light') {
      interfaceModeColor = 'black'
    }
  } else {
    // Check what the browser settings are, strapi falls back onto this when there is no local storage
    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
      interfaceModeColor = 'white';
    }
  }

  return `
    .ce-block__content {
      color: ${interfaceModeColor};
    }

    .ce-toolbar__actions-buttons svg {
      fill: ${interfaceModeColor}
    }

    .ce-toolbar__settings-btn--active, .ce-toolbar__settings-btn:hover {
      background-color: ${toolbarButtonHoverColor};
    }

    .ce-block--selected .ce-block__content {
      background: ${selectionColor};
    }

    .cdx-block::selection {
      background-color: ${selectionColor};
    }
  `;
}

const Wrapper = styled(Box)`

  ${computeInterfaceModeStyle};

Hey I was using this plugin. Could you tell me where can I paste this code to make this work?

kgrosvenor commented 2 years ago

Hey you will need to follow the steps in the README to include the project in your project. This is the best way to include in package.json so it installs nicely in one npm install command.

  "workspaces": [
    "src/plugins/strapi-plugin-react-editorjs"
  ],

Clone my forked repo into plugins in your project, remove the git association.

So it should be like

src/plugins/strapi-plugin-react-editorjs

Update your plugins config file to use the following

module.exports = ({ env }) => ({
  // ...
  'editorjs': {
    enabled: true,
    resolve: './src/plugins/strapi-plugin-react-editorjs'
  },
  // ...
})

npm run build and then restart the server

netviral commented 2 years ago

Hey you will need to follow the steps in the README to include the project in your project. This is the best way to include in package.json so it installs nicely in one npm install command.

  "workspaces": [
    "src/plugins/strapi-plugin-react-editorjs"
  ],

Clone my forked repo into plugins in your project, remove the git association.

So it should be like

src/plugins/strapi-plugin-react-editorjs

Update your plugins config file to use the following

module.exports = ({ env }) => ({
  // ...
  'editorjs': {
    enabled: true,
    resolve: './src/plugins/strapi-plugin-react-editorjs'
  },
  // ...
})

npm run build and then restart the server

Hey yes I managed to get the plugin on. I meant how do I go about changing the editor font colors according to the mode. How can I use the snippet of logic you built to get the same results?

Thank you so much in advance!

SalahAdDin commented 2 years ago

Hey you will need to follow the steps in the README to include the project in your project. This is the best way to include in package.json so it installs nicely in one npm install command.

  "workspaces": [
    "src/plugins/strapi-plugin-react-editorjs"
  ],

Clone my forked repo into plugins in your project, remove the git association.

So it should be like

src/plugins/strapi-plugin-react-editorjs

Update your plugins config file to use the following

module.exports = ({ env }) => ({
  // ...
  'editorjs': {
    enabled: true,
    resolve: './src/plugins/strapi-plugin-react-editorjs'
  },
  // ...
})

npm run build and then restart the server

Did you try to make a pull request?

I found this bug too.