Skip to content

Commit

Permalink
docs: remove-show-more
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitts committed Jun 30, 2024
1 parent 641492b commit 28caea9
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions apps/docs/components/sandpack/code-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {SandpackInitMode} from "@codesandbox/sandpack-react";

import * as React from "react";
import {FileTabs, useSandpack, useActiveCode, SandpackStack} from "@codesandbox/sandpack-react";
import {clsx} from "@nextui-org/shared-utils";
import {Language} from "prism-react-renderer";

import {HighlightedLines} from "./types";
Expand Down Expand Up @@ -31,8 +30,6 @@ export interface CodeViewerProps {
containerRef?: React.RefObject<HTMLDivElement>;
}

// const INITIAL_HEIGHT = "200px";

export const SandpackCodeViewer = React.forwardRef<any, CodeViewerProps>(
({showTabs, code: propCode, highlightedLines, containerRef}, ref) => {
const {sandpack} = useSandpack();
Expand All @@ -44,31 +41,25 @@ export const SandpackCodeViewer = React.forwardRef<any, CodeViewerProps>(
// hack to make sure we re-render the code editor and change current file
// TODO: open an issue on sandpack-react
// const [internalKey, setInternalKey] = React.useState(() => id);
const lineCountRef = React.useRef<{[key: string]: number}>({});
// const lineCountRef = React.useRef<{[key: string]: number}>({});

if (!lineCountRef.current[activeFile]) {
lineCountRef.current[activeFile] = code.split("\n").length;
}
// if (!lineCountRef.current[activeFile]) {
// lineCountRef.current[activeFile] = code.split("\n").length;
// }

const shouldShowTabs = showTabs ?? sandpack.visibleFilesFromProps.length > 1;

const fileExt = activeFile.split(".").pop() as Language;

// const isAppFile = activeFile.includes("App");

// React.useEffect(() => {
// if (containerRef && containerRef?.current !== null) {
// containerRef.current.style.height = INITIAL_HEIGHT;
// }
// }, [containerRef]);

// React.useEffect(() => {
// setInternalKey(getId());
// }, [propCode, code]);

React.useEffect(() => {
if (containerRef && containerRef?.current !== null) {
const container = containerRef?.current;
if (containerRef && containerRef.current !== null) {
const container = containerRef.current;

container.style.height = "auto";
}
Expand All @@ -79,7 +70,7 @@ export const SandpackCodeViewer = React.forwardRef<any, CodeViewerProps>(
<div className="h-full">
<SandpackStack>
{shouldShowTabs ? <FileTabs /> : null}
<div className={clsx("sp-code-viewer max-h-[600px] overflow-y-scroll")}>
<div className="sp-code-viewer max-h-[600px] overflow-y-scroll">
{/*
* Disabled in favor of Codeblock due to performance issues & font size on ios
*
Expand All @@ -97,7 +88,7 @@ export const SandpackCodeViewer = React.forwardRef<any, CodeViewerProps>(
/> */}
<Codeblock
ref={ref}
className={"pb-2"}
className="pb-2"
codeString={propCode || code}
language={fileExt}
metastring={highlightedLines && `{${highlightedLines}}`}
Expand Down

0 comments on commit 28caea9

Please sign in to comment.