Skip to content

Commit

Permalink
feat: make panels resizable
Browse files Browse the repository at this point in the history
  • Loading branch information
cazala committed Jun 1, 2023
1 parent 8fed9cd commit b7e147f
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 198 deletions.
32 changes: 20 additions & 12 deletions packages/@dcl/inspector/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/@dcl/inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
"start": "node ./build.js --watch"
},
"types": "dist/tooling-entrypoint.d.ts",
"typings": "dist/tooling-entrypoint.d.ts"
"typings": "dist/tooling-entrypoint.d.ts",
"dependencies": {
"react-resizable-panels": "^0.0.48"
}
}
15 changes: 14 additions & 1 deletion packages/@dcl/inspector/src/components/App/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ code {
display: flex;
flex-direction: column;
width: 100%;
height: 100vh;
height: 100%;
background: var(--main-bg-color);
}

Expand All @@ -54,3 +54,16 @@ code {
top: -30px;
position: absolute !important;
}

.App {
width: 100%;
height: 100%;
}

.App .horizontal-handle {
width: 4px;
}

.App .vertical-handle {
height: 4px;
}
69 changes: 47 additions & 22 deletions packages/@dcl/inspector/src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,62 @@
import React from 'react'
import React, { useRef } from 'react'

import { EntityInspector } from '../EntityInspector'
import { Hierarchy } from '../Hierarchy'
import { Renderer } from '../Renderer'
import { Box } from '../Box'
import { Toolbar } from '../Toolbar'
import { PanelGroup, Panel, PanelResizeHandle, ImperativePanelHandle } from 'react-resizable-panels'

import './App.css'
import { Resizable } from '../Resizable'
import Assets from '../Assets'
import { useSelectedEntity } from '../../hooks/sdk/useSelectedEntity'
import { useWindowSize } from '../../hooks/useWindowSize'

const App = () => {
const selectedEntity = useSelectedEntity()

const { height } = useWindowSize()

// Footer's height is 36 pixels, so we need to calculate the percentage of the screen that it takes to pass as the minSize prop for the Panel
const footerMin = (50 / height!) * 100

console.log(footerMin)

return (
<Resizable type="horizontal" min={300} initial={300}>
<Box>
<div
className="sidebar"
data-vscode-context='{"webviewSection": "sidebar", "preventDefaultContextMenuItems": true}'
>
<Resizable type="vertical" min={130} initial={130} max={730}>
<Hierarchy />
<EntityInspector />
</Resizable>
</div>
</Box>
<div className="editor">
<Box className="composite-renderer">
<Toolbar />
<Renderer />
</Box>
<Assets />
</div>
</Resizable>
<div className="App">
<PanelGroup direction="vertical" autoSaveId="vertical">
<Panel>
<PanelGroup direction="horizontal" autoSaveId="horizontal">
<Panel defaultSize={20} minSize={12} order={1}>
<Box className="composite-inspector">
<Hierarchy />
</Box>
</Panel>
<PanelResizeHandle className="horizontal-handle" />
<Panel minSize={30} order={2}>
<Box className="composite-renderer">
<Toolbar />
<Renderer />
</Box>
</Panel>
<PanelResizeHandle className="horizontal-handle" />
{selectedEntity !== null && (
<Panel defaultSize={20} minSize={15} order={3}>
<Box className="entity-inspector">
<EntityInspector />
</Box>
</Panel>
)}
</PanelGroup>
</Panel>
<PanelResizeHandle className="vertical-handle" />
<Panel minSize={footerMin} defaultSize={30}>
<Box className="composite-renderer">
<Assets />
</Box>
</Panel>
</PanelGroup>
</div>
)
}

Expand Down
7 changes: 5 additions & 2 deletions packages/@dcl/inspector/src/components/Assets/Assets.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
display: flex;
flex-direction: column;
flex: none;
width: 100%;
height: 100%;
overflow: hidden;
}

.Assets .Assets-buttons span {
Expand Down Expand Up @@ -62,5 +65,5 @@

.Assets .Assets-content {
background: var(--tree-bg-color) !important;
height: 250px !important;
}
height: calc(100% - 36px);
}
21 changes: 9 additions & 12 deletions packages/@dcl/inspector/src/components/Assets/Assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useCallback, useState } from 'react'
import cx from 'classnames'

import { AssetsTab } from './types'
import { Box } from '../Box'
import { FolderOpen } from '../Icons/Folder'
import { MdImageSearch } from 'react-icons/md'
import { HiOutlinePlus } from 'react-icons/hi'
Expand All @@ -16,11 +15,11 @@ import './Assets.css'

function Assets() {
const [catalog] = useCatalog()
const [tab, setTab] = useState<AssetsTab | undefined>(undefined)
const [tab, setTab] = useState<AssetsTab>(AssetsTab.FileSystem)

const handleTabClick = useCallback(
(value: AssetsTab) => () => {
setTab(tab === value ? undefined : value)
setTab(value)
},
[tab]
)
Expand All @@ -31,7 +30,7 @@ function Assets() {
}, [])

return (
<Box className="Assets">
<div className="Assets">
<div className="Assets-buttons">
<div onClick={handleTabClick(AssetsTab.FileSystem)}>
<div className={cx({ underlined: tab === AssetsTab.FileSystem })}>
Expand All @@ -51,14 +50,12 @@ function Assets() {
</div>
</div>
</div>
{tab && (
<div className="Assets-content">
{tab === AssetsTab.AssetsPack && catalog && <AssetsCatalog value={catalog} />}
{tab === AssetsTab.FileSystem && <ProjectAssetExplorer onImportAsset={handleTabClick(AssetsTab.Import)} />}
{tab === AssetsTab.Import && <ImportAsset onSave={handleSave} />}
</div>
)}
</Box>
<div className="Assets-content">
{tab === AssetsTab.AssetsPack && catalog && <AssetsCatalog value={catalog} />}
{tab === AssetsTab.FileSystem && <ProjectAssetExplorer onImportAsset={handleTabClick(AssetsTab.Import)} />}
{tab === AssetsTab.Import && <ImportAsset onSave={handleSave} />}
</div>
</div>
)
}

Expand Down
5 changes: 5 additions & 0 deletions packages/@dcl/inspector/src/components/Box/Box.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.Box {
height: calc(100% - 4.8px);
}

.Box.with-border {
margin: 2.4px;
padding: 3.2px;
Expand All @@ -14,4 +18,5 @@
background: var(--main-bg-color);
width: 100%;
height: 100%;
position: relative;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
display: flex;
flex-direction: column;
padding: 12px;
background-color: var(--modal);
border-radius: 8px;
margin: 12px;
height: 100%;
overflow-y: auto;
border-bottom: 1px solid var(--border-gray);
}

.Container.hover {
Expand All @@ -27,10 +25,10 @@
margin-right: 4px;
}

.Container > span {
.Container>span {
margin: 0px 0px 4px 0px;
color: var(--text);
font-size: 14px;
font-weight: 600;
cursor: pointer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.EntityInspector {
position: absolute;
width: 100%;
height: 100%;
background-color: var(--tree-bg-color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSelectedEntity } from '../../hooks/sdk/useSelectedEntity'
import { SceneInspector } from './SceneInspector'
import { TransformInspector } from './TransformInspector'
import { GltfInspector } from './GltfInspector'
import './EntityInspector.css'

export const EntityInspector: React.FC = () => {
const entity = useSelectedEntity()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Hierarchy {
height: 100%;
background: var(--tree-bg-color);
}
Loading

0 comments on commit b7e147f

Please sign in to comment.