File tree Expand file tree Collapse file tree 2 files changed +17
-36
lines changed Expand file tree Collapse file tree 2 files changed +17
-36
lines changed Original file line number Diff line number Diff line change 11/* eslint-disable @typescript-eslint/no-explicit-any */
22import React from "react" ;
33
4- import { Sandpack } from "./" ;
4+ import {
5+ SandpackCodeEditor ,
6+ SandpackFileExplorer ,
7+ SandpackLayout ,
8+ SandpackProvider ,
9+ } from "./" ;
510
611export default {
712 title : "Intro/Playground" ,
@@ -10,28 +15,12 @@ export default {
1015export const Basic : React . FC = ( ) => {
1116 return (
1217 < div style = { { height : "400vh" } } >
13- < Sandpack
14- options = { {
15- showTabs : true ,
16- closableTabs : true ,
17- experimental_enableServiceWorker : true ,
18- experimental_enableStableServiceWorkerId : true ,
19- } }
20- // customSetup={{
21- // dependencies: {
22- // "react-content-loader": "latest",
23- // "radix-ui": "latest",
24- // "styled-components": "latest",
25- // "react-dom": "latest",
26- // react: "latest",
27- // "react-table": "latest",
28- // },
29- // }}
30- // options={{
31- // bundlerURL: "https://ymxnqs-3000.csb.app",
32- // }}
33- template = "react"
34- />
18+ < SandpackProvider >
19+ < SandpackLayout >
20+ < SandpackFileExplorer />
21+ < SandpackCodeEditor closableTabs showTabs />
22+ </ SandpackLayout >
23+ </ SandpackProvider >
3524 </ div >
3625 ) ;
3726} ;
Original file line number Diff line number Diff line change @@ -96,18 +96,6 @@ export const FileTabs = ({
9696 const { activeFile, visibleFiles, setActiveFile } = sandpack ;
9797 const [ hoveredIndex , setIsHoveredIndex ] = React . useState < null | number > ( null ) ;
9898
99- const handleCloseFile = ( ev : React . MouseEvent < HTMLDivElement > ) : void => {
100- ev . stopPropagation ( ) ;
101- const tabElm = ( ev . target as HTMLElement ) . closest (
102- "[data-active]"
103- ) as HTMLElement ;
104- const pathToClose = tabElm ?. getAttribute ( "title" ) ;
105- if ( ! pathToClose ) {
106- return ;
107- }
108- sandpack . closeFile ( pathToClose ) ;
109- } ;
110-
11199 const getTriggerText = ( currentPath : string ) : string => {
112100 const documentFileName = getFileName ( currentPath ) ;
113101
@@ -224,7 +212,11 @@ export const FileTabs = ({
224212 { closableTabs && visibleFiles . length > 1 && (
225213 < span
226214 className = { classNames ( "close-button" , [ closeButtonClassName ] ) }
227- onClick = { handleCloseFile }
215+ onClick = { ( ev ) => {
216+ ev . stopPropagation ( ) ;
217+
218+ sandpack . closeFile ( filePath ) ;
219+ } }
228220 style = { {
229221 visibility :
230222 filePath === activeFile || hoveredIndex === index
You can’t perform that action at this time.
0 commit comments