@scenid/react-formulator 0.4.2 → 0.4.4

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];
@@ -31897,7 +31897,9 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31897
31897
  });
31898
31898
  }, [onChange]);
31899
31899
  React.useEffect(function () {
31900
- fetch();
31900
+ if (!readOnly) {
31901
+ fetch();
31902
+ }
31901
31903
  }, []);
31902
31904
 
31903
31905
  if (readOnly) {
@@ -31910,6 +31912,28 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31910
31912
  });
31911
31913
  }
31912
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
+
31913
31937
  return /*#__PURE__*/React__default["default"].createElement(_FormControl__default["default"], {
31914
31938
  error: dirty && hasErrors,
31915
31939
  margin: "dense",
@@ -31927,7 +31951,7 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31927
31951
  renderOption: function renderOption(option) {
31928
31952
  return /*#__PURE__*/React__default["default"].createElement(_Box__default["default"], null, /*#__PURE__*/React__default["default"].createElement(_Typography__default["default"], {
31929
31953
  variant: "body1"
31930
- }, option.entry), option.count !== undefined && /*#__PURE__*/React__default["default"].createElement(_Typography__default["default"], {
31954
+ }, option.entry), option.count !== undefined && option.count !== null && /*#__PURE__*/React__default["default"].createElement(_Typography__default["default"], {
31931
31955
  variant: "caption"
31932
31956
  }, "".concat(option.count, " Eintr\xE4ge")));
31933
31957
  },
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];
@@ -31828,7 +31828,9 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31828
31828
  });
31829
31829
  }, [onChange]);
31830
31830
  useEffect(function () {
31831
- fetch();
31831
+ if (!readOnly) {
31832
+ fetch();
31833
+ }
31832
31834
  }, []);
31833
31835
 
31834
31836
  if (readOnly) {
@@ -31841,6 +31843,28 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31841
31843
  });
31842
31844
  }
31843
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
+
31844
31868
  return /*#__PURE__*/React__default.createElement(_FormControl, {
31845
31869
  error: dirty && hasErrors,
31846
31870
  margin: "dense",
@@ -31858,7 +31882,7 @@ var FormAutocomplete = function FormAutocomplete(_ref) {
31858
31882
  renderOption: function renderOption(option) {
31859
31883
  return /*#__PURE__*/React__default.createElement(_Box, null, /*#__PURE__*/React__default.createElement(_Typography, {
31860
31884
  variant: "body1"
31861
- }, option.entry), option.count !== undefined && /*#__PURE__*/React__default.createElement(_Typography, {
31885
+ }, option.entry), option.count !== undefined && option.count !== null && /*#__PURE__*/React__default.createElement(_Typography, {
31862
31886
  variant: "caption"
31863
31887
  }, "".concat(option.count, " Eintr\xE4ge")));
31864
31888
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scenid/react-formulator",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
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
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,7 +37,11 @@ const FormAutocomplete = ({
29
37
 
30
38
  const changeValue = useCallback(newValue => { onChange({ target: { name, value: newValue?.entry || '' } }) }, [onChange])
31
39
 
32
- useEffect(() => { fetch() }, [])
40
+ useEffect(() => {
41
+ if (!readOnly) {
42
+ fetch()
43
+ }
44
+ }, [])
33
45
 
34
46
  if (readOnly) {
35
47
  return (
@@ -43,6 +55,34 @@ const FormAutocomplete = ({
43
55
  )
44
56
  }
45
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
+
46
86
  return (
47
87
  <FormControl
48
88
  error={dirty && hasErrors}
@@ -65,7 +105,7 @@ const FormAutocomplete = ({
65
105
  {option.entry}
66
106
  </Typography>
67
107
  {
68
- option.count !== undefined
108
+ (option.count !== undefined && option.count !== null)
69
109
  && (
70
110
  <Typography variant="caption">
71
111
  {`${option.count} Einträge`}
@@ -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