@bluemarble/bm-components 0.0.21 → 0.0.24

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.
@@ -1,8 +1,7 @@
1
1
  import { ReactNode } from "react";
2
- import { Autocomplete as MuiAutocomplete, AutocompleteProps as MuiAutocompleteProps, AutocompleteRenderInputParams } from "@mui/material";
3
- declare type MuiAutocomplete<T> = Omit<MuiAutocompleteProps<T, boolean, undefined, boolean>, "renderInput" | "getOptionLabel">;
4
- declare type AutocompleteProps<T> = AutocompleteWithoutProps<T> | AutocompleteWithFormikProps<T>;
5
- interface AutocompleteWithoutProps<T> extends MuiAutocomplete<T> {
2
+ import { AutocompleteProps as MuiAutocompleteProps, AutocompleteRenderInputParams } from "@mui/material";
3
+ declare type MuiAutocompleteBaseProps<T> = Omit<MuiAutocompleteProps<T, boolean, undefined, boolean>, "renderInput" | "getOptionLabel">;
4
+ interface AutocompleteWithoutProps<T> extends MuiAutocompleteBaseProps<T> {
6
5
  name?: never;
7
6
  withFormik: false;
8
7
  getOptionValue?: never;
@@ -10,7 +9,7 @@ interface AutocompleteWithoutProps<T> extends MuiAutocomplete<T> {
10
9
  getOptionLabel: (option: T) => string;
11
10
  renderInput?: (params: AutocompleteRenderInputParams) => ReactNode;
12
11
  }
13
- interface AutocompleteWithFormikProps<T> extends MuiAutocomplete<T> {
12
+ interface AutocompleteWithFormikProps<T> extends MuiAutocompleteBaseProps<T> {
14
13
  name: string;
15
14
  withFormik?: true;
16
15
  label?: string;
@@ -20,8 +19,9 @@ interface AutocompleteWithFormikProps<T> extends MuiAutocomplete<T> {
20
19
  key?: string;
21
20
  };
22
21
  renderInput?: (params: AutocompleteRenderInputParams) => ReactNode;
23
- getOptionLabel: (option: T) => string;
24
- getOptionValue: (option: T) => string | number;
22
+ getOptionLabel?: (option: T) => string;
23
+ getOptionValue?: (option: T) => string | number;
25
24
  }
25
+ declare type AutocompleteProps<T> = AutocompleteWithoutProps<T> | AutocompleteWithFormikProps<T>;
26
26
  export declare function Autocomplete<T>({ withFormik, name, getOptionValue, ...rest }: AutocompleteProps<T>): JSX.Element;
27
27
  export {};
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { TableCellProps } from "@mui/material";
3
+ import { ColumnsProps } from ".";
4
+ interface GridCellProps {
5
+ focusedIndex: {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ rowIndex: number;
10
+ columnIndex: number;
11
+ isEditing: boolean;
12
+ value: any;
13
+ bordered?: boolean;
14
+ onClick: () => void;
15
+ onDoubleClick: () => void;
16
+ onInputChange: (value: string) => void;
17
+ setCanSave: (value: boolean) => void;
18
+ canEditTable: boolean;
19
+ tableCellProps?: TableCellProps;
20
+ validationErrors?: string[];
21
+ column: ColumnsProps<any>;
22
+ }
23
+ export declare const GridCell: ({ value, focusedIndex, canEditTable, columnIndex, rowIndex, isEditing, onInputChange, bordered, onClick, onDoubleClick, setCanSave, tableCellProps, validationErrors, column, }: GridCellProps) => JSX.Element;
24
+ export {};
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import { BaseTextFieldProps } from "@mui/material";
3
+ import { InputSelectCellProps } from "../GridSelect";
4
+ export interface GridInputProps extends BaseTextFieldProps {
5
+ onDefaultValue?: (value: string) => string;
6
+ }
7
+ export interface InputCellProps {
8
+ currentValue: string;
9
+ defaultValue?: string;
10
+ inputProps?: GridInputProps;
11
+ type?: GridInputProps["type"] | "select";
12
+ select?: Omit<InputSelectCellProps, "setCanSave" | "onInputChange">;
13
+ onInputChange: (value: string) => void;
14
+ setCanSave: (value: boolean) => void;
15
+ }
16
+ export declare const InputCell: (props: InputCellProps) => JSX.Element;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ export interface InputAutocompleteCellProps {
3
+ options: any[];
4
+ label: string;
5
+ value: string;
6
+ setCanSave: (value: boolean) => void;
7
+ onInputChange: (value: string) => void;
8
+ currentValue?: string;
9
+ defaultValue?: string;
10
+ }
11
+ export declare const InputAutocompleteCell: ({ options, label, value, onInputChange, currentValue, defaultValue: ExternalDefaultValue, }: InputAutocompleteCellProps) => JSX.Element;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { InputCellProps } from "../GridInput";
3
+ export declare const InputTextCell: ({ defaultValue, currentValue, inputProps, onInputChange, }: InputCellProps) => JSX.Element;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ export interface InputSelectCellProps {
3
+ options: any[];
4
+ label: string;
5
+ value: string;
6
+ setCanSave: (value: boolean) => void;
7
+ onInputChange: (value: string) => void;
8
+ currentValue?: string;
9
+ }
10
+ export declare const InputSelectCell: ({ options, label, value, setCanSave, onInputChange, currentValue, }: InputSelectCellProps) => JSX.Element;
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import { ColumnsProps } from "..";
3
+ interface NewRowProps {
4
+ columns: ColumnsProps<any>[];
5
+ hasCheckbox: boolean;
6
+ maxPositions: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ onSaveNewRow?: (prop: any) => void;
11
+ }
12
+ export declare const NewRow: ({ columns, hasCheckbox, maxPositions, onSaveNewRow, }: NewRowProps) => JSX.Element;
13
+ export {};
@@ -0,0 +1,52 @@
1
+ /// <reference types="react" />
2
+ import { TableCellProps } from "@mui/material";
3
+ import { GridInputProps } from "./GridInput";
4
+ import { InputSelectCellProps } from "./GridSelect";
5
+ export interface onSaveOptions<T> {
6
+ prop: keyof T;
7
+ newValue: string;
8
+ index: number;
9
+ }
10
+ export interface ColumnsProps<T> {
11
+ id?: string | number;
12
+ name: keyof T | "";
13
+ label: string;
14
+ visible?: boolean;
15
+ type?: GridInputProps["type"] | "select" | "autocomplete";
16
+ inputProps?: GridInputProps;
17
+ select?: Omit<InputSelectCellProps, "setCanSave" | "onInputChange">;
18
+ formatLabelValue?: (value: string) => string;
19
+ required?: boolean;
20
+ TableCellProps?: TableCellProps;
21
+ newRow?: {
22
+ defaultValue?: string;
23
+ };
24
+ }
25
+ interface EditableGridProps<T> {
26
+ columns: ColumnsProps<T>[];
27
+ data: Array<T>;
28
+ primaryKey: keyof T;
29
+ focusedIndex: {
30
+ x: number;
31
+ y: number;
32
+ };
33
+ isEditing: boolean;
34
+ bordered?: boolean;
35
+ onSave: (item: T, options: onSaveOptions<T>) => void;
36
+ setFocusedIndex: (props: {
37
+ x: number;
38
+ y: number;
39
+ }) => void;
40
+ setIsEditing: (value: boolean) => void;
41
+ canEditTable: boolean;
42
+ setCanEditTable: (value: boolean) => void;
43
+ selectedRows: number[];
44
+ setSelectedRows: (value: number[]) => void;
45
+ checkbox?: boolean;
46
+ checkMultiple?: boolean;
47
+ onSaveNewRow?: (newRow: T) => void;
48
+ canInsertNewRow: boolean;
49
+ setCanInsertNewRow: (value: boolean) => void;
50
+ }
51
+ export declare function EditableGrid<T extends Record<string, any>>({ columns, data, primaryKey, onSave, setFocusedIndex, setIsEditing, focusedIndex, isEditing, bordered, canEditTable, setCanEditTable, selectedRows, setSelectedRows, checkbox, checkMultiple, onSaveNewRow, canInsertNewRow, }: EditableGridProps<T>): JSX.Element;
52
+ export {};
@@ -0,0 +1,23 @@
1
+ import { onSaveOptions } from "../EditableGrid";
2
+ export declare type useEditableGridResponseProps<T> = {
3
+ data: Array<T>;
4
+ focusedIndex: {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ isEditing: boolean;
9
+ setData: (props: Array<T>) => void;
10
+ setIsEditing: (value: boolean) => void;
11
+ setFocusedIndex: (props: {
12
+ x: number;
13
+ y: number;
14
+ }) => void;
15
+ onSave: (newItem: T, props: onSaveOptions<T>) => void;
16
+ canEditTable: boolean;
17
+ setCanEditTable: (value: boolean) => void;
18
+ selectedRows: number[];
19
+ setSelectedRows: (value: number[]) => void;
20
+ canInsertNewRow: boolean;
21
+ setCanInsertNewRow: (value: boolean) => void;
22
+ };
23
+ export declare function useEditableGrid<T>(): useEditableGridResponseProps<T>;
@@ -0,0 +1 @@
1
+ export declare function useEvent(event: keyof WindowEventMap, handler: (ev: any) => void, passive?: boolean): void;
@@ -7,3 +7,6 @@ export { Checkbox } from "./Checkbox";
7
7
  export { Switch } from "./Switch";
8
8
  export { Radio } from "./Radio";
9
9
  export { LargeButton } from "./LargeButton";
10
+ export { EditableGrid } from "./EditableGrid";
11
+ export { useEditableGrid } from "./hooks/useEditableGrid";
12
+ export { useEvent } from "./hooks/useEvent";
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import React, { ReactNode, FC } from 'react';
3
- import { TableCellProps, TextFieldProps, TableRowProps, StandardTextFieldProps, SelectProps as SelectProps$1, FormControlProps, InputLabelProps, AutocompleteRenderInputParams, AutocompleteProps as AutocompleteProps$1, CheckboxProps as CheckboxProps$1, FormControlLabelProps, SwitchProps as SwitchProps$1, RadioGroupProps, ButtonProps, CircularProgressProps } from '@mui/material';
3
+ import { TableCellProps, TextFieldProps, TableRowProps, StandardTextFieldProps, SelectProps as SelectProps$1, FormControlProps, InputLabelProps, AutocompleteRenderInputParams, AutocompleteProps as AutocompleteProps$1, CheckboxProps as CheckboxProps$1, FormControlLabelProps, SwitchProps as SwitchProps$1, RadioGroupProps, ButtonProps, CircularProgressProps, BaseTextFieldProps } from '@mui/material';
4
4
  import IMask$1 from 'imask';
5
5
 
6
6
  interface ColumnTitleProps {
@@ -100,9 +100,8 @@ interface SelectProps extends SelectProps$1 {
100
100
  }
101
101
  declare const Select: FC<SelectProps>;
102
102
 
103
- declare type MuiAutocomplete<T> = Omit<AutocompleteProps$1<T, boolean, undefined, boolean>, "renderInput" | "getOptionLabel">;
104
- declare type AutocompleteProps<T> = AutocompleteWithoutProps<T> | AutocompleteWithFormikProps<T>;
105
- interface AutocompleteWithoutProps<T> extends MuiAutocomplete<T> {
103
+ declare type MuiAutocompleteBaseProps<T> = Omit<AutocompleteProps$1<T, boolean, undefined, boolean>, "renderInput" | "getOptionLabel">;
104
+ interface AutocompleteWithoutProps<T> extends MuiAutocompleteBaseProps<T> {
106
105
  name?: never;
107
106
  withFormik: false;
108
107
  getOptionValue?: never;
@@ -110,7 +109,7 @@ interface AutocompleteWithoutProps<T> extends MuiAutocomplete<T> {
110
109
  getOptionLabel: (option: T) => string;
111
110
  renderInput?: (params: AutocompleteRenderInputParams) => ReactNode;
112
111
  }
113
- interface AutocompleteWithFormikProps<T> extends MuiAutocomplete<T> {
112
+ interface AutocompleteWithFormikProps<T> extends MuiAutocompleteBaseProps<T> {
114
113
  name: string;
115
114
  withFormik?: true;
116
115
  label?: string;
@@ -120,9 +119,10 @@ interface AutocompleteWithFormikProps<T> extends MuiAutocomplete<T> {
120
119
  key?: string;
121
120
  };
122
121
  renderInput?: (params: AutocompleteRenderInputParams) => ReactNode;
123
- getOptionLabel: (option: T) => string;
124
- getOptionValue: (option: T) => string | number;
122
+ getOptionLabel?: (option: T) => string;
123
+ getOptionValue?: (option: T) => string | number;
125
124
  }
125
+ declare type AutocompleteProps<T> = AutocompleteWithoutProps<T> | AutocompleteWithFormikProps<T>;
126
126
  declare function Autocomplete<T>({ withFormik, name, getOptionValue, ...rest }: AutocompleteProps<T>): JSX.Element;
127
127
 
128
128
  declare type CheckboxProps = CheckboxWithFormik | CheckboxWithoutFormik;
@@ -181,4 +181,90 @@ interface LargeButtonProps extends ButtonProps {
181
181
  }
182
182
  declare const LargeButton: ({ loading, children, CircularProgressProps, ...rest }: LargeButtonProps) => JSX.Element;
183
183
 
184
- export { Autocomplete, Checkbox, ColumnTitleProps, EditableTableCell, FilterProps, Grid, IFilter, Input, InputMask, LargeButton, Radio, Select, Switch, Td, Tr, filterData };
184
+ interface InputSelectCellProps {
185
+ options: any[];
186
+ label: string;
187
+ value: string;
188
+ setCanSave: (value: boolean) => void;
189
+ onInputChange: (value: string) => void;
190
+ currentValue?: string;
191
+ }
192
+
193
+ interface GridInputProps extends BaseTextFieldProps {
194
+ onDefaultValue?: (value: string) => string;
195
+ }
196
+
197
+ interface onSaveOptions<T> {
198
+ prop: keyof T;
199
+ newValue: string;
200
+ index: number;
201
+ }
202
+ interface ColumnsProps<T> {
203
+ id?: string | number;
204
+ name: keyof T | "";
205
+ label: string;
206
+ visible?: boolean;
207
+ type?: GridInputProps["type"] | "select" | "autocomplete";
208
+ inputProps?: GridInputProps;
209
+ select?: Omit<InputSelectCellProps, "setCanSave" | "onInputChange">;
210
+ formatLabelValue?: (value: string) => string;
211
+ required?: boolean;
212
+ TableCellProps?: TableCellProps;
213
+ newRow?: {
214
+ defaultValue?: string;
215
+ };
216
+ }
217
+ interface EditableGridProps<T> {
218
+ columns: ColumnsProps<T>[];
219
+ data: Array<T>;
220
+ primaryKey: keyof T;
221
+ focusedIndex: {
222
+ x: number;
223
+ y: number;
224
+ };
225
+ isEditing: boolean;
226
+ bordered?: boolean;
227
+ onSave: (item: T, options: onSaveOptions<T>) => void;
228
+ setFocusedIndex: (props: {
229
+ x: number;
230
+ y: number;
231
+ }) => void;
232
+ setIsEditing: (value: boolean) => void;
233
+ canEditTable: boolean;
234
+ setCanEditTable: (value: boolean) => void;
235
+ selectedRows: number[];
236
+ setSelectedRows: (value: number[]) => void;
237
+ checkbox?: boolean;
238
+ checkMultiple?: boolean;
239
+ onSaveNewRow?: (newRow: T) => void;
240
+ canInsertNewRow: boolean;
241
+ setCanInsertNewRow: (value: boolean) => void;
242
+ }
243
+ declare function EditableGrid<T extends Record<string, any>>({ columns, data, primaryKey, onSave, setFocusedIndex, setIsEditing, focusedIndex, isEditing, bordered, canEditTable, setCanEditTable, selectedRows, setSelectedRows, checkbox, checkMultiple, onSaveNewRow, canInsertNewRow, }: EditableGridProps<T>): JSX.Element;
244
+
245
+ declare type useEditableGridResponseProps<T> = {
246
+ data: Array<T>;
247
+ focusedIndex: {
248
+ x: number;
249
+ y: number;
250
+ };
251
+ isEditing: boolean;
252
+ setData: (props: Array<T>) => void;
253
+ setIsEditing: (value: boolean) => void;
254
+ setFocusedIndex: (props: {
255
+ x: number;
256
+ y: number;
257
+ }) => void;
258
+ onSave: (newItem: T, props: onSaveOptions<T>) => void;
259
+ canEditTable: boolean;
260
+ setCanEditTable: (value: boolean) => void;
261
+ selectedRows: number[];
262
+ setSelectedRows: (value: number[]) => void;
263
+ canInsertNewRow: boolean;
264
+ setCanInsertNewRow: (value: boolean) => void;
265
+ };
266
+ declare function useEditableGrid<T>(): useEditableGridResponseProps<T>;
267
+
268
+ declare function useEvent(event: keyof WindowEventMap, handler: (ev: any) => void, passive?: boolean): void;
269
+
270
+ export { Autocomplete, Checkbox, ColumnTitleProps, EditableGrid, EditableTableCell, FilterProps, Grid, IFilter, Input, InputMask, LargeButton, Radio, Select, Switch, Td, Tr, filterData, useEditableGrid, useEvent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluemarble/bm-components",
3
- "version": "0.0.21",
3
+ "version": "0.0.24",
4
4
  "description": "BM components",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",