feat: More dynamic styling for placeholder
- Create global setAttributesAccordingToPosition - Change style of placeholder to show snap side
This commit is contained in:
parent
53897754e2
commit
a18b42bb2a
2 changed files with 53 additions and 21 deletions
|
|
@ -370,6 +370,18 @@ function centerElementUnderCursor(event, element) {
|
||||||
element.style.top = `${y}px`;
|
element.style.top = `${y}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setAttributesAccordingToPosition(element, position, attributes) {
|
||||||
|
element.classList.remove(...Object.values(attributes).map(pos => pos.className));
|
||||||
|
Object.keys(attributes[position].styles).forEach(key => {
|
||||||
|
element.style[key] = '';
|
||||||
|
});
|
||||||
|
|
||||||
|
element.classList.add(attributes[position].className);
|
||||||
|
Object.entries(attributes[position].styles).forEach(([key, value]) => {
|
||||||
|
element.style[key] = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// CONCEPTS
|
// CONCEPTS
|
||||||
|
|
||||||
// NOTE: Benutzt private Zuweisungen
|
// NOTE: Benutzt private Zuweisungen
|
||||||
|
|
|
||||||
|
|
@ -52,19 +52,47 @@ class HippieTaskBar {
|
||||||
if (!this.isDragging) return;
|
if (!this.isDragging) return;
|
||||||
|
|
||||||
const closestEdge = getClosestEdge(this.placeholder);
|
const closestEdge = getClosestEdge(this.placeholder);
|
||||||
|
const borderRadius = '16px';
|
||||||
switch (closestEdge) {
|
const attributes = {
|
||||||
case 'right':
|
top: {
|
||||||
case 'left':
|
styles: {
|
||||||
this.placeholder.style.flexDirection = 'column';
|
borderTopRightRadius: '',
|
||||||
break;
|
borderBottomRightRadius: borderRadius,
|
||||||
case 'top':
|
borderBottomLeftRadius: borderRadius,
|
||||||
case 'bottom':
|
borderTopLeftRadius: '',
|
||||||
default:
|
flexDirection: 'row'
|
||||||
this.placeholder.style.flexDirection = 'row';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
styles: {
|
||||||
|
borderTopRightRadius: '',
|
||||||
|
borderBottomRightRadius: '',
|
||||||
|
borderBottomLeftRadius: borderRadius,
|
||||||
|
borderTopLeftRadius: borderRadius,
|
||||||
|
flexDirection: 'column'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
styles: {
|
||||||
|
borderTopRightRadius: borderRadius,
|
||||||
|
borderBottomRightRadius: '',
|
||||||
|
borderBottomLeftRadius: '',
|
||||||
|
borderTopLeftRadius: borderRadius,
|
||||||
|
flexDirection: 'row'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
styles: {
|
||||||
|
borderTopRightRadius: borderRadius,
|
||||||
|
borderBottomRightRadius: borderRadius,
|
||||||
|
borderBottomLeftRadius: '',
|
||||||
|
borderTopLeftRadius: '',
|
||||||
|
flexDirection: 'column'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setAttributesAccordingToPosition(this.placeholder, closestEdge, attributes);
|
||||||
centerElementUnderCursor(event, this.placeholder);
|
centerElementUnderCursor(event, this.placeholder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -139,15 +167,7 @@ class HippieTaskBar {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.element.classList.remove(...Object.values(attributes).map(pos => pos.className));
|
setAttributesAccordingToPosition(this.element, position, attributes);
|
||||||
Object.keys(attributes[position].styles).forEach(key => {
|
|
||||||
this.element.style[key] = '';
|
|
||||||
});
|
|
||||||
|
|
||||||
this.element.classList.add(attributes[position].className);
|
|
||||||
Object.entries(attributes[position].styles).forEach(([key, value]) => {
|
|
||||||
this.element.style[key] = value;
|
|
||||||
});
|
|
||||||
|
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case 'right':
|
case 'right':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue