Skip to content

Commit

Permalink
initial api reference
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Aug 18, 2023
1 parent ca6f60f commit 250a5b9
Show file tree
Hide file tree
Showing 27 changed files with 476 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
{
"files": "*.svelte",
"options": {
"parser": "svelte"
"parser": "svelte",
"printWidth": 100
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"types": "./dist/index.d.ts",
"type": "module",
"dependencies": {
"@melt-ui/svelte": "0.34.6",
"@melt-ui/svelte": "0.35.0",
"@sveltejs/adapter-vercel": "^3.0.3",
"nanoid": "^4.0.2",
"shiki": "^0.14.3",
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
%sveltekit.head%
</head>

<body data-sveltekit-preload-data="hover" class="bg-background antialiased font-sans">
<body data-sveltekit-preload-data="hover" class="bg-background antialiased font-sans overflow-y-scroll">
<div>
%sveltekit.body%
</div>
Expand Down
25 changes: 25 additions & 0 deletions src/components/api-section.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script lang="ts">
import { DataAttrsTable, PropsTable } from "@/components";
import { h3 as H3 } from "@/components/markdown";
import { p as P } from "@/components/markdown";
import type { APISchema } from "@/types";
export let schemas: APISchema[] = [];
</script>

<div class="flex flex-col gap-8">
{#each schemas as schema}
<div>
<H3>{schema.title}</H3>
<P class="!mt-2 !mb-5">{schema.description}</P>
<div class="flex flex-col gap-8">
{#if schema.props && schema.props.length}
<PropsTable props={schema.props} />
{/if}
{#if schema.dataAttributes && schema.dataAttributes.length}
<DataAttrsTable dataAttrs={schema.dataAttributes} />
{/if}
</div>
</div>
{/each}
</div>
36 changes: 36 additions & 0 deletions src/components/api-tables/data-attrs-table.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script lang="ts">
import * as Table from "@/components/ui/table";
import { Code } from "@/components";
import { parseMarkdown } from "@/utils";
import type { DataAttrSchema } from "@/types";
export let dataAttrs: DataAttrSchema[] = [];
</script>

<Table.Root>
<Table.Header>
<Table.Row class="w-1/4">
<Table.Head class="w-1/2 whitespace-nowrap">Data Attribute</Table.Head>
<Table.Head class="w-1/2 whitespace-nowrap">Value/Description</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{#if dataAttrs.length}
{#each dataAttrs as attr}
<Table.Row>
<Table.Cell class="align-baseline">
<Code>data-{attr.name}</Code>
</Table.Cell>
<Table.Cell class="align-baseline">
{#if attr.value}
<Code neutral>{attr.value}</Code>
{/if}
<p class="text-sm leading-7 my-2">
{@html parseMarkdown(attr.description)}
</p>
</Table.Cell>
</Table.Row>
{/each}
{/if}
</Table.Body>
</Table.Root>
2 changes: 2 additions & 0 deletions src/components/api-tables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as DataAttrsTable } from "./data-attrs-table.svelte";
export { default as PropsTable } from "./props-table.svelte";
40 changes: 40 additions & 0 deletions src/components/api-tables/props-table.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script lang="ts">
import * as Table from "@/components/ui/table";
import { Code } from "@/components";
import type { PropSchema } from "@/types";
import { parseMarkdown } from "@/utils";
export let props: PropSchema[] = [];
</script>

<Table.Root>
<Table.Header>
<Table.Row class="w-1/4">
<Table.Head class="w-1/4 whitespace-nowrap">Prop</Table.Head>
<Table.Head class="w-1/4 whitespace-nowrap">Default</Table.Head>
<Table.Head class="w-1/2 whitespace-nowrap">Type/Description</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{#each props as prop}
<Table.Row>
<Table.Cell class="align-baseline">
<Code>{prop.name}</Code>
</Table.Cell>
<Table.Cell class="align-baseline">
{#if prop.default}
<Code neutral>{prop.default}</Code>
{:else}
<p>-</p>
{/if}
</Table.Cell>
<Table.Cell class="align-baseline">
<Code neutral>{prop.type}</Code>
<p class="text-sm leading-7 my-2">
{@html parseMarkdown(prop.description)}
</p>
</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
3 changes: 3 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ export * from "./light-switch";
export * from "./icons";
export * from "./page-header";
export * from "./navigation";
export * from "./api-tables";
export { default as SiteHeader } from "./site-header.svelte";
export { default as TailwindIndicator } from "./tailwind-indicator.svelte";
export { default as SidebarNav } from "./navigation/sidebar-nav.svelte";
export { default as CopyCodeButton } from "./copy-code-button.svelte";
export { default as Steps } from "./steps.svelte";
export { default as Code } from "./markdown/code.svelte";
export { default as APISection } from "./api-section.svelte";
16 changes: 16 additions & 0 deletions src/components/markdown/code.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { cn } from "@/utils";
let className: string | undefined | null = undefined;
export { className as class };
export let neutral = false;
</script>

<code
class={cn(
"relative rounded !px-[0.25rem] !py-[0.15rem] font-mono !text-[12px]",
neutral ? "!bg-muted" : "!bg-secondary/25",
className
)}
>
<slot />
</code>
2 changes: 1 addition & 1 deletion src/components/ui/table/table-cell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<td
class={cn(
"p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
"px-2 py-4 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
className
)}
{...$$restProps}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/table/table-header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
export { className as class };
</script>

<thead class={cn("[&_tr]:border-b", className)} {...$$restProps}>
<thead class={cn("[&_tr]:border-b bg-muted/30", className)} {...$$restProps}>
<slot />
</thead>
8 changes: 1 addition & 7 deletions src/components/ui/table/table-row.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
export { className as class };
</script>

<tr
class={cn(
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
className
)}
{...$$restProps}
>
<tr class={cn("border-b", className)} {...$$restProps}>
<slot />
</tr>
2 changes: 1 addition & 1 deletion src/components/ui/table/table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
export { className as class };
</script>

<div class="w-full overflow-auto">
<div class="w-full overflow-auto border-border border rounded-md">
<table class={cn("w-full caption-bottom text-sm", className)} {...$$restProps}>
<slot />
</table>
Expand Down
148 changes: 148 additions & 0 deletions src/content/api-reference/accordion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import type { APISchema } from "@/types";
import { asChild } from "./helpers";

export const root: APISchema = {
title: "Root",
description: "The root accordion component used to set and manage the state of the accordion.",
props: [
{
name: "multiple",
default: "false",
type: "boolean",
description: "Whether or not multiple accordion items can be active at the same time."
},
{
name: "disabled",
default: "false",
type: "boolean",
description: "Whether or not the accordion is disabled."
},
{
name: "value",
type: "string | undefined",
description: "The active accordion item value."
},
{
name: "onValueChange",
type: "(value: string | undefined) => void",
description: "A callback function called when the active accordion item value changes."
},
{
name: "value",
type: "string | undefined",
description: "The active accordion item value when `multiple` is true."
},
{
name: "onValueChange",
type: "(value: string[]) => void",
description:
"A callback function called when the active accordion item value changes when `multiple` is true."
}
],
dataAttributes: [
{
name: "orientation",
value: "'horizontal' | 'vertical'",
description: "The orientation of the accordion."
},
{
name: "melt-accordion",
value: "",
description: "Present on the root element."
}
]
};

const item: APISchema = {
title: "Item",
description: "An accordion item.",
props: [
asChild,
{
name: "value",
type: "string",
description: "The value of the accordion item."
},
{
name: "disabled",
default: "false",
type: "boolean",
description: "Whether or not the accordion item is disabled."
}
],
dataAttributes: [
{
name: "state",
value: "'open' | 'closed'",
description: "The state of the accordion item."
},
{
name: "disabled",
value: "",
description: "Present when the accordion item is disabled."
},
{
name: "melt-accordion-item",
value: "",
description: "Present on the accordion item elements."
}
]
};

const trigger: APISchema = {
title: "Trigger",
description: "The accordion item trigger, which opens and closes the accordion item.",
props: [asChild],
dataAttributes: [
{
name: "state",
value: "'open' | 'closed'",
description: "The state of the accordion item."
},
{
name: "disabled",
value: "",
description: "Present when the accordion item is disabled."
},
{
name: "value",
value: "",
description: "The value of the accordion item."
},
{
name: "melt-accordion-trigger",
value: "",
description: "Present on the accordion item elements."
}
]
};

const content: APISchema = {
title: "Content",
description: "The accordion item content, which is displayed when the item is open.",
props: [asChild],
dataAttributes: [
{
name: "state",
value: "'open' | 'closed'",
description: "The state of the accordion item."
},
{
name: "disabled",
value: "",
description: "Present when the accordion item is disabled."
},
{
name: "value",
value: "",
description: "The value of the accordion item."
},
{
name: "melt-accordion-content",
value: "",
description: "Present on the accordion item elements."
}
]
};

export const accordion = [root, item, trigger, content];
Loading

0 comments on commit 250a5b9

Please sign in to comment.