code-hike / bright

React Server Component for syntax highlighting
https://bright.codehike.org
1.45k stars 20 forks source link

dark mode with html.class dont working #32

Closed tarcisioandrade closed 1 year ago

tarcisioandrade commented 1 year ago

I'm using bright in a project where dark mode is done by adding the "dark" or "light" class to the html, but bright isn't following the project's theme. At the moment it only works if I add a data-theme.

pomber commented 1 year ago

I used Bright with html.light yesterday and it worked. Can you share how are you using it?

tarcisioandrade commented 1 year ago

I used Bright with html.light yesterday and it worked. Can you share how are you using it?

I did it according to the documentation:

import React from "react";
import { Code as BrightCode } from "bright";

type Props = {
  code: string;
  language?: string;
  filename?: string;
};

BrightCode.theme = {
  dark: "material-palenight",
  light: "material-lighter",
};

const Code = ({ code, language, filename }: Props) => {
  return (
    <BrightCode
      code={code}
      title={filename}
      lang={language}
      style={{ margin: "48px 0 80px 0" }}
      className="[&>pre]:xl:!px-4 xl:!ml-[-32px]"
    />
  );
};

export default Code;

image

now with data-theme it works fine

image

pomber commented 1 year ago

Try adding lightSelector to the theme object:

Code.theme = {
  dark: "material-palenight",
  light: "material-lighter",
  lightSelector: 'html.light'
}
tarcisioandrade commented 1 year ago

Try adding lightSelector to the theme object:

Code.theme = {
  dark: "material-palenight",
  light: "material-lighter",
  lightSelector: 'html.light'
}

OMG! It worked perfectly, and now I've realised that in the doc it shows this "lightSelector" property, but it was in a comment and I didn't notice it. Sorry for my stupidity and thanks for your help!