48 lines
1.3 KiB
Vue
48 lines
1.3 KiB
Vue
<script setup lang="ts">
|
|
import type { PrimitiveProps } from "reka-ui";
|
|
import type { HTMLAttributes } from "vue";
|
|
import type { ButtonVariants } from ".";
|
|
import { Primitive } from "reka-ui";
|
|
import { computed } from "vue";
|
|
import { Spinner } from "@/components/ui/spinner";
|
|
import { cn } from "@/lib/utils";
|
|
import { buttonVariants } from ".";
|
|
|
|
interface Props extends PrimitiveProps {
|
|
variant?: ButtonVariants["variant"];
|
|
size?: ButtonVariants["size"];
|
|
class?: HTMLAttributes["class"];
|
|
disabled?: boolean;
|
|
loading?: boolean;
|
|
loadingLabel?: string;
|
|
}
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
as: "button",
|
|
disabled: false,
|
|
loading: false,
|
|
});
|
|
|
|
const isDisabled = computed(() => props.disabled || props.loading);
|
|
</script>
|
|
|
|
<template>
|
|
<Primitive
|
|
data-slot="button"
|
|
:data-loading="loading ? '' : undefined"
|
|
:as="as"
|
|
:as-child="asChild"
|
|
:disabled="isDisabled"
|
|
:aria-disabled="isDisabled ? 'true' : undefined"
|
|
:aria-busy="loading ? 'true' : undefined"
|
|
:class="cn(buttonVariants({ variant, size }), props.class)"
|
|
>
|
|
<Spinner
|
|
v-if="loading"
|
|
data-slot="button-spinner"
|
|
:label="loadingLabel"
|
|
/>
|
|
<slot />
|
|
</Primitive>
|
|
</template>
|