UNPKG

@ark-ui/vue

Version:

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

55 lines (50 loc) 1.76 kB
'use strict'; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } }); const vue = require('vue'); const factory = require('../factory.cjs'); const fileUtils = require('@zag-js/file-utils'); const useEnvironmentContext = require('../../providers/environment/use-environment-context.cjs'); const useForwardExpose = require('../../utils/use-forward-expose.cjs'); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ __name: "download-trigger", props: { fileName: {}, data: { type: [String, Function] }, mimeType: {}, asChild: { type: Boolean } }, setup(__props) { const props = __props; const env = useEnvironmentContext.useEnvironmentContext(useEnvironmentContext.DEFAULT_ENVIRONMENT); const download = (data) => { fileUtils.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.useForwardExpose(); return (_ctx, _cache) => { return vue.openBlock(), vue.createBlock(vue.unref(factory.ark).button, { "as-child": _ctx.asChild, type: "button", onClick: handleClick }, { default: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, "default") ]), _: 3 }, 8, ["as-child"]); }; } }); exports.default = _sfc_main;