Skip to content

Commit

Permalink
✨ View Expander!
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCubiq committed Sep 1, 2022
1 parent 9a133f1 commit 3994d79
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 30 deletions.
81 changes: 66 additions & 15 deletions src/scripts/expandViews.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,76 @@
import Selectors from "../utils/selectors";

const addExpanders = () => {
const comp_header_btn = Selectors().panels[1];
const canExpand = (view_idx) => {
// returns array of sides that can be expanded
// 0 = left, 1 = right
// todo: better way to do this
const sides = [];
switch (view_idx) {
case 0:
sides.push(1);
break;
case 1:
sides.push(0);
sides.push(1);
break;
case 2:
sides.push(0);
break;
}
return sides;
}

const ExpanderBTN = (panel, side) => {
let button = document.createElement("span");
const sideName = side === 0 ? "left" : "right";´

// create a nice button
panel.addEventListener('transitionend', (event) => {
if (event.propertyName === (sideName)) {
// console.log('Animation ended: ', sideName);
panel.classList.remove("vz-animation");
}
});

button.addEventListener("click", () => {
panel.classList.add("vz-animation");
panel.classList.toggle(`vz-expanded-${sideName}`);
// remove animation class after animation is complete
// setTimeout(() => {
// panel.classList.remove("vz-animation");
// }, 2000);
});
button.classList.add(`vz-xpand-${sideName}`);
return button;
}

let comp_expander = document.createElement("div");
comp_expander.classList.add("vz-expander-comp");
const ExpanderHeader = (panel, idx) => {
let header = document.createElement("div");
header.classList.add("vz-expander-header");

let comp_expander_div = document.createElement("div");
comp_expander_div.classList.add("MuiButtonBase-root", "MuiIconButton-root");
comp_expander.appendChild(comp_expander_div);
let wrapper = document.createElement("div");
wrapper.classList.add("MuiButtonBase-root", "MuiIconButton-root");

let comp_expander_icon = document.createElement("span");
comp_expander_icon.addEventListener("click", () => {
comp_header_btn.classList.toggle("vz-expanded");
const expandedViews = canExpand(idx);
expandedViews.forEach((view) => {
let button = ExpanderBTN(panel, view);
wrapper.appendChild(button);
});

let icon_right = comp_expander_icon.cloneNode(true);
icon_right.classList.add("vz-xpand-right");
comp_expander_div.appendChild(icon_right);
comp_expander_div.appendChild(comp_expander_icon);
comp_header_btn.appendChild(comp_expander);

header.appendChild(wrapper);

return header;
}

const addExpanders = () => {
const panels = Selectors().panels;
console.log(panels);
panels.forEach((panel, i) => {
// we want to expand only top views (3)
if (i > 2) return;
panel.appendChild(ExpanderHeader(panel, i));
});
};

export default addExpanders;
59 changes: 44 additions & 15 deletions src/styles/expandViews.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.vz-expander-comp path {
/* Buttons */

.vz-expander-header path {
/* d: path("M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"); */
/* d: path("M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z");
d: path("M344.7 238.5l-144.1-136C193.7 95.97 183.4 94.17 174.6 97.95C165.8 101.8 160.1 110.4 160.1 120V192H32.02C14.33 192 0 206.3 0 224v64c0 17.68 14.33 32 32.02 32h128.1v72c0 9.578 5.707 18.25 14.51 22.05c8.803 3.781 19.03 1.984 26-4.594l144.1-136C354.3 264.4 354.3 247.6 344.7 238.5zM416 32h-64c-17.67 0-32 14.33-32 32s14.33 32 32 32h64c17.67 0 32 14.33 32 32v256c0 17.67-14.33 32-32 32h-64c-17.67 0-32 14.33-32 32s14.33 32 32 32h64c53.02 0 96-42.98 96-96V128C512 74.98 469 32 416 32z"); */
}

.vz-expander-comp {
.vz-expander-header {
height: 8px;
z-index: 1;
top: 0;
Expand All @@ -14,7 +16,7 @@
justify-content: center;
}

.vz-expander-comp > div {
.vz-expander-header > div {
opacity: 0.3;
background-color: var(--cubiq-accent-light) !important;
/* transition: all 0.3s; */
Expand All @@ -32,15 +34,14 @@
overflow: hidden;
}

.vz-expander-comp > div:hover {
.vz-expander-header > div:hover {
top: 0;
opacity: 1;
max-width: 100px;
box-shadow: var(--cubiq-accent-light) 0px -5px 15px;
}

.vz-expander-comp > div span {
content: url("data:image/svg+xml,%3Csvg xmlns='http:https://www.w3.org/2000/svg' class='MuiSvgIcon-root' focusable='false' viewBox='0 0 24 24' aria-hidden='true'%3E%3Cpath d='M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z' fill='white'%3E%3C/path%3E%3C/svg%3E");
.vz-expander-header > div span {
opacity: 0;
font-size: 1rem;
/* margin: 0 1px; */
Expand All @@ -49,24 +50,52 @@
z-index: 1;
/* position: absolute; */
left: -0.8em;
transition-property: opacity, filter;
transition-duration: 0.3s;
transition-delay: 0.6s, .0s;
transition-property: opacity, filter, transform;
transition-duration: 0.3s, 0.3s, 0.5s;
transition-delay: 0.6s, .0s, .0s;
filter:opacity(0.3);
}

.vz-expander-comp > div:hover span {
.vz-expander-header > div:hover span {
opacity: 1;
}

.vz-expander-comp span:hover {
.vz-expander-header span:hover {
filter:opacity(1);
}

.vz-expanded-left .vz-xpand-left,
.vz-expanded-right .vz-xpand-right {
transform: scaleX(-1);
}

.vz-xpand-left {
content: url("data:image/svg+xml,%3Csvg xmlns='http:https://www.w3.org/2000/svg' class='MuiSvgIcon-root' focusable='false' viewBox='0 0 24 24' aria-hidden='true'%3E%3Cpath d='M12 4l1.41 1.41L7.83 11H20v2h-12.17l5.58 5.59L12 20l-8-8z' fill='white'%3E%3C/path%3E%3C/svg%3E");
}

.vz-xpand-right {
transform: rotate(180deg);
content: url("data:image/svg+xml,%3Csvg xmlns='http:https://www.w3.org/2000/svg' class='MuiSvgIcon-root' focusable='false' viewBox='0 0 24 24' aria-hidden='true'%3E%3Cpath d='M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z' fill='white'%3E%3C/path%3E%3C/svg%3E");
/* transform: rotate(180deg); */
}


/* Expands */

.vz-animation {
transition: all 0.5s !important;
z-index: 10;
}

#root #editor-base .mosaic-root > .vz-expanded-right {
right: 0 !important;
z-index: 10;
}

#root #editor-base .mosaic-root > .vz-expanded-left {
left: 0 !important;
z-index: 2;
}

/* .vz-expander:hover {
height: 2em;
} */
#root #editor-base .mosaic-root > div:nth-child(7) {
z-index: 90;
}

0 comments on commit 3994d79

Please sign in to comment.