-
Notifications
You must be signed in to change notification settings - Fork 26
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
7 changed files
with
375 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<script setup lang="ts"> | ||
import { | ||
computed, | ||
defineProps, | ||
onBeforeMount, | ||
onBeforeUnmount, | ||
watch, | ||
withDefaults, | ||
} from 'vue' | ||
import {AddTabKey, DeleteTabKey, TabsProviderKey, UpdateTabKey} from './symbols' | ||
import {injectStrict} from './utils' | ||
type Props = { | ||
id?: string | ||
name: string | ||
isDisabled?: boolean | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
id: undefined, | ||
isDisabled: false, | ||
}) | ||
const tabsProvider = injectStrict(TabsProviderKey) | ||
const addTab = injectStrict(AddTabKey) | ||
const updateTab = injectStrict(UpdateTabKey) | ||
const deleteTab = injectStrict(DeleteTabKey) | ||
const id = computed(() => | ||
props.id ? props.id : props.name.toLowerCase().replace(/ /g, '-') | ||
) | ||
const paneId = computed(() => id.value + '-pane') | ||
const isActive = computed(() => id.value === tabsProvider.activeId) | ||
watch( | ||
() => Object.assign({}, props), | ||
() => { | ||
updateTab(id.value, { | ||
name: props.name, | ||
isDisabled: props.isDisabled, | ||
id: id.value, | ||
paneId: paneId.value, | ||
}) | ||
} | ||
) | ||
onBeforeMount(() => { | ||
addTab({ | ||
name: props.name, | ||
isDisabled: props.isDisabled, | ||
id: id.value, | ||
paneId: paneId.value, | ||
}) | ||
}) | ||
onBeforeUnmount(() => { | ||
deleteTab(id.value) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<section | ||
v-show="isActive" | ||
:id="paneId" | ||
ref="tab" | ||
class="Tab" | ||
:data-tab-id="id" | ||
:aria-hidden="!isActive" | ||
role="tabpanel" | ||
tabindex="-1" | ||
> | ||
<slot /> | ||
</section> | ||
</template> | ||
|
||
<style lang="stylus" scoped> | ||
.Tab | ||
height 100% | ||
</style> |
Oops, something went wrong.