Skip to content

Components โ€‹

The Vue package provides a set of components that wrap the core functionality of Compote.

Available components: CCollapse ยท CCollapseTrigger ยท CDrag ยท CDrilldown ยท CDrilldownMenu ยท CDrilldownNext ยท CDrilldownBack ยท CDropdown ยท CDropdownMenu ยท CDropdownTrigger ยท CMarquee

All components support the as prop, which lets you change the rendered HTML tag or pass a custom Vue component. They also forward attributes via v-bind="$attrs" and provide a default slot for content.

WARNING

You need to import the CSS manually to make the components work.

ts
import 'compotes/css'

or individually per component

ts
import 'compotes/css/collapse'

CCollapse โ€‹

A collapsible component that can show or hide content.

Usage โ€‹

vue
<script setup lang="ts">
import { CCollapse, CCollapseTrigger } from '@compotes/vue'
</script>

<template>
  <div>
    <CCollapseTrigger aria-controls="my-collapse">
      Toggle
    </CCollapseTrigger>
    <CCollapse id="my-collapse">
      <p>Collapsible content here.</p>
    </CCollapse>
  </div>
</template>

Props โ€‹

NameTypeDefaultDescription
asstring | Component'div'The HTML tag or component to render.
idstringrequiredThe unique identifier for the collapse. Used to link with CCollapseTrigger via aria-controls.
optionsCollapseOptions-Configuration options for the collapse instance. See Collapse options.
defaultOpenbooleanfalseWhether the collapse should be open by default. Adds the c-collapse--show class on mount.

Events โ€‹

NamePayloadDescription
initCustomEvent<Collapse>Emitted when the collapse instance is initialized.
showCustomEvent<Collapse>Emitted when the collapse starts showing.
shownCustomEvent<Collapse>Emitted when the collapse has finished showing.
hideCustomEvent<Collapse>Emitted when the collapse starts hiding.
hiddenCustomEvent<Collapse>Emitted when the collapse has finished hiding.
updateCustomEvent<Collapse>Emitted when the collapse state updates.
destroyCustomEvent<Collapse>Emitted when the collapse instance is destroyed.

Slots โ€‹

NameDescription
defaultThe collapse content, including trigger and collapsible elements.

Exposed โ€‹

The component exposes the underlying collapse composable return value (state + actions). See useCollapse.

CCollapseTrigger โ€‹

A button component to toggle the CCollapse. Can be placed inside or outside a CCollapse component.

Props โ€‹

NameTypeDefaultDescription
asstring | Component'button'The HTML tag or component to render.
ariaControlsstringrequiredThe ID of the collapse element this trigger controls. Sets the aria-controls attribute.

Slots โ€‹

NameDescription
defaultThe trigger button content.

INFO

When rendered as a button, the component automatically sets type="button".

To link the trigger with a collapse element, pass the collapse's id to the CCollapseTrigger's aria-controls prop. This sets the aria-controls attribute for proper accessibility.

The component applies the c-collapse-trigger CSS class.

CDrag โ€‹

A click-and-drag scrollable component.

Usage โ€‹

vue
<script setup lang="ts">
import { CDrag } from '@compotes/vue'
</script>

<template>
  <CDrag>
    <div>Drag me!</div>
  </CDrag>
</template>

Props โ€‹

NameTypeDefaultDescription
asstring | Component'div'The HTML tag or component to render.
optionsDragOptions-Configuration options for the drag instance. See Drag options.

Events โ€‹

NamePayloadDescription
initCustomEvent<Drag>Emitted when the drag instance is initialized.
startCustomEvent<Drag>Emitted when dragging starts.
endCustomEvent<Drag>Emitted when dragging ends.
destroyCustomEvent<Drag>Emitted when the drag instance is destroyed.

Slots โ€‹

NameDescription
defaultThe draggable content.

Exposed โ€‹

The component exposes the underlying drag composable return value (state + actions). See useDrag.

CDrilldown โ€‹

A drilldown menu component for hierarchical navigation.

Usage โ€‹

vue
<script setup lang="ts">
import {
  CDrilldown,
  CDrilldownBack,
  CDrilldownMenu,
  CDrilldownNext,
} from '@compotes/vue'
</script>

<template>
  <CDrilldown>
    <CDrilldownMenu>
      <li>
        <CDrilldownNext>Fruits</CDrilldownNext>
        <CDrilldownMenu>
          <li><CDrilldownBack>Back</CDrilldownBack></li>
          <li>Apple</li>
          <li>Banana</li>
        </CDrilldownMenu>
      </li>
      <li>
        <CDrilldownNext>Vegetables</CDrilldownNext>
        <CDrilldownMenu>
          <li><CDrilldownBack>Back</CDrilldownBack></li>
          <li>Carrot</li>
          <li>Broccoli</li>
        </CDrilldownMenu>
      </li>
    </CDrilldownMenu>
  </CDrilldown>
</template>

Props โ€‹

NameTypeDefaultDescription
asstring | Component'nav'The HTML tag or component to render.
optionsDrilldownOptions-Configuration options for the drilldown instance. See Drilldown options.

Events โ€‹

NamePayloadDescription
initCustomEvent<Drilldown>Emitted when the drilldown instance is initialized.
destroyCustomEvent<Drilldown>Emitted when the drilldown instance is destroyed.
updateCustomEvent<Drilldown>Emitted when the drilldown updates.
nextCustomEvent<Drilldown>Emitted when navigating to the next level.
backCustomEvent<Drilldown>Emitted when navigating back.
resetCustomEvent<Drilldown>Emitted when the drilldown is reset.

Slots โ€‹

