Skip to content

useContentContainer ​

Introduction ​

TIP

Optionally, the component <ContentContainer> can also be used as a wrapper.

The composable useContentContainer() is used to map the depth of the page structure.

With each call of useContentContainer() in nested components, the level of the element structure is increased by one level.

The appropriate HTML element for the page structure is determined based on the level. (e.g. main, section, article)

vue
<template>
  <component v-if="currentTag" :is="currentTag">
    <slot />
  </component>
  <slot v-else />
</template>

<script setup>
import { useContentContainer } from 'vue-semantic-structure';

const { currentTag } = useContentContainer();
</script>

Types ​

ts
declare function useContentContainer(options?: ContentContainerOptions): ContentContainerReturn;

declare interface ContentContainerOptions {
  tag?: string;
  contentTags?: Array<string>;
  rootTags?: Array<string>;
  level?: number;
}

declare interface ContentContainerReturn {
  parentLevel: ComputedRef<number>;
  currentLevel: ComputedRef<number>;
  currentTag: ComputedRef<string>;
}

Options ​

PropertyTypeDescriptionDefault Value
tagStringCan be used to overwrite the tag.undefined
contentTagsArrayAvailable tags for the content structure.inject('semanticStructure_contentTags', ['article', 'section'])
rootTagsArrayAvailable tags for the root structure.inject('semanticStructure_rootTags', ['main'])
levelNumberCan be used to overwrite the level.undefined

Result ​

PropertyTypeDescription
parentLevelComputedRef<Number>;Get parent level.
currentLevelComputedRef<Number>Get current level.
currentTagComputedRef<String>Get current html tag.