From 7b2ad4e65e05959ea24e68056cbeb2f7e8e2b336 Mon Sep 17 00:00:00 2001 From: Josh Lambert Date: Fri, 27 Feb 2026 01:02:57 -0500 Subject: [PATCH] Make a new tab --- packages/kilo-docs/components/Tabs.tsx | 37 ++++++++++++++++++++++---- packages/kilo-docs/public/globals.css | 7 +++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/kilo-docs/components/Tabs.tsx b/packages/kilo-docs/components/Tabs.tsx index 0328ca5174..2f5661edc2 100644 --- a/packages/kilo-docs/components/Tabs.tsx +++ b/packages/kilo-docs/components/Tabs.tsx @@ -1,4 +1,4 @@ -import React, { useState, Children, isValidElement, ReactNode, ReactElement } from "react" +import React, { useState, useEffect, Children, isValidElement, ReactNode, ReactElement } from "react" interface TabProps { label: string @@ -9,21 +9,48 @@ interface TabsProps { children: ReactNode } +function slugify(label: string) { + return label + .toLowerCase() + .replace(/\s+/g, "-") + .replace(/[^a-z0-9-]/g, "") +} + export function Tab({ children }: TabProps) { return <>{children} } export function Tabs({ children }: TabsProps) { - const [activeIndex, setActiveIndex] = useState(0) - const tabs = Children.toArray(children).filter( (child): child is ReactElement => isValidElement(child) && (child.type === Tab || (child.props as any)?.label !== undefined), ) + const indexFromHash = () => { + if (typeof window === "undefined") return 0 + const hash = window.location.hash.slice(1) + if (!hash) return 0 + const found = tabs.findIndex((tab) => slugify(tab.props.label) === hash) + return found >= 0 ? found : 0 + } + + const [activeIndex, setActiveIndex] = useState(indexFromHash) + + useEffect(() => { + const onHashChange = () => setActiveIndex(indexFromHash()) + window.addEventListener("hashchange", onHashChange) + return () => window.removeEventListener("hashchange", onHashChange) + }, []) + + const selectTab = (index: number) => { + setActiveIndex(index) + const slug = slugify(tabs[index].props.label) + history.replaceState(null, "", `#${slug}`) + } + return (
-
+
{tabs.map((tab, index) => ( diff --git a/packages/kilo-docs/public/globals.css b/packages/kilo-docs/public/globals.css index b457039992..1dd89b9e0a 100644 --- a/packages/kilo-docs/public/globals.css +++ b/packages/kilo-docs/public/globals.css @@ -36,6 +36,13 @@ box-sizing: border-box; } +.scrollbar-none { + scrollbar-width: none; /* Firefox */ +} +.scrollbar-none::-webkit-scrollbar { + display: none; /* Chrome, Safari, Edge */ +} + html, body { overflow-x: hidden;