@danderson00/react-forms-material 0.0.16 → 0.0.20

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.
Files changed (3) hide show
  1. package/dist/index.js +39 -21
  2. package/package.json +3 -3
  3. package/src/index.js +26 -15
package/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- 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); }
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -12,6 +10,7 @@ Object.defineProperty(exports, "useFormValues", {
12
10
  return _reactForms.useFormValues;
13
11
  }
14
12
  });
13
+ exports.wrapField = void 0;
15
14
 
16
15
  var _react = require("react");
17
16
 
@@ -19,17 +18,33 @@ var _reactForms = require("@danderson00/react-forms");
19
18
 
20
19
  var _ErrorMessage = require("@danderson00/react-forms/dist/ErrorMessage");
21
20
 
22
- var core = _interopRequireWildcard(require("@material-ui/core"));
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"));
23
40
 
24
41
  require("./styles");
25
42
 
26
- var _excluded = ["className", "error", "hiddenLabel", "variant", "margin", "label", "helperText", "shrinkLabel"],
43
+ var _excluded = ["className", "error", "hiddenLabel", "variant", "margin", "label", "helperText", "shrinkLabel", "valid"],
27
44
  _excluded2 = ["name", "values", "labels", "numeric", "required", "getFieldValue", "getFieldValues"],
28
45
  _excluded3 = ["values", "labels"];
29
46
 
30
- 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); }
31
-
32
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
47
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
33
48
 
34
49
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
35
50
 
@@ -55,7 +70,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
55
70
 
