@scenid/react-formulator 0.4.1 → 0.4.3

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/index.cjs.js CHANGED
@@ -18,8 +18,8 @@ var cx = require('classnames');
18
18
  var styles$o = require('@material-ui/styles');
19
19
  var AutorenewIcon = require('@material-ui/icons/Autorenew');
20
20
  var _TextField = require('@material-ui/core/esm/TextField');
21
- var luxon = require('luxon');
22
21
  var _CircularProgress = require('@material-ui/core/esm/CircularProgress');
22
+ var luxon = require('luxon');
23
23
  var Popper = require('@material-ui/core/Popper');
24
24
  var ListSubheader = require('@material-ui/core/ListSubheader');
25
25
  var Paper = require('@material-ui/core/Paper');
@@ -31773,7 +31773,7 @@ var useFetchOptions = function useFetchOptions(arg) {
31773
31773
  loading = _useState2[0],
31774
31774
  setLoading = _useState2[1];
31775
31775
 
31776
- var _useState3 = React.useState(Array.isArray(arg) || []),
31776
+ var _useState3 = React.useState(),
31777
31777
  _useState4 = _slicedToArray(_useState3, 2),
31778
31778
  options = _useState4[0],
31779
31779
  setOptions = _useState4[1];
@@ -31896,6 +31896,11 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31896
31896
  }
31897
31897
  });
31898
31898
  }, [onChange]);
31899
+ React.useEffect(function () {
31900
+ if (!readOnly) {
31901
+ fetch();
31902
+ }
31903
+ }, []);
31899
31904
 
31900
31905
  if (readOnly) {
31901
31906
  return /*#__PURE__*/React__default["default"].createElement(FormField$1, {
@@ -31907,6 +31912,28 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31907
31912
  });
31908
31913
  }
31909
31914
 
31915
+ if (!options) {
31916
+ return /*#__PURE__*/React__default["default"].createElement(_FormControl__default["default"], {
31917
+ error: dirty && hasErrors,
31918
+ margin: "dense",
31919
+ fullWidth: true,
31920
+ required: required
31921
+ }, /*#__PURE__*/React__default["default"].createElement(_TextField__default["default"], {
31922
+ label: label,
31923
+ variant: variant,
31924
+ value: value,
31925
+ disabled: true,
31926
+ InputProps: {
31927
+ endAdornment: /*#__PURE__*/React__default["default"].createElement(_InputAdornment__default["default"], {
31928
+ position: "end"
31929
+ }, /*#__PURE__*/React__default["default"].createElement(_CircularProgress__default["default"], {
31930
+ size: 20,
31931
+ thickness: 4
31932
+ }))
31933
+ }
31934
+ }));
31935
+ }
31936
+
31910
31937
  return /*#__PURE__*/React__default["default"].createElement(_FormControl__default["default"], {
31911
31938
  error: dirty && hasErrors,
31912
31939
  margin: "dense",
package/dist/index.esm.js CHANGED
@@ -16,8 +16,8 @@ import cx from 'classnames';
16
16
  import { makeStyles as makeStyles$1 } from '@material-ui/styles';
17
17
  import AutorenewIcon from '@material-ui/icons/Autorenew';
18
18
  import _TextField from '@material-ui/core/esm/TextField';
19
- import { DateTime } from 'luxon';
20
19
  import _CircularProgress from '@material-ui/core/esm/CircularProgress';
20
+ import { DateTime } from 'luxon';
21
21
  import Popper from '@material-ui/core/Popper';
22
22
  import ListSubheader from '@material-ui/core/ListSubheader';
23
23
  import Paper from '@material-ui/core/Paper';
@@ -31704,7 +31704,7 @@ var useFetchOptions = function useFetchOptions(arg) {
31704
31704
  loading = _useState2[0],
31705
31705
  setLoading = _useState2[1];
31706
31706
 
31707
- var _useState3 = useState(Array.isArray(arg) || []),
31707
+ var _useState3 = useState(),
31708
31708
  _useState4 = _slicedToArray(_useState3, 2),
31709
31709
  options = _useState4[0],
31710
31710
  setOptions = _useState4[1];
@@ -31827,6 +31827,11 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31827
31827
  }
31828
31828
  });
31829
31829
  }, [onChange]);
