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: make panels resizable #623

Merged
merged 8 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
18 changes: 18 additions & 0 deletions packages/@dcl/inspector/package-lock.json

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

1 change: 1 addition & 0 deletions packages/@dcl/inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"react-dom": "^18.2.0",
"react-icons": "^4.7.1",
"react-modal": "^3.16.1",
"react-resizable-panels": "^0.0.48",
"typescript": "^5.0.2"
},
"files": [
Expand Down
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;
}
65 changes: 44 additions & 21 deletions packages/@dcl/inspector/src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import { PanelGroup, Panel, PanelResizeHandle } from 'react-resizable-panels'

import { EntityInspector } from '../EntityInspector'
import { Hierarchy } from '../Hierarchy'
Expand All @@ -7,31 +8,53 @@ import { Box } from '../Box'
import { Toolbar } from '../Toolbar'

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 48 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 = (48 / height!) * 100

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 @@ -14,11 +13,11 @@ import ImportAsset from '../ImportAsset'
import './Assets.css'

function Assets() {
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 @@ -29,7 +28,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 @@ -49,14 +48,12 @@ function Assets() {
</div>
</div>
</div>
{tab && (
<div className="Assets-content">
{tab === AssetsTab.AssetsPack && <AssetsCatalog />}
{tab === AssetsTab.FileSystem && <ProjectAssetExplorer onImportAsset={handleTabClick(AssetsTab.Import)} />}
{tab === AssetsTab.Import && <ImportAsset onSave={handleSave} />}
</div>
)}
</Box>
<div className="Assets-content">
{tab === AssetsTab.AssetsPack && <AssetsCatalog />}
{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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { FiHexagon } from 'react-icons/fi'
import { ROOT } from '../../lib/sdk/tree'
import { useSelectedEntity } from '../../hooks/sdk/useSelectedEntity'
import { useTree } from '../../hooks/sdk/useTree'
import { Container } from '../Container'
import { Tree } from '../Tree'
import { ContextMenu } from './ContextMenu'
import './Hierarchy.css'

function HierarchyIcon({ value, hasChildrens, isOpen }: { value: Entity; hasChildrens: boolean; isOpen: boolean }) {
if (value === ROOT) {
Expand Down Expand Up @@ -45,7 +45,7 @@ const Hierarchy: React.FC = () => {
[selectedEntity]
)
return (
<Container>
<div className="Hierarchy">
<EntityTree
value={ROOT}
getExtraContextMenu={ContextMenu}
Expand All @@ -65,7 +65,7 @@ const Hierarchy: React.FC = () => {
canRename={canRename}
canRemove={canRemove}
/>
</Container>
</div>
)
}

Expand Down
30 changes: 0 additions & 30 deletions packages/@dcl/inspector/src/components/Resizable/Resizable.css

This file was deleted.

Loading