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 { LoadingSpinner, MenuToX, XToMenu } from "@icons";
import { Tree } from "./Tree"; import { Tree } from "./Tree";
@ -7,6 +7,7 @@ import type { NavProps } from "../types";
const NavComponent: Component<NavProps> = props => { const NavComponent: Component<NavProps> = props => {
const [open, setOpen] = createSignal<boolean>(false); const [open, setOpen] = createSignal<boolean>(false);
const { tree, mobile, routes } = props; const { tree, mobile, routes } = props;
let navRef: HTMLDivElement;
if (!tree) { if (!tree) {
return <LoadingSpinner />; 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 ( return (
<div class="nav-toggle"> <div
class="nav-toggle"
ref={navRef!}
>
<div onclick={e => toggle(e)}> <div onclick={e => toggle(e)}>
{open() ? ( {open() ? (
<MenuToX class="nav-icon" /> <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 { Article } from "@icons";
import { Table } from "./Table"; import { Table } from "./Table";
@ -8,6 +8,7 @@ import { buildHierarchy } from "@config/io/helpers";
const TableOfContents: Component<TOCProps> = props => { const TableOfContents: Component<TOCProps> = props => {
const [open, setOpen] = createSignal<boolean>(false); const [open, setOpen] = createSignal<boolean>(false);
const { mobile, config, type } = props; const { mobile, config, type } = props;
let tocRef: HTMLDivElement;
function toggle(e: MouseEvent) { function toggle(e: MouseEvent) {
e.preventDefault(); e.preventDefault();
@ -21,9 +22,29 @@ const TableOfContents: Component<TOCProps> = props => {
<Table configTOC={buildHierarchy(config!)} /> <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 ( return (
<div class="toc-toggle"> <div
class="toc-toggle"
ref={tocRef!}
>
<div onclick={e => toggle(e)}> <div onclick={e => toggle(e)}>
<Article /> <Article />
</div> </div>

View file

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

View file

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

View file

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

View file

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

View file

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