Sina UI

Blocks

Docs

Everything a product's documentation needs around the words: tabs for each part of the docs, a sidebar of pages, search on ⌘K, a contents rail that follows the reader, code in several languages, and each page as Markdown for people who paste docs into an AI tool.

Installation

npx sinaui add blocks/docs

Example

The docs of Warraq, a pretend manuscript catalog: four pages under two tabs. Pick a code language once and every sample on the page follows it. Switch to Phone to see the sidebar fold into a menu.

Device
Open it

Usage

The layout goes in your docs' +layout.svelte and takes the nav as data; each page renders a DocsPage with its content as children. The example's own files:

<script lang="ts">
	import { goto } from '$app/navigation';
	import { page } from '$app/state';
	import DocsLayout from '#lib/blocks/docs/DocsLayout.svelte';
	import { href, markdownHref, product, root, sections } from './content.js';

	let { children } = $props();
</script>

<DocsLayout
	name={product}
	{sections}
	current={page.url.pathname}
	home={root}
	action={{ label: 'Dashboard', href: href('') }}
	onnavigate={(to) => goto(to)}
>
	{#snippet logo()}
		<span class="mark" aria-hidden="true">W</span>
		{product}
	{/snippet}
	{#snippet footer()}
		{product} documentation, a Sina UI demo.
		<a href={markdownHref(page.params.page ?? '')} data-sveltekit-reload>This page as Markdown</a>
	{/snippet}
	{@render children()}
</DocsLayout>

<style>
	.mark {
		display: grid;
		place-items: center;
		inline-size: 1.5rem;
		block-size: 1.5rem;
		border-radius: var(--ui-radius);
		background: var(--ui-accent);
		color: var(--ui-on-accent);
		font-size: 0.8125rem;
	}
</style>
<script lang="ts">
	import CodeTabs from '#lib/blocks/docs/CodeTabs.svelte';
	import DocsPage from '#lib/blocks/docs/DocsPage.svelte';
	import { locate } from '#lib/blocks/docs/docs.js';
	import { find, href, markdown, markdownHref, product, sections, toc } from '../content.js';
	import type { PageProps } from './$types';

	let { data }: PageProps = $props();

	const doc = $derived(find(data.slug)!);
	const place = $derived(locate(sections, href(doc.slug)));
	// One pick for every code sample on the page.
	let lang = $state<string>();

	// `code` spans in the text.
	const parts = (text: string) => text.split('`').map((t, i) => ({ t, code: i % 2 === 1 }));
</script>

<svelte:head>
	<title>{doc.title} — {product} docs</title>
	<meta name="description" content={doc.description} />
	<meta property="og:title" content="{doc.title} — {product} docs" />
	<meta property="og:description" content={doc.description} />
</svelte:head>

{#snippet text(s: string)}{#each parts(s) as p, i (i)}{#if p.code}<code>{p.t}</code
			>{:else}{p.t}{/if}{/each}{/snippet}

<DocsPage
	title={doc.title}
	description={doc.description}
	crumbs={[
		{ label: place.section.label, href: place.section.href },
		...(place.group?.title ? [{ label: place.group.title }] : []),
		{ label: doc.title }
	]}
	markdown={markdown(doc)}
	markdownHref={markdownHref(doc.slug)}
	toc={toc(doc)}
	prev={place.prev}
	next={place.next}
>
	{#each doc.blocks as b, i (i)}
		{#if b.kind === 'h2'}
			<h2 id={b.id}>{b.text}</h2>
		{:else if b.kind === 'h3'}
			<h3 id={b.id}>{b.text}</h3>
		{:else if b.kind === 'p'}
			<p>{@render text(b.text)}</p>
		{:else if b.kind === 'list'}
			<ul>
				{#each b.items as item, j (j)}<li>{@render text(item)}</li>{/each}
			</ul>
		{:else}
			<CodeTabs samples={b.samples} bind:value={lang} />
		{/if}
	{/each}
</DocsPage>

Props

DocsLayout

PropTypeDefault
namestring: the productrequired
sections{ label, href, groups }[]: top-bar tabs; one shows no tabsrequired
currentstring: the page's pathrequired
homestring'/'
logoSnippetthe name
action{ label, href }
search(query) => Command[]: your own index; pages by title without it
searchEmptystring“Nothing matches…”
onnavigate(href) => void: pass gotoa full page load
footerSnippet

DocsPage

PropTypeDefault
title, descriptionstring
crumbs{ label, href? }[]
markdownstring | () => Promise<string>: shows “Copy page as Markdown”
markdownHrefstring: shows “View as Markdown”
toc{ id, label, level? }[][]
prev, next{ label, href }

locate(sections, current) finds a page's tab, group and its previous and next pages, so the crumbs and pager come from the same nav as the sidebar. CodeTabs takes samples: { label, code, lang?, filename? }[] and a bindable value.

The content keeps one rhythm: every block sits --prose-gap (1.25rem; set it to change it) below the last, and headings get more room above than below. Wrap a component that sets its own margins, such as a lone CodeBlock or an Alert, in a div; CodeTabs already is, and each of its tabs is only as tall as its own code.

Accessibility

  • A skip link, a banner, one main region and named navigations for the tabs, pages and contents.
  • The current tab and page carry aria-current="page"; the section being read, aria-current="location".
  • Search opens on ⌘K (Ctrl+K elsewhere) and is a full keyboard command palette.
  • Below 56rem the sidebar moves into a sheet; below 75rem the contents rail hides.
  • Everything is server-rendered: the page reads without JavaScript, and reduced motion is respected.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Theme toggle
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Account menu
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Sparkline
World map
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Docs navigation
Menubar
Navigation menu
Pagination
Sidebar layout
Stat tabs
Stepper
Tabs
Table of contents
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
Docs
File explorer
Messaging
Notifications
Settings
Studio
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme