-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ZTL-UwU <[email protected]>
- Loading branch information
Showing
9 changed files
with
168 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,53 @@ | ||
<template> | ||
<render class="[&:not(:first-child)]:mt-5" /> | ||
<UiCard class="[&:not(:first-child)]:mt-5"> | ||
<UiScrollArea> | ||
<div class="border-b p-0.5 flex text-sm relative overflow-x-auto"> | ||
<div class="flex p-1"> | ||
<div | ||
v-for="(slot, i) in ($slots.default?.() ?? [])" | ||
:key="`${i}${slot?.props?.filename}`" | ||
:value="slot?.props?.filename" | ||
class="flex px-3 py-1.5 rounded-md text-muted-foreground transition-all duration-75 cursor-pointer" | ||
:class="[activeTabIndex === i && 'bg-muted text-primary']" | ||
@mousedown.left="activeTabIndex = i" | ||
> | ||
<Icon | ||
v-if="getIcon(slot?.props?.filename, slot?.props?.language)" | ||
:name="getIcon(slot?.props?.filename, slot?.props?.language)!" | ||
class="self-center mr-1.5" | ||
/> | ||
{{ slot?.props?.filename }} | ||
</div> | ||
</div> | ||
<CodeCopy | ||
v-if="selected?.props?.code && selected?.type !== 'preview'" | ||
class="self-center ml-auto mr-3 pl-2" | ||
:code="selected.props.code" | ||
/> | ||
</div> | ||
<ScrollBar orientation="horizontal" /> | ||
</UiScrollArea> | ||
|
||
<div | ||
v-for="(slot, i) in $slots.default?.() ?? []" | ||
v-show="activeTabIndex === i" | ||
:key="`${i}${slot?.props?.filename}`" | ||
:value="slot?.props?.filename" | ||
class="mt-0" | ||
> | ||
<component :is="slot" :in-group="true" /> | ||
</div> | ||
</UiCard> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import CodeGroupHeader from './CodeGroupHeader.vue'; | ||
import { Card as UiCard } from '@/components/ui/card/index'; | ||
const _slots = useSlots(); | ||
const activeTabIndex = ref(0); | ||
const selected = computed(() => { | ||
return useSlots().default?.()[activeTabIndex.value]; | ||
}); | ||
function isTag(slot: any, tag: string) { | ||
return slot.type && slot.type.tag && slot.type.tag === tag; | ||
} | ||
function checkTag(slot: any) { | ||
return isTag(slot, 'code-block') || isTag(slot, 'code') || isTag(slot, 'pre') || isTag(slot, 'preview'); | ||
} | ||
function onChangeActiveTab(index: number) { | ||
activeTabIndex.value = index; | ||
} | ||
function render() { | ||
const _slotsDefault = _slots?.default?.() || []; | ||
const tabs = _slotsDefault | ||
.filter(slot => checkTag(slot)) | ||
.map((slot, index) => { | ||
return { | ||
label: slot?.props?.filename || slot?.props?.label || `${index}`, | ||
language: slot?.props?.language || null, | ||
code: slot?.props?.code || '', | ||
}; | ||
}); | ||
return h( | ||
UiCard, | ||
() => [ | ||
h( | ||
CodeGroupHeader, | ||
{ | ||
'activeTabIndex': activeTabIndex.value, | ||
tabs, | ||
'onUpdate:activeTabIndex': onChangeActiveTab, | ||
}, | ||
), | ||
h( | ||
'div', | ||
_slotsDefault.map((slot, index) => { | ||
if (slot.props && checkTag(slot)) | ||
slot.props.inGroup = true; | ||
return h( | ||
'div', | ||
{ | ||
style: { | ||
display: index === activeTabIndex.value ? 'block' : 'none', | ||
}, | ||
}, | ||
[ | ||
checkTag(slot) | ||
? slot | ||
: h( | ||
'div', | ||
[(slot.children as any)?.default?.() || h('div')], | ||
), | ||
], | ||
); | ||
}), | ||
), | ||
], | ||
); | ||
const iconMap = new Map(Object.entries(useConfig().value.main.codeIcon)); | ||
function getIcon(filename: string, language: string) { | ||
return iconMap.get(filename?.toLowerCase()) || iconMap.get(language); | ||
} | ||
</script> |
This file was deleted.
Oops, something went wrong.
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,5 +1,5 @@ | ||
<template> | ||
<div class="p-3 bg-muted/20"> | ||
<div class="p-3"> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<template> | ||
<UiTabs | ||
class="[&:not(:first-child)]:mt-5" | ||
:default-value="($slots.default?.() ?? [])[0]?.props?.label" | ||
> | ||
<UiTabsList> | ||
<UiTabsTrigger | ||
v-for="(slot, i) in $slots.default?.() ?? []" | ||
:key="`${i}${slot?.props?.label}`" | ||
:value="slot?.props?.label" | ||
> | ||
<Icon v-if="slot?.props?.icon" :name="slot?.props?.icon" class="mr-1" /> | ||
{{ slot?.props?.label }} | ||
</UiTabsTrigger> | ||
</UiTabsList> | ||
|
||
<UiTabsContent | ||
v-for="(slot, i) in $slots.default?.() ?? []" | ||
:key="`${i}${slot?.props?.label}`" | ||
:value="slot?.props?.label" | ||
> | ||
<component :is="slot" /> | ||
</UiTabsContent> | ||
</UiTabs> | ||
</template> |
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
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,7 +1,7 @@ | ||
{ | ||
"name": "shadcn-docs-nuxt", | ||
"type": "module", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Tony Zhang <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://shadcn-docs-nuxt.vercel.app/", | ||
|