Skip to content

Commit

Permalink
add foldable
Browse files Browse the repository at this point in the history
  • Loading branch information
r4ai committed Apr 5, 2024
1 parent caa7970 commit 6ba8c82
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/website/src/pages/playground/_Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, type FC, useMemo, type ReactNode, useEffect } from "react"
import Editor from "@monaco-editor/react"
import { unified } from "unified"
import remarkParse from "remark-parse"
import remarkCallout from "@r4ai/remark-callout"
import remarkCallout, { defaultOptions } from "@r4ai/remark-callout"
import remarkRehype from "remark-rehype"
import rehypeStringify from "rehype-stringify"
import rehypeKatex from "rehype-katex"
Expand Down Expand Up @@ -134,7 +134,23 @@ const render = (html: string) =>
unified()
.use(remarkParse)
.use(remarkMath)
.use(remarkCallout)
.use(remarkCallout, {
root: (callout) => ({
tagName: callout.isFoldable ? "details" : "div",
properties: {
"data-callout": true,
"data-callout-type": callout.type,
open: callout.defaultFolded === undefined ? undefined : !callout.defaultFolded,
},
}),
title: (callout) => ({
tagName: callout.isFoldable ? "summary" : "div",
properties: {
"data-callout-title": true,
"data-is-foldable": String(callout.isFoldable),
},
}),
})
.use(remarkRehype)
.use(rehypeKatex)
.use(rehypeStringify)
Expand Down
19 changes: 19 additions & 0 deletions packages/website/src/pages/playground/_callout.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
content: "Note";
}

&[data-is-foldable="true"] {
& {
@apply cursor-pointer;
}

&::after {
@apply w-full bg-contain bg-right bg-no-repeat;
content: "Note";

/* lucide:chevron-right */
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxZW0iIGhlaWdodD0iMWVtIiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0iIzg4ODg4OCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjIiIGQ9Im05IDE4bDYtNmwtNi02Ii8+PC9zdmc+");
}
}

&::before {
@apply mt-1 block h-5 w-5 bg-current content-[""];
mask-repeat: no-repeat;
Expand All @@ -37,6 +51,11 @@
}
}

[data-callout][open] > [data-callout-title]::after {
/* lucide:chevron-down */
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxZW0iIGhlaWdodD0iMWVtIiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0iIzg4ODg4OCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjIiIGQ9Im02IDlsNiA2bDYtNiIvPjwvc3ZnPg==");
}

[data-callout][data-callout-type="info"] {
& {
@apply border-blue-600/20 bg-blue-400/20 dark:border-blue-800/20 dark:bg-blue-600/10;
Expand Down
5 changes: 5 additions & 0 deletions packages/website/src/pages/playground/a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6ba8c82

Please sign in to comment.