sidebar offset
This commit is contained in:
		
							parent
							
								
									508fd31f99
								
							
						
					
					
						commit
						d319110b5d
					
				
					 3 changed files with 57 additions and 1 deletions
				
			
		| 
						 | 
					@ -18,6 +18,9 @@ const NavComponent: Component<SidebarContent> = props => {
 | 
				
			||||||
  const { children } = props;
 | 
					  const { children } = props;
 | 
				
			||||||
  let navRef: HTMLDivElement;
 | 
					  let navRef: HTMLDivElement;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const [clientWidth, setClientWidth] = createSignal<number>(0);
 | 
				
			||||||
 | 
					  const [screenWidth, setScreenWidth] = createSignal<number>(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function toggle(e: MouseEvent) {
 | 
					  function toggle(e: MouseEvent) {
 | 
				
			||||||
    e.preventDefault();
 | 
					    e.preventDefault();
 | 
				
			||||||
    setOpen(!open());
 | 
					    setOpen(!open());
 | 
				
			||||||
| 
						 | 
					@ -36,20 +39,45 @@ const NavComponent: Component<SidebarContent> = props => {
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  onMount(() => {
 | 
					  onMount(() => {
 | 
				
			||||||
 | 
					    setClientWidth(document.body.clientWidth);
 | 
				
			||||||
 | 
					    setScreenWidth(window.outerWidth);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    onCleanup(() => {
 | 
					    onCleanup(() => {
 | 
				
			||||||
      window.removeEventListener("click", handleClickOutside);
 | 
					      window.removeEventListener("click", handleClickOutside);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createEffect(() => {
 | 
					  createEffect(() => {
 | 
				
			||||||
 | 
					    if (clientWidth() !== document.body.clientWidth) {
 | 
				
			||||||
 | 
					      setClientWidth(document.body.clientWidth);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (screenWidth() !== window.outerWidth) {
 | 
				
			||||||
 | 
					      setScreenWidth(window.outerWidth);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (open()) {
 | 
					    if (open()) {
 | 
				
			||||||
      window.addEventListener("click", handleClickOutside);
 | 
					      window.addEventListener("click", handleClickOutside);
 | 
				
			||||||
      document.body.classList.add("overflow-nav");
 | 
					      document.body.classList.add("overflow-nav");
 | 
				
			||||||
      document.body.classList.add("dim-content-nav");
 | 
					      document.body.classList.add("dim-content-nav");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // onsetter
 | 
				
			||||||
 | 
					      const header = document.getElementsByClassName(
 | 
				
			||||||
 | 
					        "header"
 | 
				
			||||||
 | 
					      )[0]! as HTMLElement;
 | 
				
			||||||
 | 
					      const bodyOffset = screenWidth() - clientWidth();
 | 
				
			||||||
 | 
					      document.body.style.width = `${screenWidth() - bodyOffset}px`;
 | 
				
			||||||
 | 
					      header.style.width = `${screenWidth() - bodyOffset}px`;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      window.removeEventListener("click", handleClickOutside);
 | 
					      window.removeEventListener("click", handleClickOutside);
 | 
				
			||||||
      document.body.classList.remove("overflow-nav");
 | 
					      document.body.classList.remove("overflow-nav");
 | 
				
			||||||
      document.body.classList.remove("dim-content-nav");
 | 
					      document.body.classList.remove("dim-content-nav");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // offsetter
 | 
				
			||||||
 | 
					      const header = document.getElementsByClassName(
 | 
				
			||||||
 | 
					        "header"
 | 
				
			||||||
 | 
					      )[0]! as HTMLElement;
 | 
				
			||||||
 | 
					      document.body.style.width = "";
 | 
				
			||||||
 | 
					      header.style.width = "";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,6 +85,7 @@ const NavComponent: Component<SidebarContent> = props => {
 | 
				
			||||||
    <div
 | 
					    <div
 | 
				
			||||||
      class="nav-toggle"
 | 
					      class="nav-toggle"
 | 
				
			||||||
      ref={navRef!}
 | 
					      ref={navRef!}
 | 
				
			||||||
 | 
					      id="nav-toggle"
 | 
				
			||||||
    >
 | 
					    >
 | 
				
			||||||
      <div onclick={e => toggle(e)}>
 | 
					      <div onclick={e => toggle(e)}>
 | 
				
			||||||
        <MenuToX class={`nav-icon ${open() ? "active" : ""}`} />
 | 
					        <MenuToX class={`nav-icon ${open() ? "active" : ""}`} />
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@ export interface Props {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const { mobile } = Astro.props;
 | 
					const { mobile } = Astro.props;
 | 
				
			||||||
---
 | 
					---
 | 
				
			||||||
<aside class=`nav-wrapper${mobile ? "-mobile" : ""}`>
 | 
					<aside class=`nav-wrapper${mobile ? "-mobile" : ""} id="nav"`>
 | 
				
			||||||
  { mobile ? (
 | 
					  { mobile ? (
 | 
				
			||||||
    <SidebarWrapper client:load>
 | 
					    <SidebarWrapper client:load>
 | 
				
			||||||
      <RootNav currentRoute={currentRoute} currentModule={currentModule} currentClass={currentClass}/>
 | 
					      <RootNav currentRoute={currentRoute} currentModule={currentModule} currentClass={currentClass}/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,8 @@ 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 [clientWidth, setClientWidth] = createSignal<number>(0);
 | 
				
			||||||
 | 
					  const [screenWidth, setScreenWidth] = createSignal<number>(0);
 | 
				
			||||||
  const { mobile, config, type } = props;
 | 
					  const { mobile, config, type } = props;
 | 
				
			||||||
  let tocRef: HTMLDivElement;
 | 
					  let tocRef: HTMLDivElement;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,20 +43,44 @@ const TableOfContents: Component<TOCProps> = props => {
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  onMount(() => {
 | 
					  onMount(() => {
 | 
				
			||||||
 | 
					    setClientWidth(document.body.clientWidth);
 | 
				
			||||||
 | 
					    setScreenWidth(window.outerWidth);
 | 
				
			||||||
    onCleanup(() => {
 | 
					    onCleanup(() => {
 | 
				
			||||||
      window.removeEventListener("click", handleClickOutside);
 | 
					      window.removeEventListener("click", handleClickOutside);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createEffect(() => {
 | 
					  createEffect(() => {
 | 
				
			||||||
 | 
					    if (clientWidth() !== document.body.clientWidth) {
 | 
				
			||||||
 | 
					      setClientWidth(document.body.clientWidth);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (screenWidth() !== window.outerWidth) {
 | 
				
			||||||
 | 
					      setScreenWidth(window.outerWidth);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (open()) {
 | 
					    if (open()) {
 | 
				
			||||||
      window.addEventListener("click", handleClickOutside);
 | 
					      window.addEventListener("click", handleClickOutside);
 | 
				
			||||||
      document.body.classList.add("overflow-toc");
 | 
					      document.body.classList.add("overflow-toc");
 | 
				
			||||||
      document.body.classList.add("dim-content-toc");
 | 
					      document.body.classList.add("dim-content-toc");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // onsetter
 | 
				
			||||||
 | 
					      const header = document.getElementsByClassName(
 | 
				
			||||||
 | 
					        "header"
 | 
				
			||||||
 | 
					      )[0]! as HTMLElement;
 | 
				
			||||||
 | 
					      const bodyOffset = screenWidth() - clientWidth();
 | 
				
			||||||
 | 
					      document.body.style.width = `${screenWidth() - bodyOffset}px`;
 | 
				
			||||||
 | 
					      header.style.width = `${screenWidth() - bodyOffset}px`;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      window.removeEventListener("click", handleClickOutside);
 | 
					      window.removeEventListener("click", handleClickOutside);
 | 
				
			||||||
      document.body.classList.remove("overflow-toc");
 | 
					      document.body.classList.remove("overflow-toc");
 | 
				
			||||||
      document.body.classList.remove("dim-content-toc");
 | 
					      document.body.classList.remove("dim-content-toc");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // offsetter
 | 
				
			||||||
 | 
					      const header = document.getElementsByClassName(
 | 
				
			||||||
 | 
					        "header"
 | 
				
			||||||
 | 
					      )[0]! as HTMLElement;
 | 
				
			||||||
 | 
					      document.body.style.width = "";
 | 
				
			||||||
 | 
					      header.style.width = "";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,6 +88,7 @@ const TableOfContents: Component<TOCProps> = props => {
 | 
				
			||||||
    <div
 | 
					    <div
 | 
				
			||||||
      class="toc-toggle"
 | 
					      class="toc-toggle"
 | 
				
			||||||
      ref={tocRef!}
 | 
					      ref={tocRef!}
 | 
				
			||||||
 | 
					      id="toc-toggle"
 | 
				
			||||||
    >
 | 
					    >
 | 
				
			||||||
      <div onclick={e => toggle(e)}>
 | 
					      <div onclick={e => toggle(e)}>
 | 
				
			||||||
        <Article />
 | 
					        <Article />
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue