@danderson00/react-forms-material 0.0.48 → 0.0.49
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/README.md +145 -145
- package/TODO.md +1 -1
- package/dist/index.js +20 -25
- package/dist/index.js.map +1 -1
- package/dist/styles.js.map +1 -1
- package/package.json +62 -62
- package/src/index.js +106 -106
- package/src/styles.js +51 -51
package/README.md
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
# @danderson00/react-forms-material
|
|
2
|
-
|
|
3
|
-
Beautiful, ultra simple, stateless, validated forms for use in React function components.
|
|
4
|
-
|
|
5
|
-
A demo is available at [https://danderson00digital.github.io/react-forms-material/](https://danderson00digital.github.io/react-forms-material/).
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```shell
|
|
10
|
-
yarn add @danderson00/react-forms-material
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```jsx
|
|
16
|
-
import React from 'react'
|
|
17
|
-
import { Form, Text, Select, Radio, Checkbox, Submit } from '@danderson00/react-forms-material'
|
|
18
|
-
|
|
19
|
-
export default ({ onSubmit, initialValues }) => (
|
|
20
|
-
<Form onSubmit={onSubmit} values={initialValues}>
|
|
21
|
-
<Text name="name" label="Name" required minLength="5" maxLength="50" />
|
|
22
|
-
<Text name="description" label="Description" multiline maxLength="100" />
|
|
23
|
-
<Select name="type" label="Type" values={['', 'Widget', 'Component']} required />
|
|
24
|
-
<Radio name="rating" label="Rating" values={[1, 2, 3]} row />
|
|
25
|
-
<Checkbox name="urgent" label="Urgent" />
|
|
26
|
-
|
|
27
|
-
<Submit>Submit</Submit>
|
|
28
|
-
</Form>
|
|
29
|
-
)
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Core Components
|
|
33
|
-
|
|
34
|
-
### `Form`
|
|
35
|
-
|
|
36
|
-
All input components must be contained within a `Form` component.
|
|
37
|
-
|
|
38
|
-
#### Props
|
|
39
|
-
|
|
40
|
-
Name|Type|Description
|
|
41
|
-
---|---|---
|
|
42
|
-
values|object|Object containing initial values for form elements
|
|
43
|
-
onSubmit|function(values)|A callback to be executed when the corresponding `Submit` component is clicked
|
|
44
|
-
|
|
45
|
-
All other props are passed on to the underlying `form` element.
|
|
46
|
-
|
|
47
|
-
### `Submit`
|
|
48
|
-
|
|
49
|
-
Renders a Material UI [`Button` component](https://material-ui.com/api/button/) that triggers the closest `Form`
|
|
50
|
-
component's `onSubmit` callback.
|
|
51
|
-
|
|
52
|
-
#### Props
|
|
53
|
-
|
|
54
|
-
All props are passed on to the underlying `Button` component.
|
|
55
|
-
|
|
56
|
-
### `Button`
|
|
57
|
-
|
|
58
|
-
A pass through of the Material UI [`Button` component](https://material-ui.com/api/button/) for convenience.
|
|
59
|
-
|
|
60
|
-
## Field Components
|
|
61
|
-
|
|
62
|
-
Field components are constructed by wrapping a Material UI [`InputLabel` component](https://material-ui.com/api/input-label/),
|
|
63
|
-
a form component and [`FormHelperText` component](https://material-ui.com/api/form-helper-text/) within a
|
|
64
|
-
[`FormControl` component](https://material-ui.com/api/form-control/), similar to a
|
|
65
|
-
[`TextField` component](https://material-ui.com/api/text-field/).
|
|
66
|
-
|
|
67
|
-
All field components can be passed the following props:
|
|
68
|
-
|
|
69
|
-
Name|Type|Description
|
|
70
|
-
---|---|---
|
|
71
|
-
name|string|Specifies the name of the property to populate with the field value (required)
|
|
72
|
-
label|string|Text on the field's label
|
|
73
|
-
value|any|Initial value for the field. The DOM API will generally cast this to a string
|
|
74
|
-
helperText|string|Specifies the helper text for the field
|
|
75
|
-
|
|
76
|
-
The following props are passed to the parent [`FormControl` component](https://material-ui.com/api/form-control/):
|
|
77
|
-
|
|
78
|
-
Name|Type|Description
|
|
79
|
-
---|---|---
|
|
80
|
-
className|string|Class name to apply to the component
|
|
81
|
-
fullWidth|boolean|Specifies that the field should occupy the full width of its parent
|
|
82
|
-
variant|string|Corresponds to the `variant` [prop](https://material-ui.com/api/form-control/#props) of a `FormControl`. One of `standard`, `outlined` or `filled`
|
|
83
|
-
margin|string|Corresponds to the `margin` [prop](https://material-ui.com/api/form-control/#props) of a `FormControl`. One of `none`, `dense` or `normal`. Most fields, except `Text` default to `normal`
|
|
84
|
-
|
|
85
|
-
All other props are passed to the input component, as described below.
|
|
86
|
-
|
|
87
|
-
### `Text`
|
|
88
|
-
|
|
89
|
-
Renders a field component with a Material UI [`Input` component](https://material-ui.com/api/input/) as the input
|
|
90
|
-
component.
|
|
91
|
-
|
|
92
|
-
### `Select`
|
|
93
|
-
|
|
94
|
-
Renders a field component with a Material UI [`Select` component](https://material-ui.com/api/select/) as the input
|
|
95
|
-
component. Options are specified using the props below and are rendered as
|
|
96
|
-
[`MenuItem` components](https://material-ui.com/api/menu-item/).
|
|
97
|
-
|
|
98
|
-
#### Props
|
|
99
|
-
|
|
100
|
-
Name|Type|Description
|
|
101
|
-
---|---|---
|
|
102
|
-
values|array(any)|Specifies the values to use for each option. The DOM API casts these to strings
|
|
103
|
-
labels|array(string)|Specifies the labels to use for each corresponding option in the `values` array. If not specified, entries from the `values` array are used.
|
|
104
|
-
|
|
105
|
-
### `Radio`
|
|
106
|
-
|
|
107
|
-
Renders a field component with a Material UI [`RadioGroup` component](https://material-ui.com/api/radio-group/) as the
|
|
108
|
-
input component. Options are specified using the props below and are rendered as `RadioButton` components, described
|
|
109
|
-
in the next section.
|
|
110
|
-
|
|
111
|
-
#### Props
|
|
112
|
-
|
|
113
|
-
Name|Type|Description
|
|
114
|
-
---|---|---
|
|
115
|
-
values|array(any)|Specifies the values to use for each option. The DOM API casts these to strings
|
|
116
|
-
labels|array(string)|Specifies the labels to use for each corresponding option in the `values` array. If not specified, entries from the `values` array are used
|
|
117
|
-
|
|
118
|
-
### `RadioButton`
|
|
119
|
-
|
|
120
|
-
Renders a field component with a Material UI [`Radio` component](https://material-ui.com/api/radio/) as the input
|
|
121
|
-
component.
|
|
122
|
-
|
|
123
|
-
### `Checkbox`
|
|
124
|
-
|
|
125
|
-
Renders a field component with a Material UI [`Checkbox` component](https://material-ui.com/api/checkbox/) as the
|
|
126
|
-
input component.
|
|
127
|
-
|
|
128
|
-
## License
|
|
129
|
-
|
|
130
|
-
**The MIT License (MIT)**
|
|
131
|
-
|
|
132
|
-
Copyright © 2022 Dale Anderson
|
|
133
|
-
|
|
134
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
135
|
-
documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
|
|
136
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
137
|
-
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
138
|
-
|
|
139
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
140
|
-
Software.
|
|
141
|
-
|
|
142
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
143
|
-
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
144
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
145
|
-
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
# @danderson00/react-forms-material
|
|
2
|
+
|
|
3
|
+
Beautiful, ultra simple, stateless, validated forms for use in React function components.
|
|
4
|
+
|
|
5
|
+
A demo is available at [https://danderson00digital.github.io/react-forms-material/](https://danderson00digital.github.io/react-forms-material/).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
yarn add @danderson00/react-forms-material
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import React from 'react'
|
|
17
|
+
import { Form, Text, Select, Radio, Checkbox, Submit } from '@danderson00/react-forms-material'
|
|
18
|
+
|
|
19
|
+
export default ({ onSubmit, initialValues }) => (
|
|
20
|
+
<Form onSubmit={onSubmit} values={initialValues}>
|
|
21
|
+
<Text name="name" label="Name" required minLength="5" maxLength="50" />
|
|
22
|
+
<Text name="description" label="Description" multiline maxLength="100" />
|
|
23
|
+
<Select name="type" label="Type" values={['', 'Widget', 'Component']} required />
|
|
24
|
+
<Radio name="rating" label="Rating" values={[1, 2, 3]} row />
|
|
25
|
+
<Checkbox name="urgent" label="Urgent" />
|
|
26
|
+
|
|
27
|
+
<Submit>Submit</Submit>
|
|
28
|
+
</Form>
|
|
29
|
+
)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Core Components
|
|
33
|
+
|
|
34
|
+
### `Form`
|
|
35
|
+
|
|
36
|
+
All input components must be contained within a `Form` component.
|
|
37
|
+
|
|
38
|
+
#### Props
|
|
39
|
+
|
|
40
|
+
Name|Type|Description
|
|
41
|
+
---|---|---
|
|
42
|
+
values|object|Object containing initial values for form elements
|
|
43
|
+
onSubmit|function(values)|A callback to be executed when the corresponding `Submit` component is clicked
|
|
44
|
+
|
|
45
|
+
All other props are passed on to the underlying `form` element.
|
|
46
|
+
|
|
47
|
+
### `Submit`
|
|
48
|
+
|
|
49
|
+
Renders a Material UI [`Button` component](https://material-ui.com/api/button/) that triggers the closest `Form`
|
|
50
|
+
component's `onSubmit` callback.
|
|
51
|
+
|
|
52
|
+
#### Props
|
|
53
|
+
|
|
54
|
+
All props are passed on to the underlying `Button` component.
|
|
55
|
+
|
|
56
|
+
### `Button`
|
|
57
|
+
|
|
58
|
+
A pass through of the Material UI [`Button` component](https://material-ui.com/api/button/) for convenience.
|
|
59
|
+
|
|
60
|
+
## Field Components
|
|
61
|
+
|
|
62
|
+
Field components are constructed by wrapping a Material UI [`InputLabel` component](https://material-ui.com/api/input-label/),
|
|
63
|
+
a form component and [`FormHelperText` component](https://material-ui.com/api/form-helper-text/) within a
|
|
64
|
+
[`FormControl` component](https://material-ui.com/api/form-control/), similar to a
|
|
65
|
+
[`TextField` component](https://material-ui.com/api/text-field/).
|
|
66
|
+
|
|
67
|
+
All field components can be passed the following props:
|
|
68
|
+
|
|
69
|
+
Name|Type|Description
|
|
70
|
+
---|---|---
|
|
71
|
+
name|string|Specifies the name of the property to populate with the field value (required)
|
|
72
|
+
label|string|Text on the field's label
|
|
73
|
+
value|any|Initial value for the field. The DOM API will generally cast this to a string
|
|
74
|
+
helperText|string|Specifies the helper text for the field
|
|
75
|
+
|
|
76
|
+
The following props are passed to the parent [`FormControl` component](https://material-ui.com/api/form-control/):
|
|
77
|
+
|
|
78
|
+
Name|Type|Description
|
|
79
|
+
---|---|---
|
|
80
|
+
className|string|Class name to apply to the component
|
|
81
|
+
fullWidth|boolean|Specifies that the field should occupy the full width of its parent
|
|
82
|
+
variant|string|Corresponds to the `variant` [prop](https://material-ui.com/api/form-control/#props) of a `FormControl`. One of `standard`, `outlined` or `filled`
|
|
83
|
+
margin|string|Corresponds to the `margin` [prop](https://material-ui.com/api/form-control/#props) of a `FormControl`. One of `none`, `dense` or `normal`. Most fields, except `Text` default to `normal`
|
|
84
|
+
|
|
85
|
+
All other props are passed to the input component, as described below.
|
|
86
|
+
|
|
87
|
+
### `Text`
|
|
88
|
+
|
|
89
|
+
Renders a field component with a Material UI [`Input` component](https://material-ui.com/api/input/) as the input
|
|
90
|
+
component.
|
|
91
|
+
|
|
92
|
+
### `Select`
|
|
93
|
+
|
|
94
|
+
Renders a field component with a Material UI [`Select` component](https://material-ui.com/api/select/) as the input
|
|
95
|
+
component. Options are specified using the props below and are rendered as
|
|
96
|
+
[`MenuItem` components](https://material-ui.com/api/menu-item/).
|
|
97
|
+
|
|
98
|
+
#### Props
|
|
99
|
+
|
|
100
|
+
Name|Type|Description
|
|
101
|
+
---|---|---
|
|
102
|
+
values|array(any)|Specifies the values to use for each option. The DOM API casts these to strings
|
|
103
|
+
labels|array(string)|Specifies the labels to use for each corresponding option in the `values` array. If not specified, entries from the `values` array are used.
|
|
104
|
+
|
|
105
|
+
### `Radio`
|
|
106
|
+
|
|
107
|
+
Renders a field component with a Material UI [`RadioGroup` component](https://material-ui.com/api/radio-group/) as the
|
|
108
|
+
input component. Options are specified using the props below and are rendered as `RadioButton` components, described
|
|
109
|
+
in the next section.
|
|
110
|
+
|
|
111
|
+
#### Props
|
|
112
|
+
|
|
113
|
+
Name|Type|Description
|
|
114
|
+
---|---|---
|
|
115
|
+
values|array(any)|Specifies the values to use for each option. The DOM API casts these to strings
|
|
116
|
+
labels|array(string)|Specifies the labels to use for each corresponding option in the `values` array. If not specified, entries from the `values` array are used
|
|
117
|
+
|
|
118
|
+
### `RadioButton`
|
|
119
|
+
|
|
120
|
+
Renders a field component with a Material UI [`Radio` component](https://material-ui.com/api/radio/) as the input
|
|
121
|
+
component.
|
|
122
|
+
|
|
123
|
+
### `Checkbox`
|
|
124
|
+
|
|
125
|
+
Renders a field component with a Material UI [`Checkbox` component](https://material-ui.com/api/checkbox/) as the
|
|
126
|
+
input component.
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
**The MIT License (MIT)**
|
|
131
|
+
|
|
132
|
+
Copyright © 2022 Dale Anderson
|
|
133
|
+
|
|
134
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
135
|
+
documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
|
|
136
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
137
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
138
|
+
|
|
139
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
140
|
+
Software.
|
|
141
|
+
|
|
142
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
143
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
144
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
145
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/TODO.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
- Import specific components from @material-ui rather than everything from the main module (drastically reduce bundle size)
|
|
1
|
+
- Import specific components from @material-ui rather than everything from the main module (drastically reduce bundle size)
|
|
2
2
|
- Change dependency on @material-ui to peerDependency of version "*" to prevent conflicts with user dependencies
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,12 @@ Object.defineProperty(exports, "wrapInput", {
|
|
|
30
30
|
return _reactForms.wrapInput;
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
+
Object.defineProperty(exports, "wrapSubmit", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function get() {
|
|
36
|
+
return _reactForms.wrapSubmit;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
33
39
|
var _react = require("react");
|
|
34
40
|
var _reactForms = require("@danderson00/react-forms");
|
|
35
41
|
var _ErrorMessage = require("@danderson00/react-forms/src/ErrorMessage");
|
|
@@ -48,7 +54,7 @@ var _excluded = ["className", "error", "hiddenLabel", "variant", "margin", "labe
|
|
|
48
54
|
_excluded2 = ["name", "values", "labels", "numeric", "required", "getFieldValue", "getFieldValues", "inputProps"],
|
|
49
55
|
_excluded3 = ["values", "labels"];
|
|
50
56
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
51
|
-
function _typeof(
|
|
57
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
52
58
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
53
59
|
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."); }
|
|
54
60
|
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); }
|
|
@@ -57,27 +63,23 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
57
63
|
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; }
|
|
58
64
|
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; }
|
|
59
65
|
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; }
|
|
60
|
-
function ownKeys(
|
|
61
|
-
function _objectSpread(
|
|
66
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
67
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
62
68
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
63
69
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
64
70
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
65
|
-
var ErrorMessage = function ErrorMessage(_ref) {
|
|
71
|
+
var ErrorMessage = exports.ErrorMessage = function ErrorMessage(_ref) {
|
|
66
72
|
var error = _ref.error;
|
|
67
73
|
return /*#__PURE__*/(0, _react.createElement)(_FormHelperText["default"], {
|
|
68
74
|
children: (0, _ErrorMessage.extractErrorMessage)(error),
|
|
69
75
|
error: true
|
|
70
76
|
});
|
|
71
77
|
};
|
|
72
|
-
exports.
|
|
73
|
-
var Form = (0, _reactForms.FormProvider)(_reactForms.context.Provider, {
|
|
78
|
+
var Form = exports.Form = (0, _reactForms.FormProvider)(_reactForms.context.Provider, {
|
|
74
79
|
margin: 'dense'
|
|
75
80
|
}, ErrorMessage);
|
|
76
|
-
exports.
|
|
77
|
-
var
|
|
78
|
-
exports.Submit = Submit;
|
|
79
|
-
var Button = _Button["default"];
|
|
80
|
-
exports.Button = Button;
|
|
81
|
+
var Submit = exports.Submit = (0, _reactForms.wrapSubmit)(_Button["default"]);
|
|
82
|
+
var Button = exports.Button = _Button["default"];
|
|
81
83
|
var wrapped = function wrapped(component, options, baseOptions) {
|
|
82
84
|
return (0, _reactForms.wrapInput)(base(component, options, baseOptions), _objectSpread({
|
|
83
85
|
passErrorProp: true
|
|
@@ -134,23 +136,19 @@ var base = function base(component) {
|
|
|
134
136
|
});
|
|
135
137
|
};
|
|
136
138
|
};
|
|
137
|
-
var Input = (0, _reactForms.wrapInput)(_Input["default"]);
|
|
138
|
-
exports.
|
|
139
|
-
var
|
|
140
|
-
exports.Text = Text;
|
|
141
|
-
var Checkbox = wrapped(_Checkbox["default"], {
|
|
139
|
+
var Input = exports.Input = (0, _reactForms.wrapInput)(_Input["default"]);
|
|
140
|
+
var Text = exports.Text = wrapped(_Input["default"]);
|
|
141
|
+
var Checkbox = exports.Checkbox = wrapped(_Checkbox["default"], {
|
|
142
142
|
type: 'checkbox'
|
|
143
143
|
}, {
|
|
144
144
|
alwaysShrinkLabel: true
|
|
145
145
|
});
|
|
146
|
-
exports.
|
|
147
|
-
var RadioButton = wrapped(_Radio["default"], {
|
|
146
|
+
var RadioButton = exports.RadioButton = wrapped(_Radio["default"], {
|
|
148
147
|
type: 'radio'
|
|
149
148
|
}, {
|
|
150
149
|
shrinkLabel: false
|
|
151
150
|
});
|
|
152
|
-
exports.
|
|
153
|
-
var Radio = (0, _reactForms.createRawConsumer)(base(function (_ref4) {
|
|
151
|
+
var Radio = exports.Radio = (0, _reactForms.createRawConsumer)(base(function (_ref4) {
|
|
154
152
|
var name = _ref4.name,
|
|
155
153
|
values = _ref4.values,
|
|
156
154
|
labels = _ref4.labels,
|
|
@@ -181,8 +179,7 @@ var Radio = (0, _reactForms.createRawConsumer)(base(function (_ref4) {
|
|
|
181
179
|
}, {
|
|
182
180
|
alwaysShrinkLabel: true
|
|
183
181
|
}));
|
|
184
|
-
exports.
|
|
185
|
-
var Select = wrapped(function (_ref5) {
|
|
182
|
+
var Select = exports.Select = wrapped(function (_ref5) {
|
|
186
183
|
var values = _ref5.values,
|
|
187
184
|
labels = _ref5.labels,
|
|
188
185
|
props = _objectWithoutProperties(_ref5, _excluded3);
|
|
@@ -202,7 +199,5 @@ var Select = wrapped(function (_ref5) {
|
|
|
202
199
|
}, {
|
|
203
200
|
alwaysShrinkLabel: true
|
|
204
201
|
});
|
|
205
|
-
exports.
|
|
206
|
-
var wrapField = wrapped;
|
|
207
|
-
exports.wrapField = wrapField;
|
|
202
|
+
var wrapField = exports.wrapField = wrapped;
|
|
208
203
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_react","require","_reactForms","_ErrorMessage","_Button","_interopRequireDefault","_Checkbox","_FormControl","_FormHelperText","_Input","_InputLabel","_MenuItem","_Radio","_RadioGroup","_Select","_excluded","_excluded2","_excluded3","obj","__esModule","_typeof","Symbol","iterator","constructor","prototype","_toConsumableArray","arr","_arrayWithoutHoles","_iterableToArray","_unsupportedIterableToArray","_nonIterableSpread","TypeError","o","minLen","_arrayLikeToArray","n","Object","toString","call","slice","name","Array","from","test","iter","isArray","len","length","i","arr2","_objectWithoutProperties","source","excluded","target","_objectWithoutPropertiesLoose","key","getOwnPropertySymbols","sourceSymbolKeys","indexOf","propertyIsEnumerable","sourceKeys","keys","ownKeys","object","enumerableOnly","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","value","_toPropertyKey","configurable","writable","arg","_toPrimitive","String","input","hint","prim","toPrimitive","undefined","res","Number","ErrorMessage","_ref","error","createElement","MuiFormHelperText","children","extractErrorMessage","exports","Form","FormProvider","context","Provider","margin","Submit","wrapSubmit","MuiButton","Button","wrapped","component","options","baseOptions","wrapInput","base","passErrorProp","_ref2","alwaysShrinkLabel","_ref2$shrinkLabel","shrinkLabel","shrinkLabelOption","passError","_ref3","className","hiddenLabel","variant","label","helperText","valid","pattern","inputProps","MuiFormControl","concat","type","fullWidth","required","MuiInputLabel","htmlFor","id","shrink","Input","MuiInput","Text","Checkbox","MuiCheckbox","RadioButton","MuiRadio","Radio","createRawConsumer","_ref4","values","labels","numeric","getFieldValue","getFieldValues","props","MuiRadioGroup","map","index","Select","_ref5","MuiSelect","MuiMenuItem","wrapField"],"sources":["../src/index.js"],"sourcesContent":["import { createElement } from 'react'\r\nimport { FormProvider, Group, context, createRawConsumer, wrapInput, wrapSubmit, useForm, useFormValues } from '@danderson00/react-forms'\r\nimport { extractErrorMessage } from '@danderson00/react-forms/src/ErrorMessage'\r\nimport MuiButton from '@material-ui/core/Button'\r\nimport MuiCheckbox from '@material-ui/core/Checkbox'\r\nimport MuiFormControl from '@material-ui/core/FormControl'\r\nimport MuiFormHelperText from '@material-ui/core/FormHelperText'\r\nimport MuiInput from '@material-ui/core/Input'\r\nimport MuiInputLabel from '@material-ui/core/InputLabel'\r\nimport MuiMenuItem from '@material-ui/core/MenuItem'\r\nimport MuiRadio from '@material-ui/core/Radio'\r\nimport MuiRadioGroup from '@material-ui/core/RadioGroup'\r\nimport MuiSelect from '@material-ui/core/Select'\r\nimport './styles'\r\n\r\nexport const ErrorMessage = ({ error }) => createElement(MuiFormHelperText, { children: extractErrorMessage(error), error: true })\r\nexport const Form = FormProvider(context.Provider, { margin: 'dense' }, ErrorMessage)\r\nexport const Submit = wrapSubmit(MuiButton)\r\nexport const Button = MuiButton\r\nexport { useForm, useFormValues, Group, wrapInput }\r\n\r\nconst wrapped = (component, options, baseOptions) => wrapInput(\r\n base(component, options, baseOptions),\r\n { passErrorProp: true, ...options }\r\n)\r\n\r\nconst base = (component, options = {}, { alwaysShrinkLabel, shrinkLabel: shrinkLabelOption = true, passError } = {}) => (\r\n ({ className, error, hiddenLabel, variant, margin, label, helperText, shrinkLabel, valid, pattern, ...inputProps }) => {\r\n return (\r\n createElement(MuiFormControl, {\r\n className: `react-forms-material-field${options.type ? ` react-forms-material-${options.type}` : ''}${className ? ` ${className}` : ''}`,\r\n error,\r\n fullWidth: inputProps.fullWidth,\r\n hiddenLabel,\r\n required: inputProps.required,\r\n variant,\r\n margin,\r\n children: [\r\n ...(label ? [createElement(MuiInputLabel, {\r\n key: 'label',\r\n htmlFor: inputProps.id,\r\n children: label,\r\n ...(shrinkLabelOption === false && { shrink: false }),\r\n ...((alwaysShrinkLabel || shrinkLabel) && { className: 'MuiInputLabel-shrink' }),\r\n })] : []),\r\n\r\n createElement(component, {\r\n key: 'input',\r\n variant,\r\n ...(passError && { error }),\r\n ...inputProps,\r\n inputProps: { ...(pattern && { pattern }), ...inputProps.inputProps }\r\n }),\r\n\r\n ...(helperText ? [createElement(MuiFormHelperText, {\r\n key: 'helperText',\r\n children: helperText\r\n })] : [])\r\n ]\r\n })\r\n )\r\n }\r\n)\r\n\r\nexport const Input = wrapInput(MuiInput)\r\nexport const Text = wrapped(MuiInput)\r\nexport const Checkbox = wrapped(MuiCheckbox, { type: 'checkbox' }, { alwaysShrinkLabel: true })\r\nexport const RadioButton = wrapped(MuiRadio, { type: 'radio' }, { shrinkLabel: false })\r\n\r\nexport const Radio = createRawConsumer(base(\r\n ({ name, values, labels, numeric, required, getFieldValue, getFieldValues, inputProps, ...props }) => {\r\n return createElement(MuiRadioGroup, { ...props, children: [\r\n values.map((value, index) => {\r\n return createElement(RadioButton, {\r\n name,\r\n value,\r\n numeric,\r\n key: value,\r\n label: (labels && labels[index]) || value,\r\n margin: props.margin,\r\n ...(required && { required }),\r\n inputProps\r\n })\r\n })\r\n ] }\r\n )},\r\n { type: 'radiogroup' },\r\n { alwaysShrinkLabel: true }\r\n))\r\n\r\nexport const Select = wrapped(({ values, labels, ...props }) =>\r\n createElement(MuiSelect, { ...props, children:\r\n values.map((value, index) =>\r\n createElement(MuiMenuItem, {\r\n value,\r\n key: value,\r\n children: (labels && labels[index]) || value,\r\n ...(props.required && { required: props.required })\r\n })\r\n )\r\n }),\r\n { type: 'select' },\r\n { alwaysShrinkLabel: true }\r\n)\r\n\r\nexport const wrapField = wrapped"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,YAAA,GAAAF,sBAAA,CAAAJ,OAAA;AACA,IAAAO,eAAA,GAAAH,sBAAA,CAAAJ,OAAA;AACA,IAAAQ,MAAA,GAAAJ,sBAAA,CAAAJ,OAAA;AACA,IAAAS,WAAA,GAAAL,sBAAA,CAAAJ,OAAA;AACA,IAAAU,SAAA,GAAAN,sBAAA,CAAAJ,OAAA;AACA,IAAAW,MAAA,GAAAP,sBAAA,CAAAJ,OAAA;AACA,IAAAY,WAAA,GAAAR,sBAAA,CAAAJ,OAAA;AACA,IAAAa,OAAA,GAAAT,sBAAA,CAAAJ,OAAA;AACAA,OAAA;AAAiB,IAAAc,SAAA;EAAAC,UAAA;EAAAC,UAAA;AAAA,SAAAZ,uBAAAa,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA;AAAA,SAAAE,QAAAF,GAAA,sCAAAE,OAAA,wBAAAC,MAAA,uBAAAA,MAAA,CAAAC,QAAA,aAAAJ,GAAA,kBAAAA,GAAA,gBAAAA,GAAA,WAAAA,GAAA,yBAAAG,MAAA,IAAAH,GAAA,CAAAK,WAAA,KAAA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","_Button","_interopRequireDefault","_Checkbox","_FormControl","_FormHelperText","_Input","_InputLabel","_MenuItem","_Radio","_RadioGroup","_Select","_excluded","_excluded2","_excluded3","obj","__esModule","_typeof","o","Symbol","iterator","constructor","prototype","_toConsumableArray","arr","_arrayWithoutHoles","_iterableToArray","_unsupportedIterableToArray","_nonIterableSpread","TypeError","minLen","_arrayLikeToArray","n","Object","toString","call","slice","name","Array","from","test","iter","isArray","len","length","i","arr2","_objectWithoutProperties","source","excluded","target","_objectWithoutPropertiesLoose","key","getOwnPropertySymbols","sourceSymbolKeys","indexOf","propertyIsEnumerable","sourceKeys","keys","ownKeys","e","r","t","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","value","_toPropertyKey","configurable","writable","arg","_toPrimitive","String","input","hint","prim","toPrimitive","undefined","res","Number","ErrorMessage","exports","_ref","error","createElement","MuiFormHelperText","children","extractErrorMessage","Form","FormProvider","context","Provider","margin","Submit","wrapSubmit","MuiButton","Button","wrapped","component","options","baseOptions","wrapInput","base","passErrorProp","_ref2","alwaysShrinkLabel","_ref2$shrinkLabel","shrinkLabel","shrinkLabelOption","passError","_ref3","className","hiddenLabel","variant","label","helperText","valid","pattern","inputProps","MuiFormControl","concat","type","fullWidth","required","MuiInputLabel","htmlFor","id","shrink","Input","MuiInput","Text","Checkbox","MuiCheckbox","RadioButton","MuiRadio","Radio","createRawConsumer","_ref4","values","labels","numeric","getFieldValue","getFieldValues","props","MuiRadioGroup","map","index","Select","_ref5","MuiSelect","MuiMenuItem","wrapField"],"sources":["../src/index.js"],"sourcesContent":["import { createElement } from 'react'\nimport { FormProvider, Group, context, createRawConsumer, wrapInput, wrapSubmit, useForm, useFormValues } from '@danderson00/react-forms'\nimport { extractErrorMessage } from '@danderson00/react-forms/src/ErrorMessage'\nimport MuiButton from '@material-ui/core/Button'\nimport MuiCheckbox from '@material-ui/core/Checkbox'\nimport MuiFormControl from '@material-ui/core/FormControl'\nimport MuiFormHelperText from '@material-ui/core/FormHelperText'\nimport MuiInput from '@material-ui/core/Input'\nimport MuiInputLabel from '@material-ui/core/InputLabel'\nimport MuiMenuItem from '@material-ui/core/MenuItem'\nimport MuiRadio from '@material-ui/core/Radio'\nimport MuiRadioGroup from '@material-ui/core/RadioGroup'\nimport MuiSelect from '@material-ui/core/Select'\nimport './styles'\n\nexport const ErrorMessage = ({ error }) => createElement(MuiFormHelperText, { children: extractErrorMessage(error), error: true })\nexport const Form = FormProvider(context.Provider, { margin: 'dense' }, ErrorMessage)\nexport const Submit = wrapSubmit(MuiButton)\nexport const Button = MuiButton\nexport { useForm, useFormValues, Group, wrapInput, wrapSubmit }\n\nconst wrapped = (component, options, baseOptions) => wrapInput(\n base(component, options, baseOptions),\n { passErrorProp: true, ...options }\n)\n\nconst base = (component, options = {}, { alwaysShrinkLabel, shrinkLabel: shrinkLabelOption = true, passError } = {}) => (\n ({ className, error, hiddenLabel, variant, margin, label, helperText, shrinkLabel, valid, pattern, ...inputProps }) => {\n return (\n createElement(MuiFormControl, {\n className: `react-forms-material-field${options.type ? ` react-forms-material-${options.type}` : ''}${className ? ` ${className}` : ''}`,\n error,\n fullWidth: inputProps.fullWidth,\n hiddenLabel,\n required: inputProps.required,\n variant,\n margin,\n children: [\n ...(label ? [createElement(MuiInputLabel, {\n key: 'label',\n htmlFor: inputProps.id,\n children: label,\n ...(shrinkLabelOption === false && { shrink: false }),\n ...((alwaysShrinkLabel || shrinkLabel) && { className: 'MuiInputLabel-shrink' }),\n })] : []),\n\n createElement(component, {\n key: 'input',\n variant,\n ...(passError && { error }),\n ...inputProps,\n inputProps: { ...(pattern && { pattern }), ...inputProps.inputProps }\n }),\n\n ...(helperText ? [createElement(MuiFormHelperText, {\n key: 'helperText',\n children: helperText\n })] : [])\n ]\n })\n )\n }\n)\n\nexport const Input = wrapInput(MuiInput)\nexport const Text = wrapped(MuiInput)\nexport const Checkbox = wrapped(MuiCheckbox, { type: 'checkbox' }, { alwaysShrinkLabel: true })\nexport const RadioButton = wrapped(MuiRadio, { type: 'radio' }, { shrinkLabel: false })\n\nexport const Radio = createRawConsumer(base(\n ({ name, values, labels, numeric, required, getFieldValue, getFieldValues, inputProps, ...props }) => {\n return createElement(MuiRadioGroup, { ...props, children: [\n values.map((value, index) => {\n return createElement(RadioButton, {\n name,\n value,\n numeric,\n key: value,\n label: (labels && labels[index]) || value,\n margin: props.margin,\n ...(required && { required }),\n inputProps\n })\n })\n ] }\n )},\n { type: 'radiogroup' },\n { alwaysShrinkLabel: true }\n))\n\nexport const Select = wrapped(({ values, labels, ...props }) =>\n createElement(MuiSelect, { ...props, children:\n values.map((value, index) =>\n createElement(MuiMenuItem, {\n value,\n key: value,\n children: (labels && labels[index]) || value,\n ...(props.required && { required: props.required })\n })\n )\n }),\n { type: 'select' },\n { alwaysShrinkLabel: true }\n)\n\nexport const wrapField = wrapped\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,YAAA,GAAAF,sBAAA,CAAAJ,OAAA;AACA,IAAAO,eAAA,GAAAH,sBAAA,CAAAJ,OAAA;AACA,IAAAQ,MAAA,GAAAJ,sBAAA,CAAAJ,OAAA;AACA,IAAAS,WAAA,GAAAL,sBAAA,CAAAJ,OAAA;AACA,IAAAU,SAAA,GAAAN,sBAAA,CAAAJ,OAAA;AACA,IAAAW,MAAA,GAAAP,sBAAA,CAAAJ,OAAA;AACA,IAAAY,WAAA,GAAAR,sBAAA,CAAAJ,OAAA;AACA,IAAAa,OAAA,GAAAT,sBAAA,CAAAJ,OAAA;AACAA,OAAA;AAAiB,IAAAc,SAAA;EAAAC,UAA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EAAE;AAAM,CAC7B,CAAC;AAEM,IAAM8C,SAAS,GAAAtE,OAAA,CAAAsE,SAAA,GAAGtD,OAAO"}
|
package/dist/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","names":["_injectCss","_interopRequireDefault","require","obj","__esModule","injectCss"],"sources":["../src/styles.js"],"sourcesContent":["import injectCss from '@danderson00/react-forms/src/injectCss'\
|
|
1
|
+
{"version":3,"file":"styles.js","names":["_injectCss","_interopRequireDefault","require","obj","__esModule","injectCss"],"sources":["../src/styles.js"],"sourcesContent":["import injectCss from '@danderson00/react-forms/src/injectCss'\n\ninjectCss('react-forms-material-styles', `\n .react-forms-material-radiogroup.MuiFormControl-root {\n overflow: hidden;\n }\n\n .react-forms-material-radio.MuiFormControl-root {\n flex-direction: row-reverse;\n justify-content: flex-end;\n }\n \n .react-forms-material-radio .MuiInputLabel-formControl {\n position: static;\n }\n\n .react-forms-material-radio .MuiRadio-root {\n transform: translate(0, 9px) scale(1);\n } \n \n .react-forms-material-checkbox .MuiCheckbox-root {\n transform: translate(0, 9px) scale(1);\n }\n \n /* allow forms to be embedded in dialogs - essentially replicate a few styles */\n .MuiDialog-container form {\n display: flex;\n }\n \n .MuiDialog-container form .MuiDialogContent-root {\n display: flex;\n align-items: flex-start;\n flex-direction: column;\n }\n\n .MuiDialog-container form .MuiDialogActions-root {\n align-self: flex-end;\n }\n \n .react-forms input::-webkit-outer-spin-button,\n .react-forms input::-webkit-inner-spin-button {\n -webkit-appearance: none;\n margin: 0;\n }\n\n .react-forms input[type=number] {\n -moz-appearance: textfield;\n }\n`)\n\n\n"],"mappings":";;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8D,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA;AAE9D,IAAAE,qBAAS,EAAC,6BAA6B,smCA8CtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@danderson00/react-forms-material",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Beautiful, ultra simple, stateless, validated forms for use in React function components",
|
|
5
|
-
"main": "src/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "jest",
|
|
8
|
-
"build": "babel src --source-maps --out-dir dist",
|
|
9
|
-
"prepare": "babel src --source-maps --out-dir dist"
|
|
10
|
-
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"@danderson00/react-forms": "0.0.
|
|
13
|
-
"@material-ui/core": "^4.11.3"
|
|
14
|
-
},
|
|
15
|
-
"peerDependencies": {
|
|
16
|
-
"react": "*"
|
|
17
|
-
},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@babel/cli": "^7.4.4",
|
|
20
|
-
"@babel/core": "^7.4.4",
|
|
21
|
-
"@babel/preset-env": "^7.4.4",
|
|
22
|
-
"@babel/preset-react": "^7.0.0",
|
|
23
|
-
"babel-jest": "26.6.3",
|
|
24
|
-
"enzyme": "^3.9.0",
|
|
25
|
-
"enzyme-adapter-react-16": "^1.9.1",
|
|
26
|
-
"jest": "26.6.3",
|
|
27
|
-
"react": "^18.2.0",
|
|
28
|
-
"react-dom": "^18.2.0"
|
|
29
|
-
},
|
|
30
|
-
"jest": {
|
|
31
|
-
"moduleNameMapper": {
|
|
32
|
-
"\\.css$": "<rootDir>/test/setup/styleMock.js"
|
|
33
|
-
},
|
|
34
|
-
"setupFilesAfterEnv": [
|
|
35
|
-
"<rootDir>test/setup/beforeAll.js"
|
|
36
|
-
]
|
|
37
|
-
},
|
|
38
|
-
"babel": {
|
|
39
|
-
"presets": [
|
|
40
|
-
"@babel/preset-env",
|
|
41
|
-
"@babel/preset-react"
|
|
42
|
-
]
|
|
43
|
-
},
|
|
44
|
-
"keywords": [
|
|
45
|
-
"react",
|
|
46
|
-
"stateless",
|
|
47
|
-
"form",
|
|
48
|
-
"function",
|
|
49
|
-
"component",
|
|
50
|
-
"material",
|
|
51
|
-
"ui"
|
|
52
|
-
],
|
|
53
|
-
"author": "danderson00",
|
|
54
|
-
"license": "MIT",
|
|
55
|
-
"publishConfig": {
|
|
56
|
-
"access": "public"
|
|
57
|
-
},
|
|
58
|
-
"repository": {
|
|
59
|
-
"type": "git",
|
|
60
|
-
"url": "git+https://gitlab.com/danderson00/react-forms.git"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@danderson00/react-forms-material",
|
|
3
|
+
"version": "0.0.49",
|
|
4
|
+
"description": "Beautiful, ultra simple, stateless, validated forms for use in React function components",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"build": "babel src --source-maps --out-dir dist",
|
|
9
|
+
"prepare": "babel src --source-maps --out-dir dist"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@danderson00/react-forms": "0.0.49",
|
|
13
|
+
"@material-ui/core": "^4.11.3"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": "*"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@babel/cli": "^7.4.4",
|
|
20
|
+
"@babel/core": "^7.4.4",
|
|
21
|
+
"@babel/preset-env": "^7.4.4",
|
|
22
|
+
"@babel/preset-react": "^7.0.0",
|
|
23
|
+
"babel-jest": "26.6.3",
|
|
24
|
+
"enzyme": "^3.9.0",
|
|
25
|
+
"enzyme-adapter-react-16": "^1.9.1",
|
|
26
|
+
"jest": "26.6.3",
|
|
27
|
+
"react": "^18.2.0",
|
|
28
|
+
"react-dom": "^18.2.0"
|
|
29
|
+
},
|
|
30
|
+
"jest": {
|
|
31
|
+
"moduleNameMapper": {
|
|
32
|
+
"\\.css$": "<rootDir>/test/setup/styleMock.js"
|
|
33
|
+
},
|
|
34
|
+
"setupFilesAfterEnv": [
|
|
35
|
+
"<rootDir>test/setup/beforeAll.js"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"babel": {
|
|
39
|
+
"presets": [
|
|
40
|
+
"@babel/preset-env",
|
|
41
|
+
"@babel/preset-react"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"react",
|
|
46
|
+
"stateless",
|
|
47
|
+
"form",
|
|
48
|
+
"function",
|
|
49
|
+
"component",
|
|
50
|
+
"material",
|
|
51
|
+
"ui"
|
|
52
|
+
],
|
|
53
|
+
"author": "danderson00",
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://gitlab.com/danderson00/react-forms.git"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import { createElement } from 'react'
|
|
2
|
-
import { FormProvider, Group, context, createRawConsumer, wrapInput, wrapSubmit, useForm, useFormValues } from '@danderson00/react-forms'
|
|
3
|
-
import { extractErrorMessage } from '@danderson00/react-forms/src/ErrorMessage'
|
|
4
|
-
import MuiButton from '@material-ui/core/Button'
|
|
5
|
-
import MuiCheckbox from '@material-ui/core/Checkbox'
|
|
6
|
-
import MuiFormControl from '@material-ui/core/FormControl'
|
|
7
|
-
import MuiFormHelperText from '@material-ui/core/FormHelperText'
|
|
8
|
-
import MuiInput from '@material-ui/core/Input'
|
|
9
|
-
import MuiInputLabel from '@material-ui/core/InputLabel'
|
|
10
|
-
import MuiMenuItem from '@material-ui/core/MenuItem'
|
|
11
|
-
import MuiRadio from '@material-ui/core/Radio'
|
|
12
|
-
import MuiRadioGroup from '@material-ui/core/RadioGroup'
|
|
13
|
-
import MuiSelect from '@material-ui/core/Select'
|
|
14
|
-
import './styles'
|
|
15
|
-
|
|
16
|
-
export const ErrorMessage = ({ error }) => createElement(MuiFormHelperText, { children: extractErrorMessage(error), error: true })
|
|
17
|
-
export const Form = FormProvider(context.Provider, { margin: 'dense' }, ErrorMessage)
|
|
18
|
-
export const Submit = wrapSubmit(MuiButton)
|
|
19
|
-
export const Button = MuiButton
|
|
20
|
-
export { useForm, useFormValues, Group, wrapInput }
|
|
21
|
-
|
|
22
|
-
const wrapped = (component, options, baseOptions) => wrapInput(
|
|
23
|
-
base(component, options, baseOptions),
|
|
24
|
-
{ passErrorProp: true, ...options }
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
const base = (component, options = {}, { alwaysShrinkLabel, shrinkLabel: shrinkLabelOption = true, passError } = {}) => (
|
|
28
|
-
({ className, error, hiddenLabel, variant, margin, label, helperText, shrinkLabel, valid, pattern, ...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
|
-
})] : []),
|
|
46
|
-
|
|
47
|
-
createElement(component, {
|
|
48
|
-
key: 'input',
|
|
49
|
-
variant,
|
|
50
|
-
...(passError && { error }),
|
|
51
|
-
...inputProps,
|
|
52
|
-
inputProps: { ...(pattern && { pattern }), ...inputProps.inputProps }
|
|
53
|
-
}),
|
|
54
|
-
|
|
55
|
-
...(helperText ? [createElement(MuiFormHelperText, {
|
|
56
|
-
key: 'helperText',
|
|
57
|
-
children: helperText
|
|
58
|
-
})] : [])
|
|
59
|
-
]
|
|
60
|
-
})
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
export const Input = wrapInput(MuiInput)
|
|
66
|
-
export const Text = wrapped(MuiInput)
|
|
67
|
-
export const Checkbox = wrapped(MuiCheckbox, { type: 'checkbox' }, { alwaysShrinkLabel: true })
|
|
68
|
-
export const RadioButton = wrapped(MuiRadio, { type: 'radio' }, { shrinkLabel: false })
|
|
69
|
-
|
|
70
|
-
export const Radio = createRawConsumer(base(
|
|
71
|
-
({ name, values, labels, numeric, required, getFieldValue, getFieldValues, inputProps, ...props }) => {
|
|
72
|
-
return createElement(MuiRadioGroup, { ...props, children: [
|
|
73
|
-
values.map((value, index) => {
|
|
74
|
-
return createElement(RadioButton, {
|
|
75
|
-
name,
|
|
76
|
-
value,
|
|
77
|
-
numeric,
|
|
78
|
-
key: value,
|
|
79
|
-
label: (labels && labels[index]) || value,
|
|
80
|
-
margin: props.margin,
|
|
81
|
-
...(required && { required }),
|
|
82
|
-
inputProps
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
] }
|
|
86
|
-
)},
|
|
87
|
-
{ type: 'radiogroup' },
|
|
88
|
-
{ alwaysShrinkLabel: true }
|
|
89
|
-
))
|
|
90
|
-
|
|
91
|
-
export const Select = wrapped(({ values, labels, ...props }) =>
|
|
92
|
-
createElement(MuiSelect, { ...props, children:
|
|
93
|
-
values.map((value, index) =>
|
|
94
|
-
createElement(MuiMenuItem, {
|
|
95
|
-
value,
|
|
96
|
-
key: value,
|
|
97
|
-
children: (labels && labels[index]) || value,
|
|
98
|
-
...(props.required && { required: props.required })
|
|
99
|
-
})
|
|
100
|
-
)
|
|
101
|
-
}),
|
|
102
|
-
{ type: 'select' },
|
|
103
|
-
{ alwaysShrinkLabel: true }
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
export const wrapField = wrapped
|
|
1
|
+
import { createElement } from 'react'
|
|
2
|
+
import { FormProvider, Group, context, createRawConsumer, wrapInput, wrapSubmit, useForm, useFormValues } from '@danderson00/react-forms'
|
|
3
|
+
import { extractErrorMessage } from '@danderson00/react-forms/src/ErrorMessage'
|
|
4
|
+
import MuiButton from '@material-ui/core/Button'
|
|
5
|
+
import MuiCheckbox from '@material-ui/core/Checkbox'
|
|
6
|
+
import MuiFormControl from '@material-ui/core/FormControl'
|
|
7
|
+
import MuiFormHelperText from '@material-ui/core/FormHelperText'
|
|
8
|
+
import MuiInput from '@material-ui/core/Input'
|
|
9
|
+
import MuiInputLabel from '@material-ui/core/InputLabel'
|
|
10
|
+
import MuiMenuItem from '@material-ui/core/MenuItem'
|
|
11
|
+
import MuiRadio from '@material-ui/core/Radio'
|
|
12
|
+
import MuiRadioGroup from '@material-ui/core/RadioGroup'
|
|
13
|
+
import MuiSelect from '@material-ui/core/Select'
|
|
14
|
+
import './styles'
|
|
15
|
+
|
|
16
|
+
export const ErrorMessage = ({ error }) => createElement(MuiFormHelperText, { children: extractErrorMessage(error), error: true })
|
|
17
|
+
export const Form = FormProvider(context.Provider, { margin: 'dense' }, ErrorMessage)
|
|
18
|
+
export const Submit = wrapSubmit(MuiButton)
|
|
19
|
+
export const Button = MuiButton
|
|
20
|
+
export { useForm, useFormValues, Group, wrapInput, wrapSubmit }
|
|
21
|
+
|
|
22
|
+
const wrapped = (component, options, baseOptions) => wrapInput(
|
|
23
|
+
base(component, options, baseOptions),
|
|
24
|
+
{ passErrorProp: true, ...options }
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const base = (component, options = {}, { alwaysShrinkLabel, shrinkLabel: shrinkLabelOption = true, passError } = {}) => (
|
|
28
|
+
({ className, error, hiddenLabel, variant, margin, label, helperText, shrinkLabel, valid, pattern, ...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
|
+
})] : []),
|
|
46
|
+
|
|
47
|
+
createElement(component, {
|
|
48
|
+
key: 'input',
|
|
49
|
+
variant,
|
|
50
|
+
...(passError && { error }),
|
|
51
|
+
...inputProps,
|
|
52
|
+
inputProps: { ...(pattern && { pattern }), ...inputProps.inputProps }
|
|
53
|
+
}),
|
|
54
|
+
|
|
55
|
+
...(helperText ? [createElement(MuiFormHelperText, {
|
|
56
|
+
key: 'helperText',
|
|
57
|
+
children: helperText
|
|
58
|
+
})] : [])
|
|
59
|
+
]
|
|
60
|
+
})
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
export const Input = wrapInput(MuiInput)
|
|
66
|
+
export const Text = wrapped(MuiInput)
|
|
67
|
+
export const Checkbox = wrapped(MuiCheckbox, { type: 'checkbox' }, { alwaysShrinkLabel: true })
|
|
68
|
+
export const RadioButton = wrapped(MuiRadio, { type: 'radio' }, { shrinkLabel: false })
|
|
69
|
+
|
|
70
|
+
export const Radio = createRawConsumer(base(
|
|
71
|
+
({ name, values, labels, numeric, required, getFieldValue, getFieldValues, inputProps, ...props }) => {
|
|
72
|
+
return createElement(MuiRadioGroup, { ...props, children: [
|
|
73
|
+
values.map((value, index) => {
|
|
74
|
+
return createElement(RadioButton, {
|
|
75
|
+
name,
|
|
76
|
+
value,
|
|
77
|
+
numeric,
|
|
78
|
+
key: value,
|
|
79
|
+
label: (labels && labels[index]) || value,
|
|
80
|
+
margin: props.margin,
|
|
81
|
+
...(required && { required }),
|
|
82
|
+
inputProps
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
] }
|
|
86
|
+
)},
|
|
87
|
+
{ type: 'radiogroup' },
|
|
88
|
+
{ alwaysShrinkLabel: true }
|
|
89
|
+
))
|
|
90
|
+
|
|
91
|
+
export const Select = wrapped(({ values, labels, ...props }) =>
|
|
92
|
+
createElement(MuiSelect, { ...props, children:
|
|
93
|
+
values.map((value, index) =>
|
|
94
|
+
createElement(MuiMenuItem, {
|
|
95
|
+
value,
|
|
96
|
+
key: value,
|
|
97
|
+
children: (labels && labels[index]) || value,
|
|
98
|
+
...(props.required && { required: props.required })
|
|
99
|
+
})
|
|
100
|
+
)
|
|
101
|
+
}),
|
|
102
|
+
{ type: 'select' },
|
|
103
|
+
{ alwaysShrinkLabel: true }
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
export const wrapField = wrapped
|
package/src/styles.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import injectCss from '@danderson00/react-forms/src/injectCss'
|
|
2
|
-
|
|
3
|
-
injectCss('react-forms-material-styles', `
|
|
4
|
-
.react-forms-material-radiogroup.MuiFormControl-root {
|
|
5
|
-
overflow: hidden;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.react-forms-material-radio.MuiFormControl-root {
|
|
9
|
-
flex-direction: row-reverse;
|
|
10
|
-
justify-content: flex-end;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.react-forms-material-radio .MuiInputLabel-formControl {
|
|
14
|
-
position: static;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.react-forms-material-radio .MuiRadio-root {
|
|
18
|
-
transform: translate(0, 9px) scale(1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.react-forms-material-checkbox .MuiCheckbox-root {
|
|
22
|
-
transform: translate(0, 9px) scale(1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/* allow forms to be embedded in dialogs - essentially replicate a few styles */
|
|
26
|
-
.MuiDialog-container form {
|
|
27
|
-
display: flex;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.MuiDialog-container form .MuiDialogContent-root {
|
|
31
|
-
display: flex;
|
|
32
|
-
align-items: flex-start;
|
|
33
|
-
flex-direction: column;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.MuiDialog-container form .MuiDialogActions-root {
|
|
37
|
-
align-self: flex-end;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.react-forms input::-webkit-outer-spin-button,
|
|
41
|
-
.react-forms input::-webkit-inner-spin-button {
|
|
42
|
-
-webkit-appearance: none;
|
|
43
|
-
margin: 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.react-forms input[type=number] {
|
|
47
|
-
-moz-appearance: textfield;
|
|
48
|
-
}
|
|
49
|
-
`)
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
import injectCss from '@danderson00/react-forms/src/injectCss'
|
|
2
|
+
|
|
3
|
+
injectCss('react-forms-material-styles', `
|
|
4
|
+
.react-forms-material-radiogroup.MuiFormControl-root {
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.react-forms-material-radio.MuiFormControl-root {
|
|
9
|
+
flex-direction: row-reverse;
|
|
10
|
+
justify-content: flex-end;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.react-forms-material-radio .MuiInputLabel-formControl {
|
|
14
|
+
position: static;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.react-forms-material-radio .MuiRadio-root {
|
|
18
|
+
transform: translate(0, 9px) scale(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.react-forms-material-checkbox .MuiCheckbox-root {
|
|
22
|
+
transform: translate(0, 9px) scale(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* allow forms to be embedded in dialogs - essentially replicate a few styles */
|
|
26
|
+
.MuiDialog-container form {
|
|
27
|
+
display: flex;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.MuiDialog-container form .MuiDialogContent-root {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: flex-start;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.MuiDialog-container form .MuiDialogActions-root {
|
|
37
|
+
align-self: flex-end;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.react-forms input::-webkit-outer-spin-button,
|
|
41
|
+
.react-forms input::-webkit-inner-spin-button {
|
|
42
|
+
-webkit-appearance: none;
|
|
43
|
+
margin: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.react-forms input[type=number] {
|
|
47
|
+
-moz-appearance: textfield;
|
|
48
|
+
}
|
|
49
|
+
`)
|
|
50
|
+
|
|
51
|
+
|