Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create code switcher tab #8

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions components/content/ContentSwitcher.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script setup lang="ts">
defineProps<{
items: ContentSwitcherItem[];
}>();

const selectedIndex = ref(0);

function onTabChange(index: number) {
selectedIndex.value = index;
}
const route = useRoute();
</script>

<template>
<div>
<UTabs
:items="items"
:ui="{ list: { width: 'w-auto' } }"
@change="onTabChange"
/>
<div
v-for="(item, index) in items"
v-show="selectedIndex === index"
:key="item.partial"
>
<ContentQuery
v-slot="{ data }"
:path="$route.path"
find="one"
:where="{ _partial: true, _path: { $icontains: item.partial } }"
>
<ContentRenderer :value="data" />
</ContentQuery>
</div>
<UDivider />
</div>
</template>
16 changes: 16 additions & 0 deletions components/content/DisplayPartial.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup lang="ts">
defineProps<{
partial: string;
}>();
</script>

<template>
<ContentQuery
v-slot="{ data }"
path="_partials"
find="one"
:where="{ _partial: true, title: { $icontains: partial } }"
>
<ContentRenderer :value="data" />
</ContentQuery>
</template>
18 changes: 18 additions & 0 deletions content/10.getting-started/1.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ This template is a ready-to-use documentation template made with [Nuxt UI Pro](h
premium components built on top of [Nuxt UI](https://ui.nuxt.com) to create beautiful & responsive Nuxt applications in
minutes.

::content-switcher
---
items: [{
label: 'HardHat',
partial: '_getting-started/_aPartial'
}, {
label: 'Forge',
partial: '_getting-started/_anotherpartial'
Comment on lines +14 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perfect, being able to specify dedicated pages for each partial 💯

}]
---
::

There are already many websites based on this template:

- [Nuxt](https://nuxt.com) - The Nuxt website
Expand All @@ -17,6 +29,12 @@ There are already many websites based on this template:
- [Nuxt Devtools](https://devtools.nuxt.com) - The documentation of `@nuxt/devtools`
- [Nuxt Studio](https://nuxt.studio) - The pro version of Nuxt Content

::display-partial
---
partial: 'Setting up your wallet'
---
::

## Features

- Powered by [Nuxt 3](https://nuxt.com)
Expand Down
5 changes: 5 additions & 0 deletions content/10.getting-started/_getting-started/_aPartial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: A Partial
---

This is a partial that's coming from somewhere else!
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Another Partial
---

This is the second partial
9 changes: 9 additions & 0 deletions content/_partials/setting-up-your-wallet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Setting up your wallet
---

Here's how to setup your wallet, follow the instructions below:

1. Download wallet
2. ???
3. Profit
14 changes: 14 additions & 0 deletions types/CodeSwitcher.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare interface ContentSwitcherItem {
/**
* The label to display on the tab
*/
label: string;
/**
* The general path to the partial that is relative to the parent markdown.
*
* Example:
*
* "_getting-started/_aPartial" => `_getting-started/_aPartial.md`
*/
partial: string;
}
Loading