@jasperoosthoek/react-toolbox 0.7.0 → 0.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jasperoosthoek/react-toolbox",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "author": "jasperoosthoek",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -85,6 +85,8 @@ export const FormTextArea = ({ as = 'textarea', rows = 3, ...restProps }: FormIn
85
85
  />
86
86
  );
87
87
 
88
+ export type FormTextAreaProps = FormInputProps;
89
+
88
90
  export const FormDate = (props: FormInputProps) => (
89
91
  <FormInput
90
92
  {...props}
@@ -382,6 +384,7 @@ export const FormDropdown = <T,>({
382
384
  variant = 'light',
383
385
  pristine,
384
386
  keyName,
387
+ onEnter,
385
388
  ...restProps
386
389
  }: FormDropdownProps<T>) => {
387
390
  const { strings } = useLocalization();
@@ -418,7 +421,14 @@ export const FormDropdown = <T,>({
418
421
  {label && <Form.Label>{label}</Form.Label>}
419
422
 
420
423
  <div className={`form-control ${isInvalid ? 'is-invalid' : ''}`}>
421
- <Dropdown>
424
+ <Dropdown
425
+ onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
426
+ if (e.key === 'Enter' && typeof onEnter === 'function') {
427
+ e.preventDefault();
428
+ onEnter();
429
+ }
430
+ }}
431
+ >
422
432
  <Dropdown.Toggle variant={variant}>
423
433
  {selectedItem
424
434
  ? selectedItem[nameKey] as string
@@ -73,6 +73,10 @@ export const FormModal = <
73
73
  console.error(`Unrecognised props given to FormModal:`, restProps);
74
74
  }
75
75
 
76
+ if (!formFields) {
77
+ console.error(`Property formFields cannot be empty.`)
78
+ return null;
79
+ }
76
80
  const getInitialFormData = () => ({
77
81
  ...Object.entries(formFields).reduce((o, [key, { initialValue }]) => ({ ...o, [key]: initialValue || '' }), {}),
78
82
  ...initialState || {},
@@ -78,7 +78,7 @@ export type DataTableProps<D extends any[]> = {
78
78
  columns: DataTableColumn<D[number]>[];
79
79
  rowsPerPage?: number | null;
80
80
  rowsPerPageOptions?: RowsPerPageOptions;
81
- filterColumn?: (keyof D) | ((row: D[number]) => string) | ((keyof D) | ((row: D[number]) => string))[];
81
+ filterColumn?: string | ((row: D[number]) => string) | (string | ((row: D[number]) => string))[];
82
82
  orderByDefault?: ((row: D[number]) => number) | string | null;
83
83
  orderByDefaultDirection?: OrderByDirection;
84
84
  onMove?: OnMove<D[number]>;
@@ -98,7 +98,7 @@ export const DataTable = <D extends any[]>({
98
98
  data: allData,
99
99
  columns,
100
100
  rowsPerPage: rowsPerPageDefault = 10,
101
- rowsPerPageOptions = [10,25, 50, 100, null],
101
+ rowsPerPageOptions = [10, 25, 50, 100, null],
102
102
  filterColumn,
103
103
  orderByDefault,
104
104
  orderByDefaultDirection='asc',
@@ -271,9 +271,8 @@ export const DataTable = <D extends any[]>({
271
271
  }
272
272
  >
273
273
  <option
274
- value=""
274
+ value="everything"
275
275
  disabled={rowsPerPage !== null}
276
- selected={rowsPerPage === null}
277
276
  >
278
277
  {strings.getString('select')}
279
278
  </option>
@@ -12,7 +12,6 @@ export const usePrevious = <T>(value: T): T | undefined => {
12
12
  return ref.current;
13
13
  };
14
14
 
15
-
16
15
  // https://stackoverflow.com/questions/54666401/how-to-use-throttle-or-debounce-with-react-hook
17
16
  export const useDebouncedEffect = (effect: () => void, deps: any[], delay: number) => {
18
17
  useEffect(() => {
@@ -66,6 +65,11 @@ export const useInterval = (func: () => void, value: number) => useEffect(() =>
66
65
 
67
66
  export const useLocalStorage = <T,>(key: string, initialValue: T): [T, (value: T) => void] => {
68
67
  const initialLocalStorageValue = localStorage.getItem(key);
68
+
69
+ if (initialLocalStorageValue === null) {
70
+ localStorage.setItem(key, JSON.stringify(initialValue));
71
+ }
72
+
69
73
  const [state, setState] = useState<T>(
70
74
  initialLocalStorageValue
71
75
  ? JSON.parse(initialLocalStorageValue) as T
@@ -79,18 +83,14 @@ export const useLocalStorage = <T,>(key: string, initialValue: T): [T, (value: T
79
83
  }
80
84
  };
81
85
 
86
+ // Manually dispatch an event to update components in the same document
82
87
  window.addEventListener('storage', handleStorageChange);
83
-
84
- return () => {
85
- window.removeEventListener('storage', handleStorageChange);
86
- };
88
+ return () => window.removeEventListener('storage', handleStorageChange);
87
89
  }, [key]);
88
90
 
89
91
  const setLocalStorage = (value: T) => {
90
92
  setState(value);
91
93
  localStorage.setItem(key, JSON.stringify(value));
92
-
93
- // Manually dispatch an event to update components in the same document
94
94
  window.dispatchEvent(new StorageEvent('storage', {
95
95
  key,
96
96
  newValue: JSON.stringify(value),