diff --git a/src/components/CodeBlock/CodeBlock.tsx b/src/components/CodeBlock/CodeBlock.tsx index 2f6875e3d..3378074ec 100644 --- a/src/components/CodeBlock/CodeBlock.tsx +++ b/src/components/CodeBlock/CodeBlock.tsx @@ -33,6 +33,7 @@ export const CodeBlock = component$(({ content, language }) => { }) const copyLabel = useSignal('Copy') + const isCollapsed = useSignal(true) const copy$ = $(() => { navigator.clipboard.writeText(content) @@ -43,18 +44,29 @@ export const CodeBlock = component$(({ content, language }) => { }) return ( -
+
{language}
-
-
+      
+
+      
     
) }) diff --git a/src/components/__Preview/__Preview.tsx b/src/components/__Preview/__Preview.tsx index 8a43e122f..55d45fea3 100644 --- a/src/components/__Preview/__Preview.tsx +++ b/src/components/__Preview/__Preview.tsx @@ -12,6 +12,8 @@ import styles from './preview.css?inline' type PreviewProps = PropsOf<'iframe'> & { url: string + title: string + description?: string } type PreviewDisplaySize = 'mobile' | 'tablet' | 'desktop' @@ -24,10 +26,11 @@ const getExampleFilePath = server$(function (url: string) { const getExampleCode = server$(function (url: string) { const rootDir = process.cwd() const exampleUrl = `${rootDir}/src/routes${url}/index@examples.tsx` - return fs.readFileSync(exampleUrl, 'utf-8') + const codeContent = fs.readFileSync(exampleUrl, 'utf-8') + return codeContent.replace(/\/\*\*[\s\S]*?\*\//, '').trim() }) -export const Preview = component$(({ url, class: classNames, ...props }) => { +export const Preview = component$(({ url, class: classNames, title, ...props }) => { useStyles$(styles) const { isDark } = useDark() @@ -63,6 +66,8 @@ export const Preview = component$(({ url, class: classNames, ...pr return (
+

{title}

+ {props.description &&

{props.description}

}
  • diff --git a/src/routes/docs/components/accordion/index.tsx b/src/routes/docs/components/accordion/index.tsx index 63fd5cf81..75ee4e6b3 100644 --- a/src/routes/docs/components/accordion/index.tsx +++ b/src/routes/docs/components/accordion/index.tsx @@ -1,33 +1,49 @@ -import { component$ } from '@builder.io/qwik' +import { component$, useComputed$ } from '@builder.io/qwik' +import { server$ } from '@builder.io/qwik-city' import { Preview } from '~/components/__Preview/__Preview' +import fs from 'fs' -export default component$(() => { - return ( -
    -
    -

    Default accordion

    - -
    +export const getAccordionsPreview = server$(() => { + function getTitleAndDescription(fileContent: string) { + const pattern = /\/\*\*[^]*?title:\s*(.*?)\s*\*[^]*?description:\s*(.*?)\s*\*\// + const match = pattern.exec(fileContent) -
    -

    Always open accordion

    - -
    + let title = '' + let description = '' -
    -

    Flush accordion

    - -
    + if (match) { + title = match[1].trim() + description = match[2].trim() + } -
    -

    Styling accordion

    - -
    + return { + title, + description, + } + } + + const accordions = fs.readdirSync('src/routes/examples/accordion').map((file) => { + const path = 'src/routes/examples/accordion/' + file + const content = fs.readFileSync(path + '/index@examples.tsx', 'utf-8') + const { title, description } = getTitleAndDescription(content) + return { + title, + description, + url: '/examples/accordion/' + file, + height: '300', + } + }) + return accordions +}) -
    -

    Closed first item

    - -
    +export default component$(() => { + const accordions = useComputed$(() => getAccordionsPreview()) + + return ( +
    + {accordions.value.map((accordion) => ( + + ))}
    ) }) diff --git a/src/routes/docs/components/navbar/index.tsx b/src/routes/docs/components/navbar/index.tsx index 675c262e6..5402544c4 100644 --- a/src/routes/docs/components/navbar/index.tsx +++ b/src/routes/docs/components/navbar/index.tsx @@ -13,8 +13,12 @@ export default component$(() => { return (