-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): add tabs card variant
Signed-off-by: ZTL-UwU <zhangtianli2006@163.com>
- Loading branch information
Showing
5 changed files
with
122 additions
and
103 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,55 +1,13 @@ | ||
<template> | ||
<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> | ||
<render /> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import ScrollBar from '../ui/scroll-area/ScrollBar.vue'; | ||
const activeTabIndex = ref(0); | ||
const selected = computed(() => { | ||
return useSlots().default?.()[activeTabIndex.value]; | ||
}); | ||
import Tabs from './Tabs.vue'; | ||
const iconMap = new Map(Object.entries(useConfig().value.main.codeIcon)); | ||
function getIcon(filename: string, language: string) { | ||
return iconMap.get(filename?.toLowerCase()) || iconMap.get(language); | ||
const _slots = useSlots(); | ||
function render() { | ||
const slots = _slots?.default?.() || []; | ||
return h(Tabs, { variant: 'card' }, slots); | ||
} | ||
</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,25 +1,94 @@ | ||
<template> | ||
<UiTabs | ||
v-if="variant === 'separate'" | ||
class="[&:not(:first-child)]:mt-5" | ||
:default-value="($slots.default?.() ?? [])[0]?.props?.label" | ||
:default-value="label(($slots.default?.() ?? [])[0]?.props)" | ||
> | ||
<UiTabsList> | ||
<UiTabsTrigger | ||
v-for="(slot, i) in $slots.default?.() ?? []" | ||
:key="`${i}${slot?.props?.label}`" | ||
:value="slot?.props?.label" | ||
:key="`${i}${label(slot.props)}`" | ||
:value="label(slot.props)" | ||
> | ||
<Icon v-if="slot?.props?.icon" :name="slot?.props?.icon" class="mr-1" /> | ||
{{ slot?.props?.label }} | ||
<Icon | ||
v-if="icon(slot?.props)" | ||
:name="icon(slot?.props)!" | ||
class="self-center mr-1.5" | ||
/> | ||
{{ label(slot.props) }} | ||
</UiTabsTrigger> | ||
</UiTabsList> | ||
|
||
<UiTabsContent | ||
v-for="(slot, i) in $slots.default?.() ?? []" | ||
:key="`${i}${slot?.props?.label}`" | ||
:value="slot?.props?.label" | ||
:key="`${i}${label(slot.props)}`" | ||
:value="label(slot.props)" | ||
> | ||
<component :is="slot" /> | ||
</UiTabsContent> | ||
</UiTabs> | ||
|
||
<UiCard v-else-if="variant === 'card'" 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}${label(slot.props)}`" | ||
:value="label(slot.props)" | ||
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="icon(slot?.props)" | ||
:name="icon(slot?.props)!" | ||
class="self-center mr-1.5" | ||
/> | ||
{{ label(slot.props) }} | ||
</div> | ||
</div> | ||
<CodeCopy | ||
v-if="$slots.default?.()[activeTabIndex]?.props?.code" | ||
class="self-center ml-auto mr-3 pl-2" | ||
:code="$slots.default?.()[activeTabIndex]?.props?.code" | ||
/> | ||
</div> | ||
<ScrollBar orientation="horizontal" /> | ||
</UiScrollArea> | ||
|
||
<div | ||
v-for="(slot, i) in $slots.default?.() ?? []" | ||
v-show="activeTabIndex === i" | ||
:key="`${i}${label(slot.props)}`" | ||
:value="label(slot.props)" | ||
class="mt-0" | ||
:class="[padded && ($slots.default?.()[activeTabIndex]?.type as any).tag !== 'pre' && 'p-3']" | ||
> | ||
<component :is="slot" :in-group="true" /> | ||
</div> | ||
</UiCard> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import ScrollBar from '../ui/scroll-area/ScrollBar.vue'; | ||
withDefaults(defineProps<{ | ||
variant?: 'separate' | 'card'; | ||
padded?: boolean; | ||
}>(), { | ||
variant: 'separate', | ||
padded: true, | ||
}); | ||
const activeTabIndex = ref(0); | ||
const iconMap = new Map(Object.entries(useConfig().value.main.codeIcon)); | ||
function icon(props: any) { | ||
return props?.icon || iconMap.get(props?.filename?.toLowerCase()) || iconMap.get(props?.language); | ||
} | ||
function label(props: any) { | ||
return props?.label || props?.filename; | ||
} | ||
</script> |
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