1
1
import React , { useState } from "react" ;
2
2
import { PrismLight as SyntaxHighlighter } from "react-syntax-highlighter" ;
3
3
import { vscDarkPlus } from "react-syntax-highlighter/dist/esm/styles/prism" ;
4
- import { vs } from "react-syntax-highlighter/dist/esm/styles/prism" ;
5
4
6
5
// Import only the languages we need
7
6
import typescript from "react-syntax-highlighter/dist/esm/languages/prism/typescript" ;
@@ -33,7 +32,7 @@ interface CodeBlockProps {
33
32
| "css" ;
34
33
showLineNumbers ?: boolean ;
35
34
showCopyButton ?: boolean ;
36
- variant ?: "default" | "hero" | "light" ;
35
+ variant ?: "default" | "hero" ;
37
36
}
38
37
39
38
export const CodeBlock : React . FC < CodeBlockProps > = ( {
@@ -44,52 +43,6 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({
44
43
variant = "default" ,
45
44
} ) => {
46
45
const [ copied , setCopied ] = useState ( false ) ;
47
- const [ detectedTheme , setDetectedTheme ] = useState < "light" | "dark" > ( "dark" ) ;
48
-
49
- // Detect the actual theme based on background
50
- React . useEffect ( ( ) => {
51
- if ( variant !== "default" ) return ;
52
-
53
- const checkTheme = ( ) => {
54
- const body = document . body ;
55
- const computedStyle = window . getComputedStyle ( body ) ;
56
- const bgColor = computedStyle . backgroundColor ;
57
-
58
- // Check if background is light
59
- if ( bgColor === "rgb(255, 255, 255)" || bgColor === "white" ) {
60
- setDetectedTheme ( "light" ) ;
61
- } else {
62
- // Check the nearest parent with a background
63
- let foundDarkBg = false ;
64
-
65
- // Look for elements with dark backgrounds
66
- const darkElements = document . querySelectorAll (
67
- ".bg-gray-950, .bg-gray-900, .min-h-screen" ,
68
- ) ;
69
- darkElements . forEach ( ( el ) => {
70
- const elBg = window . getComputedStyle ( el ) . backgroundColor ;
71
- if ( elBg && elBg !== "rgba(0, 0, 0, 0)" && elBg !== "transparent" ) {
72
- // Parse RGB values
73
- const match = elBg . match ( / \d + / g) ;
74
- if ( match ) {
75
- const [ r , g , b ] = match . map ( Number ) ;
76
- // If all values are low, it's a dark background
77
- if ( r < 50 && g < 50 && b < 50 ) {
78
- foundDarkBg = true ;
79
- }
80
- }
81
- }
82
- } ) ;
83
-
84
- setDetectedTheme ( foundDarkBg ? "dark" : "light" ) ;
85
- }
86
- } ;
87
-
88
- checkTheme ( ) ;
89
- // Re-check on window resize or other changes
90
- window . addEventListener ( "resize" , checkTheme ) ;
91
- return ( ) => window . removeEventListener ( "resize" , checkTheme ) ;
92
- } , [ variant ] ) ;
93
46
94
47
const handleCopy = async ( ) => {
95
48
try {
@@ -110,21 +63,12 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({
110
63
// Always disable line numbers for now
111
64
const shouldShowLineNumbers = false ;
112
65
113
- // Use light theme for light variant or detected light theme
114
- const isLightTheme =
115
- variant === "light" || ( variant === "default" && detectedTheme === "light" ) ;
116
- const theme = isLightTheme ? vs : vscDarkPlus ;
117
-
118
66
return (
119
67
< div className = "relative group" >
120
68
{ showCopyButton && variant !== "hero" && (
121
69
< button
122
70
onClick = { handleCopy }
123
- className = { `absolute top-3 right-3 px-3 py-1 ${
124
- isLightTheme
125
- ? "bg-gray-100/80 hover:bg-gray-200/90 text-gray-700 border-gray-300/50"
126
- : "bg-gray-700/50 hover:bg-gray-600/70 text-gray-300 border-gray-600/50"
127
- } backdrop-blur-sm rounded text-xs border transition-all duration-200 z-10 ${
71
+ className = { `absolute top-3 right-3 px-3 py-1 bg-gray-700/50 hover:bg-gray-600/70 backdrop-blur-sm rounded text-xs text-gray-300 border border-gray-600/50 transition-all duration-200 z-10 ${
128
72
copied ? "opacity-100" : "opacity-50 group-hover:opacity-100"
129
73
} `}
130
74
title = "Copy code"
@@ -170,9 +114,7 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({
170
114
className = { `overflow-x-auto rounded-lg shadow-lg ${
171
115
variant === "hero"
172
116
? "bg-gray-900/80 border border-gray-700/30"
173
- : isLightTheme
174
- ? "bg-gray-50 border border-gray-200"
175
- : "bg-gray-900/90 border border-gray-700/50"
117
+ : "bg-gray-900/90 border border-gray-700/50"
176
118
} `}
177
119
>
178
120
< div style = { { position : "relative" } } >
@@ -200,7 +142,7 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({
200
142
) }
201
143
< SyntaxHighlighter
202
144
language = { language }
203
- style = { theme }
145
+ style = { vscDarkPlus }
204
146
showLineNumbers = { false }
205
147
customStyle = { {
206
148
margin : 0 ,
@@ -211,7 +153,7 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({
211
153
: variant === "hero"
212
154
? "1.25rem"
213
155
: "1rem" ,
214
- background : isLightTheme ? "#fafafa" : "transparent" ,
156
+ background : "transparent" ,
215
157
fontSize : variant === "hero" ? "0.9375rem" : "0.875rem" ,
216
158
lineHeight : 1.7 ,
217
159
fontFamily :
0 commit comments