@uxf/core 11.42.0 → 11.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -392,6 +392,19 @@ cxa("foo", [1 && "bar", { baz:false, bat:null }, ["hello", ["world"]]], "cya");
392
392
  //=> "foo bar hello world cya"
393
393
  ```
394
394
 
395
+ ### downloadFile
396
+
397
+ Intended as only way to programmatically download file if there is no option to use native anchor with `download` html attribute (eg. in form submit events).
398
+
399
+ ```ts
400
+ import { downloadFile } from "@uxf/core/utils/download-file";
401
+ import { FormEventHandler } from "react";
402
+
403
+ const submitHandler: FormEventHandler<HTMLFormElement> = () => {
404
+ downloadFile("https://example.com/file", "file.txt")
405
+ };
406
+ ```
407
+
395
408
  ## Validators
396
409
  ```tsx
397
410
  import { Validator } from "@uxf/core";
@@ -6,6 +6,7 @@ const react_1 = require("react");
6
6
  * @deprecated Use import from @uxf/core-react instead.
7
7
  */
8
8
  function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onClick, onKeyDown, onKeyUp, submit, }) {
9
+ // eslint-disable-next-line react-hooks/rules-of-hooks
9
10
  const _onClick = (0, react_1.useCallback)((e) => {
10
11
  var _a;
11
12
  if ((isClickable || isHyperlink) && analyticsCallback) {
@@ -26,6 +27,7 @@ function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onCl
26
27
  e.preventDefault();
27
28
  }
28
29
  }, [analyticsCallback, isClickable, isHyperlink, onClick, submit]);
30
+ // eslint-disable-next-line react-hooks/rules-of-hooks
29
31
  const _onKeyUp = (0, react_1.useCallback)((e) => {
30
32
  if (isClickable && (e.key === "Enter" || e.key === " ")) {
31
33
  e.target.dispatchEvent(new MouseEvent("click", {
@@ -39,6 +41,7 @@ function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onCl
39
41
  }
40
42
  }
41
43
  }, [isClickable, onKeyUp]);
44
+ // eslint-disable-next-line react-hooks/rules-of-hooks
42
45
  const _onKeyDown = (0, react_1.useCallback)((e) => {
43
46
  if (isClickable && e.key === " ") {
44
47
  e.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.42.0",
3
+ "version": "11.45.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
@@ -0,0 +1 @@
1
+ export declare function downloadFile(url: string, filename: string): void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadFile = downloadFile;
4
+ function downloadFile(url, filename) {
5
+ const link = document.createElement("a");
6
+ link.href = url;
7
+ link.download = filename;
8
+ document.body.appendChild(link);
9
+ link.click();
10
+ document.body.removeChild(link);
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const download_file_1 = require("./download-file");
4
+ test("should accept parameters and not throw an error", () => {
5
+ const url = "https://example.com/file";
6
+ const filename = "file.txt";
7
+ expect(() => (0, download_file_1.downloadFile)(url, filename)).not.toThrow();
8
+ });