-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
130 additions
and
21 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Tab | ||
|
||
## 基础用法 | ||
|
||
```vue demo | ||
<script setup> | ||
import { ref } from 'vue' | ||
const items = [ | ||
{ | ||
key: '1', | ||
label: 'Tab 1', | ||
}, | ||
{ | ||
key: '2', | ||
label: 'Tab 2', | ||
}, | ||
{ | ||
key: '3', | ||
label: 'Tab 3', | ||
}, | ||
] | ||
const current = ref('1') | ||
</script> | ||
<template> | ||
<Tabs :items="items" @change="current = $event"></Tabs> | ||
current: Tab {{ current }} | ||
</template> | ||
``` | ||
|
||
## 内容插槽 | ||
|
||
```vue demo | ||
<script setup> | ||
const items = [ | ||
{ | ||
key: '1', | ||
label: 'Tab 1', | ||
}, | ||
{ | ||
key: '2', | ||
label: 'Tab 2', | ||
}, | ||
{ | ||
key: '3', | ||
label: 'Tab 3', | ||
}, | ||
] | ||
</script> | ||
<template> | ||
<Tabs :items="items"> | ||
<template #default="{ current }"> | ||
<div>current: Tab {{ current }}</div> | ||
</template> | ||
</Tabs> | ||
</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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script setup lang="ts"> | ||
import { ref, computed, type PropType } from 'vue' | ||
defineOptions({ name: 'Tabs' }) | ||
const emit = defineEmits<{ change: [key: string] }>() | ||
const slots = defineSlots<{ default?(props: { current: string }): any }>() | ||
const props = defineProps({ | ||
current: { type: String, default: '' }, | ||
items: { | ||
type: Array as PropType< | ||
{ | ||
key: string | ||
label: string | ||
}[] | ||
>, | ||
default: () => [], | ||
}, | ||
}) | ||
const keys = computed(() => props.items.map(item => item.key)) | ||
const currentKey = ref(keys.value.includes(props.current) ? props.current : keys.value[0]) | ||
const clickHandler = (key: string) => { | ||
if (currentKey.value !== key) { | ||
currentKey.value = key | ||
emit('change', key) | ||
} | ||
} | ||
</script> | ||
<template> | ||
<div v-if="items.length > 0" class="border-b border-slate-200 dark:border-slate-700"> | ||
<nav class="flex space-x-1"> | ||
<button | ||
v-for="item in props.items" | ||
type="button" | ||
:data-active="currentKey === item.key" | ||
class="inline-flex items-center gap-x-2 whitespace-nowrap border-b-2 border-transparent px-1 py-2 text-sm text-slate-500 hover:text-primary-500 focus:text-primary-500 focus:outline-none disabled:pointer-events-none disabled:opacity-50 data-[active='true']:border-primary-500 data-[active='true']:font-semibold data-[active='true']:text-primary-500 dark:text-slate-400 dark:data-[active='true']:text-primary-500" | ||
role="tab" | ||
@click="clickHandler(item.key)" | ||
> | ||
{{ item.label }} | ||
</button> | ||
</nav> | ||
<div> | ||
<template v-if="keys.includes(currentKey)"> | ||
<slot name="default" :current="currentKey" /> | ||
</template> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Tabs } from './Tabs.vue' |
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