Prefer rem, assure that dialogs scale correctly.
This commit is contained in:
@@ -24,7 +24,6 @@ const modalPosition = ref({ x: 0, y: 0 })
|
||||
const dialogWidth = ref(null)
|
||||
const dialogHeight = ref(null)
|
||||
const hasMoved = ref(false)
|
||||
const margin = 8 // viewport margin in px to keep dialog from touching edges
|
||||
|
||||
// Collect incoming non-prop attributes (e.g., class / style from usage site)
|
||||
const attrs = useAttrs()
|
||||
@@ -62,8 +61,8 @@ function handleDrag(event) {
|
||||
const h = dialogHeight.value || modalRef.value?.offsetHeight || 0
|
||||
const vw = window.innerWidth
|
||||
const vh = window.innerHeight
|
||||
x = clamp(x, margin, Math.max(margin, vw - w - margin))
|
||||
y = clamp(y, margin, Math.max(margin, vh - h - margin))
|
||||
x = clamp(x, 0, Math.max(0, vw - w - 0))
|
||||
y = clamp(y, 0, Math.max(0, vh - h - 0))
|
||||
modalPosition.value = { x, y }
|
||||
event.preventDefault()
|
||||
}
|
||||
@@ -97,10 +96,14 @@ const modalStyle = computed(() => {
|
||||
// <BaseDialog class="settings-modal" :style="{ top: '...' }" /> works even with fragment root.
|
||||
const modalAttrs = computed(() => {
|
||||
const { class: extClass, style: extStyle, ...rest } = attrs
|
||||
// When dialog has been moved (dragged), internal positioning styles must override external ones
|
||||
const mergedStyle = hasMoved.value
|
||||
? [extStyle, modalStyle.value].filter(Boolean)
|
||||
: [modalStyle.value, extStyle].filter(Boolean)
|
||||
return {
|
||||
...rest,
|
||||
class: ['ec-modal', extClass].filter(Boolean),
|
||||
style: [modalStyle.value, extStyle].filter(Boolean), // external style overrides internal
|
||||
style: mergedStyle,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -120,7 +123,8 @@ function positionNearAnchor() {
|
||||
const anchor = props.anchorEl || anchorRef.value
|
||||
if (!anchor) return
|
||||
const rect = anchor.getBoundingClientRect()
|
||||
const offsetY = 8 // vertical gap below the anchor
|
||||
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize)
|
||||
const offsetY = 0.5 * rootFontSize // vertical gap below the anchor in rem converted to pixels
|
||||
const w = modalRef.value?.offsetWidth || dialogWidth.value || 320
|
||||
const h = modalRef.value?.offsetHeight || dialogHeight.value || 200
|
||||
const vw = window.innerWidth
|
||||
@@ -128,8 +132,8 @@ function positionNearAnchor() {
|
||||
let x = rect.left
|
||||
let y = rect.bottom + offsetY
|
||||
// If anchor is wider than dialog and would overflow right edge, clamp; otherwise keep left align
|
||||
x = clamp(x, margin, Math.max(margin, vw - w - margin))
|
||||
y = clamp(y, margin, Math.max(margin, vh - h - margin))
|
||||
x = clamp(x, 0, Math.max(0, vw - w - 0))
|
||||
y = clamp(y, 0, Math.max(0, vh - h - 0))
|
||||
modalPosition.value = { x, y }
|
||||
}
|
||||
|
||||
@@ -172,8 +176,8 @@ function handleResize() {
|
||||
const vw = window.innerWidth
|
||||
const vh = window.innerHeight
|
||||
modalPosition.value = {
|
||||
x: clamp(modalPosition.value.x, margin, Math.max(margin, vw - w - margin)),
|
||||
y: clamp(modalPosition.value.y, margin, Math.max(margin, vh - h - margin)),
|
||||
x: clamp(modalPosition.value.x, 0, Math.max(0, vw - w - 0)),
|
||||
y: clamp(modalPosition.value.y, 0, Math.max(0, vh - h - 0)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,12 +216,12 @@ onUnmounted(() => {
|
||||
background: color-mix(in srgb, var(--panel) 85%, transparent);
|
||||
backdrop-filter: blur(0.625em);
|
||||
color: var(--ink);
|
||||
border-radius: 0.6em;
|
||||
min-height: 23em;
|
||||
min-width: 26em;
|
||||
max-width: min(34em, 90vw);
|
||||
box-shadow: 0 0.6em 1.8em rgba(0, 0, 0, 0.35);
|
||||
border: 0.0625em solid color-mix(in srgb, var(--muted) 40%, transparent);
|
||||
border-radius: 0.6rem;
|
||||
min-height: 23rem;
|
||||
min-width: 26rem;
|
||||
max-width: min(34rem, 90vw);
|
||||
box-shadow: 0 0.6rem 1.8rem rgba(0, 0, 0, 0.35);
|
||||
border: 0.0625rem solid color-mix(in srgb, var(--muted) 40%, transparent);
|
||||
z-index: 1000;
|
||||
overflow: hidden;
|
||||
}
|
||||
@@ -229,35 +233,35 @@ onUnmounted(() => {
|
||||
.ec-form {
|
||||
display: grid;
|
||||
grid-template-rows: auto 1fr auto;
|
||||
min-height: 23em;
|
||||
min-height: 23rem;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
.ec-header {
|
||||
cursor: move;
|
||||
user-select: none;
|
||||
padding: 0.75em 1em 0.5em 1em;
|
||||
padding: 0.75rem 1rem 0.5rem 1rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 1em;
|
||||
gap: 1rem;
|
||||
}
|
||||
.ec-title {
|
||||
margin: 0;
|
||||
font-size: 1.1em;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
.ec-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1em;
|
||||
padding: 0 1em 0.5em 1em;
|
||||
gap: 1rem;
|
||||
padding: 0 1rem 0.5rem 1rem;
|
||||
overflow: auto;
|
||||
}
|
||||
.ec-footer {
|
||||
padding: 0.5em 1em 1em 1em;
|
||||
padding: 0.5rem 1rem 1rem 1rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1em;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user