11/* Copyright 2024 Marimo. All rights reserved. */
22
33import { useAtomValue } from "jotai" ;
4- import React from "react" ;
4+ import { XIcon } from "lucide-react" ;
5+ import * as React from "react" ;
6+ import { Button } from "@/components/ui/button" ;
57import { useCellActions , useNotebook } from "@/core/cells/cells" ;
68import { cellFocusAtom , useCellFocusActions } from "@/core/cells/focus" ;
79import type { CellId } from "@/core/cells/ids" ;
810import { useVariables } from "@/core/variables/state" ;
911import type { VariableName } from "@/core/variables/types" ;
1012import { cn } from "@/utils/cn" ;
13+ import { useChromeActions , useChromeState } from "../state" ;
1114import {
1215 type CellGraph ,
1316 cellGraphsAtom ,
@@ -122,13 +125,14 @@ const MinimapCell: React.FC<MinimapCellProps> = (props) => {
122125 ) ;
123126} ;
124127
125- export const Minimap : React . FC < { className ?: string } > = ( { className } ) => {
128+ const MinimapInternal : React . FC < {
129+ open : boolean ;
130+ setOpen : ( update : boolean ) => void ;
131+ } > = ( { open, setOpen } ) => {
126132 const notebook = useNotebook ( ) ;
127-
128133 const cellPositions : Record < CellId , number > = Object . fromEntries (
129134 notebook . cellIds . inOrderIds . map ( ( id , idx ) => [ id , idx ] ) ,
130135 ) ;
131-
132136 const columnBoundaries : number [ ] = [ ] ;
133137 let cellCount = 0 ;
134138 for ( const [ idx , column ] of notebook . cellIds . getColumns ( ) . entries ( ) ) {
@@ -137,16 +141,24 @@ export const Minimap: React.FC<{ className?: string }> = ({ className }) => {
137141 }
138142 cellCount += column . inOrderIds . length ;
139143 }
140-
141144 return (
142145 < div
143146 className = { cn (
144- "fixed top-14 right-4 z-50 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 rounded-lg border shadow-lg w-64 flex flex-col max-h-[75vh]" ,
145- className ,
147+ "fixed top-14 right-5 z-50 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 rounded-lg border shadow-lg w-64 flex flex-col max-h-[58vh]" ,
148+ "motion-safe:transition-transform motion-safe:duration-200 motion-safe:ease-in-out" ,
149+ open ? "translate-x-0" : "translate-x-[calc(100%+20px)]" ,
146150 ) }
147151 >
148152 < div className = "flex items-center justify-between p-4 border-b" >
149153 < span className = "text-sm font-semibold" > Minimap</ span >
154+ < Button
155+ variant = "ghost"
156+ size = "icon"
157+ className = "h-6 w-6"
158+ onClick = { ( ) => setOpen ( false ) }
159+ >
160+ < XIcon className = "h-4 w-4" />
161+ </ Button >
150162 </ div >
151163 < div className = "overflow-y-auto overflow-x-hidden flex-1 scrollbar-none" >
152164 < div className = "py-3 pl-3 pr-4 relative min-h-full" >
@@ -173,6 +185,12 @@ export const Minimap: React.FC<{ className?: string }> = ({ className }) => {
173185 ) ;
174186} ;
175187
188+ export const Minimap : React . FC = ( ) => {
189+ const { setIsMinimapOpen } = useChromeActions ( ) ;
190+ const { isMinimapOpen } = useChromeState ( ) ;
191+ return < MinimapInternal open = { isMinimapOpen } setOpen = { setIsMinimapOpen } /> ;
192+ } ;
193+
176194function codePreview ( code : string ) : string | undefined {
177195 return code . split ( "\n" ) [ 0 ] . trim ( ) || undefined ;
178196}
0 commit comments