added click outside sidebars handling, fixed some spacing issues

This commit is contained in:
Xanazf 2024-10-13 00:04:38 +03:00
parent 0df624df40
commit 119c8a2e6c
Signed by: Xanazf
GPG key ID: 4E4A5AD1FB748427
7 changed files with 132 additions and 52 deletions

View file

@ -1,4 +1,4 @@
import { createSignal, type Component } from "solid-js";
import { createSignal, onMount, type Component } from "solid-js";
import { LoadingSpinner, MenuToX, XToMenu } from "@icons";
import { Tree } from "./Tree";
@ -7,6 +7,7 @@ import type { NavProps } from "../types";
const NavComponent: Component<NavProps> = props => {
const [open, setOpen] = createSignal<boolean>(false);
const { tree, mobile, routes } = props;
let navRef: HTMLDivElement;
if (!tree) {
return <LoadingSpinner />;
@ -28,8 +29,29 @@ const NavComponent: Component<NavProps> = props => {
);
}
const handleClickOutside = (event: MouseEvent) => {
const isLink = "href" in (event.target || {});
if (
isLink ||
(document.body.contains(event.target as Node) &&
!navRef.contains(event.target as Node))
) {
setOpen(false);
}
};
onMount(() => {
window.addEventListener("click", handleClickOutside);
return () => {
window.removeEventListener("click", handleClickOutside);
};
});
return (
<div class="nav-toggle">
<div
class="nav-toggle"
ref={navRef!}
>
<div onclick={e => toggle(e)}>
{open() ? (
<MenuToX class="nav-icon" />

View file

@ -1,4 +1,4 @@
import { createSignal, type Component } from "solid-js";
import { createSignal, onMount, type Component } from "solid-js";
import { Article } from "@icons";
import { Table } from "./Table";
@ -8,6 +8,7 @@ import { buildHierarchy } from "@config/io/helpers";
const TableOfContents: Component<TOCProps> = props => {
const [open, setOpen] = createSignal<boolean>(false);
const { mobile, config, type } = props;
let tocRef: HTMLDivElement;
function toggle(e: MouseEvent) {
e.preventDefault();
@ -21,9 +22,29 @@ const TableOfContents: Component<TOCProps> = props => {
<Table configTOC={buildHierarchy(config!)} />
);
}
const handleClickOutside = (event: MouseEvent) => {
const isLink = "href" in (event.target || {});
if (
isLink ||
(document.body.contains(event.target as Node) &&
!tocRef.contains(event.target as Node))
) {
setOpen(false);
}
};
onMount(() => {
window.addEventListener("click", handleClickOutside);
return () => {
window.removeEventListener("click", handleClickOutside);
};
});
return (
<div class="toc-toggle">
<div
class="toc-toggle"
ref={tocRef!}
>
<div onclick={e => toggle(e)}>
<Article />
</div>

View file

@ -5,6 +5,7 @@
border-radius: 6px;
border: 1px solid hsla(var(--blue) 10 15 / 0.6);
margin-top: 1rem;
margin-inline: 1.272rem;
& .root-nav-entry {
position: relative;
@ -33,10 +34,12 @@
left: 0;
width: 100%;
height: 1px;
background: linear-gradient(90deg,
background: linear-gradient(
90deg,
transparent 25%,
hsla(var(--accent-500) / 0.88) 50%,
transparent 75%);
transparent 75%
);
}
}
}
@ -386,9 +389,11 @@ html.dark .typevariants {
&::before {
width: 0;
background: linear-gradient(to right,
background: linear-gradient(
to right,
hsla(var(--accent-400) / 0.5) var(--percent),
hsla(var(--accent-400) / 0) 100%);
hsla(var(--accent-400) / 0) 100%
);
animation: percentToZero 250ms ease-in-out forwards;
transition: width 0.25s ease-in-out;
}

View file

@ -83,6 +83,7 @@ ul {
.markdown-alert-title {
text-transform: lowercase;
text-transform: capitalize;
margin-block: 0 !important;
}
@media (min-width: 65rem) {
@ -110,17 +111,16 @@ ul {
flex-direction: row;
}
.docslayout-inner {
flex-grow: 1;
max-width: 80rem;
}
.docs {
display: flex;
flex-direction: row;
}
.docs-content {
& section {
max-width: 45svw;
}
}
.docslayout-inner {
min-width: 33.8rem;
}

View file

@ -13,6 +13,7 @@
max-height: 500px;
scrollbar-width: none;
-ms-overflow-style: none;
--width: 30rem;
&::-webkit-scrollbar {
display: none;
@ -45,14 +46,15 @@
display: none;
}
transition: width 0.3s ease,
transition:
width 0.3s ease,
height 0.3s ease,
background-color 0.3s ease,
backdrop-filter 0.3s ease,
padding 0.3s ease;
&.shown {
width: 100svw;
width: var(--width);
background-color: hsl(var(--bg-900) / 0.6);
backdrop-filter: blur(3px) saturate(180%);
display: flex;
@ -113,6 +115,18 @@
}
}
@media (max-width: 55rem) {
.nav-toggle {
--width: 45svw;
}
}
@media (max-width: 38rem) {
.nav-toggle {
--width: 100svw;
}
}
@media (min-width: 85rem) {
.nav-wrapper-mobile {
display: none;

View file

@ -54,7 +54,7 @@
top: 2.6rem;
right: -1rem;
width: 0;
height: 0;
height: max(min(100svh, 800px), calc(100svh - 8rem));
font-size: 0.745rem;
font-weight: 600;
scrollbar-width: none;
@ -64,7 +64,8 @@
display: none;
}
transition: width 0.3s ease,
transition:
width 0.3s ease,
height 0.3s ease,
background-color 0.3s ease,
backdrop-filter 0.3s ease,
@ -84,16 +85,23 @@
}
}
@media (min-width: 65rem) {
@media (max-width: 55rem) {
.toc-toggle {
--width: 25svw;
}
.toc-wrapper {
display: none;
}
}
@media (min-width: 65rem) {
.toc-wrapper-mobile {
display: none;
}
.toc-wrapper {
--width: 25svw;
background-color: transparent;
display: block;
position: sticky;
@ -133,3 +141,9 @@
}
}
}
@media (min-width: 85rem) {
.toc-wrapper {
width: max-content;
}
}

View file

@ -122,11 +122,13 @@ footer {
display: flex;
justify-content: space-between;
padding-inline: 1rem;
background: linear-gradient(150deg,
background: linear-gradient(
150deg,
hsla(var(--blue) 60 5 / 1) 10%,
hsla(var(--blue) 75 6 / 1) 25%,
hsla(var(--blue) 80 8 / 1) 55%,
hsla(var(--blue) 77 7 / 1) 80%);
hsla(var(--blue) 77 7 / 1) 80%
);
& ._credits {
display: flex;
@ -184,6 +186,12 @@ footer {
}
}
@media (min-width: 65rem) {
.search {
display: block;
}
}
@media (min-width: 85rem) {
html {
font-size: 16px;
@ -202,10 +210,6 @@ footer {
display: none;
}
.search {
display: block;
}
.spacer-desktop {
display: block;
font-size: 1.374rem;