Skip to content

Commit

Permalink
fix: apply light mode for Fence
Browse files Browse the repository at this point in the history
  • Loading branch information
yanCode committed Nov 23, 2024
1 parent 1d99b6f commit 1653b88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion docs/src/components/Fence.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { Fragment } from 'react'
import Highlight, { defaultProps } from 'prism-react-renderer'
import { useTheme } from 'next-themes'
import lightTheme from 'prism-react-renderer/themes/github'


export function Fence({ children, language }) {
const { resolvedTheme } = useTheme()
return (
<Highlight
{...defaultProps}
code={children.trimEnd()}
language={language}
theme={undefined}
theme={resolvedTheme !== 'dark' ? lightTheme: undefined }
>
{({ className, style, tokens, getTokenProps }) => (
<pre className={className} style={style}>
Expand Down
13 changes: 11 additions & 2 deletions docs/src/components/ThemeSelector.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { useTheme } from 'next-themes'
import { Listbox } from '@headlessui/react'
import clsx from 'clsx'
Expand Down Expand Up @@ -55,13 +55,22 @@ function SystemIcon(props) {

export function ThemeSelector(props) {
let { theme, setTheme } = useTheme()

const [mounted, setMounted] = useState(false)
useEffect(() => {
if (theme) {
document.documentElement.setAttribute('data-theme', theme)
}
}, [theme])

// useEffect only runs on the client, so now we can safely show the UI
useEffect(() => {
setMounted(true)
}, [])

if (!mounted) {
return null
}

return (
<Listbox
as="div"
Expand Down

0 comments on commit 1653b88

Please sign in to comment.