Frontend: Fixed sidebar being visible for a second on mobile. Tooltips now can be shown from bottom or top depending on where it can be displayed.
This commit is contained in:
parent
7e61cee8ca
commit
7f9cee5798
3 changed files with 59 additions and 31 deletions
|
@ -1,4 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
|
import { afterUpdate } from "svelte";
|
||||||
import SvgIcon from "@jamescoyle/svelte-icon";
|
import SvgIcon from "@jamescoyle/svelte-icon";
|
||||||
import "$lib/css/pill.css";
|
import "$lib/css/pill.css";
|
||||||
import { mdiHelp, mdiPlus } from "@mdi/js";
|
import { mdiHelp, mdiPlus } from "@mdi/js";
|
||||||
|
@ -14,48 +15,68 @@
|
||||||
export let tooltip_data = [];
|
export let tooltip_data = [];
|
||||||
|
|
||||||
const white = shouldColorBeWhite(color.slice(1));
|
const white = shouldColorBeWhite(color.slice(1));
|
||||||
let style;
|
let style =
|
||||||
let pill_arrow;
|
shadow_color === null
|
||||||
|
? `background-color: ${color};
|
||||||
|
box-shadow: 0px 8px 18px -1px ${color}60;`
|
||||||
|
: `background-color: ${color};
|
||||||
|
box-shadow: 0px 8px 18px -1px ${shadow_color}60;`;
|
||||||
|
|
||||||
|
// pill elements from DOM
|
||||||
|
let pill_arrowup;
|
||||||
|
let pill_arrowdown;
|
||||||
let pill_tooltip;
|
let pill_tooltip;
|
||||||
let main_pill;
|
let main_pill;
|
||||||
let innerWidth;
|
|
||||||
|
|
||||||
if (shadow_color === null) {
|
// constants and variables
|
||||||
style = `background-color: ${color};
|
let innerWidth;
|
||||||
box-shadow: 0px 8px 18px -1px ${color}60;`;
|
let scrollY;
|
||||||
} else {
|
let offsetUp;
|
||||||
style = `background-color: ${color};
|
|
||||||
box-shadow: 0px 8px 18px -1px ${shadow_color}60;`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function showingTooltip(visible) {
|
function showingTooltip(visible) {
|
||||||
|
// outofbound for left
|
||||||
|
const isOutofBoundLeft =
|
||||||
|
main_pill.offsetLeft + main_pill.offsetWidth / 2 <
|
||||||
|
pill_tooltip.offsetWidth / 2;
|
||||||
|
// outofbound for right
|
||||||
|
const isOutofBoundRight =
|
||||||
|
pill_tooltip.offsetLeft + pill_tooltip.offsetWidth > innerWidth;
|
||||||
|
|
||||||
// Showing tooltip
|
// Showing tooltip
|
||||||
const isOutofBoundLeft=(main_pill.offsetLeft+(main_pill.offsetWidth/2)<(pill_tooltip.offsetWidth/2));
|
|
||||||
const isOutofBoundRight=((pill_tooltip.offsetLeft+pill_tooltip.offsetWidth)>innerWidth);
|
|
||||||
if (visible && tooltip_data.length > 0) {
|
if (visible && tooltip_data.length > 0) {
|
||||||
pill_tooltip.style.visibility = "visible";
|
// forcing left or right depending on the out of bound situation
|
||||||
pill_arrow.style.visibility = "visible";
|
if (isOutofBoundLeft) {
|
||||||
if(isOutofBoundLeft)
|
|
||||||
{
|
|
||||||
pill_tooltip.style.left = "0";
|
pill_tooltip.style.left = "0";
|
||||||
}
|
}
|
||||||
if(isOutofBoundRight)
|
if (isOutofBoundRight) {
|
||||||
{
|
|
||||||
pill_tooltip.style.right = "0";
|
pill_tooltip.style.right = "0";
|
||||||
}
|
}
|
||||||
pill_tooltip.style.top = `${
|
// Setting the top size depending on the situation
|
||||||
main_pill.offsetTop - pill_tooltip.offsetHeight - 16
|
if (scrollY > offsetUp) {
|
||||||
}px`;
|
// 51 represents the size of the pill
|
||||||
|
pill_tooltip.style.top = `${main_pill.offsetTop + 51 + 16}px`;
|
||||||
|
pill_arrowdown.style.visibility = "visible";
|
||||||
|
} else {
|
||||||
|
pill_tooltip.style.top = `${offsetUp}px`;
|
||||||
|
pill_arrowup.style.visibility = "visible";
|
||||||
|
}
|
||||||
|
pill_tooltip.style.visibility = "visible";
|
||||||
}
|
}
|
||||||
// Hiding tooltip
|
// Hiding tooltip
|
||||||
else {
|
else {
|
||||||
pill_tooltip.style.visibility = "hidden";
|
pill_tooltip.style.visibility = "hidden";
|
||||||
pill_arrow.style.visibility = "hidden";
|
pill_arrowup.style.visibility = "hidden";
|
||||||
|
pill_arrowdown.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterUpdate(async () => {
|
||||||
|
// 16 = arrow size + something
|
||||||
|
offsetUp = main_pill.offsetTop - pill_tooltip.offsetHeight - 16;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window bind:innerWidth />
|
<svelte:window bind:innerWidth bind:scrollY/>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class={white ? "pill-container pill-white" : "pill-container pill-black"}
|
class={white ? "pill-container pill-white" : "pill-container pill-black"}
|
||||||
|
@ -68,7 +89,8 @@
|
||||||
bind:this={main_pill}
|
bind:this={main_pill}
|
||||||
>
|
>
|
||||||
{#if show_tooltip === true}
|
{#if show_tooltip === true}
|
||||||
<div class="pill-arrow" bind:this={pill_arrow} />
|
<div class="pill-arrow pill-arrow-up" bind:this={pill_arrowup} />
|
||||||
|
<div class="pill-arrow pill-arrow-down" bind:this={pill_arrowdown} />
|
||||||
<div class="pill-tooltip" bind:this={pill_tooltip}>
|
<div class="pill-tooltip" bind:this={pill_tooltip}>
|
||||||
{#each tooltip_data as td}
|
{#each tooltip_data as td}
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
@media screen and (max-width: 1200px)
|
@media screen and (max-width: 1200px)
|
||||||
{
|
{
|
||||||
.sidebar {
|
.sidebar {
|
||||||
visibility: hidden;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
transition: all .3s ease 0s;
|
|
||||||
box-shadow: 0px 8px 18px -1px #261C2C30;
|
box-shadow: 0px 8px 18px -1px #261C2C30;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
@ -115,13 +114,20 @@
|
||||||
.pill-arrow {
|
.pill-arrow {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
transform: translateY(-2.2rem);
|
|
||||||
width: 0px;
|
|
||||||
height: 0px;
|
|
||||||
border-left: 20px solid transparent;
|
border-left: 20px solid transparent;
|
||||||
border-right: 20px solid transparent;
|
border-right: 20px solid transparent;
|
||||||
border-top: 20px solid var(--color-background);
|
width: 0px;
|
||||||
|
height: 0px;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
transition: all .3s ease 0s;
|
|
||||||
filter: drop-shadow(0px 8px 18px #261C2C20);
|
filter: drop-shadow(0px 8px 18px #261C2C20);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pill-arrow-up {
|
||||||
|
transform: translateY(-2.2rem);
|
||||||
|
border-top: 20px solid var(--color-background);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pill-arrow-down {
|
||||||
|
transform: translateY(2.2rem);
|
||||||
|
border-bottom: 20px solid var(--color-background);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue