-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from xmimiex/feat/preview
feat: add expand and title + description
- Loading branch information
Showing
9 changed files
with
91 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<section id="accordions"> | ||
<div> | ||
<h2 class="my-3">Default accordion</h2> | ||
<Preview url="/examples/accordion/default-accordion" height="300" /> | ||
</div> | ||
export const getAccordionsPreview = server$(() => { | ||
function getTitleAndDescription(fileContent: string) { | ||
const pattern = /\/\*\*[^]*?title:\s*(.*?)\s*\*[^]*?description:\s*(.*?)\s*\*\// | ||
const match = pattern.exec(fileContent) | ||
|
||
<div> | ||
<h2 class="my-3">Always open accordion</h2> | ||
<Preview url="/examples/accordion/always-open-accordion" height="300" /> | ||
</div> | ||
let title = '' | ||
let description = '' | ||
|
||
<div> | ||
<h2 class="my-3">Flush accordion</h2> | ||
<Preview url="/examples/accordion/flush-accordion" height="300" /> | ||
</div> | ||
if (match) { | ||
title = match[1].trim() | ||
description = match[2].trim() | ||
} | ||
|
||
<div> | ||
<h2 class="my-3">Styling accordion</h2> | ||
<Preview url="/examples/accordion/styling-accordion" height="300" /> | ||
</div> | ||
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 | ||
}) | ||
|
||
<div> | ||
<h2 class="my-3">Closed first item</h2> | ||
<Preview url="/examples/accordion/closed-first-accordion" height="300" /> | ||
</div> | ||
export default component$(() => { | ||
const accordions = useComputed$(() => getAccordionsPreview()) | ||
|
||
return ( | ||
<section class="flex flex-col gap-8"> | ||
{accordions.value.map((accordion) => ( | ||
<Preview title={accordion.title} url={accordion.url} description={accordion.description} height={accordion.height} /> | ||
))} | ||
</section> | ||
) | ||
}) |
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
4 changes: 4 additions & 0 deletions
4
src/routes/examples/accordion/always-open-accordion/index@examples.tsx
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
4 changes: 4 additions & 0 deletions
4
src/routes/examples/accordion/closed-first-accordion/index@examples.tsx
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
5 changes: 5 additions & 0 deletions
5
src/routes/examples/accordion/default-accordion/index@examples.tsx
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
5 changes: 5 additions & 0 deletions
5
src/routes/examples/accordion/flush-accordion/index@examples.tsx
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
5 changes: 5 additions & 0 deletions
5
src/routes/examples/accordion/styling-accordion/index@examples.tsx
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