@ark-ui/solid
Version:
A collection of unstyled, accessible UI components for Solid, utilizing state machines for seamless interaction.
39 lines (36 loc) • 1.16 kB
JSX
import {
ark
} from "./UFYZ7HLU.jsx";
import {
useEnvironmentContext
} from "./CGW54HAQ.jsx";
// src/components/download-trigger/download-trigger.tsx
import { downloadFile } from "@zag-js/file-utils";
import { splitProps } from "solid-js";
function DownloadTrigger(props) {
const [downloadProps, restProps] = splitProps(props, ["fileName", "data", "mimeType", "onClick"]);
const env = useEnvironmentContext();
const download = (data) => {
downloadFile({ file: data, name: downloadProps.fileName, type: downloadProps.mimeType, win: env().getWindow() });
};
const handleClick = (e) => {
if (typeof downloadProps.onClick === "function") {
downloadProps.onClick(e);
}
if (e.defaultPrevented) return;
if (typeof downloadProps.data === "function") {
const maybePromise = downloadProps.data();
if (maybePromise instanceof Promise) {
maybePromise.then((data) => download(data));
} else {
download(maybePromise);
}
} else {
download(downloadProps.data);
}
};
return <ark.button {...restProps} type="button" onClick={handleClick} />;
}
export {
DownloadTrigger
};