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(
transparent 25%, 90deg,
hsla(var(--accent-500) / 0.88) 50%, transparent 25%,
transparent 75%); hsla(var(--accent-500) / 0.88) 50%,
transparent 75%
);
} }
} }
} }
@ -60,7 +63,7 @@
} }
#injectedMd { #injectedMd {
&>p:not(:first-child) { & > p:not(:first-child) {
margin-block: 0.724rem; margin-block: 0.724rem;
} }
} }
@ -74,7 +77,7 @@
} }
.typedocs-content { .typedocs-content {
&>p { & > p {
margin-block: 0.618rem; margin-block: 0.618rem;
} }
@ -102,7 +105,7 @@
padding: 1.272rem; padding: 1.272rem;
transition: border 0.3s; transition: border 0.3s;
&>.typedata-name { & > .typedata-name {
display: flex; display: flex;
align-items: center; align-items: center;
font-size: 1.272rem; font-size: 1.272rem;
@ -138,7 +141,7 @@
& .typedata-detailsdata, & .typedata-detailsdata,
.typedocs-subheading { .typedocs-subheading {
&>p { & > p {
margin-top: 0.618rem; margin-top: 0.618rem;
} }
@ -198,7 +201,7 @@
width: max-content; width: max-content;
transition: opacity 0.5s; transition: opacity 0.5s;
&>a { & > a {
opacity: inherit; opacity: inherit;
} }
} }
@ -265,7 +268,7 @@ html.dark .typeprops {
align-items: center; align-items: center;
gap: 0.117rem; gap: 0.117rem;
&>svg { & > svg {
height: 1.272rem; height: 1.272rem;
width: 1.272rem; width: 1.272rem;
} }
@ -317,7 +320,7 @@ html.dark .typefuncs {
align-items: center; align-items: center;
gap: 0.117rem; gap: 0.117rem;
&>svg { & > svg {
height: 1.272rem; height: 1.272rem;
width: 1.272rem; width: 1.272rem;
} }
@ -386,9 +389,11 @@ html.dark .typevariants {
&::before { &::before {
width: 0; width: 0;
background: linear-gradient(to right, background: linear-gradient(
hsla(var(--accent-400) / 0.5) var(--percent), to right,
hsla(var(--accent-400) / 0) 100%); hsla(var(--accent-400) / 0.5) var(--percent),
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;
} }
@ -419,7 +424,7 @@ html.dark .typevariants {
min-width: 30svw; min-width: 30svw;
} }
&>p { & > p {
margin-block: 1.217rem; margin-block: 1.217rem;
} }
} }

View file

@ -45,7 +45,7 @@
} }
.heading { .heading {
&>[id] { & > [id] {
width: max-content; width: max-content;
} }
@ -75,7 +75,7 @@ ul {
.markdown-alert { .markdown-alert {
margin-block: 0.618rem; margin-block: 0.618rem;
&>*:not(:first-child) { & > *:not(:first-child) {
margin-block: 0.724rem; margin-block: 0.724rem;
} }
} }
@ -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:
height 0.3s ease, width 0.3s ease,
background-color 0.3s ease, height 0.3s ease,
backdrop-filter 0.3s ease, background-color 0.3s ease,
padding 0.3s ease; backdrop-filter 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;
@ -95,7 +97,7 @@
max-width: 70%; max-width: 70%;
margin-left: 3.33em; margin-left: 3.33em;
&>div { & > div {
min-height: 4em; min-height: 4em;
display: grid; display: grid;
@ -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

@ -35,7 +35,7 @@
font-size: 1.614rem; font-size: 1.614rem;
max-height: 500px; max-height: 500px;
&>svg { & > svg {
height: 100%; height: 100%;
width: 24px; width: 24px;
} }
@ -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,11 +64,12 @@
display: none; display: none;
} }
transition: width 0.3s ease, transition:
height 0.3s ease, width 0.3s ease,
background-color 0.3s ease, height 0.3s ease,
backdrop-filter 0.3s ease, background-color 0.3s ease,
padding 0.3s ease; backdrop-filter 0.3s ease,
padding 0.3s ease;
&.shown { &.shown {
overflow-y: scroll; overflow-y: scroll;
@ -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;
@ -117,7 +125,7 @@
list-style: none; list-style: none;
&.active { &.active {
&>.toc_a { & > .toc_a {
color: hsl(var(--green) 72 60); color: hsl(var(--green) 72 60);
} }
} }
@ -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(
hsla(var(--blue) 60 5 / 1) 10%, 150deg,
hsla(var(--blue) 75 6 / 1) 25%, hsla(var(--blue) 60 5 / 1) 10%,
hsla(var(--blue) 80 8 / 1) 55%, hsla(var(--blue) 75 6 / 1) 25%,
hsla(var(--blue) 77 7 / 1) 80%); hsla(var(--blue) 80 8 / 1) 55%,
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;