@jasperoosthoek/react-toolbox 0.6.0 → 0.6.2

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.
@@ -4,6 +4,20 @@
4
4
  http://jedwatson.github.io/classnames
5
5
  */
6
6
 
7
+ /*!
8
+ * mime-db
9
+ * Copyright(c) 2014 Jonathan Ong
10
+ * Copyright(c) 2015-2022 Douglas Christopher Wilson
11
+ * MIT Licensed
12
+ */
13
+
14
+ /*!
15
+ * mime-types
16
+ * Copyright(c) 2014 Jonathan Ong
17
+ * Copyright(c) 2015 Douglas Christopher Wilson
18
+ * MIT Licensed
19
+ */
20
+
7
21
  /**
8
22
  * @license React
9
23
  * react-jsx-runtime.production.js
@@ -1,3 +1,4 @@
1
+ import { AxiosInstance } from 'axios';
1
2
  export declare const isEmpty: (value: unknown) => boolean;
2
3
  export declare const snakeToCamelCase: (str: string) => string;
3
4
  export declare const camelToSnakeCase: (str: string) => string;
@@ -5,3 +6,7 @@ export declare const pluralToSingle: (str: string) => string;
5
6
  export declare const arrayToObject: <T extends any[]>(array: T, byKey: string) => any;
6
7
  export declare const roundFixed: (str: string | number, decimals?: number) => string;
7
8
  export declare const round: (str: string | number, decimals?: number) => number;
9
+ export type DownloadFileOptions = {
10
+ axios: AxiosInstance;
11
+ };
12
+ export declare const downloadFile: (url: string, filename: string, options: DownloadFileOptions) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jasperoosthoek/react-toolbox",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "author": "jasperoosthoek",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -55,7 +55,7 @@
55
55
  "bootstrap": "^5.1.3",
56
56
  "moment": "^2.29.4",
57
57
  "react": "^19.0.0",
58
- "react-bootstrap": "^2.7.4",
58
+ "react-bootstrap": "^2.10.9",
59
59
  "react-dnd": "^16.0.1",
60
60
  "react-dom": "^19.0.0",
61
61
  "react-icons": "^5.3.0",
@@ -1,4 +1,4 @@
1
- import React, { ChangeEvent } from 'react';
1
+ import React, { ChangeEvent, ReactNode } from 'react';
2
2
  import { InputGroup, Form, FormControlProps } from 'react-bootstrap';
3
3
 
4
4
  import { useLocalization } from '../../localization/LocalizationContext';
@@ -10,29 +10,47 @@ export type SearchBoxProps = {
10
10
  onChange: (value: string) => void;
11
11
  onClear?: () => void;
12
12
  onSearch?: () => void;
13
+ label?: ReactNode | string | number;
14
+ placeholder?: string | false;
13
15
  }
14
- export const SearchBox = ({ className='', value, onChange, onClear, onSearch }: SearchBoxProps) => {
16
+ export const SearchBox = ({
17
+ className='',
18
+ value,
19
+ onChange,
20
+ onClear,
21
+ onSearch,
22
+ label,
23
+ placeholder,
24
+ }: SearchBoxProps) => {
15
25
  const { strings } = useLocalization();
16
26
 
17
- return (<>
18
- <InputGroup {...className ? { className } : {}}>
19
- <Form.Control
20
- value={value}
21
- placeholder={strings.getString('search')}
22
- onChange={(e: ChangeEvent<HTMLInputElement>) => onChange(e.target.value)}
23
- />
24
- {onClear &&
25
- <UnCheckButton
26
- variant="outline-secondary"
27
- onClick={() => onClear()}
27
+ return (
28
+ <Form.Group>
29
+ {label && <Form.Label>{label}</Form.Label>}
30
+
31
+ <InputGroup {...className ? { className } : {}}>
32
+ <Form.Control
33
+ value={value}
34
+ placeholder={
35
+ placeholder
36
+ ? placeholder
37
+ : placeholder !== false && strings.getString('search')
38
+ }
39
+ onChange={(e: ChangeEvent<HTMLInputElement>) => onChange(e.target.value)}
28
40
  />
29
- }
30
- {onSearch &&
31
- <SearchButton
32
- variant="outline-secondary"
33
- onClick={() => onSearch()}
34
- />
35
- }
36
- </InputGroup></>
41
+ {onClear &&
42
+ <UnCheckButton
43
+ variant="outline-secondary"
44
+ onClick={() => onClear()}
45
+ />
46
+ }
47
+ {onSearch &&
48
+ <SearchButton
49
+ variant="outline-secondary"
50
+ onClick={() => onSearch()}
51
+ />
52
+ }
53
+ </InputGroup>
54
+ </Form.Group>
37
55
  )
38
56
  }
@@ -1,3 +1,4 @@
1
+ import axios, { AxiosInstance } from 'axios';
1
2
 
2
3
  export const isEmpty = (value: unknown) =>
3
4
  value === undefined
@@ -40,3 +41,26 @@ export const arrayToObject = <T extends any[]>(array: T, byKey: string) => Objec
40
41
 
41
42
  export const roundFixed = (str: string | number, decimals?: number) => parseFloat(`${str}`).toFixed(decimals || 0);
42
43
  export const round = (str: string | number, decimals?: number) => parseFloat(parseFloat(`${str}`).toFixed(decimals || 0));
44
+
45
+ export type DownloadFileOptions = {
46
+ axios: AxiosInstance;
47
+ }
48
+ export const downloadFile = (url: string, filename: string, options: DownloadFileOptions) => (
49
+ // https://gist.github.com/javilobo8/097c30a233786be52070986d8cdb1743
50
+
51
+ (options.axios || axios.create())({
52
+ url,
53
+ method: 'GET',
54
+ responseType: 'blob',
55
+ }).then((response) => {
56
+ const url = window.URL.createObjectURL(new Blob([response.data]));
57
+ const link = document.createElement('a');
58
+ link.href = url;
59
+ link.setAttribute(
60
+ 'download',
61
+ filename,
62
+ );
63
+ document.body.appendChild(link);
64
+ link.click();
65
+ })
66
+ );