Skip to content

Commit bc89444

Browse files
authored
Merge pull request #110 from HyperloopUPV-H8/ethernet-view/split-pane-logic
[ethernet-view] Collapsible elements
2 parents e2308c5 + d74829f commit bc89444

14 files changed

Lines changed: 148 additions & 65 deletions

File tree

backend/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Backend-H8
1111
backend
1212
!build
1313
# MacOS build
14-
cmd
14+
cmd/cmd
15+
cmd/logger/
1516

1617
# EXCEL
1718
*.xlsx
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

ethernet-view/src/hooks/useSplit/useSplit.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ function getAffectedAndUnaffectedElements(
171171

172172
function getNewMainElement(
173173
mainElement: SplitElement,
174-
shrinkedElements: SplitElement[]
174+
elements: SplitElement[]
175175
): SplitElement {
176176
const mainElementLength =
177177
1 -
178-
shrinkedElements.reduce((prevValue, currentElement) => {
178+
elements.reduce((prevValue, currentElement) => {
179179
return prevValue + currentElement.length;
180180
}, 0);
181181

@@ -195,10 +195,8 @@ function substractDisplacement(
195195
let remaindingDistance = Math.abs(distance);
196196

197197
for (let i = 0; i < orderedElements.length; i++) {
198-
const newLength = Math.max(
199-
orderedElements[i].length - remaindingDistance,
200-
orderedElements[i].minLength
201-
);
198+
let newLength = orderedElements[i].length - remaindingDistance;
199+
if(newLength < orderedElements[i].minLength) newLength = 0;
202200
remaindingDistance = Math.max(
203201
remaindingDistance - (orderedElements[i].length - newLength),
204202
0

ethernet-view/src/layouts/SplitLayout/Component/Component.module.scss

Lines changed: 0 additions & 4 deletions
This file was deleted.

ethernet-view/src/layouts/SplitLayout/Component/Component.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@use "src/styles/styles";
2+
3+
.wrapper {
4+
min-width: 0;
5+
min-height: 0;
6+
}
7+
8+
.collapsed {
9+
padding: .6rem;
10+
background-color: styles.$base-color;
11+
border-radius: .8rem;
12+
}
13+
14+
.icon {
15+
width: 2rem;
16+
17+
img {
18+
filter: invert(1);
19+
width: 100%;
20+
color: white;
21+
}
22+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import styles from "layouts/SplitLayout/Pane/Pane.module.scss";
2+
3+
type Props = {
4+
component: React.ReactNode;
5+
normalizedLength: number;
6+
collapsedIcon: string;
7+
};
8+
9+
export const Pane = ({ component, normalizedLength, collapsedIcon }: Props) => {
10+
11+
const isCollapsed = normalizedLength === 0;
12+
13+
return (
14+
<div
15+
className={isCollapsed ? styles.collapsed : styles.wrapper}
16+
style={{
17+
flex: normalizedLength,
18+
}}
19+
>
20+
<div className={styles.icon} style={{
21+
display: isCollapsed ? "block" : "none"
22+
}}>
23+
<img src={collapsedIcon} alt="collapsed" />
24+
</div>
25+
26+
<div style={isCollapsed ? {display: "none"} : {height: "100%"}}>
27+
{component}
28+
</div>
29+
30+
</div>
31+
);
32+
};

ethernet-view/src/layouts/SplitLayout/SplitLayout.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React from "react";
22
import styles from "layouts/SplitLayout/SplitLayout.module.scss";
33
import { useSplit } from "hooks/useSplit/useSplit";
4-
import { Component } from "layouts/SplitLayout/Component/Component";
4+
import { Pane } from "layouts/SplitLayout/Pane/Pane";
55
import { Separator } from "layouts/SplitLayout/Separator/Separator";
66
import { Orientation } from "hooks/useSplit/Orientation";
77

88
type Props = {
9-
components: React.ReactNode[];
9+
components: {
10+
component: React.ReactNode;
11+
collapsedIcon: string;
12+
}[];
1013
orientation?: Orientation;
1114
};
1215

@@ -15,7 +18,7 @@ export const SplitLayout = ({
1518
components,
1619
orientation = Orientation.HORIZONTAL,
1720
}: Props) => {
18-
const minSizes = components.map(() => 0.2);
21+
const minSizes = components.map(() => 0.05);
1922
const [splitElements, onSeparatorMouseDown] = useSplit(
2023
minSizes,
2124
orientation
@@ -32,9 +35,10 @@ export const SplitLayout = ({
3235
{components.map((component, index) => {
3336
return (
3437
<React.Fragment key={index}>
35-
<Component
36-
component={component}
38+
<Pane
39+
component={component.component}
3740
normalizedLength={splitElements[index].length}
41+
collapsedIcon={component.collapsedIcon}
3842
/>
3943
{index < components.length - 1 && (
4044
<Separator

0 commit comments

Comments
 (0)