Skip to content

Commit 1409082

Browse files
committed
feat(ui): add scroll area component and expand markdown renderer
1 parent db5d3d2 commit 1409082

File tree

5 files changed

+84
-7
lines changed

5 files changed

+84
-7
lines changed

packages/ui/src/components/markdown/Markdown.svelte

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<script lang="ts">
2-
import Markdown from "svelte-exmarkdown"
3-
import type { Plugin } from "svelte-exmarkdown"
42
import rehypeShikiFromHighlighter from "@shikijs/rehype/core"
3+
import rehypeClassNames from "rehype-class-names"
4+
import rehypeKatex from "rehype-katex"
5+
import remarkMath from "remark-math"
56
import { createHighlighterCoreSync } from "shiki/core"
67
import { createJavaScriptRegexEngine } from "shiki/engine/javascript"
7-
import ts from "shiki/langs/typescript.mjs"
8+
import html from "shiki/langs/html.mjs"
9+
import json from "shiki/langs/json.mjs"
10+
import rust from "shiki/langs/rust.mjs"
811
import svelte from "shiki/langs/svelte.mjs"
12+
import ts from "shiki/langs/typescript.mjs"
913
import vitesseDark from "shiki/themes/vitesse-dark.mjs"
10-
import rehypeKatex from "rehype-katex"
11-
import remarkMath from "remark-math"
12-
import rehypeClassNames from "rehype-class-names"
14+
import Markdown from "svelte-exmarkdown"
15+
import type { Plugin } from "svelte-exmarkdown"
1316
import Pre from "./Pre.svelte"
1417
1518
const addClass: Plugin = {
@@ -26,7 +29,7 @@
2629
rehypeShikiFromHighlighter,
2730
createHighlighterCoreSync({
2831
themes: [vitesseDark],
29-
langs: [ts, svelte],
32+
langs: [ts, svelte, json, html, rust],
3033
engine: createJavaScriptRegexEngine()
3134
}),
3235
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Scrollbar from "./scroll-area-scrollbar.svelte";
2+
import Root from "./scroll-area.svelte";
3+
4+
export {
5+
Root,
6+
Scrollbar,
7+
//,
8+
Root as ScrollArea,
9+
Scrollbar as ScrollAreaScrollbar,
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script lang="ts">
2+
import { ScrollArea as ScrollAreaPrimitive, type WithoutChild } from "bits-ui"
3+
import { cn } from "../../../utils"
4+
5+
let {
6+
ref = $bindable(null),
7+
class: className,
8+
orientation = "vertical",
9+
children,
10+
...restProps
11+
}: WithoutChild<ScrollAreaPrimitive.ScrollbarProps> = $props()
12+
</script>
13+
14+
<ScrollAreaPrimitive.Scrollbar
15+
bind:ref
16+
{orientation}
17+
class={cn(
18+
"flex touch-none select-none transition-colors",
19+
orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-px",
20+
orientation === "horizontal" && "h-2.5 w-full border-t border-t-transparent p-px",
21+
className
22+
)}
23+
{...restProps}
24+
>
25+
{@render children?.()}
26+
<ScrollAreaPrimitive.Thumb
27+
class={cn("bg-border relative rounded-full", orientation === "vertical" && "flex-1")}
28+
/>
29+
</ScrollAreaPrimitive.Scrollbar>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script lang="ts">
2+
import { ScrollArea as ScrollAreaPrimitive, type WithoutChild } from "bits-ui"
3+
import { cn } from "../../../utils"
4+
import { Scrollbar } from "./index.js"
5+
6+
let {
7+
ref = $bindable(null),
8+
viewportRef = $bindable(null),
9+
class: className,
10+
orientation = "vertical",
11+
scrollbarXClasses = "",
12+
scrollbarYClasses = "",
13+
children,
14+
...restProps
15+
}: WithoutChild<ScrollAreaPrimitive.RootProps> & {
16+
viewportRef?: HTMLDivElement | null
17+
orientation?: "vertical" | "horizontal" | "both" | undefined
18+
scrollbarXClasses?: string | undefined
19+
scrollbarYClasses?: string | undefined
20+
} = $props()
21+
</script>
22+
23+
<ScrollAreaPrimitive.Root bind:ref {...restProps} class={cn("relative overflow-hidden", className)}>
24+
<ScrollAreaPrimitive.Viewport bind:ref={viewportRef} class="h-full w-full rounded-[inherit]">
25+
{@render children?.()}
26+
</ScrollAreaPrimitive.Viewport>
27+
{#if orientation === "vertical" || orientation === "both"}
28+
<Scrollbar orientation="vertical" class={scrollbarYClasses} />
29+
{/if}
30+
{#if orientation === "horizontal" || orientation === "both"}
31+
<Scrollbar orientation="horizontal" class={scrollbarXClasses} />
32+
{/if}
33+
<ScrollAreaPrimitive.Corner />
34+
</ScrollAreaPrimitive.Root>

packages/ui/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export { default as RetroGrid } from "./components/animation/RetroGrid.svelte"
1515
export { default as AuroraText } from "./components/animation/AuroraText.svelte"
1616
export * as Constants from "./constants"
1717
export * as Form from "./components/ui/form"
18+
export * as ScrollArea from "./components/ui/scroll-area"
1819
export { default as ModeToggle } from "./components/theme/mode-toggle.svelte"

0 commit comments

Comments
 (0)