@ark-ui/solid
Version:
A collection of unstyled, accessible UI components for Solid, utilizing state machines for seamless interaction.
41 lines (38 loc) • 1.22 kB
JavaScript
import { ark } from './EPLBB4QN.js';
import { useEnvironmentContext } from './5QLLQM7E.js';
import { createComponent, mergeProps } from 'solid-js/web';
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 createComponent(ark.button, mergeProps(restProps, {
type: "button",
onClick: handleClick
}));
}
export { DownloadTrigger };