56
71
  var ErrorMessage = function ErrorMessage(_ref) {
57
72
  var error = _ref.error;
58
- return /*#__PURE__*/(0, _react.createElement)(core.FormHelperText, {
73
+ return /*#__PURE__*/(0, _react.createElement)(_FormHelperText["default"], {
59
74
  children: (0, _ErrorMessage.extractErrorMessage)(error),
60
75
  error: true
61
76
  });
@@ -66,9 +81,9 @@ var Form = (0, _reactForms.FormProvider)(_reactForms.context.Provider, {
66
81
  margin: 'dense'
67
82
  }, ErrorMessage);
68
83
  exports.Form = Form;
69
- var Submit = (0, _reactForms.wrapSubmit)(core.Button);
84
+ var Submit = (0, _reactForms.wrapSubmit)(_Button["default"]);
70
85
  exports.Submit = Submit;
71
- var Button = core.Button;
86
+ var Button = _Button["default"];
72
87
  exports.Button = Button;
73
88
 
74
89
  var wrapped = function wrapped(component, options, baseOptions) {
@@ -94,9 +109,10 @@ var base = function base(component) {
94
109
  label = _ref3.label,
95
110
  helperText = _ref3.helperText,
96
111
  shrinkLabel = _ref3.shrinkLabel,
112
+ valid = _ref3.valid,
97
113
  inputProps = _objectWithoutProperties(_ref3, _excluded);
98
114
 
99
- return /*#__PURE__*/(0, _react.createElement)(core.FormControl, {
115
+ return /*#__PURE__*/(0, _react.createElement)(_FormControl["default"], {
100
116
  className: "react-forms-material-field".concat(options.type ? " react-forms-material-".concat(options.type) : '').concat(className ? " ".concat(className) : ''),
101
117
  error: error,
102
118
  fullWidth: inputProps.fullWidth,
@@ -104,7 +120,7 @@ var base = function base(component) {
104
120
  required: inputProps.required,
105
121
  variant: variant,
106
122
  margin: margin,
107
- children: [].concat(_toConsumableArray(label ? [/*#__PURE__*/(0, _react.createElement)(core.InputLabel, _objectSpread(_objectSpread({
123
+ children: [].concat(_toConsumableArray(label ? [/*#__PURE__*/(0, _react.createElement)(_InputLabel["default"], _objectSpread(_objectSpread({
108
124
  key: 'label',
109
125
  htmlFor: inputProps.id,
110
126
  children: label
@@ -114,7 +130,7 @@ var base = function base(component) {
114
130
  className: 'MuiInputLabel-shrink'
115
131
  }))] : []), [/*#__PURE__*/(0, _react.createElement)(component, _objectSpread({
116
132
  key: 'input'
117
- }, inputProps))], _toConsumableArray(helperText ? [/*#__PURE__*/(0, _react.createElement)(core.FormHelperText, {
133
+ }, inputProps))], _toConsumableArray(helperText ? [/*#__PURE__*/(0, _react.createElement)(_FormHelperText["default"], {
118
134
  key: 'helperText',
119
135
  children: helperText
120
136
  })] : []))
@@ -122,17 +138,17 @@ var base = function base(component) {
122
138
  };
123
139
  };
124
140
 
125
- var Input = (0, _reactForms.wrapInput)(core.Input);
141
+ var Input = (0, _reactForms.wrapInput)(_Input["default"]);
126
142
  exports.Input = Input;
127
- var Text = wrapped(core.Input);
143
+ var Text = wrapped(_Input["default"]);
128
144
  exports.Text = Text;
129
- var Checkbox = wrapped(core.Checkbox, {
145
+ var Checkbox = wrapped(_Checkbox["default"], {
130
146
  type: 'checkbox'
131
147
  }, {
132
148
  alwaysShrinkLabel: true
133
149
  });
134
150
  exports.Checkbox = Checkbox;
135
- var RadioButton = wrapped(core.Radio, {
151
+ var RadioButton = wrapped(_Radio["default"], {
136
152
  type: 'radio'
137
153
  }, {
138
154
  shrinkLabel: false
@@ -148,7 +164,7 @@ var Radio = (0, _reactForms.createRawConsumer)(base(function (_ref4) {
148
164
  getFieldValues = _ref4.getFieldValues,
149
165
  props = _objectWithoutProperties(_ref4, _excluded2);
150
166
 
151
- return /*#__PURE__*/(0, _react.createElement)(core.RadioGroup, _objectSpread(_objectSpread({}, props), {}, {
167
+ return /*#__PURE__*/(0, _react.createElement)(_RadioGroup["default"], _objectSpread(_objectSpread({}, props), {}, {
152
168
  children: [values.map(function (value, index) {
153
169
  return /*#__PURE__*/(0, _react.createElement)(RadioButton, _objectSpread({
154
170
  name: name,
@@ -173,9 +189,9 @@ var Select = wrapped(function (_ref5) {
173
189
  labels = _ref5.labels,
174
190
  props = _objectWithoutProperties(_ref5, _excluded3);
175
191
 
176
- return /*#__PURE__*/(0, _react.createElement)(core.Select, _objectSpread(_objectSpread({}, props), {}, {
192
+ return /*#__PURE__*/(0, _react.createElement)(_Select["default"], _objectSpread(_objectSpread({}, props), {}, {
177
193
  children: values.map(function (value, index) {
178
- return /*#__PURE__*/(0, _react.createElement)(core.MenuItem, _objectSpread({
194
+ return /*#__PURE__*/(0, _react.createElement)(_MenuItem["default"], _objectSpread({
179
195
  value: value,
180
196
  key: value,
181
197
  children: labels && labels[index] || value
@@ -189,4 +205,6 @@ var Select = wrapped(function (_ref5) {
189
205
  }, {
190
206
  alwaysShrinkLabel: true
191
207
  });
192
- exports.Select = Select;
208
+ exports.Select = Select;
209
+ var wrapField = wrapped;
210
+ exports.wrapField = wrapField;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danderson00/react-forms-material",
3
- "version": "0.0.16",
3
+ "version": "0.0.20",
4
4
  "description": "Beautiful, ultra simple, stateless, validated forms for use in React function components",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
@@ -10,7 +10,7 @@
10
10
  "prepare": "babel src --source-maps false --out-dir dist"
11
11
  },
12
12
  "dependencies": {
13
- "@danderson00/react-forms": "0.0.16",
13
+ "@danderson00/react-forms": "0.0.20",
14
14
  "@material-ui/core": "^4.11.3"
15
15
  },
16
16
  "peerDependencies": {
@@ -52,7 +52,7 @@
52
52
  "ui"
53
53
  ],
54
54
  "author": "danderson00",
55
- "license": "UNLICENSED",
55
+ "license": "MIT",
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
package/src/index.js CHANGED
@@ -1,13 +1,22 @@
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 * as core from '@material-ui/core'
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'
5
14
  import './styles'
6
15
 
7
- export const ErrorMessage = ({ error }) => createElement(core.FormHelperText, { children: extractErrorMessage(error), error: true })
16
+ export const ErrorMessage = ({ error }) => createElement(MuiFormHelperText, { children: extractErrorMessage(error), error: true })
8
17
  export const Form = FormProvider(context.Provider, { margin: 'dense' }, ErrorMessage)
9
- export const Submit = wrapSubmit(core.Button)
10
- export const Button = core.Button
18
+ export const Submit = wrapSubmit(MuiButton)
19
+ export const Button = MuiButton
11
20
  export { useFormValues }
12
21
 
13
22
  const wrapped = (component, options, baseOptions) => wrapInput(
@@ -16,8 +25,8 @@ const wrapped = (component, options, baseOptions) => wrapInput(
16
25
  )
17
26
 
18
27
  const base = (component, options = {}, { alwaysShrinkLabel, shrinkLabel: shrinkLabelOption = true } = {}) => (
19
- ({ className, error, hiddenLabel, variant, margin, label, helperText, shrinkLabel, ...inputProps }) => (
20
- createElement(core.FormControl, {
28
+ ({ className, error, hiddenLabel, variant, margin, label, helperText, shrinkLabel, valid, ...inputProps }) => (
29
+ createElement(MuiFormControl, {
21
30
  className: `react-forms-material-field${options.type ? ` react-forms-material-${options.type}` : ''}${className ? ` ${className}` : ''}`,
22
31
  error,
23
32
  fullWidth: inputProps.fullWidth,
@@ -26,7 +35,7 @@ const base = (component, options = {}, { alwaysShrinkLabel, shrinkLabel: shrinkL
26
35
  variant,
27
36
  margin,
28
37
  children: [
29
- ...(label ? [createElement(core.InputLabel, {
38
+ ...(label ? [createElement(MuiInputLabel, {
30
39
  key: 'label',
31
40
  htmlFor: inputProps.id,
32
41
  children: label,
@@ -36,7 +45,7 @@ const base = (component, options = {}, { alwaysShrinkLabel, shrinkLabel: shrinkL
36
45
 
37
46
  createElement(component, { key: 'input', ...inputProps }),
38
47
 
39
- ...(helperText ? [createElement(core.FormHelperText, {
48
+ ...(helperText ? [createElement(MuiFormHelperText, {
40
49
  key: 'helperText',
41
50
  children: helperText
42
51
  })] : [])
@@ -45,14 +54,14 @@ const base = (component, options = {}, { alwaysShrinkLabel, shrinkLabel: shrinkL
45
54
  )
46
55
  )
47
56
 
48
- export const Input = wrapInput(core.Input)
49
- export const Text = wrapped(core.Input)
50
- export const Checkbox = wrapped(core.Checkbox, { type: 'checkbox' }, { alwaysShrinkLabel: true })
51
- export const RadioButton = wrapped(core.Radio, { type: 'radio' }, { shrinkLabel: false })
57
+ export const Input = wrapInput(MuiInput)
58
+ export const Text = wrapped(MuiInput)
59
+ export const Checkbox = wrapped(MuiCheckbox, { type: 'checkbox' }, { alwaysShrinkLabel: true })
60
+ export const RadioButton = wrapped(MuiRadio, { type: 'radio' }, { shrinkLabel: false })
52
61
 
53
62
  export const Radio = createRawConsumer(base(
54
63
  ({ name, values, labels, numeric, required, getFieldValue, getFieldValues, ...props }) => (
55
- createElement(core.RadioGroup, { ...props, children: [
64
+ createElement(MuiRadioGroup, { ...props, children: [
56
65
  values.map((value, index) =>
57
66
  createElement(RadioButton, {
58
67
  name,
@@ -71,9 +80,9 @@ export const Radio = createRawConsumer(base(
71
80
  ))
72
81
 
73
82
  export const Select = wrapped(({ values, labels, ...props }) =>
74
- createElement(core.Select, { ...props, children:
83
+ createElement(MuiSelect, { ...props, children:
75
84
  values.map((value, index) =>
76
- createElement(core.MenuItem, {
85
+ createElement(MuiMenuItem, {
77
86
  value,
78
87
  key: value,
79
88
  children: (labels && labels[index]) || value,
@@ -84,3 +93,5 @@ export const Select = wrapped(({ values, labels, ...props }) =>
84
93
  { type: 'select' },
85
94
  { alwaysShrinkLabel: true }
86
95
  )
96
+
97
+ export const wrapField = wrapped