@bluemarble/bm-components 0.0.10 → 0.0.13

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,9 +1,8 @@
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 } 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, InputLabel, FormControlLabel, Checkbox as Checkbox$1, Switch as Switch$1, FormLabel, RadioGroup, Radio as Radio$1, CircularProgress } from '@mui/material';
4
4
  import emStyled from '@emotion/styled';
5
5
  import '@emotion/react';
6
- import { useTable } from 'react-table';
7
6
  import { Field, useField } from 'formik';
8
7
 
9
8
  const GridHeader = ({ setOrder, setOrderBy, order, orderBy, titles = [], }) => {
@@ -14760,18 +14759,6 @@ const EditableTableCell = (allProps) => {
14760
14759
  }, isEditing: isEditing, name: name, rowData: rowData, onSave: onSave, handleCancelEditing: handleCancelEditing, setIsEditing: setIsEditing, formatInputDefautvalue: formatInputDefautvalue, type: type })))) : (React__default.createElement(React__default.Fragment, null, formatCellValue(value)))));
14761
14760
  };
14762
14761
 
14763
- function GridV2({ columns, data, }) {
14764
- const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({ columns, data });
14765
- return (React__default.createElement("table", Object.assign({}, getTableProps()),
14766
- React__default.createElement("thead", null, headerGroups.map((headerGroup) => (React__default.createElement("tr", Object.assign({}, headerGroup.getHeaderGroupProps()), headerGroup.headers.map((column) => (React__default.createElement("th", Object.assign({}, column.getHeaderProps()), column.render("Header")))))))),
14767
- React__default.createElement("tbody", Object.assign({}, getTableBodyProps()), rows.map((row, i) => {
14768
- prepareRow(row);
14769
- return (React__default.createElement("tr", Object.assign({}, row.getRowProps()), row.cells.map((cell) => {
14770
- return React__default.createElement("td", Object.assign({}, cell.getCellProps()), cell.render("Cell"));
14771
- })));
14772
- }))));
14773
- }
14774
-
14775
14762
  const Input = (_a) => {
14776
14763
  var { withFormik = true } = _a, rest = __rest(_a, ["withFormik"]);
14777
14764
  if (withFormik)
@@ -14785,8 +14772,8 @@ const BaseInput$1 = (props) => {
14785
14772
  const FormikInput = (_a) => {
14786
14773
  var { name } = _a, rest = __rest(_a, ["name"]);
14787
14774
  return (React__default.createElement(Field, { name: name }, (_a) => {
14788
- var _b = _a.field, field = __rest(_b, ["value"]);
14789
- return (React__default.createElement(BaseInput$1, Object.assign({}, field, rest)));
14775
+ var _b = _a.field, { value } = _b, field = __rest(_b, ["value"]);
14776
+ return (React__default.createElement(BaseInput$1, Object.assign({}, field, rest, { defaultValue: value })));
14790
14777
  }));
14791
14778
  };
14792
14779
 
@@ -14813,15 +14800,20 @@ const BaseInputMask = (_a) => {
14813
14800
  function FormikInputMask(_a) {
14814
14801
  var { mask, defaultValue, name } = _a, rest = __rest(_a, ["mask", "defaultValue", "name"]);
14815
14802
  const { ref, value, unmaskedValue, setValue } = useIMask(mask);
14803
+ const initialValue = useRef();
14816
14804
  useEffect(() => {
14817
14805
  if (!value && defaultValue)
14818
14806
  setValue(String(defaultValue));
14807
+ else if (initialValue.current) {
14808
+ setValue(String(initialValue.current));
14809
+ }
14819
14810
  }, [defaultValue]);
14820
14811
  const onChange = (setFieldValue) => {
14821
14812
  setFieldValue(name, unmaskedValue);
14822
14813
  };
14823
14814
  return (React__default.createElement(Field, { name: name }, (_a) => {
14824
- var _b = _a.field, field = __rest(_b, ["value"]), { form: { setFieldValue } } = _a;
14815
+ var _b = _a.field, { value } = _b, field = __rest(_b, ["value"]), { form: { setFieldValue } } = _a;
14816
+ initialValue.current = value;
14825
14817
  return (React__default.createElement(BaseInput$1, Object.assign({}, rest, field, { onChange: () => onChange(setFieldValue), inputRef: ref })));
14826
14818
  }));
14827
14819
  }
@@ -14844,7 +14836,7 @@ const BaseSelect = (_a) => {
14844
14836
  };
14845
14837
  const FormikSelect = (_a) => {
14846
14838
  var { name, label, children, FormControlProps, InputLabelProps } = _a, rest = __rest(_a, ["name", "label", "children", "FormControlProps", "InputLabelProps"]);
14847
- const [_b, meta, { setValue }] = useField({ name }), field = __rest(_b, ["value"]);
14839
+ const [_b, meta, { setValue }] = useField({ name }), { value } = _b, field = __rest(_b, ["value"]);
14848
14840
  const onChange = (_, { props: { value } }) => {
14849
14841
  setValue(value);
14850
14842
  };
@@ -14852,7 +14844,7 @@ const FormikSelect = (_a) => {
14852
14844
  React__default.createElement(CustomInputLabel, Object.assign({}, InputLabelProps), label),
14853
14845
  React__default.createElement(Select$1, Object.assign({ inputProps: {
14854
14846
  name,
14855
- }, label: label }, rest, field, { onChange: onChange }), children)));
14847
+ }, label: label }, rest, field, { defaultValue: value, onChange: onChange }), children)));
14856
14848
  };