NameDescription
defaultThe drilldown structure with menus, next and back buttons.

Exposed โ€‹

The component exposes the underlying drilldown composable return value (state + actions). See useDrilldown.

CDrilldownMenu โ€‹

A container for drilldown menu items. Renders with the c-drilldown-menu CSS class.

Props โ€‹

NameTypeDefaultDescription
asstring | Component'ul'The HTML tag or component to render.
idstring-The unique identifier for the menu. If not provided, one will be generated.

Slots โ€‹

NameDescription
defaultThe menu items (<li> elements).

CDrilldownNext โ€‹

A button to navigate to the next level in the drilldown. Renders with the c-drilldown-next CSS class.

Props โ€‹

NameTypeDefaultDescription
asstring | Component'button'The HTML tag or component to render.

Slots โ€‹

NameDescription
defaultThe button content.

INFO

When rendered as a button, the component automatically sets type="button".

CDrilldownBack โ€‹

A button to navigate back in the drilldown. Renders with the c-drilldown-back CSS class.

Props โ€‹

NameTypeDefaultDescription
asstring | Component'button'The HTML tag or component to render.

Slots โ€‹

NameDescription
defaultThe button content.

INFO

When rendered as a button, the component automatically sets type="button".

CDropdown โ€‹

A dropdown component.

Usage โ€‹

vue
<script setup lang="ts">
import { CDropdown, CDropdownMenu, CDropdownTrigger } from '@compotes/vue'
</script>

<template>
  <CDropdown>
    <CDropdownTrigger>Open menu</CDropdownTrigger>
    <CDropdownMenu>
      <a href="#">Option 1</a>
      <a href="#">Option 2</a>
    </CDropdownMenu>
  </CDropdown>
</template>

Props โ€‹

NameTypeDefaultDescription
asstring | Component'div'The HTML tag or component to render.
idstring-The unique identifier for the dropdown. If not provided, one will be generated.
optionsDropdownOptions-Configuration options for the dropdown instance. See Dropdown options.

Events โ€‹

NamePayloadDescription
initCustomEvent<Dropdown>Emitted when the dropdown instance is initialized.
openedCustomEvent<Dropdown>Emitted when the dropdown opens.
closedCustomEvent<Dropdown>Emitted when the dropdown closes.
destroyCustomEvent<Dropdown>Emitted when the dropdown instance is destroyed.

Slots โ€‹

NameDescription
defaultThe dropdown structure, including trigger and menu.

Exposed โ€‹

The component exposes the underlying dropdown composable return value (state + actions). See useDropdown.

Context โ€‹

CDropdown provides its resolved menuId to child components via Vue's provide/inject. This allows CDropdownTrigger and CDropdownMenu to automatically wire up aria-controls and menu IDs.

CDropdownMenu โ€‹

The container for the dropdown content. Renders with the c-dropdown-container CSS class.

Props โ€‹

NameTypeDefaultDescription
asstring | Component'div'The HTML tag or component to render.
idstring-The unique identifier for the menu. If not provided, the ID from the parent CDropdown context is used.

Slots โ€‹

NameDescription
defaultThe dropdown menu content.

CDropdownTrigger โ€‹

The button to toggle the dropdown. Must be placed inside a CDropdown component.

Props โ€‹

NameTypeDefaultDescription
asstring | Component'button'The HTML tag or component to render.

Slots โ€‹

NameDescription
defaultThe trigger button content.

INFO

When rendered as a button, the component automatically sets type="button". It also auto-sets aria-controls from the parent CDropdown context via the menu ID.

The component applies the c-dropdown-trigger CSS class.

CMarquee โ€‹

A scrolling marquee component. Unlike other components, CMarquee manages its own inner container element via the containerAs prop.

Usage โ€‹

vue
<script setup lang="ts">
import { CMarquee } from '@compotes/vue'
</script>

<template>
  <CMarquee>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
  </CMarquee>
</template>

The rendered HTML structure is:

html
<div class="c-marquee">          <!-- as (outer element) -->
  <ul class="c-marquee-container"> <!-- containerAs (inner container) -->
    <li>Item 1</li>                 <!-- slot content -->
    <li>Item 2</li>
    <li>Item 3</li>
  </ul>
</div>

Props โ€‹

NameTypeDefaultDescription
asstring | Component'div'The HTML tag or component for the outer element.
containerAsstring | Component'ul'The HTML tag or component for the inner container.
optionsMarqueeOptions-Configuration options for the marquee instance. See Marquee options.

Events โ€‹

NamePayloadDescription
initCustomEvent<Marquee>Emitted when the marquee instance is initialized.
playCustomEvent<Marquee>Emitted when the marquee starts playing.
pauseCustomEvent<Marquee>Emitted when the marquee pauses.
loopCustomEvent<Marquee>Emitted when the marquee completes a loop.
destroyCustomEvent<Marquee>Emitted when the marquee instance is destroyed.

Slots โ€‹

NameDescription
defaultThe marquee items, placed inside the inner container.

Exposed โ€‹

The component exposes the underlying marquee composable return value (state + actions). See useMarquee.

Accessing Exposed Values โ€‹

Use a template ref to access the exposed composable from a parent component:

vue
<script setup lang="ts">
import { CCollapse, CCollapseTrigger } from '@compotes/vue'
import { useTemplateRef } from 'vue'

const collapseRef = useTemplateRef('myCollapse')

function openCollapse() {
  collapseRef.value?.show()
}
</script>

<template>
  <button @click="openCollapse">
    Open from outside
  </button>
  <CCollapse id="my-collapse" ref="myCollapse">
    <p>Content here.</p>
  </CCollapse>
</template>

Released under the MIT License.