@danderson00/react-forms-material 0.0.25 → 0.1.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.
- package/dist/index.js +112 -191
- package/dist/styles.js +45 -4
- package/package.json +10 -25
- package/src/index.js +42 -40
- package/src/styles.js +23 -8
package/dist/index.js
CHANGED
|
@@ -1,214 +1,135 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { FormProvider, context, createRawConsumer, wrapInput, wrapSubmit, useFormValues } from '@danderson00/react-forms';
|
|
3
|
+
import { extractErrorMessage } from '@danderson00/react-forms/dist/ErrorMessage';
|
|
4
|
+
import MuiButton from '@mui/material/Button';
|
|
5
|
+
import MuiCheckbox from '@mui/material/Checkbox';
|
|
6
|
+
import MuiFormControl from '@mui/material/FormControl';
|
|
7
|
+
import MuiFormHelperText from '@mui/material/FormHelperText';
|
|
8
|
+
import MuiInput from '@mui/material/Input';
|
|
9
|
+
import MuiInputLabel from '@mui/material/InputLabel';
|
|
10
|
+
import MuiMenuItem from '@mui/material/MenuItem';
|
|
11
|
+
import MuiRadio from '@mui/material/Radio';
|
|
12
|
+
import MuiRadioGroup from '@mui/material/RadioGroup';
|
|
13
|
+
import MuiSelect from '@mui/material/Select';
|
|
14
|
+
import './styles';
|
|
15
|
+
export const ErrorMessage = ({
|
|
16
|
+
error
|
|
17
|
+
}) => createElement(MuiFormHelperText, {
|
|
18
|
+
children: extractErrorMessage(error),
|
|
19
|
+
error: true
|
|
12
20
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _react = require("react");
|
|
16
|
-
|
|
17
|
-
var _reactForms = require("@danderson00/react-forms");
|
|
18
|
-
|
|
19
|
-
var _ErrorMessage = require("@danderson00/react-forms/dist/ErrorMessage");
|
|
20
|
-
|
|
21
|
-
var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
|
|
22
|
-
|
|
23
|
-
var _Checkbox = _interopRequireDefault(require("@material-ui/core/Checkbox"));
|
|
24
|
-
|
|
25
|
-
var _FormControl = _interopRequireDefault(require("@material-ui/core/FormControl"));
|
|
26
|
-
|
|
27
|
-
var _FormHelperText = _interopRequireDefault(require("@material-ui/core/FormHelperText"));
|
|
28
|
-
|
|
29
|
-
var _Input = _interopRequireDefault(require("@material-ui/core/Input"));
|
|
30
|
-
|
|
31
|
-
var _InputLabel = _interopRequireDefault(require("@material-ui/core/InputLabel"));
|
|
32
|
-
|
|
33
|
-
var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));
|
|
34
|
-
|
|
35
|
-
var _Radio = _interopRequireDefault(require("@material-ui/core/Radio"));
|
|
36
|
-
|
|
37
|
-
var _RadioGroup = _interopRequireDefault(require("@material-ui/core/RadioGroup"));
|
|
38
|
-
|
|
39
|
-
var _Select = _interopRequireDefault(require("@material-ui/core/Select"));
|
|
40
|
-
|
|
41
|
-
require("./styles");
|
|
42
|
-
|
|
43
|
-
var _excluded = ["className", "error", "hiddenLabel", "variant", "margin", "label", "helperText", "shrinkLabel", "valid"],
|
|
44
|
-
_excluded2 = ["name", "values", "labels", "numeric", "required", "getFieldValue", "getFieldValues"],
|
|
45
|
-
_excluded3 = ["values", "labels"];
|
|
46
|
-
|
|
47
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
48
|
-
|
|
49
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
50
|
-
|
|
51
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
52
|
-
|
|
53
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
54
|
-
|
|
55
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
56
|
-
|
|
57
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
58
|
-
|
|
59
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
60
|
-
|
|
61
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
62
|
-
|
|
63
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
64
|
-
|
|
65
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
66
|
-
|
|
67
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
68
|
-
|
|
69
|
-
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; }
|
|
70
|
-
|
|
71
|
-
var ErrorMessage = function ErrorMessage(_ref) {
|
|
72
|
-
var error = _ref.error;
|
|
73
|
-
return /*#__PURE__*/(0, _react.createElement)(_FormHelperText["default"], {
|
|
74
|
-
children: (0, _ErrorMessage.extractErrorMessage)(error),
|
|
75
|
-
error: true
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
exports.ErrorMessage = ErrorMessage;
|
|
80
|
-
var Form = (0, _reactForms.FormProvider)(_reactForms.context.Provider, {
|
|
21
|
+
export const Form = FormProvider(context.Provider, {
|
|
81
22
|
margin: 'dense'
|
|
82
23
|
}, ErrorMessage);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
var Button = _Button["default"];
|
|
87
|
-
exports.Button = Button;
|
|
88
|
-
|
|
89
|
-
var wrapped = function wrapped(component, options, baseOptions) {
|
|
90
|
-
return (0, _reactForms.wrapInput)(base(component, options, baseOptions), _objectSpread({
|
|
91
|
-
passErrorProp: true
|
|
92
|
-
}, options));
|
|
93
|
-
};
|
|
24
|
+
export const Submit = wrapSubmit(MuiButton);
|
|
25
|
+
export const Button = MuiButton;
|
|
26
|
+
export { useFormValues };
|
|
94
27
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
alwaysShrinkLabel = _ref2.alwaysShrinkLabel,
|
|
100
|
-
_ref2$shrinkLabel = _ref2.shrinkLabel,
|
|
101
|
-
shrinkLabelOption = _ref2$shrinkLabel === void 0 ? true : _ref2$shrinkLabel,
|
|
102
|
-
passError = _ref2.passError;
|
|
103
|
-
|
|
104
|
-
return function (_ref3) {
|
|
105
|
-
var className = _ref3.className,
|
|
106
|
-
error = _ref3.error,
|
|
107
|
-
hiddenLabel = _ref3.hiddenLabel,
|
|
108
|
-
variant = _ref3.variant,
|
|
109
|
-
margin = _ref3.margin,
|
|
110
|
-
label = _ref3.label,
|
|
111
|
-
helperText = _ref3.helperText,
|
|
112
|
-
shrinkLabel = _ref3.shrinkLabel,
|
|
113
|
-
valid = _ref3.valid,
|
|
114
|
-
inputProps = _objectWithoutProperties(_ref3, _excluded);
|
|
28
|
+
const wrapped = (component, options, baseOptions) => wrapInput(base(component, options, baseOptions), {
|
|
29
|
+
passErrorProp: true,
|
|
30
|
+
...options
|
|
31
|
+
});
|
|
115
32
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
33
|
+
const base = (component, options = {}, {
|
|
34
|
+
alwaysShrinkLabel,
|
|
35
|
+
shrinkLabel: shrinkLabelOption = true,
|
|
36
|
+
passError
|
|
37
|
+
} = {}) => ({
|
|
38
|
+
className,
|
|
39
|
+
error,
|
|
40
|
+
hiddenLabel,
|
|
41
|
+
variant,
|
|
42
|
+
margin,
|
|
43
|
+
label,
|
|
44
|
+
helperText,
|
|
45
|
+
shrinkLabel,
|
|
46
|
+
valid,
|
|
47
|
+
...inputProps
|
|
48
|
+
}) => createElement(MuiFormControl, {
|
|
49
|
+
className: `react-forms-material-field${options.type ? ` react-forms-material-${options.type}` : ''}${className ? ` ${className}` : ''}`,
|
|
50
|
+
error,
|
|
51
|
+
fullWidth: inputProps.fullWidth,
|
|
52
|
+
hiddenLabel,
|
|
53
|
+
required: inputProps.required,
|
|
54
|
+
variant,
|
|
55
|
+
margin,
|
|
56
|
+
children: [...(label ? [createElement(MuiInputLabel, {
|
|
57
|
+
key: 'label',
|
|
58
|
+
htmlFor: inputProps.id,
|
|
59
|
+
children: label,
|
|
60
|
+
...(shrinkLabelOption === false && {
|
|
61
|
+
shrink: false
|
|
62
|
+
}),
|
|
63
|
+
...((alwaysShrinkLabel || shrinkLabel) && {
|
|
64
|
+
className: 'MuiInputLabel-shrink'
|
|
65
|
+
})
|
|
66
|
+
})] : []), createElement(component, {
|
|
67
|
+
key: 'input',
|
|
68
|
+
variant,
|
|
69
|
+
...(passError && {
|
|
70
|
+
error
|
|
71
|
+
}),
|
|
72
|
+
...inputProps
|
|
73
|
+
}), ...(helperText ? [createElement(MuiFormHelperText, {
|
|
74
|
+
key: 'helperText',
|
|
75
|
+
children: helperText
|
|
76
|
+
})] : [])]
|
|
77
|
+
});
|
|
144
78
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
exports.Text = Text;
|
|
149
|
-
var Checkbox = wrapped(_Checkbox["default"], {
|
|
79
|
+
export const Input = wrapInput(MuiInput);
|
|
80
|
+
export const Text = wrapped(MuiInput);
|
|
81
|
+
export const Checkbox = wrapped(MuiCheckbox, {
|
|
150
82
|
type: 'checkbox'
|
|
151
83
|
}, {
|
|
152
84
|
alwaysShrinkLabel: true
|
|
153
85
|
});
|
|
154
|
-
|
|
155
|
-
var RadioButton = wrapped(_Radio["default"], {
|
|
86
|
+
export const RadioButton = wrapped(MuiRadio, {
|
|
156
87
|
type: 'radio'
|
|
157
88
|
}, {
|
|
158
89
|
shrinkLabel: false
|
|
159
90
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}));
|
|
183
|
-
})]
|
|
184
|
-
}));
|
|
185
|
-
}, {
|
|
91
|
+
export const Radio = createRawConsumer(base(({
|
|
92
|
+
name,
|
|
93
|
+
values,
|
|
94
|
+
labels,
|
|
95
|
+
numeric,
|
|
96
|
+
required,
|
|
97
|
+
getFieldValue,
|
|
98
|
+
getFieldValues,
|
|
99
|
+
...props
|
|
100
|
+
}) => createElement(MuiRadioGroup, { ...props,
|
|
101
|
+
children: [values.map((value, index) => createElement(RadioButton, {
|
|
102
|
+
name,
|
|
103
|
+
value,
|
|
104
|
+
numeric,
|
|
105
|
+
key: value,
|
|
106
|
+
label: labels && labels[index] || value,
|
|
107
|
+
margin: props.margin,
|
|
108
|
+
...(required && {
|
|
109
|
+
required
|
|
110
|
+
})
|
|
111
|
+
}))]
|
|
112
|
+
}), {
|
|
186
113
|
type: 'radiogroup'
|
|
187
114
|
}, {
|
|
188
115
|
alwaysShrinkLabel: true
|
|
189
116
|
}));
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
children: labels && labels[index] || value
|
|
202
|
-
}, props.required && {
|
|
203
|
-
required: props.required
|
|
204
|
-
}));
|
|
117
|
+
export const Select = wrapped(({
|
|
118
|
+
values,
|
|
119
|
+
labels,
|
|
120
|
+
...props
|
|
121
|
+
}) => createElement(MuiSelect, { ...props,
|
|
122
|
+
children: values.map((value, index) => createElement(MuiMenuItem, {
|
|
123
|
+
value,
|
|
124
|
+
key: value,
|
|
125
|
+
children: labels && labels[index] || value,
|
|
126
|
+
...(props.required && {
|
|
127
|
+
required: props.required
|
|
205
128
|
})
|
|
206
|
-
}))
|
|
207
|
-
}, {
|
|
129
|
+
}))
|
|
130
|
+
}), {
|
|
208
131
|
type: 'select'
|
|
209
132
|
}, {
|
|
210
133
|
alwaysShrinkLabel: true
|
|
211
134
|
});
|
|
212
|
-
|
|
213
|
-
var wrapField = wrapped;
|
|
214
|
-
exports.wrapField = wrapField;
|
|
135
|
+
export const wrapField = wrapped;
|
package/dist/styles.js
CHANGED
|
@@ -1,7 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
import injectCss from '@danderson00/react-forms/dist/injectCss';
|
|
2
|
+
injectCss('react-forms-material-styles', `
|
|
3
|
+
.react-forms-material-radiogroup.MuiFormControl-root {
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
}
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
.react-forms-material-radio.MuiFormControl-root {
|
|
8
|
+
flex-direction: row-reverse;
|
|
9
|
+
justify-content: flex-end;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.react-forms-material-radio .MuiInputLabel-formControl {
|
|
13
|
+
position: static;
|
|
14
|
+
}
|
|
4
15
|
|
|
5
|
-
|
|
16
|
+
.react-forms-material-radio .MuiRadio-root {
|
|
17
|
+
transform: translate(0, 9px) scale(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.react-forms-material-checkbox .MuiCheckbox-root {
|
|
21
|
+
transform: translate(0, 9px) scale(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* allow forms to be embedded in dialogs - essentially replicate a few styles */
|
|
25
|
+
.MuiDialog-container form {
|
|
26
|
+
display: flex;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.MuiDialog-container form .MuiDialogContent-root {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: flex-start;
|
|
32
|
+
flex-direction: column;
|
|
33
|
+
}
|
|
6
34
|
|
|
7
|
-
|
|
35
|
+
.MuiDialog-container form .MuiDialogActions-root {
|
|
36
|
+
align-self: flex-end;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.react-forms input::-webkit-outer-spin-button,
|
|
40
|
+
.react-forms input::-webkit-inner-spin-button {
|
|
41
|
+
-webkit-appearance: none;
|
|
42
|
+
margin: 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.react-forms input[type=number] {
|
|
46
|
+
-moz-appearance: textfield;
|
|
47
|
+
}
|
|
48
|
+
`);
|
package/package.json
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danderson00/react-forms-material",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Beautiful, ultra simple, stateless, validated forms for use in React function components",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
5
|
"module": "src/index.js",
|
|
7
6
|
"scripts": {
|
|
8
|
-
"test": "jest"
|
|
9
|
-
"build": "babel src --out-dir dist",
|
|
10
|
-
"prepare": "babel src --source-maps false --out-dir dist"
|
|
7
|
+
"test": "jest"
|
|
11
8
|
},
|
|
12
9
|
"dependencies": {
|
|
13
|
-
"@danderson00/react-forms": "0.0.25",
|
|
14
|
-
"@material-ui/core": "^4.11.3"
|
|
15
10
|
},
|
|
16
11
|
"peerDependencies": {
|
|
17
|
-
"react": "^
|
|
12
|
+
"react": "^18.2.0"
|
|
18
13
|
},
|
|
19
14
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"enzyme-adapter-react-16": "^1.9.1",
|
|
27
|
-
"jest": "26.6.0",
|
|
28
|
-
"react": "^17.0.1",
|
|
29
|
-
"react-dom": "^17.0.1"
|
|
15
|
+
"@danderson00/react-forms": "0.0.27",
|
|
16
|
+
"@emotion/react": "^11.9.3",
|
|
17
|
+
"@emotion/styled": "^11.9.3",
|
|
18
|
+
"@mui/material": "^5.8.7",
|
|
19
|
+
"react": "^18.2.0",
|
|
20
|
+
"react-dom": "^18.2.0"
|
|
30
21
|
},
|
|
31
22
|
"jest": {
|
|
32
23
|
"moduleNameMapper": {
|
|
@@ -36,12 +27,6 @@
|
|
|
36
27
|
"<rootDir>test/setup/beforeAll.js"
|
|
37
28
|
]
|
|
38
29
|
},
|
|
39
|
-
"babel": {
|
|
40
|
-
"presets": [
|
|
41
|
-
"@babel/preset-env",
|
|
42
|
-
"@babel/preset-react"
|
|
43
|
-
]
|
|
44
|
-
},
|
|
45
30
|
"keywords": [
|
|
46
31
|
"react",
|
|
47
32
|
"stateless",
|
|
@@ -60,4 +45,4 @@
|
|
|
60
45
|
"type": "git",
|
|
61
46
|
"url": "git+https://gitlab.com/danderson00/react-forms.git"
|
|
62
47
|
}
|
|
63
|
-
}
|
|
48
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { createElement } from 'react'
|
|
2
2
|
import { FormProvider, context, createRawConsumer, wrapInput, wrapSubmit, useFormValues } from '@danderson00/react-forms'
|
|
3
3
|
import { extractErrorMessage } from '@danderson00/react-forms/dist/ErrorMessage'
|
|
4
|
-
import MuiButton from '@material
|
|
5
|
-
import MuiCheckbox from '@material
|
|
6
|
-
import MuiFormControl from '@material
|
|
7
|
-
import MuiFormHelperText from '@material
|
|
8
|
-
import MuiInput from '@material
|
|
9
|
-
import MuiInputLabel from '@material
|
|
10
|
-
import MuiMenuItem from '@material
|
|
11
|
-
import MuiRadio from '@material
|
|
12
|
-
import MuiRadioGroup from '@material
|
|
13
|
-
import MuiSelect from '@material
|
|
4
|
+
import MuiButton from '@mui/material/Button'
|
|
5
|
+
import MuiCheckbox from '@mui/material/Checkbox'
|
|
6
|
+
import MuiFormControl from '@mui/material/FormControl'
|
|
7
|
+
import MuiFormHelperText from '@mui/material/FormHelperText'
|
|
8
|
+
import MuiInput from '@mui/material/Input'
|
|
9
|
+
import MuiInputLabel from '@mui/material/InputLabel'
|
|
10
|
+
import MuiMenuItem from '@mui/material/MenuItem'
|
|
11
|
+
import MuiRadio from '@mui/material/Radio'
|
|
12
|
+
import MuiRadioGroup from '@mui/material/RadioGroup'
|
|
13
|
+
import MuiSelect from '@mui/material/Select'
|
|
14
14
|
import './styles'
|
|
15
15
|
|
|
16
16
|
export const ErrorMessage = ({ error }) => createElement(MuiFormHelperText, { children: extractErrorMessage(error), error: true })
|
|
@@ -25,38 +25,40 @@ const wrapped = (component, options, baseOptions) => wrapInput(
|
|
|
25
25
|
)
|
|
26
26
|
|
|
27
27
|
const base = (component, options = {}, { alwaysShrinkLabel, shrinkLabel: shrinkLabelOption = true, passError } = {}) => (
|
|
28
|
-
({ className, error, hiddenLabel, variant, margin, label, helperText, shrinkLabel, valid, ...inputProps }) =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
({ className, error, hiddenLabel, variant, margin, label, helperText, shrinkLabel, valid, ...inputProps }) => {
|
|
29
|
+
return (
|
|
30
|
+
createElement(MuiFormControl, {
|
|
31
|
+
className: `react-forms-material-field${options.type ? ` react-forms-material-${options.type}` : ''}${className ? ` ${className}` : ''}`,
|
|
32
|
+
error,
|
|
33
|
+
fullWidth: inputProps.fullWidth,
|
|
34
|
+
hiddenLabel,
|
|
35
|
+
required: inputProps.required,
|
|
36
|
+
variant,
|
|
37
|
+
margin,
|
|
38
|
+
children: [
|
|
39
|
+
...(label ? [createElement(MuiInputLabel, {
|
|
40
|
+
key: 'label',
|
|
41
|
+
htmlFor: inputProps.id,
|
|
42
|
+
children: label,
|
|
43
|
+
...(shrinkLabelOption === false && { shrink: false }),
|
|
44
|
+
...((alwaysShrinkLabel || shrinkLabel) && { className: 'MuiInputLabel-shrink' }),
|
|
45
|
+
})] : []),
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
createElement(component, {
|
|
48
|
+
key: 'input',
|
|
49
|
+
variant,
|
|
50
|
+
...(passError && { error }),
|
|
51
|
+
...inputProps
|
|
52
|
+
}),
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
...(helperText ? [createElement(MuiFormHelperText, {
|
|
55
|
+
key: 'helperText',
|
|
56
|
+
children: helperText
|
|
57
|
+
})] : [])
|
|
58
|
+
]
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
}
|
|
60
62
|
)
|
|
61
63
|
|
|
62
64
|
export const Input = wrapInput(MuiInput)
|
package/src/styles.js
CHANGED
|
@@ -5,24 +5,39 @@ injectCss('react-forms-material-styles', `
|
|
|
5
5
|
overflow: hidden;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
.react-forms-material-radio,
|
|
9
|
+
.react-forms-material-checkbox {
|
|
10
|
+
display: flex !important;
|
|
11
|
+
flex-direction: row-reverse !important;
|
|
12
|
+
align-items: center;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
.react-forms-material-radio.MuiFormControl-root {
|
|
9
16
|
flex-direction: row-reverse;
|
|
10
17
|
justify-content: flex-end;
|
|
11
18
|
}
|
|
12
19
|
|
|
13
|
-
.react-forms-material-radio .MuiInputLabel-formControl
|
|
20
|
+
.react-forms-material-radio .MuiInputLabel-formControl,
|
|
21
|
+
.react-forms-material-radiogroup .MuiInputLabel-formControl,
|
|
22
|
+
.react-forms-material-checkbox .MuiInputLabel-formControl {
|
|
14
23
|
position: static;
|
|
24
|
+
transform: none;
|
|
25
|
+
line-height: 1;
|
|
26
|
+
transform: translateY(2px) scale(1);
|
|
15
27
|
}
|
|
16
|
-
|
|
17
|
-
.react-forms-material-radio .MuiRadio-root {
|
|
18
|
-
transform: translate(0, 9px) scale(1);
|
|
19
|
-
}
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
|
|
30
|
+
.react-forms input::-webkit-outer-spin-button,
|
|
31
|
+
.react-forms input::-webkit-inner-spin-button {
|
|
32
|
+
-webkit-appearance: none;
|
|
33
|
+
margin: 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.react-forms input[type=number] {
|
|
37
|
+
-moz-appearance: textfield;
|
|
23
38
|
}
|
|
24
39
|
|
|
25
|
-
/* allow forms to be embedded in dialogs - essentially replicate a few styles */
|
|
40
|
+
${''/* allow forms to be embedded in dialogs - essentially replicate a few styles */}
|
|
26
41
|
.MuiDialog-container form {
|
|
27
42
|
display: flex;
|
|
28
43
|
}
|