@maif/react-forms 1.0.4 → 1.0.8

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.
@@ -15,6 +15,8 @@ var _reactSelect = _interopRequireDefault(require("react-select"));
15
15
 
16
16
  var _Option = require("../Option");
17
17
 
18
+ var _utils = require("../utils");
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
21
 
20
22
  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); }
@@ -44,47 +46,63 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
44
46
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
45
47
 
46
48
  var valueToSelectOption = function valueToSelectOption(value) {
47
- var isMulti = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
49
+ var possibleValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
50
+ var isMulti = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
51
+ var maybeTransformer = arguments.length > 3 ? arguments[3] : undefined;
48
52
 
49
53
  if (value === null) {
50
54
  return null;
51
55
  }
52
56
 
53
57
  if (isMulti) {
54
- return value.map(function (x) {
55
- return valueToSelectOption(x);
56
- });
58
+ return (0, _Option.option)(value).map(function (v) {
59
+ return v.map(function (x) {
60
+ return valueToSelectOption(x, possibleValues, false, maybeTransformer);
61
+ });
62
+ }).getOrElse([]);
57
63
  }
58
64
 
59
- return {
60
- label: (value === null || value === void 0 ? void 0 : value.label) || value,
61
- value: (value === null || value === void 0 ? void 0 : value.value) || value
62
- };
65
+ var maybeValue = (0, _Option.option)(possibleValues.find(function (v) {
66
+ return (0, _utils.deepEqual)(v.value, value);
67
+ }));
68
+ return maybeValue.getOrElse({
69
+ label: maybeValue.map(function (v) {
70
+ return v.label;
71
+ }).getOrElse(value),
72
+ value: maybeValue.map(function (v) {
73
+ return v.value;
74
+ }).getOrElse(value)
75
+ });
63
76
  };
64
77
 
65
78
  var SelectInput = function SelectInput(props) {
79
+ var possibleValues = (props.possibleValues || []).map(function (v) {
80
+ return props.transformer ? props.transformer(v) : v;
81
+ }).map(function (v) {
82
+ return {
83
+ label: (v === null || v === void 0 ? void 0 : v.label) || v,
84
+ value: (v === null || v === void 0 ? void 0 : v.value) || v
85
+ };
86
+ });
87
+
66
88
  var _useState = (0, _react.useState)(false),
67
89
  _useState2 = _slicedToArray(_useState, 2),
68
90
  loading = _useState2[0],
69
91
  setLoading = _useState2[1];
70
92
 
71
- var _useState3 = (0, _react.useState)(valueToSelectOption(props.value || props.defaultValue, props.isMulti)),
93
+ var _useState3 = (0, _react.useState)(possibleValues),
72
94
  _useState4 = _slicedToArray(_useState3, 2),
73
- value = _useState4[0],
74
- setValue = _useState4[1];
95
+ values = _useState4[0],
96
+ setValues = _useState4[1];
75
97
 
76
- var _useState5 = (0, _react.useState)((props.possibleValues || []).map(function (v) {
77
- return props.transformer ? props.transformer(v) : v;
78
- }).map(function (v) {
79
- return valueToSelectOption(v);
80
- })),
98
+ var _useState5 = (0, _react.useState)(valueToSelectOption(props.value || props.defaultValue, possibleValues, props.isMulti, props.transformer)),
81
99
  _useState6 = _slicedToArray(_useState5, 2),
82
- values = _useState6[0],
83
- setValues = _useState6[1];
100
+ value = _useState6[0],
101
+ setValue = _useState6[1];
84
102
 
85
103
  (0, _react.useEffect)(function () {
86
- setValue(valueToSelectOption(props.value || props.defaultValue, props.isMulti));
87
- }, []);
104
+ setValue(valueToSelectOption(props.value, values, props.isMulti, props.transformer));
105
+ }, [props.value, values]);
88
106
  (0, _react.useEffect)(function () {
89
107
  if (props.optionsFrom) {
90
108
  var cond = (0, _Option.option)(props.fetchCondition).map(function (cond) {
@@ -97,7 +115,7 @@ var SelectInput = function SelectInput(props) {
97
115
  return r.json();
98
116
  }).then(function (values) {
99
117
  return values.map(function (x) {
100
- return props.transformer ? props.transformer(x) : valueToSelectOption(x);
118
+ return props.transformer ? props.transformer(x) : valueToSelectOption(x, values, props.isMulti, props.transformer);
101
119
  });
102
120
  }).then(function (values) {
103
121
  setValues(values);
@@ -108,7 +126,7 @@ var SelectInput = function SelectInput(props) {
108
126
  });
109
127
  }
110
128
  }
111
- }, [values, props.isMulti]);
129
+ }, [props.optionsFrom]);
112
130
 
113
131
  var onChange = function onChange(changes) {
114
132
  setValue(changes);
@@ -122,11 +140,21 @@ var SelectInput = function SelectInput(props) {
122
140
  }
123
141
  };
124
142
 
125
- var createOption = function createOption(option) {
126
- var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
127
- fn(option);
128
- setValues([].concat(_toConsumableArray(values), [valueToSelectOption(option)]));
129
- onChange(valueToSelectOption(option));
143
+ var handleCreate = function handleCreate(label, fn) {
144
+ var createdValue = (0, _Option.option)(fn).map(function (func) {
145
+ return func(label);
146
+ }).map(function (createdOpt) {
147
+ return (0, _Option.option)(props.transformer).map(function (t) {
148
+ return t(createdOpt);
149
+ }).getOrElse(createdOpt);
150
+ }).getOrElse(valueToSelectOption(label, values));
151
+ setValues([].concat(_toConsumableArray(values), [createdValue]));
152
+
153
+ if (props.isMulti) {
154
+ onChange([].concat(_toConsumableArray(value), [createdValue]));
155
+ } else {
156
+ onChange(createdValue);
157
+ }
130
158
  };
131
159
 
132
160
  if (props.createOption) {
@@ -140,7 +168,7 @@ var SelectInput = function SelectInput(props) {
140
168
  onChange: onChange,
141
169
  options: values,
142
170
  onCreateOption: function onCreateOption(option) {
143
- return props.onCreateOption ? createOption(option, props.onCreateOption) : createOption(option);
171
+ return handleCreate(option, props.onCreateOption);
144
172
  },
145
173
  classNamePrefix: "react-form-select",
146
174
  className: props.className
package/lib/style.d.ts ADDED
@@ -0,0 +1,159 @@
1
+ export namespace style {
2
+ const input: {
3
+ display: string;
4
+ width: string;
5
+ padding: string;
6
+ fontSize: string;
7
+ color: string;
8
+ border: string;
9
+ borderRadius: number;
10
+ "&[readonly]": {
11
+ backgroundColor: string;
12
+ opacity: number;
13
+ };
14
+ };
15
+ namespace btn {
16
+ const borderRadius: number;
17
+ const padding: number;
18
+ const fontSize: string;
19
+ const cursor: string;
20
+ const border: number;
21
+ }
22
+ namespace btn_sm {
23
+ const fontSize_1: string;
24
+ export { fontSize_1 as fontSize };
25
+ const padding_1: string;
26
+ export { padding_1 as padding };
27
+ }
28
+ const btn_group: {
29
+ "& > button:not(:last-child)": {
30
+ borderTopRightRadius: number;
31
+ borderBottomRightRadius: number;
32
+ };
33
+ "& > button:not(:first-child)": {
34
+ borderTopLeftRadius: number;
35
+ borderBottomLeftRadius: number;
36
+ };
37
+ };
38
+ const btn_red: {
39
+ color: string;
40
+ backgroundColor: string;
41
+ borderColor: string;
42
+ "&:hover": {
43
+ backgroundColor: string;
44
+ borderColor: string;
45
+ };
46
+ };
47
+ const btn_green: {
48
+ color: string;
49
+ backgroundColor: string;
50
+ borderColor: string;
51
+ "&:hover": {
52
+ backgroundColor: string;
53
+ borderColor: string;
54
+ };
55
+ };
56
+ const btn_blue: {
57
+ color: string;
58
+ backgroundColor: string;
59
+ borderColor: string;
60
+ "&:hover": {
61
+ backgroundColor: string;
62
+ borderColor: string;
63
+ };
64
+ };
65
+ const btn_grey: {
66
+ color: string;
67
+ backgroundColor: string;
68
+ borderColor: string;
69
+ "&:hover": {
70
+ backgroundColor: string;
71
+ borderColor: string;
72
+ };
73
+ };
74
+ namespace txt_red {
75
+ const color: string;
76
+ }
77
+ namespace ml_5 {
78
+ const marginLeft: number;
79
+ }
80
+ namespace ml_10 {
81
+ const marginLeft_1: number;
82
+ export { marginLeft_1 as marginLeft };
83
+ }
84
+ namespace mt_5 {
85
+ const marginTop: number;
86
+ }
87
+ namespace mt_10 {
88
+ const marginTop_1: number;
89
+ export { marginTop_1 as marginTop };
90
+ }
91
+ namespace mt_20 {
92
+ const marginTop_2: number;
93
+ export { marginTop_2 as marginTop };
94
+ }
95
+ namespace mb_5 {
96
+ const marginBottom: number;
97
+ }
98
+ namespace p_15 {
99
+ const padding_2: number;
100
+ export { padding_2 as padding };
101
+ }
102
+ namespace pr_15 {
103
+ const paddingRight: number;
104
+ }
105
+ namespace d_none {
106
+ const display: string;
107
+ }
108
+ namespace flex {
109
+ const display_1: string;
110
+ export { display_1 as display };
111
+ }
112
+ namespace flexColumn {
113
+ const flexDirection: string;
114
+ }
115
+ namespace justifyContentBetween {
116
+ const justifyContent: string;
117
+ }
118
+ namespace jc_end {
119
+ const justifyContent_1: string;
120
+ export { justifyContent_1 as justifyContent };
121
+ }
122
+ namespace ac_center {
123
+ const alignContent: string;
124
+ }
125
+ namespace ai_center {
126
+ const alignItems: string;
127
+ }
128
+ namespace cursor_pointer {
129
+ const cursor_1: string;
130
+ export { cursor_1 as cursor };
131
+ }
132
+ namespace collapse {
133
+ const display_2: string;
134
+ export { display_2 as display };
135
+ const justifyContent_2: string;
136
+ export { justifyContent_2 as justifyContent };
137
+ const cursor_2: string;
138
+ export { cursor_2 as cursor };
139
+ }
140
+ namespace collapse_label {
141
+ export const fontWeight: string;
142
+ const marginTop_3: number;
143
+ export { marginTop_3 as marginTop };
144
+ }
145
+ const datepicker: {
146
+ "& input": {
147
+ borderRadius: string;
148
+ };
149
+ };
150
+ const code: {};
151
+ namespace input__boolean__on {
152
+ const color_1: string;
153
+ export { color_1 as color };
154
+ }
155
+ namespace input__boolean__off {
156
+ const color_2: string;
157
+ export { color_2 as color };
158
+ }
159
+ }
package/lib/style.js ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.style = void 0;
7
+ var style = {
8
+ input: {
9
+ display: "block",
10
+ width: "100%",
11
+ padding: "8px 12px",
12
+ fontSize: "1rem",
13
+ color: "#495057",
14
+ border: "1px solid #ced4da",
15
+ borderRadius: 4,
16
+ "&[readonly]": {
17
+ backgroundColor: "#e9ecef",
18
+ opacity: 1
19
+ }
20
+ },
21
+ btn: {
22
+ borderRadius: 5,
23
+ padding: 10,
24
+ fontSize: "1rem",
25
+ cursor: "pointer",
26
+ border: 0
27
+ },
28
+ btn_sm: {
29
+ fontSize: "0.875rem",
30
+ padding: ".25rem .5rem"
31
+ },
32
+ btn_group: {
33
+ "& > button:not(:last-child)": {
34
+ borderTopRightRadius: 0,
35
+ borderBottomRightRadius: 0
36
+ },
37
+ "& > button:not(:first-child)": {
38
+ borderTopLeftRadius: 0,
39
+ borderBottomLeftRadius: 0
40
+ }
41
+ },
42
+ btn_red: {
43
+ color: "#fff",
44
+ backgroundColor: "#dc3545",
45
+ borderColor: "#dc3545",
46
+ "&:hover": {
47
+ backgroundColor: "#c82333",
48
+ borderColor: "#bd2130"
49
+ }
50
+ },
51
+ btn_green: {
52
+ color: "#fff",
53
+ backgroundColor: "#28a745",
54
+ borderColor: "#28a745",
55
+ "&:hover": {
56
+ backgroundColor: "#218838",
57
+ borderColor: "#1e7e34"
58
+ }
59
+ },
60
+ btn_blue: {
61
+ color: "#fff",
62
+ backgroundColor: "#007bff",
63
+ borderColor: "#007bff",
64
+ "&:hover": {
65
+ backgroundColor: "#0069d9",
66
+ borderColor: "#0062cc"
67
+ }
68
+ },
69
+ btn_grey: {
70
+ color: "#fff",
71
+ backgroundColor: "#6c757d",
72
+ borderColor: "#6c757d",
73
+ "&:hover": {
74
+ backgroundColor: "#5c636a",
75
+ borderColor: "#5c636a"
76
+ }
77
+ },
78
+ txt_red: {
79
+ color: "#dc3545"
80
+ },
81
+ ml_5: {
82
+ marginLeft: 5
83
+ },
84
+ ml_10: {
85
+ marginLeft: 10
86
+ },
87
+ mt_5: {
88
+ marginTop: 5
89
+ },
90
+ mt_10: {
91
+ marginTop: 10
92
+ },
93
+ mt_20: {
94
+ marginTop: 20
95
+ },
96
+ mb_5: {
97
+ marginBottom: 5
98
+ },
99
+ p_15: {
100
+ padding: 15
101
+ },
102
+ pr_15: {
103
+ paddingRight: 15
104
+ },
105
+ d_none: {
106
+ display: "none"
107
+ },
108
+ flex: {
109
+ display: "flex"
110
+ },
111
+ flexColumn: {
112
+ flexDirection: "column"
113
+ },
114
+ justifyContentBetween: {
115
+ justifyContent: "space-between"
116
+ },
117
+ jc_end: {
118
+ justifyContent: "end"
119
+ },
120
+ ac_center: {
121
+ alignContent: "center"
122
+ },
123
+ ai_center: {
124
+ alignItems: "center"
125
+ },
126
+ cursor_pointer: {
127
+ cursor: "pointer"
128
+ },
129
+ collapse: {
130
+ display: "flex",
131
+ justifyContent: "space-between",
132
+ cursor: "pointer"
133
+ },
134
+ collapse_label: {
135
+ fontWeight: "bold",
136
+ marginTop: 7
137
+ },
138
+ datepicker: {
139
+ "& input": {
140
+ borderRadius: "4px"
141
+ }
142
+ },
143
+ code: {},
144
+ input__boolean__on: {
145
+ color: "MediumSeaGreen"
146
+ },
147
+ input__boolean__off: {
148
+ color: "tomato"
149
+ }
150
+ };
151
+ exports.style = style;
@@ -0,0 +1 @@
1
+ export function useCustomStyle(overrideStyle?: {}): import("jss").Classes<"code" | "flex" | "input" | "btn" | "btn_sm" | "btn_group" | "btn_red" | "btn_green" | "btn_blue" | "btn_grey" | "txt_red" | "ml_5" | "ml_10" | "mt_5" | "mt_10" | "mt_20" | "mb_5" | "p_15" | "pr_15" | "d_none" | "flexColumn" | "justifyContentBetween" | "jc_end" | "ac_center" | "ai_center" | "cursor_pointer" | "collapse" | "collapse_label" | "datepicker" | "input__boolean__on" | "input__boolean__off">;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useCustomStyle = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _reactJss = require("react-jss");
11
+
12
+ var _style = require("./style");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ 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; }
19
+
20
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
+
22
+ var useCustomStyle = function useCustomStyle() {
23
+ var overrideStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
24
+ var useStyle = (0, _reactJss.createUseStyles)(_objectSpread(_objectSpread({}, _style.style), overrideStyle));
25
+ var classes = useStyle();
26
+ return classes;
27
+ };
28
+
29
+ exports.useCustomStyle = useCustomStyle;
package/lib/utils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export function deepEqual(a: any, b: any): boolean;
package/lib/utils.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.deepEqual = void 0;
7
+
8
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
9
+
10
+ var deepEqual = function deepEqual(a, b) {
11
+ if (a === b) return true;
12
+ if (_typeof(a) !== 'object' || _typeof(b) !== 'object' || a === null || b === null) return false;
13
+ var keysA = Object.keys(a),
14
+ keysB = Object.keys(b);
15
+ if (keysA.length !== keysB.length) return false;
16
+
17
+ for (var _i = 0, _keysA = keysA; _i < _keysA.length; _i++) {
18
+ var key = _keysA[_i];
19
+ if (!keysB.includes(key)) return false;
20
+
21
+ if (typeof a[key] === 'function' || typeof b[key] === 'function') {
22
+ if (a[key].toString() !== b[key].toString()) return false;
23
+ } else {
24
+ if (!deepEqual(a[key], b[key])) return false;
25
+ }
26
+ }
27
+
28
+ return true;
29
+ };
30
+
31
+ exports.deepEqual = deepEqual;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maif/react-forms",
3
3
  "description": "Build react safe forms as fast as possible",
4
- "version": "1.0.4",
4
+ "version": "1.0.8",
5
5
  "main": "lib/index.js",
6
6
  "author": "MAIF team",
7
7
  "keywords": [
@@ -113,8 +113,9 @@
113
113
  "react-ace": "9.4.3",
114
114
  "react-feather": "2.0.9",
115
115
  "react-hook-form": "7.17.1",
116
+ "react-jss": "10.8.2",
116
117
  "react-rainbow-components": "1.26.0",
117
- "react-select": "4.3.1",
118
+ "react-select": "5.2.1",
118
119
  "react-tooltip": "4.2.21",
119
120
  "showdown": "1.9.1",
120
121
  "typescript": "^4.3.5",