CloseButton

Button component for closing dialogs, modals, or dismissing content

Usage

import { CloseButton } from '@hareui/vue'
<script setup lang="ts">import { CloseButton } from '@hareui/vue'</script><template>  <CloseButton /></template>

Anatomy

A single <button> with a default close icon that the default slot can replace.

<CloseButton>
  <!-- optional custom icon -->
</CloseButton>

ui keys: base, icon.

Examples

Interactive

Clicked: 0 times
<script setup lang="ts">import { ref } from 'vue'import { CloseButton } from '@hareui/vue'const count = ref(0)</script><template>  <div class="flex flex-col items-center justify-center gap-4">    <CloseButton :aria-label="`Close (clicked ${count} times)`" @click="count++" />    <span class="text-sm text-muted">Clicked: {{ count }} times</span>  </div></template>

With Custom Icon

Custom Icon
Alternative Icon
<script setup lang="ts">import { CloseButton } from '@hareui/vue'import { Icon } from '@iconify/vue'</script><template>  <div class="flex items-center gap-4">    <div class="flex flex-col items-center gap-2">      <CloseButton>        <Icon icon="gravity-ui:circle-xmark" />      </CloseButton>      <span class="text-xs text-muted">Custom Icon</span>    </div>    <div class="flex flex-col items-center gap-2">      <CloseButton>        <Icon icon="gravity-ui:xmark" />      </CloseButton>      <span class="text-xs text-muted">Alternative Icon</span>    </div>  </div></template>

Customization

Tailwind CSS

<script setup lang="ts">import { CloseButton } from '@hareui/vue'</script><template>  <CloseButton    aria-label="Close"    class="size-8 rounded-full bg-default text-muted hover:bg-default-hover hover:text-foreground active:scale-95"  /></template>

Global theme override

app.use(createHareUI({
  ui: {
    closeButton: {
      slots: { base: 'rounded-full' },
    },
  },
}))

Styling Reference

ui keydata-slotDescription
baseclose-buttonThe root <button>
iconclose-button-iconThe default close icon <svg>

Interactive states

  • Hover: :hover
  • Active/Pressed: :active
  • Focus: :focus-visible
  • Disabled: :disabled / [aria-disabled=true]

API Reference

Props

PropTypeDefaultDescription
variant"default"'default'Visual style of the close button.
disabledbooleanfalseWhether the button is disabled.
ariaLabelstring"Close"Accessible label of the button.
uiComponentSlots<{ slots: { base: string[]; icon: string; }; variants: { variant: { default: { base: string; }; }; }; defaultVariants: { variant: string; }; }>-Per-slot class overrides.

Slots

SlotPropsDescription
defaultanyReplaces the default close icon.

On this page

No Headings