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: Add max, min btn #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/components/CircuitJsonPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,12 @@ export const CircuitJsonPreview = ({
onValueChange={setActiveTab as any}
className="rf-flex-grow rf-flex rf-flex-col rf-p-2"
>
{" "}
<div
className={cn("rf-flex rf-items-center rf-gap-2", headerClassName)}
className={cn(
"rf-flex rf-items-center rf-gap-2 rf-sticky rf-top-2 rf-z-50 rf-bg-white/90 rf-p-2 rf-rounded-lg rf-shadow-sm",
headerClassName,
)}
>
{leftHeaderContent}
{leftHeaderContent && <div className="rf-flex-grow" />}
Expand Down Expand Up @@ -318,7 +322,6 @@ export const CircuitJsonPreview = ({
</ErrorBoundary>
</div>
</TabsContent>

<TabsContent value="assembly">
<div
className={cn(
Expand Down Expand Up @@ -367,7 +370,6 @@ export const CircuitJsonPreview = ({
</ErrorBoundary>
</div>
</TabsContent>

<TabsContent value="cad">
<div
className={cn(
Expand All @@ -384,7 +386,6 @@ export const CircuitJsonPreview = ({
</ErrorBoundary>
</div>
</TabsContent>

<TabsContent value="bom">
<div
className={cn(
Expand Down
43 changes: 42 additions & 1 deletion lib/components/RunFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createCircuitWebWorker } from "@tscircuit/eval-webworker"
import { CircuitJsonPreview, type TabId } from "./CircuitJsonPreview"
import { useEffect, useMemo, useReducer, useRef, useState } from "react"
import Debug from "debug"
import { Loader2, Play } from "lucide-react"
import { Loader2, Play, Maximize2, Minimize2 } from "lucide-react"

// TODO waiting for core PR: https://github.com/tscircuit/core/pull/489
// import { orderedRenderPhases } from "@tscircuit/core"
Expand Down Expand Up @@ -37,6 +37,11 @@ interface Props {
*/
showRunButton?: boolean

/**
* Whether to show the fullscreen toggle button
*/
showToggleFullScreen?: boolean

/**
* An optional left-side header, you can put a save button, a run button, or
* a title here.
Expand Down Expand Up @@ -112,6 +117,7 @@ export const RunFrame = (props: Props) => {
)
const lastRunCountTriggerRef = useRef(0)
const [isRunning, setIsRunning] = useState(false)
const [isFullscreen, setIsFullscreen] = useState(false)
const [renderLog, setRenderLog] = useState<RenderLog | null>(null)
const [activeTab, setActiveTab] = useState<TabId>(
props.defaultActiveTab ?? "pcb",
Expand Down Expand Up @@ -281,9 +287,21 @@ export const RunFrame = (props: Props) => {
return `cj-${Math.random().toString(36).substring(2, 15)}`
}, [circuitJson])

const toggleFullscreen = () => {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen()
setIsFullscreen(true)
} else {
document.exitFullscreen()
setIsFullscreen(false)
}
}

return (
<CircuitJsonPreview
defaultActiveTab={props.defaultActiveTab}
onToggleFullScreen={toggleFullscreen}
isFullScreen={isFullscreen}
leftHeaderContent={
<>
{props.showRunButton && (
Expand All @@ -303,6 +321,29 @@ export const RunFrame = (props: Props) => {
)}
</button>
)}
{props.showToggleFullScreen && (
<div className="rf-flex rf-items-center rf-gap-2">
<button
type="button"
onClick={() => {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen()
setIsFullscreen(true)
} else {
document.exitFullscreen()
setIsFullscreen(false)
}
}}
className="rf-flex rf-items-center rf-gap-2 rf-px-2 rf-py-2 rf-text-zinc-900 rf-rounded-md rf-bg-white hover:rf-bg-zinc-100"
>
{isFullscreen ? (
<Minimize2 className="rf-w-4 rf-h-4" />
) : (
<Maximize2 className="rf-w-4 rf-h-4" />
)}
</button>
</div>
)}
{props.leftHeaderContent}
</>
}
Expand Down
Loading
Loading