summaryrefslogtreecommitdiff
path: root/docs/src/components/MenuToggle.tsx
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2021-07-15 14:13:35 -0400
committerGravatar GitHub <noreply@github.com> 2021-07-15 14:13:35 -0400
commit166e22bdf35b9751dc42f5cc6cb27a99b077df93 (patch)
treee8643360c2250dda82ebf95b62281978547d5188 /docs/src/components/MenuToggle.tsx
parentfb8bf7ec43f7b09348c12d5ff9f81131c70ef5e9 (diff)
downloadastro-166e22bdf35b9751dc42f5cc6cb27a99b077df93.tar.gz
astro-166e22bdf35b9751dc42f5cc6cb27a99b077df93.tar.zst
astro-166e22bdf35b9751dc42f5cc6cb27a99b077df93.zip
merge in docs site (#705)
Diffstat (limited to 'docs/src/components/MenuToggle.tsx')
-rw-r--r--docs/src/components/MenuToggle.tsx44
1 files changed, 44 insertions, 0 deletions
diff --git a/docs/src/components/MenuToggle.tsx b/docs/src/components/MenuToggle.tsx
new file mode 100644
index 000000000..605581077
--- /dev/null
+++ b/docs/src/components/MenuToggle.tsx
@@ -0,0 +1,44 @@
+import type { FunctionalComponent } from 'preact';
+import { h, Fragment } from 'preact';
+import { useState, useEffect } from 'preact/hooks';
+
+const MenuToggle: FunctionalComponent = () => {
+ const [sidebarShown, setSidebarShown] = useState(false);
+
+ useEffect(() => {
+ const body = document.getElementsByTagName('body')[0];
+ if (sidebarShown) {
+ body.classList.add('mobile-sidebar-toggle');
+ } else {
+ body.classList.remove('mobile-sidebar-toggle');
+ }
+ }, [sidebarShown]);
+
+ return (
+ <button
+ type="button"
+ aria-pressed={sidebarShown ? 'true' : 'false'}
+ id="menu-toggle"
+ onClick={() => setSidebarShown(!sidebarShown)}
+ >
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="1em"
+ height="1em"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M4 6h16M4 12h16M4 18h16"
+ />
+ </svg>
+ <span className="sr-only">Toggle sidebar</span>
+ </button>
+ );
+};
+
+export default MenuToggle;