Skip to content

Commit

Permalink
Resizable elements window
Browse files Browse the repository at this point in the history
Allows to drag the divider between the preview and
elements windows in order to resize the elements window.

This is very helpful, if the elements window is too narrow when
lots of nested elements exist.
  • Loading branch information
tvdeyen committed Nov 29, 2024
1 parent 095a9fa commit 5e510e5
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 43 deletions.
2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/admin.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/admin.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/custom-properties.css

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

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/custom-properties.css.map

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

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/welcome.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/welcome.css.map

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

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

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

18 changes: 18 additions & 0 deletions app/javascript/alchemy_admin/components/elements_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SortableElements from "alchemy_admin/sortable_elements"

class ElementsWindow extends HTMLElement {
#visible = true
#turboFrame = null

constructor() {
super()
Expand Down Expand Up @@ -42,13 +43,18 @@ class ElementsWindow extends HTMLElement {

hide() {
document.body.classList.remove("elements-window-visible")
document.body.style.removeProperty("--elements-window-width")
this.#visible = false
this.toggleButton.closest("sl-tooltip").content = Alchemy.t("Show elements")
this.toggleButton
.querySelector("alchemy-icon")
.setAttribute("name", "menu-fold")
}

resize(width) {
document.body.style.setProperty("--elements-window-width", `${width}px`)
}

get collapseButton() {
return this.querySelector("#collapse-all-elements-button")
}
Expand All @@ -61,6 +67,18 @@ class ElementsWindow extends HTMLElement {
return document.getElementById("alchemy_preview_window")
}

get turboFrame() {
if (!this.#turboFrame) {
this.#turboFrame = this.closest("turbo-frame")
}
return this.#turboFrame
}

set isDragged(dragged) {
this.turboFrame.style.transitionProperty = dragged ? "none" : null
this.turboFrame.style.pointerEvents = dragged ? "none" : null
}

#attachEvents() {
this.collapseButton?.addEventListener("click", () => {
this.collapseAllElements()
Expand Down
Loading

0 comments on commit 5e510e5

Please sign in to comment.