@symply.io/basic-components 1.0.0-beta.9 → 1.0.1

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,4 +1,4 @@
1
1
  import { AutocompleteProps } from "./types";
2
- declare function CustomAutocomplete<T, multiple extends boolean | undefined>(props: AutocompleteProps<T, multiple>): JSX.Element;
2
+ declare function CustomAutocomplete<T, multiple extends boolean | undefined = false>(props: AutocompleteProps<T, multiple>): JSX.Element;
3
3
  export default CustomAutocomplete;
4
4
  export * from "./types";
@@ -27,12 +27,12 @@ import TextField from "@mui/material/TextField";
27
27
  import useInteractions from "./useInteractions";
28
28
  import useCustomTheme from "../useCustomTheme";
29
29
  function CustomAutocomplete(props) {
30
- var size = props.size, value = props.value, options = props.options, multiple = props.multiple, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onChange = props.onChange, rest = __rest(props, ["size", "value", "options", "multiple", "primaryColor", "secondaryColor", "onChange"]);
30
+ var size = props.size, value = props.value, options = props.options, multiple = props.multiple, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onChange = props.onChange, required = props.required, rest = __rest(props, ["size", "value", "options", "multiple", "primaryColor", "secondaryColor", "onChange", "required"]);
31
31
  var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
32
32
  var _a = useInteractions(), inputValue = _a.inputValue, onInputChange = _a.onInputChange;
33
- return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Autocomplete, { size: size, fullWidth: true, options: options, multiple: multiple, onChange: function (_, value) {
34
- onChange(value);
35
- }, inputValue: inputValue, onInputChange: onInputChange, renderInput: function (params) { return _jsx(TextField, __assign({}, params, rest, { size: size })); } }) })));
33
+ return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Autocomplete, { size: size, fullWidth: true, options: options, multiple: multiple, onChange: function (_, val) {
34
+ onChange(val);
35
+ }, isOptionEqualToValue: function (opt, val) { return opt.label === val.label; }, value: value, inputValue: inputValue, onInputChange: onInputChange, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, rest, { required: required, size: size, inputProps: __assign(__assign({}, params.inputProps), { required: required && (Array.isArray(value) ? value.length === 0 : !value) }) }))); } }) })));
36
36
  }
37
37
  export default CustomAutocomplete;
38
38
  export * from "./types";
@@ -1,10 +1,12 @@
1
1
  import { CSSProperties } from "react";
2
2
  import { TextFieldProps } from "@mui/material/TextField";
3
- export declare type AutocompleteOptionType<T> = T & {
3
+ export declare type AutocompleteOptionType<T = {
4
+ [name: string]: unknown;
5
+ }> = T & {
4
6
  label: string;
5
7
  };
6
- export declare type AutocompleteValueType<T, multiple> = multiple extends false | undefined ? AutocompleteOptionType<T> | null : Array<AutocompleteOptionType<T>> | null;
7
- export interface AutocompleteProps<T, multiple> extends Omit<TextFieldProps, "onChange"> {
8
+ export declare type AutocompleteValueType<T, multiple extends boolean | undefined> = multiple extends false | undefined ? AutocompleteOptionType<T> | null : Array<AutocompleteOptionType<T>>;
9
+ export interface AutocompleteProps<T, multiple extends boolean | undefined> extends Omit<TextFieldProps, "onChange" | "value"> {
8
10
  multiple?: multiple;
9
11
  options: Array<AutocompleteOptionType<T>>;
10
12
  value: AutocompleteValueType<T, multiple>;
@@ -1,4 +1,4 @@
1
1
  import { AutocompleteWithFilterProps } from "./types";
2
- declare function AutocompleteWithFilter<T, multiple extends boolean | undefined>(props: AutocompleteWithFilterProps<T, multiple>): JSX.Element;
2
+ declare function AutocompleteWithFilter<T, multiple extends boolean | undefined = false>(props: AutocompleteWithFilterProps<T, multiple>): JSX.Element;
3
3
  export default AutocompleteWithFilter;
4
4
  export * from "./types";
@@ -31,7 +31,7 @@ import useCustomTheme from "../useCustomTheme";
31
31
  var icon = _jsx(CheckBoxOutlineBlankIcon, { fontSize: "small" });
32
32
  var checkedIcon = _jsx(CheckBoxIcon, { fontSize: "small" });
33
33
  function AutocompleteWithFilter(props) {
34
- var size = props.size, value = props.value, options = props.options, multiple = props.multiple, disableCloseOnSelect = props.disableCloseOnSelect, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onChange = props.onChange, rest = __rest(props, ["size", "value", "options", "multiple", "disableCloseOnSelect", "primaryColor", "secondaryColor", "onChange"]);
34
+ var size = props.size, value = props.value, options = props.options, multiple = props.multiple, disableCloseOnSelect = props.disableCloseOnSelect, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onChange = props.onChange, required = props.required, rest = __rest(props, ["size", "value", "options", "multiple", "disableCloseOnSelect", "primaryColor", "secondaryColor", "onChange", "required"]);
35
35
  var filter = createFilterOptions({
36
36
  ignoreCase: true,
37
37
  ignoreAccents: true,
@@ -39,14 +39,14 @@ function AutocompleteWithFilter(props) {
39
39
  stringify: function (option) { return option.label; }
40
40
  });
41
41
  var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
42
- return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Autocomplete, { size: size, fullWidth: true, limitTags: 1, options: options, multiple: multiple, filterOptions: filter, onChange: function (_, value) {
43
- onChange(value);
44
- }, disableCloseOnSelect: disableCloseOnSelect || multiple, getOptionLabel: function (option) {
42
+ return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Autocomplete, { size: size, fullWidth: true, limitTags: 1, options: options, multiple: multiple, filterOptions: filter, onChange: function (_, val) {
43
+ onChange(val);
44
+ }, value: value, disableCloseOnSelect: disableCloseOnSelect || multiple, getOptionLabel: function (option) {
45
45
  return option.label || "";
46
46
  }, renderOption: function (props, option, _a) {
47
47
  var selected = _a.selected;
48
48
  return (_jsxs("li", __assign({}, props, { children: [_jsx(Checkbox, { icon: icon, color: "primary", checkedIcon: checkedIcon, style: { marginRight: 8 }, checked: selected }), option.label || ""] })));
49
- }, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, rest, { variant: "outlined" }))); } }) })));
49
+ }, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, rest, { variant: "outlined", required: required, inputProps: __assign(__assign({}, params.inputProps), { required: required && (Array.isArray(value) ? value.length === 0 : !value) }) }))); } }) })));
50
50
  }
51
51
  export default AutocompleteWithFilter;
52
52
  export * from "./types";
@@ -3,13 +3,13 @@ import { TextFieldProps } from "@mui/material/TextField";
3
3
  export declare type AutocompleteWithFilterOptionType<T> = T & {
4
4
  label: string;
5
5
  };
6
- export declare type AutocompleteWithFilterValueType<T, multiple> = multiple extends false | undefined ? AutocompleteWithFilterOptionType<T> | null : Array<AutocompleteWithFilterOptionType<T>> | null;
7
- export interface AutocompleteWithFilterProps<T, multiple> extends Omit<TextFieldProps, "onChange"> {
8
- value: AutocompleteWithFilterValueType<T, multiple>;
6
+ export declare type AutocompleteWithFilterlValueType<T, multiple extends boolean | undefined> = multiple extends false | undefined ? AutocompleteWithFilterOptionType<T> | null : Array<AutocompleteWithFilterOptionType<T>>;
7
+ export interface AutocompleteWithFilterProps<T, multiple extends boolean | undefined> extends Omit<TextFieldProps, "onChange" | "value"> {
8
+ value: AutocompleteWithFilterlValueType<T, multiple>;
9
9
  options: Array<AutocompleteWithFilterOptionType<T>>;
10
10
  disableCloseOnSelect?: boolean;
11
11
  multiple?: multiple;
12
12
  primaryColor?: CSSProperties["color"];
13
13
  secondaryColor?: CSSProperties["color"];
14
- onChange: (value: AutocompleteWithFilterValueType<T, multiple>) => void;
14
+ onChange: (value: AutocompleteWithFilterlValueType<T, multiple>) => void;
15
15
  }
@@ -23,7 +23,7 @@ import Grid from "@mui/material/Grid";
23
23
  function Content(props) {
24
24
  var children = props.children, title = props.title, desc = props.desc, _a = props.color, color = _a === void 0 ? "primary" : _a, loading = props.loading, disabled = props.disabled, buttons = props.buttons, _b = props.submitText, submitText = _b === void 0 ? "Save" : _b, _c = props.cancelText, cancelText = _c === void 0 ? "Cancel" : _c, _d = props.showTopRightCloseButton, showTopRightCloseButton = _d === void 0 ? false : _d, _e = props.hideBottomButtons, hideBottomButtons = _e === void 0 ? false : _e, _f = props.noForm, noForm = _f === void 0 ? false : _f, onClose = props.onClose, onSubmit = props.onSubmit;
25
25
  var theme = useTheme();
26
- return (_jsxs(_Fragment, { children: [_jsxs(DialogTitle, __assign({ id: "form-dialog-title", sx: {
26
+ return (_jsxs(_Fragment, { children: [_jsxs(DialogTitle, __assign({ sx: {
27
27
  "& > span": {
28
28
  fontWeight: "700!important"
29
29
  }
@@ -15,7 +15,7 @@ import Grid from "@mui/material/Grid";
15
15
  import useCustomTheme from "../useCustomTheme";
16
16
  import TableBodyRow from "./TableBodyRow";
17
17
  var BasicTableBody = forwardRef(function (props, ref) {
18
- var rows = props.rows, columns = props.columns, forFrozen = props.forFrozen, noDataText = props.noDataText, cellMinWidth = props.cellMinWidth;
18
+ var rows = props.rows, columns = props.columns, forFrozen = props.forFrozen, noDataText = props.noDataText;
19
19
  var theme = useCustomTheme();
20
20
  return (_jsx(Grid, __assign({ item: true, sx: {
21
21
  maxHeight: "41vh",
@@ -27,9 +27,9 @@ var BasicTableBody = forwardRef(function (props, ref) {
27
27
  width: forFrozen ? 0 : "initial"
28
28
  }
29
29
  } }, { children: _jsx("div", __assign({ ref: ref }, { children: rows && rows.length > 0 ? (rows.map(function (row, index) {
30
- return (_jsx(TableBodyRow, { row: row, rows: rows, columns: columns, cellMinWidth: cellMinWidth }, "BasicTable_".concat(index)));
30
+ return (_jsx(TableBodyRow, { row: row, rows: rows, columns: columns }, "BasicTable_".concat(index)));
31
31
  })) : (_jsx(Grid, __assign({ container: true, justifyContent: "space-around", alignItems: "center", wrap: "nowrap", sx: {
32
- height: "60px",
32
+ height: theme.spacing(7.5),
33
33
  borderBottomWidth: "thin",
34
34
  borderBottomColor: "#e5e5e5",
35
35
  borderBottomStyle: "solid",
@@ -43,7 +43,6 @@ var BasicTableBody = forwardRef(function (props, ref) {
43
43
  fontWeight: 600
44
44
  }
45
45
  } }, { children: _jsx(Grid, __assign({ item: true, xs: 4, md: 3, lg: 2, textAlign: "center", sx: {
46
- minWidth: cellMinWidth,
47
46
  paddingLeft: theme.spacing(0.625),
48
47
  paddingRight: theme.spacing(0.625)
49
48
  } }, { children: noDataText })) }))) })) })));
@@ -14,10 +14,10 @@ import { cloneElement } from "react";
14
14
  import Grid from "@mui/material/Grid";
15
15
  import useCustomTheme from "../useCustomTheme";
16
16
  function BasicTableBodyRow(props) {
17
- var row = props.row, rows = props.rows, columns = props.columns, cellMinWidth = props.cellMinWidth;
17
+ var row = props.row, rows = props.rows, columns = props.columns;
18
18
  var theme = useCustomTheme();
19
19
  return (_jsx(Grid, __assign({ container: true, justifyContent: "space-evenly", alignItems: "center", wrap: "nowrap", sx: {
20
- height: "60px",
20
+ height: theme.spacing(7.5),
21
21
  borderBottomWidth: "thin",
22
22
  borderBottomColor: "#e5e5e5",
23
23
  borderBottomStyle: "solid",
@@ -31,9 +31,10 @@ function BasicTableBodyRow(props) {
31
31
  fontWeight: 600
32
32
  }
33
33
  } }, { children: columns.map(function (col) {
34
- var accessor = col.accessor, Cell = col.Cell, _a = col.align, align = _a === void 0 ? "center" : _a;
35
- return (_jsx(Grid, __assign({ item: true, xs: 4, md: 3, lg: 2, textAlign: align, sx: {
36
- minWidth: cellMinWidth,
34
+ var accessor = col.accessor, Cell = col.Cell, _a = col.minWidth, minWidth = _a === void 0 ? "120px!important" : _a, width = col.width, _b = col.align, align = _b === void 0 ? "center" : _b;
35
+ return (_jsx(Grid, __assign({ item: true, textAlign: align, sx: {
36
+ minWidth: minWidth,
37
+ width: width,
37
38
  paddingLeft: theme.spacing(0.625),
38
39
  paddingRight: theme.spacing(0.625)
39
40
  } }, { children: cloneElement(Cell, { column: col, rows: rows, row: row }) }), accessor));
@@ -14,12 +14,12 @@ import { cloneElement } from "react";
14
14
  import Grid from "@mui/material/Grid";
15
15
  import useCustomTheme from "../useCustomTheme";
16
16
  function BasicTableFooter(props) {
17
- var footers = props.footers, cellMinWidth = props.cellMinWidth;
17
+ var footers = props.footers;
18
18
  var theme = useCustomTheme();
19
19
  return footers && footers.length > 0 ? (_jsx(Grid, __assign({ item: true, sx: {
20
20
  backgroundColor: "#eaf0f6",
21
21
  padding: theme.spacing(1.5, 0),
22
- height: "50px"
22
+ height: theme.spacing(6.25)
23
23
  } }, { children: _jsx(Grid, __assign({ container: true, justifyContent: "space-evenly", alignItems: "center", wrap: "nowrap", sx: {
24
24
  lineHeight: "24px",
25
25
  minWidth: "100%",
@@ -29,9 +29,10 @@ function BasicTableFooter(props) {
29
29
  fontWeight: 600
30
30
  }
31
31
  } }, { children: footers.map(function (footer) {
32
- var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a;
33
- return (_jsx(Grid, __assign({ item: true, xs: 4, md: 3, lg: 2, textAlign: align, sx: {
34
- minWidth: cellMinWidth,
32
+ var accessor = footer.accessor, Cell = footer.Cell, _a = footer.minWidth, minWidth = _a === void 0 ? "120px!important" : _a, width = footer.width, _b = footer.align, align = _b === void 0 ? "center" : _b;
33
+ return (_jsx(Grid, __assign({ item: true, textAlign: align, sx: {
34
+ minWidth: minWidth,
35
+ width: width,
35
36
  paddingLeft: theme.spacing(0.625),
36
37
  paddingRight: theme.spacing(0.625),
37
38
  whiteSpace: "nowrap",
@@ -14,12 +14,12 @@ import { cloneElement } from "react";
14
14
  import Grid from "@mui/material/Grid";
15
15
  import useCustomTheme from "../useCustomTheme";
16
16
  function BasicTableHeader(props) {
17
- var headers = props.headers, cellMinWidth = props.cellMinWidth;
17
+ var headers = props.headers;
18
18
  var theme = useCustomTheme();
19
19
  return headers && headers.length > 0 ? (_jsx(Grid, __assign({ item: true, sx: {
20
20
  backgroundColor: "#eaf0f6",
21
21
  padding: theme.spacing(1.5, 0),
22
- height: "50px"
22
+ height: theme.spacing(6.25)
23
23
  } }, { children: _jsx(Grid, __assign({ container: true, justifyContent: "space-evenly", alignItems: "center", wrap: "nowrap", sx: {
24
24
  lineHeight: "24px",
25
25
  minWidth: "100%",
@@ -29,9 +29,10 @@ function BasicTableHeader(props) {
29
29
  fontWeight: 600
30
30
  }
31
31
  } }, { children: headers.map(function (header) {
32
- var accessor = header.accessor, Cell = header.Cell, _a = header.align, align = _a === void 0 ? "center" : _a, title = header.title, onSort = header.onSort, _b = header.canSort, canSort = _b === void 0 ? false : _b;
33
- return (_jsx(Grid, __assign({ item: true, xs: 4, md: 3, lg: 2, title: title, textAlign: align, sx: {
34
- minWidth: cellMinWidth,
32
+ var accessor = header.accessor, Cell = header.Cell, _a = header.align, align = _a === void 0 ? "center" : _a, _b = header.minWidth, minWidth = _b === void 0 ? "120px!important" : _b, width = header.width, title = header.title, onSort = header.onSort, _c = header.canSort, canSort = _c === void 0 ? false : _c;
33
+ return (_jsx(Grid, __assign({ item: true, title: title, textAlign: align, sx: {
34
+ minWidth: minWidth,
35
+ width: width,
35
36
  paddingLeft: theme.spacing(0.625),
36
37
  paddingRight: theme.spacing(0.625),
37
38
  whiteSpace: "nowrap",
@@ -22,25 +22,21 @@ import TableHeader from "./TableHeader";
22
22
  import TableFooter from "./TableFooter";
23
23
  function BasicTable(props) {
24
24
  var _a;
25
- var _b;
26
- var _c = props.columns, columns = _c === void 0 ? [] : _c, _d = props.rows, rows = _d === void 0 ? [] : _d, _e = props.headers, headers = _e === void 0 ? [] : _e, _f = props.footers, footers = _f === void 0 ? [] : _f, _g = props.noDataText, noDataText = _g === void 0 ? "No Data!" : _g, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, _h = props.cellMinWidth, cellMinWidth = _h === void 0 ? "initial" : _h;
25
+ var _b = props.columns, columns = _b === void 0 ? [] : _b, _c = props.rows, rows = _c === void 0 ? [] : _c, _d = props.headers, headers = _d === void 0 ? [] : _d, _e = props.footers, footers = _e === void 0 ? [] : _e, _f = props.noDataText, noDataText = _f === void 0 ? "No Data!" : _f, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor;
27
26
  var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
28
27
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
29
28
  var fronzenColsCount = useMemo(function () { var _a; return (_a = columns.filter(function (col) { return col.canBeFrozen; })) === null || _a === void 0 ? void 0 : _a.length; }, [columns]);
30
29
  var canFreeze = useMemo(function () { return isUpMd && (rows === null || rows === void 0 ? void 0 : rows.length) > 0 && fronzenColsCount > 0; }, [fronzenColsCount, isUpMd, rows.length]);
31
- var _j = useScroll({
30
+ var _g = useScroll({
32
31
  canFreeze: canFreeze
33
- }), frozenWidth = _j.frozenWidth, setFrozenWidth = _j.setFrozenWidth, fixedRef = _j.fixedRef, dynamicRef = _j.dynamicRef;
32
+ }), frozenWidth = _g.frozenWidth, setFrozenWidth = _g.setFrozenWidth, fixedRef = _g.fixedRef, dynamicRef = _g.dynamicRef;
34
33
  useEffect(function () {
35
- var _a, _b;
36
- var initFrozenWidth = ((_a = document.getElementById("frozenContainer")) === null || _a === void 0 ? void 0 : _a.clientWidth) ||
37
- ((_b = fixedRef.current) === null || _b === void 0 ? void 0 : _b.clientWidth) ||
38
- fronzenColsCount * 123 ||
39
- 370;
40
34
  if (columns) {
35
+ var frozenCols = columns.filter(function (col) { return col.canBeFrozen; });
36
+ var initialFrozenWidth_1 = frozenCols.reduce(function (width, col) { return width + (col.minWidth || 120); }, 1);
41
37
  setFrozenWidth(function (fw) {
42
- if (fw !== initFrozenWidth) {
43
- return initFrozenWidth;
38
+ if (fw !== initialFrozenWidth_1) {
39
+ return initialFrozenWidth_1;
44
40
  }
45
41
  return fw;
46
42
  });
@@ -67,21 +63,17 @@ function BasicTable(props) {
67
63
  zIndex: 999,
68
64
  backgroundColor: "Menu",
69
65
  boxShadow: "6px 0 6px -4px rgba(0,0,0,0.15)"
70
- } }, { children: _jsxs(Grid, __assign({ container: true, direction: "column", justifyContent: "center" }, { children: [_jsx(TableHeader, { cellMinWidth: cellMinWidth, headers: headers.filter(function (header) { return header.canBeFrozen; }) }), _jsx(TableBody, { forFrozen: true, rows: rows, ref: fixedRef, cellMinWidth: cellMinWidth, columns: columns.filter(function (col) { return col.canBeFrozen; }) }), _jsx(TableFooter, { cellMinWidth: cellMinWidth, footers: footers.filter(function (footer) { return footer.canBeFrozen; }) })] })) }))), _jsx(Grid, __assign({ item: true, style: {
66
+ } }, { children: _jsxs(Grid, __assign({ container: true, direction: "column", justifyContent: "center" }, { children: [_jsx(TableHeader, { headers: headers.filter(function (header) { return header.canBeFrozen; }) }), _jsx(TableBody, { forFrozen: true, rows: rows, ref: fixedRef, columns: columns.filter(function (col) { return col.canBeFrozen; }) }), _jsx(TableFooter, { footers: footers.filter(function (footer) { return footer.canBeFrozen; }) })] })) }))), _jsx(Grid, __assign({ item: true, style: {
71
67
  width: "100%",
72
- marginLeft: canFreeze
73
- ? ((_b = document.getElementById("frozenContainer")) === null || _b === void 0 ? void 0 : _b.clientWidth) ||
74
- frozenWidth ||
75
- 0
76
- : 0,
68
+ marginLeft: canFreeze ? frozenWidth || 0 : 0,
77
69
  overflow: "auto"
78
- } }, { children: _jsxs(Grid, __assign({ container: true, direction: "column", justifyContent: "center" }, { children: [_jsx(TableHeader, { cellMinWidth: cellMinWidth, headers: headers.filter(function (header) {
70
+ } }, { children: _jsxs(Grid, __assign({ container: true, direction: "column", justifyContent: "center" }, { children: [_jsx(TableHeader, { headers: headers.filter(function (header) {
79
71
  return isUpMd ? !header.canBeFrozen : true;
80
72
  }) }), _jsx(TableBody, { rows: rows, ref: dynamicRef, noDataText: noDataText, columns: columns.filter(function (col) {
81
73
  return isUpMd ? !col.canBeFrozen : true;
82
- }), cellMinWidth: cellMinWidth }), _jsx(TableFooter, { footers: footers.filter(function (footer) {
74
+ }) }), _jsx(TableFooter, { footers: footers.filter(function (footer) {
83
75
  return isUpMd ? !footer.canBeFrozen : true;
84
- }), cellMinWidth: cellMinWidth })] })) }))] })) })) })));
76
+ }) })] })) }))] })) })) })));
85
77
  }
86
78
  export default BasicTable;
87
79
  export * from "./types";
@@ -15,7 +15,9 @@ export interface IColumn {
15
15
  accessor: string;
16
16
  canSort?: boolean;
17
17
  canBeFrozen?: boolean;
18
- [name: string]: unknown;
18
+ minWidth?: number;
19
+ width?: number;
20
+ [name: string]: any;
19
21
  }
20
22
  interface IHeader extends IColumn {
21
23
  Cell: ReactElement;
@@ -30,7 +32,7 @@ interface IBodyColumn extends IColumn {
30
32
  Cell: ReactElement;
31
33
  }
32
34
  export interface IRow {
33
- [name: string]: unknown;
35
+ [name: string]: any;
34
36
  }
35
37
  export interface SortingProps {
36
38
  field: string;
@@ -43,26 +45,24 @@ export interface UseTableProps {
43
45
  initialState?: InitialStateProps;
44
46
  disableSortBy?: boolean;
45
47
  onSort?: (props: SortingProps) => unknown;
48
+ [name: string]: any;
46
49
  }
47
50
  export interface UseScrollProps {
48
51
  canFreeze?: boolean;
49
52
  }
50
- interface BasicTableBaseProps {
51
- cellMinWidth?: CSSProperties["minWidth"];
52
- }
53
- export interface BasicTableHeaderProps extends BasicTableBaseProps {
53
+ export interface BasicTableHeaderProps {
54
54
  headers: Array<IHeader>;
55
55
  }
56
- export interface BasicTableFooterProps extends BasicTableBaseProps {
56
+ export interface BasicTableFooterProps {
57
57
  footers: Array<IFooter>;
58
58
  }
59
- export interface BasicTableBodyProps extends BasicTableBaseProps {
59
+ export interface BasicTableBodyProps {
60
60
  columns: Array<IBodyColumn>;
61
61
  rows: Array<IRow>;
62
62
  noDataText?: string;
63
63
  forFrozen?: boolean;
64
64
  }
65
- export interface BasicTableBodyRowProps extends BasicTableBaseProps {
65
+ export interface BasicTableBodyRowProps {
66
66
  columns: Array<IBodyColumn>;
67
67
  rows: Array<IRow>;
68
68
  row: IRow;
@@ -5,7 +5,7 @@ function useScroll(props) {
5
5
  var canFreeze = props.canFreeze;
6
6
  var theme = useTheme();
7
7
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
8
- var _a = useState(370), frozenWidth = _a[0], setFrozenWidth = _a[1];
8
+ var _a = useState(0), frozenWidth = _a[0], setFrozenWidth = _a[1];
9
9
  var fixedRef = useRef(null);
10
10
  var dynamicRef = useRef(null);
11
11
  var resetFrozenWidth = useCallback(function () {
@@ -10,6 +10,8 @@ declare function useTable(props: UseTableProps): {
10
10
  accessor: string;
11
11
  canSort: boolean | undefined;
12
12
  canBeFrozen?: boolean | undefined;
13
+ minWidth?: number | undefined;
14
+ width?: number | undefined;
13
15
  Cell: JSX.Element;
14
16
  title: string;
15
17
  onSort: ({ field }: Pick<SortingProps, "field">) => void;
@@ -23,6 +25,8 @@ declare function useTable(props: UseTableProps): {
23
25
  accessor: string;
24
26
  canSort?: boolean | undefined;
25
27
  canBeFrozen?: boolean | undefined;
28
+ minWidth?: number | undefined;
29
+ width?: number | undefined;
26
30
  Cell: import("react").FunctionComponentElement<any>;
27
31
  }[];
28
32
  columns: {
@@ -34,6 +38,8 @@ declare function useTable(props: UseTableProps): {
34
38
  accessor: string;
35
39
  canSort?: boolean | undefined;
36
40
  canBeFrozen?: boolean | undefined;
41
+ minWidth?: number | undefined;
42
+ width?: number | undefined;
37
43
  Cell: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
38
44
  }[];
39
45
  rows: import("./types").IRow[];
@@ -1,8 +1,8 @@
1
- import { CSSProperties, ReactNode } from "react";
1
+ import { CSSProperties, ReactElement } from "react";
2
2
  import { CheckboxProps } from "@mui/material/Checkbox";
3
3
  import { FormGroupProps } from "@mui/material/FormGroup";
4
4
  export interface CheckBoxProps extends Omit<CheckboxProps, "onChange"> {
5
- label: string | ReactNode;
5
+ label: string | ReactElement;
6
6
  onChange: (val: boolean) => void;
7
7
  primaryColor?: CSSProperties["color"];
8
8
  secondaryColor?: CSSProperties["color"];
@@ -26,7 +26,7 @@ function FormRadioGroup(props) {
26
26
  onChange(event.target.value);
27
27
  }, sx: {
28
28
  my: 1,
29
- "& label span:first-child span:first-child": {
29
+ "& label span:first-of-type span:first-of-type": {
30
30
  margin: "-5px 0 -5px 0"
31
31
  }
32
32
  } }, { children: options.map(function (opt) {
@@ -0,0 +1,3 @@
1
+ import { LoadingModalProps } from "./types";
2
+ declare function LoadingModal(props: LoadingModalProps): JSX.Element;
3
+ export default LoadingModal;
@@ -0,0 +1,29 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import Box from "@mui/material/Box";
14
+ import Grid from "@mui/material/Grid";
15
+ import Dialog from "@mui/material/Dialog";
16
+ import DialogContent from "@mui/material/DialogContent";
17
+ import Typography from "@mui/material/Typography";
18
+ import CircularProgress from "@mui/material/CircularProgress";
19
+ import ThemeProvider from "@mui/material/styles/ThemeProvider";
20
+ import useCustomTheme from "../useCustomTheme";
21
+ function LoadingModal(props) {
22
+ var open = props.open, _a = props.text, text = _a === void 0 ? "Loading..." : _a, _b = props.direction, direction = _b === void 0 ? "column" : _b, _c = props.showProgess, showProgess = _c === void 0 ? false : _c, _d = props.percent, percent = _d === void 0 ? 0 : _d, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor;
23
+ var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
24
+ return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Dialog, __assign({ maxWidth: "xs", open: open, sx: { backgroundColor: "#7A7A7A97" }, PaperProps: { sx: { backgroundColor: "#F2F2F2CF" } }, onClose: function (_, reason) {
25
+ if (reason === "backdropClick")
26
+ return;
27
+ }, disableEscapeKeyDown: true }, { children: _jsx(DialogContent, { children: _jsxs(Grid, __assign({ container: true, direction: direction, justifyContent: "space-between", alignItems: "center", "data-testid": "loading-grid" }, { children: [_jsxs(Box, __assign({ position: "relative", display: "inline-flex", sx: { mt: 1.25 } }, { children: [_jsx(CircularProgress, { size: showProgess ? 56 : 40, value: percent, variant: showProgess ? "determinate" : "indeterminate" }), showProgess && percent >= 0 && (_jsx(Box, __assign({ top: 0, left: 0, bottom: 0, right: 0, position: "absolute", display: "flex", alignItems: "center", justifyContent: "center" }, { children: _jsxs(Typography, __assign({ variant: "caption" }, { children: [Math.round(percent), "%"] })) })))] })), _jsx(Typography, __assign({ variant: "subtitle1", component: "span", sx: { mt: 1 } }, { children: text }))] })) }) })) })));
28
+ }
29
+ export default LoadingModal;
@@ -1,4 +1,4 @@
1
- import { LoadingModalProps } from "./types";
2
- declare function LoadingModal(props: LoadingModalProps): JSX.Element;
1
+ import LoadingModal from "./Modal";
3
2
  export default LoadingModal;
3
+ export * from "./useLoadingModal";
4
4
  export * from "./types";
@@ -1,30 +1,4 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import Box from "@mui/material/Box";
14
- import Grid from "@mui/material/Grid";
15
- import Dialog from "@mui/material/Dialog";
16
- import DialogContent from "@mui/material/DialogContent";
17
- import Typography from "@mui/material/Typography";
18
- import CircularProgress from "@mui/material/CircularProgress";
19
- import ThemeProvider from "@mui/material/styles/ThemeProvider";
20
- import useCustomTheme from "../useCustomTheme";
21
- function LoadingModal(props) {
22
- var open = props.open, _a = props.text, text = _a === void 0 ? "Loading..." : _a, _b = props.direction, direction = _b === void 0 ? "column" : _b, _c = props.showProgess, showProgess = _c === void 0 ? false : _c, _d = props.percent, percent = _d === void 0 ? 0 : _d, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor;
23
- var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
24
- return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Dialog, __assign({ maxWidth: "xs", open: open, sx: { backgroundColor: "#7A7A7A97" }, PaperProps: { sx: { backgroundColor: "#F2F2F2CF" } }, onClose: function (_, reason) {
25
- if (reason === "backdropClick")
26
- return;
27
- }, disableEscapeKeyDown: true }, { children: _jsx(DialogContent, { children: _jsxs(Grid, __assign({ container: true, direction: direction, justifyContent: "space-between", alignItems: "center", "data-testid": "loading-grid" }, { children: [_jsxs(Box, __assign({ position: "relative", display: "inline-flex", sx: { mt: 1.25 } }, { children: [_jsx(CircularProgress, { size: showProgess ? 56 : 40, value: percent, variant: showProgess ? "determinate" : "indeterminate" }), showProgess && percent >= 0 && (_jsx(Box, __assign({ top: 0, left: 0, bottom: 0, right: 0, position: "absolute", display: "flex", alignItems: "center", justifyContent: "center" }, { children: _jsxs(Typography, __assign({ variant: "caption" }, { children: [Math.round(percent), "%"] })) })))] })), _jsx(Typography, __assign({ variant: "subtitle1", component: "span", sx: { mt: 1 } }, { children: text }))] })) }) })) })));
28
- }
1
+ import LoadingModal from "./Modal";
29
2
  export default LoadingModal;
3
+ export * from "./useLoadingModal";
30
4
  export * from "./types";
@@ -1,4 +1,4 @@
1
- import { CSSProperties } from "react";
1
+ import { CSSProperties, ReactElement } from "react";
2
2
  import { GridProps } from "@mui/material/Grid";
3
3
  export interface LoadingModalProps {
4
4
  open: boolean;
@@ -9,3 +9,16 @@ export interface LoadingModalProps {
9
9
  primaryColor?: CSSProperties["color"];
10
10
  secondaryColor?: CSSProperties["color"];
11
11
  }
12
+ export interface LoadingModalInstanceProps {
13
+ id: string;
14
+ text: string;
15
+ }
16
+ export interface LoadingModalContextProps {
17
+ onOpenLoadingModal: (text?: string) => LoadingModalInstanceProps | null;
18
+ onCloseLoadingModal: (instance: LoadingModalInstanceProps) => void;
19
+ }
20
+ export interface LoadingModalProviderProps {
21
+ children: ReactElement;
22
+ primaryColor?: CSSProperties["color"];
23
+ secondaryColor?: CSSProperties["color"];
24
+ }
@@ -0,0 +1,3 @@
1
+ import { LoadingModalContextProps, LoadingModalProviderProps } from "./types";
2
+ export declare function LoadingModalProvider(props: LoadingModalProviderProps): JSX.Element;
3
+ export declare function useLoadingModal(): LoadingModalContextProps;
@@ -0,0 +1,57 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
22
+ import { cloneElement, useMemo, useState, useContext, useCallback, createContext } from "react";
23
+ import generateUUID from "../utils/uuid";
24
+ import LoadingModal from "./Modal";
25
+ var LoadingModalContext = createContext({
26
+ onOpenLoadingModal: function () { return null; },
27
+ onCloseLoadingModal: function () { }
28
+ });
29
+ export function LoadingModalProvider(props) {
30
+ var children = props.children, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor;
31
+ var _a = useState([]), instances = _a[0], setInstances = _a[1];
32
+ var modalArgs = useMemo(function () {
33
+ return instances.length > 0
34
+ ? {
35
+ open: true,
36
+ text: instances[instances.length - 1].text
37
+ }
38
+ : { open: false, text: "Loading..." };
39
+ }, [instances]);
40
+ var onOpenLoadingModal = useCallback(function (loadingText) {
41
+ var instance = {
42
+ id: generateUUID(),
43
+ text: loadingText || "Loading..."
44
+ };
45
+ setInstances(function (insts) { return __spreadArray(__spreadArray([], insts, true), [instance], false); });
46
+ return instance;
47
+ }, []);
48
+ var onCloseLoadingModal = useCallback(function (instance) {
49
+ if (instance === null || instance === void 0 ? void 0 : instance.id) {
50
+ setInstances(function (insts) { return __spreadArray([], insts.filter(function (inst) { return inst.id !== instance.id; }), true); });
51
+ }
52
+ }, []);
53
+ return (_jsx(LoadingModalContext.Provider, __assign({ value: { onOpenLoadingModal: onOpenLoadingModal, onCloseLoadingModal: onCloseLoadingModal } }, { children: _jsxs(_Fragment, { children: [cloneElement(children), _jsx(LoadingModal, __assign({}, modalArgs, { primaryColor: primaryColor, secondaryColor: secondaryColor }))] }) })));
54
+ }
55
+ export function useLoadingModal() {
56
+ return useContext(LoadingModalContext);
57
+ }
package/README.md CHANGED
@@ -211,20 +211,23 @@ Reusable table component
211
211
  ```tsx
212
212
  import { BasicTable, useTable } from '@symply.io/basic-components';
213
213
  // or
214
- import BasicTable, { useTable } from '@symply.io/basic-components//BasicTable';
214
+ import BasicTable, { useTable } from '@symply.io/basic-components/BasicTable';
215
215
  ```
216
216
 
217
217
  <h5>Column Props (IColumn)</h5>
218
218
 
219
- | Name | Type | Default | Required | Description |
220
- | ----------- | --------------------------- | ------- | -------- | ----------------------------------------------- |
221
- | Body | ReactElement | | true | The component to render the column body cell. |
222
- | Header | ReactElement | | true | The component to render the column header cell. |
223
- | Footer | ReactElement | | false | The component to render the column footer cell. |
224
- | accessor | string | | true | The key of the column, it should be unique. |
225
- | align | "left" \|"center" \|"right" | | false | The alignment of the column. |
226
- | canBeFrozen | bool | | false | If true, the column can be frozen |
227
- | canSort | bool | | false | If true, the column can be sortable. |
219
+ | Name | Type | Default | Required | Description |
220
+ | ----------- | --------------------------- | ------- | -------- | ----------------------------------------------------- |
221
+ | accessor | string | | true | The key of the column, it should be unique. |
222
+ | align | "left" \|"center" \|"right" | | false | The alignment of the column. |
223
+ | Body | ReactElement | | true | The component to render the column body cell. |
224
+ | canBeFrozen | bool | | false | If true, the column can be frozen |
225
+ | canSort | bool | | false | If true, the column can be sortable. |
226
+ | Header | ReactElement | | true | The component to render the column header cell. |
227
+ | headerTip | string | | false | The tip title text when the mouse is over the header. |
228
+ | Footer | ReactElement | | false | The component to render the column footer cell. |
229
+ | minWidth | number | 120 | false | The minimum width of cells. |
230
+ | width | number | | false | The fixed width of cells. |
228
231
 
229
232
  <h5>Hook Props</h5>
230
233
 
@@ -295,10 +298,10 @@ import CheckBox from '@symply.io/basic-components/CheckBox/CheckBox';
295
298
 
296
299
  <h5>Props</h5>
297
300
 
298
- | Name | Type | Default | Required | Description |
299
- | -------- | ------------------- | ------- | -------- | ------------------------------------------------------------ |
300
- | label | string \| ReactNode | | true | The label of the checkbox. |
301
- | onChange | func | | true | Callback fired when the `checkbox` value is changed.<br />**Signature:**<br/>`function(value: boolean) => void`<br/>*value:* The value of the `checkbox` element. |
301
+ | Name | Type | Default | Required | Description |
302
+ | -------- | ---------------------- | ------- | -------- | ------------------------------------------------------------ |
303
+ | label | string \| ReactElement | | true | The label of the checkbox. |
304
+ | onChange | func | | true | Callback fired when the `checkbox` value is changed.<br />**Signature:**<br/>`function(value: boolean) => void`<br/>*value:* The value of the `checkbox` element. |
302
305
 
303
306
 
304
307
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.0.0-beta.9",
3
+ "version": "1.0.1",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",
@@ -53,9 +53,9 @@
53
53
  "dependencies": {
54
54
  "@emotion/react": "^11.7.1",
55
55
  "@emotion/styled": "^11.6.0",
56
- "@mui/icons-material": "^5.4.2",
57
- "@mui/material": "^5.4.2",
58
- "@mui/system": "^5.4.2",
56
+ "@mui/icons-material": "~5.4.2",
57
+ "@mui/material": "~5.4.2",
58
+ "@mui/system": "~5.4.2",
59
59
  "@reach/router": "^1.3.4",
60
60
  "color-alpha": "^1.1.3",
61
61
  "react-player": "^2.9.0",
@@ -0,0 +1,2 @@
1
+ declare function generateUUID(length?: number): string;
2
+ export default generateUUID;
package/utils/uuid.js ADDED
@@ -0,0 +1,56 @@
1
+ function generateUUID(length) {
2
+ if (length === void 0) { length = 32; }
3
+ if (length < 16)
4
+ throw new Error("Length should be equal or greater than 16");
5
+ function UUID() {
6
+ this.chars = [
7
+ "a",
8
+ "1",
9
+ "2",
10
+ "b",
11
+ "3",
12
+ "4",
13
+ "c",
14
+ "5",
15
+ "6",
16
+ "d",
17
+ "7",
18
+ "8",
19
+ "e",
20
+ "9",
21
+ "0",
22
+ "f"
23
+ ];
24
+ this.rand = "";
25
+ }
26
+ UUID.prototype = {
27
+ getRandomUInt: function () {
28
+ var s = "";
29
+ this.chars.sort(function () {
30
+ return Date.now() % (Math.random() * length * 23) >
31
+ Math.random() * 7 * length
32
+ ? -1
33
+ : 1;
34
+ });
35
+ for (var i = 0; i < this.chars.length; i += 1) {
36
+ s = s.concat(this.chars[i]);
37
+ }
38
+ return s;
39
+ },
40
+ getRandomChars: function () {
41
+ this.rand = Date.now().toString(16).concat(this.getRandomUInt());
42
+ return this.rand;
43
+ },
44
+ generate: function () {
45
+ var id = Date.now().toString();
46
+ var idLen = id.length;
47
+ this.getRandomChars();
48
+ for (var i = 0; i < length - idLen; i += 1) {
49
+ id = id.concat(this.rand.charAt(Math.floor(Math.random() * this.rand.length)));
50
+ }
51
+ return id.toString();
52
+ }
53
+ };
54
+ return new UUID().generate();
55
+ }
56
+ export default generateUUID;