Components
Share Button
Uses the native share sheet and falls back to copying the link.
Installation
$ npx veil-ui@latest add share-buttonUsage
import { ShareButton } from "@/components/ui/share-button";
<ShareButton title="Veil UI" url="https://veil-ui.dev" />;Examples
Basic
With a URL
Outline
The button uses navigator.share when the browser exposes it. Otherwise it
copies the URL to the clipboard and confirms with “Link copied”.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | — | Title passed to the native share sheet. |
| text | string | — | Body text passed to the native share sheet. |
| url | string | window.location.href | URL to share or copy. |
| label | string | "Share" | Visible button label. |
| copiedLabel | string | "Link copied" | Confirmation shown after copying. |
| ...props | ButtonProps | — | All Button props and native button attributes. |
Accessibility
- The label change is announced through a polite live region.
- Clipboard access requires a secure context; handle failures in your own analytics if needed.
- The native share sheet is provided by the platform and is fully accessible.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add share-button --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { Check, Share2 } from "lucide-vue-next";
import { ref } from "vue";
import { Button } from "@/components/ui/button";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
/** Share sheet title. */
title?: string;
text?: string;
/** URL to share; defaults to the current location. */
url?: string;
label?: string;
copiedLabel?: string;
class?: string;
}>(),
{ label: "Share", copiedLabel: "Link copied" },
);
const copied = ref(false);
async function handleShare() {
const shareUrl = props.url ?? window.location.href;
if (typeof navigator.share === "function") {
try {
await navigator.share({ title: props.title, text: props.text, url: shareUrl });
return;
} catch {
return;
}
}
await navigator.clipboard?.writeText(shareUrl);
copied.value = true;
}
</script>
<template>
<Button
data-slot="share-button"
v-bind="$attrs"
:class="props.class"
@click="handleShare"
>
<Check v-if="copied" aria-hidden="true" />
<Share2 v-else aria-hidden="true" />
<span aria-live="polite">{{ copied ? copiedLabel : label }}</span>
</Button>
</template>