31830
+ useEffect(function () {
31831
+ if (!readOnly) {
31832
+ fetch();
31833
+ }
31834
+ }, []);
31830
31835
 
31831
31836
  if (readOnly) {
31832
31837
  return /*#__PURE__*/React__default.createElement(FormField$1, {
@@ -31838,6 +31843,28 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31838
31843
  });
31839
31844
  }
31840
31845
 
31846
+ if (!options) {
31847
+ return /*#__PURE__*/React__default.createElement(_FormControl, {
31848
+ error: dirty && hasErrors,
31849
+ margin: "dense",
31850
+ fullWidth: true,
31851
+ required: required
31852
+ }, /*#__PURE__*/React__default.createElement(_TextField, {
31853
+ label: label,
31854
+ variant: variant,
31855
+ value: value,
31856
+ disabled: true,
31857
+ InputProps: {
31858
+ endAdornment: /*#__PURE__*/React__default.createElement(_InputAdornment, {
31859
+ position: "end"
31860
+ }, /*#__PURE__*/React__default.createElement(_CircularProgress, {
31861
+ size: 20,
31862
+ thickness: 4
31863
+ }))
31864
+ }
31865
+ }));
31866
+ }
31867
+
31841
31868
  return /*#__PURE__*/React__default.createElement(_FormControl, {
31842
31869
  error: dirty && hasErrors,
31843
31870
  margin: "dense",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scenid/react-formulator",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "repository": "https://dennykoch@bitbucket.org/scenid/react-formulator.git",
@@ -1,7 +1,15 @@
1
- import React, { useCallback } from 'react'
1
+ import React, { useEffect, useCallback } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
- import { Box, Typography, FormControl, FormHelperText } from '@material-ui/core'
4
+ import {
5
+ Box,
6
+ Typography,
7
+ FormControl,
8
+ FormHelperText,
9
+ TextField,
10
+ InputAdornment,
11
+ CircularProgress
12
+ } from '@material-ui/core'
5
13
 
6
14
  import FormField from '../FormField'
7
15
  import FormReadOnlyText from '../../ReadOnly/FormReadOnlyText'
@@ -29,6 +37,12 @@ const FormAutocomplete = ({
29
37
 
30
38
  const changeValue = useCallback(newValue => { onChange({ target: { name, value: newValue?.entry || '' } }) }, [onChange])
31
39
 
40
+ useEffect(() => {
41
+ if (!readOnly) {
42
+ fetch()
43
+ }
44
+ }, [])
45
+
32
46
  if (readOnly) {
33
47
  return (
34
48
  <FormField
@@ -41,6 +55,34 @@ const FormAutocomplete = ({
41
55
  )
42
56
  }
43
57
 
58
+ if (!options) {
59
+ return (
60
+ <FormControl
61
+ error={dirty && hasErrors}
62
+ margin="dense"
63
+ fullWidth
64
+ required={required}
65
+ >
66
+ <TextField
67
+ label={label}
68
+ variant={variant}
69
+ value={value}
70
+ disabled
71
+ InputProps={{
72
+ endAdornment: (
73
+ <InputAdornment position="end">
74
+ <CircularProgress
75
+ size={20}
76
+ thickness={4}
77
+ />
78
+ </InputAdornment>
79
+ )
80
+ }}
81
+ />
82
+ </FormControl>
83
+ )
84
+ }
85
+
44
86
  return (
45
87
  <FormControl
46
88
  error={dirty && hasErrors}
@@ -35,7 +35,7 @@ const useFetchOptions = (arg, fetchOptions = {}) => {
35
35
  const controller = useRef()
36
36
 
37
37
  const [loading, setLoading] = useState(false)
38
- const [options, setOptions] = useState(Array.isArray(arg) || [])
38
+ const [options, setOptions] = useState()
39
39
 
40
40
  const fetch = useCallback(async () => {
41
41
  if (Array.isArray(arg)) return setOptions(arg)
@@ -141,7 +141,8 @@ Types.args = {
141
141
  hiddenGroupInput1: 'sensitive data',
142
142
  hiddenGroupInput2: 'non-public information',
143
143
  hiddenGroupInput3: 'top secret value',
144
- autocompleteField1: catBreeds[5].entry
144
+ autocompleteField1: catBreeds[5].entry,
145
+ autocompleteField2: catBreeds[10].entry
145
146
  }
146
147
  }
147
148