envoc-form 3.0.0-3 → 3.2.0

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.
@@ -7,6 +7,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
7
7
 
8
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
9
9
 
10
+ import classNames from 'classnames';
10
11
  import React, { useEffect, useRef } from 'react';
11
12
  import { default as ReactSelect } from 'react-select';
12
13
  export var overrideTheme = function overrideTheme(theme) {
@@ -22,6 +23,8 @@ var red = '#f86c6b';
22
23
  var inputBorderColor = '#c2cfd6';
23
24
  var inputBorderColorFocused = '#8ad4ee';
24
25
  var inputBoxShadowFocused = '0 0 0 0.2rem rgba(32, 168, 216, 0.25)';
26
+ var placeholderColor = '#9ca3af';
27
+ var disabledSingleValueColor = '#4b5563';
25
28
  export var customStyles = {
26
29
  control: function control(provided, _ref) {
27
30
  var isFocused = _ref.isFocused,
@@ -39,6 +42,17 @@ export var customStyles = {
39
42
  return _objectSpread(_objectSpread({}, provided), {}, {
40
43
  zIndex: 3
41
44
  });
45
+ },
46
+ singleValue: function singleValue(provided, state) {
47
+ var color = state.isDisabled ? disabledSingleValueColor : '';
48
+ return _objectSpread(_objectSpread({}, provided), {}, {
49
+ color: color
50
+ });
51
+ },
52
+ placeholder: function placeholder(defaultStyles) {
53
+ return _objectSpread(_objectSpread({}, defaultStyles), {}, {
54
+ color: placeholderColor
55
+ });
42
56
  }
43
57
  }; // internal to forms use only
44
58
 
@@ -48,7 +62,7 @@ export default function ReactSelectInput(_ref2) {
48
62
  disabled = _ref2.disabled,
49
63
  onSelected = _ref2.onSelected,
50
64
  onChange = _ref2.onChange,
51
- onBlur = _ref2.onBlur,
65
+ _onBlur = _ref2.onBlur,
52
66
  value = _ref2.value,
53
67
  options = _ref2.options,
54
68
  defaultValue = _ref2.defaultValue,
@@ -61,6 +75,23 @@ export default function ReactSelectInput(_ref2) {
61
75
  useEffect(function () {
62
76
  onSelectedRef.current && onSelectedRef.current(selectedItems);
63
77
  }, [selectedItems]);
78
+ var onBlurRef = useRef(_onBlur);
79
+ onBlurRef.current = _onBlur;
80
+ var touched = meta.touched;
81
+ useEffect(function () {
82
+ if (!touched) return; // without the timer set to 0, if the empty option is selected the required message doesn't appear until clicked away from the select input
83
+
84
+ var timerRef = setTimeout(function () {
85
+ onBlurRef.current && onBlurRef.current();
86
+ }, 0);
87
+ return function () {
88
+ clearTimeout(timerRef);
89
+ };
90
+ }, [value, touched]);
91
+ var classes = classNames(className, 'react-select-input', {
92
+ 'is-invalid': !!meta.error,
93
+ disabled: disabled
94
+ });
64
95
  return /*#__PURE__*/React.createElement(ReactSelect, _extends({}, props, {
65
96
  options: options,
66
97
  isDisabled: disabled,
@@ -71,7 +102,10 @@ export default function ReactSelectInput(_ref2) {
71
102
  getOptionValue: getOptionValue,
72
103
  value: selectedItems,
73
104
  onChange: handleChange,
74
- className: "react-select-input",
105
+ onBlur: function onBlur() {
106
+ return _onBlur();
107
+ },
108
+ className: classes,
75
109
  theme: overrideTheme,
76
110
  styles: customStyles,
77
111
  menuPortalTarget: document.body,
package/es/index.js CHANGED
@@ -1,15 +1,20 @@
1
+ import * as normalizers from './normalizers';
2
+ import { BoolInput, InlineBoolInput } from './BoolInput';
3
+ import { InlineMoneyInput, MoneyInput } from './MoneyInput';
4
+ import AddressInput from './AddressInput';
5
+ import ConfirmBaseForm from './ConfirmBaseForm';
6
+ import ConfirmDeleteForm from './ConfirmDeleteForm';
7
+ import ErrorScrollTarget from './ErrorScrollTarget';
1
8
  import Form from './Form';
9
+ import FormGroup from './FormGroup';
10
+ import FormGroupWrapper from './FormGroupWrapper';
2
11
  import FormInput from './FormInput';
3
- import InlineFormInput from './InlineFormInput';
4
12
  import FormInputArray from './FormInputArray';
13
+ import FormSection from './FormSection';
5
14
  import IconInput from './IconInput';
6
- import { BoolInput, InlineBoolInput } from './BoolInput';
15
+ import InlineFormInput from './InlineFormInput';
7
16
  import StandardFormActions from './StandardFormActions';
8
- import validators from './validators';
9
- import * as normalizers from './normalizers';
10
- import ConfirmBaseForm from './ConfirmBaseForm';
11
- import ConfirmDeleteForm from './ConfirmDeleteForm';
12
17
  import SubmitFormButton from './SubmitFormButton';
13
- import AddressInput from './AddressInput';
14
- import { MoneyInput, InlineMoneyInput } from './MoneyInput';
15
- export { Form, FormInput, InlineFormInput, FormInputArray, IconInput, BoolInput, InlineBoolInput, validators, normalizers, StandardFormActions, ConfirmBaseForm, ConfirmDeleteForm, SubmitFormButton, AddressInput, MoneyInput, InlineMoneyInput };
18
+ import useStandardFormInput from './useStandardFormInput';
19
+ import validators from './validators';
20
+ export { AddressInput, BoolInput, ConfirmBaseForm, ConfirmDeleteForm, ErrorScrollTarget, Form, FormGroup, FormGroupWrapper, FormInput, FormInputArray, FormSection, IconInput, InlineBoolInput, InlineFormInput, InlineMoneyInput, MoneyInput, normalizers, StandardFormActions, SubmitFormButton, useStandardFormInput, validators };
@@ -16,6 +16,8 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
16
16
 
17
17
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
18
 
19
+ var _classnames = _interopRequireDefault(require("classnames"));
20
+
19
21
  var _react = _interopRequireWildcard(require("react"));
20
22
 
21
23
  var _reactSelect = _interopRequireDefault(require("react-select"));
@@ -45,6 +47,8 @@ var red = '#f86c6b';
45
47
  var inputBorderColor = '#c2cfd6';
46
48
  var inputBorderColorFocused = '#8ad4ee';
47
49
  var inputBoxShadowFocused = '0 0 0 0.2rem rgba(32, 168, 216, 0.25)';
50
+ var placeholderColor = '#9ca3af';
51
+ var disabledSingleValueColor = '#4b5563';
48
52
  var customStyles = {
49
53
  control: function control(provided, _ref) {
50
54
  var isFocused = _ref.isFocused,
@@ -62,6 +66,17 @@ var customStyles = {
62
66
  return _objectSpread(_objectSpread({}, provided), {}, {
63
67
  zIndex: 3
64
68
  });
69
+ },
70
+ singleValue: function singleValue(provided, state) {
71
+ var color = state.isDisabled ? disabledSingleValueColor : '';
72
+ return _objectSpread(_objectSpread({}, provided), {}, {
73
+ color: color
74
+ });
75
+ },
76
+ placeholder: function placeholder(defaultStyles) {
77
+ return _objectSpread(_objectSpread({}, defaultStyles), {}, {
78
+ color: placeholderColor
79
+ });
65
80
  }
66
81
  }; // internal to forms use only
67
82
 
@@ -73,7 +88,7 @@ function ReactSelectInput(_ref2) {
73
88
  disabled = _ref2.disabled,
74
89
  onSelected = _ref2.onSelected,
75
90
  onChange = _ref2.onChange,
76
- onBlur = _ref2.onBlur,
91
+ _onBlur = _ref2.onBlur,
77
92
  value = _ref2.value,
78
93
  options = _ref2.options,
79
94
  defaultValue = _ref2.defaultValue,
@@ -85,6 +100,23 @@ function ReactSelectInput(_ref2) {
85
100
  (0, _react.useEffect)(function () {
86
101
  onSelectedRef.current && onSelectedRef.current(selectedItems);
87
102
  }, [selectedItems]);
103
+ var onBlurRef = (0, _react.useRef)(_onBlur);
104
+ onBlurRef.current = _onBlur;
105
+ var touched = meta.touched;
106
+ (0, _react.useEffect)(function () {
107
+ if (!touched) return; // without the timer set to 0, if the empty option is selected the required message doesn't appear until clicked away from the select input
108
+
109
+ var timerRef = setTimeout(function () {
110
+ onBlurRef.current && onBlurRef.current();
111
+ }, 0);
112
+ return function () {
113
+ clearTimeout(timerRef);
114
+ };
115
+ }, [value, touched]);
116
+ var classes = (0, _classnames["default"])(className, 'react-select-input', {
117
+ 'is-invalid': !!meta.error,
118
+ disabled: disabled
119
+ });
88
120
  return /*#__PURE__*/_react["default"].createElement(_reactSelect["default"], (0, _extends2["default"])({}, props, {
89
121
  options: options,
90
122
  isDisabled: disabled,
@@ -95,7 +127,10 @@ function ReactSelectInput(_ref2) {
95
127
  getOptionValue: getOptionValue,
96
128
  value: selectedItems,
97
129
  onChange: handleChange,
98
- className: "react-select-input",
130
+ onBlur: function onBlur() {
131
+ return _onBlur();
132
+ },
133
+ className: classes,
99
134
  theme: overrideTheme,
100
135
  styles: customStyles,
101
136
  menuPortalTarget: document.body,
package/lib/index.js CHANGED
@@ -7,127 +7,167 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- Object.defineProperty(exports, "Form", {
10
+ Object.defineProperty(exports, "BoolInput", {
11
11
  enumerable: true,
12
12
  get: function get() {
13
- return _Form["default"];
13
+ return _BoolInput.BoolInput;
14
14
  }
15
15
  });
16
- Object.defineProperty(exports, "FormInput", {
16
+ Object.defineProperty(exports, "InlineBoolInput", {
17
17
  enumerable: true,
18
18
  get: function get() {
19
- return _FormInput["default"];
19
+ return _BoolInput.InlineBoolInput;
20
20
  }
21
21
  });
22
- Object.defineProperty(exports, "InlineFormInput", {
22
+ Object.defineProperty(exports, "InlineMoneyInput", {
23
23
  enumerable: true,
24
24
  get: function get() {
25
- return _InlineFormInput["default"];
25
+ return _MoneyInput.InlineMoneyInput;
26
26
  }
27
27
  });
28
- Object.defineProperty(exports, "FormInputArray", {
28
+ Object.defineProperty(exports, "MoneyInput", {
29
29
  enumerable: true,
30
30
  get: function get() {
31
- return _FormInputArray["default"];
31
+ return _MoneyInput.MoneyInput;
32
32
  }
33
33
  });
34
- Object.defineProperty(exports, "IconInput", {
34
+ Object.defineProperty(exports, "AddressInput", {
35
35
  enumerable: true,
36
36
  get: function get() {
37
- return _IconInput["default"];
37
+ return _AddressInput["default"];
38
38
  }
39
39
  });
40
- Object.defineProperty(exports, "BoolInput", {
40
+ Object.defineProperty(exports, "ConfirmBaseForm", {
41
41
  enumerable: true,
42
42
  get: function get() {
43
- return _BoolInput.BoolInput;
43
+ return _ConfirmBaseForm["default"];
44
44
  }
45
45
  });
46
- Object.defineProperty(exports, "InlineBoolInput", {
46
+ Object.defineProperty(exports, "ConfirmDeleteForm", {
47
47
  enumerable: true,
48
48
  get: function get() {
49
- return _BoolInput.InlineBoolInput;
49
+ return _ConfirmDeleteForm["default"];
50
50
  }
51
51
  });
52
- Object.defineProperty(exports, "StandardFormActions", {
52
+ Object.defineProperty(exports, "ErrorScrollTarget", {
53
53
  enumerable: true,
54
54
  get: function get() {
55
- return _StandardFormActions["default"];
55
+ return _ErrorScrollTarget["default"];
56
56
  }
57
57
  });
58
- Object.defineProperty(exports, "validators", {
58
+ Object.defineProperty(exports, "Form", {
59
59
  enumerable: true,
60
60
  get: function get() {
61
- return _validators["default"];
61
+ return _Form["default"];
62
62
  }
63
63
  });
64
- Object.defineProperty(exports, "ConfirmBaseForm", {
64
+ Object.defineProperty(exports, "FormGroup", {
65
65
  enumerable: true,
66
66
  get: function get() {
67
- return _ConfirmBaseForm["default"];
67
+ return _FormGroup["default"];
68
68
  }
69
69
  });
70
- Object.defineProperty(exports, "ConfirmDeleteForm", {
70
+ Object.defineProperty(exports, "FormGroupWrapper", {
71
71
  enumerable: true,
72
72
  get: function get() {
73
- return _ConfirmDeleteForm["default"];
73
+ return _FormGroupWrapper["default"];
74
74
  }
75
75
  });
76
- Object.defineProperty(exports, "SubmitFormButton", {
76
+ Object.defineProperty(exports, "FormInput", {
77
77
  enumerable: true,
78
78
  get: function get() {
79
- return _SubmitFormButton["default"];
79
+ return _FormInput["default"];
80
80
  }
81
81
  });
82
- Object.defineProperty(exports, "AddressInput", {
82
+ Object.defineProperty(exports, "FormInputArray", {
83
83
  enumerable: true,
84
84
  get: function get() {
85
- return _AddressInput["default"];
85
+ return _FormInputArray["default"];
86
86
  }
87
87
  });
88
- Object.defineProperty(exports, "MoneyInput", {
88
+ Object.defineProperty(exports, "FormSection", {
89
89
  enumerable: true,
90
90
  get: function get() {
91
- return _MoneyInput.MoneyInput;
91
+ return _FormSection["default"];
92
92
  }
93
93
  });
94
- Object.defineProperty(exports, "InlineMoneyInput", {
94
+ Object.defineProperty(exports, "IconInput", {
95
95
  enumerable: true,
96
96
  get: function get() {
97
- return _MoneyInput.InlineMoneyInput;
97
+ return _IconInput["default"];
98
+ }
99
+ });
100
+ Object.defineProperty(exports, "InlineFormInput", {
101
+ enumerable: true,
102
+ get: function get() {
103
+ return _InlineFormInput["default"];
104
+ }
105
+ });
106
+ Object.defineProperty(exports, "StandardFormActions", {
107
+ enumerable: true,
108
+ get: function get() {
109
+ return _StandardFormActions["default"];
110
+ }
111
+ });
112
+ Object.defineProperty(exports, "SubmitFormButton", {
113
+ enumerable: true,
114
+ get: function get() {
115
+ return _SubmitFormButton["default"];
116
+ }
117
+ });
118
+ Object.defineProperty(exports, "useStandardFormInput", {
119
+ enumerable: true,
120
+ get: function get() {
121
+ return _useStandardFormInput["default"];
122
+ }
123
+ });
124
+ Object.defineProperty(exports, "validators", {
125
+ enumerable: true,
126
+ get: function get() {
127
+ return _validators["default"];
98
128
  }
99
129
  });
100
130
  exports.normalizers = void 0;
101
131
 
102
- var _Form = _interopRequireDefault(require("./Form"));
132
+ var normalizers = _interopRequireWildcard(require("./normalizers"));
103
133
 
104
- var _FormInput = _interopRequireDefault(require("./FormInput"));
134
+ exports.normalizers = normalizers;
105
135
 
106
- var _InlineFormInput = _interopRequireDefault(require("./InlineFormInput"));
136
+ var _BoolInput = require("./BoolInput");
107
137
 
108
- var _FormInputArray = _interopRequireDefault(require("./FormInputArray"));
138
+ var _MoneyInput = require("./MoneyInput");
109
139
 
110
- var _IconInput = _interopRequireDefault(require("./IconInput"));
140
+ var _AddressInput = _interopRequireDefault(require("./AddressInput"));
111
141
 
112
- var _BoolInput = require("./BoolInput");
142
+ var _ConfirmBaseForm = _interopRequireDefault(require("./ConfirmBaseForm"));
113
143
 
114
- var _StandardFormActions = _interopRequireDefault(require("./StandardFormActions"));
144
+ var _ConfirmDeleteForm = _interopRequireDefault(require("./ConfirmDeleteForm"));
115
145
 
116
- var _validators = _interopRequireDefault(require("./validators"));
146
+ var _ErrorScrollTarget = _interopRequireDefault(require("./ErrorScrollTarget"));
117
147
 
118
- var normalizers = _interopRequireWildcard(require("./normalizers"));
148
+ var _Form = _interopRequireDefault(require("./Form"));
119
149
 
120
- exports.normalizers = normalizers;
150
+ var _FormGroup = _interopRequireDefault(require("./FormGroup"));
121
151
 
122
- var _ConfirmBaseForm = _interopRequireDefault(require("./ConfirmBaseForm"));
152
+ var _FormGroupWrapper = _interopRequireDefault(require("./FormGroupWrapper"));
123
153
 
124
- var _ConfirmDeleteForm = _interopRequireDefault(require("./ConfirmDeleteForm"));
154
+ var _FormInput = _interopRequireDefault(require("./FormInput"));
155
+
156
+ var _FormInputArray = _interopRequireDefault(require("./FormInputArray"));
157
+
158
+ var _FormSection = _interopRequireDefault(require("./FormSection"));
159
+
160
+ var _IconInput = _interopRequireDefault(require("./IconInput"));
161
+
162
+ var _InlineFormInput = _interopRequireDefault(require("./InlineFormInput"));
163
+
164
+ var _StandardFormActions = _interopRequireDefault(require("./StandardFormActions"));
125
165
 
126
166
  var _SubmitFormButton = _interopRequireDefault(require("./SubmitFormButton"));
127
167
 
128
- var _AddressInput = _interopRequireDefault(require("./AddressInput"));
168
+ var _useStandardFormInput = _interopRequireDefault(require("./useStandardFormInput"));
129
169
 
130
- var _MoneyInput = require("./MoneyInput");
170
+ var _validators = _interopRequireDefault(require("./validators"));
131
171
 
132
172
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
133
173
 
package/package.json CHANGED
@@ -1,99 +1,100 @@
1
- {
2
- "name": "envoc-form",
3
- "version": "3.0.0-3",
4
- "description": "Envoc form components",
5
- "keywords": [
6
- "react-component",
7
- "react",
8
- "forms",
9
- "components",
10
- "envoc"
11
- ],
12
- "homepage": "",
13
- "repository": "",
14
- "license": "MIT",
15
- "author": "Envoc Developers",
16
- "sideEffects": false,
17
- "main": "lib/index.js",
18
- "module": "es/index.js",
19
- "files": [
20
- "dist",
21
- "src",
22
- "lib",
23
- "es"
24
- ],
25
- "scripts": {
26
- "build": "yarn verify-imports && yarn build:esm && yarn build:cjs && yarn build:css",
27
- "rebuild": "rimraf ./{dist,es,lib} && yarn build",
28
- "build:esm": "cross-env BABEL_ENV=esm-dir babel src --out-dir es --ignore \"src/**/*.spec.js\",\"src/**/*.test.js\"",
29
- "build:css": "sass src/styles.scss dist/css/envoc-form-styles.css",
30
- "build:cjs": "babel src --out-dir lib --ignore \"src/**/*.spec.js\",\"src/**/*.test.js\"",
31
- "verify-imports": "node ../../scripts/check-for-scss-imports.js envoc-form",
32
- "start": "webpack serve --config ./webpack.demo.config.js",
33
- "test": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts test --watchAll=false",
34
- "coverage": "yarn test --reporters=jest-junit --coverage --coverageReporters=cobertura"
35
- },
36
- "dependencies": {
37
- "axios": "^0.21.1",
38
- "classnames": "^2.3.1",
39
- "date-fns": "^2.22.1",
40
- "envoc-request": "^3.0.0-3",
41
- "lru-cache": "^6.0.0",
42
- "prop-types": "^15.7.2",
43
- "react-date-picker": "^8.2.0",
44
- "react-dropzone": "^11.3.4",
45
- "react-router": "^6.2.1",
46
- "react-select": "^3.1.1",
47
- "react-textarea-autosize": "^8.3.3",
48
- "react-toastify": "^7.0.4",
49
- "reactstrap": "^8.9.0",
50
- "smoothscroll-polyfill": "^0.4.4",
51
- "uuid": "^8.3.2",
52
- "@fortawesome/react-fontawesome": "~0.1.16",
53
- "@fortawesome/free-solid-svg-icons": "~5.15.4",
54
- "@fortawesome/fontawesome-svg-core": "~1.2.36"
55
- },
56
- "devDependencies": {
57
- "@babel/cli": "^7.14.5",
58
- "@babel/core": "^7.14.6",
59
- "@babel/plugin-transform-runtime": "^7.14.5",
60
- "@babel/preset-env": "^7.14.7",
61
- "@babel/preset-react": "^7.14.5",
62
- "@testing-library/jest-dom": "^5.14.1",
63
- "@testing-library/react": "^11.2.5",
64
- "@testing-library/user-event": "^12.7.1",
65
- "babel-loader": "^8.2.2",
66
- "bootstrap": "^4.6.0",
67
- "clean-webpack-plugin": "^3.0.0",
68
- "cross-env": "7.0.3",
69
- "css-loader": "^5.0.2",
70
- "html-webpack-plugin": "^5.3.2",
71
- "identity-obj-proxy": "^3.0.0",
72
- "jest-junit": "~12.2.0",
73
- "react": "^17.0.1",
74
- "react-dom": "^17.0.1",
75
- "react-router-dom": "^6.2.1",
76
- "react-scripts": "^4.0.3",
77
- "rimraf": "~3.0.2",
78
- "sass": "^1.35.2",
79
- "sass-loader": "^11.0.1",
80
- "style-loader": "^2.0.0",
81
- "webpack": "^5.45.0",
82
- "webpack-cli": "^4.7.2",
83
- "webpack-dev-server": "^3.11.2",
84
- "typedoc-plugin-markdown": "~3.10.3",
85
- "typedoc": "~0.21.4"
86
- },
87
- "peerDependencies": {
88
- "@babel/runtime": "^7.14.6",
89
- "formik": "^2.2.9",
90
- "react": ">=16.8.0",
91
- "react-dom": ">=16.8.0",
92
- "react-router-dom": "^6.2.1"
93
- },
94
- "jest": {
95
- "transformIgnorePatterns": [
96
- "^.+\\.module\\.(css|sass|scss)$"
97
- ]
98
- }
99
- }
1
+ {
2
+ "name": "envoc-form",
3
+ "version": "3.2.0",
4
+ "description": "Envoc form components",
5
+ "keywords": [
6
+ "react-component",
7
+ "react",
8
+ "forms",
9
+ "components",
10
+ "envoc"
11
+ ],
12
+ "homepage": "",
13
+ "repository": "",
14
+ "license": "MIT",
15
+ "author": "Envoc Developers",
16
+ "sideEffects": false,
17
+ "main": "lib/index.js",
18
+ "module": "es/index.js",
19
+ "files": [
20
+ "dist",
21
+ "src",
22
+ "lib",
23
+ "es"
24
+ ],
25
+ "dependencies": {
26
+ "axios": "^0.21.1",
27
+ "classnames": "^2.3.1",
28
+ "date-fns": "^2.22.1",
29
+ "envoc-request": "^3.2.0",
30
+ "lru-cache": "^6.0.0",
31
+ "prop-types": "^15.7.2",
32
+ "react-date-picker": "^8.2.0",
33
+ "react-dropzone": "^11.3.4",
34
+ "react-router": "^6.2.1",
35
+ "react-select": "^3.1.1",
36
+ "react-textarea-autosize": "^8.3.3",
37
+ "react-toastify": "^7.0.4",
38
+ "reactstrap": "^8.9.0",
39
+ "smoothscroll-polyfill": "^0.4.4",
40
+ "uuid": "^8.3.2",
41
+ "@fortawesome/react-fontawesome": "~0.1.16",
42
+ "@fortawesome/free-solid-svg-icons": "~5.15.4",
43
+ "@fortawesome/fontawesome-svg-core": "~1.2.36"
44
+ },
45
+ "devDependencies": {
46
+ "@babel/cli": "^7.14.5",
47
+ "@babel/core": "^7.14.6",
48
+ "@babel/plugin-transform-runtime": "^7.14.5",
49
+ "@babel/preset-env": "^7.14.7",
50
+ "@babel/preset-react": "^7.14.5",
51
+ "@testing-library/jest-dom": "^5.14.1",
52
+ "@testing-library/react": "^11.2.5",
53
+ "@testing-library/user-event": "^12.7.1",
54
+ "babel-loader": "^8.2.2",
55
+ "bootstrap": "^4.6.0",
56
+ "clean-webpack-plugin": "^3.0.0",
57
+ "cross-env": "7.0.3",
58
+ "css-loader": "^5.0.2",
59
+ "html-webpack-plugin": "^5.3.2",
60
+ "identity-obj-proxy": "^3.0.0",
61
+ "jest-junit": "~12.2.0",
62
+ "react": "^17.0.1",
63
+ "react-dom": "^17.0.1",
64
+ "react-router-dom": "^6.2.1",
65
+ "react-scripts": "^4.0.3",
66
+ "rimraf": "~3.0.2",
67
+ "sass": "^1.35.2",
68
+ "sass-loader": "^11.0.1",
69
+ "style-loader": "^2.0.0",
70
+ "webpack": "^5.45.0",
71
+ "webpack-cli": "^4.7.2",
72
+ "webpack-dev-server": "^3.11.2",
73
+ "typedoc-plugin-markdown": "~3.10.3",
74
+ "typedoc": "~0.21.4"
75
+ },
76
+ "peerDependencies": {
77
+ "@babel/runtime": "^7.14.6",
78
+ "formik": "^2.2.9",
79
+ "react": ">=16.8.0",
80
+ "react-dom": ">=16.8.0",
81
+ "react-router-dom": "^6.2.1"
82
+ },
83
+ "jest": {
84
+ "transformIgnorePatterns": [
85
+ "^.+\\.module\\.(css|sass|scss)$"
86
+ ]
87
+ },
88
+ "scripts": {
89
+ "build": "yarn verify-imports && yarn build:esm && yarn build:cjs && yarn build:css",
90
+ "rebuild": "rimraf ./{dist,es,lib} && yarn build",
91
+ "build:esm": "cross-env BABEL_ENV=esm-dir babel src --out-dir es --ignore \"src/**/*.spec.js\",\"src/**/*.test.js\"",
92
+ "build:css": "sass src/styles.scss dist/css/envoc-form-styles.css",
93
+ "build:cjs": "babel src --out-dir lib --ignore \"src/**/*.spec.js\",\"src/**/*.test.js\"",
94
+ "verify-imports": "node ../../scripts/check-for-scss-imports.js envoc-form",
95
+ "start": "webpack serve --config ./webpack.demo.config.js",
96
+ "test": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts test --watchAll=false",
97
+ "coverage": "yarn test --reporters=jest-junit --coverage --coverageReporters=cobertura"
98
+ },
99
+ "readme": "# envoc-form\r\n\r\n[![npm package][npm-badge]][npm]\r\n\r\nBase form package for envoc projects.\r\n\r\n[npm-badge]: https://img.shields.io/npm/v/envoc-form.png?style=flat\r\n[npm]: https://www.npmjs.com/package/envoc-form"
100
+ }
@@ -110,7 +110,7 @@ exports[`AddressInput has matching snapshot 1`] = `
110
110
  class=" css-lbak6p-Component"
111
111
  >
112
112
  <div
113
- class=" css-1osw1h9-placeholder"
113
+ class=" css-1vk4ta-placeholder"
114
114
  >
115
115
  State
116
116
  </div>
@@ -23,7 +23,7 @@ exports[`BoolInput has matching snapshot 1`] = `
23
23
  class=" css-lbak6p-Component"
24
24
  >
25
25
  <div
26
- class=" css-1osw1h9-placeholder"
26
+ class=" css-1vk4ta-placeholder"
27
27
  >
28
28
  Select...
29
29
  </div>
@@ -234,7 +234,7 @@ exports[`FormInput has matching select snapshot 1`] = `
234
234
  class=" css-lbak6p-Component"
235
235
  >
236
236
  <div
237
- class=" css-1osw1h9-placeholder"
237
+ class=" css-1vk4ta-placeholder"
238
238
  >
239
239
  Select...
240
240
  </div>
@@ -1,3 +1,4 @@
1
+ import classNames from 'classnames';
1
2
  import React, { useEffect, useRef } from 'react';
2
3
  import { default as ReactSelect } from 'react-select';
3
4
 
@@ -17,6 +18,8 @@ const red = '#f86c6b';
17
18
  const inputBorderColor = '#c2cfd6';
18
19
  const inputBorderColorFocused = '#8ad4ee';
19
20
  const inputBoxShadowFocused = '0 0 0 0.2rem rgba(32, 168, 216, 0.25)';
21
+ const placeholderColor = '#9ca3af';
22
+ const disabledSingleValueColor = '#4b5563';
20
23
 
21
24
  export const customStyles = {
22
25
  control: (provided, { isFocused, selectProps }) => {
@@ -35,6 +38,13 @@ export const customStyles = {
35
38
  };
36
39
  },
37
40
  menu: (provided) => ({ ...provided, zIndex: 3 }),
41
+ singleValue: (provided, state) => {
42
+ const color = state.isDisabled ? disabledSingleValueColor : '';
43
+ return { ...provided, color };
44
+ },
45
+ placeholder: (defaultStyles) => {
46
+ return { ...defaultStyles, color: placeholderColor };
47
+ },
38
48
  };
39
49
 
40
50
  // internal to forms use only
@@ -59,6 +69,28 @@ export default function ReactSelectInput({
59
69
  onSelectedRef.current && onSelectedRef.current(selectedItems);
60
70
  }, [selectedItems]);
61
71
 
72
+ const onBlurRef = useRef(onBlur);
73
+ onBlurRef.current = onBlur;
74
+ const { touched } = meta;
75
+
76
+ useEffect(() => {
77
+ if (!touched) return;
78
+
79
+ // without the timer set to 0, if the empty option is selected the required message doesn't appear until clicked away from the select input
80
+ const timerRef = setTimeout(() => {
81
+ onBlurRef.current && onBlurRef.current();
82
+ }, 0);
83
+
84
+ return () => {
85
+ clearTimeout(timerRef);
86
+ };
87
+ }, [value, touched]);
88
+
89
+ const classes = classNames(className, 'react-select-input', {
90
+ 'is-invalid': !!meta.error,
91
+ disabled: disabled,
92
+ });
93
+
62
94
  return (
63
95
  <ReactSelect
64
96
  {...props}
@@ -69,7 +101,8 @@ export default function ReactSelectInput({
69
101
  getOptionValue={getOptionValue}
70
102
  value={selectedItems}
71
103
  onChange={handleChange}
72
- className="react-select-input"
104
+ onBlur={() => onBlur()}
105
+ className={classes}
73
106
  theme={overrideTheme}
74
107
  styles={customStyles}
75
108
  menuPortalTarget={document.body}
package/src/index.js CHANGED
@@ -1,33 +1,45 @@
1
+ import * as normalizers from './normalizers';
2
+
3
+ import { BoolInput, InlineBoolInput } from './BoolInput';
4
+ import { InlineMoneyInput, MoneyInput } from './MoneyInput';
5
+
6
+ import AddressInput from './AddressInput';
7
+ import ConfirmBaseForm from './ConfirmBaseForm';
8
+ import ConfirmDeleteForm from './ConfirmDeleteForm';
9
+ import ErrorScrollTarget from './ErrorScrollTarget';
1
10
  import Form from './Form';
11
+ import FormGroup from './FormGroup';
12
+ import FormGroupWrapper from './FormGroupWrapper';
2
13
  import FormInput from './FormInput';
3
- import InlineFormInput from './InlineFormInput';
4
14
  import FormInputArray from './FormInputArray';
15
+ import FormSection from './FormSection';
5
16
  import IconInput from './IconInput';
6
- import { BoolInput, InlineBoolInput } from './BoolInput';
17
+ import InlineFormInput from './InlineFormInput';
7
18
  import StandardFormActions from './StandardFormActions';
8
- import validators from './validators';
9
- import * as normalizers from './normalizers';
10
- import ConfirmBaseForm from './ConfirmBaseForm';
11
- import ConfirmDeleteForm from './ConfirmDeleteForm';
12
19
  import SubmitFormButton from './SubmitFormButton';
13
- import AddressInput from './AddressInput';
14
- import { MoneyInput, InlineMoneyInput } from './MoneyInput';
20
+ import useStandardFormInput from './useStandardFormInput';
21
+ import validators from './validators';
15
22
 
16
23
  export {
24
+ AddressInput,
25
+ BoolInput,
26
+ ConfirmBaseForm,
27
+ ConfirmDeleteForm,
28
+ ErrorScrollTarget,
17
29
  Form,
30
+ FormGroup,
31
+ FormGroupWrapper,
18
32
  FormInput,
19
- InlineFormInput,
20
33
  FormInputArray,
34
+ FormSection,
21
35
  IconInput,
22
- BoolInput,
23
36
  InlineBoolInput,
24
- validators,
37
+ InlineFormInput,
38
+ InlineMoneyInput,
39
+ MoneyInput,
25
40
  normalizers,
26
41
  StandardFormActions,
27
- ConfirmBaseForm,
28
- ConfirmDeleteForm,
29
42
  SubmitFormButton,
30
- AddressInput,
31
- MoneyInput,
32
- InlineMoneyInput,
43
+ useStandardFormInput,
44
+ validators,
33
45
  };