-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
252 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.