# UiButton

## Usage

This component transparently wraps `RouterLink` and `button` and toggles between both based on the presence of the `to` prop. Providing the `to` prop will use `RouterLink` to render an `a` element with an appropriate `href` attribute. Both absolute URL references (e.g. `to="https://example.org/"`) and route locations (e.g. `:to="{ name: 'home' }"`) can be used with the latter being resolved against the host applications `vue-router` routes.

**Important**: Always implement direct navigation interactions using the `to` prop rather than attaching a `click` event listener to `UiButton` to ensure a properly accessible and usable link is created.

This component binds all non-prop attributes on its principal element (either a `button` or an `a` element). This allows you to add arbitrary HTML attributes (and event listeners) on the principal element without them being explicitly supported by the component.

```html
<template>
  <UiButton size="lg" appearance="secondary" @click="save">
    Save
  </UiButton>

  <UiButton @click="save">
    <UiIcon name="save" />
    Save
  </UiButton>

  <!-- Icon-only button's **must** have an “aria-label” attribute. -->
  <UiButton aria-label="Save" @click="save">
    <UiIcon name="save" />
  </UiButton>

  <UiButton :to="{ name: 'home' }">
    Internal link
  </UiButton>

  <UiButton to="https://example.org/">
    External link
  </UiButton>
</template>

<script setup>
import UiButton from "@dpa-id-components/dpa-shared-components/components/UiButton/UiButton.vue";
</script>
```
