Skip to content

Commit

Permalink
style: add drag handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaviju committed Oct 7, 2024
1 parent 937ac3f commit f5b149b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions libs/plugins-runtime/src/lib/assets/resize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions libs/plugins-runtime/src/lib/create-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@ export function createModal(

const initialPosition = {
blockStart: 40,
inlineEnd: 320,
// To be able to resize the element as expected the position must be absolute from the right.
// This value is the length of the window minus the width of the element plus the width of the design tab.
inlineStart: window.innerWidth - defaultWidth - 270,
};

console.log(initialPosition.inlineStart);
console.log(window.innerWidth, defaultWidth);

modal.style.setProperty(
'--modal-block-start',
`${initialPosition.blockStart}px`
);
modal.style.setProperty(
'--modal-inline-end',
`${initialPosition.inlineEnd}px`
'--modal-inline-start',
`${initialPosition.inlineStart}px`
);

const maxWidth = window.innerWidth - initialPosition.inlineEnd;
const maxWidth = window.innerWidth - initialPosition.inlineStart;
const maxHeight = window.innerHeight - initialPosition.blockStart;
let width = Math.min(options?.width || defaultWidth, maxWidth);
let height = Math.min(options?.height || defaultHeight, maxHeight);
Expand Down
2 changes: 1 addition & 1 deletion libs/plugins-runtime/src/lib/drag-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const dragHandler = (el: HTMLElement, target: HTMLElement = el, move?: ()

currentTranslate = { x: deltaX, y: deltaY };

target.style.transform = `translate(${deltaX}px, ${deltaY}px) scale(-1, 1)`;
target.style.transform = `translate(${deltaX}px, ${deltaY}px)`;

move?.();
};
Expand Down
28 changes: 23 additions & 5 deletions libs/plugins-runtime/src/lib/modal/plugin.modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@
color: var(--color-foreground-secondary);
}

::-webkit-resizer {
display: none;
/* background-image: url('../assets/resize.svg');
position: relative;
inset-block-end: 10px;
inset-inline-end: 10px; */
}

.wrapper {
box-sizing: border-box;
display: flex;
flex-direction: column;
position: absolute;
inset-block-start: var(--modal-block-start);
inset-inline-end: var(--modal-inline-end);
inset-inline-start: var(--modal-inline-start);
z-index: 1000;
padding: 10px;
border-radius: 15px;
Expand All @@ -41,13 +49,23 @@
min-inline-size: 25px;
min-block-size: 200px;
resize: both;
transform: scale(-1, 1);
cursor: se-resize;
&:after {
content: '';
inline-size: 1rem;
block-size: 1rem;
background-image: url('../assets/resize.svg');
background-position: center;
right: 5px;
bottom: 5px;
pointer-events: none;
position: absolute;
}
}

.inner {
padding: 10px;
cursor:grab;
transform: scale(-1, 1);
padding: 10px;
cursor: grab;
}

.header {
Expand Down

0 comments on commit f5b149b

Please sign in to comment.