Skip to content

Commit

Permalink
add doc search & modernize docs (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Nov 8, 2023
1 parent 2fd1698 commit 8e5d90b
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 90 deletions.
115 changes: 115 additions & 0 deletions apps/www/src/lib/components/docs/command-menu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<script lang="ts">
import { Circle, File, Laptop, Moon, Sun } from "radix-icons-svelte";
import * as Command from "@/registry/new-york/ui/command";
import { Button } from "@/registry/new-york/ui/button";
import { onMount } from "svelte";
import { cn } from "@/utils";
import { docsConfig } from "@/config/docs";
import { goto } from "$app/navigation";
import { resetMode, setMode } from "mode-watcher";
let open = false;
onMount(() => {
function handleKeydown(e: KeyboardEvent) {
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
open = true;
}
}
document.addEventListener("keydown", handleKeydown);
return () => {
document.removeEventListener("keydown", handleKeydown);
};
});
function runCommand(cmd: () => void) {
open = false;
cmd();
}
const mainNav = docsConfig.mainNav.filter((item) => !item.external);
const sidebarNav = docsConfig.sidebarNav;
</script>

<Button
variant="outline"
class={cn(
"relative w-full justify-start text-sm text-muted-foreground sm:pr-12 md:w-40 xl:w-64"
)}
on:click={() => (open = true)}
{...$$restProps}
>
<span class="hidden lg:inline-flex"> Search documentation... </span>
<span class="inline-flex lg:hidden">Search...</span>
<kbd
class="pointer-events-none absolute right-1.5 top-1.5 hidden h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium opacity-100 sm:flex"
>
<span class="text-xs">⌘</span>K
</kbd>
</Button>
<Command.Dialog bind:open>
<Command.Input placeholder="Type a command or search" />
<Command.List>
<Command.Empty>No results found.</Command.Empty>
<Command.Group heading="Links">
{#each mainNav as navItem}
<Command.Item
value={navItem.title}
onSelect={() =>
runCommand(() => {
navItem.href && goto(navItem.href);
})}
>
<File class="mr-2 h-4 w-4" />
{navItem.title}
</Command.Item>
{/each}
</Command.Group>
{#each sidebarNav as group}
<Command.Group heading={group.title}>
{#each group.items as navItem}
<Command.Item
value={navItem.title}
onSelect={() =>
runCommand(() => {
navItem.href && goto(navItem.href);
})}
>
<div
class="mr-2 flex h-4 w-4 items-center justify-center"
>
<Circle class="h-3 w-3" />
</div>
{navItem.title}
</Command.Item>
{/each}
</Command.Group>
{/each}
<Command.Separator />
<Command.Group heading="Theme">
<Command.Item
value="light"
onSelect={() => runCommand(() => setMode("light"))}
>
<Sun class="mr-2 h-4 w-4" />
Light
</Command.Item>
<Command.Item
value="dark"
onSelect={() => runCommand(() => setMode("dark"))}
>
<Moon class="mr-2 h-4 w-4" />
Dark
</Command.Item>
<Command.Item
value="system"
onSelect={() => runCommand(() => resetMode())}
>
<Laptop class="mr-2 h-4 w-4" />
System
</Command.Item>
</Command.Group>
</Command.List>
</Command.Dialog>
2 changes: 1 addition & 1 deletion apps/www/src/lib/components/docs/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
Settings,
SunMedium,
Trash,
Twitter,
User,
X
} from "lucide-svelte";
Expand All @@ -36,6 +35,7 @@ import Pnpm from "./pnpm.svelte";
import RadixSvelte from "./radix-svelte.svelte";
import Tailwind from "./tailwind.svelte";
import Yarn from "./yarn.svelte";
import Twitter from "./twitter.svelte";

export type Icon = LucideIcon;

Expand Down
12 changes: 12 additions & 0 deletions apps/www/src/lib/components/docs/icons/twitter.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<svg
height="23"
viewBox="0 0 1200 1227"
width="23"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
{...$$restProps}
>
<path
d="M714.163 519.284L1160.89 0H1055.03L667.137 450.887L357.328 0H0L468.492 681.821L0 1226.37H105.866L515.491 750.218L842.672 1226.37H1200L714.137 519.284H714.163ZM569.165 687.828L521.697 619.934L144.011 79.6944H306.615L611.412 515.685L658.88 583.579L1055.08 1150.3H892.476L569.165 687.854V687.828Z"
/>
</svg>
3 changes: 2 additions & 1 deletion apps/www/src/lib/components/docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ export { default as ThemeWrapper } from "./theme-wrapper.svelte";
export { default as Tree } from "./tree.svelte";
export { default as TailwindIndicator } from "./tailwind-indicator.svelte";
export { default as ComponentPreviewManual } from "./component-preview-manual.svelte";
export { default as CommandMenu } from "./command-menu.svelte";
export { default as ModeToggle } from "./mode-toggle.svelte";

export * from "./icons";
export * from "./page-header";
export * from "./nav";
export * from "./examples-nav";
export * from "./dashboard";
export * from "./light-switch";
export * from "./theme-customizer";
export * from "./forms";
1 change: 0 additions & 1 deletion apps/www/src/lib/components/docs/light-switch/index.ts

This file was deleted.

27 changes: 0 additions & 27 deletions apps/www/src/lib/components/docs/light-switch/light-switch.svelte

This file was deleted.

31 changes: 31 additions & 0 deletions apps/www/src/lib/components/docs/mode-toggle.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script lang="ts">
import { Moon, Sun } from "radix-icons-svelte";
import { Button } from "@/registry/new-york/ui/button";
import * as DropdownMenu from "@/registry/new-york/ui/dropdown-menu";
import { resetMode, setMode } from "mode-watcher";
</script>

<DropdownMenu.Root positioning={{ placement: "bottom-end" }}>
<DropdownMenu.Trigger asChild let:builder>
<Button builders={[builder]} variant="ghost" class="w-9 px-0">
<Sun
class="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-roate-90 dark:scale-0"
/>
<Moon
class="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"
/>
<span class="sr-only">Toggle theme</span>
</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content>
<DropdownMenu.Item on:click={() => setMode("light")}>
Light
</DropdownMenu.Item>
<DropdownMenu.Item on:click={() => setMode("dark")}>
Dark
</DropdownMenu.Item>
<DropdownMenu.Item on:click={() => resetMode()}>
System
</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Root>
72 changes: 55 additions & 17 deletions apps/www/src/lib/components/docs/nav/main-nav.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { page } from "$app/stores";
import { docsConfig } from "$lib/config/docs";
import { siteConfig } from "$lib/config/site";
import { cn } from "$lib/utils";
import { Icons } from "../icons";
Expand All @@ -9,25 +8,64 @@
<div class="mr-4 hidden md:flex">
<a href="/" class="mr-6 flex items-center space-x-2">
<Icons.logo class="h-6 w-6" />
<span class="hidden font-bold sm:inline-block">
<span class="hidden font-bold sm:inline-block text-[15px] lg:text-base">
{siteConfig.name}
</span>
</a>
<nav class="flex items-center space-x-6 text-sm font-medium">
{#each docsConfig.mainNav as navItem}
<a
href={navItem.href}
class={cn(
"transition-colors hover:text-foreground/80",
$page.url.pathname === navItem.href
? "text-foreground"
: "text-foreground/60"
)}
target={navItem.external ? "_blank" : undefined}
rel={navItem.external ? "noreferrer" : undefined}
>
{navItem.title}
</a>
{/each}
<a
href="/docs"
class={cn(
"transition-colors hover:text-foreground/80",
$page.url.pathname === "/docs"
? "text-foreground"
: "text-foreground/60"
)}
>
Documentation
</a>
<a
href="/docs/components"
class={cn(
"transition-colors hover:text-foreground/80",
$page.url.pathname.startsWith("/docs/components")
? "text-foreground"
: "text-foreground/60"
)}
>
Components
</a>
<a
href="/docs/components"
class={cn(
"transition-colors hover:text-foreground/80",
$page.url.pathname.startsWith("/themes")
? "text-foreground"
: "text-foreground/60"
)}
>
Themes
</a>
<a
href="/docs"
class={cn(
"transition-colors hover:text-foreground/80",
$page.url.pathname.startsWith("/examples")
? "text-foreground"
: "text-foreground/60"
)}
>
Examples
</a>
<a
href={siteConfig.links.github}
target="_blank"
rel="noopener noreferrer"
class={cn(
"hidden text-foreground/60 transition-colors hover:text-foreground/80 xl:block"
)}
>
GitHub
</a>
</nav>
</div>
12 changes: 8 additions & 4 deletions apps/www/src/lib/components/docs/nav/mobile-nav.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import * as Sheet from "@/registry/new-york/ui/sheet";
import { SidebarOpen } from "lucide-svelte";
import { ViewVertical } from "radix-icons-svelte";
import { Button } from "@/registry/new-york/ui/button";
import { docsConfig } from "$lib/config/docs";
import { siteConfig } from "$lib/config/site";
Expand All @@ -17,12 +17,12 @@
variant="ghost"
class="mr-2 px-0 text-base hover:bg-transparent focus-visible:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 md:hidden"
>
<SidebarOpen class="h-5 w-5" />
<ViewVertical class="h-5 w-5" />
<span class="sr-only">Toggle Menu</span>
</Button>
</Sheet.Trigger>
<Sheet.Content side="left" class="pr-0">
<MobileLink href="/" class="flex items-center" {open}>
<MobileLink href="/" class="flex items-center" bind:open>
<Icons.logo class="mr-2 h-4 w-4" />
<span class="font-bold">{siteConfig.name}</span>
</MobileLink>
Expand All @@ -43,7 +43,11 @@
{#if navItem?.items?.length}
{#each navItem.items as item}
{#if !item.disabled && item.href}
<MobileLink href={item.href} bind:open>
<MobileLink
href={item.href}
bind:open
class="text-muted-foreground"
>
{item.title}
</MobileLink>
{/if}
Expand Down
Loading

1 comment on commit 8e5d90b

@vercel
Copy link

@vercel vercel bot commented on 8e5d90b Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.