Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(explorer): add darkmode theme to SyntaxHighlighter #4127

18 changes: 10 additions & 8 deletions apps/explorer/src/components/module/PkgModulesWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function PkgModulesWrapper({
)}
/>
</div>
<div className="flex-1 overflow-auto pt-sm">
<div className="max-h-[560px] flex-1 overflow-auto pt-sm">
<VerticalList>
<div className="flex flex-col gap-sm">
{moduleNames.map((name) => (
Expand Down Expand Up @@ -189,13 +189,15 @@ function ExecutePanelContent({
))}
</SegmentedButton>

<ListTabContent id={EXECUTE_TAB.id}>
<ModuleFunctionsInteraction
key={`${packageId}-${moduleName}`}
packageId={packageId}
moduleName={moduleName}
/>
</ListTabContent>
<div className="pr-md--rs">
<ListTabContent id={EXECUTE_TAB.id}>
<ModuleFunctionsInteraction
key={`${packageId}-${moduleName}`}
packageId={packageId}
moduleName={moduleName}
/>
</ListTabContent>
</div>
</TabsProvider>
</TabbedContentWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { useOnScreen } from '@iota/core';
import { Theme, useOnScreen, useTheme } from '@iota/core';
import { useRef, useEffect, useState } from 'react';
import { Highlight, themes } from 'prism-react-renderer';
import type { Language } from 'prism-react-renderer';
Expand Down Expand Up @@ -35,19 +35,25 @@ export function SyntaxHighlighter({
const observerElem = useRef<HTMLDivElement | null>(null);
const { isIntersecting } = useOnScreen(observerElem);
const [loadedLines, setLoadedLines] = useState(MAX_LINES);
const { theme } = useTheme();

useEffect(() => {
if (isIntersecting) {
setLoadedLines((prev) => prev + MAX_LINES);
}
}, [isIntersecting]);

const isDark = theme === Theme.Dark;
const codeTheme = isDark ? themes.oneDark : themes.github;

return (
<div className="overflow-auto whitespace-pre font-mono text-sm">
<Highlight code={code} language={language} theme={themes.github}>
<Highlight code={code} language={language} theme={codeTheme}>
{({ style, tokens, getLineProps, getTokenProps }) => (
<pre className="overflow-auto bg-transparent p-xs font-medium" style={style}>
{tokens.slice(0, loadedLines).map((line, i) => (
<div {...getLineProps({ line, key: i })} key={i} className="table-row">
<div className="table-cell select-none pr-4 text-left text-primary-30 opacity-50">
<div className="table-cell select-none pr-4 text-left text-primary-30 opacity-50 dark:text-primary-80">
{i + 1}
</div>

Expand Down
Loading