-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters