Skip to content

Commit

Permalink
prop field and collapsible
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Dec 7, 2024
1 parent 67890a6 commit 99d7bc9
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 50 deletions.
20 changes: 19 additions & 1 deletion docs/src/content/components/callout.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ section: Components
---

<script>
import { Callout } from "@svecodocs/kit";
import { Callout, PropField } from "@svecodocs/kit";
import Avocado from "phosphor-svelte/lib/Avocado";
</script>

Expand Down Expand Up @@ -86,3 +86,21 @@ This is an example of a note callout with a custom icon.
This is an example of a warning callout with a custom title.

</Callout>

## Props

<PropField name="type" type="'warning' | 'note' | 'danger' | 'tip' | 'success'" defaultValue="'note'">
The type of callout to display.
</PropField>

<PropField name="title" type="string">
Override the default title for the callout.
</PropField>

<PropField name="icon" type="Component">
Override the default icon for the callout.
</PropField>

<PropField name="children" type="Snippet">
The content to display inside of the callout's body.
</PropField>
8 changes: 7 additions & 1 deletion docs/src/content/components/card-grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ section: Components
---

<script>
import { CardGrid, Card } from "@svecodocs/kit";
import { CardGrid, Card, PropField } from "@svecodocs/kit";
import RocketLaunch from "phosphor-svelte/lib/RocketLaunch";
import Blueprint from "phosphor-svelte/lib/Blueprint";
import Binary from "phosphor-svelte/lib/Binary";
Expand Down Expand Up @@ -92,3 +92,9 @@ Use the `CardGrid` component to display a grid of [`Card`](/docs/components/card
content in your Markdown file.
</Card>
</CardGrid>

## Props

<PropField name="cols" type="number" defaultValue="2">
The number of columns to display the cards in. Uses flex column layout when in smaller viewports.
</PropField>
16 changes: 15 additions & 1 deletion docs/src/content/components/card.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ section: Components
---

<script>
import { Card } from "@svecodocs/kit";
import { Card, PropField } from "@svecodocs/kit";
import RocketLaunch from "phosphor-svelte/lib/RocketLaunch";
</script>

Expand Down Expand Up @@ -88,3 +88,17 @@ You can use the `horizontal` prop to display the card horizontally.
<Card title="A horizontal card" horizontal icon={RocketLaunch}>
You can use markdown in here, just ensure to include a space between the component and the content in your Markdown file.
</Card>

## Props

<PropField name="title" type="string" required>
The title to display in the card.
</PropField>

<PropField name="icon" type="Component">
The icon to display in the card.
</PropField>

<PropField name="children" type="Snippet">
The body content of the card.
</PropField>
4 changes: 4 additions & 0 deletions docs/src/content/components/checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ section: Components
<DemoContainer class="flex items-center gap-2.5 flex-wrap">
<Checkbox checked />
</DemoContainer>

## Props

See [Bits UI Checkbox](https://bits-ui.com/docs/components/checkbox) for available props.
49 changes: 49 additions & 0 deletions docs/src/content/components/collapsible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: Collapsible
description: Show and hide content in a collapsible container.
section: Components
---

<script>
import { Collapsible, DemoContainer, PropField } from "@svecodocs/kit";
</script>

## Usage

```svelte title="document.md"
<script>
import { Collapsible, DemoContainer } from "@svecodocs/kit";
</script>
<Collapsible title="more info">
<!-- space here so MD can render -->
To learn more about SvelteKit, check out the [SvelteKit documentation](https://svelte.dev/kit).
<!-- space here so MD can render -->
</Collapsible>
```

## Example

<Collapsible title="more info" class="mt-6">

To learn more about SvelteKit, check out the [SvelteKit documentation](https://svelte.dev/kit).

</Collapsible>

## Props

<PropField name="title" type="string">
The title to display in the trigger. "Hide" and "Show" prefix will be added automatically.
</PropField>

<PropField name="open" type="boolean" defaultValue="false">
Whether the content should be open or closed.
</PropField>

<PropField name="triggerContent" type="Snippet">
Override the content inside of the trigger button.
</PropField>

<PropField name="children" type="Snippet">
The content that is collapsible.
</PropField>
60 changes: 52 additions & 8 deletions docs/src/content/components/prop-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,68 @@ description: Display a prop field with a name, type, and description.
section: Components
---

<script>
import { PropField, Collapsible } from "@svecodocs/kit";
</script>

Use the `PropField` component to annotate props/params in your documentation.

## Usage

```svelte title="document.md"
<script>
import { PropField } from "@svecodocs/kit";
</script>
Work in progress.
<PropField name="checked" type="boolean" required defaultValue="false">
<!-- Space here-->
The checked state of the checkbox.
<!-- Space here-->
</PropField>
```

## API Reference
## Examples

### Props
### Basic

<PropField name="checked" type="boolean" defaultValue="false">
<PropField name="checked" type="boolean" defaultValue="false" required>
The checked state of the checkbox.
</PropField>

<PropField name="onCheckedChange" type="(checked: boolean) => void">
The name of the prop.
### Object

You can use `PropField` in combination with the [`Collapsible`](/docs/components/collapsible) component to represent more complex types.

```svelte title="document.md"
<script>
import { PropField, Collapsible } from "@svecodocs/kit";
</script>
<PropField name="options" type="CheckboxOptions" required>
<!-- Space here -->
Configuration options to customize the behavior of the `Checkbox` component.
<!-- Space here -->
<Collapsible title="properties">
<PropField name="width" type="number" required>
The width to apply to the checkbox.
</PropField>
<PropField name="height" type="number" required defaultValue="20">
The height to apply to the checkbox.
</PropField>
</Collapsible>
</PropField>
```

<PropField name="options" type="CheckboxOptions" required>

Configuration options to customize the behavior of the `Checkbox` component.

<PropField name="name" type="string" required>
The name used to submit the checkbox as a form field.
<Collapsible title="properties">
<PropField name="width" type="number" required>
The width to apply to the checkbox.
</PropField>
<PropField name="height" type="number" required defaultValue="20">
The height to apply to the checkbox.
</PropField>
</Collapsible>
</PropField>
4 changes: 4 additions & 0 deletions docs/src/content/components/switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ section: Components
<DemoContainer class="flex items-center gap-2.5 flex-wrap">
<Switch checked />
</DemoContainer>

## Props

See [Bits UI Switch](https://bits-ui.com/docs/components/switch) for available props.
16 changes: 15 additions & 1 deletion docs/src/content/components/tabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ section: Components
---

<script>
import { Tabs, TabItem, Callout } from "@svecodocs/kit";
import { Tabs, TabItem, Callout, PropField } from "@svecodocs/kit";
</script>

You can use the `Tabs` and `TabItem` components to create tabbed interfaces. A `label` prop must be provided to each `TabItem` which will be used to display the label. Whichever tab should be active by default is specified by the `value` prop on the `Tabs` component.
Expand Down Expand Up @@ -63,3 +63,17 @@ export async function load() {
<Callout type="note" class="mt-8">
If you plan to use markdown-specific syntax in your tabs, ensure you include a space between the component and the content in your Markdown file.
</Callout>

## Props

### Tabs

<PropField name="value" type="string" required>
The label of the tab to be active by default.
</PropField>

### TabItem

<PropField name="label" type="string" required>
The label to display for the tab.
</PropField>
2 changes: 1 addition & 1 deletion packages/kit/src/lib/components/card-grid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
setContext("is-grid", true);
</script>

<div class="grid {getCols()} mt-6 gap-5" data-card-grid="">
<div class="flex flex-col md:grid {getCols()} mt-6 gap-5" data-card-grid="">
{@render children?.()}
</div>
49 changes: 49 additions & 0 deletions packages/kit/src/lib/components/collapsible.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script lang="ts">
import { Collapsible, type WithoutChild } from "bits-ui";
import type { ComponentProps, Snippet } from "svelte";
import CaretRight from "phosphor-svelte/lib/CaretRight";
import { cn } from "$lib/utils.js";
import Button from "./ui/button/button.svelte";
let {
title,
open = $bindable(false),
children,
class: className,
triggerContent,
}: Omit<WithoutChild<ComponentProps<Collapsible.Root>>, "title"> & {
title: string;
triggerContent?: Snippet;
} = $props();
const triggerPrefix = $derived(open ? "Hide" : "Show");
const triggerText = $derived(`${triggerPrefix} ${title}`);
</script>

<Collapsible.Root bind:open class={cn("mt-3 rounded-lg border", className)}>
<Collapsible.Trigger>
{#snippet child({ props })}
<Button
{...props}
variant="ghost"
class={cn(
"border-border dark:data-[state=open]:bg-foreground/5 hover:dark:data-[state=open]:bg-foreground/7 dark:data-[state=open]:ring-foreground/5 hover:dark:data-[state=open]:ring-foreground/7 hover:bg-foreground/2 data-[state=open]:bg-foreground/2 hover:data-[state=open]:bg-foreground/3 data-[state=open]:ring-foreground/2 hover:data-[state=open]:ring-foreground/3 inline-flex w-full items-center justify-start gap-2 rounded-lg px-4 py-2.5 font-normal active:scale-100 data-[state=open]:rounded-b-none data-[state=open]:border-b data-[state=open]:[&>svg]:rotate-90"
)}
>
<CaretRight
class="text-muted-foreground size-4 transition-transform duration-150"
data-open={open ? "" : undefined}
data-closed={open ? undefined : ""}
/>
{#if triggerContent}
{@render triggerContent?.()}
{:else}
{triggerText}
{/if}
</Button>
{/snippet}
</Collapsible.Trigger>
<Collapsible.Content class={cn("px-4 pb-4 [&>p]:mt-4")}>
{@render children?.()}
</Collapsible.Content>
</Collapsible.Root>
48 changes: 31 additions & 17 deletions packages/kit/src/lib/components/prop-field.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import type { Snippet } from "svelte";
import Separator from "./ui/separator/separator.svelte";
import { cn } from "$lib/utils.js";
let {
name,
Expand All @@ -20,33 +21,46 @@
</script>

<div class="mt-6 flex flex-col gap-3">
<div class="flex items-center gap-3">
<div
class="text-brand-link dark:text-brand-link-hover relative rounded-[5px] py-[0.1875rem] font-mono"
>
{name}
</div>
<div
class="text-foreground/90 relative rounded-[5px] bg-gray-200/60 px-[0.375rem] py-[0.1875rem] font-mono text-[0.9em] dark:bg-gray-100/10"
>
{type}
<div class="flex flex-wrap items-center gap-1.5 md:gap-3">
<div class="flex flex-wrap items-center gap-1.5">
<div class="text-brand-700 dark:text-brand-400 relative font-mono text-sm md:text-base">
{name}<span class="text-muted-foreground text-sm md:text-base">:</span>
</div>
<div
class="text-foreground/90 relative min-w-fit rounded-[5px] bg-gray-200/60 px-[0.375rem] py-[0.1875rem] font-mono text-[0.75em] md:text-[0.9em] dark:bg-gray-100/10"
>
<span class="sr-only">type:</span>
{type}
</div>
</div>

{#if Boolean(defaultValue || required)}
<Separator orientation="vertical" class="h-5" />
{/if}
{#if defaultValue}
<div class="text-foreground flex items-center gap-1 font-mono">
default: <span
class="rounded-[5px] bg-gray-200/60 px-[0.375rem] py-[0.1875rem] font-mono text-[0.9em] dark:bg-gray-100/10"
>{defaultValue}</span
<div class="text-muted-foreground flex items-center font-mono">
<span class="text-sm md:text-base">
default<span class="text-muted-foreground">:</span>
</span>
<span
class="text-foreground/90 ml-1 min-w-fit rounded-[5px] bg-gray-200/60 px-[0.375rem] py-[0.1875rem] font-mono text-[0.75em] md:text-[0.9em] dark:bg-gray-100/10"
>
{defaultValue}
</span>
</div>
{#if required}
<Separator orientation="vertical" class="h-5" />
{/if}
{/if}
{#if required}
<span
class="relative rounded-[5px] bg-red-200 px-[0.375rem] py-[0.1875rem] font-mono text-[0.9em] text-red-900 dark:bg-red-500/20 dark:text-red-100"
>required</span
class="relative mr-auto min-w-fit rounded-[5px] bg-red-100 px-[0.375rem] py-[0.1875rem] font-mono text-[0.75em] text-red-900 md:text-[0.9em] dark:bg-red-500/20 dark:text-red-200"
>
required
</span>
{/if}
</div>
<div class="-mb-2">
<div class={cn("-mb-2 text-sm md:text-base [&>p]:text-sm md:[&>p]:text-base")}>
{#if description}
{description}
{:else}
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/lib/components/tabs/tabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<Tabs.Root class="relative mb-12 mt-6 w-full" {value}>
<Tabs.List class="w-full justify-start rounded-none bg-transparent p-0">
{#each ctx.items as item}
{#each ctx.items as item (item)}
<Tabs.Trigger
class="text-muted-foreground data-[state=active]:border-b-brand data-[state=active]:text-foreground relative h-9 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-medium shadow-none transition-none data-[state=active]:shadow-none"
value={item}
Expand Down
Loading

0 comments on commit 99d7bc9

Please sign in to comment.