14857
14849
 
14858
14850
  function Autocomplete(_a) {
@@ -14868,7 +14860,9 @@ function BaseInput(props) {
14868
14860
  }
14869
14861
  function FormikAutocomplete(_a) {
14870
14862
  var { getOptionValue } = _a, props = __rest(_a, ["getOptionValue"]);
14871
- const [_b, , { setValue }] = useField({ name: props.name }), field = __rest(_b, []);
14863
+ const [_b, , { setValue }] = useField({
14864
+ name: props.name,
14865
+ }), { value: defaultValue } = _b, field = __rest(_b, ["value"]);
14872
14866
  const onChange = (_, newValue) => {
14873
14867
  if (getOptionValue) {
14874
14868
  setValue(getOptionValue(newValue));
@@ -14876,7 +14870,7 @@ function FormikAutocomplete(_a) {
14876
14870
  else
14877
14871
  setValue(newValue);
14878
14872
  };
14879
- return (React__default.createElement(Autocomplete$1, Object.assign({}, props, { renderInput: (params) => (React__default.createElement(TextField, Object.assign({}, params, field, { label: props.label }))), onChange: onChange })));
14873
+ return (React__default.createElement(Autocomplete$1, Object.assign({}, props, { renderInput: (params) => (React__default.createElement(TextField, Object.assign({}, params, field, { label: props.label }))), defaultValue: props.options.find((option) => Object.values(option)[0] === defaultValue), onChange: onChange })));
14880
14874
  }
14881
14875
 
14882
14876
  const Checkbox = (_a) => {
@@ -14894,11 +14888,11 @@ const FormikCheckbox = (_a) => {
14894
14888
  var { label, name, FormControlLabelProps } = _a, props = __rest(_a, ["label", "name", "FormControlLabelProps"]);
14895
14889
  const [_b, , { setValue }] = useField({
14896
14890
  name,
14897
- }), field = __rest(_b, ["value", "onChange"]);
14891
+ }), { value, onChange: unused } = _b, field = __rest(_b, ["value", "onChange"]);
14898
14892
  const onChange = (_, value) => {
14899
14893
  setValue(value);
14900
14894
  };
14901
- return (React__default.createElement(FormControlLabel, Object.assign({ label: label, onChange: onChange, control: React__default.createElement(Checkbox$1, Object.assign({}, props)) }, field, FormControlLabelProps)));
14895
+ return (React__default.createElement(FormControlLabel, Object.assign({ label: label, onChange: onChange, control: React__default.createElement(Checkbox$1, Object.assign({}, props, { defaultChecked: value })) }, field, FormControlLabelProps)));
14902
14896
  };
14903
14897
 
14904
14898
  const Switch = (_a) => {
@@ -14916,11 +14910,11 @@ const FormikSwitch = (_a) => {
14916
14910
  var { label, name, FormControlLabelProps } = _a, props = __rest(_a, ["label", "name", "FormControlLabelProps"]);
14917
14911
  const [_b, , { setValue }] = useField({
14918
14912
  name,
14919
- }), field = __rest(_b, ["value", "onChange"]);
14913
+ }), { value, onChange: unused } = _b, field = __rest(_b, ["value", "onChange"]);
14920
14914
  const onChange = (_, value) => {
14921
14915
  setValue(value);
14922
14916
  };
14923
- return (React__default.createElement(FormControlLabel, Object.assign({ label: label, onChange: onChange, control: React__default.createElement(Switch$1, Object.assign({}, props)) }, field, FormControlLabelProps)));
14917
+ return (React__default.createElement(FormControlLabel, Object.assign({ label: label, onChange: onChange, control: React__default.createElement(Switch$1, Object.assign({}, props, { defaultChecked: value })) }, field, FormControlLabelProps)));
14924
14918
  };
14925
14919
 
14926
14920
  const Radio = (_a) => {
@@ -14941,15 +14935,15 @@ const FormikRadio = (_a) => {
14941
14935
  const onChange = (setFieldValue, value) => {
14942
14936
  setFieldValue(name, value);
14943
14937
  };
14944
- return (React__default.createElement(Field, null, ({ form: { setFieldValue } }) => (React__default.createElement(FormControl, null,
14938
+ return (React__default.createElement(Field, null, ({ field: { value }, form: { setFieldValue } }) => (React__default.createElement(FormControl, null,
14945
14939
  label && React__default.createElement(FormLabel, null, label),
14946
- React__default.createElement(RadioGroup, Object.assign({ onChange: (_, value) => onChange(setFieldValue, value) }, rest), options.map((option) => (React__default.createElement(FormControlLabel, { key: String(option.value), value: option.value, label: option.label, control: React__default.createElement(Radio$1, null) }))))))));
14940
+ React__default.createElement(RadioGroup, Object.assign({ defaultValue: value, onChange: (_, value) => onChange(setFieldValue, value) }, rest), options.map((option) => (React__default.createElement(FormControlLabel, { key: String(option.value), value: option.value, label: option.label, control: React__default.createElement(Radio$1, null) }))))))));
14947
14941
  };
14948
14942
 
14949
14943
  const LargeButton = (_a) => {
14950
- var { loading, children } = _a, rest = __rest(_a, ["loading", "children"]);
14951
- return (React__default.createElement(Button, Object.assign({ variant: "contained", fullWidth: true, sx: Object.assign({ color: "#fff", fontWeight: "bold" }, rest.sx) }, rest), children));
14944
+ var { loading, children, CircularProgressProps } = _a, rest = __rest(_a, ["loading", "children", "CircularProgressProps"]);
14945
+ return (React__default.createElement(Button, Object.assign({ variant: "contained", fullWidth: true, sx: Object.assign({ color: "#fff", fontWeight: "bold" }, rest.sx), disabled: rest.disabled || loading }, rest), loading ? (React__default.createElement(CircularProgress, Object.assign({ size: 25, color: "inherit" }, CircularProgressProps))) : (children)));
14952
14946
  };
14953
14947
 
14954
- export { Autocomplete, Checkbox, EditableTableCell, Grid, GridV2, Input, InputMask, LargeButton, Radio, Select, Switch, Td, Tr, filterData };
14948
+ export { Autocomplete, Checkbox, EditableTableCell, Grid, Input, InputMask, LargeButton, Radio, Select, Switch, Td, Tr, filterData };
14955
14949
  //# sourceMappingURL=index.js.map