Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,36 @@ window.addEventListener('mave:clipcopy', (event) => {
}
})

// Development alignment grid: Ctrl+G toggles #dev-grid, which only renders
// when dev routes are enabled. The state survives page loads.
const DEV_GRID_KEY = "mave:dev-grid"

const readDevGrid = () => {
try {
return localStorage.getItem(DEV_GRID_KEY) === "on"
} catch (_error) {
return false
}
}

const applyDevGrid = () => {
const grid = document.getElementById("dev-grid")
if (grid) grid.hidden = !readDevGrid()
}

window.addEventListener("keydown", (event) => {
const grid = document.getElementById("dev-grid")
if (!grid || !event.ctrlKey || event.metaKey || event.altKey || event.key.toLowerCase() !== "g") return

event.preventDefault()
grid.hidden = !grid.hidden
try {
localStorage.setItem(DEV_GRID_KEY, grid.hidden ? "off" : "on")
} catch (_error) {}
})
window.addEventListener("phx:page-loading-stop", applyDevGrid)
applyDevGrid()

// The lines below enable quality of life phoenix_live_reload
// development features:
//
Expand Down
26 changes: 26 additions & 0 deletions lib/mave_core_web/components/layouts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@ defmodule MaveCoreWeb.Layouts do

embed_templates "layouts/*"

@doc """
Renders a development-only alignment grid overlay, toggled with Ctrl+G.

Renders nothing unless dev routes are enabled, so the overlay never ships
in production builds.
"""
if Application.compile_env(:mave_core, :dev_routes, false) do
def dev_grid(assigns) do
~H"""
<div
id="dev-grid"
aria-hidden="true"
hidden
class="pointer-events-none fixed inset-0 z-[9999]"
style="background-image: linear-gradient(to right, rgb(255 0 80 / 0.22) 1px, transparent 1px), linear-gradient(to bottom, rgb(255 0 80 / 0.22) 1px, transparent 1px), linear-gradient(to right, rgb(255 0 80 / 0.08) 1px, transparent 1px), linear-gradient(to bottom, rgb(255 0 80 / 0.08) 1px, transparent 1px); background-size: 32px 32px, 32px 32px, 8px 8px, 8px 8px;"
>
</div>
"""
end
else
def dev_grid(assigns) do
~H"""
"""
end
end

@doc """
Shows the flash group with standard titles and content.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
</head>
<body class="bg-white h-full overflow-hidden">
{@inner_content}
<.dev_grid />
</body>
</html>
1 change: 1 addition & 0 deletions lib/mave_core_web/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
</head>
<body>
{@inner_content}
<.dev_grid />
</body>
</html>
Loading