@danderson00/react-forms-material 0.0.44 → 0.0.45
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 +9 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.js +42 -39
package/dist/index.js
CHANGED
|
@@ -45,9 +45,10 @@ var _RadioGroup = _interopRequireDefault(require("@material-ui/core/RadioGroup")
|
|
|
45
45
|
var _Select = _interopRequireDefault(require("@material-ui/core/Select"));
|
|
46
46
|
require("./styles");
|
|
47
47
|
var _excluded = ["className", "error", "hiddenLabel", "variant", "margin", "label", "helperText", "shrinkLabel", "valid", "pattern"],
|
|
48
|
-
_excluded2 = ["name", "values", "labels", "numeric", "required", "getFieldValue", "getFieldValues"],
|
|
48
|
+
_excluded2 = ["name", "values", "labels", "numeric", "required", "getFieldValue", "getFieldValues", "inputProps"],
|
|
49
49
|
_excluded3 = ["values", "labels"];
|
|
50
50
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
51
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
51
52
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
52
53
|
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."); }
|
|
53
54
|
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); }
|
|
@@ -58,7 +59,9 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
58
59
|
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; }
|
|
59
60
|
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; }
|
|
60
61
|
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; }
|
|
61
|
-
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; }
|
|
62
|
+
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
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
64
|
+
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); }
|
|
62
65
|
var ErrorMessage = function ErrorMessage(_ref) {
|
|
63
66
|
var error = _ref.error;
|
|
64
67
|
return /*#__PURE__*/(0, _react.createElement)(_FormHelperText["default"], {
|
|
@@ -155,10 +158,11 @@ var Radio = (0, _reactForms.createRawConsumer)(base(function (_ref4) {
|
|
|
155
158
|
required = _ref4.required,
|
|
156
159
|
getFieldValue = _ref4.getFieldValue,
|
|
157
160
|
getFieldValues = _ref4.getFieldValues,
|
|
161
|
+
inputProps = _ref4.inputProps,
|
|
158
162
|
props = _objectWithoutProperties(_ref4, _excluded2);
|
|
159
163
|
return /*#__PURE__*/(0, _react.createElement)(_RadioGroup["default"], _objectSpread(_objectSpread({}, props), {}, {
|
|
160
164
|
children: [values.map(function (value, index) {
|
|
161
|
-
return /*#__PURE__*/(0, _react.createElement)(RadioButton, _objectSpread({
|
|
165
|
+
return /*#__PURE__*/(0, _react.createElement)(RadioButton, _objectSpread(_objectSpread({
|
|
162
166
|
name: name,
|
|
163
167
|
value: value,
|
|
164
168
|
numeric: numeric,
|
|
@@ -167,6 +171,8 @@ var Radio = (0, _reactForms.createRawConsumer)(base(function (_ref4) {
|
|
|
167
171
|
margin: props.margin
|
|
168
172
|
}, required && {
|
|
169
173
|
required: required
|
|
174
|
+
}), {}, {
|
|
175
|
+
inputProps: inputProps
|
|
170
176
|
}));
|
|
171
177
|
})]
|
|
172
178
|
}));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ErrorMessage","error","createElement","MuiFormHelperText","children","extractErrorMessage","Form","FormProvider","context","Provider","margin","Submit","wrapSubmit","MuiButton","Button","wrapped","component","options","baseOptions","wrapInput","base","passErrorProp","alwaysShrinkLabel","shrinkLabel","shrinkLabelOption","passError","className","hiddenLabel","variant","label","helperText","valid","pattern","inputProps","MuiFormControl","type","fullWidth","required","MuiInputLabel","key","htmlFor","id","shrink","Input","MuiInput","Text","Checkbox","MuiCheckbox","RadioButton","MuiRadio","Radio","createRawConsumer","name","values","labels","numeric","getFieldValue","getFieldValues","props","MuiRadioGroup","map","value","index","Select","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/dist/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 }\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
|
|
1
|
+
{"version":3,"file":"index.js","names":["ErrorMessage","error","createElement","MuiFormHelperText","children","extractErrorMessage","Form","FormProvider","context","Provider","margin","Submit","wrapSubmit","MuiButton","Button","wrapped","component","options","baseOptions","wrapInput","base","passErrorProp","alwaysShrinkLabel","shrinkLabel","shrinkLabelOption","passError","className","hiddenLabel","variant","label","helperText","valid","pattern","inputProps","MuiFormControl","type","fullWidth","required","MuiInputLabel","key","htmlFor","id","shrink","Input","MuiInput","Text","Checkbox","MuiCheckbox","RadioButton","MuiRadio","Radio","createRawConsumer","name","values","labels","numeric","getFieldValue","getFieldValues","props","MuiRadioGroup","map","value","index","Select","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/dist/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 }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAiB;EAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEV,IAAMA,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M,GAAGhD,OAAO,CAAC;EAAA,IAAGsC,MAAM,SAANA,MAAM;IAAEC,MAAM,SAANA,MAAM;IAAKI,KAAK;EAAA,oBACvD,IAAAxD,oBAAa,EAAC8D,kBAAS,kCAAON,KAAK;IAAEtD,QAAQ,EAC3CiD,MAAM,CAACO,GAAG,CAAC,UAACC,KAAK,EAAEC,KAAK;MAAA,oBACtB,IAAA5D,oBAAa,EAAC+D,oBAAW;QACvBJ,KAAK,EAALA,KAAK;QACLtB,GAAG,EAAEsB,KAAK;QACVzD,QAAQ,EAAGkD,MAAM,IAAIA,MAAM,CAACQ,KAAK,CAAC,IAAKD;MAAK,GACxCH,KAAK,CAACrB,QAAQ,IAAI;QAAEA,QAAQ,EAAEqB,KAAK,CAACrB;MAAS,CAAC,EAClD;IAAA;EACH,GACD;AAAA,GACF;EAAEF,IAAI,EAAE;AAAS,CAAC,EAClB;EAAEb,iBAAiB,EAAE;AAAM,CAAC,CAC7B;AAAA;AAEM,IAAM4C,SAAS,GAAGnD,OAAO;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danderson00/react-forms-material",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.45",
|
|
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 --out-dir dist"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@danderson00/react-forms": "0.0.
|
|
13
|
+
"@danderson00/react-forms": "0.0.45",
|
|
14
14
|
"@material-ui/core": "^4.11.3"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
package/src/index.js
CHANGED
|
@@ -25,39 +25,41 @@ 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, pattern, ...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, 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
|
+
})] : []),
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
createElement(component, {
|
|
48
|
+
key: 'input',
|
|
49
|
+
variant,
|
|
50
|
+
...(passError && { error }),
|
|
51
|
+
...inputProps,
|
|
52
|
+
inputProps: { ...(pattern && { pattern }), ...inputProps.inputProps }
|
|
53
|
+
}),
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
...(helperText ? [createElement(MuiFormHelperText, {
|
|
56
|
+
key: 'helperText',
|
|
57
|
+
children: helperText
|
|
58
|
+
})] : [])
|
|
59
|
+
]
|
|
60
|
+
})
|
|
61
|
+
)
|
|
62
|
+
}
|
|
61
63
|
)
|
|
62
64
|
|
|
63
65
|
export const Input = wrapInput(MuiInput)
|
|
@@ -66,21 +68,22 @@ export const Checkbox = wrapped(MuiCheckbox, { type: 'checkbox' }, { alwaysShrin
|
|
|
66
68
|
export const RadioButton = wrapped(MuiRadio, { type: 'radio' }, { shrinkLabel: false })
|
|
67
69
|
|
|
68
70
|
export const Radio = createRawConsumer(base(
|
|
69
|
-
({ name, values, labels, numeric, required, getFieldValue, getFieldValues, ...props }) =>
|
|
70
|
-
createElement(MuiRadioGroup, { ...props, children: [
|
|
71
|
-
values.map((value, index) =>
|
|
72
|
-
createElement(RadioButton, {
|
|
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, {
|
|
73
75
|
name,
|
|
74
76
|
value,
|
|
75
77
|
numeric,
|
|
76
78
|
key: value,
|
|
77
79
|
label: (labels && labels[index]) || value,
|
|
78
80
|
margin: props.margin,
|
|
79
|
-
...(required && { required })
|
|
81
|
+
...(required && { required }),
|
|
82
|
+
inputProps
|
|
80
83
|
})
|
|
81
|
-
)
|
|
82
|
-
] }
|
|
83
|
-
),
|
|
84
|
+
})
|
|
85
|
+
] }
|
|
86
|
+
)},
|
|
84
87
|
{ type: 'radiogroup' },
|
|
85
88
|
{ alwaysShrinkLabel: true }
|
|
86
89
|
))
|