@atlaskit/datetime-picker
Version:
A date time picker allows the user to select an associated date and time.
59 lines (57 loc) • 2.75 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.componentWithCondition = componentWithCondition;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
/**
* Gets all available ref types from two prop sets and returns
* them in a ref prop
*
* @example
* ```
* type P1 = { ref: Ref(HTMLDivElement), ... };
* type P2 = { ref: Ref(HTMLSpanElement), ... };
*
* GetRefAttributes(P1, P2) // {ref: Ref(HTMLDivElement | HTMLSpanElement)}
* ```
*/
/**
* Returns one of components depending on a boolean condition.
* The result component will be a union of the two props and
* an or on both ref types.
*
* @example
* ```
* const Component = componentWithCondition(
* isBooleanConditionMet,
* ComponentWithConditionMet,
* ComponentWithConditionNotMet,
* );
*
* @param condition Function returning boolean value
* @param componentTrue Component that will be returned if conditionGetter is "true"
* @param componentFalse Component that will be returned if conditionGetter is "false"
* @returns Component Depending on a Condition result
*/
function componentWithCondition(condition, ComponentTrue, ComponentFalse) {
var ComponentWithCondition = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
return (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: to unblock React 18.2.0 -> 18.3.1 version bump in Jira
condition() ? /*#__PURE__*/_react.default.createElement(ComponentTrue, (0, _extends2.default)({}, props, {
ref: ref
})) : /*#__PURE__*/_react.default.createElement(ComponentFalse, (0, _extends2.default)({}, props, {
ref: ref
}))
);
});
if (ComponentTrue.name !== '') {
ComponentWithCondition.displayName = "ComponentWithCondition[".concat(condition.name, "]");
}
return ComponentWithCondition;
}