1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | exports.__esModule = true;
|
6 | exports["default"] = exports.useFormControlContext = exports.useFormControl = void 0;
|
7 |
|
8 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9 |
|
10 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
11 |
|
12 | var _core = require("@emotion/core");
|
13 |
|
14 | var _react = require("react");
|
15 |
|
16 | var _Box = _interopRequireDefault(require("../Box"));
|
17 |
|
18 |
|
19 | var useFormControl = function useFormControl(props) {
|
20 | var context = useFormControlContext();
|
21 |
|
22 | if (!context) {
|
23 | return props;
|
24 | }
|
25 |
|
26 | var keys = Object.keys(context);
|
27 | return keys.reduce(function (acc, prop) {
|
28 |
|
29 | acc[prop] = props[prop];
|
30 |
|
31 | if (context) {
|
32 | if (props[prop] == null) {
|
33 | acc[prop] = context[prop];
|
34 | }
|
35 | }
|
36 |
|
37 | return acc;
|
38 | }, {});
|
39 | };
|
40 |
|
41 | exports.useFormControl = useFormControl;
|
42 | var FormControlContext = (0, _react.createContext)();
|
43 |
|
44 | var useFormControlContext = function useFormControlContext() {
|
45 | return (0, _react.useContext)(FormControlContext);
|
46 | };
|
47 |
|
48 | exports.useFormControlContext = useFormControlContext;
|
49 | var FormControl = (0, _react.forwardRef)(function (_ref, ref) {
|
50 | var isInvalid = _ref.isInvalid,
|
51 | isRequired = _ref.isRequired,
|
52 | isDisabled = _ref.isDisabled,
|
53 | isReadOnly = _ref.isReadOnly,
|
54 | rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref, ["isInvalid", "isRequired", "isDisabled", "isReadOnly"]);
|
55 | var context = {
|
56 | isRequired: isRequired,
|
57 | isDisabled: isDisabled,
|
58 | isInvalid: isInvalid,
|
59 | isReadOnly: isReadOnly
|
60 | };
|
61 | return (0, _core.jsx)(FormControlContext.Provider, {
|
62 | value: context
|
63 | }, (0, _core.jsx)(_Box["default"], (0, _extends2["default"])({
|
64 | role: "group",
|
65 | ref: ref
|
66 | }, rest)));
|
67 | });
|
68 | FormControl.displayName = "FormControl";
|
69 | var _default = FormControl;
|
70 | exports["default"] = _default; |
\ | No newline at end of file |