Skip to content

Instantly share code, notes, and snippets.

@KonnorRogers
Created October 10, 2025 22:42
Show Gist options
  • Save KonnorRogers/541bd57560a9d7060f3603ccbad54edb to your computer and use it in GitHub Desktop.
Save KonnorRogers/541bd57560a9d7060f3603ccbad54edb to your computer and use it in GitHub Desktop.
full screen dialog
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<script data-fa-kit-code="38c11e3f20" type="module" src="https://early.webawesome.com/[email protected]/dist/webawesome.loader.js"></script>
<link rel="stylesheet" href="https://early.webawesome.com/[email protected]/dist/styles/webawesome.css">
<script type="module">
const dialog = document.querySelector("#draggable-dialog")
// not supported in Chrome 140, but supported in FF 143
// const getInnerDialog = () => dialog.shadowRoot.querySelector("::part(dialog)")
const getInnerDialog = () => dialog.shadowRoot.querySelector("[part~='dialog']")
let pointerId = null
dialog.addEventListener("pointerdown", startDrag)
dialog.addEventListener("pointerup", stopDrag)
dialog.addEventListener("pointermove", drag)
let pointerdownTimeout = null
let dragDelay = 200
let innerDialog = null
let isDragging = false;
let offsetX = null
let offsetY = null
function startDrag(e) {
if (pointerdownTimeout) { clearTimeout(pointerdownTimeout) }
pointerdownTimeout = setTimeout(() => {
isDragging = true;
innerDialog = getInnerDialog()
const clientRect = innerDialog.getBoundingClientRect()
offsetX = e.clientX - clientRect.x;
offsetY = e.clientY - clientRect.y;
const newX = e.clientX - offsetX;
const newY = e.clientY - offsetY;
dialog.style.setProperty("--left", `${newX}px`);
dialog.style.setProperty("--right", `unset`)
dialog.style.setProperty("--top", `${newY}px`);
dialog.style.setProperty("--bottom", `unset`);
dialog.setPointerCapture(e.pointerId)
}, dragDelay)
}
function stopDrag(e) {
isDragging = false
if (pointerdownTimeout) {
clearTimeout(pointerdownTimeout)
}
try {
dialog.releasePointerCapture(e.pointerId)
} catch (_e) { /** not a big deal. */ }
}
function drag(e) {
if (!isDragging) { return }
const newX = e.clientX - offsetX;
const newY = e.clientY - offsetY;
dialog.style.setProperty("--left", `${newX}px`);
dialog.style.setProperty("--top", `${newY}px`);
}
const fullScreenButton = document.querySelector("#full-screen-button")
fullScreenButton.addEventListener("click", () => {
innerDialog = getInnerDialog()
// dialog sets a max-height of: calc(100vh - var(--wa-space-2xl)) and the same for max-width.
innerDialog.style.height = "100vh"
innerDialog.style.width = "100vw"
dialog.style.setProperty("--left", `calc(var(--wa-space-2xl) / 2)`);
dialog.style.setProperty("--right", `unset`)
dialog.style.setProperty("--top", `calc(var(--wa-space-2xl) / 2)`);
dialog.style.setProperty("--bottom", `unset`);
})
</script>
<style>
#draggable-dialog {
position: absolute;
&::part(dialog) {
margin: 0;
bottom: var(--bottom, 0);
right: var(--right, 0);
top: var(--top, unset);
left: var(--left, unset);
}
}
</style>
<main style="padding: 4rem;">
<wa-button data-dialog="open draggable-dialog">Open Draggable Window</wa-button>
</main>
<!-- set draggable="true" and break everything. -->
<wa-dialog
id="draggable-dialog"
>
<wa-button id="full-screen-button">Make Full Screen</wa-button>
<wa-input label="To"></wa-input>
<wa-divider></wa-divider>
<wa-input label="cc"></wa-input>
<wa-divider></wa-divider>
<wa-textarea label="Message"></wa-textarea>
</wa-dialog>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment