@bluemarble/bm-components 0.0.81 → 0.0.83

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/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { memo, useState, useRef, useMemo, useEffect, useCallback } from 'react';
3
- import { TableHead, TableRow, TableCell, TableSortLabel, Chip, Tooltip, IconButton, Paper, LinearProgress, TableContainer, Table, TableBody, TablePagination, Popover, Box as Box$2, Typography, Autocomplete as Autocomplete$1, TextField, Button, FormControl, Select as Select$1, InputLabel, FormControlLabel, Checkbox as Checkbox$1, Switch as Switch$1, FormLabel, RadioGroup, Radio as Radio$1, CircularProgress, Stack, MenuItem, Modal as Modal$1, Dialog as Dialog$1, DialogTitle, DialogContentText, DialogActions } from '@mui/material';
3
+ import { TableHead, TableRow, TableCell, TableSortLabel, Chip, Tooltip, IconButton, Paper, LinearProgress, TableContainer, Table, TableBody, TablePagination, Popover, Box as Box$2, Typography, Autocomplete as Autocomplete$1, TextField, Button, FormControl, Select as Select$1, FormHelperText, InputLabel, FormControlLabel, Checkbox as Checkbox$1, Switch as Switch$1, FormLabel, RadioGroup, Radio as Radio$1, CircularProgress, Stack, MenuItem, Modal as Modal$1, Dialog as Dialog$1, DialogTitle, DialogContentText, DialogActions } from '@mui/material';
4
4
  import emStyled from '@emotion/styled';
5
5
  import '@emotion/react';
6
6
  import { Field, useField } from 'formik';
@@ -14804,8 +14804,8 @@ const BaseInput$1 = (props) => {
14804
14804
  const FormikInput = (_a) => {
14805
14805
  var { name, shrink } = _a, rest = __rest(_a, ["name", "shrink"]);
14806
14806
  return (React__default.createElement(Field, { name: name }, (_a) => {
14807
- var _b = _a.field, { value } = _b, field = __rest(_b, ["value"]);
14808
- return (React__default.createElement(BaseInput$1, Object.assign({ defaultValue: value }, field, rest, { InputLabelProps: Object.assign({ shrink }, rest.InputLabelProps) })));
14807
+ var _b = _a.field, { value } = _b, field = __rest(_b, ["value"]), { meta: { error } } = _a;
14808
+ return (React__default.createElement(BaseInput$1, Object.assign({ defaultValue: value, error: Boolean(error), helperText: error }, field, rest, { InputLabelProps: Object.assign({ shrink }, rest.InputLabelProps) })));
14809
14809
  }));
14810
14810
  };
14811
14811
 
@@ -14846,10 +14846,10 @@ function FormikInputMask(_a) {
14846
14846
  formikSaveFunction.current(name, unmaskedValue);
14847
14847
  }, [value]);
14848
14848
  return (React__default.createElement(Field, { name: name }, (_a) => {
14849
- var _b = _a.field, { value } = _b, field = __rest(_b, ["value"]), { form: { setFieldValue } } = _a;
14849
+ var _b = _a.field, { value } = _b, field = __rest(_b, ["value"]), { meta: { error }, form: { setFieldValue } } = _a;
14850
14850
  initialValue.current = value;
14851
14851
  formikSaveFunction.current = setFieldValue;
14852
- return React__default.createElement(BaseInput$1, Object.assign({}, rest, field, { inputRef: ref }));
14852
+ return (React__default.createElement(BaseInput$1, Object.assign({}, rest, field, { inputRef: ref, error: Boolean(error), helperText: error })));
14853
14853
  }));
14854
14854
  }
14855
14855
 
@@ -14870,16 +14870,17 @@ const BaseSelect = (_a) => {
14870
14870
  }, label: label }, rest), children)));
14871
14871
  };
14872
14872
  const FormikSelect = (_a) => {
14873
- var { name, label, children, FormControlProps, InputLabelProps } = _a, rest = __rest(_a, ["name", "label", "children", "FormControlProps", "InputLabelProps"]);
14873
+ var { name, label, children, FormControlProps, InputLabelProps, helperText } = _a, rest = __rest(_a, ["name", "label", "children", "FormControlProps", "InputLabelProps", "helperText"]);
14874
14874
  const [_b, meta, { setValue }] = useField({ name }), { value } = _b, field = __rest(_b, ["value"]);
14875
14875
  const onChange = (_, { props: { value } }) => {
14876
14876
  setValue(value);
14877
14877
  };
14878
- return (React__default.createElement(FormControl, Object.assign({ fullWidth: true }, FormControlProps),
14878
+ return (React__default.createElement(FormControl, Object.assign({ fullWidth: true }, FormControlProps, { error: Boolean(meta === null || meta === void 0 ? void 0 : meta.error) }),
14879
14879
  React__default.createElement(CustomInputLabel, Object.assign({}, InputLabelProps), label),
14880
14880
  React__default.createElement(Select$1, Object.assign({ inputProps: {
14881
14881
  name
14882
- }, label: label }, rest, field, { defaultValue: value, onChange: onChange }), children)));
14882
+ }, label: label }, rest, field, { defaultValue: value, onChange: onChange }), children),
14883
+ React__default.createElement(FormHelperText, null, helperText || (meta === null || meta === void 0 ? void 0 : meta.error))));
14883
14884
  };
14884
14885
 
14885
14886
  function Autocomplete(_a) {
@@ -14895,7 +14896,7 @@ function BaseInput(props) {
14895
14896
  }
14896
14897
  function FormikAutocomplete(_a) {
14897
14898
  var { getOptionValue, option } = _a, props = __rest(_a, ["getOptionValue", "option"]);
14898
- const [_b, , { setValue }] = useField({
14899
+ const [_b, meta, { setValue }] = useField({
14899
14900
  name: props.name
14900
14901
  }), { value: defaultValue } = _b, field = __rest(_b, ["value"]);
14901
14902
  const defaultOption = useMemo(() => {
@@ -14931,7 +14932,7 @@ function FormikAutocomplete(_a) {
14931
14932
  return a[key] === b[key];
14932
14933
  return Object.values(a)[0] === Object.values(b)[0];
14933
14934
  };
14934
- return (React__default.createElement(Autocomplete$1, Object.assign({ getOptionLabel: getOptionLabel, renderInput: (params) => (React__default.createElement(TextField, Object.assign({}, params, field, { label: props.label }))), defaultValue: defaultOption, onChange: onChange, isOptionEqualToValue: isOptionEqualToValue }, props)));
14935
+ return (React__default.createElement(Autocomplete$1, Object.assign({ getOptionLabel: getOptionLabel, renderInput: (params) => (React__default.createElement(TextField, Object.assign({ error: Boolean(meta === null || meta === void 0 ? void 0 : meta.error), helperText: meta === null || meta === void 0 ? void 0 : meta.error }, params, field, { label: props.label }))), defaultValue: defaultOption, onChange: onChange, isOptionEqualToValue: isOptionEqualToValue }, props)));
14935
14936
  }
14936
14937
 
14937
14938
  const Checkbox = (_a) => {
@@ -14953,7 +14954,7 @@ const FormikCheckbox = (_a) => {
14953
14954
  const onChange = (_, value) => {
14954
14955
  setValue(value);
14955
14956
  };
14956
- return (React__default.createElement(FormControlLabel, Object.assign({ label: label, onChange: onChange, control: React__default.createElement(Checkbox$1, Object.assign({}, props, { defaultChecked: value })) }, field, FormControlLabelProps)));
14957
+ return (React__default.createElement(FormControlLabel, Object.assign({ label: label, onChange: onChange, control: React__default.createElement(Checkbox$1, Object.assign({}, props, { defaultChecked: Boolean(value) })) }, field, FormControlLabelProps)));
14957
14958
  };
14958
14959
 
14959
14960
  const Switch = (_a) => {
@@ -15129,7 +15130,7 @@ function createFilter(filters) {
15129
15130
  };
15130
15131
  }
15131
15132
 
15132
- function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100] }) {
15133
+ function useGrid({ columns, filters = [], search, rowsPerPageOptions = [30, 60, 100] }) {
15133
15134
  const [defaultData, setDefaultData] = useState([]);
15134
15135
  const [sortedBy, setSortedBy] = useState('');
15135
15136
  const [sortedDirection, setSortedDirection] = useState('desc');
@@ -15192,10 +15193,14 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100] })
15192
15193
  setRowsPerPage(rows);
15193
15194
  };
15194
15195
  const filteredData = useMemo(() => {
15195
- const newData = defaultData.slice(0);
15196
+ let newData = defaultData.slice(0);
15197
+ if (search && search.value !== '') {
15198
+ const searchBy = createSearch(search);
15199
+ newData = newData.filter(searchBy);
15200
+ }
15196
15201
  const newFilter = createFilter(filters);
15197
15202
  return newData.filter(newFilter.apply);
15198
- }, [defaultData, filters]);
15203
+ }, [defaultData, filters, search]);
15199
15204
  const displayData = useMemo(() => {
15200
15205
  const sortedData = sortData(filteredData);
15201
15206
  const startPage = currentPage * rowsPerPage;
@@ -15220,6 +15225,44 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100] })
15220
15225
  setSort
15221
15226
  };
15222
15227
  }
15228
+ function searchKeysForValue(row, compare) {
15229
+ const rowKeys = Object.keys(row);
15230
+ let match = false;
15231
+ const isNumberOrString = (value) => ['number', 'string'].includes(typeof value);
15232
+ for (const key of rowKeys) {
15233
+ const objValue = row[key];
15234
+ if (objValue) {
15235
+ if (Array.isArray(objValue))
15236
+ match = objValue.some((obj) => isNumberOrString(obj)
15237
+ ? compare(obj)
15238
+ : searchKeysForValue(obj, compare));
15239
+ else if (typeof objValue === 'object')
15240
+ match = searchKeysForValue(objValue, compare);
15241
+ else
15242
+ match = compare(row[key]);
15243
+ if (match)
15244
+ return match;
15245
+ }
15246
+ }
15247
+ return match;
15248
+ }
15249
+ function createSearch(options) {
15250
+ const searchValue = options.caseSensitive
15251
+ ? options.value
15252
+ : String(options.value).toLowerCase();
15253
+ function compare(objValue) {
15254
+ const value = options.caseSensitive
15255
+ ? String(objValue)
15256
+ : String(objValue).toLowerCase();
15257
+ if (options.exact)
15258
+ return value === searchValue;
15259
+ return value.includes(searchValue);
15260
+ }
15261
+ return (row) => {
15262
+ const match = searchKeysForValue(row, compare);
15263
+ return match;
15264
+ };
15265
+ }
15223
15266
 
15224
15267
  /* eslint no-undef: "off" */
15225
15268
  function useEvent(event, handler, passive = false) {