UNPKG

@ark-ui/vue

Version:

A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.

51 lines (48 loc) 1.61 kB
import { defineComponent, createBlock, openBlock, unref, withCtx, renderSlot } from 'vue'; import { ark } from '../factory.js'; import { downloadFile } from '@zag-js/file-utils'; import { useEnvironmentContext, DEFAULT_ENVIRONMENT } from '../../providers/environment/use-environment-context.js'; import { useForwardExpose } from '../../utils/use-forward-expose.js'; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "download-trigger", props: { fileName: {}, data: { type: [String, Function] }, mimeType: {}, asChild: { type: Boolean } }, setup(__props) { const props = __props; const env = useEnvironmentContext(DEFAULT_ENVIRONMENT); const download = (data) => { downloadFile({ file: data, name: props.fileName, type: props.mimeType, win: env?.value.getWindow() || window }); }; const handleClick = (e) => { if (e.defaultPrevented) return; if (typeof props.data === "function") { const maybePromise = props.data(); if (maybePromise instanceof Promise) { maybePromise.then((data) => download(data)); } else { download(maybePromise); } } else { download(props.data); } }; useForwardExpose(); return (_ctx, _cache) => { return openBlock(), createBlock(unref(ark).button, { "as-child": _ctx.asChild, type: "button", onClick: handleClick }, { default: withCtx(() => [ renderSlot(_ctx.$slots, "default") ]), _: 3 }, 8, ["as-child"]); }; } }); export { _sfc_main as default };